Esempio n. 1
0
def test_external_if_statement(solver, use_llvm):
    model_ = model.Model(IfSystem('m_system', EqTest('tm1'),EqTest('tm2'),EqTest('tm3')), use_llvm=use_llvm)
    s = simulation.Simulation(model_, solver_type=solver, t_start=0, t_stop=1.0, num=1, num_inner=1)
    s.solve()
    expected = 7
    assert s.model.historian_df['m_system.tm1.test_nm.Y'][1] == expected
    assert s.model.historian_df['m_system.tm2.test_nm.Y'][1] == expected
    assert s.model.historian_df['m_system.tm3.test_nm.Y'][1] == expected
Esempio n. 2
0
def test_external_if_statement(solver, use_llvm):
    model_ = model.Model(IfSystem('if_system', IfTest('tm1')), use_llvm=use_llvm,
                         imports=[("external_import_else_if", "h_test")])
    s = simulation.Simulation(model_, solver_type=solver, t_start=0, t_stop=10.0, num=10, num_inner=10)
    s.solve()
    expected_ti1 = 106
    expected_ti4 = 1
    assert s.model.historian_df['if_system.tm1.test_nm.T_i1'][1] == expected_ti1
    assert s.model.historian_df['if_system.tm1.test_nm.T_i4'][1] == expected_ti4
Esempio n. 3
0
def test_external_mapping(solver, use_llvm):
    model_ = model.Model(DynamicDataSystem('system'),
                         imports=[("external_data_functions", "h_test")],
                         use_llvm=use_llvm)
    s = simulation.Simulation(model_,
                              solver_type=solver,
                              t_start=0,
                              t_stop=10.0,
                              num=10,
                              num_inner=10)
    s.solve()
    expected = 106.0
    assert s.model.historian_df['system.tm1.test_nm.T_i1'][1] == expected
Esempio n. 4
0
def test_external_if_statement_if_else_executed(solver, use_llvm):
    model_ = model.Model(IfSystem('if_system2', IfTest3('tm1')),
                         use_llvm=use_llvm)
    s = simulation.Simulation(model_,
                              solver_type=solver,
                              t_start=0,
                              t_stop=10.0,
                              num=10,
                              num_inner=10)
    s.solve()
    expected_ti4 = 1
    assert s.model.historian_df['if_system2.tm1.test_nm.T_i4'][
        1] == expected_ti4
def test_simple_set_model(solver, use_llvm):
    n = 100
    subsystem = SimpleSystem('system', k=.1, n=n, x0=[0] * n)

    s = simulation.Simulation(model.Model(subsystem, use_llvm=use_llvm),
                              t_start=0,
                              t_stop=1,
                              num=100,
                              num_inner=100,
                              max_step=1,
                              solver_type=solver)
    # Solve and plot
    s.solve()
    for i in range(n):
        assert approx(s.model.historian_df['system.SET_simples.simple'+ str(i) +'.mechanics.x'][100], rel=0.01) ==\
               s.model.historian_df['system.SET_simples.simple' + str(i) + '.mechanics.k'][100]
Esempio n. 6
0
        ("Dew Point Temperature {C}", InterpolationType.PIESEWISE),
        'system.tm0.test_nm.T2':
        ('Dry Bulb Temperature {C}', InterpolationType.LINEAR)
    }
    external_mappings.append(
        ExternalMappingElement(malmo_sturup_data_frame,
                               index_to_timestep_mapping,
                               index_to_timestep_mapping_start,
                               time_multiplier, dataframe_aliases))
    history_file = "test.csv"
    if os.path.exists(history_file):
        os.remove(history_file)
    histr = LocalHistorian(history_file, 1000)
    # histr = InMemoryHistorian()
    model = model.Model(StaticDataSystem('system', n=1),
                        external_mappings=external_mappings,
                        data_loader=LocalDataLoader(chunksize=None),
                        historian=histr)
    s = simulation.Simulation(model,
                              t_start=0,
                              t_stop=10000.0,
                              num=10000,
                              num_inner=100,
                              max_step=.1)

    # Solve and plot
    tic = time()
    s.solve()
    toc = time()
    historian_df = pandas.read_csv(history_file)
    # historian_df =s.model.historian_df
    print('Execution time: ', toc - tic)
Esempio n. 7
0
def test_external_if_statement_cycle_dependancy(solver, use_llvm):
    model_ = model.Model(IfSystem('if_system3', IfTest4('tm1')), use_llvm=use_llvm)
    s = simulation.Simulation(model_, solver_type=solver, t_start=0, t_stop=10.0, num=10, num_inner=10)
    s.solve()
Esempio n. 8
0
                            tag="conductors",
                            structure=ItemsStructure.SET)


#def test_mapping():
if __name__ == '__main__':

    from numerous.engine import model, simulation
    from time import time
    import numpy as np
    n = 2
    T0 = [150, 50]
    subsystem = ThermalSystem('system', n=n, T0=T0)
    # Define simulation
    n = 100
    s = simulation.Simulation(model.Model(subsystem),
                              t_start=0,
                              t_stop=500.0,
                              num=n,
                              num_inner=1,
                              max_step=1000)
    # Solve and plot

    time_ = np.logspace(0, 4, n)
    s.reset()

    t_last = 0
    tic = time()
    for t_ in time_:
        #print('time: ',t_)
        stop = s.step(t_ - t_last)
Esempio n. 9
0
            self.register_items([spc3, te])


if __name__ == "__main__":
    from numerous.engine import model, simulation
    from time import time
    from matplotlib import pyplot as plt

    subsystem = OscillatorSystem('system',
                                 k=0.01,
                                 c=0.001,
                                 a=0,
                                 n=2,
                                 x0=[1, 2, 3])
    # Define simulation
    s = simulation.Simulation(model.Model(subsystem, use_llvm=False),
                              t_start=0,
                              t_stop=500.0,
                              num=1000,
                              num_inner=100,
                              max_step=1)
    # Solve and plot
    tic = time()
    s.solve()
    toc = time()
    print('Execution time: ', toc - tic)

    s.model.historian_df[[
        'system.SET_oscillators.oscillator0.mechanics.x',
        'system.SET_oscillators.oscillator1.mechanics.x'
    ]].plot()