Skip to content

Commit 38a5699

Browse files
authored
update (#131)
1 parent a99b459 commit 38a5699

25 files changed

+112
-123
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.36.7
1+
0.37.0

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/ModelInstance.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ interface SimpleModelInstance : VariableAccessor, Closeable {
4545
*/
4646
val isTerminated: Boolean
4747

48-
/**
49-
* Current simulation time
50-
*/
51-
val simulationTime: Double
52-
5348
/**
5449
* The last status returned by the FMU
5550
*/
@@ -79,13 +74,10 @@ interface SimpleModelInstance : VariableAccessor, Closeable {
7974
}
8075

8176
fun setupExperiment(start: Double = 0.0, stop: Double = 0.0, tolerance: Double = 0.0): Boolean
82-
8377
fun enterInitializationMode(): Boolean
84-
8578
fun exitInitializationMode(): Boolean
8679

8780
fun reset(): Boolean
88-
8981
fun terminate(): Boolean
9082

9183
fun getFMUstate(): FmuState

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/SlaveInstance.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ interface SlaveInstance : ModelInstance<CoSimulationModelDescription> {
3636
/**
3737
* Step simulation forward in time
3838
*
39+
* @param currentTime current simulation time
3940
* @param stepSize time to step simulation forward (in seconds)
4041
*/
41-
fun doStep(stepSize: Double): Boolean
42+
fun doStep(currentTime: Double, stepSize: Double): Boolean
4243

4344
}

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/VariableAccessor.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ interface VariableReader {
4343
realVr: ValueReferences?, realRefs: DoubleArray?,
4444
boolVr: ValueReferences?, boolRefs: BooleanArray?,
4545
strVr: ValueReferences?, strRefs: StringArray?
46-
): FmiStatus
46+
): FmiStatus {
47+
if (intVr != null && intRefs != null) {
48+
readInteger(intVr, intRefs)
49+
}
50+
if (realVr != null && realRefs != null) {
51+
readReal(realVr, realRefs)
52+
}
53+
if (boolVr != null && boolRefs != null) {
54+
readBoolean(boolVr, boolRefs)
55+
}
56+
if (strVr != null && strRefs != null) {
57+
readString(strVr, strRefs)
58+
}
59+
return FmiStatus.OK
60+
}
4761

4862
}
4963

@@ -62,7 +76,21 @@ interface VariableWriter {
6276
realVr: ValueReferences?, realValues: DoubleArray?,
6377
boolVr: ValueReferences?, boolValues: BooleanArray?,
6478
strVr: ValueReferences?, strValues: StringArray?,
65-
): FmiStatus
79+
): FmiStatus {
80+
if (intVr != null && intValues != null) {
81+
writeInteger(intVr, intValues)
82+
}
83+
if (realVr != null && realValues != null) {
84+
writeReal(realVr, realValues)
85+
}
86+
if (boolVr != null && boolValues != null) {
87+
writeBoolean(boolVr, boolValues)
88+
}
89+
if (strVr != null && strValues != null) {
90+
writeString(strVr, strValues)
91+
}
92+
return FmiStatus.OK
93+
}
6694

6795
}
6896

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/AbstractFmu.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package no.ntnu.ihb.fmi4j.importer
2626

2727
import no.ntnu.ihb.fmi4j.CoSimulationModel
2828
import no.ntnu.ihb.fmi4j.ModelExchangeModel
29-
import no.ntnu.ihb.fmi4j.modeldescription.ModelDescriptionParser
3029
import no.ntnu.ihb.fmi4j.modeldescription.ModelDescriptionProvider
3130
import no.ntnu.ihb.fmi4j.modeldescription.util.FmiModelDescriptionUtil
3231
import no.ntnu.ihb.fmi4j.util.extractContentTo
@@ -39,8 +38,8 @@ import java.util.*
3938
import java.util.concurrent.atomic.AtomicBoolean
4039

4140
abstract class AbstractFmu internal constructor(
42-
val name: String,
43-
protected val extractedFmu: File
41+
val name: String,
42+
protected val extractedFmu: File
4443
) : Closeable {
4544

4645
val guid: String
@@ -217,7 +216,8 @@ abstract class AbstractFmu internal constructor(
217216
}
218217

219218
private fun returnCorrectFmuType(fmuName: String, temp: File): AbstractFmu {
220-
return when (val version = FmiModelDescriptionUtil.extractVersion(getModelDescriptionFileFromExtractedFmuDir(temp).readText())) {
219+
return when (val version =
220+
FmiModelDescriptionUtil.extractVersion(getModelDescriptionFileFromExtractedFmuDir(temp).readText())) {
221221
"1.0" -> no.ntnu.ihb.fmi4j.importer.fmi1.Fmu(fmuName, temp)
222222
"2.0" -> no.ntnu.ihb.fmi4j.importer.fmi2.Fmu(fmuName, temp)
223223
else -> {

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/AbstractModelInstance.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ abstract class AbstractModelInstance<out E : CommonModelDescription, out T : Fmi
6363
protected val stopDefined
6464
get() = stopTime > startTime
6565

66-
/**
67-
* Current simulation time
68-
*/
69-
override var simulationTime: Double = 0.0
70-
internal set
71-
7266
override val lastStatus: FmiStatus
7367
get() = wrapper.lastStatus
7468

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/CoSimulationFmu.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import java.io.Closeable
3232

3333

3434
class CoSimulationFmu(
35-
private val fmu: Fmu
35+
private val fmu: Fmu
3636
) : CoSimulationModel, Closeable by fmu {
3737

3838
override val modelDescription: CoSimulationModelDescription by lazy {

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/CoSimulationSlave.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ import org.slf4j.LoggerFactory
3838
* @author Lars Ivar Hatledal
3939
*/
4040
class CoSimulationSlave internal constructor(
41-
instanceName: String,
42-
wrapper: CoSimulationLibraryWrapper,
43-
modelDescription: CoSimulationModelDescription
44-
) : SlaveInstance, AbstractModelInstance<CoSimulationModelDescription, CoSimulationLibraryWrapper>(instanceName, wrapper, modelDescription) {
41+
instanceName: String,
42+
wrapper: CoSimulationLibraryWrapper,
43+
modelDescription: CoSimulationModelDescription
44+
) : SlaveInstance, AbstractModelInstance<CoSimulationModelDescription, CoSimulationLibraryWrapper>(
45+
instanceName,
46+
wrapper,
47+
modelDescription
48+
) {
4549

4650
/**
4751
* Call init with provided start and stop
@@ -62,8 +66,6 @@ class CoSimulationSlave internal constructor(
6266
stopTime = stop
6367
}
6468

65-
simulationTime = start
66-
6769
return true.also {
6870
wrapper.lastStatus = FmiStatus.OK
6971
}
@@ -73,22 +75,16 @@ class CoSimulationSlave internal constructor(
7375
return wrapper.initializeSlave(startTime, stopTime).isOK()
7476
}
7577

76-
override fun doStep(stepSize: Double): Boolean {
78+
override fun doStep(currentTime: Double, stepSize: Double): Boolean {
7779

78-
val tNext = (simulationTime + stepSize)
80+
val tNext = (currentTime + stepSize)
7981

8082
if (stopDefined && tNext > stopTime) {
8183
LOG.warn("Cannot perform doStep! tNext=$tNext > stopTime=$stopTime")
8284
return false
8385
}
8486

85-
return wrapper.doStep(simulationTime, stepSize, newStep = true).let { status ->
86-
(status == FmiStatus.OK).also { success ->
87-
if (success) {
88-
simulationTime = tNext
89-
}
90-
}
91-
}
87+
return wrapper.doStep(currentTime, stepSize, newStep = true).isOK()
9288

9389
}
9490

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/FmiStatusKind.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package no.ntnu.ihb.fmi4j.importer.fmi1
2929
* @author Lars Ivar Hatledal
3030
*/
3131
enum class FmiStatusKind(
32-
val code: Int
32+
val code: Int
3333
) {
3434

3535
/**
@@ -64,4 +64,4 @@ enum class FmiStatusKind(
6464
}
6565
}
6666

67-
}
67+
}

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/Fmu.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import java.net.URL
4242
* @author Lars Ivar Hatledal
4343
*/
4444
class Fmu internal constructor(
45-
name: String,
46-
extractedFmu: File
45+
name: String,
46+
extractedFmu: File
4747
) : AbstractFmu(name, extractedFmu) {
4848

4949
private val libraries = mutableListOf<Fmi1Library>()
@@ -82,8 +82,10 @@ class Fmu internal constructor(
8282
* Get the absolute name of the native library on the form "C://folder/name.extension"
8383
*/
8484
internal fun getAbsoluteLibraryPath(modelIdentifier: String): File {
85-
return File(extractedFmu, BINARIES_FOLDER + File.separator + OsUtil.libraryFolderName + OsUtil.platformBitness
86-
+ File.separator + modelIdentifier + "." + OsUtil.libExtension)
85+
return File(
86+
extractedFmu, BINARIES_FOLDER + File.separator + OsUtil.libraryFolderName + OsUtil.platformBitness
87+
+ File.separator + modelIdentifier + "." + OsUtil.libExtension
88+
)
8789
}
8890

8991
internal fun registerLibrary(library: Fmi1Library) {

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/ModelExchangeFmu.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.io.Closeable
3636
* @author Lars Ivar Hatledal
3737
*/
3838
class ModelExchangeFmu(
39-
private val fmu: Fmu
39+
private val fmu: Fmu
4040
) : ModelExchangeModel, Closeable by fmu {
4141

4242
override val modelDescription: ModelExchangeModelDescription by lazy {

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi1/ModelExchangeInstance.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ open class ModelExchangeInstance internal constructor(
7777
}
7878

7979
fun setTime(time: Double): FmiStatus {
80-
return wrapper.setTime(time).also {
81-
simulationTime = time
82-
}
80+
return wrapper.setTime(time)
8381
}
8482

8583
fun setContinuousStates(x: DoubleArray) = wrapper.setContinuousStates(x)

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/AbstractModelInstance.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ abstract class AbstractModelInstance<out E : CommonModelDescription, out T : Fmi
6767
protected val stopDefined
6868
get() = stopTime > startTime
6969

70-
/**
71-
* Current simulation time
72-
*/
73-
override var simulationTime: Double = 0.0
74-
internal set
75-
7670
override val lastStatus: FmiStatus
7771
get() = wrapper.lastStatus
7872

@@ -100,9 +94,7 @@ abstract class AbstractModelInstance<out E : CommonModelDescription, out T : Fmi
10094
stopTime = stop
10195
}
10296

103-
return (wrapper.setupExperiment(tolerance, startTime, stopTime).isOK()).also {
104-
simulationTime = start
105-
}
97+
return (wrapper.setupExperiment(tolerance, startTime, stopTime).isOK())
10698

10799
}
108100

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/CoSimulationFmu.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
package no.ntnu.ihb.fmi4j.importer.fmi2
2626

2727
import no.ntnu.ihb.fmi4j.CoSimulationModel
28-
import no.ntnu.ihb.fmi4j.SlaveInstance
2928
import no.ntnu.ihb.fmi4j.importer.fmi2.jni.CoSimulationLibraryWrapper
3029
import no.ntnu.ihb.fmi4j.importer.fmi2.jni.Fmi2CoSimulationLibrary
3130
import no.ntnu.ihb.fmi4j.modeldescription.CoSimulationModelDescription
3231
import java.io.Closeable
3332

3433

3534
class CoSimulationFmu(
36-
private val fmu: Fmu
35+
private val fmu: Fmu
3736
) : CoSimulationModel, Closeable by fmu {
3837

3938
override val modelDescription: CoSimulationModelDescription by lazy {

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/CoSimulationSlave.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,16 @@ class CoSimulationSlave internal constructor(
4646
/**
4747
* @see CoSimulationLibraryWrapper.doStep
4848
*/
49-
override fun doStep(stepSize: Double): Boolean {
49+
override fun doStep(currentTime: Double, stepSize: Double): Boolean {
5050

51-
val tNext = (simulationTime + stepSize)
51+
val tNext = (currentTime + stepSize)
5252

5353
if (stopDefined && tNext > stopTime) {
5454
LOG.warn("Cannot perform doStep! tNext=$tNext > stopTime=$stopTime")
5555
return false
5656
}
5757

58-
return wrapper.doStep(simulationTime, stepSize, noSetFMUStatePriorToCurrent = true).let { status ->
59-
(status == FmiStatus.OK).also { success ->
60-
if (success) {
61-
simulationTime = tNext
62-
}
63-
}
64-
}
58+
return wrapper.doStep(currentTime, stepSize, noSetFMUStatePriorToCurrent = true).isOK()
6559

6660
}
6761

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/FmiStatusKind.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package no.ntnu.ihb.fmi4j.importer.fmi2
2929
* @author Lars Ivar Hatledal
3030
*/
3131
enum class FmiStatusKind(
32-
val code: Int
32+
val code: Int
3333
) {
3434

3535
/**
@@ -74,4 +74,4 @@ enum class FmiStatusKind(
7474
}
7575
}
7676

77-
}
77+
}

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/Fmu.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import java.net.URL
4242
* @author Lars Ivar Hatledal
4343
*/
4444
class Fmu internal constructor(
45-
name: String,
46-
extractedFmu: File
45+
name: String,
46+
extractedFmu: File
4747
) : AbstractFmu(name, extractedFmu) {
4848

4949
private val libraries = mutableListOf<Fmi2Library>()
@@ -76,8 +76,10 @@ class Fmu internal constructor(
7676
}
7777

7878
fun getAbsoluteLibraryPath(modelIdentifier: String): File {
79-
return File(extractedFmu, BINARIES_FOLDER + File.separator + OsUtil.libraryFolderName + OsUtil.platformBitness
80-
+ File.separator + modelIdentifier + "." + OsUtil.libExtension)
79+
return File(
80+
extractedFmu, BINARIES_FOLDER + File.separator + OsUtil.libraryFolderName + OsUtil.platformBitness
81+
+ File.separator + modelIdentifier + "." + OsUtil.libExtension
82+
)
8183
}
8284

8385
internal fun registerLibrary(library: Fmi2Library) {
@@ -88,8 +90,10 @@ class Fmu internal constructor(
8890
instances.add(instance)
8991
}
9092

91-
internal fun instantiate(library: Fmi2Library, instanceName: String, guid: String,
92-
fmiType: Int, visible: Boolean, loggingOn: Boolean): Long {
93+
internal fun instantiate(
94+
library: Fmi2Library, instanceName: String, guid: String,
95+
fmiType: Int, visible: Boolean, loggingOn: Boolean
96+
): Long {
9397
LOG.trace("Calling instantiate: visible=$visible, loggingOn=$loggingOn")
9498
return library.instantiate(instanceName, fmiType, guid, resourcesPath, visible, loggingOn)
9599
}

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/ModelExchangeFmu.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import java.io.Closeable
3535
* @author Lars Ivar Hatledal
3636
*/
3737
class ModelExchangeFmu(
38-
private val fmu: Fmu
38+
private val fmu: Fmu
3939
) : ModelExchangeModel, Closeable by fmu {
4040

4141
override val modelDescription: ModelExchangeModelDescription by lazy {
@@ -59,7 +59,7 @@ class ModelExchangeFmu(
5959
}
6060

6161
fun newInstance(instanceName: String, visible: Boolean = false, loggingOn: Boolean = false): ModelExchangeInstance {
62-
val c = instantiate(instanceName, visible, loggingOn)
62+
val c = instantiate(instanceName, visible, loggingOn)
6363
val wrapper = ModelExchangeLibraryWrapper(c, lib)
6464
return ModelExchangeInstance(instanceName, wrapper, modelDescription).also {
6565
fmu.registerInstance(it)

fmi-import/src/main/kotlin/no/ntnu/ihb/fmi4j/importer/fmi2/ModelExchangeInstance.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ open class ModelExchangeInstance internal constructor(
4848
* @param time
4949
*/
5050
fun setTime(time: Double): FmiStatus {
51-
return wrapper.setTime(time).also {
52-
simulationTime = time
53-
}
51+
return wrapper.setTime(time)
5452
}
5553

5654
/**

0 commit comments

Comments
 (0)