Skip to content

Commit

Permalink
Merge pull request #424 from INTO-CPS-Association/kel/fmi3-all-types-…
Browse files Browse the repository at this point in the history
…buffers

Kel/fmi3 all types buffers
  • Loading branch information
lausdahl authored Jul 16, 2024
2 parents 836a407 + 18df205 commit dec864d
Show file tree
Hide file tree
Showing 233 changed files with 14,875 additions and 3,467 deletions.
1,412 changes: 1,412 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
PYTHON_VERSION: '3.11.8'
MAVEN_VERSION: 3.8.1
WINDOWS_VERSION: 'windows-2019'
MACOS_VERSION: 'macos-latest'
MACOS_VERSION: 'macos-13'



Expand Down Expand Up @@ -109,10 +109,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, windows-2019, macos-latest ] # ubuntu-latest, , macos-latest
os: [ ubuntu-22.04, windows-2019, macos-13 ] # ubuntu-latest, , macos-13
platform: [ x64 ] #x32, x64 ]
exclude:
- os: macos-latest
- os: macos-13
platform: x32
steps:
- name: Set up Java
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ __pycache__/
/external_tester/venv/

*.ci-friendly-pom.xml
.venv
.metals/metals.mv.db
.bloop/ast-test.json
.bloop/ast.json
Expand Down
19 changes: 1 addition & 18 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions .idea/saveactions_settings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public static AIntLiteralExp newAIntLiteralExp(Integer value) {
return exp;
}


public static AStringLiteralExp newAStringLiteralExp(String value) {
AStringLiteralExp exp = new AStringLiteralExp();
exp.setValue(value);
Expand Down
4 changes: 4 additions & 0 deletions ast/src/main/resources/mabl.astv2
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,8 @@ type
= {real}
| {int}
| {uInt}
| {float}
| {short}
| {byte}
| {long}
;
6 changes: 5 additions & 1 deletion ast/src/main/resources/mabl.astv2.tostring
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ import java.util.stream.Collectors;
%type->#primitive->string="string"
%type->#primitive->#numeric->real="real"
%type->#primitive->#numeric->int="int"
%type->#primitive->#numeric->uInt="uint"
%type->#primitive->#numeric->uInt="uint"
%type->#primitive->#numeric->long="long"
%type->#primitive->#numeric->short="short"
%type->#primitive->#numeric->float="float"
%type->#primitive->#numeric->byte="byte"
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
10 changes: 5 additions & 5 deletions fmi/src/main/kotlin/ModelDescription.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.intocps.maestro.fmi

import org.intocps.fmi.jnifmuapi.fmi2.schemas.Fmi2Schema
import org.intocps.fmi.jnifmuapi.xml.SchemaProvider
import org.intocps.fmi.jnifmuapi.xml.SchemaResourceResolver
import org.intocps.maestro.fmi.xml.NamedNodeMapIterator
import org.intocps.maestro.fmi.xml.NodeIterator
Expand All @@ -27,7 +27,7 @@ abstract class ModelDescription
SAXException::class,
IOException::class,
ParserConfigurationException::class
) constructor(xmlInputStream: InputStream, schemaModelDescription: Source) {
) constructor(xmlInputStream: InputStream, schemaModelDescription: Source, provider: SchemaProvider) {
private val DEBUG = false

@JvmField
Expand All @@ -38,7 +38,7 @@ abstract class ModelDescription

init {
val docBuilderFactory = DocumentBuilderFactory.newInstance()
validateAgainstXSD(StreamSource(xmlInputStream), schemaModelDescription)
validateAgainstXSD(StreamSource(xmlInputStream), schemaModelDescription, provider)
xmlInputStream.reset()
doc = docBuilderFactory.newDocumentBuilder().parse(xmlInputStream)
val xPathfactory = XPathFactory.newInstance()
Expand Down Expand Up @@ -173,9 +173,9 @@ abstract class ModelDescription

companion object {
@Throws(SAXException::class, IOException::class)
fun validateAgainstXSD(document: Source, schemaSource: Source) {
fun validateAgainstXSD(document: Source, schemaSource: Source, provider: SchemaProvider) {
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).run {
this.resourceResolver = SchemaResourceResolver(Fmi2Schema())
this.resourceResolver = SchemaResourceResolver(provider)
this.newSchema(schemaSource).newValidator().validate(document)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 All @@ -18,7 +18,7 @@ abstract class Fmi2ModelDescriptionUnit : ModelDescription {
ParserConfigurationException::class
)
constructor(xmlInputStream: InputStream, schemaModelDescription: Source) : super(
xmlInputStream, schemaModelDescription
xmlInputStream, schemaModelDescription, Fmi2Schema()
)

// Unit definitions attribute
Expand All @@ -33,9 +33,11 @@ abstract class Fmi2ModelDescriptionUnit : ModelDescription {
"BaseUnit" -> {
setBaseUnit(parseBaseUnit(childNode))
}

"DisplayUnit" -> {
// displayUnits.add(parseDisplayUnit(childNode))
}

"Annotations" -> {
}
}
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,17 +1,17 @@
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
import org.intocps.maestro.fmi.ModelDescription
import org.intocps.maestro.fmi.xml.NodeIterator
import org.w3c.dom.Node
import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.lang.reflect.InvocationTargetException
import javax.xml.transform.stream.StreamSource
import javax.xml.xpath.XPathExpressionException


class Fmi3ModelDescription : ModelDescription {
private var variables: Collection<Fmi3Variable>? = null
private var typeDefinitions: Collection<IFmi3TypeDefinition>? = null
Expand All @@ -21,17 +21,17 @@ class Fmi3ModelDescription : ModelDescription {
private var derivatives: List<Fmi3ScalarVariable>? = null
private var derivativeToDerivativeSource: Map<Fmi3ScalarVariable, Fmi3ScalarVariable>? = null

constructor(file: File) : super(
ByteArrayInputStream(IOUtils.toByteArray(FileInputStream(file))), StreamSource(
Fmi3ModelDescription::class.java.classLoader.getResourceAsStream(
"fmi3ModelDescription.xsd"
)
)
)
// constructor(file: File) : super(
// ByteArrayInputStream(IOUtils.toByteArray(FileInputStream(file))), StreamSource(
// Fmi3ModelDescription::class.java.classLoader.getResourceAsStream(
// "fmi3ModelDescription.xsd"
// )
// )
// )

constructor(file: InputStream) : super(
file,
StreamSource(Fmi3ModelDescription::class.java.classLoader.getResourceAsStream("fmi3ModelDescription.xsd"))
StreamSource(ByteArrayInputStream(IOUtils.toByteArray(Fmi3Schema().schema))), Fmi3Schema()
)

fun getScalarVariables(): List<Fmi3ScalarVariable> {
Expand Down Expand Up @@ -100,12 +100,15 @@ class Fmi3ModelDescription : ModelDescription {
Fmi3ModelStructureElementEnum.Output -> variable.outputDependencies.putAll(
dependencyScalarVariableToDependencyKinds
)

Fmi3ModelStructureElementEnum.ContinuousStateDerivative -> variable.derivativesDependencies.putAll(
dependencyScalarVariableToDependencyKinds
)

Fmi3ModelStructureElementEnum.ClockedState -> {
//TODO: Implement
}

Fmi3ModelStructureElementEnum.InitialUnknown -> variable.initialUnknownsDependencies.putAll(
dependencyScalarVariableToDependencyKinds
)
Expand Down Expand Up @@ -218,9 +221,11 @@ class Fmi3ModelDescription : ModelDescription {
"BaseUnit" -> {
setBaseUnit(parseBaseUnit(childNode))
}

"DisplayUnit" -> {
displayUnits.add(parseDisplayUnit(childNode))
}

"Annotations" -> {
}
}
Expand Down Expand Up @@ -279,7 +284,7 @@ class Fmi3ModelDescription : ModelDescription {
return Fmi3ModelStructureElement(
valueOf(node.nodeName),
node.attributes.getNamedItem("valueReference").nodeValue.toUInt(),
node.attributes.getNamedItem("dependencies")?.nodeValue?.split(" ")
node.attributes.getNamedItem("dependencies")?.nodeValue?.split(" ")?.filter { value->value.trim().length>0 }
?.map { value -> value.toUInt() },
(node.attributes.getNamedItem("dependenciesKind")?.nodeValue ?: "").let { dependencyKinds ->
if (dependencyKinds.isEmpty()) null else dependencyKinds.split(" ")
Expand Down Expand Up @@ -485,6 +490,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 @@ -565,6 +573,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 All @@ -581,7 +592,7 @@ class Fmi3ModelDescription : ModelDescription {
val typeDefinition: ClockTypeDefinition? =
getTypeDefinitionFromDeclaredType(declaredType ?: "") as ClockTypeDefinition?

val interval = node.attributes.getNamedItem("interval")?.nodeValue
val interval = node.attributes.getNamedItem("intervalVariability")?.nodeValue

return ClockVariable(
node.attributes.getNamedItem("name").nodeValue,
Expand All @@ -599,15 +610,15 @@ class Fmi3ModelDescription : ModelDescription {
node.attributes.getNamedItem("clocks")?.nodeValue?.split(" ")?.map { value -> value.toUInt() },
Fmi3TypeEnum.ClockType,
declaredType,
node.attributes.getNamedItem("canBeDeactivated").nodeValue?.toBoolean()
?: typeDefinition?.canBeDeactivated,
when(node.attributes.getNamedItem("canBeDeactivated")?.nodeValue?.toBoolean()
?: typeDefinition?.canBeDeactivated){true->true;false,null->false},
node.attributes.getNamedItem("priority")?.nodeValue?.toUInt() ?: typeDefinition?.priority,
if (interval == null) typeDefinition!!.interval else valueOf(interval),
node.attributes.getNamedItem("intervalDecimal")?.nodeValue?.toFloat()
?: typeDefinition?.intervalDecimal,
node.attributes.getNamedItem("shiftDecimal")?.nodeValue?.toFloat() ?: typeDefinition?.shiftDecimal
?: (0).toFloat(),
node.attributes.getNamedItem("supportsFraction").nodeValue?.toBoolean()
node.attributes.getNamedItem("supportsFraction")?.nodeValue?.toBoolean()
?: typeDefinition?.supportsFraction ?: false,
node.attributes.getNamedItem("resolution")?.nodeValue?.toULong() ?: typeDefinition?.resolution,
node.attributes.getNamedItem("intervalCounter")?.nodeValue?.toULong()
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
Loading

0 comments on commit dec864d

Please sign in to comment.