feat(core,cosim): string variable support in fmu codegen, typed cosim… · modelscript/modelscript@f52621b · GitHub
Skip to content

Commit f52621b

Browse files
committed
feat(core,cosim): string variable support in fmu codegen, typed cosim coupling
1 parent acd0f22 commit f52621b

5 files changed

Lines changed: 93 additions & 23 deletions

File tree

‎packages/core/src/compiler/modelica/fmu-codegen.ts‎

Lines changed: 76 additions & 11 deletions

‎packages/cosim/src/coupling.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*
66
* Defines which output variables from one participant feed into
77
* which input variables of another participant.
8+
/**
9+
* Value type for co-simulation variable exchange.
10+
* Supports all FMI 2.0 scalar types: Real, Integer, Boolean, String.
811
*/
12+
export type CosimValue = number | string | boolean;
913

1014
/** A single variable coupling: one output feeds one input. */
1115
export interface VariableCoupling {
@@ -66,8 +70,8 @@ export class CouplingGraph {
6670
* Apply coupling values: given a map of all participant outputs,
6771
* produce a map of participant ID → input values to inject.
6872
*/
69-
applyCouplings(allOutputs: Map<string, Map<string, number>>): Map<string, Map<string, number>> {
70-
const inputs = new Map<string, Map<string, number>>();
73+
applyCouplings(allOutputs: Map<string, Map<string, CosimValue>>): Map<string, Map<string, CosimValue>> {
74+
const inputs = new Map<string, Map<string, CosimValue>>();
7175

7276
for (const coupling of this.couplings) {
7377
const sourceOutputs = allOutputs.get(coupling.from.participantId);
@@ -78,7 +82,7 @@ export class CouplingGraph {
7882

7983
let targetInputs = inputs.get(coupling.to.participantId);
8084
if (!targetInputs) {
81-
targetInputs = new Map<string, number>();
85+
targetInputs = new Map<string, CosimValue>();
8286
inputs.set(coupling.to.participantId, targetInputs);
8387
}
8488
targetInputs.set(coupling.to.variableName, value);

‎packages/cosim/src/mqtt/protocol.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface SetInputsCommand {
7878
/** Participant ID. */
7979
participantId: string;
8080
/** Variable name → value map. */
81-
values: Record<string, number>;
81+
values: Record<string, number | string | boolean>;
8282
}
8383

8484
/** Terminate command. */
@@ -118,7 +118,7 @@ export interface StatusMessage {
118118
/** Error message (when state is 'error'). */
119119
error?: string | undefined;
120120
/** Output variable values (after step). */
121-
outputs?: Record<string, number> | undefined;
121+
outputs?: Record<string, number | string | boolean> | undefined;
122122
}
123123

124124
// ── Result messages ──
@@ -128,7 +128,7 @@ export interface StepResult {
128128
/** Simulation time. */
129129
time: number;
130130
/** Participant ID → variable values map. */
131-
participants: Record<string, Record<string, number>>;
131+
participants: Record<string, Record<string, number | string | boolean>>;
132132
}
133133

134134
// ── Batched variable data ──
@@ -138,7 +138,7 @@ export interface VariableBatch {
138138
/** Simulation time. */
139139
time: number;
140140
/** Variable name → value map. */
141-
values: Record<string, number>;
141+
values: Record<string, number | string | boolean>;
142142
}
143143

144144
// ── Serialization helpers ──

‎packages/cosim/src/orchestrator.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class Orchestrator {
9898
const effectiveH = Math.min(h, experiment.stopTime - t);
9999

100100
// ── Step 2a: Collect all current outputs ──
101-
const allOutputs = new Map<string, Map<string, number>>();
101+
const allOutputs = new Map<string, Map<string, number | string | boolean>>();
102102
for (const p of participants) {
103103
const outputs = await p.getOutputs();
104104
allOutputs.set(p.id, outputs);
@@ -121,10 +121,10 @@ export class Orchestrator {
121121
}
122122

123123
// ── Step 2e: Collect outputs and publish results ──
124-
const stepOutputs: Record<string, Record<string, number>> = {};
124+
const stepOutputs: Record<string, Record<string, number | string | boolean>> = {};
125125
for (const p of participants) {
126126
const outputs = await p.getOutputs();
127-
const map: Record<string, number> = {};
127+
const map: Record<string, number | string | boolean> = {};
128128
outputs.forEach((value, key) => {
129129
map[key] = value;
130130
});

‎packages/cosim/src/participant.ts‎

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)