fmi

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Exchange = "fmi/1"

Exchange names the request/reply protocol the engine and the runner speak, as an engine listing reports it.

View Source
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

View Source
var ErrModelDescription = errors.New("malformed modelDescription.xml")

ErrModelDescription is the typed error for a malformed modelDescription.xml.

View Source
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.

View Source
var ErrUnsupportedVersion = errors.New("unsupported FMI version")

ErrUnsupportedVersion is the typed error for an fmiVersion this package does not read.

View Source
var ErrVariable = errors.New("fmi variable refused")

ErrVariable is the typed error for a ToolVariable an FMU cannot answer for.

Functions

func FileURI

func FileURI(path string) string

FileURI spells the file: URI naming the file at path: the absolute path, escaped, a Windows drive gaining the leading slash the URL form carries.

func New

func New(look func() (string, error)) analysis.Manifested

New returns the `tool:fmi` engine. look finds the runner's executable; nil reads RunnerEnv, whose absence is the absence the engine reports.

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

func ParseBaseUnit(unit string) (BaseUnit, bool)

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

func (b BaseUnit) SIExpression() string

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.

func (*Description) Unit

func (d *Description) Unit(name string) (Unit, bool)

Unit returns the unit named, and whether the description declares one.

func (*Description) Variable

func (d *Description) Variable(name string) (Variable, bool)

Variable returns the variable named, and whether the description holds one.

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.

const (
	KindReal        Kind = "Real"
	KindInteger     Kind = "Integer"
	KindBoolean     Kind = "Boolean"
	KindString      Kind = "String"
	KindEnumeration Kind = "Enumeration"
	KindBinary      Kind = "Binary"
	KindClock       Kind = "Clock"
)

The kinds a variable's type reads as.

type ModelDescriptionError

type ModelDescriptionError struct {
	Detail string
	Err    error
}

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

type RunnerError struct {
	Message string
	Stderr  string
}

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 Unit

type Unit struct {
	Name string
	Base *BaseUnit
}

Unit is one declared unit.

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

type VariableError struct {
	FMU      string
	Variable string
	Detail   string
}

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.

func (*VariableError) Is

func (e *VariableError) Is(target error) bool

Is matches ErrVariable.

type Version

type Version string

Version is an FMI version as fmiVersion spells it: major.minor only.

const (
	Version1 Version = "1.0"
	Version2 Version = "2.0"
	Version3 Version = "3.0"
)

FMI versions this package reads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL