Skip to content

Commit

Permalink
updated fmi3 with new types in the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Nov 2, 2023
1 parent de6d772 commit f0e24dd
Show file tree
Hide file tree
Showing 56 changed files with 1,420 additions and 794 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.intocps.maestro.fmi.fmi2.Fmi2ModelDescriptionUnit;
import org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi2.Fmi2Unit;
import org.intocps.maestro.fmi.fmi2.Fmi2Unit;
import org.intocps.maestro.fmi.xml.NodeIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.intocps.maestro.fmi.fmi2

import org.intocps.fmi.jnifmuapi.fmi2.schemas.Fmi2Schema
import org.intocps.maestro.fmi.ModelDescription
import org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi2.Fmi2Unit
import org.intocps.maestro.fmi.xml.NodeIterator
import org.xml.sax.SAXException
import java.io.IOException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi2
package org.intocps.maestro.fmi.fmi2

import org.intocps.maestro.fmi.ModelDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi3
package org.intocps.maestro.fmi.fmi3

import org.apache.commons.io.IOUtils
import org.intocps.fmi.jnifmuapi.fmi3.schemas.Fmi3Schema
Expand Down Expand Up @@ -491,6 +491,9 @@ class Fmi3ModelDescription : ModelDescription {
node.attributes.getNamedItem("previous")?.nodeValue?.toUInt(),
node.attributes.getNamedItem("clocks")?.nodeValue?.split(" ")?.map { value -> value.toUInt() },
Fmi3TypeEnum.StringType,
(node.attributes.getNamedItem("initial")?.nodeValue ?: "").let {
if (it.isEmpty()) null else valueOf<Initial>(it)
},
node.attributes.let { att ->
val startValues: MutableList<String> = mutableListOf()
for (i in 0 until att.length) {
Expand Down Expand Up @@ -571,6 +574,9 @@ class Fmi3ModelDescription : ModelDescription {
node.attributes.getNamedItem("quantity")?.nodeValue ?: typeDefinition?.quantity,
node.attributes.getNamedItem("min")?.nodeValue?.toLong(),
node.attributes.getNamedItem("max")?.nodeValue?.toLong(),
(node.attributes.getNamedItem("initial")?.nodeValue ?: "").let {
if (it.isEmpty()) null else valueOf<Initial>(it)
},
node.attributes.getNamedItem("start")?.nodeValue?.split(" ")?.map { value -> value.toLong() },
getDimensionsFromVariableNode(node)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi3
package org.intocps.maestro.fmi.fmi3

data class Fmi3ModelStructureElement(val elementType: Fmi3ModelStructureElementEnum, val valueReference: UInt, val dependencies: List<UInt>?, val dependenciesKind: List<Fmi3DependencyKind>?)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi3
package org.intocps.maestro.fmi.fmi3

data class FloatTypeDefinition(
override val name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi3
package org.intocps.maestro.fmi.fmi3

import org.intocps.maestro.fmi.ModelDescription

Expand Down
90 changes: 64 additions & 26 deletions fmi/src/main/kotlin/org/intocps/maestro/fmi/fmi3/Fmi3Variables.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.intocps.maestro.fmi.org.intocps.maestro.fmi.fmi3
package org.intocps.maestro.fmi.fmi3

import org.intocps.maestro.fmi.Fmi2ModelDescription
import org.intocps.maestro.fmi.ModelDescription

abstract class Fmi3Variable protected constructor(
Expand All @@ -13,9 +12,20 @@ abstract class Fmi3Variable protected constructor(
val intermediateUpdate: Boolean? = false,
val previous: UInt? = null,
val clocks: List<UInt>? = null,
val typeIdentifier: Fmi3TypeEnum // This is for easier type identification and is not part of the official spec
val typeIdentifier: Fmi3TypeEnum, // This is for easier type identification and is not part of the official spec
val initial: ModelDescription.Initial? = null //this is not present for all but added for convenience
) {
fun getValueReferenceAsLong():Long { return valueReference.toLong() }
fun getValueReferenceAsLong(): Long {
return valueReference.toLong()
}

override fun toString(): String {
return "$name: ${typeIdentifier.name}"
}

abstract fun isScalar(): Boolean;


}

data class Dimension(val valueReference: UInt?, val start: List<Long>?)
Expand All @@ -32,7 +42,7 @@ class FloatVariable(
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
val declaredType: String? = null,
val initial: ModelDescription.Initial? = null,
initial: ModelDescription.Initial? = null,
val quantity: String? = null,
val unit: String? = null,
val displayUnit: String? = null,
Expand All @@ -44,7 +54,7 @@ class FloatVariable(
val start: Collection<Double>? = null,
val derivative: UInt? = null,
val reinit: Boolean? = false,
val dimensions: List<Dimension>? = null
val dimensions: List<Dimension>? = null
) : Fmi3Variable(
name,
valueReference,
Expand All @@ -55,8 +65,13 @@ class FloatVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
) {
override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}
}

class Int64Variable(
name: String,
Expand All @@ -70,7 +85,7 @@ class Int64Variable(
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
val declaredType: String? = null,
val initial: ModelDescription.Initial? = null,
initial: ModelDescription.Initial? = null,
val quantity: String? = null,
val min: Long? = null,
val max: Long? = null,
Expand All @@ -86,8 +101,11 @@ class Int64Variable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class IntVariable(
name: String,
Expand All @@ -101,7 +119,7 @@ class IntVariable(
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
val declaredType: String? = null,
val initial: ModelDescription.Initial? = null,
initial: ModelDescription.Initial? = null,
val quantity: String? = null,
val min: Int? = null,
val max: Int? = null,
Expand All @@ -117,8 +135,11 @@ class IntVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class BooleanVariable(
name: String,
Expand All @@ -132,7 +153,7 @@ class BooleanVariable(
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
val declaredType: String? = null,
val initial: ModelDescription.Initial? = null,
initial: ModelDescription.Initial? = null,
val start: List<Boolean>? = null,
val dimensions: List<Dimension>? = null
) : Fmi3Variable(
Expand All @@ -145,8 +166,11 @@ class BooleanVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class StringVariable(
name: String,
Expand All @@ -159,6 +183,7 @@ class StringVariable(
previous: UInt? = null,
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
initial: ModelDescription.Initial? = null,
val start: List<String>? = null,
val dimensions: List<Dimension>? = null
) : Fmi3Variable(
Expand All @@ -171,8 +196,11 @@ class StringVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class BinaryVariable(
name: String,
Expand All @@ -186,7 +214,7 @@ class BinaryVariable(
clocks: List<UInt>? = null,
typeIdentifier: Fmi3TypeEnum,
val declaredType: String? = null,
val initial: ModelDescription.Initial? = null,
initial: ModelDescription.Initial? = null,
val mimeType: String? = null,
val maxSize: UInt? = null,
val start: List<ByteArray>? = null,
Expand All @@ -201,8 +229,11 @@ class BinaryVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class EnumerationVariable(
name: String,
Expand All @@ -219,6 +250,7 @@ class EnumerationVariable(
val quantity: String? = null,
val min: Long? = null,
val max: Long? = null,
initial: ModelDescription.Initial? = null,
val start: List<Long>? = null,
val dimensions: List<Dimension>? = null
) : Fmi3Variable(
Expand All @@ -231,8 +263,11 @@ class EnumerationVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
initial
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

class ClockVariable(
name: String,
Expand Down Expand Up @@ -266,8 +301,11 @@ class ClockVariable(
intermediateUpdate,
previous,
clocks,
typeIdentifier
)
typeIdentifier,
null
){ override fun isScalar(): Boolean {
return dimensions.isNullOrEmpty()
}}

enum class Fmi3Causality {
StructuralParameter,
Expand Down
Loading

0 comments on commit f0e24dd

Please sign in to comment.