Esempio n. 1
0
 def buildToFolderPath(self,dest_folder_path):
     # Write .mos script to folder
     mos_script_path = os.path.join(dest_folder_path, self.mos_script_file_name)
     self.writeMOSScriptToPath(mos_script_path)
     # Run mos script with OMC
     run_omc.runMosScript(mos_script_path)
     # Get binary path from folder and model name
     binary_file_path = os.path.join(dest_folder_path, self.model_name)
     # Initialize compiled model instance from path
     compiled_model = CompiledModelicaModel(self.model_name, binary_file_path)
     return compiled_model
Esempio n. 2
0
    def buildToFolderPath(self, dest_folder_path, base_dir, results_dirname):
        logger.debug('Enter build folder path')

        mos_script_path = os.path.join(dest_folder_path,
                                       self.mos_script_file_name)
        self.writeMOSScriptToPath(mos_script_path)

        logger.debug('run_omc')
        run_omc.runMosScript(mos_script_path)

        logger.debug('binary_file_path')
        binary_file_path = os.path.join(dest_folder_path, self.model_name)

        logger.debug('Generating compiled model')
        compiled_model = CompiledModelicaModel(self.model_name,
                                               binary_file_path, base_dir,
                                               results_dirname)
        logger.debug('Generated compiled model')
        return compiled_model
Esempio n. 3
0
def createSweepRunAndPlotForModelInfo(mos_script_factory_inst, plot_vars,
                                      iterations, output_folder_path,
                                      sweep_value_formula_str,
                                      csv_file_name_python_skeleton,
                                      csv_file_name_modelica_skeleton,
                                      plot_std_run, fixed_params_str):
    output_mos_path = os.path.join(output_folder_path,
                                   gral_settings.mos_script_filename)
    # EL scripting de modelica se rompe con la backslash (aunque estemos en windows). Hay que mandar la de unix nomas:
    output_mos_path = output_mos_path.replace("\\", "/")
    csv_file_name_modelica = csv_file_name_modelica_skeleton.format(i_name="i")
    mos_script_factory_inst.setSetting("csv_file_name_modelica",
                                       csv_file_name_modelica)
    # mos_script_factory_inst.setSetting("plot_vars",plot_vars)
    mos_script_factory_inst.setSetting("iterations", iterations)
    mos_script_factory_inst.setSetting("sweep_value_formula_str",
                                       sweep_value_formula_str)
    mos_script_factory_inst.setSetting("output_mos_path", output_mos_path)
    mos_script_factory_inst.createMosScript()  # argument-less method for now
    writeRunLog(
        mos_script_factory_inst.initializedSettings(),
        os.path.join(output_folder_path,
                     gral_settings.omc_creation_settings_filename))
    run_omc.runMosScript(output_mos_path)
    plots_folder_path = os.path.join(output_folder_path, "plots")
    os.makedirs(plots_folder_path)
    sweeping_vars = mos_script_factory_inst.initializedSettings()["sweep_vars"]
    sweeping_info = sweepingInfoPerIteration(
        mos_script_factory_inst.initializedSettings(),
        csv_file_name_python_skeleton)
    model_name_only = mos_script_factory_inst.initializedSettings(
    )["model_name"].split(".")[-1]
    plot_csv.plotVarsFromSweepingInfo(plot_vars, model_name_only,
                                      sweeping_info, plots_folder_path,
                                      plot_std_run, fixed_params_str)
    readme_path = os.path.join(output_folder_path,
                               gral_settings.readme_filename)
    readme_writer.writeReadme(readme_path, sweeping_info)
Esempio n. 4
0
 def test_omc_builds_a_model_correctly(self):
     mos_str = model_str + build_model_str
     mos_path = createTMPMos(mos_str, self)
     process_output = omc_runner.runMosScript(mos_path)
     error_line = process_output.splitlines()[-1]
     self.assertEqual(error_line, '""')
     # The following should be another test but because of slow building times, we minimize the
     # amount of compiling Modelica times
     # Test that OMC leaves no trash after building and simulating
     mos_folder_path = os.path.dirname(mos_path)
     trash_files = []
     for x in os.listdir(mos_folder_path):
         if re.match('.*\.(c|o|h|makefile|log|libs|json)$', x):
             trash_files.append(x)
     if len(trash_files) > 0:
         not_removed_files = ",".join(trash_files)
         fail_message = "The following files should've been removed but weren't: {0}".format(
             not_removed_files)
         self.fail(fail_message)
Esempio n. 5
0
 def test_omc_loads_a_model_correctly(self):
     mos_str = model_str
     mos_path = createTMPMos(mos_str, self)
     process_output = omc_runner.runMosScript(mos_path)
     self.assertEqual(process_output, "true\n")