Variable
Contents
Intro
The Variable interface is an interface, which provides an uniform access models to models in Simantics. It includes
- Tree-structured address space for accessing model structure and properties
- Uniform access to model configuration and state
Key use cases include
- Browsing of the model structure (see Model Browser)
- Browsing and manipulation of objects (see Selection View)
- Tabular data (see Spreadsheets)
Main functional requirements include representation of
- Structural models with procedural features (see Structural)
- Runtime data of solvers (see Experiments)
- Historical data from experiments
- Ontological data
Solution
A variable is an interface with the following services
- Querying children (variable) by name
- Querying properties (variables) by name
- Querying a value for a property variable
- Querying adapter interfaces
A set of built-in properties include
- URI, which is an unique string identifier and locator of the variable in the tree structure
- Parent, which is the tree parent of the variable
- HasName, which is a local identifier for the variable within its parent. Names are also used to create URIs.
- HasLabel, which is a short textual representation of the variable
- hasStandardResource, which returns the context resource in a standard graph-based child variable
- Represents, TODO
- Type, which returns a single type resource classifying the variable
- Role, which tells whether the variable is a child or a property (TODO: could be deprecated)
- DATATYPE, which returns the data type of a property variable. (TODO: should be HasDatatype)
- A model is a container for all data related to some user task e.g. simulation model.
- A context is an entity under a model which spans a set of variables specified by paths
- A path is an identifier which can be used to retrieve a variable from given context
- A path separator which identifies traversal of parents based on role. Specified separators are '.', '/', '#'
The specified roles are defined as
- Parent variable is denoted by the '.' separator
- Children are denoted by the '/' separator.
- Properties are denoted by the '#' separator. All properties contain a value.
Procedural children and variables are used with large data sets. E.g. query-based views can be exposed. Procedural properties also enable efficient slicing of arrays e.g. URI#Array_Property/0-99
A model typically contains a number of contexts which are browsed using the Variable interface. Typical contexts are//
- The base context, which can be used to browse the structure and configuration values of the model
- Configuration value contexts with e.g. set point values for some variables
- Experiment contexts with structure and values retrieved from simulator using Databoard Accessor interface
Generic tools such as Model Browser, Selection View, Diagram, Chart, Spreadsheet, OperationUI use the the path identifiers to refer to their data. Once a desired Variable has been obtained its value can be accessed using direct database requests or Databoard Accessor.
The variable system processes two kinds of textual identifiers
- A URI is a complete reference to a variable
- Examples:
- Models and contexts are identified by URIs
- A path is a relative reference to a variable based on another variable
- A path can contain a number of leading parent steps denoted by '.'
- Examples:
- /Diagram/PI_X#PI_MASS_FLOW
- ./Diagram2/PI_X#PI_MASS_FLOW#HasDatatype
Path identifiers can also be serialized into graph representation, which is name-independent and survives export/import. In e.g. structural this is an ordered set of path separators and configuration resources.
Refactoring
- add Collection<Variable> browseProperties(ReadGraph graph, String classification) throws DatabaseException;
- add standard property classifications, which returns a set of strings
- deprecate browseChildren, browseProperties => add get
Connection modelling
- Connection point properties are classified with http://www.simantics.org/Structural-1.0/ConnectionRelation
- The value of a connection point property is an object of class org.simantics.structural2.variables.Connection
public interface Connection { Collection<Variable> getConnectionPoints(ReadGraph graph) throws DatabaseException; }
It is assumed that instances of org.simantics.structural2.variables.Connection have proper identities (equals/hashCode) based on flattened connections.
The value of connection point properties can be null. This means that the connection point is not connected.
String editing operations
- HasDisplayValue is a String-valued property, which is a formatted and unit-converted representation of the property value.
- expression is a String-valued property, which is an SCL-formula used to compute the value of the property. If the property can be computed using an expression, this property is always available and returns null if an expression has not been defined.
- validator is a org.simantics.utils.strings.StringInputValidator-valued property. The validator is used for checking values to be written into a property.
public interface StringInputProblem { enum Severity { Error, Warning } String getDescription(); int getBegin(); int getEnd(); Severity getSeverity(); } public interface StringInputValidator { Collection<StringInputProblem> validate(String input); }
- valid is a Boolean-valued property, which indicates whether the property contains a valid value.
Property properties
- required is a Boolean-valued property, which indicates that the property should contain a valid value
- default is a Boolean-valued property, which indicates that the property value is a default value
- readOnly is a Boolean-valued property, which indicates that the property value can not be written
Assumptions
- §1 Everything after '#' has a value
- §2 For all realization resources a variable can be obtained by graph.adapt(r, Variable.class)
- §3 For all realization resources the variable URI equals graph.getURI(r)
- §4 A variable can be part of at most one Context
- §5 A variable can be part of at most one Model
- $6 All values can be accessed using either Variable.getValue or Variable.getInterface(Accessor.class)
- $7 All properties retrieved using Variable.browseProperties shall be available using Variable.getProperty
Standard modelling in Layer0
Child modelling
Standard child modelling assumes a context resource res.
- childResource : where (res, L0.ConsistsOf, childResource)
- childVariable = graph.adaptContextual(childResource, this, Variable.class, Variable.class)
Property modelling
Standard property modelling assumes a context resource res.
- (predicate, object) : where (res, predicate, object) and (predicate <R L0.HasProperty)
- childProperty = graph.adaptContextual(object, ModelledVariablePropertyDescriptor(this, predicate), Variable.class)
For property variables there are two context resources available, the associated value and the predicate. Properties are found from the value context first and then from the predicate context.
Layer0 properties
For all variables
- NAME: String
The name of the resource. The URI uses an escaped version of this name. For graph-based variables this is L0.HasName
- LABEL: String
The standard textual representation for the variable. For graph-based variables this is L0.HasLabel
- TYPE: Resource
A single type related to the variable.
- URI: String
The variable URI, see Implementations
- SERIALIZED: String
An immutable string identified for this part
- PARENT: Variable
The parent variable
- ROLE: Role
Is Role.Property if URI contains '#', else is Role.Child. If role is Role.Property, then the variable has a value.
- CONTEXT : Variable
The context variable of this variable. The URI of the context variable is a prefix of the URI of this variable.
- CHILD_COUNT: Integer
The amount of children.
- PROPERTY_COUNT: Integer
The amount of properties.
For variables, where Role is Role.Child
- REPRESENTS: Resource
The configuration resource related to this variable.
For variables, where Role is Role.Property
- REPRESENTS: Resource
The literal resource related to this variable.
- EXPRESSION: String
The expression for determining the value of the property. Null if there is no expression.
- PREDICATE: Variable
The variable representing the predicate.
- DATATYPE: Datatype
The data type of the property.
- INPUT_VALIDATOR: String -> String
A function which performs validation for potential inputs to setValue.
Modelling
- L0.ConsistsOf determines modelled variable children
- L0.HasProperty determines the predicates used for producing variable properties
- L0.Entity defined the adapter org.simantics.db.layer0.variable.StandardGraphChildVariableAdapter
- L0.Value defines the adapter org.simantics.db.layer0.variable.StandardModelledPropertyVariable
- L0X.ResourcePropertyRelation defines the adapter org.simantics.db.layer0.variable.ResourcePropertyVariableAdapter
Implementation
- org.simantics.db.layer0.variable.StandardGraphChildVariable implements a child variable based on a parent variable and on a context resource.
- org.simantics.db.layer0.variable.StandardGraphPropertyVariable implements a child variable based on a parent variable and on a (subject, predicate <R L0.HasProperty) resource pair.
- org.simantics.db.layer0.variable.VariableSpaceManipulator: for modifying the variable space
- org.simantics.db.layer0.variable.InputValidator: for validating user input
- org.simantics.db.layer0.variable.Formatter: for representing values
- org.simantics.databoard.units.IUnitConverter: for representing values according to user needs
Frequent cases
1. Given variable v, obtain model
Procedure: call Variables.getModel(graph, v)
2. Given variable v, obtain realization
Procedure: call Variables.getRealization(graph, v)
3. Given Variable URI, obtain Variable
Procedure: call Variables.getVariable(graph, uri)
4. Given Variable URI, obtain textual RVI
Procedure: call Variables.getRVI(graph, v)
5. Given a configuration resource r and context variable obtain variable
Procedure: call Variable.browse(graph, r)
6. Given two variables v1 and v2, obtain RVI of second based on first
call Variables.getRVI(graph, v1, v2)
7. Given Realization URI and RVI, obtain Variable
call Variables.getVariable(graph, uri, rvi)
8. Obtain string representation for value of Variable v
-Obtain value val (Object) by v.getValue() -Obtain converter c by v.getInterface(IUnitConverter.class) -Obtain converted value cval (Object) by c.convert(val) -Obtain formatter f by v.getInterface(Formatter.class) -Obtain String representation by f.format(cval)
Varible space modelling
Cases
Datatypes
Record
- All named fields are '/name'
- Tuples are named after position e.g. '/11'
Union
- Union does not show in URI
Array
- Elements are named after position e.g. '/11'
Map
- Items are named after key
Take for example http://www.asd.org/Project/AprosModel1/BaseRealization/a/TA_1#TA11_POINT_ELEV
Property sets
Two alternatives
Set is also a value
http://www.asd.org/Project/BalasModel1/BaseRealization/Valve1/FSET#Set1/Flowrate
Set1 is now a Databoard record.
Only items are values
http://www.asd.org/Project/BalasModel1/BaseRealization/Valve1/FSET/Set1#Flowrate
Units
Formatting
Standard variables
Cases
Inferred configuration values from structural
Expressions
Variable syntax in SCL
- Implement variable interface methods as normal functions
- Example:
browse entrypoint "./Out#sdf"
- Example:
- Use . and #-for browsing
- How to browse parent? Explicit function
- Example:
(parent entrypoint).Out#sdf
- Special operator for parents (binds stronger than . or #):
- Example:
!entrypoint.Out#sdf
- Resolve entrypoints in the context
- Example:
Out#sdf
- Local variable definitions may shadow context
- Example:
Experiment modelling
Each running or stored historical experiment in Simantics is modelled as a realization under the Model. Realizations have URIs as defined by ReadGraph.getURI. Some realizations are entirely backed by the semantic graph and some are backed by an Accessor provided by a running simulator or a time series stored as a file in the semantic graph. The structure of the Variable tree under the realization is generated from the semantic model configuration and can be implemented in different ways ranging from persistent graph to lazily produced transient virtual graph. The realizations are browsed using Variable interface methods and variable values can be obtained using Variable methods or by obtaining Databoard Accessor using Variable.getInterface. Each variable serves an instantaneous value and each variable can also contain a property which serves a time series associated to the variable such as in historical data or sampled history of a running experiment.
Validation scenario
The standard model is validated in a headless structural-based setup with
- Structural configuration with joined diagrams and reusable component types
- Procedural children provided by simulator
- Accessor-backed simulator