Opened 7 years ago

Closed 6 years ago

#2864 closed enhancement (fixed)

Change result handling in PyFMI

Reported by: Christian Andersson Owned by: Christian Andersson
Priority: major Milestone: PyFMI-1.3
Component: PyFMI Version: trunk
Keywords: Cc:

Description (last modified by Christian Andersson)

There has been suggestions or need for improvement of how the result is handled when performing a simulation.

The result handling should be able to directly store the result in memory for instance, should be able to store a subset of the variables and there should be an option for providing a custom result handler.

A suggestion is to base all result handling on a base class:

class ResultHandler:

    def simulation_start(self):
        """
        This method is called before the simulation has started and 
        before the initialization call for the FMU.
        """
        pass
        
    def initialize_complete(self):
        """ 
        This method is called after the initialization method of the FMU
        has been been called.
        """
        pass
        
    def integration_point(self, solver=None):
        """ 
        This method is called for each time-point for which result are
        to be stored as indicated by the "number of communcation points"
        provided to the simulation method.
        """
        pass
        
    def simulation_end(self):
        """
        This method is called at the end of a simulation.
        """
        pass
    
    def set_options(self, options):
        """
        Options are the options dictionary provided to the simulation
        method and this method is called before simulation start.
        """
        pass
        
    def get_result(self):
        """
        Method for retrieving the result. This method should return a 
        result of an instance of ResultStorage or of an instance of a 
        subclass of ResultStorage.
        """
        raise NotImplementedError

Note that I believe that the set_filter method is not needed as we need anyway to provide the options dictionary before the simulation starts, to get for instance the file_name if that has been specified. During this method we could also access the filter from the options.

Note 2 - I believe the arguments to store_point etc are unnecessary. The model can be stored internally via the start method and the argument t, y to the store_point method is also unnecessary as they also can be retrieved from the model as the model is up-to-date at the time store point is called.

Note 3 - For the cases when a solver is available, when simulating Model Exchange models, it would be convenient to have access to the solver as well. For Co-Simulation there is no solver. (Modified store_point)

Note 4 - Updated the proposal.

We need also to specify a base class for "using" the result

class ResultStorage:
    pass

dealt with in ticket:2889

and to change the simulation options with the following options

opts["result_handling"] = ["file", "memory", "custom"]
opts["result_handler"] = MyCustomResultHandler() (Inherits from ResultHandler)

opts["filter"] = "*der"

The filter should be based on http://en.wikipedia.org/wiki/Glob_%28programming%29

Change History (10)

comment:1 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:2 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:3 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:4 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:5 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:6 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:7 Changed 7 years ago by Christian Andersson

Description: modified (diff)

comment:8 Changed 7 years ago by Christian Andersson

changeset:4836

Updated the result handling in pyfmi as discussed in ticket:2864. Added an option to store the result in memory, related to ticket:2813. Additionally added an option to filter the result variables, related to ticket:2828

comment:9 Changed 7 years ago by Christian Andersson

changeset:4837

Updated the result handling to fix problems when using FMI2. Related to ticket:2864

comment:10 Changed 6 years ago by Christian Andersson

Resolution: fixed
Status: newclosed

This is considered good enough for now.

Note: See TracTickets for help on using tickets.