Changeset 13551


Ignore:
Timestamp:
Sep 20, 2019 10:07:45 AM (3 months ago)
Author:
Christian Andersson
Message:

Added option to store or not store the variable descriptions. Related to ticket:5846

Location:
PyFMI/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • PyFMI/trunk/CHANGELOG

    r13434 r13551  
    22
    33--- PyFMI-trunk ---
     4    * Added option to specify if the variable descriptions should be
     5      stored or not in the result file (ticket:5846)
    46    * Fixed issue with estimating directional derivatives when the
    57      structure info is not used and the matrix has zero dim (ticket:5836)
  • PyFMI/trunk/src/common/io.py

    r13026 r13551  
    17261726
    17271727        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]
    17281733
    17291734        # Write descriptions       
     
    21352140        len_name_items = len(sorted_vars)+1
    21362141        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       
    21442143        len_name_data, name_data, len_desc_data, desc_data = fmi_util.convert_sorted_vars_name_desc(sorted_vars)
    21452144       
    21462145        self._write_header("name", len_name_data, len_name_items, "char")
    21472146        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       
    21482152        self._write_header("description", len_desc_data, len_desc_items, "char")
    21492153        self.dump_native_data(desc_data)
  • PyFMI/trunk/src/pyfmi/fmi_algorithm_drivers.py

    r13065 r13551  
    116116            into memory after the simulation finishes.
    117117            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            Default: True
    118124
    119125        filter --
     
    169175            'result_handler': None,
    170176            'return_result': True,
     177            'result_store_variable_description': True,
    171178            'filter':None,
    172179            'extra_equations':None,
     
    616623            into memory after the simulation finishes.
    617624            Default: True
     625       
     626        result_store_variable_description --
     627            Determines if the description for the variables should be
     628            stored in the result file or not. Only impacts the result
     629            file formats that supports storing the variable description.
     630            Default: True
    618631           
    619632        time_limit --
     
    644657            'result_handling':"binary",
    645658            'result_handler': None,
     659            'result_store_variable_description': True,
    646660            'return_result': True,
    647661            'time_limit': None,
  • PyFMI/trunk/tests/test_io.py

    r13026 r13551  
    151151   
    152152    @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")] == ""
     170   
     171    @testattr(stddist = True)
    153172    def test_get_description_unicode(self):
    154173        model = Dummy_FMUModelME1([], "Description.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME1.0"), _connect_dll=False)
     
    428447   
    429448    @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")] == ""
     466   
     467    @testattr(stddist = True)
    430468    def test_read_all_variables(self):
    431469        res = ResultDymolaBinary(os.path.join(file_path, "files", "Results", "DoublePendulum.mat"))
Note: See TracChangeset for help on using the changeset viewer.