def setUpClass(cls): model_file = os.path.join(get_files_path(), 'Modelica', 'NegatedAlias.mo') name = compile_fmu("NegatedAlias", model_file) model_file = os.path.join(get_files_path(), 'Modelica', 'ParameterAlias.mo') name = compile_fmu("ParameterAlias", model_file)
def setup_class_base(cls, mo_file, class_name, options={}, target="me", version=None): """ Set up a new test model. Compiles the model. Call this with proper args from setUpClass(). mo_file - the relative path from the files dir to the .mo file to compile class_name - the qualified name of the class to simulate options - a dict of options to set in the compiler, defaults to no options """ global _model_name cls.mo_path = os.path.join(get_files_path(), 'Modelica', mo_file) if version == None: _model_name = compile_fmu(class_name, cls.mo_path, compiler_options=options, target=target) else: _model_name = compile_fmu(class_name, cls.mo_path, compiler_options=options, target=target, version=version)
def test_event_iteration(self): """ This tests FMUs with event iteration (JModelica.org). """ fmu_name = compile_fmu('EventIter.EventMiddleIter', os.path.join(path_to_mos,'EventIter.mo')) model = load_fmu(fmu_name) sim_res = model.simulate(final_time=10) nose.tools.assert_almost_equal(sim_res.initial('x'), 2.00000, 4) nose.tools.assert_almost_equal(sim_res.final('x'), 10.000000, 4) nose.tools.assert_almost_equal(sim_res.final('y'), 3.0000000, 4) nose.tools.assert_almost_equal(sim_res.final('z'), 2.0000000, 4) fmu_name = compile_fmu('EventIter.EventStartIter', os.path.join(path_to_mos,'EventIter.mo')) model = FMUModel(fmu_name) sim_res = model.simulate(final_time=10) nose.tools.assert_almost_equal(sim_res.initial('x'), 1.00000, 4) nose.tools.assert_almost_equal(sim_res.initial('y'), -1.00000, 4) nose.tools.assert_almost_equal(sim_res.initial('z'), 1.00000, 4) nose.tools.assert_almost_equal(sim_res.final('x'), -2.000000, 4) nose.tools.assert_almost_equal(sim_res.final('y'), -1.0000000, 4) nose.tools.assert_almost_equal(sim_res.final('z'), 4.0000000, 4)
def setUpClass(cls): """ Sets up the test class. """ cls.coupled_name = compile_fmu( "Modelica.Mechanics.Rotational.Examples.CoupledClutches", target="cs", version="2.0", compiler_options={'eliminate_alias_constants': False}) cls.bouncing_name = compile_fmu( "BouncingBall", os.path.join(path_to_mofiles, "BouncingBall.mo"), target="cs", version="2.0", compiler_options={'eliminate_alias_constants': False}) cls.terminate = compile_fmu("Terminate", os.path.join(path_to_mofiles, "Terminate.mo"), target="cs", version="2.0") cls.assert_fail = compile_fmu("AssertFail", os.path.join(path_to_mofiles, "Terminate.mo"), target="cs", version="2.0") cls.initialize_solver = compile_fmu("Inputs.DiscChange", os.path.join( path_to_mofiles, "InputTests.mo"), target="cs", version="2.0")
def setUpClass(cls): """ Sets up the test class. """ cls.rlc_circuit = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo"), version="1.0") cls.depPar1 = compile_fmu("DepParTests.DepPar1",os.path.join(path_to_mofiles,"DepParTests.mo"), version="1.0") cls.string1 = compile_fmu("StringModel1",os.path.join(path_to_mofiles,"TestString.mo"), version="1.0")
def test_set_compiler_options(self): """ Test compiling with compiler options.""" libdir = os.path.join(get_files_path(), 'MODELICAPATH_test', 'LibLoc1', 'LibA') co = {"index_reduction":True, "equation_sorting":True} compile_fmu('RLC_Circuit', [os.path.join(path_to_mofiles,'RLC_Circuit.mo'), libdir], compiler_options = co)
def test_event_iteration(self): """ This tests FMUs with event iteration (JModelica.org). """ fmu_name = compile_fmu('EventIter.EventMiddleIter', os.path.join(path_to_mos, 'EventIter.mo')) model = load_fmu(fmu_name) sim_res = model.simulate(final_time=10) nose.tools.assert_almost_equal(sim_res.initial('x'), 2.00000, 4) nose.tools.assert_almost_equal(sim_res.final('x'), 10.000000, 4) nose.tools.assert_almost_equal(sim_res.final('y'), 3.0000000, 4) nose.tools.assert_almost_equal(sim_res.final('z'), 2.0000000, 4) fmu_name = compile_fmu('EventIter.EventStartIter', os.path.join(path_to_mos, 'EventIter.mo')) model = FMUModel(fmu_name) sim_res = model.simulate(final_time=10) nose.tools.assert_almost_equal(sim_res.initial('x'), 1.00000, 4) nose.tools.assert_almost_equal(sim_res.initial('y'), -1.00000, 4) nose.tools.assert_almost_equal(sim_res.initial('z'), 1.00000, 4) nose.tools.assert_almost_equal(sim_res.final('x'), -2.000000, 4) nose.tools.assert_almost_equal(sim_res.final('y'), -1.0000000, 4) nose.tools.assert_almost_equal(sim_res.final('z'), 4.0000000, 4)
def setUpClass(cls): """ Compile the test model. """ file_name = os.path.join(get_files_path(), 'Modelica', 'Reinit.mo') compile_fmu("Reinit.ReinitWriteback", file_name)
def setUpClass(cls): """ Sets up the test class. """ cls.coupled_name = compile_fmu( "Modelica.Mechanics.Rotational.Examples.CoupledClutches", target="me", version="2.0", compiler_options={'eliminate_alias_constants': False}) cls.bouncing_name = compile_fmu( "BouncingBall", os.path.join(path_to_mofiles, "BouncingBall.mo"), target="me", version="2.0", compiler_options={'eliminate_alias_constants': False}) cls.enum_name = compile_fmu("Enumerations.Enumeration2", os.path.join(path_to_mofiles, "Enumerations.mo"), target="me", version="2.0") cls.string1 = compile_fmu("StringModel1", os.path.join(path_to_mofiles, "TestString.mo"), target="me", version="2.0") cls.linear2 = compile_fmu("LinearTest.Linear2", os.path.join(path_to_mofiles, "Linear.mo"), target="me", version="2.0")
def setUpClass(cls): """ Sets up the test class. """ rlc_circuit = compile_fmu( "RLC_Circuit", os.path.join(path_to_mofiles, "RLC_Circuit.mo")) depPar1 = compile_fmu("DepParTests.DepPar1", os.path.join(path_to_mofiles, "DepParTests.mo"))
def setUpClass(cls): """ Sets up the test class. """ name = compile_fmu("NegatedAlias", os.path.join(path_to_mofiles, "NegatedAlias.mo")) name = compile_fmu('TablesTest.Table1DfromArray', os.path.join(path_to_mofiles, 'TablesTests.mo'))
def test_set_compiler_options(self): """ Test compiling with compiler options.""" libdir = os.path.join(get_files_path(), 'MODELICAPATH_test', 'LibLoc1', 'LibA') co = {"index_reduction":True, "equation_sorting":True, "extra_lib_dirs":[libdir]} compile_fmu('RLC_Circuit', os.path.join(path_to_mofiles,'RLC_Circuit.mo'), compiler_options = co)
def setUpClass(cls): """ Sets up the test class. """ cls.coupled_name = compile_fmu("Modelica.Mechanics.Rotational.Examples.CoupledClutches", target="cs", version="2.0", compiler_options={'eliminate_alias_constants':False}) cls.bouncing_name = compile_fmu("BouncingBall",os.path.join(path_to_mofiles,"BouncingBall.mo"), target="cs", version="2.0", compiler_options={'eliminate_alias_constants':False}) cls.jacobian_name = compile_fmu("JacFuncTests.BasicJacobianTest",os.path.join(path_to_mofiles,"JacTest.mo"), target="cs", version="2.0", compiler_options={'generate_ode_jacobian':True}) cls.terminate = compile_fmu("Terminate",os.path.join(path_to_mofiles,"Terminate.mo"),target="cs", version="2.0") cls.assert_fail = compile_fmu("AssertFail",os.path.join(path_to_mofiles,"Terminate.mo"),target="cs", version="2.0")
def setUpClass(cls): """ Compile the test model. """ file_name = os.path.join(get_files_path(), 'Modelica', 'noState.mo') _ex1_name = compile_fmu("NoState.Example1", file_name) _ex2_name = compile_fmu("NoState.Example2", file_name) _cc_name = compile_fmu("Modelica.Mechanics.Rotational.Examples.CoupledClutches")
def setUpClass(cls): """ Compile the test model. """ file_name = os.path.join(get_files_path(), 'Modelica', 'noState.mo') _ex1_name = compile_fmu("NoState.Example1", file_name) _ex2_name = compile_fmu("NoState.Example2", file_name) _cc_name = compile_fmu( "Modelica.Mechanics.Rotational.Examples.CoupledClutches")
def setUpClass(cls): """ Sets up the test class. """ cls.negAliasFmu = compile_fmu("NegatedAlias", os.path.join(path_to_mofiles, "NegatedAlias.mo"), version=1.0) cls.enumFMU = compile_fmu('Parameter.Enum', os.path.join(path_to_mofiles, 'ParameterTests.mo'), version=1.0)
def setup_class_base(cls, mo_file, class_name, options={}, format='jmu', target="me"): """ Set up a new test model. Compiles the model. Call this with proper args from setUpClass(). mo_file - the relative path from the files dir to the .mo file to compile class_name - the qualified name of the class to simulate options - a dict of options to set in the compiler, defaults to no options format - either 'jmu' or 'fmu' depending on which format should be tested """ global _model_name cls.mo_path = os.path.join(get_files_path(), 'Modelica', mo_file) if format == 'jmu': _model_name = compile_jmu(class_name, cls.mo_path, compiler_options=options) elif format == 'fmu': _model_name = compile_fmu(class_name, cls.mo_path, compiler_options=options, target=target) else: raise Exception("Format must be either 'jmu' or 'fmu'.")
def setUpClass(cls): model_file = os.path.join(get_files_path(), 'Modelica', 'NegatedAlias.mo') name = compile_fmu("NegatedAlias", model_file) name = compile_fmu("NegatedAlias", model_file, target="cs", compile_to="NegatedAliasCS.fmu") name = compile_fmu("NegatedAlias", model_file, version=2.0, target="cs", compile_to="NegatedAliasCS2.fmu") model_file = os.path.join(get_files_path(), 'Modelica', 'ParameterAlias.mo') name = compile_fmu("ParameterAlias", model_file)
def setUpClass(cls): """ Sets up the test class. """ m = compile_fmu( 'DependentParameterTest2', os.path.join(path_to_mofiles, 'DependentParameterTest.mo'))
def setUpClass(cls): """ Sets up the test class. """ fpath = os.path.join(get_files_path(), 'Modelica', "DepPar.mo") cpath = "DepPar.DepPar1" cls.fmu_name = compile_fmu(cpath, fpath, version="1.0")
def test_inlined_switches(self): """ Test a model that need in-lined switches to initialize. """ path = os.path.join(get_files_path(), 'Modelica', 'event_init.mo') fmu_name = compile_fmu('Init', path) model = load_fmu(fmu_name) model.initialize() assert N.abs(model.get("x") - (-2.15298995)) < 1e-3
def test_check_against_unneccesary_derivatives_eval(self): name = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo"), compiler_options={"generate_html_diagnostics":True, "log_level":6}) model = load_fmu(name, log_level=6) model.set("_log_level", 6) model.initialize() len_log = len(model.get_log()) model.time = 1e-4 model.get_derivatives() assert len(model.get_log()) > len_log len_log = len(model.get_log()) model.get_derivatives() len_log_diff = len(model.get_log())-len_log model.time = 1e-4 len_log = len(model.get_log()) model.get_derivatives() assert len(model.get_log())-len_log_diff == len_log len_log = len(model.get_log()) model.continuous_states = model.continuous_states model.get_derivatives() assert len(model.get_log())-len_log_diff == len_log len_log = len(model.get_log()) model.continuous_states = model.continuous_states+1 model.get_derivatives() assert len(model.get_log())-len_log_diff > len_log
def setUpClass(cls): """ Sets up the test class. """ cls.fmu = compile_fmu('InitTest1', os.path.join(path_to_mofiles, 'InitTest.mo'), version="1.0")
def test_check_against_unneccesary_derivatives_eval(self): name = compile_fmu("RLC_Circuit", os.path.join(path_to_mofiles, "RLC_Circuit.mo"), compiler_options={ "generate_html_diagnostics": True, "log_level": 6 }) model = load_fmu(name, log_level=6) model.set("_log_level", 6) model.initialize() len_log = len(model.get_log()) model.time = 1e-4 model.get_derivatives() assert len(model.get_log()) > len_log len_log = len(model.get_log()) model.get_derivatives() len_log_diff = len(model.get_log()) - len_log model.time = 1e-4 len_log = len(model.get_log()) model.get_derivatives() assert len(model.get_log()) - len_log_diff == len_log len_log = len(model.get_log()) model.continuous_states = model.continuous_states model.get_derivatives() assert len(model.get_log()) - len_log_diff == len_log len_log = len(model.get_log()) model.continuous_states = model.continuous_states + 1 model.get_derivatives() assert len(model.get_log()) - len_log_diff > len_log
def setUpClass(cls): """ Sets up the test class. """ cls.rlc_circuit = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo"),target="cs", version="1.0") cls.rlc_circuit_square = compile_fmu("RLC_Circuit_Square",os.path.join(path_to_mofiles,"RLC_Circuit.mo"),target="cs", version="1.0") cls.no_state3 = compile_fmu("NoState.Example3",os.path.join(path_to_mofiles,"noState.mo"),target="cs", version="1.0") cls.simple_input = compile_fmu("Inputs.SimpleInput",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs", version="1.0") cls.simple_input2 = compile_fmu("Inputs.SimpleInput2",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs", version="1.0") cls.input_discontinuity = compile_fmu("Inputs.InputDiscontinuity",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs", version="1.0") cls.terminate = compile_fmu("Terminate",os.path.join(path_to_mofiles,"Terminate.mo"),target="cs", version="1.0") cls.assert_fail = compile_fmu("AssertFail",os.path.join(path_to_mofiles,"Terminate.mo"),target="cs", version="1.0") cls.initialize_solver = compile_fmu("Inputs.DiscChange",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs", version="1.0")
def setUp(self): """ Sets up the test case. """ fpath = os.path.join(path_to_mofiles,'RLC_Circuit.mo') fmuname = compile_fmu('RLC_Circuit',fpath) self._model = FMUModelME1(fmuname)
def setUpClass(self): """ Sets up the test class. """ self.fmu = compile_fmu('Parameter.Error.Structural', os.path.join(path_to_mofiles, 'ParameterTests.mo'), version="1.0")
def setUp(self): """ Sets up the test case. """ fpath = os.path.join(path_to_mofiles, 'RLC_Circuit.mo') fmuname = compile_fmu('RLC_Circuit', fpath) self._model = FMUModelME1(fmuname)
def setUpClass(cls): """ Sets up the test class. """ m = compile_fmu( 'LoggerTest', os.path.join(path_to_mofiles, 'LoggerTest.mo'), compiler_log_level='e', compiler_options={'generate_only_initial_system': True})
def setUpClass(cls): cname = 'DISTLib.Examples.Simulation' fname = os.path.join(get_files_path(), 'Modelica', 'DISTLib.mo') _fn_distlib = compile_fmu( cname, fname, compiler_options={'generate_ode_jacobian': True}, version="2.0alpha")
def setUpClass(cls): cname = 'Furuta' fname = os.path.join(get_files_path(), 'Modelica', 'furuta.mo') _fn_furuta = compile_fmu( cname, fname, compiler_options={'generate_ode_jacobian': True}, version="2.0alpha")
def test_simulate_no_state(self): name = compile_fmu("Modelica.Blocks.Examples.IntegerNetwork1", version = 2.0, compiler_options={"generate_ode_jacobian":True, "eliminate_alias_constants":False}) model = load_fmu(name) res = model.simulate(final_time=3) assert res.final("integerStep.y") == 3.0
def setUpClass(cls): cname = 'NonLinear.MultiSystems' fname = os.path.join(get_files_path(), 'Modelica', 'NonLinear.mo') _fn_nonlin = compile_fmu(cname, fname, compiler_options={ 'generate_ode_jacobian': True, 'fmi_version': 2.0 })
def setUpClass(cls): cname = 'NonLinear.MultiSystems' fname = os.path.join(get_files_path(), 'Modelica', 'NonLinear.mo') _fn_nonlin = compile_fmu(cname, fname, compiler_options={ 'generate_ode_jacobian': True, 'automatic_tearing': False }, version="2.0alpha")
def setUpClass(cls): cname = 'NonLinear.TwoSystems_wIO' fname = os.path.join(get_files_path(), 'Modelica', 'NonLinearIO.mo') fn_nonlinIO = compile_fmu(cname, fname, compiler_options={ 'generate_ode_jacobian': True, 'eliminate_alias_variables': False, 'fmi_version': 2.0 })
def test_assert_raises_sensitivity_parameters(self): """ This tests that an exception is raised if a sensitivity calculation is to be perfomed and the parameters are not contained in the model. """ fmu_name = compile_fmu('EventIter.EventMiddleIter', os.path.join(path_to_mos,'EventIter.mo')) model = load_fmu(fmu_name) opts = model.simulate_options() opts["sensitivities"] = ["hej", "hopp"] nose.tools.assert_raises(FMUException,model.simulate,0,1,(),'AssimuloFMIAlg',opts)
def setUpClass(cls): """ Sets up the test class. """ rlc_circuit = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo"),target="cs") rlc_circuit_square = compile_fmu("RLC_Circuit_Square",os.path.join(path_to_mofiles,"RLC_Circuit.mo"),target="cs") no_state3 = compile_fmu("NoState.Example3",os.path.join(path_to_mofiles,"noState.mo"),target="cs") simple_input = compile_fmu("Inputs.SimpleInput",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs") simple_input2 = compile_fmu("Inputs.SimpleInput2",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs") input_discontinuity = compile_fmu("Inputs.InputDiscontinuity",os.path.join(path_to_mofiles,"InputTests.mo"),target="cs")
def test_variable_alias(self): model_file = os.path.join(get_files_path(), 'Modelica', 'NegatedAlias.mo') name = compile_fmu("NegatedAlias", model_file) simple_alias = load_fmu(name) opts = simple_alias.simulate_options() opts["result_handling"] = "custom" opts["result_handler"] = ResultHandlerCSV(simple_alias) res = simple_alias.simulate(options=opts) # test that res['y'] returns a vector of the same length as the time # vector nose.tools.assert_equal(len(res['y']),len(res['time']), "Wrong size of result vector.") x = res["x"] y = res["y"] for i in range(len(x)): nose.tools.assert_equal(x[i], -y[i])
def setUpClass(cls): """ Sets up the test class. """ name = compile_fmu("NegatedAlias",os.path.join(path_to_mofiles,"NegatedAlias.mo")) name = compile_fmu('TablesTest.Table1DfromArray', os.path.join(path_to_mofiles,'TablesTests.mo'))
def setUpClass(cls): cname='DISTLib.Examples.Simulation' fname = os.path.join(get_files_path(), 'Modelica', 'DISTLib.mo') _fn_distlib = compile_fmu(cname, fname, compiler_options={'generate_ode_jacobian':True}, version="2.0alpha")
def setUpClass(cls): """ Sets up the test class. """ rlc_circuit = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo")) depPar1 = compile_fmu("DepParTests.DepPar1",os.path.join(path_to_mofiles,"DepParTests.mo"))
def setUpClass(cls): cname='NonLinear.TwoSystems_wIO' fname = os.path.join(get_files_path(), 'Modelica', 'NonLinearIO.mo') fn_nonlinIO = compile_fmu(cname, fname, compiler_options={'generate_ode_jacobian':True,'eliminate_alias_variables':False,'automatic_tearing':False}, version="2.0alpha")
def setUpClass(cls): """ Sets up the test class. """ m = compile_fmu('DependentParameterTest2',os.path.join(path_to_mofiles,'DependentParameterTest.mo'))
def setUpClass(cls): cname='NonLinear.MultiSystems' fname = os.path.join(get_files_path(), 'Modelica', 'NonLinear.mo') _fn_nonlin = compile_fmu(cname, fname, compiler_options={'generate_ode_jacobian':True,'automatic_tearing':False}, version="2.0alpha")
def setUpClass(cls): """ Compile the test model. """ file_name = os.path.join(get_files_path(), 'Modelica', 'RelationTests.mo') compile_fmu("RelationTests.RelationLE", file_name) compile_fmu("RelationTests.RelationGE", file_name) compile_fmu("RelationTests.RelationLEInv", file_name) compile_fmu("RelationTests.RelationGEInv", file_name) compile_fmu("RelationTests.RelationLEInit", file_name) compile_fmu("RelationTests.RelationGEInit", file_name) compile_fmu("RelationTests.TestRelationalOp1", file_name)
def setUpClass(cls): cname='Furuta' fname = os.path.join(get_files_path(), 'Modelica', 'furuta.mo') _fn_furuta = compile_fmu(cname, fname, compiler_options={'generate_ode_jacobian':True}, version="2.0alpha")
def setUp(self): """ Sets up the test class. """ self.fmu_name = compile_fmu(self._cpath, self._fpath) self.model = FMUModelME1(self.fmu_name)
def setUpClass(cls): """ Sets up the test class. """ m = compile_fmu('LoggerTest',os.path.join(path_to_mofiles,'LoggerTest.mo'),compiler_log_level='e', compiler_options={'generate_only_initial_system':True})
def setUpClass(cls): """ Sets up the test class. """ m = compile_fmu('InitTest1',os.path.join(path_to_mofiles,'InitTest.mo'))
def setUpClass(cls): cname='BlockOdeJacTest' fname = os.path.join(get_files_path(), 'Modelica', 'BlockOdeJacTest.mo') _fn_block = compile_fmu(cname, fname, compiler_options={'generate_ode_jacobian':True, 'automatic_tearing':False}, version="2.0alpha")
def setUpClass(cls): """ Compile the test model. """ file_name = os.path.join(get_files_path(), 'Modelica', 'EventIter.mo') compile_fmu("EventIter.EventInfiniteIteration1", file_name) compile_fmu("EventIter.EventInfiniteIteration2", file_name) compile_fmu("EventIter.EventInfiniteIteration3", file_name) compile_fmu("EventIter.EnhancedEventIteration1", file_name) compile_fmu("EventIter.EnhancedEventIteration2", file_name) compile_fmu("EventIter.SingularSystem1", file_name)