forked from Eureka10shen/SLRed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (61 loc) · 2.39 KB
/
main.py
File metadata and controls
66 lines (61 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2024 Shen Fang, Beihang University.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
# os.environ['CUDA_VISIBLE_DEVICES'] = '1'
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
from absl import logging
logging.set_verbosity(logging.INFO)
import argparse
import warnings
import importlib
from reduction import reduced_detailed, reduced_sl, reduce_pymars
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Kinetic mechanism reduction')
parser.add_argument('--fuel', type=str, default='n_heptane', help='Name of fuel')
parser.add_argument('--method', type=str, default='sl', help='Reduction method')
args = parser.parse_args()
if args.method == 'sl': # sparse learning method
try:
module_name = f'cfgs.{args.fuel}'
module = importlib.import_module(module_name)
default = module.default
print(f"Successfully imported 'default' from {module_name}")
except ImportError as e:
print(f"Error: Unable to import 'default' from {module_name}. {e}")
# sparse learning reduction
cfg = default()
reduced_sl(cfg)
elif args.method == 'dr': # detailed reduction method
try:
module_name = f'cfgs.{args.fuel}'
module = importlib.import_module(module_name)
default = module.default
print(f"Successfully imported 'default' from {module_name}")
except ImportError as e:
print(f"Error: Unable to import 'default' from {module_name}. {e}")
# detailed reduction
cfg = default()
cfg.unlock()
cfg.eps_r = 0.1 # initial epsilon
cfg.eps_q = 0.1
cfg.ref_rct1 = 'H + O2 <=> O + OH' # user-defined reference reactions
cfg.ref_rct2 = 'H + O2 (+M) <=> HO2 (+M)'
cfg.n_steps = 100
cfg.error_limit = 15
cfg.lock()
reduced_detailed(cfg)
else: # methods from pyMARS, e.g. DRGEP and DRGEPSA
cfg_file = os.path.join('./cfgs', args.fuel+'.yaml')
reduce_pymars(cfg_file)