Skip to content
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
22487f1
Started converting ID to JSR
anthonymstohr Feb 15, 2019
c76177f
JSR simulation work
anthonymstohr Feb 19, 2019
05c5bfb
Reorganized the simulations
anthonymstohr Feb 27, 2019
c21e72b
added run case info
anthonymstohr Mar 1, 2019
74470d5
Some reorganization for the two experiment types; JSR sims
anthonymstohr Mar 20, 2019
318fbdc
JSR simulation work done
anthonymstohr Mar 22, 2019
95cdef7
Finished and cleaned up JSR simulation
anthonymstohr Mar 30, 2019
bf299aa
Renamed Simulation to AutoignitionSimulation more consistently.
rwest Apr 5, 2019
8cb4b2b
Removed simulation.py which is now autoignition_simulation.py
rwest Apr 5, 2019
caa248a
added new eval model created by anthony
May 5, 2019
07a2f3b
Reorganized sims/eval models
anthonymstohr Apr 11, 2019
c337fc5
Refactored autoignition simulation and eval model
Jul 8, 2019
51761d9
Updated and modified jsr_simulation class and eval model for jsr (nee…
Jul 8, 2019
b8ca5e0
simulations runs but need to debug cantera stuff
Jul 8, 2019
1408523
close to get trapezoidal error function working!
Jul 9, 2019
771ea25
trapezoidal error function for area under curves works now but still …
Jul 9, 2019
0aaf21f
trapezodial error function successfully works. setup_case and run_cas…
Aug 15, 2019
110cfcf
started refactoring
Aug 16, 2019
d8ade12
ignition delays and jsr simulations successfully work
Aug 16, 2019
927215b
Added continue to ignore non-yaml files, pep-8 style, and check for c…
sevyharris Jul 4, 2021
1e270b8
Added plotting.py in order to automaticly generate concentration plot…
Jul 6, 2021
28404c2
cleaned up plotting.py code
Jul 6, 2021
8a5bb53
Added plot generation into jsr_eval_model.py
Jul 6, 2021
586d596
Small code improvements for jsr plotting
Jul 8, 2021
81811df
pyteck runs with multiple jsrs can use _ in name
sevyharris Jul 4, 2021
b78a87e
moving contents of autoignition back into simulation file
sevyharris Feb 23, 2022
03c3aae
moved JSRSimulation code into simulation
sevyharris Feb 23, 2022
0dd2cc8
fix PEP8 in simulation.py
sevyharris Feb 23, 2022
fe7ab9d
saving before I attempt to move jsr_eval into eval_model
sevyharris Feb 23, 2022
1dbb77a
changed datapoint to one set of conditions
sevyharris Feb 23, 2022
a130918
completed conversion of SpeciesProfileDatapoint to one reaction setting
sevyharris Feb 24, 2022
7869d40
added timeout for integration failure in JSR
sevyharris Feb 24, 2022
10fd2dc
created factory for multiple simulation types
sevyharris Feb 25, 2022
d88ff03
refactored eval_model for multiple sim types, just st right now
sevyharris Feb 25, 2022
55ac50f
JSR runs on eval_model code
sevyharris Feb 25, 2022
04f58ca
added more metadata to output, robust search for h5 files in plotting
sevyharris Feb 25, 2022
d058045
remove extra get_changing_variables function
sevyharris Feb 25, 2022
c71ce3f
add comments to new functions
sevyharris Feb 25, 2022
fccf2e9
eval_model tests pass again
sevyharris Feb 26, 2022
685d1e7
ignition delay tests pass
sevyharris Feb 27, 2022
ca74a47
add overall test of jsr code
sevyharris Feb 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ target/

# project-specific data files
*.h5

# IDE specific files
.vscode
91 changes: 44 additions & 47 deletions pyteck/eval_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
print('Warning: YAML must be installed to read input file.')
raise

from pyked.chemked import ChemKED, DataPoint
from pyked.chemked import ChemKED

# Local imports
from .utils import units
from .simulation import Simulation
from .simulation import AutoIgnitionSimulation as Simulation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I'm not sure I like the idea of importing something under a different name - could likely confuse people down the line. Is there a good reason for it?


min_deviation = 0.10
"""float: minimum allowable standard deviation for experimental data"""
Expand All @@ -40,7 +40,7 @@ def create_simulations(dataset, properties):
Returns
-------
simulations : list
List of :class:`Simulation` objects for each simulation
List of :class:`AutoignitionSimulation` objects for each simulation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I should wait to review until refactoring finished, but this file/module/class seems a little confused right now about if it's specific to Autoignition, or if it's generic for all simulations.

So I'm going to pause reviewing now. Let me know if/when I should take another look.


"""

Expand All @@ -59,19 +59,20 @@ def create_simulations(dataset, properties):
)
return simulations


def simulation_worker(sim_tuple):
"""Worker for multiprocessing of simulation cases.

Parameters
----------
sim_tuple : tuple
Contains Simulation object and other parameters needed to setup
Contains AutoignitionSimulation object and other parameters needed to setup
and run case.

Returns
-------
sim : ``Simulation``
Simulation case with calculated ignition delay.
sim : ``AutoignitionSimulation``
AutoignitionSimulation case with calculated ignition delay.

"""
sim, model_file, model_spec_key, path, restart = sim_tuple
Expand Down Expand Up @@ -113,7 +114,6 @@ def estimate_std_dev(indep_variable, dep_variable):
dep_variable = numpy.delete(dep_variable, idx[1:])
indep_variable = numpy.delete(indep_variable, idx[1:])


# ensure data sorted based on independent variable to avoid some problems
sorted_vars = sorted(zip(indep_variable, dep_variable))
indep_variable = [pt[0] for pt in sorted_vars]
Expand Down Expand Up @@ -143,8 +143,8 @@ def get_changing_variable(cases):

Parameters
----------
cases : list(pyked.chemked.DataPoint)
List of DataPoint with experimental case data.
cases : list(pyked.chemked.IgnitionDataPoint)
List of IgnitionDataPoint with experimental case data.

Returns
-------
Expand Down Expand Up @@ -192,7 +192,7 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,
data_path='data', model_path='models',
results_path='results', model_variant_file=None,
num_threads=None, print_results=False, restart=False,
skip_validation=False,
skip_validation=False
):
"""Evaluates the ignition delay error of a model for a given dataset.

Expand Down Expand Up @@ -257,7 +257,7 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,
# If number of threads not specified, use either max number of available
# cores minus 1, or use 1 if multiple cores not available.
if not num_threads:
num_threads = multiprocessing.cpu_count()-1 or 1
num_threads = multiprocessing.cpu_count() - 1 or 1

# Loop through all datasets
for idx_set, dataset in enumerate(dataset_list):
Expand Down Expand Up @@ -290,27 +290,18 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,
# Need to check if Ar or He in reactants but not model,
# and if so skip this dataset (for now).
#######################################################
if ((any(['Ar' in spec for case in properties.datapoints
for spec in case.composition]
)
and 'Ar' not in model_spec_key[model_name]
) or
(any(['He' in spec for case in properties.datapoints
for spec in case.composition]
)
and 'He' not in model_spec_key[model_name]
)
):
warnings.warn('Warning: Ar or He in dataset, but not in model. Skipping.',
RuntimeWarning
)
Ar_in_model = 'Ar' in model_spec_key[model_name]
He_in_model = 'He' in model_spec_key[model_name]
Ar_in_dataset = any(['Ar' in spec for case in properties.datapoints for spec in case.composition])
He_in_dataset = any(['He' in spec for case in properties.datapoints for spec in case.composition])
if (Ar_in_dataset and not Ar_in_model) or (He_in_dataset and not He_in_model):
warnings.warn(
'Warning: Ar or He in dataset, but not in model. Skipping.',
RuntimeWarning
)
error_func_sets[idx_set] = numpy.nan
continue

# Use available number of processors minus one,
# or one process if single core.
pool = multiprocessing.Pool(processes=num_threads)

# setup all cases
jobs = []
for idx, sim in enumerate(simulations):
Expand All @@ -323,7 +314,7 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,
bath_gases = set(model_variant[model_name]['bath gases'])
gases = bath_gases.intersection(
set([c['species-name'] for c in sim.properties.composition])
)
)

# If only one bath gas present, use that. If multiple, use the
# predominant species. If none of the designated bath gases
Expand All @@ -347,11 +338,10 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,

# choose closest pressure
# better way to do this?
i = numpy.argmin(numpy.abs(numpy.array(
[float(n)
for n in list(model_variant[model_name]['pressures'])
]
) - pres))
i = numpy.argmin(numpy.abs(numpy.array([
float(n)
for n in list(model_variant[model_name]['pressures'])
]) - pres))
pres = list(model_variant[model_name]['pressures'])[i]
model_mod += model_variant[model_name]['pressures'][pres]

Expand All @@ -361,13 +351,19 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,

jobs.append([sim, model_file, model_spec_key[model_name], results_path, restart])

# run all cases
jobs = tuple(jobs)
results = pool.map(simulation_worker, jobs)
if num_threads == 1:
# Don't use the threadpool if only 1 processor (useful for debugging)
results = []
for job in jobs:
results.append(simulation_worker(job))
else:
pool = multiprocessing.Pool(processes=num_threads)
jobs = tuple(jobs)
results = pool.map(simulation_worker, jobs)

# not adding more proceses, and ensure all finished
pool.close()
pool.join()
# not adding more proceses, and ensure all finished
pool.close()
pool.join()

dataset_meta['datapoints'] = []

Expand Down Expand Up @@ -399,16 +395,17 @@ def evaluate_model(model_name, spec_keys_file, dataset_file,

# calculate error function for this dataset
error_func = numpy.power(
(numpy.log(ignition_delays_sim) -
numpy.log(ignition_delays_exp)) / standard_dev, 2
)
(numpy.log(ignition_delays_sim) - numpy.log(ignition_delays_exp))
/ standard_dev, 2
)
error_func = numpy.nanmean(error_func)
error_func_sets[idx_set] = error_func
dataset_meta['error function'] = float(error_func)

dev_func = (numpy.log(ignition_delays_sim) -
numpy.log(ignition_delays_exp)
) / standard_dev
dev_func = (
numpy.log(ignition_delays_sim)
- numpy.log(ignition_delays_exp)
) / standard_dev
dev_func = numpy.nanmean(dev_func)
dev_func_sets[idx_set] = dev_func
dataset_meta['absolute deviation'] = float(dev_func)
Expand Down
Loading