Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/OpenModelica/OpenModelica…
- Loading branch information
Showing
449 changed files
with
3,348 additions
and
8,041 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
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
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,20 @@ | ||
uniontype UT | ||
record R | ||
Real r; | ||
end R; | ||
|
||
function f | ||
input UT ut; | ||
output Real r; | ||
algorithm | ||
R(r = r) := ut; | ||
end f; | ||
end UT; | ||
|
||
function test | ||
output Real x; | ||
protected | ||
UT ut = R(1.0); | ||
algorithm | ||
x := UT.f(ut); | ||
end test; |
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,17 @@ | ||
// name: UniontypeFunc1 | ||
// keywords: uniontype function | ||
// status: correct | ||
// cflags: -g=MetaModelica | ||
// | ||
// Tests functions inside of uniontypes. | ||
// | ||
|
||
loadFile("UniontypeFunc1.mo"); getErrorString(); | ||
test(); getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// "" | ||
// 1.0 | ||
// "" | ||
// 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,44 @@ | ||
// status: correct | ||
|
||
setCommandLineOptions("-g=MetaModelica"); | ||
loadString(" | ||
package TestCref | ||
|
||
uniontype U | ||
record R | ||
Real r; | ||
end R; | ||
end U; | ||
uniontype U2 | ||
record R2 | ||
array<U> u; | ||
end R2; | ||
end U2; | ||
function f | ||
output Real r1,r2,r3; | ||
protected | ||
array<U> a; | ||
array<U2> au2; | ||
U u; | ||
U2 u2; | ||
algorithm | ||
a := arrayCreate(10, R(1.0)); | ||
au2 := arrayCreate(3, R2(a)); | ||
r1 := a[1].r; | ||
u := au2[2].u[8]; | ||
r2 := au2[2].u[8].r; | ||
u2 := R2(a); | ||
r3 := u2.u[1].r; | ||
end f; | ||
|
||
end TestCref; | ||
");getErrorString(); | ||
TestCref.f();getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// true | ||
// "" | ||
// (1.0,1.0,1.0) | ||
// "" | ||
// endResult |
Oops, something went wrong.