Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FMU/Reference-FMUs
Submodule Reference-FMUs updated 322 files
24 changes: 14 additions & 10 deletions src/Internal/Library3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Library3 : Library
{
public Library3(string path) : base(path)
{
fmi3InstantiateBasicCoSimulation = FmuLibrary.LoadFunction<FMI3.fmi3InstantiateBasicCoSimulationTYPE>(nameof(fmi3InstantiateBasicCoSimulation));
fmi3InstantiateCoSimulation = FmuLibrary.LoadFunction<FMI3.fmi3InstantiateCoSimulationTYPE>(nameof(fmi3InstantiateCoSimulation));
fmi3FreeInstance = FmuLibrary.LoadFunction<FMI3.fmi3FreeInstanceTYPE>(nameof(fmi3FreeInstance));
fmi3EnterInitializationMode = FmuLibrary.LoadFunction<FMI3.fmi3EnterInitializationModeTYPE>(nameof(fmi3EnterInitializationMode));
fmi3ExitInitializationMode = FmuLibrary.LoadFunction<FMI3.fmi3ExitInitializationModeTYPE>(nameof(fmi3ExitInitializationMode));
Expand All @@ -28,7 +28,7 @@ public Library3(string path) : base(path)
}

// ReSharper disable InconsistentNaming -- must use fmi standard names to load function in library
private readonly FMI3.fmi3InstantiateBasicCoSimulationTYPE fmi3InstantiateBasicCoSimulation;
private readonly FMI3.fmi3InstantiateCoSimulationTYPE fmi3InstantiateCoSimulation;
private readonly FMI3.fmi3FreeInstanceTYPE fmi3FreeInstance;
private readonly FMI3.fmi3EnterInitializationModeTYPE fmi3EnterInitializationMode;
private readonly FMI3.fmi3ExitInitializationModeTYPE fmi3ExitInitializationMode;
Expand All @@ -50,16 +50,17 @@ public override Callbacks CreateCallbacks(Instance instance, ICallbacks cb) =>

public override IntPtr Instantiate(string name, string guid, string tmpFolder, Callbacks callbacks)
{
return fmi3InstantiateBasicCoSimulation(
return fmi3InstantiateCoSimulation(
name,
guid,
tmpFolder,
FMI3.fmi3Boolean.fmi3False,
FMI3.fmi3Boolean.fmi3True,
FMI3.fmi3Boolean.fmi3False,
FMI3.fmi3Boolean.fmi3False,
FMI3.fmi3Boolean.fmi3False,
callbacks.Custom,
IntPtr.Zero,
0,
callbacks.Custom,
((Callbacks3)callbacks).LogMessageDelegate,
IntPtr.Zero
);
Expand All @@ -80,15 +81,18 @@ public override void Setup(IntPtr handle, double currentTime)

public override void Step(IntPtr handle, double currentTime, double step)
{
fmi3DoStep(
var buf = Marshalling.AllocateMemory(4, sizeof(bool));
var res = fmi3DoStep(
handle,
currentTime,
step,
FMI3.fmi3Boolean.fmi3True,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero
buf,
buf+sizeof(bool),
buf+2*sizeof(bool),
buf+3*sizeof(bool)
);
if (res != 0) { throw new FmuException("Status not OK: " + res); }
}

public override void Shutdown(IntPtr handle, bool started)
Expand Down Expand Up @@ -185,4 +189,4 @@ Func<IntPtr, UInt32[], ulong, T[], ulong, int> call
throw new FmuException("Failed to write");
}
}
}
}
2 changes: 1 addition & 1 deletion src/Internal/ModelVersion3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Femyou.Internal
{
public class ModelVersion3 : IModelVersion
{
public string CoSimulationElementName { get; } = "BasicCoSimulation";
public string CoSimulationElementName { get; } = "CoSimulation";
public string GuidAttributeName { get; } = "instantiationToken";
public Library Load(string path) => new Library3(path);

Expand Down
12 changes: 7 additions & 5 deletions src/Interop/fmi3FunctionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public delegate void fmi3CallbackLogMessage(fmi3InstanceEnvironment componentEnv
fmi3String category,
fmi3String message);

public delegate fmi3Instance fmi3InstantiateBasicCoSimulationTYPE(
public delegate fmi3Instance fmi3InstantiateCoSimulationTYPE(
fmi3String instanceName,
fmi3String instantiationToken,
fmi3String resourceLocation,
fmi3Boolean visible,
fmi3Boolean loggingOn,
fmi3Boolean intermediateVariableGetRequired,
fmi3Boolean intermediateInternalVariableGetRequired,
fmi3Boolean intermediateVariableSetRequired,
fmi3Boolean eventModeUsed,
fmi3Boolean earlyReturnAllowed,
IntPtr requiredIntermediateVariables, /* FAKE, pointer */
fmi3Integer nRequiredIntermediateVariables, /* FAKE, size_t */
fmi3InstanceEnvironment instanceEnvironment,
fmi3CallbackLogMessage logMessage,
IntPtr intermediateUpdate);
Expand Down Expand Up @@ -64,7 +65,8 @@ public delegate fmi3Status fmi3DoStepTYPE(fmi3Instance instance,
fmi3Float64 currentCommunicationPoint,
fmi3Float64 communicationStepSize,
fmi3Boolean noSetFMUStatePriorToCurrentPoint,
IntPtr terminate,
IntPtr eventHandlingNeeded,
IntPtr terminateSimulation,
IntPtr earlyReturn,
IntPtr lastSuccessfulTime);

Expand Down
28 changes: 14 additions & 14 deletions tests/InstanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public void ChangeInstanceDefaultValues((string filename, string variableName, F

static readonly (string, string, Func<IInstance, IEnumerable<IVariable>, IEnumerable<object>>, object, Action<IInstance, IEnumerable<IVariable>>, object)[] DefaultValuesTestCases =
{
("Feedthrough.fmu", "bool_in", (i,v) => i.ReadBoolean(v).Cast<object>(), false, (i,vs) => i.WriteBoolean(vs.Select(v => (v,true))), true),
("Feedthrough.fmu", "string_param", (i,v) => i.ReadString(v), "Set me!", (i,vs) => i.WriteString(vs.Select(v => (v,"Foo"))), "Foo"),
("Feedthrough.fmu", "Boolean_input", (i,v) => i.ReadBoolean(v).Cast<object>(), false, (i,vs) => i.WriteBoolean(vs.Select(v => (v,true))), true),
("Feedthrough.fmu", "String_input", (i,v) => i.ReadString(v), "Set me!", (i,vs) => i.WriteString(vs.Select(v => (v,"Foo"))), "Foo"),
("BouncingBall.fmu", "g", (i,v) => i.ReadReal(v).Cast<object>(), -9.81, (i,vs) => i.WriteReal(vs.Select(v => (v,3.46))), 3.46),
("Stair.fmu", "counter", (i,v) => i.ReadInteger(v).Cast<object>(), 1, (i,vs) => {}, 1),
("Feedthrough.fmu", "int_in", (i,v) => i.ReadInteger(v).Cast<object>(), 0, (i,vs) => i.WriteInteger(vs.Select(v => (v,28))), 28)
("Feedthrough.fmu", "Int32_input", (i,v) => i.ReadInteger(v).Cast<object>(), 0, (i,vs) => i.WriteInteger(vs.Select(v => (v,28))), 28)
};

[Test]
Expand All @@ -64,17 +64,17 @@ public void FeedthroughReferenceScenario() // see https://github.com/modelica/Re
{
using var model = Model.Load(_getFmuPath("Feedthrough.fmu"));
using var instance = Tools.CreateInstance(model, "reference");
instance.WriteReal((model.Variables["real_fixed_param"], 1));
instance.WriteString((model.Variables["string_param"], "FMI is awesome!"));
var real_tunable_param = model.Variables["real_tunable_param"];
var real_continuous_in = model.Variables["real_continuous_in"];
var real_continuous_out = model.Variables["real_continuous_out"];
var real_discrete_in = model.Variables["real_discrete_in"];
var real_discrete_out = model.Variables["real_discrete_out"];
var int_in = model.Variables["int_in"];
var int_out = model.Variables["int_out"];
var bool_in = model.Variables["bool_in"];
var bool_out = model.Variables["bool_out"];
instance.WriteReal((model.Variables["Float64_fixed_parameter"], 1));
instance.WriteString((model.Variables["String_input"], "FMI is awesome!"));
var real_tunable_param = model.Variables["Float64_tunable_parameter"];
var real_continuous_in = model.Variables["Float64_continuous_input"];
var real_continuous_out = model.Variables["Float64_continuous_output"];
var real_discrete_in = model.Variables["Float64_discrete_input"];
var real_discrete_out = model.Variables["Float64_discrete_output"];
var int_in = model.Variables["Int32_input"];
var int_out = model.Variables["Int32_output"];
var bool_in = model.Variables["Boolean_input"];
var bool_out = model.Variables["Boolean_output"];
instance.StartTime(0.0);
foreach (var pt in feedthroughScenario)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ModelTests(int version)
}
private readonly Func<string, string> _getFmuPath;

[TestCase("BouncingBall.fmu", "bouncingball", "This model calculates the trajectory, over time, of a ball dropped from a height of 1 m.")]
[TestCase("BouncingBall.fmu", "bouncingball", "This model calculates the trajectory, over time, of a ball dropped from a height of 1 m")]
[TestCase("VanDerPol.fmu", "van der pol oscillator", "This model implements the van der Pol oscillator")]
public void ModelHasNameAndDescription(string filename, string expectedName, string expectedDescription)
{
Expand All @@ -30,8 +30,8 @@ public void ModelHasVariables()
var fmuPath = _getFmuPath("Feedthrough.fmu");
using var model = Model.Load(fmuPath);
Assert.That(model.Variables.Count(), Is.GreaterThanOrEqualTo(11));
Assert.That(model.Variables["string_param"].Description, Is.EqualTo("String parameter"));
Assert.That(model.Variables["bool_out"].Description, Is.EqualTo("boolean output"));
Assert.That(model.Variables["String_input"].Description, Is.EqualTo("String parameter"));
Assert.That(model.Variables["Boolean_output"].Description, Is.EqualTo("boolean output"));
}
}
}
2 changes: 1 addition & 1 deletion tests/TestTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class TestTools
public static string GetFmuPath(int version, string filename) =>
Path.Combine(FmuFolder(version), filename);
public static string FmuFolder(int version) =>
Path.Combine(BaseFolder, "FMU", $"bin{version}", "dist");
Path.Combine(BaseFolder, "FMU", $"bin{version}", "fmus");
public static string BaseFolder => Tools
.GetBaseFolder(new Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath, nameof(Femyou));
}
Expand Down