Model and ModelProxy¶
Model¶
- class simu.Model¶
Bases:
ABCThis is the base class for all process models to be implemented.
By deriving from this class, handler objects are available as class attributes to deal with the particular aspects. Visit their documentation for details.
The model implementation is then divided into two parts: (a) the interface, and (b) the model implementation itself. These parts are represented by the two methods
interface()anddefine()respectively.A model is then either instantiated by a parent model, whereas it is represented in that parent model by a
ModelProxyobject, or it can be defined as the top level model by callingtop().- __init__()¶
The constructor is parameterless but still needs to be called by the subclass constructors (if implemented) to initialise the object. Defining a constructor for the subclasses can be useful to pass custom data into the model.
- parameters: ParameterHandler¶
The handler object that takes care of parameter configuration
- properties: PropertyHandler¶
The handler object that takes care of property configuration
- materials: MaterialHandler¶
The handler object that takes care of materials
- hierarchy: HierarchyHandler¶
The handler object that takes care of defining sub models
- residuals: ResidualHandler = None¶
The handler object that takes care of residuals
- bounds: BoundHandler = None¶
The handler object that takes care of domain boundaries
- classmethod top(name: str = 'model') ModelProxy¶
Define this model as top level model, hence instantiate, create proxy, and finalise it.
This is the recommended and fastest way to declare a model as being the top level model. It will create a proxy object (via
proxy()) and finalise the configuration of it viasimu.core.model.base.ModelProxy.finalise().Performing the finalisation in one go after creating the proxy object is only possible, if the model is suitable to be top model. That is, it must not have material ports or parameters to be connected.
- Parameters:
name (str) – The name of the top level model
- Returns:
The readily configured
ModelProxyobject
- classmethod proxy(name: str = 'model') ModelProxy¶
Instantiate and create proxy of this model.
This is a helper method called by the
HierarchyHandlerwhen defining a child model. After the proxy class is generated, the parent model can connect materials and provide parameters. When that is done, the proxy object can be finalised.- Parameters:
name (str) – The name of the top level model
- Returns:
The
ModelProxyobject, ready for configuration from parent context. It then still needs to be finalised.
- interface() None¶
This virtual method is to define all model parameters, material ports, and properties provided by this model. This makes the interface of the model in the hierarchical context nearly self-documenting. A simple example implementation could be
def interface(self): """Here a nice documentation of the model interface""" self.parameters.define("length", 10.0, "m") self.properties.provide("area", unit="m**2")
Above interface requires a parameter called
lengthwith a default value of 10 metres. It promises to calculate a property calledareawhich has a unit compatible to square metres.
- abstractmethod define() None¶
This abstract method is to define the model implementation, including the use of submodules, creation of internal materials, and calculation of residuals and model properties. Matching to the example described in the
interface()method, a simple implementation could bedef define(self): """Here documentation of the internal function of the model. This distinction can be used to include this doc-string only for detailed documentation sections.""" length = self.parameters["length"] self.properties["area"] = length * length
Here we read out the previously defined parameter
lengthand calculate the propertyarea.
- create_proxy(name: str = 'model') ModelProxy¶
Create a proxy object for configuration in hierarchy context. This is the instance variant of the
proxy()class method.
ModelProxy¶
- class simu.core.model.base.ModelProxy¶
Proxy class for models, being main object to relate to when accessing a child model during definition of the parent model.
As for the
Modelclass, this proxy version offers via its handlers functionality to deal with parameters, properties, hierarchy, materials, and residuals, but the angle of view is different:The
Modelclass deals with the implementation of the model, while theModelProxyclass offers its access to connect to it as a client. This client is most likely a parentModelor, if it is a top level model, aNumericHandlerobject.ModelProxyobjects are created from within theModelclass, and do not need to be instantiated directly by SiMu client code.- parameters: ParameterProxy¶
The proxy of the parameter handler, to connect and update parameters
- properties: PropertyProxy¶
The proxy of the property handler, making properties available
- hierarchy: HierarchyProxy¶
The proxy of the hierarchy handler, to parametrise child models
- materials: MaterialProxy¶
The proxy of the material handler, to connect material ports
- residuals: Mapping[str, Residual]¶
A handler object that takes care of residuals. This is really just a non-mutable mapping of residuals, as the client code is not supposed to temper with the definition of the child model. The residuals are still browsable, as required for instance by the
NumericHandlerobject for obvious reasons.
- bounds: Mapping[str, Quantity]¶
The non-mutable proxy of the bound handler, to be queried by the
NumericHandler.
AModel¶
- class simu.AModel¶
-
This is a wrapper class of
Modelto enable short notations for common method calls, and by that allowing to shorten the syntax when creating models, while still keeping the underlying structure.The abbreviations are given in the following table:
Abbreviation
… resolves to
pa
pad
pas
pr
prd
h
hd
ha
m
md
mcf
mcs
r
ra
b
ba
- __init__()¶
The constructor is parameterless but still needs to be called by the subclass constructors (if implemented) to initialise the object. Defining a constructor for the subclasses can be useful to pass custom data into the model.
- create_proxy(name: str = 'model') AModelProxy¶
Create a proxy object for configuration in hierarchy context. By redefining
Model.create_proxy, instances ofAModelalso generateAModelProxyobjects when being exposed in parent model context.
AModelProxy¶
- class simu.core.model.amodel.AModelProxy¶
This is a wrapper class of
ModelProxyto enable short notations for common method calls, and by that allowing to shorten the syntax when creating models, while still keeping the underlying structure.The abbreviations are given in the following table:
Abbreviation
… resolves to
pa
pap
pau
pr
h
m
mc
mcm
r
b