Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
579 changed files
with
9,271 additions
and
11,759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
flattening/modelica/algorithms-functions/UnknownDimensionFunctionCall.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// status: correct | ||
|
||
package Modelica_Noise | ||
package Math | ||
package Random | ||
package Generators | ||
package Xorshift64star | ||
extends Interfaces.PartialGenerator(final nState = 2); | ||
|
||
redeclare function extends initialState | ||
protected | ||
Real r; | ||
constant Integer p = 10; | ||
algorithm | ||
if localSeed == 0 and globalSeed == 0 then | ||
state := {126247697, globalSeed}; | ||
else | ||
state := {localSeed, globalSeed}; | ||
end if; | ||
for i in 1:p loop | ||
(r, state) := random(state); | ||
end for; | ||
end initialState; | ||
|
||
redeclare function extends random | ||
external "C" ModelicaRandom_xorshift64star(stateIn, stateOut, result) annotation(Include = " | ||
#include <stdint.h> | ||
#define ModelicaRandom_INVM64 5.42101086242752217004e-20 /* = 2^(-64) */ | ||
#define ModelicaRandom_RAND(INT64) ( (int64_t)(INT64) * ModelicaRandom_INVM64 + 0.5 ) | ||
void ModelicaRandom_xorshift64star(int state_in[], int state_out[], double* y) { | ||
union s_tag { | ||
int32_t s32[2]; | ||
uint64_t s64; | ||
} s; | ||
int i; | ||
uint64_t x; | ||
for (i=0; i<sizeof(s)/sizeof(uint32_t); i++) { | ||
s.s32[i] = state_in[i]; | ||
} | ||
x = s.s64; | ||
/* The actual algorithm */ | ||
x ^= x >> 12; /* a */ | ||
x ^= x << 25; /* b */ | ||
x ^= x >> 27; /* c */ | ||
#if defined(_MSC_VER) | ||
x = x * 2685821657736338717i64; | ||
#else | ||
x = x * 2685821657736338717LL; | ||
#endif | ||
/* Convert outputs */ | ||
s.s64 = x; | ||
for (i=0; i<sizeof(s)/sizeof(uint32_t); i++) { | ||
state_out[i] = s.s32[i]; | ||
} | ||
*y = ModelicaRandom_RAND(x); | ||
} | ||
"); | ||
end random; | ||
end Xorshift64star; | ||
end Generators; | ||
|
||
package Interfaces | ||
partial package PartialGenerator | ||
constant Integer nState = 1; | ||
|
||
replaceable partial function initialState | ||
input Integer localSeed; | ||
input Integer globalSeed; | ||
output Integer[nState] state; | ||
end initialState; | ||
|
||
replaceable partial function random | ||
input Integer[nState] stateIn; | ||
output Real result; | ||
output Integer[nState] stateOut; | ||
end random; | ||
end PartialGenerator; | ||
end Interfaces; | ||
end Random; | ||
end Math; | ||
end Modelica_Noise; | ||
|
||
function f | ||
input Integer i[2]; | ||
output Real r; | ||
protected | ||
Integer io[:]; // : here is the culprit | ||
algorithm | ||
(r,io) := Modelica_Noise.Math.Random.Generators.Xorshift64star.random(i); | ||
end f; | ||
|
||
model M | ||
constant Real r = f({1,2}); | ||
end M; | ||
|
||
// Result: | ||
// function Modelica_Noise.Math.Random.Generators.Xorshift64star.random | ||
// input Integer[2] stateIn; | ||
// output Real result; | ||
// output Integer[2] stateOut; | ||
// | ||
// external "C" ModelicaRandom_xorshift64star(stateIn, stateOut, result); | ||
// end Modelica_Noise.Math.Random.Generators.Xorshift64star.random; | ||
// | ||
// function f | ||
// input Integer[2] i; | ||
// output Real r; | ||
// protected Integer[:] io; | ||
// algorithm | ||
// (r, io) := Modelica_Noise.Math.Random.Generators.Xorshift64star.random({i[1], i[2]}); | ||
// end f; | ||
// | ||
// class M | ||
// constant Real r = 0.2575342903011664; | ||
// end M; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// name: EnumArrayConnector | ||
// keywords: connect enum array | ||
// status: correct | ||
// | ||
// Tests that connectors containing arrays with enum dimensions work correctly. | ||
// | ||
|
||
model EnumArrayConnector | ||
type E = enumeration(a, b); | ||
|
||
connector C | ||
Real e; | ||
flow Real f; | ||
stream Real s[E]; | ||
end C; | ||
|
||
model B | ||
C c; | ||
end B; | ||
|
||
B b; | ||
end EnumArrayConnector; | ||
|
||
// Result: | ||
// class EnumArrayConnector | ||
// Real b.c.e; | ||
// Real b.c.f; | ||
// Real b.c.s[EnumArrayConnector.E.a]; | ||
// Real b.c.s[EnumArrayConnector.E.b]; | ||
// equation | ||
// b.c.f = 0.0; | ||
// end EnumArrayConnector; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.