Exemplo n.º 1
0
        raise ValueError
    uneliminable = []
    #~ uneliminable = ['plant.sigma']
    #~ uneliminable = ['plant.sigma', 'der(plant.evaporator.alpha)']
    caus_opts = sp.CausalizationOptions()
    caus_opts['linear_solver'] = linear_solver
    caus_opts['solve_blocks'] = True

    if source != "Modelica":
        raise ValueError
    class_name = "CombinedCycleStartup.Startup6Reference"
    file_paths = (os.path.join(get_files_path(), "CombinedCycle.mo"),
                  os.path.join(get_files_path(), "CombinedCycleStartup.mop"))
    init_res = ResultDymolaTextual('ccpp_init.txt')
    opts = {'generate_html_diagnostics': True}
    model = transfer_model(class_name, file_paths, compiler_options=opts)
    model = sp.BLTModel(model, caus_opts)

    # Get model variable vectors
    model.calculateValuesForDependentParameters()
    var_kinds = {
        'dx': model.DERIVATIVE,
        'x': model.DIFFERENTIATED,
        'w': model.REAL_ALGEBRAIC
    }
    mvar_vectors = {
        'dx':
        N.array([
            var for var in model.getVariables(var_kinds['dx'])
            if not var.isAlias()
        ]),
Exemplo n.º 2
0
     if source == "strings":
         eqs_str = ['$x + y = 2$', '$x = 1$']
         varis_str = ['$x$', '$y$']
         edg_indices = [(0, 0), (0, 1), (1, 0)]
     else:
         class_name = "Simple"
         file_paths = "simple.mop"
         #~ opts = {'eliminate_alias_variables': False, 'generate_html_diagnostics': True, 'index_reduction': False,
         #~ 'equation_sorting': False, 'automatic_add_initial_equations': False}
         #~ opts = {'eliminate_alias_variables': False, 'generate_html_diagnostics': True, 'inline_functions': 'none'}
         opts = {
             'eliminate_alias_variables': False,
             'generate_html_diagnostics': True
         }
         model = transfer_model(class_name,
                                file_paths,
                                compiler_options=opts)
         init_fmu = load_fmu(
             compile_fmu(class_name, file_paths, compiler_options=opts))
 elif problem == "circuit":
     caus_opts['tearing'] = True
     caus_opts['tear_vars'] = ['i3']
     caus_opts['tear_res'] = [8]
     #~ caus_opts['analyze_var'] = 'u2'
     start_time = 0.
     final_time = 100.
     input = lambda t: []
     if source == "strings":
         eqs_str = [
             '$u_0 = \sin(t)$', '$u_1 = R_1 \cdot i_1$',
             '$u_2 = R_2 \cdot i_2$', '$u_2 = R_3 \cdot i_3$',
Exemplo n.º 3
0
#~ caus_opts['solve_blocks'] = True
#~ caus_opts['inline'] = False
#~ caus_opts['closed_form'] = True
caus_opts['dense_tol'] = 1e10
#~ caus_opts['inline_solved'] = True

#~ sim_res = ResultDymolaTextual(os.path.join(get_files_path(), "vehicle_turn_dymola.txt"))
sim_res = ResultDymolaTextual("opt_asphalt.txt")
start_time = 0.
final_time = sim_res.get_variable_data('time').t[-1]
ncp = 500
ncp = 0
class_name = "Car"
file_paths = "st_wf.mop"
opts = {'generate_html_diagnostics': True, 'state_initial_equations': True}
model = transfer_model(class_name, file_paths, compiler_options=opts)
grad_model = transfer_model("Car", file_paths, compiler_options=opts)
init_fmu = load_fmu(compile_fmu(class_name, file_paths, compiler_options=opts))

# Create input data
# This would have worked if one input was not constant...
#~ columns = [0]
#~ columns += [sim_res.get_column(input_var.getName()) for input_var in model.getVariables(model.REAL_INPUT)]
#~ input = sim_res.get_data_matrix()[:, columns]

input_matrix = sim_res.get_variable_data("time").x.reshape([-1, 1])
for input_var in model.getVariables(model.REAL_INPUT):
	input_data = sim_res.get_variable_data(input_var.getName()).x.reshape([-1, 1])
	if len(input_data) <= 2:
		input_data = np.array(input_matrix.shape[0] * [input_data[-1]]).reshape([-1, 1])
	input_matrix = np.hstack([input_matrix, input_data])
Exemplo n.º 4
0
     start_time = 0.0
     final_time = 2.0
     input = lambda t: []
     ncp = 500
     if source == "strings":
         eqs_str = ["$x + y = 2$", "$x = 1$"]
         varis_str = ["$x$", "$y$"]
         edg_indices = [(0, 0), (0, 1), (1, 0)]
     else:
         class_name = "Simple"
         file_paths = "simple.mop"
         # ~ opts = {'eliminate_alias_variables': False, 'generate_html_diagnostics': True, 'index_reduction': False,
         # ~ 'equation_sorting': False, 'automatic_add_initial_equations': False}
         # ~ opts = {'eliminate_alias_variables': False, 'generate_html_diagnostics': True, 'inline_functions': 'none'}
         opts = {"eliminate_alias_variables": False, "generate_html_diagnostics": True}
         model = transfer_model(class_name, file_paths, compiler_options=opts)
         init_fmu = load_fmu(compile_fmu(class_name, file_paths, compiler_options=opts))
 elif problem == "circuit":
     caus_opts["tearing"] = True
     caus_opts["tear_vars"] = ["i3"]
     caus_opts["tear_res"] = [8]
     # ~ caus_opts['analyze_var'] = 'u2'
     start_time = 0.0
     final_time = 100.0
     input = lambda t: []
     if source == "strings":
         eqs_str = [
             "$u_0 = \sin(t)$",
             "$u_1 = R_1 \cdot i_1$",
             "$u_2 = R_2 \cdot i_2$",
             "$u_2 = R_3 \cdot i_3$",