Skip to content

Commit 2d01965

Browse files
Auto-format code using pep8 (#324)
Co-authored-by: GitHub Actions <actions@github.com>
1 parent 55c2178 commit 2d01965

File tree

5 files changed

+52
-60
lines changed

5 files changed

+52
-60
lines changed

src/acom_music_box/conditions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,3 @@ def read_data_values_from_table(cls, data_json, react_types=None):
327327
logger.debug(f"For {react_types} data_values = {data_values}")
328328

329329
return data_values
330-

src/acom_music_box/music_box.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def solve(self, callback=None):
9191
raise Exception(f"Error: MusicBox object {self} has no chemistry step time.")
9292
if self.box_model_options.output_step_time is None:
9393
raise Exception(f"Error: MusicBox object {self} has no output step time.")
94-
94+
9595
# sets up initial conditions to be current conditions
9696
curr_conditions = self.initial_conditions
9797

@@ -112,11 +112,10 @@ def solve(self, callback=None):
112112

113113
header = ["time.s", "ENV.temperature.K", "ENV.pressure.Pa", "ENV.air number density.mol m-3"]
114114
for species, _ in self.state.get_concentrations().items():
115-
header.append("CONC."+species+".mol m-3")
116-
115+
header.append("CONC." + species + ".mol m-3")
117116

118117
# set the initial conditions in the state
119-
self.state.set_conditions(curr_conditions.temperature, curr_conditions.pressure) # air denisty will be calculated based on Ideal gas law
118+
self.state.set_conditions(curr_conditions.temperature, curr_conditions.pressure) # air denisty will be calculated based on Ideal gas law
120119
self.state.set_concentrations(curr_conditions.species_concentrations)
121120
self.state.set_user_defined_rate_parameters(curr_conditions.rate_parameters)
122121

@@ -137,7 +136,7 @@ def solve(self, callback=None):
137136
row.append(conditions["pressure"][0])
138137
row.append(conditions["air_density"][0])
139138
for _, concentration in self.state.get_concentrations().items():
140-
row.append(concentration[0])
139+
row.append(concentration[0])
141140
output_array.append(row)
142141

143142
next_output_time += self.box_model_options.output_step_time
@@ -165,7 +164,7 @@ def solve(self, callback=None):
165164
else:
166165
next_conditions = None
167166
# set the current conditions in the state
168-
self.state.set_conditions(curr_conditions.temperature, curr_conditions.pressure) # air denisty will be calculated based on Ideal gas law
167+
self.state.set_conditions(curr_conditions.temperature, curr_conditions.pressure) # air denisty will be calculated based on Ideal gas law
169168
self.state.set_concentrations(curr_conditions.species_concentrations)
170169
self.state.set_user_defined_rate_parameters(curr_conditions.rate_parameters)
171170

@@ -214,13 +213,13 @@ def loadJson(self, path_to_json):
214213
camp_path = os.path.join(os.path.dirname(path_to_json), self.config_file)
215214

216215
# Initalize the musica solver
217-
self.solver = musica.MICM(config_path = camp_path, solver_type=musica.SolverType.rosenbrock_standard_order)
216+
self.solver = musica.MICM(config_path=camp_path, solver_type=musica.SolverType.rosenbrock_standard_order)
218217
self.state = self.solver.create_state(1)
219218

220219
def load_mechanism(self, mechanism, solver_type=musica.SolverType.rosenbrock_standard_order):
221220
"""
222221
Creates a solver for the specified mechanism.
223-
222+
224223
Args:
225224
mechanism (Mechanism): The mechanism to be used for the solver.
226225
"""

tests/integration/test_analytical.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ def test_in_code(self):
126126
C = mc.Species(name="C")
127127
gas = mc.Phase(name="gas", species=[A, B, C])
128128
arr1 = mc.Arrhenius(name="B->C", A=1.2e-4, B=7, C=75, D=50, E=0.5,
129-
reactants=[B], products=[C], gas_phase=gas)
129+
reactants=[B], products=[C], gas_phase=gas)
130130
arr2 = mc.Arrhenius(name="A->B", A=4.0e-3, C=50,
131-
reactants=[A], products=[B], gas_phase=gas)
131+
reactants=[A], products=[B], gas_phase=gas)
132132
mechanism = mc.Mechanism(name="test_mechanism", species=[A, B, C],
133-
phases=[gas], reactions=[arr1, arr2])
133+
phases=[gas], reactions=[arr1, arr2])
134134
box_model.load_mechanism(mechanism)
135135

136136
# Set up the initial conditions
@@ -147,7 +147,6 @@ def test_in_code(self):
147147

148148
self.solve_and_compare(box_model)
149149

150-
151150

152151
if __name__ == "__main__":
153152
logging.basicConfig(level=logging.DEBUG)

tests/integration/test_chapman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_run(self):
1616
# solves and saves output
1717
model = box_model.solve()
1818

19-
model.columns = [ column for column in model.columns ]
19+
model.columns = [column for column in model.columns]
2020

2121
current_dir = os.path.dirname(__file__)
2222
expected_results_path = os.path.join(current_dir, "expected_results/chapman_test.csv")

tests/integration/test_in_code_mechanism.py

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def define_system(self):
1818
D = mc.Species(name="D")
1919
E = mc.Species(name="E")
2020
F = mc.Species(name="F")
21-
species = { "A": A, "B": B, "C": C, "D": D, "E": E, "F": F }
21+
species = {"A": A, "B": B, "C": C, "D": D, "E": E, "F": F}
2222
gas = mc.Phase(name="gas", species=list(species.values()))
2323

2424
return gas, species
@@ -32,38 +32,38 @@ def create_box_model(self, mechanism):
3232

3333
# Set the initial conditions
3434
box_model.initial_conditions = Conditions(
35-
temperature=298.15,
36-
pressure=101325.0,
37-
species_concentrations={
38-
"A": 1.0,
39-
"B": 0.0,
40-
"C": 0.0,
41-
"D": 10.0,
42-
"E": 0.0,
43-
"F": 0.0,
44-
})
35+
temperature=298.15,
36+
pressure=101325.0,
37+
species_concentrations={
38+
"A": 1.0,
39+
"B": 0.0,
40+
"C": 0.0,
41+
"D": 10.0,
42+
"E": 0.0,
43+
"F": 0.0,
44+
})
4545

4646
# Set the evolving conditions
4747
box_model.add_evolving_condition(
48-
300.0,
49-
Conditions(
50-
temperature=310.0,
51-
pressure=100100.0,
52-
species_concentrations={
53-
"D": 1.0,
54-
"E": 0.0,
55-
"F": 0.0,
56-
}))
48+
300.0,
49+
Conditions(
50+
temperature=310.0,
51+
pressure=100100.0,
52+
species_concentrations={
53+
"D": 1.0,
54+
"E": 0.0,
55+
"F": 0.0,
56+
}))
5757
box_model.add_evolving_condition(
58-
450.0,
59-
Conditions(
60-
temperature=280.0,
61-
pressure=90500.0,
62-
species_concentrations={
63-
"A": 100.0,
64-
"B": 0.0,
65-
"C": 0.0,
66-
}))
58+
450.0,
59+
Conditions(
60+
temperature=280.0,
61+
pressure=90500.0,
62+
species_concentrations={
63+
"A": 100.0,
64+
"B": 0.0,
65+
"C": 0.0,
66+
}))
6767

6868
# Set the time step and duration
6969
box_model.box_model_options.simulation_length = 600.0
@@ -177,48 +177,47 @@ def solve_and_compare(self, box_model, calc_k1, calc_k2, calc_k3, calc_k4):
177177
assert math.isclose(A_conc, A_conc_model, rel_tol=1e-6, abs_tol=1.0e-3), f"A concentrations differ at time {time}"
178178
assert math.isclose(B_conc, B_conc_model, rel_tol=1e-6, abs_tol=1.0e-3), f"B concentrations differ at time {time}"
179179
assert math.isclose(C_conc, C_conc_model, rel_tol=1e-6, abs_tol=1.0e-3), f"C concentrations differ at time {time}"
180-
181-
180+
182181
def test_arrhenius(self):
183182
"""
184183
Test the Arrhenius reaction mechanism.
185184
"""
186185
gas, species = self.define_system()
187186
arr1 = mc.Arrhenius(name="A->B", A=4.0e-3, C=50,
188-
reactants=[species["A"]], products=[species["B"]], gas_phase=gas)
187+
reactants=[species["A"]], products=[species["B"]], gas_phase=gas)
189188
arr2 = mc.Arrhenius(name="B->C", A=1.2e-4, B=2.5, C=75, D=50, E=0.5,
190-
reactants=[species["B"]], products=[species["C"]], gas_phase=gas)
189+
reactants=[species["B"]], products=[species["C"]], gas_phase=gas)
191190
arr3 = mc.Arrhenius(name="D->E", A=4.0e-3, C=35,
192-
reactants=[species["D"]], products=[species["E"]], gas_phase=gas)
191+
reactants=[species["D"]], products=[species["E"]], gas_phase=gas)
193192
arr4 = mc.Arrhenius(name="E->F", A=1.2e-4, B=1.4, C=75, D=50, E=0.1,
194-
reactants=[species["E"]], products=[species["F"]], gas_phase=gas)
193+
reactants=[species["E"]], products=[species["F"]], gas_phase=gas)
195194
mechanism = mc.Mechanism(name="test_mechanism", species=list(species.values()),
196-
phases=[gas], reactions=[arr1, arr2, arr3, arr4])
197-
195+
phases=[gas], reactions=[arr1, arr2, arr3, arr4])
196+
198197
box_model = self.create_box_model(mechanism)
199198

200199
# Define the rate constants as functions of temperature, pressure, and air density
201200
def calc_k1(temperature, pressure, air_density):
202201
return 4.0e-3 * math.exp(50 / temperature)
203202

204203
def calc_k2(temperature, pressure, air_density):
205-
return (
204+
return (
206205
1.2e-4
207206
* math.exp(75 / temperature)
208207
* (temperature / 50) ** 2.5
209208
* (1.0 + 0.5 * pressure)
210-
)
211-
209+
)
210+
212211
def calc_k3(temperature, pressure, air_density):
213212
return 4.0e-3 * math.exp(35 / temperature)
214213

215214
def calc_k4(temperature, pressure, air_density):
216-
return (
215+
return (
217216
1.2e-4
218217
* math.exp(75 / temperature)
219218
* (temperature / 50) ** 1.4
220219
* (1.0 + 0.1 * pressure)
221-
)
220+
)
222221

223222
self.solve_and_compare(box_model, calc_k1, calc_k2, calc_k3, calc_k4)
224223

@@ -227,7 +226,3 @@ def calc_k4(temperature, pressure, air_density):
227226
logging.basicConfig(level=logging.DEBUG)
228227
test = TestInCodeMechanism()
229228
test.test_arrhenius()
230-
231-
232-
233-

0 commit comments

Comments
 (0)