Changeset 13581
- Timestamp:
- Sep 24, 2019 8:44:55 AM (2 months ago)
- Location:
- PyFMI/branches/PyFMI-2.5.x
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
PyFMI/branches/PyFMI-2.5.x
- Property svn:mergeinfo changed
/PyFMI/trunk merged: 13434,13439,13464,13551,13571,13578
- Property svn:mergeinfo changed
-
PyFMI/branches/PyFMI-2.5.x/CHANGELOG
r13362 r13581 1 1 --- CHANGELOG --- 2 3 --- PyFMI-trunk --- 4 * Added option to specify if the variable descriptions should be 5 stored or not in the result file (ticket:5846) 6 * Fixed issue with estimating directional derivatives when the 7 structure info is not used and the matrix has zero dim (ticket:5836) 2 8 3 9 --- PyFMI-2.5.4 --- -
PyFMI/branches/PyFMI-2.5.x/setup.py
- Property svn:mergeinfo changed
/PyFMI/trunk/setup.py merged: 13434,13439
r13363 r13581 156 156 if not x.find('--version'): 157 157 VERSION = x[10:] 158 copy_args.remove(x) 159 if not x.find('--debug'): 160 if x[8:].upper() == "TRUE": 161 debug_flag = True 162 else: 163 debug_flag = False 158 164 copy_args.remove(x) 159 165 - Property svn:mergeinfo changed
-
PyFMI/branches/PyFMI-2.5.x/src/common
- Property svn:mergeinfo changed
/PyFMI/trunk/src/common merged: 13551
- Property svn:mergeinfo changed
-
PyFMI/branches/PyFMI-2.5.x/src/common/io.py
r13031 r13581 1726 1726 1727 1727 f.write('\n') 1728 1729 if not opts["result_store_variable_description"]: 1730 max_desc_length = 0 1731 descriptions = [[0,""] for d in descriptions] 1732 descs_sens = ["" for d in descs_sens] 1728 1733 1729 1734 # Write descriptions … … 2135 2140 len_name_items = len(sorted_vars)+1 2136 2141 len_desc_items = len_name_items 2137 """ 2138 name_data = ["time"] + [var.name for var in sorted_vars] 2139 desc_data = ["Time in [s]"] + [var.description for var in sorted_vars] 2140 2141 len_name_data, name_data = fmi_util.convert_str_list(name_data) 2142 len_desc_data, desc_data = fmi_util.convert_str_list(desc_data) 2143 """ 2142 2144 2143 len_name_data, name_data, len_desc_data, desc_data = fmi_util.convert_sorted_vars_name_desc(sorted_vars) 2145 2144 2146 2145 self._write_header("name", len_name_data, len_name_items, "char") 2147 2146 self.dump_native_data(name_data) 2147 2148 if not opts["result_store_variable_description"]: 2149 len_desc_data = 1 2150 desc_data = encode(" "*len_desc_items) 2151 2148 2152 self._write_header("description", len_desc_data, len_desc_items, "char") 2149 2153 self.dump_native_data(desc_data) -
PyFMI/branches/PyFMI-2.5.x/src/pyfmi
- Property svn:mergeinfo changed
/PyFMI/trunk/src/pyfmi merged: 13434,13551,13571,13578
- Property svn:mergeinfo changed
-
PyFMI/branches/PyFMI-2.5.x/src/pyfmi/fmi.pyx
r13365 r13581 533 533 self.file_object = None 534 534 535 cdef _logger(self, FMIL.jm_string module, int log_level, FMIL.jm_string message) with gil: 535 cdef _logger(self, FMIL.jm_string c_module, int log_level, FMIL.jm_string c_message) with gil: 536 module = decode(c_module) 537 message = decode(c_message) 538 536 539 if self._additional_logger: 537 540 self._additional_logger(module, log_level, message) … … 7802 7805 A = output_matrix 7803 7806 7807 if len_v == 0 or len_f == 0: 7808 return A 7809 7804 7810 dfpert = N.zeros(len_f, dtype = N.double) 7805 7811 for i in range(len_v): -
PyFMI/branches/PyFMI-2.5.x/src/pyfmi/fmi_algorithm_drivers.py
r13066 r13581 116 116 into memory after the simulation finishes. 117 117 Default: True 118 119 result_store_variable_description -- 120 Determines if the description for the variables should be 121 stored in the result file or not. Only impacts the result 122 file formats that supports storing the variable description 123 ("file" and "binary"). 124 Default: True 118 125 119 126 filter -- … … 169 176 'result_handler': None, 170 177 'return_result': True, 178 'result_store_variable_description': True, 171 179 'filter':None, 172 180 'extra_equations':None, … … 616 624 into memory after the simulation finishes. 617 625 Default: True 626 627 result_store_variable_description -- 628 Determines if the description for the variables should be 629 stored in the result file or not. Only impacts the result 630 file formats that supports storing the variable description 631 ("file" and "binary"). 632 Default: True 618 633 619 634 time_limit -- … … 644 659 'result_handling':"binary", 645 660 'result_handler': None, 661 'result_store_variable_description': True, 646 662 'return_result': True, 647 663 'time_limit': None, -
PyFMI/branches/PyFMI-2.5.x/tests/test_fmi.py
r13365 r13581 458 458 459 459 class Test_FMUModelME2: 460 461 @testattr(stddist = True) 462 def test_estimate_directional_derivatives_without_structure_info(self): 463 full_path = os.path.join(file_path, "files", "FMUs", "XML", "ME2.0", "BouncingBall.fmu") 464 model = Dummy_FMUModelME2([], full_path, _connect_dll=False) 465 466 def f(*args, **kwargs): 467 derh = model.values[model.variables["v"].value_reference] 468 derv = -9.81 469 model.values[model.variables["der(h)"].value_reference] = derh 470 return np.array([derh, derv]) 471 model.get_derivatives = f 472 473 model.initialize() 474 model.event_update() 475 model.enter_continuous_time_mode() 476 477 [As, Bs, Cs, Ds] = model.get_state_space_representation(use_structure_info=False) 478 [A, B, C, D] = model.get_state_space_representation() 479 480 assert As.shape == A.shape, str(As.shape)+' '+str(A.shape) 481 assert Bs.shape == B.shape, str(Bs.shape)+' '+str(B.shape) 482 assert Cs.shape == C.shape, str(Cs.shape)+' '+str(C.shape) 483 assert Ds.shape == D.shape, str(Ds.shape)+' '+str(D.shape) 484 485 assert np.allclose(As, A.toarray()), str(As)+' '+str(A.toarray()) 486 assert np.allclose(Bs, B.toarray()), str(Bs)+' '+str(B.toarray()) 487 assert np.allclose(Cs, C.toarray()), str(Cs)+' '+str(C.toarray()) 488 assert np.allclose(Ds, D.toarray()), str(Ds)+' '+str(D.toarray()) 489 460 490 @testattr(stddist = True) 461 491 def test_estimate_directional_derivatives_BCD(self): … … 484 514 B = func(use_structure_info=True, output_matrix=A) 485 515 assert A is B #Test that the returned matrix is actually the same as the input 486 np.allclose(A.toarray(),B.toarray())516 assert np.allclose(A.toarray(),B.toarray()) 487 517 A = func(use_structure_info=False) 488 518 B = func(use_structure_info=False, output_matrix=A) 489 519 assert A is B 490 np.allclose(A,B)520 assert np.allclose(A,B) 491 521 C = func(use_structure_info=True, output_matrix=A) 492 522 assert A is not C 493 np.allclose(C.toarray(), A)523 assert np.allclose(C.toarray(), A) 494 524 D = func(use_structure_info=False, output_matrix=C) 495 525 assert D is not C 496 np.allclose(D, C.toarray())526 assert np.allclose(D, C.toarray()) 497 527 498 528 B = model._get_B(use_structure_info=True) … … 500 530 D = model._get_D(use_structure_info=True) 501 531 502 np.allclose(B.toarray(), np.array([[0.0],[0.0]]))503 np.allclose(C.toarray(), np.array([[0.0, 0.0],[0.0, 1.0], [1.0, 0.0]]))504 np.allclose(D.toarray(), np.array([[-1.0],[0.0], [1.0]]))532 assert np.allclose(B.toarray(), np.array([[0.0],[0.0]])) 533 assert np.allclose(C.toarray(), np.array([[0.0, 0.0],[0.0, 1.0], [1.0, 0.0]])) 534 assert np.allclose(D.toarray(), np.array([[-1.0],[0.0], [1.0]])) 505 535 506 536 B = model._get_B(use_structure_info=False) … … 508 538 D = model._get_D(use_structure_info=False) 509 539 510 np.allclose(B, np.array([[0.0],[0.0]]))511 np.allclose(C, np.array([[0.0, 0.0],[0.0, 1.0], [1.0, 0.0]]))512 np.allclose(D, np.array([[-1.0],[0.0], [1.0]]))540 assert np.allclose(B, np.array([[0.0],[0.0]])) 541 assert np.allclose(C, np.array([[0.0, 0.0],[0.0, 1.0], [1.0, 0.0]])) 542 assert np.allclose(D, np.array([[-1.0],[0.0], [1.0]])) 513 543 514 544 @testattr(stddist = True) … … 535 565 [state_dep, input_dep] = model.get_output_dependencies() 536 566 537 assert len(state_dep.keys()) == 0 538 assert len(input_dep.keys()) == 0 567 assert len(state_dep.keys()) == 0, len(state_dep.keys()) 568 assert len(input_dep.keys()) == 0, len(input_dep.keys()) 539 569 540 570 @testattr(stddist = True) … … 546 576 [state_dep, input_dep] = model.get_derivatives_dependencies() 547 577 548 assert len(state_dep.keys()) == 0 549 assert len(input_dep.keys()) == 0 578 assert len(state_dep.keys()) == 0, len(state_dep.keys()) 579 assert len(input_dep.keys()) == 0, len(input_dep.keys()) 550 580 551 581 @testattr(stddist = True) … … 566 596 model = FMUModelME2("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) 567 597 568 assert model.get_variable_unit("J1.w") == "rad/s" 569 assert model.get_variable_unit("J1.phi") == "rad" 598 assert model.get_variable_unit("J1.w") == "rad/s", model.get_variable_unit("J1.w") 599 assert model.get_variable_unit("J1.phi") == "rad", model.get_variable_unit("J1.phi") 570 600 571 601 nose.tools.assert_raises(FMUException, model.get_variable_unit, "clutch1.useHeatPort") … … 577 607 model = FMUModelME2("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) 578 608 579 assert model.get_variable_display_unit("J1.phi") == "deg" 609 assert model.get_variable_display_unit("J1.phi") == "deg", model.get_variable_display_unit("J1.phi") 580 610 nose.tools.assert_raises(FMUException, model.get_variable_display_unit, "J1.w") 581 611 … … 595 625 596 626 enum = model.get_variable_declared_type("x") 597 assert len(enum.items.keys()) == 2 627 assert len(enum.items.keys()) == 2, len(enum.items.keys()) 598 628 enum = model.get_variable_declared_type("home") 599 assert len(enum.items.keys()) == 4 629 assert len(enum.items.keys()) == 4, len(enum.items.keys()) 600 630 601 631 nose.tools.assert_raises(FMUException, model.get_variable_declared_type, "z") … … 635 665 for var in vars: 636 666 [r,i,b] = model.get_model_time_varying_value_references(filter=var) 637 assert len(r) == 1 667 assert len(r) == 1, len(r) 638 668 639 669 [r,i,b] = model.get_model_time_varying_value_references(filter=list(vars.keys())) 640 assert len(r) == 1 670 assert len(r) == 1, len(r) 641 671 642 672 @testattr(stddist = True) … … 704 734 sc_x = negated_alias.get_scalar_variable("x") 705 735 706 assert sc_x.name == "x" 707 assert sc_x.value_reference >= 0 708 assert sc_x.type == fmi.FMI2_REAL 709 assert sc_x.variability == fmi.FMI2_CONTINUOUS 710 assert sc_x.causality == fmi.FMI2_LOCAL 736 assert sc_x.name == "x", sc_x.name 737 assert sc_x.value_reference >= 0, sc_x.value_reference 738 assert sc_x.type == fmi.FMI2_REAL, sc_x.type 739 assert sc_x.variability == fmi.FMI2_CONTINUOUS, sc_x.variability 740 assert sc_x.causality == fmi.FMI2_LOCAL, sc_x.causality 711 741 712 742 nose.tools.assert_raises(FMUException, negated_alias.get_scalar_variable, "not_existing") … … 725 755 model = FMUModelME1("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) 726 756 727 assert model.get_name() == "CoupledClutches" 757 assert model.get_name() == "CoupledClutches", model.get_name() 728 758 729 759 @testattr(stddist = True) … … 732 762 model = FMUModelCS1("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "CS1.0"), _connect_dll=False) 733 763 734 assert model.get_name() == "CoupledClutches" 764 assert model.get_name() == "CoupledClutches", model.get_name() 735 765 736 766 @testattr(stddist = True) … … 739 769 model = FMUModelME2("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False) 740 770 741 assert model.get_name() == "CoupledClutches" 771 assert model.get_name() == "CoupledClutches", model.get_name() 742 772 743 773 @testattr(stddist = True) … … 746 776 model = FMUModelCS2("CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "CS2.0"), _connect_dll=False) 747 777 748 assert model.get_name() == "CoupledClutches" 778 assert model.get_name() == "CoupledClutches", model.get_name() -
PyFMI/branches/PyFMI-2.5.x/tests/test_io.py
r13031 r13581 151 151 152 152 @testattr(stddist = True) 153 def test_description_not_stored(self): 154 model = Dummy_FMUModelME1([], "CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) 155 model.initialize() 156 157 opts = model.simulate_options() 158 opts["result_store_variable_description"] = False 159 160 result_writer = ResultHandlerFile(model) 161 result_writer.set_options(opts) 162 result_writer.simulation_start() 163 result_writer.initialize_complete() 164 result_writer.integration_point() 165 result_writer.simulation_end() 166 167 res = ResultDymolaTextual('CoupledClutches_result.txt') 168 169 assert res.description[res.get_variable_index("J1.phi")] == "", "Description is not empty, " + res.description[res.get_variable_index("J1.phi")] 170 171 @testattr(stddist = True) 153 172 def test_get_description_unicode(self): 154 173 model = Dummy_FMUModelME1([], "Description.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) … … 428 447 429 448 @testattr(stddist = True) 449 def test_description_not_stored(self): 450 model = Dummy_FMUModelME1([], "CoupledClutches.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False) 451 model.initialize() 452 453 opts = model.simulate_options() 454 opts["result_store_variable_description"] = False 455 456 result_writer = ResultHandlerBinaryFile(model) 457 result_writer.set_options(opts) 458 result_writer.simulation_start() 459 result_writer.initialize_complete() 460 result_writer.integration_point() 461 result_writer.simulation_end() 462 463 res = ResultDymolaBinary('CoupledClutches_result.mat') 464 465 assert res.description[res.get_variable_index("J1.phi")] == "", "Description is not empty, " + res.description[res.get_variable_index("J1.phi")] 466 467 @testattr(stddist = True) 430 468 def test_read_all_variables(self): 431 469 res = ResultDymolaBinary(os.path.join(file_path, "files", "Results", "DoublePendulum.mat"))
Note: See TracChangeset
for help on using the changeset viewer.