Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Oct 19, 2015
2 parents a13d66f + 29d30bf commit bdd216d
Show file tree
Hide file tree
Showing 43 changed files with 2,246 additions and 669 deletions.
1 change: 1 addition & 0 deletions flattening/modelica/redeclare/Makefile
Expand Up @@ -33,6 +33,7 @@ Redeclare4.mo \
Redeclare5.mo \
Redeclare6.mo \
Redeclare6.mos \
RedeclareArrayComponent1.mo \
RedeclareBaseClass1.mo \
RedeclareClass1.mo \
RedeclareClass4.mo \
Expand Down
27 changes: 27 additions & 0 deletions flattening/modelica/redeclare/RedeclareArrayComponent1.mo
@@ -0,0 +1,27 @@
// name: RedeclareArrayComponent1
// keywords: redeclare component array
// status: correct
//
// Checks that a redeclared components gets get correct type when using an array
// type.
//

model A
replaceable Real x[2];
end A;

model RedeclareArrayComponent1
type Real3 = Real[3];
A a1(redeclare Real3 x);
A a2(redeclare Real x);
end RedeclareArrayComponent1;

// Result:
// class RedeclareArrayComponent1
// Real a1.x[1];
// Real a1.x[2];
// Real a1.x[3];
// Real a2.x[1];
// Real a2.x[2];
// end RedeclareArrayComponent1;
// endResult
2 changes: 0 additions & 2 deletions openmodelica/bootstrapping/LoadCompilerSources.mos
Expand Up @@ -122,7 +122,6 @@ if true then /* Suppress output */
prefixPath + "BackEnd/BackendDAEUtil.mo",
prefixPath + "BackEnd/BackendDump.mo",
prefixPath + "BackEnd/BackendEquation.mo",
prefixPath + "BackEnd/BackendQSS.mo",
prefixPath + "BackEnd/BackendVariable.mo",
prefixPath + "BackEnd/BackendVarTransform.mo",
prefixPath + "BackEnd/BinaryTree.mo",
Expand Down Expand Up @@ -193,7 +192,6 @@ if true then /* Suppress output */
prefixPath + "Template/CodegenJava.mo",
prefixPath + "Template/CodegenJS.mo",
prefixPath + "Template/CodegenModelica.mo",
prefixPath + "Template/CodegenQSS.mo",
prefixPath + "Template/CodegenUtil.mo",
prefixPath + "Template/CodegenXML.mo",
prefixPath + "Template/DAEDumpTpl.mo",
Expand Down
1 change: 1 addition & 0 deletions openmodelica/cppruntime/Makefile
Expand Up @@ -5,6 +5,7 @@ tearnonlin1.mos \
WhenStatement1.mos \
BouncingBall.mos \
clockedTest.mos \
clockedTypesTest.mos \
mathFunctionsTest.mos \
functionPointerTest.mos \
recordTupleReturnTest.mos \
Expand Down
4 changes: 2 additions & 2 deletions openmodelica/cppruntime/clockedTest.mos
Expand Up @@ -18,8 +18,8 @@ model DID \"Double Integrator Discrete-time\"
output Real y1, y2;
equation
ud = sample(u, Clock(dt));
xd1 = previous(xd1) + p * ud * dt;
xd2 = previous(xd2) + previous(xd1) * dt + 0.5 * ud * dt * dt;
xd1 = previous(xd1) + p * ud * interval(ud);
xd2 = previous(xd2) + previous(xd1) * interval(xd1) + 0.5 * ud * interval()^2;
y1 = hold(previous(xd1));
y2 = hold(previous(xd2));
end DID;
Expand Down
51 changes: 51 additions & 0 deletions openmodelica/cppruntime/clockedTypesTest.mos
@@ -0,0 +1,51 @@
// name: clockedTypesTest
// keywords: synchronous clocked equations types
// status: correct
// teardown_command: rm -f *ClockedTypes*

setCommandLineOptions("+simCodeTarget=Cpp");

loadString("
model ClockedTypes
Boolean firstTick(start = true);
Boolean pulse(start = false);
Integer counter(start = 0);
String text(start = \"\");
equation
when Clock(0.5) then
firstTick = false;
pulse = not previous(pulse);
counter = previous(counter) + 1;
text = previous(text) + \", \" + String(counter);
end when;
end ClockedTypes;
");
getErrorString();

simulate(ClockedTypes);
val(firstTick, 0.0);
val(firstTick, 1.0);
val(pulse, 0.0);
val(pulse, 1.0);
val(counter, 0.0);
val(counter, 1.0);
//val(text, 1.0); // not supported in results file?
getErrorString();

// Result:
// true
// true
// ""
// record SimulationResult
// resultFile = "ClockedTypes_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ClockedTypes', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// 0.0
// 0.0
// 1.0
// 1.0
// 1.0
// 3.0
// ""
// endResult
3 changes: 2 additions & 1 deletion openmodelica/cppruntime/fmu/modelExchange/2.0/Makefile
Expand Up @@ -2,7 +2,8 @@ TEST = ../../../../../rtest -v


TESTFILES = \
DIC_FMU2_CPP.mos
DIC_FMU2_CPP.mos \
testModelDescription.mos

FAILINGTESTFILES = \
CoupledClutches_FMU2_CPP.mos
Expand Down
143 changes: 143 additions & 0 deletions openmodelica/cppruntime/fmu/modelExchange/2.0/testModelDescription.mos
@@ -0,0 +1,143 @@
// name: testModelDescription
// keywords: FMI 2.0 export clocks
// status: correct
// teardown_command: rm -rf binaries sources modelDescription.xml modelDescription.tmp.xml *SID* output.log
//

setCommandLineOptions("+simCodeTarget=Cpp"); getErrorString();
loadString("
model SID
constant Real dt = 0.1;
parameter Real p = 1;
parameter Real y_start = 0;
Real xd(start = y_start);
input Real u(start = -2);
output Real y;
equation
when Clock(dt) then
xd = previous(xd) + p * u * dt;
y = previous(xd);
end when;
end SID;
");
getErrorString();

translateModelFMU(SID, version="2.0");
getErrorString();

// unzip to console, quiet, extra quiet
system("unzip -cqq SID.fmu modelDescription.xml | grep -v guid | grep -v generationDateAndTime | grep -v generationTool > modelDescription.tmp.xml");
readFile("modelDescription.tmp.xml");

// Result:
// true
// ""
// true
// ""
// "SimCode: The model SID has been translated to FMU"
// ""
// 0
// "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
// <fmiModelDescription
// fmiVersion=\"2.0\"
// modelName=\"SID\"
// description=\"\"
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
// modelIdentifier=\"SID\">
// </ModelExchange>
// <LogCategories>
// <Category name=\"logEvents\" />
// <Category name=\"logSingularLinearSystems\" />
// <Category name=\"logNonlinearSystems\" />
// <Category name=\"logDynamicStateSelection\" />
// <Category name=\"logStatusWarning\" />
// <Category name=\"logStatusDiscard\" />
// <Category name=\"logStatusError\" />
// <Category name=\"logStatusFatal\" />
// <Category name=\"logStatusPending\" />
// <Category name=\"logAll\" />
// <Category name=\"logFmi2Call\" />
// </LogCategories>
// <DefaultExperiment startTime=\"0.0\" stopTime=\"1.0\" tolerance=\"1e-06\"/>
// <ModelVariables>
// <!-- Index of variable = \"1\" -->
// <ScalarVariable
// name=\"previous(xd)\"
// valueReference=\"0\"
// variability=\"discrete\"
// causality=\"local\"
// clockIndex=\"1\"
// initial=\"exact\">
// <Real start=\"0.0\"/>
// </ScalarVariable>
// <!-- Index of variable = \"2\" -->
// <ScalarVariable
// name=\"u\"
// valueReference=\"1\"
// variability=\"continuous\"
// causality=\"input\"
// >
// <Real start=\"-2.0\"/>
// </ScalarVariable>
// <!-- Index of variable = \"3\" -->
// <ScalarVariable
// name=\"xd\"
// valueReference=\"2\"
// variability=\"discrete\"
// causality=\"local\"
// clockIndex=\"1\"
// previous=\"1\"
// initial=\"exact\">
// <Real start=\"0.0\"/>
// </ScalarVariable>
// <!-- Index of variable = \"4\" -->
// <ScalarVariable
// name=\"y\"
// valueReference=\"3\"
// variability=\"discrete\"
// causality=\"output\"
// clockIndex=\"1\"
// initial=\"calculated\">
// <Real/>
// </ScalarVariable>
// <!-- Index of variable = \"5\" -->
// <ScalarVariable
// name=\"p\"
// valueReference=\"4\"
// variability=\"fixed\"
// causality=\"parameter\"
// initial=\"exact\">
// <Real start=\"1.0\"/>
// </ScalarVariable>
// <!-- Index of variable = \"6\" -->
// <ScalarVariable
// name=\"y_start\"
// valueReference=\"5\"
// variability=\"fixed\"
// causality=\"parameter\"
// initial=\"exact\">
// <Real start=\"0.0\"/>
// </ScalarVariable>
// </ModelVariables>
// <ModelStructure>
// <Outputs>
// <Unknown index=\"4\" />
// </Outputs>
// <Derivatives>
// </Derivatives>
// <DiscreteStates>
// <Unknown index=\"3\" />
// </DiscreteStates>
// <InitialUnknowns>
// </InitialUnknowns>
// <Clocks>
// <Clock><Periodic>
// <Real interval=\"0.1\" />
// </Periodic></Clock>
// </Clocks>
// </ModelStructure>
// </fmiModelDescription>
// "
// endResult
1 change: 1 addition & 0 deletions openmodelica/fmi/ModelExchange/2.0/Makefile
Expand Up @@ -18,6 +18,7 @@ Modelica.Blocks.Sources.BooleanPulse.mos \
Modelica.Electrical.Analog.Examples.ChuaCircuit.mos \
Modelica_Mechanics_MultiBody_Examples_Elementary_Pendulum.mos \
Modelica_Mechanics_MultiBody_Examples_Elementary_DoublePendulum.mos \
testExperimentalFMU.mos

# test that currently fail. Move up when fixed.
# Run make testfailing
Expand Down
33 changes: 33 additions & 0 deletions openmodelica/fmi/ModelExchange/2.0/testExperimentalFMU.mos
@@ -0,0 +1,33 @@
// name: TestExperimentalFMU
// keywords: fmu export QSS multirate
// status: correct

loadString("
model advection
parameter Real alpha = 0.5, mu = 100;
constant Integer N = 100;
Real u[N];
initial equation
for i in 1:33 loop
u[i] = 1;
end for;
equation
der(u[1]) = ((-u[1]) + 1) * N - mu * u[1] * (u[1] - alpha) * (u[1] - 1);
for j in 2:N loop
der(u[j]) = ((-u[j]) + u[j - 1]) * N - mu * u[j] * (u[j] - alpha) * (u[j] - 1);
end for;
end advection; ");
setDebugFlags("fmuExperimental");
translateModelFMU(advection ,"2","me","<default>");
getErrorString();
system("unzip -cqq advection.fmu sources/advection.c | grep \"void advection_functionODE_Partial(\"");

// Result:
// true
// true
// "SimCode: The model advection has been translated to FMU"
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// void advection_functionODE_Partial(DATA *data, threadData_t *threadData, int i)
// 0

1 change: 1 addition & 0 deletions simulation/modelica/nonlinear_system/Makefile
Expand Up @@ -44,6 +44,7 @@ problem8_newton.mos \
problem9.mos \
problem10.mos \
problem11.mos \
problem12.mos \

# test that currently fail. Move up when fixed.
# Run make testfailing
Expand Down
19 changes: 19 additions & 0 deletions simulation/modelica/nonlinear_system/nlsTestPackage.mo
Expand Up @@ -149,4 +149,23 @@ package nonlinear_system

end problem11;

model problem12
function f1
input Real x;
input Real y;
input Integer n;
output Real z;
algorithm
z := 1;
for i in 1:n loop
z := z*(x+y);
end for;
end f1;
Real x,y,z;
equation
x^4 = y - 1;
y -3*x^2 + 1 = z*(1-time);
z = f1(x,y,5);
end problem12;

end nonlinear_system;
44 changes: 44 additions & 0 deletions simulation/modelica/nonlinear_system/problem12.mos
@@ -0,0 +1,44 @@
// name: problem12
// status: correct
// teardown_command: rm -f nonlinear_system.problem12* output.log

loadFile("nlsTestPackage.mo"); getErrorString();

simulate(nonlinear_system.problem12); getErrorString();

val(x,{0.0, 0.5, 1.0});
val(y,{0.0, 0.5, 1.0});
val(z,{0.0, 0.5, 1.0});

setCommandLineOptions("+d=NLSanalyticJacobian");
simulate(nonlinear_system.problem12); getErrorString();

val(x,{0.0, 0.5, 1.0});
val(y,{0.0, 0.5, 1.0});
val(z,{0.0, 0.5, 1.0});

// Result:
// true
// ""
// record SimulationResult
// resultFile = "nonlinear_system.problem12_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'nonlinear_system.problem12', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
// "
// {0.1413741945152485,0.2812491225132911,1.0}
// {1.000399466692872,1.006256979103416,2.0}
// {1.940439478068367,3.537907544719854,243.0}
// true
// record SimulationResult
// resultFile = "nonlinear_system.problem12_res.mat",
// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'nonlinear_system.problem12', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
// messages = ""
// end SimulationResult;
// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information.
// "
// {0.1413741945152598,0.2812491225131152,1.0}
// {1.000399466692872,1.0062569791034,2.0}
// {1.940439478068463,3.537907544717219,243.0}
// endResult

0 comments on commit bdd216d

Please sign in to comment.