Time = 1e-06
========Time Spent in diffenet parts========
loop Time = 21.7963 s
other Time = 1e-06 s
rho Equations = 0.010316 s
U Equations = 0.194424 s
Y Equations = 2.65603 s
E Equations = 0.18264 s
p Equations = 0.531852 s
chemistry correctThermo = 0.907214 s
turbulence correct = 2.6e-05 s
combustion correct(in Y) = 17.2706 s
percentage of chemistry = 79.2364 %
percentage of rho/U/Y/E = 13.963 %
Time = 1e-06
========Time Spent in diffenet parts========
loop Time = 22.8885 s
other Time = 0 s
rho Equations = 0.010008 s
U Equations = 0.184964 s
Y Equations = 2.60104 s
E Equations = 0.159949 s
p Equations = 0.495936 s
chemistry correctThermo = 0.802762 s
turbulence correct = 2e-05 s
combustion correct(in Y) = 18.6158 s
percentage of chemistry = 81.3325 %
percentage of rho/U/Y/E = 12.9146 %
Python
import cantera as ct
import numpy as np
import time
# Assuming mech and data are defined
gas = ct.Solution(mech)
# Create Reactor and ReactorNet
r = ct.Reactor(gas, name='R1', energy='off')
sim = ct.ReactorNet([r])
sim.rtol, sim.atol = 1e-6, 1e-10
time_steps = [] # List to store time for each iteration
start_time = time.time() # Start timer
# Repeat the entire process 100 times
for _ in range(10000):
# Initialize the state
npstate = data[0, :11] # Assuming data is defined and has sufficient rows
T_old, P_old, Y_old = npstate[0], npstate[1], npstate[2:]
gas.TPY = T_old, P_old, Y_old
res_1st = [T_old, P_old] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights)
# Measure time for advancing the simulation
r.syncState()
sim.reinitialize()
sim.advance(time_step)
sim.initial_time = 0.0
# Get new state
new_TPY = [gas.T, gas.P] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights)
res_1st += new_TPY
elapsed_time = time.time() - start_time # Calculate elapsed time
# Print average time after all iterations
print("Elapsed times for each iteration:", elapsed_time)
# print("Average time per iteration:", np.mean(time_steps))
# Assuming mech and data are defined
gas = ct.Solution(mech)
time_steps = [] # List to store time for each iteration
start_time = time.time() # Start timer
# Repeat the entire process 100 times
for _ in range(10000):
# Initialize the state
npstate = data[0, :11] # Assuming data is defined and has sufficient rows
T_old, P_old, Y_old = npstate[0], npstate[1], npstate[2:]
gas.TPY = T_old, P_old, Y_old
res_1st = [T_old, P_old] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights)
# Create Reactor and ReactorNet
r = ct.Reactor(gas, name='R1', energy='off')
sim = ct.ReactorNet([r])
sim.rtol, sim.atol = 1e-6, 1e-10
# Measure time for advancing the simulation
sim.advance(time_step)
# Get new state
new_TPY = [gas.T, gas.P] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights)
res_1st += new_TPY
elapsed_time = time.time() - start_time # Calculate elapsed time
# Print average time after all iterations
print("Elapsed times for each iteration:", elapsed_time)
# print("Average time per iteration:", np.mean(time_steps))
Results:
Elapsed times for each iteration: 1.2987749576568604
Elapsed times for each iteration: 1.4612696170806885
Conclusions
An approximate 8% to 10% speedup could be expected, although this improvement may diminish with larger mesh sizes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request addresses the issue of repetitive initialization in the Cantera Reactor by calling syncState().
Performance Test
Versions Tested
DeepFlame Version:
Test Environment:
Example Used:
Logs
Python
import cantera as ct import numpy as np import time # Assuming mech and data are defined gas = ct.Solution(mech) # Create Reactor and ReactorNet r = ct.Reactor(gas, name='R1', energy='off') sim = ct.ReactorNet([r]) sim.rtol, sim.atol = 1e-6, 1e-10 time_steps = [] # List to store time for each iteration start_time = time.time() # Start timer # Repeat the entire process 100 times for _ in range(10000): # Initialize the state npstate = data[0, :11] # Assuming data is defined and has sufficient rows T_old, P_old, Y_old = npstate[0], npstate[1], npstate[2:] gas.TPY = T_old, P_old, Y_old res_1st = [T_old, P_old] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights) # Measure time for advancing the simulation r.syncState() sim.reinitialize() sim.advance(time_step) sim.initial_time = 0.0 # Get new state new_TPY = [gas.T, gas.P] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights) res_1st += new_TPY elapsed_time = time.time() - start_time # Calculate elapsed time # Print average time after all iterations print("Elapsed times for each iteration:", elapsed_time) # print("Average time per iteration:", np.mean(time_steps)) # Assuming mech and data are defined gas = ct.Solution(mech) time_steps = [] # List to store time for each iteration start_time = time.time() # Start timer # Repeat the entire process 100 times for _ in range(10000): # Initialize the state npstate = data[0, :11] # Assuming data is defined and has sufficient rows T_old, P_old, Y_old = npstate[0], npstate[1], npstate[2:] gas.TPY = T_old, P_old, Y_old res_1st = [T_old, P_old] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights) # Create Reactor and ReactorNet r = ct.Reactor(gas, name='R1', energy='off') sim = ct.ReactorNet([r]) sim.rtol, sim.atol = 1e-6, 1e-10 # Measure time for advancing the simulation sim.advance(time_step) # Get new state new_TPY = [gas.T, gas.P] + list(gas.Y) + list(gas.partial_molar_enthalpies / gas.molecular_weights) res_1st += new_TPY elapsed_time = time.time() - start_time # Calculate elapsed time # Print average time after all iterations print("Elapsed times for each iteration:", elapsed_time) # print("Average time per iteration:", np.mean(time_steps))Results:
Conclusions
An approximate 8% to 10% speedup could be expected, although this improvement may diminish with larger mesh sizes.