Documentation
¶
Overview ¶
Package fmi reads Functional Mock-up Units: the modelDescription.xml of an .fmu archive as a Description, and the `tool:fmi` analysis engine that computes a ToolExecution-annotated calc or action by handing the FMU to the runner OPENSYSML_FMI_RUNNER names. The package never runs the FMU's native code itself; the runner is the operator's grant of that execution.
Index ¶
- Constants
- Variables
- func FileURI(path string) string
- func New(look func() (string, error)) analysis.Manifested
- type BaseUnit
- type Causality
- type Description
- type Dimension
- type Experiment
- type Interface
- type Kind
- type ModelDescriptionError
- type RunnerError
- type Unit
- type UnsupportedVersionError
- type Variability
- type Variable
- type VariableError
- type Version
Constants ¶
const Exchange = "fmi/1"
Exchange names the request/reply protocol the engine and the runner speak, as an engine listing reports it.
const RunnerEnv = "OPENSYSML_FMI_RUNNER"
RunnerEnv names the environment variable holding the FMI runner: an executable name looked up on PATH or a path, exactly as OPENSYSML_SMT names the solver. Setting it is the operator's grant of execution: the runner instantiates an FMU's native code, which nothing in the build checks. Unset, the engine registers and refuses every question through Covers.
Variables ¶
var ErrModelDescription = errors.New("malformed modelDescription.xml")
ErrModelDescription is the typed error for a malformed modelDescription.xml.
var ErrNotFMU = errors.New("not a Functional Mock-up Unit")
ErrNotFMU is the typed error for data that is not an FMU: not a zip archive, or a zip with no modelDescription.xml at its root.
var ErrUnsupportedVersion = errors.New("unsupported FMI version")
ErrUnsupportedVersion is the typed error for an fmiVersion this package does not read.
var ErrVariable = errors.New("fmi variable refused")
ErrVariable is the typed error for a ToolVariable an FMU cannot answer for.
Functions ¶
Types ¶
type BaseUnit ¶
type BaseUnit struct {
Kg, M, S, A, K, Mol, Cd, Rad int
Factor, Offset float64 // Factor defaults 1
}
BaseUnit is the SI base-unit exponents of a Unit and the factor and offset converting its values to the SI unit.
func ParseBaseUnit ¶
ParseBaseUnit reads a unit spelled as a product of the SI base symbols alone: `kg`, `m`, `s`, `A`, `K`, `mol`, `cd` and `rad` joined by `*`, `.` or `/`, each optionally raised by `^n`, `^-n`, a trailing digit or a ²/³ superscript — `m/s2`, `m/s^2`, `m/s²` and `kg.m/s2` all read. Named units such as `N` are not parsed.
func (BaseUnit) SIExpression ¶
SIExpression spells the coherent KerML unit expression the exponents read as: the positive powers first, then `/` the negatives, in the order kg m s A K mol cd rad — `m/s^2` for acceleration, `kg*m/s^2` for force and `1/s` for frequency. A dimensionless unit spells as "" and reads as no unit at all.
type Causality ¶
type Causality string
Causality is a variable's causality attribute.
const ( CausalityParameter Causality = "parameter" CausalityCalculatedParameter Causality = "calculatedParameter" CausalityInput Causality = "input" CausalityOutput Causality = "output" CausalityLocal Causality = "local" CausalityIndependent Causality = "independent" CausalityStructuralParameter Causality = "structuralParameter" )
The causalities a variable may declare.
type Description ¶
type Description struct {
FMIVersion Version
ModelName, Description, Author, Version, GenerationTool, GenerationDateAndTime string
InstantiationToken string // FMI3 instantiationToken, FMI2 guid
CoSimulation, ModelExchange, ScheduledExecution *Interface // nil when absent
Units []Unit
Variables []Variable // document order
DefaultExperiment *Experiment
// Platforms are the sorted names of binaries/<platform>/ directories that
// hold at least one file; empty for a source-only or description-only archive.
Platforms []string
}
Description is the model description of one FMU.
func ParseModelDescription ¶
func ParseModelDescription(data []byte) (*Description, error)
ParseModelDescription reads the XML of one modelDescription.xml.
func Read ¶
func Read(path string) (*Description, error)
Read opens the .fmu archive at path and reads its model description and the platforms its binaries are built for.
func ReadArchive ¶
func ReadArchive(r io.ReaderAt, size int64) (*Description, error)
ReadArchive reads the .fmu archive held in memory at r.
func (*Description) Inputs ¶
func (d *Description) Inputs() []Variable
Inputs are the variables settable before or at initialization: causality input, parameter or structuralParameter, in document order.
func (*Description) Outputs ¶
func (d *Description) Outputs() []Variable
Outputs are the readable variables: causality output, calculatedParameter or local, in document order.
type Dimension ¶
type Dimension struct {
Start uint64 // meaningful only when HasStart
HasStart bool
ValueReference uint32 // meaningful only when HasVR
HasVR bool
}
Dimension is one array dimension of an FMI 3.0 variable: fixed at start, or structural when it names the valueReference of a structural parameter.
type Experiment ¶
type Experiment struct {
StartTime, StopTime, Tolerance, StepSize float64
HasStart, HasStop, HasTolerance, HasStepSize bool
}
Experiment is a DefaultExperiment element: the experiment the FMU's documentation suggests. Each field is meaningful only when its Has flag is set.
type Interface ¶
type Interface struct {
ModelIdentifier string
NeedsExecutionTool, CanHandleVariableCommunicationStepSize,
CanGetAndSetFMUState, CanSerializeFMUState, ProvidesDirectionalDerivatives bool
}
Interface is one FMI interface the FMU provides.
type Kind ¶
type Kind string
Kind is a variable's type normalized across the FMI versions: the type element's name as FMI 2.0 writes it, with the FMI 3.0 scalar types folded onto it.
type ModelDescriptionError ¶
ModelDescriptionError reports a model description that does not read.
func (*ModelDescriptionError) Error ¶
func (e *ModelDescriptionError) Error() string
Error gives the detail, then the cause.
func (*ModelDescriptionError) Is ¶
func (e *ModelDescriptionError) Is(target error) bool
Is matches ErrModelDescription.
func (*ModelDescriptionError) Unwrap ¶
func (e *ModelDescriptionError) Unwrap() error
Unwrap returns the cause.
type RunnerError ¶
RunnerError is a reply carrying the runner's own error member.
func (*RunnerError) Error ¶
func (e *RunnerError) Error() string
Error names the runner's message, then what it wrote to standard error.
type UnsupportedVersionError ¶
type UnsupportedVersionError struct {
Version string
}
UnsupportedVersionError reports a model description of a version other than 1.0, 2.0 or 3.0 — including pre-release spellings such as "3.0-beta.1".
func (*UnsupportedVersionError) Error ¶
func (e *UnsupportedVersionError) Error() string
Error names the version read.
func (*UnsupportedVersionError) Is ¶
func (e *UnsupportedVersionError) Is(target error) bool
Is matches ErrUnsupportedVersion.
type Variability ¶
type Variability string
Variability is a variable's variability attribute.
const ( VariabilityConstant Variability = "constant" VariabilityFixed Variability = "fixed" VariabilityTunable Variability = "tunable" VariabilityDiscrete Variability = "discrete" VariabilityContinuous Variability = "continuous" )
The variabilities a variable may declare.
type Variable ¶
type Variable struct {
Name, Description string
ValueReference uint32
Causality Causality // FMI 2/3 default "local"
Variability Variability // default "continuous" for Real, else "discrete"
Kind Kind
FMIType string // the element name as written (Float64, Real, Int32…)
Start string // raw start text, "" when none
HasStart bool
Unit string // unit attribute, or the declaredType's unit when the variable has none
DeclaredType string
Min, Max string
// Dimensions are the variable's array dimensions in document order; empty
// for a scalar. A Dimension with HasStart is fixed; HasVR names the
// valueReference of a structural parameter.
Dimensions []Dimension
}
Variable is one scalar variable of the model.
func (Variable) UnitExponents ¶
func (v Variable) UnitExponents(d *Description) (BaseUnit, bool)
UnitExponents resolves the variable's unit to coherent SI base-unit exponents: the declared unit's BaseUnit, else the unit spelling itself as a product of the base symbols. False for a variable with no unit, one that resolves to nothing, or a non-coherent unit (factor other than 1 or an offset, as km or degC carry).
type VariableError ¶
VariableError reports a ToolVariable naming no variable of the FMU, or naming one of the wrong direction. Detail lists the candidates it could have been.
func (*VariableError) Error ¶
func (e *VariableError) Error() string
Error names the FMU, the variable and the detail.