Skip to content

Commit c3ebc45

Browse files
Added new mmoc and c compile python methods.
1 parent c22d7b0 commit c3ebc45

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/python/qss_solver/simulate.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,54 @@ def compile_model(model_file, flags=''):
2626
return False
2727
return True
2828

29+
def compile_mmoc_model(model_file, flags=''):
30+
"""
31+
Compile the specified Modelica model.
32+
33+
Parameters:
34+
- model_file: Path to the model file.
35+
- flags: Additional flags for compilation.
36+
"""
37+
mmoc_cmd = os.path.join(os.environ['MMOC_BIN'], 'mmoc.sh')
38+
39+
model_name = fh.get_file_name(model_file)
40+
#model_path = fh.get_base_path(model_file)
41+
42+
logging.info(f'Compiling model: {model_name}')
43+
try:
44+
if flags == '':
45+
comp_flags = '-o ' + flags
46+
subprocess.check_call([mmoc_cmd, comp_flags, model_file])
47+
else:
48+
subprocess.check_call([mmoc_cmd, model_file])
49+
logging.info('Compilation done')
50+
except subprocess.CalledProcessError as e:
51+
logging.error(f"Compilation failed for {model_name}: {e}")
52+
return False
53+
return True
54+
55+
def compile_c_model(model_file, flags=''):
56+
"""
57+
Compile the specified Modelica model.
58+
59+
Parameters:
60+
- model_file: Path to the C model file.
61+
- flags: Additional flags for compilation.
62+
"""
63+
build_cmd = os.path.join(os.environ['MMOC_BIN'], 'build.sh')
64+
65+
model_name = fh.get_file_name(model_file)
66+
model_path = fh.get_base_path(model_file)
67+
68+
logging.info(f'Compiling model: {model_name}')
69+
try:
70+
subprocess.check_call([build_cmd, model_name, model_path, flags])
71+
logging.info('Compilation done')
72+
except subprocess.CalledProcessError as e:
73+
logging.error(f"Compilation failed for {model_name}: {e}")
74+
return False
75+
return True
76+
2977
def execute_model(model_file):
3078
"""
3179
Run the executable model given.

0 commit comments

Comments
 (0)