diff --git a/flattening/modelica/redeclare/Makefile b/flattening/modelica/redeclare/Makefile index 9e63802a168..cd917abcd95 100644 --- a/flattening/modelica/redeclare/Makefile +++ b/flattening/modelica/redeclare/Makefile @@ -33,6 +33,7 @@ Redeclare4.mo \ Redeclare5.mo \ Redeclare6.mo \ Redeclare6.mos \ +RedeclareArrayComponent1.mo \ RedeclareBaseClass1.mo \ RedeclareClass1.mo \ RedeclareClass4.mo \ diff --git a/flattening/modelica/redeclare/RedeclareArrayComponent1.mo b/flattening/modelica/redeclare/RedeclareArrayComponent1.mo new file mode 100644 index 00000000000..328e587771d --- /dev/null +++ b/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 diff --git a/openmodelica/bootstrapping/LoadCompilerSources.mos b/openmodelica/bootstrapping/LoadCompilerSources.mos index afd86b11417..9b44927ddff 100644 --- a/openmodelica/bootstrapping/LoadCompilerSources.mos +++ b/openmodelica/bootstrapping/LoadCompilerSources.mos @@ -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", @@ -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", diff --git a/openmodelica/cppruntime/Makefile b/openmodelica/cppruntime/Makefile index bd0a736ad83..8fc8b65be98 100644 --- a/openmodelica/cppruntime/Makefile +++ b/openmodelica/cppruntime/Makefile @@ -5,6 +5,7 @@ tearnonlin1.mos \ WhenStatement1.mos \ BouncingBall.mos \ clockedTest.mos \ +clockedTypesTest.mos \ mathFunctionsTest.mos \ functionPointerTest.mos \ recordTupleReturnTest.mos \ diff --git a/openmodelica/cppruntime/clockedTest.mos b/openmodelica/cppruntime/clockedTest.mos index 7ba6f1f6e61..fbe07a54b56 100644 --- a/openmodelica/cppruntime/clockedTest.mos +++ b/openmodelica/cppruntime/clockedTest.mos @@ -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; diff --git a/openmodelica/cppruntime/clockedTypesTest.mos b/openmodelica/cppruntime/clockedTypesTest.mos new file mode 100644 index 00000000000..a4886a21a29 --- /dev/null +++ b/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 diff --git a/openmodelica/cppruntime/fmu/modelExchange/2.0/Makefile b/openmodelica/cppruntime/fmu/modelExchange/2.0/Makefile index 0f1cfc18e84..218eaf1d713 100644 --- a/openmodelica/cppruntime/fmu/modelExchange/2.0/Makefile +++ b/openmodelica/cppruntime/fmu/modelExchange/2.0/Makefile @@ -2,7 +2,8 @@ TEST = ../../../../../rtest -v TESTFILES = \ -DIC_FMU2_CPP.mos +DIC_FMU2_CPP.mos \ +testModelDescription.mos FAILINGTESTFILES = \ CoupledClutches_FMU2_CPP.mos diff --git a/openmodelica/cppruntime/fmu/modelExchange/2.0/testModelDescription.mos b/openmodelica/cppruntime/fmu/modelExchange/2.0/testModelDescription.mos new file mode 100644 index 00000000000..8205aed3511 --- /dev/null +++ b/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 +// " +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// " +// endResult diff --git a/openmodelica/fmi/ModelExchange/2.0/Makefile b/openmodelica/fmi/ModelExchange/2.0/Makefile index 49c9c74ad71..5202f0bf3c3 100644 --- a/openmodelica/fmi/ModelExchange/2.0/Makefile +++ b/openmodelica/fmi/ModelExchange/2.0/Makefile @@ -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 diff --git a/openmodelica/fmi/ModelExchange/2.0/testExperimentalFMU.mos b/openmodelica/fmi/ModelExchange/2.0/testExperimentalFMU.mos new file mode 100644 index 00000000000..80c05f08f20 --- /dev/null +++ b/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",""); +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 + diff --git a/simulation/modelica/nonlinear_system/Makefile b/simulation/modelica/nonlinear_system/Makefile index 2eca76ac40d..0cf3552ea19 100644 --- a/simulation/modelica/nonlinear_system/Makefile +++ b/simulation/modelica/nonlinear_system/Makefile @@ -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 diff --git a/simulation/modelica/nonlinear_system/nlsTestPackage.mo b/simulation/modelica/nonlinear_system/nlsTestPackage.mo index f3415d7a575..7f0654bd197 100644 --- a/simulation/modelica/nonlinear_system/nlsTestPackage.mo +++ b/simulation/modelica/nonlinear_system/nlsTestPackage.mo @@ -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; diff --git a/simulation/modelica/nonlinear_system/problem12.mos b/simulation/modelica/nonlinear_system/problem12.mos new file mode 100644 index 00000000000..82c1107da90 --- /dev/null +++ b/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 diff --git a/simulation/modelica/others/Makefile b/simulation/modelica/others/Makefile index c7bd559b034..d2799a39d63 100644 --- a/simulation/modelica/others/Makefile +++ b/simulation/modelica/others/Makefile @@ -52,6 +52,22 @@ TestLapack.mos \ TestExpressionSolve.mos \ TestNormVar.mos \ TestSolve.mos \ +TestSolve2.mos \ +TestSolve3.mos \ +TestSolve4.mos \ +TestSolve5.mos \ +TestSolve6.mos \ +TestSolve7.mos \ +TestSolve8.mos \ +TestSolve9.mos \ +TestSolve10.mos \ +TestSolve11.mos \ +TestSolve12.mos \ +TestSolve13.mos \ +TestSolve14.mos \ +TestSolve15.mos \ +TestSolve16.mos \ +TestSolve17.mos \ VariableFilter.mos \ WhenStatement4.mos @@ -64,6 +80,7 @@ pendulum4.mos \ SpaceProbe.mos \ filterTest.mos \ Bug1048.mos \ +TestSolve18.mos \ # Dependency files that are not .mo .mos or Makefile # Add them here or they will be cleaned. diff --git a/simulation/modelica/others/TestSolve.mo b/simulation/modelica/others/TestSolve.mo deleted file mode 100644 index e000dafb97d..00000000000 --- a/simulation/modelica/others/TestSolve.mo +++ /dev/null @@ -1,258 +0,0 @@ -model ModelTestSolve - Real x,y,z; -equation - ( 1 / x ) * 2 = 1; - ( y / 1 ) * 2 = 1; - 4 = ( 1 / z ) * 3; -end ModelTestSolve; - -model ModelTestSolve2 - Real[12] x(each start = -1); - Real y[:] = array(-1 * (-1) ^ i * min(max(abs((-1) ^ i * time ^ i + sin(time ^ i) + cos(i * time) + i), 1e-5), 10 + sin(time ^ i)) for i in 1:10); -equation - x[1] * y[2] + y[3] * x[1] + y[4] * x[1] * y[3] + y[5] * (x[1] * y[4]) + y[7] * y[1] * y[9] * x[1] + y[1] * x[1] ^ 1 = 10 ^ time; - sqrt(x[2] + y[1] * x[2]) = time; - x[3] ^ 3 = x[2]; - (x[4] * y[1]) ^ 3 * x[4] ^ 4 = x[2]; - exp(y[3] * sinh(x[5]) + time) = 1; - abs(x[6] - sin(time)) = 0; - x[7] = time * x[7] ^ (-2); - abs((x[8] + x[8]*exp(sum(y))-(10-(sum(y))))) ^ 2 = 0; - x[9]*(x[8]+10) = time-1; - (if time < 0 then tanh((sinh((log(x[10]-1))^5-1))^3-1) else x[10]) = 10; - x[11] = sqrt(delay(x[11],0.01) + time); - exp(x[12]) * y[2] + y[3] * exp(x[12]) + y[4] * exp(x[12]) * y[3] + y[5] * (x[1] * y[4]) + y[7] * y[1] * y[9] * exp(x[12]) + y[1] * exp(x[12]) ^ 1 = 10 ^ time; - -end ModelTestSolve2; - -model ModelTestSolve3 - Real x,y,z,w,v; -equation - sin(x) = sqrt(-cos(x)^2 + x); - sinh(y)/cosh(y) = min(time+0.5,10/11); - exp(log(sqrt(z))) = exp(log(sqrt(3*z+time))); - y*sinh(w) = z*cosh(w); - cosh(v*(w+1) + time*10) = sinh(v*(w+1)+time*10); -end ModelTestSolve3; - - - -model ModelTestSolve4 -" -test: cosh, sinh, tanh -" - constant Real s[:] = {-1,1}; - Real[2] x(start=s); - Real[2] y(start=s); - Real[2] z(start=s); - Real err[6]; - Real Err (start = 0, fixed = true); -equation - for i in 1:2 loop - cosh(x[i]) = 1.1 + 0.5*time; - sinh(y[i]) = 1.1 + 0.5*time; - tanh(z[i]) = 0.5*time; - err[(i-1)*3 +1] = abs(-cosh(x[i]) + 1.1 + 0.5*time); - err[(i-1)*3 +2] = abs(-sinh(y[i]) + 1.1 + 0.5*time); - err[(i-1)*3 +3] = abs(-tanh(z[i]) + 0.5*time); - end for; - - der(Err) = sum(err); -end ModelTestSolve4; - - -model ModelTestSolve5 -" -test: cos, sin, tan -" - constant Real s[:] = {-1,1}; - Real[2] x(start=s); - Real[2] y(start=s); - Real[2] z(start=s); - Real err[6]; - Real Err (start = 0, fixed = true); -equation - - for i in 1:2 loop - cos(x[i]) = 0.5*time; - sin(y[i]) = 0.5*time; - tan(z[i]) = 0.5*time; - err[(i-1)*3 +1] = abs(-cos(x[i]) + 0.5*time); - err[(i-1)*3 +2] = abs(-sin(y[i]) + 0.5*time); - err[(i-1)*3 +3] = abs(-tan(z[i]) + 0.5*time); - end for; - - der(Err) = sum(err); -end ModelTestSolve5; - -model ModelTestSolve6 - Real x(start=0); - Real y(start=4); - Real z(start=10); - Real w; -equation - cos(x) = time; - cos(y) = time; - cos(z) = time; - w = acos(time); -end ModelTestSolve6; - -model ModelTestSolve7 - Real x(start=0); - Real y(start=4); - Real z(start=10); - Real w; -equation - sin(x) = time; - sin(y) = time; - sin(z) = time; - w = asin(time); -end ModelTestSolve7; - -model ModelTestSolve8 - Real x(start=0); - Real y(start=4); - Real z(start=10); - Real w; -equation - tan(x) = time; - tan(y) = time; - tan(z) = time; - w = atan(time); -end ModelTestSolve8; - -model ModelTestSolve9 - Real x(start=-1); - Real y(start=-4); - Real z(start=-10); - Real w; -equation - cos(x) = time; - cos(y) = time; - cos(z) = time; - w = acos(time); -end ModelTestSolve9; - -model ModelTestSolve10 - Real x(start=-1); - Real y(start=-4); - Real z(start=-10); - Real w; -equation - sin(x) = time; - sin(y) = time; - sin(z) = time; - w = asin(time); -end ModelTestSolve10; - -model ModelTestSolve11 - Real x(start=0); - Real y(start=4); - Real z(start=10); - Real w; -equation - tan(x) = time; - tan(y) = time; - tan(z) = time; - w = atan(time); -end ModelTestSolve11; - -model ModelTestSolve12 - Real x(start=-1); - Real y; - Real z(start=6); - Real v(start=-6); - Real w; -equation - z = sin(time)^2; - y = cos(z); - cos(x+cos(z)+w) = time; - cos(x+cos(v)+w) = time; - w = acos(time); -end ModelTestSolve12; - -model ModelTestSolve13 - Real x(start=-1); - Real y; - Real z(start=6); - Real v(start=-6); - Real w; -equation - z = sin(time)^2; - y = cos(z); - cos(x+z+w) = time; - cos(x+v+w) = time; - w = acos(time); -end ModelTestSolve13; - -model ModelTestSolve14 - Real x(start=-1); - Real y; - Real z(start=6); - Real v(start=-6); - Real w; -equation - abs(z) = sin(time)^2; - abs(y) = cos(z); - abs(cos(x+z+w)) = time; - abs(cos(x+v+w)) = time; - abs(w) = acos(time); -end ModelTestSolve14; - -model ModelTestSolve15 - Real x(start=-1); - Real y(start=1); - Real z(start=6); - Real v(start=-6); - Real w(start = 5); -equation - (z)^4 = exp(time)^2; - (y)^2 = exp(cos(z)); - (log(abs(x+z+w)))^(exp(z)+1) = exp(time); - (log(abs(x+v+w)))^(exp(z)+1) = exp(time); - abs(w) = exp(acos(time)); -end ModelTestSolve15; - -model ModelTestSolve16 - Real x(start=-1); - Real y(start=1); - Real z(start=6); - Real v(start=-6); - Real w(start = 5); - Real a1,a2; -equation - (z)^4 = exp(time)^2; - (y)^2 = exp(cos(z)); - (log(abs(x+z+w)))^(exp(z)+1) = exp(time); - (log(abs(x+v+w)))^(exp(z)+1) = exp(time); - abs(w) = exp(acos(time)); - a1 = abs(x+z+w); - a2 = abs(x+v+w); -end ModelTestSolve16; - -model ModelTestSolve17 - Real x,y,z(start=2),w,v; - Real res(start=0,fixed=true); -equation - (1/x)^4 = exp(time+1); - (1/x + log10(y))^(max(abs(x),4)) = max(sqrt(exp(2+7*time)),50); - (exp(sqrt(1-z)))^(x) = x^2+time+1; - log(sqrt(((v-1))+1/y))^20 = y^2*exp(-10*time-100); - (sin(1/x + 1/v + 1/(sqrt(abs(z)/(z^2))) + 1/z) + sin(1/x) + sqrt(abs(v-1))*sqrt(w-1))^x = 0; - - der(res) = abs((1/x)^4 - exp(time+1)) + abs( (1/x + log10(y))^(max(abs(x),4)) - max(sqrt(exp(2+7*time)),50)) - + abs((exp(sqrt(1-z)))^(x) -( x^2+time+1)) + abs(log(sqrt(((v-1))+1/y))^20 - y^2*exp(-10*time-100)) - + abs((sin(1/x + 1/v + 1/(sqrt(abs(z)/(z^2))) + 1/z) + sin(1/x) + sqrt(abs(v-1))*sqrt(w-1))^x); -end ModelTestSolve17; - -model ModelTestSolve18 - parameter Real x(fixed=false),y(fixed=false); - Real z; -initial equation - time = 5*(exp(sign(2*x + 1))-1); - time = y*(exp(if y>0 then time else 2*time))-1; -equation - der(z) = x-y; -end ModelTestSolve18; - - diff --git a/simulation/modelica/others/TestSolve.mos b/simulation/modelica/others/TestSolve.mos index 18706f37310..961ae959360 100644 --- a/simulation/modelica/others/TestSolve.mos +++ b/simulation/modelica/others/TestSolve.mos @@ -1,149 +1,23 @@ // name: TestSolve // status: correct -// teardown_command: rm -f ModelTestSolve* output.log // // Checks that the backend knows how to solve certain expressions // -loadFile("TestSolve.mo");getErrorString(); -simulate(ModelTestSolve, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); - -simulate(ModelTestSolve2,simflags="-lv LOG_NLS_V"); -val(x[1],0.0); -val(x[2],0.0); -val(x[3],0.0); -val(x[4],0.0); -val(x[5],0.0); -val(x[6],0.0); -val(x[7],0.0); -val(x[8],0.0); -val(x[9],0.0); -val(x[10],0.0); -val(x[11],0.0); -val(x[12],0.0); -val(x[1],1.0); -val(x[2],1.0); -val(x[3],1.0); -val(x[4],1.0); -val(x[5],1.0); -val(x[6],1.0); -val(x[7],1.0); -val(x[8],1.0); -val(x[9],1.0); -val(x[10],1.0); -val(x[11],1.0); -val(x[12],1.0); - -simulate(ModelTestSolve3, simflags="-lv LOG_NLS_V"); -val(x,0.0); -val(y,0.0); -val(z,0.0); -val(w,0.0); -val(v,0.0); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); -val(v,0.5); - -simulate(ModelTestSolve4, simflags="-lv LOG_NLS_V"); -val(x[1],0.5); -val(y[1],0.5); -val(z[1],0.5); -val(x[2],0.5); -val(y[2],0.5); -val(z[2],0.5); -val(Err,1); - -simulate(ModelTestSolve5, simflags="-lv LOG_NLS_V"); -val(x[1],0.5); -val(y[1],0.5); -val(z[1],0.5); -val(x[2],0.5); -val(y[2],0.5); -val(z[2],0.5); -val(Err,1); - -simulate(ModelTestSolve6, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve7, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve8, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve9, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve10, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve11, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); - -simulate(ModelTestSolve12, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); -val(v,0.5); - -simulate(ModelTestSolve13, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); -val(v,0.5); - -simulate(ModelTestSolve14, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); -val(v,0.5); +loadString(" +model ModelTestSolve + Real x,y,z; +equation + ( 1 / x ) * 2 = 1; + ( y / 1 ) * 2 = 1; + 4 = ( 1 / z ) * 3; +end ModelTestSolve; +"); getErrorString(); -simulate(ModelTestSolve15, simflags="-lv LOG_NLS_V"); +simulate(ModelTestSolve, simflags="-lv LOG_NLS_V"); getErrorString(); val(x,0.5); val(y,0.5); val(z,0.5); -val(w,0.5); -val(v,0.5); - -simulate(ModelTestSolve16, simflags="-lv LOG_NLS_V"); -val(x,0.5); -val(y,0.5); -val(z,0.5); -val(w,0.5); -val(v,0.5); - -simulate(ModelTestSolve17, simflags="-lv LOG_NLS_V -s euler", stopTime=0.1); -val(res,0.1); -val(res,0.0); - -simulate(ModelTestSolve18, tolerance=0.001); -val(z,1.0) // Result: // true @@ -158,276 +32,8 @@ val(z,1.0) // LOG_NLS | info | free non-linear system solvers // " // end SimulationResult; +// "" // 2.0 // 0.5 // 0.75 -// record SimulationResult -// resultFile = "ModelTestSolve2_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve2', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.008849557522123894 -// 0.0 -// 0.0 -// 0.0 -// 0.0 -// 0.0 -// 0.0 -// 13.74819306053072 -// -0.04210846684003049 -// 10.0 -// 0.0 -// -4.727387818712341 -// 0.2134742295027177 -// 0.419855241434907 -// 0.748801190865333 -// 0.769077109674782 -// -0.5167956387245741 -// 0.8414709848078965 -// 1.0 -// 24.06811711311686 -// 0.0 -// 10.0 -// 1.616020834119052 -// -1.544239158504185 -// record SimulationResult -// resultFile = "ModelTestSolve3_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve3', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 1.0 -// 0.5493061443340549 -// -0.0 -// 0.0 -// -0.0 -// 1.0 -// 1.522261218861711 -// -0.25 -// -0.1657302257256409 -// -5.993265193323057 -// record SimulationResult -// resultFile = "ModelTestSolve4_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve4', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -0.8140001025611593 -// 1.108572441796849 -// 0.2554128118829954 -// 0.8140001025611594 -// 1.108572441796849 -// 0.2554128118829954 -// 6.797090936218891e-16 -// record SimulationResult -// resultFile = "ModelTestSolve5_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve5', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -1.318116071652818 -// 0.2526802551420786 -// 0.2449786631268641 -// 1.318116071652818 -// 0.2526802551420786 -// 0.2449786631268641 -// 2.621263568911969e-17 -// record SimulationResult -// resultFile = "ModelTestSolve6_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 1.047197551196598 -// 5.235987755982988 -// 11.51917306316257 -// 1.047197551196598 -// record SimulationResult -// resultFile = "ModelTestSolve7_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve7', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.5235987755982989 -// 2.617993877991494 -// 8.901179185171081 -// 0.5235987755982989 -// record SimulationResult -// resultFile = "ModelTestSolve8_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve8', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.4636476090008061 -// 3.605240262590599 -// 9.888425569770185 -// 0.4636476090008061 -// record SimulationResult -// resultFile = "ModelTestSolve9_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve9', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -1.047197551196598 -// -5.235987755982988 -// -11.51917306316257 -// 1.047197551196598 -// record SimulationResult -// resultFile = "ModelTestSolve10_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve10', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.5235987755982989 -// -3.665191429188092 -// -9.948376736367678 -// 0.5235987755982989 -// record SimulationResult -// resultFile = "ModelTestSolve11_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve11', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.4636476090008061 -// 3.605240262590599 -// 9.888425569770185 -// 0.4636476090008061 -// record SimulationResult -// resultFile = "ModelTestSolve12_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve12', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -0.9737008433540479 -// 0.9737008433540479 -// 0.2298488470659301 -// 1.047197551196598 -// -6.053336460113656 -// record SimulationResult -// resultFile = "ModelTestSolve13_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve13', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -0.2298488470659301 -// 0.9737008433540479 -// 0.2298488470659301 -// 1.047197551196598 -// -6.053336460113655 -// record SimulationResult -// resultFile = "ModelTestSolve14_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve14', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -0.2298488470659301 -// 0.9737008433540479 -// 0.2298488470659301 -// 1.047197551196598 -// -6.053336460113655 -// record SimulationResult -// resultFile = "ModelTestSolve15_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve15', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -1.085543757874853 -// 1.151917842006256 -// 1.284025416687741 -// 2.849653908226362 -// -4.812245717390759 -// record SimulationResult -// resultFile = "ModelTestSolve16_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve16', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// -3.805609927078452 -// 1.151917842006256 -// 1.284025416687741 -// 2.849653908226362 -// 0.6278866210164383 -// record SimulationResult -// resultFile = "ModelTestSolve17_res.mat", -// simulationOptions = "startTime = 0.0, stopTime = 0.1, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve17', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V -s euler'", -// messages = "LOG_NLS | info | initialize mixed system solvers -// LOG_NLS | info | initialize non-linear system solvers -// LOG_NLS | info | update static data of non-linear system solvers -// LOG_NLS | info | free mixed system solvers -// LOG_NLS | info | free non-linear system solvers -// " -// end SimulationResult; -// 0.07916290493249628 -// 0.0 -// record SimulationResult -// resultFile = "", -// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 0.001, method = 'dassl', fileNamePrefix = 'ModelTestSolve18', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", -// messages = "Simulation execution failed for model: ModelTestSolve18 -// assert | debug | Solving non-linear system 5 failed at time=0. -// | | | | For more information please use -lv LOG_NLS. -// assert | info | simulation terminated by an assertion at initialization -// " -// end SimulationResult; -// NaN // endResult diff --git a/simulation/modelica/others/TestSolve10.mos b/simulation/modelica/others/TestSolve10.mos new file mode 100644 index 00000000000..1bd0e5d7850 --- /dev/null +++ b/simulation/modelica/others/TestSolve10.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve10 + Real x(start=-1); + Real y(start=-4); + Real z(start=-10); + Real w; +equation + sin(x) = time; + sin(y) = time; + sin(z) = time; + w = asin(time); +end ModelTestSolve10; +"); getErrorString(); + +simulate(ModelTestSolve10, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve10_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve10', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 0.5235987755982989 +// -3.665191429188092 +// -9.948376736367678 +// 0.5235987755982989 +// endResult diff --git a/simulation/modelica/others/TestSolve11.mos b/simulation/modelica/others/TestSolve11.mos new file mode 100644 index 00000000000..d6811071be3 --- /dev/null +++ b/simulation/modelica/others/TestSolve11.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve11 + Real x(start=0); + Real y(start=4); + Real z(start=10); + Real w; +equation + tan(x) = time; + tan(y) = time; + tan(z) = time; + w = atan(time); +end ModelTestSolve11; +"); getErrorString(); + +simulate(ModelTestSolve11, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve11_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve11', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 0.4636476090008061 +// 3.605240262590599 +// 9.888425569770185 +// 0.4636476090008061 +// endResult diff --git a/simulation/modelica/others/TestSolve12.mos b/simulation/modelica/others/TestSolve12.mos new file mode 100644 index 00000000000..8a07c0eaf89 --- /dev/null +++ b/simulation/modelica/others/TestSolve12.mos @@ -0,0 +1,49 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve12 + Real x(start=-1); + Real y; + Real z(start=6); + Real v(start=-6); + Real w; +equation + z = sin(time)^2; + y = cos(z); + cos(x+cos(z)+w) = time; + cos(x+cos(v)+w) = time; + w = acos(time); +end ModelTestSolve12; +"); getErrorString(); + +simulate(ModelTestSolve12, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve12_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve12', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -0.9737008433540479 +// 0.9737008433540479 +// 0.2298488470659301 +// 1.047197551196598 +// -6.053336460113656 +// endResult diff --git a/simulation/modelica/others/TestSolve13.mos b/simulation/modelica/others/TestSolve13.mos new file mode 100644 index 00000000000..a5b7f26ad49 --- /dev/null +++ b/simulation/modelica/others/TestSolve13.mos @@ -0,0 +1,49 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve13 + Real x(start=-1); + Real y; + Real z(start=6); + Real v(start=-6); + Real w; +equation + z = sin(time)^2; + y = cos(z); + cos(x+z+w) = time; + cos(x+v+w) = time; + w = acos(time); +end ModelTestSolve13; +"); getErrorString(); + +simulate(ModelTestSolve13, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve13_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve13', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -0.2298488470659301 +// 0.9737008433540479 +// 0.2298488470659301 +// 1.047197551196598 +// -6.053336460113655 +// endResult diff --git a/simulation/modelica/others/TestSolve14.mos b/simulation/modelica/others/TestSolve14.mos new file mode 100644 index 00000000000..df1c01425d8 --- /dev/null +++ b/simulation/modelica/others/TestSolve14.mos @@ -0,0 +1,50 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve14 + Real x(start=-1); + Real y; + Real z(start=6); + Real v(start=-6); + Real w; +equation + abs(z) = sin(time)^2; + abs(y) = cos(z); + abs(cos(x+z+w)) = time; + abs(cos(x+v+w)) = time; + abs(w) = acos(time); +end ModelTestSolve14; +"); getErrorString(); + +simulate(ModelTestSolve14, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve14_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve14', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information. +// " +// -0.2298488470659301 +// 0.9737008433540479 +// 0.2298488470659301 +// 1.047197551196598 +// -6.053336460113655 +// endResult diff --git a/simulation/modelica/others/TestSolve15.mos b/simulation/modelica/others/TestSolve15.mos new file mode 100644 index 00000000000..ffbdb46f26f --- /dev/null +++ b/simulation/modelica/others/TestSolve15.mos @@ -0,0 +1,49 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve15 + Real x(start=-1); + Real y(start=1); + Real z(start=6); + Real v(start=-6); + Real w(start = 5); +equation + (z)^4 = exp(time)^2; + (y)^2 = exp(cos(z)); + (log(abs(x+z+w)))^(exp(z)+1) = exp(time); + (log(abs(x+v+w)))^(exp(z)+1) = exp(time); + abs(w) = exp(acos(time)); +end ModelTestSolve15; +"); getErrorString(); + +simulate(ModelTestSolve15, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve15_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve15', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -1.085543757874853 +// 1.151917842006256 +// 1.284025416687741 +// 2.849653908226362 +// -4.812245717390759 +// endResult diff --git a/simulation/modelica/others/TestSolve16.mos b/simulation/modelica/others/TestSolve16.mos new file mode 100644 index 00000000000..7c57ee629df --- /dev/null +++ b/simulation/modelica/others/TestSolve16.mos @@ -0,0 +1,53 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve16 + Real x(start=-1); + Real y(start=1); + Real z(start=6); + Real v(start=-6); + Real w(start = 5); + Real a1,a2; +equation + (z)^4 = exp(time)^2; + (y)^2 = exp(cos(z)); + (log(abs(x+z+w)))^(exp(z)+1) = exp(time); + (log(abs(x+v+w)))^(exp(z)+1) = exp(time); + abs(w) = exp(acos(time)); + a1 = abs(x+z+w); + a2 = abs(x+v+w); +end ModelTestSolve16; +"); getErrorString(); + +simulate(ModelTestSolve16, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve16_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve16', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information. +// " +// -3.805609927078452 +// 1.151917842006256 +// 1.284025416687741 +// 2.849653908226362 +// 0.6278866210164383 +// endResult diff --git a/simulation/modelica/others/TestSolve17.mos b/simulation/modelica/others/TestSolve17.mos new file mode 100644 index 00000000000..5a28610fe72 --- /dev/null +++ b/simulation/modelica/others/TestSolve17.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve17 + Real x,y,z(start=2),w,v; + Real res(start=0,fixed=true); +equation + (1/x)^4 = exp(time+1); + (1/x + log10(y))^(max(abs(x),4)) = max(sqrt(exp(2+7*time)),50); + (exp(sqrt(1-z)))^(x) = x^2+time+1; + log(sqrt(((v-1))+1/y))^20 = y^2*exp(-10*time-100); + (sin(1/x + 1/v + 1/(sqrt(abs(z)/(z^2))) + 1/z) + sin(1/x) + sqrt(abs(v-1))*sqrt(w-1))^x = 0; + + der(res) = abs((1/x)^4 - exp(time+1)) + abs( (1/x + log10(y))^(max(abs(x),4)) - max(sqrt(exp(2+7*time)),50)) + + abs((exp(sqrt(1-z)))^(x) -( x^2+time+1)) + abs(log(sqrt(((v-1))+1/y))^20 - y^2*exp(-10*time-100)) + + abs((sin(1/x + 1/v + 1/(sqrt(abs(z)/(z^2))) + 1/z) + sin(1/x) + sqrt(abs(v-1))*sqrt(w-1))^x); +end ModelTestSolve17; +"); getErrorString(); + +simulate(ModelTestSolve17, simflags="-lv LOG_NLS_V -s euler", stopTime=0.1); getErrorString(); +val(res,0.1); +val(res,0.0); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve17_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 0.1, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve17', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V -s euler'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "Warning: There are iteration variables with default zero start attribute. Use +d=initialization for more information. +// " +// 0.07916290493249595 +// 0.0 +// endResult diff --git a/simulation/modelica/others/TestSolve18.mos b/simulation/modelica/others/TestSolve18.mos new file mode 100644 index 00000000000..b262f920d47 --- /dev/null +++ b/simulation/modelica/others/TestSolve18.mos @@ -0,0 +1,23 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve18 + parameter Real x(fixed=false),y(fixed=false); + Real z; +initial equation + time = 5*(exp(sign(2*x + 1))-1); + time = y*(exp(if y>0 then time else 2*time))-1; +equation + der(z) = x-y; +end ModelTestSolve18; +"); getErrorString(); + +simulate(ModelTestSolve18, tolerance=0.001); getErrorString(); +val(z,1.0); + +// Result: +// endResult diff --git a/simulation/modelica/others/TestSolve2.mos b/simulation/modelica/others/TestSolve2.mos new file mode 100644 index 00000000000..239581f5c93 --- /dev/null +++ b/simulation/modelica/others/TestSolve2.mos @@ -0,0 +1,91 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve2 + Real[12] x(each start = -1); + Real y[:] = array(-1 * (-1) ^ i * min(max(abs((-1) ^ i * time ^ i + sin(time ^ i) + cos(i * time) + i), 1e-5), 10 + sin(time ^ i)) for i in 1:10); +equation + x[1] * y[2] + y[3] * x[1] + y[4] * x[1] * y[3] + y[5] * (x[1] * y[4]) + y[7] * y[1] * y[9] * x[1] + y[1] * x[1] ^ 1 = 10 ^ time; + sqrt(x[2] + y[1] * x[2]) = time; + x[3] ^ 3 = x[2]; + (x[4] * y[1]) ^ 3 * x[4] ^ 4 = x[2]; + exp(y[3] * sinh(x[5]) + time) = 1; + abs(x[6] - sin(time)) = 0; + x[7] = time * x[7] ^ (-2); + abs((x[8] + x[8]*exp(sum(y))-(10-(sum(y))))) ^ 2 = 0; + x[9]*(x[8]+10) = time-1; + (if time < 0 then tanh((sinh((log(x[10]-1))^5-1))^3-1) else x[10]) = 10; + x[11] = sqrt(delay(x[11],0.01) + time); + exp(x[12]) * y[2] + y[3] * exp(x[12]) + y[4] * exp(x[12]) * y[3] + y[5] * (x[1] * y[4]) + y[7] * y[1] * y[9] * exp(x[12]) + y[1] * exp(x[12]) ^ 1 = 10 ^ time; +end ModelTestSolve2; +"); getErrorString(); + +simulate(ModelTestSolve2,simflags="-lv LOG_NLS_V"); getErrorString(); +val(x[1],0.0); +val(x[2],0.0); +val(x[3],0.0); +val(x[4],0.0); +val(x[5],0.0); +val(x[6],0.0); +val(x[7],0.0); +val(x[8],0.0); +val(x[9],0.0); +val(x[10],0.0); +val(x[11],0.0); +val(x[12],0.0); +val(x[1],1.0); +val(x[2],1.0); +val(x[3],1.0); +val(x[4],1.0); +val(x[5],1.0); +val(x[6],1.0); +val(x[7],1.0); +val(x[8],1.0); +val(x[9],1.0); +val(x[10],1.0); +val(x[11],1.0); +val(x[12],1.0); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve2_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve2', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 0.008849557522123894 +// 0.0 +// 0.0 +// 0.0 +// 0.0 +// 0.0 +// 0.0 +// 13.74819306053072 +// -0.04210846684003049 +// 10.0 +// 0.0 +// -4.727387818712341 +// 0.2134742295027176 +// 0.419855241434907 +// 0.748801190865333 +// 0.769077109674782 +// -0.5167956387245743 +// 0.8414709848078965 +// 1.0 +// 24.06811711311686 +// 0.0 +// 10.0 +// 1.616020834119052 +// -1.544239158504185 +// endResult diff --git a/simulation/modelica/others/TestSolve3.mos b/simulation/modelica/others/TestSolve3.mos new file mode 100644 index 00000000000..a6099aab725 --- /dev/null +++ b/simulation/modelica/others/TestSolve3.mos @@ -0,0 +1,55 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve3 + Real x,y,z,w,v; +equation + sin(x) = sqrt(-cos(x)^2 + x); + sinh(y)/cosh(y) = min(time+0.5,10/11); + exp(log(sqrt(z))) = exp(log(sqrt(3*z+time))); + y*sinh(w) = z*cosh(w); + cosh(v*(w+1) + time*10) = sinh(v*(w+1)+time*10); +end ModelTestSolve3; +"); getErrorString(); + +simulate(ModelTestSolve3, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.0); +val(y,0.0); +val(z,0.0); +val(w,0.0); +val(v,0.0); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); +val(v,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve3_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve3', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 1.0 +// 0.5493061443340549 +// -0.0 +// 0.0 +// -0.0 +// 1.0 +// 1.522261218861711 +// -0.25 +// -0.1657302257256409 +// -5.993265193323057 +// endResult diff --git a/simulation/modelica/others/TestSolve4.mos b/simulation/modelica/others/TestSolve4.mos new file mode 100644 index 00000000000..698255fa602 --- /dev/null +++ b/simulation/modelica/others/TestSolve4.mos @@ -0,0 +1,59 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// test: cosh, sinh, tanh + +loadString(" +model ModelTestSolve4 + constant Real s[:] = {-1,1}; + Real[2] x(start=s); + Real[2] y(start=s); + Real[2] z(start=s); + Real err[6]; + Real Err (start = 0, fixed = true); +equation + for i in 1:2 loop + cosh(x[i]) = 1.1 + 0.5*time; + sinh(y[i]) = 1.1 + 0.5*time; + tanh(z[i]) = 0.5*time; + err[(i-1)*3 +1] = abs(-cosh(x[i]) + 1.1 + 0.5*time); + err[(i-1)*3 +2] = abs(-sinh(y[i]) + 1.1 + 0.5*time); + err[(i-1)*3 +3] = abs(-tanh(z[i]) + 0.5*time); + end for; + + der(Err) = sum(err); +end ModelTestSolve4; +"); getErrorString(); + +simulate(ModelTestSolve4, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x[1],0.5); +val(y[1],0.5); +val(z[1],0.5); +val(x[2],0.5); +val(y[2],0.5); +val(z[2],0.5); +val(Err,1); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve4_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve4', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -0.8140001025611593 +// 1.108572441796849 +// 0.2554128118829954 +// 0.8140001025611594 +// 1.108572441796849 +// 0.2554128118829954 +// 6.797090936218891e-16 +// endResult diff --git a/simulation/modelica/others/TestSolve5.mos b/simulation/modelica/others/TestSolve5.mos new file mode 100644 index 00000000000..62e4c7b7541 --- /dev/null +++ b/simulation/modelica/others/TestSolve5.mos @@ -0,0 +1,60 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// test: cos, sin, tan + +loadString(" +model ModelTestSolve5 + constant Real s[:] = {-1,1}; + Real[2] x(start=s); + Real[2] y(start=s); + Real[2] z(start=s); + Real err[6]; + Real Err (start = 0, fixed = true); +equation + + for i in 1:2 loop + cos(x[i]) = 0.5*time; + sin(y[i]) = 0.5*time; + tan(z[i]) = 0.5*time; + err[(i-1)*3 +1] = abs(-cos(x[i]) + 0.5*time); + err[(i-1)*3 +2] = abs(-sin(y[i]) + 0.5*time); + err[(i-1)*3 +3] = abs(-tan(z[i]) + 0.5*time); + end for; + + der(Err) = sum(err); +end ModelTestSolve5; +"); getErrorString(); + +simulate(ModelTestSolve5, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x[1],0.5); +val(y[1],0.5); +val(z[1],0.5); +val(x[2],0.5); +val(y[2],0.5); +val(z[2],0.5); +val(Err,1); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve5_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve5', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -1.318116071652818 +// 0.2526802551420786 +// 0.2449786631268641 +// 1.318116071652818 +// 0.2526802551420786 +// 0.2449786631268641 +// 2.621263568911969e-17 +// endResult diff --git a/simulation/modelica/others/TestSolve6.mos b/simulation/modelica/others/TestSolve6.mos new file mode 100644 index 00000000000..d78bbba095a --- /dev/null +++ b/simulation/modelica/others/TestSolve6.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve6 + Real x(start=0); + Real y(start=4); + Real z(start=10); + Real w; +equation + cos(x) = time; + cos(y) = time; + cos(z) = time; + w = acos(time); +end ModelTestSolve6; +"); getErrorString(); + +simulate(ModelTestSolve6, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve6_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve6', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 1.047197551196598 +// 5.235987755982988 +// 11.51917306316257 +// 1.047197551196598 +// endResult diff --git a/simulation/modelica/others/TestSolve7.mos b/simulation/modelica/others/TestSolve7.mos new file mode 100644 index 00000000000..da1b1b16adc --- /dev/null +++ b/simulation/modelica/others/TestSolve7.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve7 + Real x(start=0); + Real y(start=4); + Real z(start=10); + Real w; +equation + sin(x) = time; + sin(y) = time; + sin(z) = time; + w = asin(time); +end ModelTestSolve7; +"); getErrorString(); + +simulate(ModelTestSolve7, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve7_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve7', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 0.5235987755982989 +// 2.617993877991494 +// 8.901179185171081 +// 0.5235987755982989 +// endResult diff --git a/simulation/modelica/others/TestSolve8.mos b/simulation/modelica/others/TestSolve8.mos new file mode 100644 index 00000000000..f96fc5b8974 --- /dev/null +++ b/simulation/modelica/others/TestSolve8.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve8 + Real x(start=0); + Real y(start=4); + Real z(start=10); + Real w; +equation + tan(x) = time; + tan(y) = time; + tan(z) = time; + w = atan(time); +end ModelTestSolve8; +"); getErrorString(); + +simulate(ModelTestSolve8, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve8_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve8', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// 0.4636476090008061 +// 3.605240262590599 +// 9.888425569770185 +// 0.4636476090008061 +// endResult diff --git a/simulation/modelica/others/TestSolve9.mos b/simulation/modelica/others/TestSolve9.mos new file mode 100644 index 00000000000..4a534ea1a45 --- /dev/null +++ b/simulation/modelica/others/TestSolve9.mos @@ -0,0 +1,45 @@ +// name: TestSolve +// status: correct +// +// Checks that the backend knows how to solve certain expressions +// + +loadString(" +model ModelTestSolve9 + Real x(start=-1); + Real y(start=-4); + Real z(start=-10); + Real w; +equation + cos(x) = time; + cos(y) = time; + cos(z) = time; + w = acos(time); +end ModelTestSolve9; +"); getErrorString(); + +simulate(ModelTestSolve9, simflags="-lv LOG_NLS_V"); getErrorString(); +val(x,0.5); +val(y,0.5); +val(z,0.5); +val(w,0.5); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "ModelTestSolve9_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ModelTestSolve9', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv LOG_NLS_V'", +// messages = "LOG_NLS | info | initialize mixed system solvers +// LOG_NLS | info | initialize non-linear system solvers +// LOG_NLS | info | update static data of non-linear system solvers +// LOG_NLS | info | free mixed system solvers +// LOG_NLS | info | free non-linear system solvers +// " +// end SimulationResult; +// "" +// -1.047197551196598 +// -5.235987755982988 +// -11.51917306316257 +// 1.047197551196598 +// endResult diff --git a/simulation/modelica/synchronous/DID.mo b/simulation/modelica/synchronous/DID.mo index 7ed44c0e756..c3811e9db55 100644 --- a/simulation/modelica/synchronous/DID.mo +++ b/simulation/modelica/synchronous/DID.mo @@ -12,4 +12,4 @@ equation y1 = if previous(first) then y1_start else previous(y1) + p * u * dt; y2 = if previous(first) then y2_start else previous(y2) + previous(y1)*dt + 0.5 * u * dt*dt; end when; -end DID; \ No newline at end of file +end DID; diff --git a/simulation/modelica/synchronous/Makefile b/simulation/modelica/synchronous/Makefile index 561d7c69082..be3f4fa8cd7 100644 --- a/simulation/modelica/synchronous/Makefile +++ b/simulation/modelica/synchronous/Makefile @@ -9,10 +9,14 @@ SynchronousFeatures.SpeedControl.mos \ SynchronousFeatures.ControlledMass.mos \ SynchronousFeatures.VaryingClock.mos \ WhenClocks.mos \ +Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mos \ +Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mos \ +Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mos \ # test that currently fail. Move up when fixed. # Run make failingtest FAILINGTESTFILES = \ +Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mos \ DID.mos \ # Dependency files that are not .mo .mos or Makefile diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mo b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mo new file mode 100644 index 00000000000..9c4e0542fa0 --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mo @@ -0,0 +1,224 @@ +package ModelicaServices "ModelicaServices (OpenModelica implementation) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation" + extends Modelica.Icons.Package; + + package Machine + extends Modelica.Icons.Package; + final constant Real eps = 1.e-15 "Biggest number such that 1.0 + eps = 1.0"; + final constant Real small = 1.e-60 "Smallest number such that small and -small are representable on the machine"; + final constant Real inf = 1.e+60 "Biggest Real number such that inf and -inf are representable on the machine"; + final constant Integer Integer_inf = OpenModelica.Internal.Architecture.integerMax() "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine"; + end Machine; + annotation(Protection(access = Access.hide), version = "3.2.1", versionBuild = 2, versionDate = "2013-08-14", dateModified = "2013-08-14 08:44:41Z"); +end ModelicaServices; + +package Modelica "Modelica Standard Library - Version 3.2.1 (Build 4)" + extends Modelica.Icons.Package; + + package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)" + extends Modelica.Icons.Package; + + package Interfaces "Library of connectors and partial models for input/output blocks" + extends Modelica.Icons.InterfacesPackage; + connector BooleanInput = input Boolean "'input Boolean' as connector"; + connector BooleanOutput = output Boolean "'output Boolean' as connector"; + end Interfaces; + end Blocks; + + package Math "Library of mathematical functions (e.g., sin, cos) and of functions operating on vectors and matrices" + extends Modelica.Icons.Package; + + package Icons "Icons for Math" + extends Modelica.Icons.IconsPackage; + + partial function AxisCenter "Basic icon for mathematical function with y-axis in the center" end AxisCenter; + end Icons; + + function asin "Inverse sine (-1 <= u <= 1)" + extends Modelica.Math.Icons.AxisCenter; + input Real u; + output .Modelica.SIunits.Angle y; + external "builtin" y = asin(u); + end asin; + + function exp "Exponential, base e" + extends Modelica.Math.Icons.AxisCenter; + input Real u; + output Real y; + external "builtin" y = exp(u); + end exp; + end Math; + + package Constants "Library of mathematical constants and constants of nature (e.g., pi, eps, R, sigma)" + extends Modelica.Icons.Package; + final constant Real pi = 2 * Math.asin(1.0); + final constant Real small = ModelicaServices.Machine.small "Smallest number such that small and -small are representable on the machine"; + final constant .Modelica.SIunits.Velocity c = 299792458 "Speed of light in vacuum"; + final constant Real mue_0(final unit = "N/A2") = 4 * pi * 1.e-7 "Magnetic constant"; + end Constants; + + package Icons "Library of icons" + extends Icons.Package; + + partial package ExamplesPackage "Icon for packages containing runnable examples" + extends Modelica.Icons.Package; + end ExamplesPackage; + + partial model Example "Icon for runnable examples" end Example; + + partial package Package "Icon for standard packages" end Package; + + partial package InterfacesPackage "Icon for packages containing interfaces" + extends Modelica.Icons.Package; + end InterfacesPackage; + + partial package SourcesPackage "Icon for packages containing sources" + extends Modelica.Icons.Package; + end SourcesPackage; + + partial package IconsPackage "Icon for packages containing icons" + extends Modelica.Icons.Package; + end IconsPackage; + end Icons; + + package SIunits "Library of type and unit definitions based on SI units according to ISO 31-1992" + extends Modelica.Icons.Package; + + package Conversions "Conversion functions to/from non SI units and type definitions of non SI units" + extends Modelica.Icons.Package; + + package NonSIunits "Type definitions of non SI units" + extends Modelica.Icons.Package; + type Temperature_degC = Real(final quantity = "ThermodynamicTemperature", final unit = "degC") "Absolute temperature in degree Celsius (for relative temperature use SIunits.TemperatureDifference)" annotation(absoluteValue = true); + end NonSIunits; + end Conversions; + + type Angle = Real(final quantity = "Angle", final unit = "rad", displayUnit = "deg"); + type Time = Real(final quantity = "Time", final unit = "s"); + type Velocity = Real(final quantity = "Velocity", final unit = "m/s"); + type Acceleration = Real(final quantity = "Acceleration", final unit = "m/s2"); + type FaradayConstant = Real(final quantity = "FaradayConstant", final unit = "C/mol"); + end SIunits; + annotation(version = "3.2.1", versionBuild = 4, versionDate = "2013-08-14", dateModified = "2015-09-30 09:15:00Z"); +end Modelica; + +package Modelica_Synchronous "Modelica_Synchronous (version 0.92 Build 2) - Basic synchronous input/output control blocks +that are triggered by clocks" + extends Modelica.Icons.Package; + + package Examples "Library of examples to demonstrate the usage of package Modelica_Synchronous" + extends Modelica.Icons.ExamplesPackage; + + package Elementary "Examples that are used for the documentation of the blocks" + extends Modelica.Icons.ExamplesPackage; + + package BooleanSignals "Examples that are used for the documentation of the Modelica_Synchronous.BooleanSignals sub-library" + extends Modelica.Icons.ExamplesPackage; + + model TimeBasedPulse "Example of using the clocked simulation time based Boolean Pulse source block" + extends Modelica.Icons.Example; + .Modelica_Synchronous.BooleanSignals.TimeBasedSources.Pulse pulse(width = 50, period = 0.4, startTime = 0.1); + .Modelica_Synchronous.ClockSignals.Clocks.PeriodicRealClock periodicClock1(period = 0.1); + .Modelica_Synchronous.BooleanSignals.Sampler.AssignClock assignClock1; + equation + connect(periodicClock1.y, assignClock1.clock); + connect(pulse.y, assignClock1.u); + annotation(experiment(StopTime = 1.0)); + end TimeBasedPulse; + end BooleanSignals; + end Elementary; + end Examples; + + package ClockSignals "Library of blocks for clocked signals" + extends Modelica.Icons.Package; + + package Clocks "Library of blocks that generate clocks" + extends Modelica.Icons.SourcesPackage; + + block PeriodicRealClock "Generates a periodic clock signal with a period defined by a Real number" + parameter Modelica.SIunits.Time period "Period of clock (defined as Real number)" annotation(Evaluate = true); + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialPeriodicClock; + equation + if useSolver then + y = Clock(Clock(period), solverMethod = solverMethod); + else + y = Clock(period); + end if; + end PeriodicRealClock; + end Clocks; + + package Interfaces "Library of connectors and partial blocks with clock signals" + extends Modelica.Icons.InterfacesPackage; + connector ClockInput = input Clock "'input Clock' as connector"; + connector ClockOutput = output Clock "'output Clock' as connector"; + + partial block PartialClock "Icon, connector, and solver method of a block that generates a clock" + parameter Boolean useSolver = false "= true, if solverMethod shall be explicitely defined" annotation(Evaluate = true); + parameter Modelica_Synchronous.Types.SolverMethod solverMethod = "ExplicitEuler" "Integration method used for discretized continuous-time partitions"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockOutput y; + end PartialClock; + + partial block PartialPeriodicClock "Icon, connector, and solver method of a block that generates a periodic clock" + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialClock; + end PartialPeriodicClock; + + partial block ClockedBlockIcon "Basic graphical layout of block where at least one input or output is a clocked variable" end ClockedBlockIcon; + end Interfaces; + end ClockSignals; + + package BooleanSignals "Library of clocked blocks for Boolean signals" + extends Modelica.Icons.Package; + + package Sampler "Library of sampler and hold blocks for Boolean signals" + extends Modelica.Icons.Package; + + block AssignClock "Assigns a clock to a clocked Boolean signal" + Modelica.Blocks.Interfaces.BooleanInput u "Connector of clocked, Boolean input signal"; + Modelica.Blocks.Interfaces.BooleanOutput y "Connector of clocked, Boolean output signal"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockInput clock; + equation + when clock then + y = u; + end when; + end AssignClock; + end Sampler; + + package TimeBasedSources "Package of signal source blocks generating clocked simulation time based Boolean signals" + extends Modelica.Icons.SourcesPackage; + + block Pulse "Generate pulse signal of type Boolean" + extends BooleanSignals.Interfaces.PartialClockedSO; + parameter Real width(final min = Modelica.Constants.small, final max = 100) = 50 "Width of pulse in % of period"; + parameter Modelica.SIunits.Time period(final min = Modelica.Constants.small, start = 1) "Time for one period"; + parameter Modelica.SIunits.Time startTime = 0 "Time instant of first pulse"; + protected + Modelica.SIunits.Time simTime; + parameter Modelica.SIunits.Time Twidth = period * width / 100 "width of one pulse" annotation(HideResult = true); + Modelica.SIunits.Time next(start = startTime, fixed = true) "next = startTime + n*period, for smallest n such that next>simTime"; + equation + simTime = sample(time); + next = if simTime >= previous(next) and previous(next) < simTime + period then previous(next) + period else previous(next); + y = simTime >= previous(next) or simTime <= next - period + Twidth; + end Pulse; + end TimeBasedSources; + + package Interfaces "Library of partial blocks for components with clocked Boolean signals" + extends Modelica.Icons.InterfacesPackage; + + partial block PartialClockedSO "Block with clocked single output Boolean signals" + extends Modelica_Synchronous.ClockSignals.Interfaces.ClockedBlockIcon; + Modelica.Blocks.Interfaces.BooleanOutput y "Connector of clocked, Real output signal"; + end PartialClockedSO; + end Interfaces; + end BooleanSignals; + + package Types "Library of types with choices, especially to build menus" + extends Modelica.Icons.Package; + type SolverMethod = String "Enumeration defining the integration method to solve differential equations in a clocked discretized continuous-time partition"; + end Types; + annotation(version = "0.92", versionBuild = 2, versionDate = "2013-09-19", dateModified = "2015-09-09 18:16:00Z"); +end Modelica_Synchronous; + +model TimeBasedPulse_total "Example of using the clocked simulation time based Boolean Pulse source block" + extends Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse; + annotation(experiment(StopTime = 1.0)); +end TimeBasedPulse_total; diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mos b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mos new file mode 100644 index 00000000000..66ea62043da --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mos @@ -0,0 +1,28 @@ +// name: Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse +// keywords: synchronous features +// status: correct +// + +loadFile("Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse.mo"); getErrorString(); +simulate(Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse, startTime=0, stopTime=1, numberOfIntervals = 0); getErrorString(); +val(pulse.y, 0.0); +val(pulse.y, 0.1); +val(pulse.y, 0.2); +val(pulse.y, 0.3); // 2015-10-14: Fails because value at 0.3 should be 0.0 but is 1.0 +val(pulse.y, 1.0); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedPulse', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", +// messages = "" +// end SimulationResult; +// "" +// 0.0 +// 1.0 +// 1.0 +// 0.0 +// 1.0 +// endResult diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mo b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mo new file mode 100644 index 00000000000..2d6ddf05dd6 --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mo @@ -0,0 +1,157 @@ +package Modelica "Modelica Standard Library - Version 3.2.1 (Build 4)" + extends Modelica.Icons.Package; + + package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)" + extends Modelica.Icons.Package; + + package Interfaces "Library of connectors and partial models for input/output blocks" + extends Modelica.Icons.InterfacesPackage; + connector BooleanInput = input Boolean "'input Boolean' as connector"; + connector BooleanOutput = output Boolean "'output Boolean' as connector"; + end Interfaces; + end Blocks; + + package Icons "Library of icons" + extends Icons.Package; + + partial package ExamplesPackage "Icon for packages containing runnable examples" + extends Modelica.Icons.Package; + end ExamplesPackage; + + partial model Example "Icon for runnable examples" end Example; + + partial package Package "Icon for standard packages" end Package; + + partial package InterfacesPackage "Icon for packages containing interfaces" + extends Modelica.Icons.Package; + end InterfacesPackage; + + partial package SourcesPackage "Icon for packages containing sources" + extends Modelica.Icons.Package; + end SourcesPackage; + end Icons; + + package SIunits "Library of type and unit definitions based on SI units according to ISO 31-1992" + extends Modelica.Icons.Package; + type Time = Real(final quantity = "Time", final unit = "s"); + end SIunits; + annotation(version = "3.2.1", versionBuild = 4, versionDate = "2013-08-14", dateModified = "2015-09-30 09:15:00Z"); +end Modelica; + +package Modelica_Synchronous "Modelica_Synchronous (version 0.92 Build 2) - Basic synchronous input/output control blocks +that are triggered by clocks" + extends Modelica.Icons.Package; + + package Examples "Library of examples to demonstrate the usage of package Modelica_Synchronous" + extends Modelica.Icons.ExamplesPackage; + + package Elementary "Examples that are used for the documentation of the blocks" + extends Modelica.Icons.ExamplesPackage; + + package BooleanSignals "Examples that are used for the documentation of the Modelica_Synchronous.BooleanSignals sub-library" + extends Modelica.Icons.ExamplesPackage; + + model TimeBasedStep "Example of using the clocked simulation time based Boolean Step source block" + extends Modelica.Icons.Example; + .Modelica_Synchronous.BooleanSignals.TimeBasedSources.Step step(startTime = 0.2); + .Modelica_Synchronous.ClockSignals.Clocks.PeriodicRealClock periodicClock1(period = 0.1); + .Modelica_Synchronous.BooleanSignals.Sampler.AssignClock assignClock1; + equation + connect(periodicClock1.y, assignClock1.clock); + connect(step.y, assignClock1.u); + annotation(experiment(StopTime = 1.0)); + end TimeBasedStep; + end BooleanSignals; + end Elementary; + end Examples; + + package ClockSignals "Library of blocks for clocked signals" + extends Modelica.Icons.Package; + + package Clocks "Library of blocks that generate clocks" + extends Modelica.Icons.SourcesPackage; + + block PeriodicRealClock "Generates a periodic clock signal with a period defined by a Real number" + parameter Modelica.SIunits.Time period "Period of clock (defined as Real number)" annotation(Evaluate = true); + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialPeriodicClock; + equation + if useSolver then + y = Clock(Clock(period), solverMethod = solverMethod); + else + y = Clock(period); + end if; + end PeriodicRealClock; + end Clocks; + + package Interfaces "Library of connectors and partial blocks with clock signals" + extends Modelica.Icons.InterfacesPackage; + connector ClockInput = input Clock "'input Clock' as connector"; + connector ClockOutput = output Clock "'output Clock' as connector"; + + partial block PartialClock "Icon, connector, and solver method of a block that generates a clock" + parameter Boolean useSolver = false "= true, if solverMethod shall be explicitely defined" annotation(Evaluate = true); + parameter Modelica_Synchronous.Types.SolverMethod solverMethod = "ExplicitEuler" "Integration method used for discretized continuous-time partitions"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockOutput y; + end PartialClock; + + partial block PartialPeriodicClock "Icon, connector, and solver method of a block that generates a periodic clock" + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialClock; + end PartialPeriodicClock; + + partial block ClockedBlockIcon "Basic graphical layout of block where at least one input or output is a clocked variable" end ClockedBlockIcon; + end Interfaces; + end ClockSignals; + + package BooleanSignals "Library of clocked blocks for Boolean signals" + extends Modelica.Icons.Package; + + package Sampler "Library of sampler and hold blocks for Boolean signals" + extends Modelica.Icons.Package; + + block AssignClock "Assigns a clock to a clocked Boolean signal" + Modelica.Blocks.Interfaces.BooleanInput u "Connector of clocked, Boolean input signal"; + Modelica.Blocks.Interfaces.BooleanOutput y "Connector of clocked, Boolean output signal"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockInput clock; + equation + when clock then + y = u; + end when; + end AssignClock; + end Sampler; + + package TimeBasedSources "Package of signal source blocks generating clocked simulation time based Boolean signals" + extends Modelica.Icons.SourcesPackage; + + block Step "Generate step signal of type Boolean" + extends BooleanSignals.Interfaces.PartialClockedSO; + parameter Modelica.SIunits.Time startTime = 0 "Time instant of step start"; + parameter Boolean startValue = false "Output before startTime"; + protected + Modelica.SIunits.Time simTime; + equation + simTime = sample(time); + y = if simTime >= startTime then not startValue else startValue; + end Step; + end TimeBasedSources; + + package Interfaces "Library of partial blocks for components with clocked Boolean signals" + extends Modelica.Icons.InterfacesPackage; + + partial block PartialClockedSO "Block with clocked single output Boolean signals" + extends Modelica_Synchronous.ClockSignals.Interfaces.ClockedBlockIcon; + Modelica.Blocks.Interfaces.BooleanOutput y "Connector of clocked, Real output signal"; + end PartialClockedSO; + end Interfaces; + end BooleanSignals; + + package Types "Library of types with choices, especially to build menus" + extends Modelica.Icons.Package; + type SolverMethod = String "Enumeration defining the integration method to solve differential equations in a clocked discretized continuous-time partition"; + end Types; + annotation(version = "0.92", versionBuild = 2, versionDate = "2013-09-19", dateModified = "2015-09-09 18:16:00Z"); +end Modelica_Synchronous; + +model TimeBasedStep_total "Example of using the clocked simulation time based Boolean Step source block" + extends Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep; + annotation(experiment(StopTime = 1.0)); +end TimeBasedStep_total; diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mos b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mos new file mode 100644 index 00000000000..47cc94dd8ac --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mos @@ -0,0 +1,26 @@ +// name: Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep +// keywords: synchronous features +// status: correct +// + +loadFile("Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep.mo"); getErrorString(); +simulate(Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep, startTime=0, stopTime=1, numberOfIntervals=0); getErrorString(); +val(step.y,0.0); +val(step.y,0.1); +val(step.y,0.2); +val(step.y,1.0); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica_Synchronous.Examples.Elementary.BooleanSignals.TimeBasedStep', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", +// messages = "" +// end SimulationResult; +// "" +// 0.0 +// 0.0 +// 1.0 +// 1.0 +// endResult diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mo b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mo new file mode 100644 index 00000000000..c45858f936a --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mo @@ -0,0 +1,158 @@ +package Modelica "Modelica Standard Library - Version 3.2.1 (Build 4)" + extends Modelica.Icons.Package; + + package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)" + extends Modelica.Icons.Package; + + package Interfaces "Library of connectors and partial models for input/output blocks" + extends Modelica.Icons.InterfacesPackage; + connector IntegerInput = input Integer "'input Integer' as connector"; + connector IntegerOutput = output Integer "'output Integer' as connector"; + end Interfaces; + end Blocks; + + package Icons "Library of icons" + extends Icons.Package; + + partial package ExamplesPackage "Icon for packages containing runnable examples" + extends Modelica.Icons.Package; + end ExamplesPackage; + + partial model Example "Icon for runnable examples" end Example; + + partial package Package "Icon for standard packages" end Package; + + partial package InterfacesPackage "Icon for packages containing interfaces" + extends Modelica.Icons.Package; + end InterfacesPackage; + + partial package SourcesPackage "Icon for packages containing sources" + extends Modelica.Icons.Package; + end SourcesPackage; + end Icons; + + package SIunits "Library of type and unit definitions based on SI units according to ISO 31-1992" + extends Modelica.Icons.Package; + type Time = Real(final quantity = "Time", final unit = "s"); + end SIunits; + annotation(version = "3.2.1", versionBuild = 4, versionDate = "2013-08-14", dateModified = "2015-09-30 09:15:00Z"); +end Modelica; + +package Modelica_Synchronous "Modelica_Synchronous (version 0.92 Build 2) - Basic synchronous input/output control blocks +that are triggered by clocks" + extends Modelica.Icons.Package; + + package Examples "Library of examples to demonstrate the usage of package Modelica_Synchronous" + extends Modelica.Icons.ExamplesPackage; + + package Elementary "Examples that are used for the documentation of the blocks" + extends Modelica.Icons.ExamplesPackage; + + package IntegerSignals "Examples that are used for the documentation of the Modelica_Synchronous.IntegerSignals sub-library" + extends Modelica.Icons.ExamplesPackage; + + model TimeBasedStep "Example of using the clocked simulation time based Integer Step source block" + extends Modelica.Icons.Example; + .Modelica_Synchronous.IntegerSignals.TimeBasedSources.Step step(height = 3, offset = 1, startTime = 0.2); + .Modelica_Synchronous.ClockSignals.Clocks.PeriodicRealClock periodicClock1(period = 0.1); + .Modelica_Synchronous.IntegerSignals.Sampler.AssignClock assignClock1; + equation + connect(step.y, assignClock1.u); + connect(periodicClock1.y, assignClock1.clock); + annotation(experiment(StopTime = 1.0)); + end TimeBasedStep; + end IntegerSignals; + end Elementary; + end Examples; + + package ClockSignals "Library of blocks for clocked signals" + extends Modelica.Icons.Package; + + package Clocks "Library of blocks that generate clocks" + extends Modelica.Icons.SourcesPackage; + + block PeriodicRealClock "Generates a periodic clock signal with a period defined by a Real number" + parameter Modelica.SIunits.Time period "Period of clock (defined as Real number)" annotation(Evaluate = true); + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialPeriodicClock; + equation + if useSolver then + y = Clock(Clock(period), solverMethod = solverMethod); + else + y = Clock(period); + end if; + end PeriodicRealClock; + end Clocks; + + package Interfaces "Library of connectors and partial blocks with clock signals" + extends Modelica.Icons.InterfacesPackage; + connector ClockInput = input Clock "'input Clock' as connector"; + connector ClockOutput = output Clock "'output Clock' as connector"; + + partial block PartialClock "Icon, connector, and solver method of a block that generates a clock" + parameter Boolean useSolver = false "= true, if solverMethod shall be explicitely defined" annotation(Evaluate = true); + parameter Modelica_Synchronous.Types.SolverMethod solverMethod = "ExplicitEuler" "Integration method used for discretized continuous-time partitions"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockOutput y; + end PartialClock; + + partial block PartialPeriodicClock "Icon, connector, and solver method of a block that generates a periodic clock" + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialClock; + end PartialPeriodicClock; + + partial block ClockedBlockIcon "Basic graphical layout of block where at least one input or output is a clocked variable" end ClockedBlockIcon; + end Interfaces; + end ClockSignals; + + package IntegerSignals "Library of clocked blocks for Integer signals" + extends Modelica.Icons.Package; + + package Sampler "Library of sampler and hold blocks for Integer signals" + extends Modelica.Icons.Package; + + block AssignClock "Assigns a clock to a clocked Integer signal" + Modelica.Blocks.Interfaces.IntegerInput u "Connector of clocked, Integer input signal"; + Modelica.Blocks.Interfaces.IntegerOutput y "Connector of clocked, Integer output signal"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockInput clock; + equation + when clock then + y = u; + end when; + end AssignClock; + end Sampler; + + package TimeBasedSources "Package of signal source blocks generating clocked simulation time based Integer signals" + extends Modelica.Icons.SourcesPackage; + + block Step "Generate step signal of type Integer" + extends Interfaces.PartialClockedSO; + parameter Integer height = 1 "Height of step"; + parameter Integer offset = 0 "Offset of output signal y"; + parameter Modelica.SIunits.Time startTime = 0 "Output y = offset for time < startTime"; + protected + Modelica.SIunits.Time simTime; + equation + simTime = sample(time); + y = offset + (if simTime < startTime then 0 else height); + end Step; + end TimeBasedSources; + + package Interfaces "Library of partial blocks for components with clocked Integer signals" + extends Modelica.Icons.InterfacesPackage; + + partial block PartialClockedSO "Block with clocked single output Integer signal" + extends Modelica_Synchronous.ClockSignals.Interfaces.ClockedBlockIcon; + Modelica.Blocks.Interfaces.IntegerOutput y "Connector of clocked, Real output signal"; + end PartialClockedSO; + end Interfaces; + end IntegerSignals; + + package Types "Library of types with choices, especially to build menus" + extends Modelica.Icons.Package; + type SolverMethod = String "Enumeration defining the integration method to solve differential equations in a clocked discretized continuous-time partition"; + end Types; + annotation(version = "0.92", versionBuild = 2, versionDate = "2013-09-19", dateModified = "2015-09-09 18:16:00Z"); +end Modelica_Synchronous; + +model TimeBasedStep_total "Example of using the clocked simulation time based Integer Step source block" + extends Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep; + annotation(experiment(StopTime = 1.0)); +end TimeBasedStep_total; diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mos b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mos new file mode 100644 index 00000000000..af59ad7bdd6 --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mos @@ -0,0 +1,26 @@ +// name: Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep +// keywords: synchronous features +// status: correct +// + +loadFile("Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep.mo"); getErrorString(); +simulate(Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep, startTime=0, stopTime=1, numberOfIntervals=0); getErrorString(); +val(step.y,0.0); +val(step.y,0.1); +val(step.y,0.2); +val(step.y,1.0); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica_Synchronous.Examples.Elementary.IntegerSignals.TimeBasedStep', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", +// messages = "" +// end SimulationResult; +// "" +// 1.0 +// 1.0 +// 4.0 +// 4.0 +// endResult diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mo b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mo new file mode 100644 index 00000000000..9b53c0e53c7 --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mo @@ -0,0 +1,394 @@ +package ModelicaServices "ModelicaServices (OpenModelica implementation) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation" + extends Modelica.Icons.Package; + + package Machine + extends Modelica.Icons.Package; + final constant Real eps = 1.e-15 "Biggest number such that 1.0 + eps = 1.0"; + final constant Real small = 1.e-60 "Smallest number such that small and -small are representable on the machine"; + final constant Real inf = 1.e+60 "Biggest Real number such that inf and -inf are representable on the machine"; + final constant Integer Integer_inf = OpenModelica.Internal.Architecture.integerMax() "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine"; + end Machine; + annotation(Protection(access = Access.hide), version = "3.2.1", versionBuild = 2, versionDate = "2013-08-14", dateModified = "2013-08-14 08:44:41Z"); +end ModelicaServices; + +package Modelica "Modelica Standard Library - Version 3.2.1 (Build 4)" + extends Modelica.Icons.Package; + + package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)" + extends Modelica.Icons.Package; + + package Interfaces "Library of connectors and partial models for input/output blocks" + extends Modelica.Icons.InterfacesPackage; + connector RealInput = input Real "'input Real' as connector"; + connector RealOutput = output Real "'output Real' as connector"; + + partial block SO "Single Output continuous control block" + extends Modelica.Blocks.Icons.Block; + RealOutput y "Connector of Real output signal"; + end SO; + end Interfaces; + + package Math "Library of Real mathematical functions as input/output blocks" + extends Modelica.Icons.Package; + + block Feedback "Output difference between commanded and feedback input" + .Modelica.Blocks.Interfaces.RealInput u1; + .Modelica.Blocks.Interfaces.RealInput u2; + .Modelica.Blocks.Interfaces.RealOutput y; + equation + y = u1 - u2; + end Feedback; + end Math; + + package Sources "Library of signal source blocks generating Real and Boolean signals" + extends Modelica.Icons.SourcesPackage; + + block Ramp "Generate ramp signal" + parameter Real height = 1 "Height of ramps"; + parameter Modelica.SIunits.Time duration(min = 0.0, start = 2) "Duration of ramp (= 0.0 gives a Step)"; + parameter Real offset = 0 "Offset of output signal"; + parameter Modelica.SIunits.Time startTime = 0 "Output = offset for time < startTime"; + extends .Modelica.Blocks.Interfaces.SO; + equation + y = offset + (if time < startTime then 0 else if time < startTime + duration then (time - startTime) * height / duration else height); + end Ramp; + end Sources; + + package Icons "Icons for Blocks" + extends Modelica.Icons.IconsPackage; + + partial block Block "Basic graphical layout of input/output block" end Block; + end Icons; + end Blocks; + + package Mechanics "Library of 1-dim. and 3-dim. mechanical components (multi-body, rotational, translational)" + extends Modelica.Icons.Package; + + package Rotational "Library to model 1-dimensional, rotational mechanical systems" + extends Modelica.Icons.Package; + + package Components "Components for 1D rotational mechanical drive trains" + extends Modelica.Icons.Package; + + model Inertia "1D-rotational component with inertia" + Rotational.Interfaces.Flange_a flange_a "Left flange of shaft"; + Rotational.Interfaces.Flange_b flange_b "Right flange of shaft"; + parameter .Modelica.SIunits.Inertia J(min = 0, start = 1) "Moment of inertia"; + parameter StateSelect stateSelect = StateSelect.default "Priority to use phi and w as states" annotation(HideResult = true); + .Modelica.SIunits.Angle phi(stateSelect = stateSelect) "Absolute rotation angle of component"; + .Modelica.SIunits.AngularVelocity w(stateSelect = stateSelect) "Absolute angular velocity of component (= der(phi))"; + .Modelica.SIunits.AngularAcceleration a "Absolute angular acceleration of component (= der(w))"; + equation + phi = flange_a.phi; + phi = flange_b.phi; + w = der(phi); + a = der(w); + J * a = flange_a.tau + flange_b.tau; + end Inertia; + end Components; + + package Sensors "Sensors to measure variables in 1D rotational mechanical components" + extends Modelica.Icons.SensorsPackage; + + model SpeedSensor "Ideal sensor to measure the absolute flange angular velocity" + extends Rotational.Interfaces.PartialAbsoluteSensor; + Modelica.Blocks.Interfaces.RealOutput w(unit = "rad/s") "Absolute angular velocity of flange as output signal"; + equation + w = der(flange.phi); + end SpeedSensor; + end Sensors; + + package Sources "Sources to drive 1D rotational mechanical components" + extends Modelica.Icons.SourcesPackage; + + model Torque "Input signal acting as external torque on a flange" + extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2; + Modelica.Blocks.Interfaces.RealInput tau(unit = "N.m") "Accelerating torque acting at flange (= -flange.tau)"; + equation + flange.tau = -tau; + end Torque; + end Sources; + + package Interfaces "Connectors and partial models for 1D rotational mechanical components" + extends Modelica.Icons.InterfacesPackage; + + connector Flange_a "1-dim. rotational flange of a shaft (filled square icon)" + .Modelica.SIunits.Angle phi "Absolute rotation angle of flange"; + flow .Modelica.SIunits.Torque tau "Cut torque in the flange"; + end Flange_a; + + connector Flange_b "1-dim. rotational flange of a shaft (non-filled square icon)" + .Modelica.SIunits.Angle phi "Absolute rotation angle of flange"; + flow .Modelica.SIunits.Torque tau "Cut torque in the flange"; + end Flange_b; + + connector Support "Support/housing of a 1-dim. rotational shaft" + .Modelica.SIunits.Angle phi "Absolute rotation angle of the support/housing"; + flow .Modelica.SIunits.Torque tau "Reaction torque in the support/housing"; + end Support; + + partial model PartialElementaryOneFlangeAndSupport2 "Partial model for a component with one rotational 1-dim. shaft flange and a support used for textual modeling, i.e., for elementary models" + parameter Boolean useSupport = false "= true, if support flange enabled, otherwise implicitly grounded" annotation(Evaluate = true, HideResult = true); + Flange_b flange "Flange of shaft"; + Support support(phi = phi_support, tau = -flange.tau) if useSupport "Support/housing of component"; + protected + Modelica.SIunits.Angle phi_support "Absolute angle of support flange"; + equation + if not useSupport then + phi_support = 0; + end if; + end PartialElementaryOneFlangeAndSupport2; + + partial model PartialAbsoluteSensor "Partial model to measure a single absolute flange variable" + extends Modelica.Icons.RotationalSensor; + Flange_a flange "Flange of shaft from which sensor information shall be measured"; + equation + 0 = flange.tau; + end PartialAbsoluteSensor; + end Interfaces; + end Rotational; + end Mechanics; + + package Math "Library of mathematical functions (e.g., sin, cos) and of functions operating on vectors and matrices" + extends Modelica.Icons.Package; + + package Icons "Icons for Math" + extends Modelica.Icons.IconsPackage; + + partial function AxisCenter "Basic icon for mathematical function with y-axis in the center" end AxisCenter; + end Icons; + + function asin "Inverse sine (-1 <= u <= 1)" + extends Modelica.Math.Icons.AxisCenter; + input Real u; + output .Modelica.SIunits.Angle y; + external "builtin" y = asin(u); + end asin; + + function exp "Exponential, base e" + extends Modelica.Math.Icons.AxisCenter; + input Real u; + output Real y; + external "builtin" y = exp(u); + end exp; + end Math; + + package Constants "Library of mathematical constants and constants of nature (e.g., pi, eps, R, sigma)" + extends Modelica.Icons.Package; + final constant Real pi = 2 * Math.asin(1.0); + final constant Real small = ModelicaServices.Machine.small "Smallest number such that small and -small are representable on the machine"; + final constant .Modelica.SIunits.Velocity c = 299792458 "Speed of light in vacuum"; + final constant Real mue_0(final unit = "N/A2") = 4 * pi * 1.e-7 "Magnetic constant"; + end Constants; + + package Icons "Library of icons" + extends Icons.Package; + + partial package ExamplesPackage "Icon for packages containing runnable examples" + extends Modelica.Icons.Package; + end ExamplesPackage; + + partial model Example "Icon for runnable examples" end Example; + + partial package Package "Icon for standard packages" end Package; + + partial package InterfacesPackage "Icon for packages containing interfaces" + extends Modelica.Icons.Package; + end InterfacesPackage; + + partial package SourcesPackage "Icon for packages containing sources" + extends Modelica.Icons.Package; + end SourcesPackage; + + partial package SensorsPackage "Icon for packages containing sensors" + extends Modelica.Icons.Package; + end SensorsPackage; + + partial package IconsPackage "Icon for packages containing icons" + extends Modelica.Icons.Package; + end IconsPackage; + + partial class RotationalSensor "Icon representing a round measurement device" end RotationalSensor; + end Icons; + + package SIunits "Library of type and unit definitions based on SI units according to ISO 31-1992" + extends Modelica.Icons.Package; + + package Conversions "Conversion functions to/from non SI units and type definitions of non SI units" + extends Modelica.Icons.Package; + + package NonSIunits "Type definitions of non SI units" + extends Modelica.Icons.Package; + type Temperature_degC = Real(final quantity = "ThermodynamicTemperature", final unit = "degC") "Absolute temperature in degree Celsius (for relative temperature use SIunits.TemperatureDifference)" annotation(absoluteValue = true); + end NonSIunits; + end Conversions; + + type Angle = Real(final quantity = "Angle", final unit = "rad", displayUnit = "deg"); + type Time = Real(final quantity = "Time", final unit = "s"); + type AngularVelocity = Real(final quantity = "AngularVelocity", final unit = "rad/s"); + type AngularAcceleration = Real(final quantity = "AngularAcceleration", final unit = "rad/s2"); + type Velocity = Real(final quantity = "Velocity", final unit = "m/s"); + type Acceleration = Real(final quantity = "Acceleration", final unit = "m/s2"); + type MomentOfInertia = Real(final quantity = "MomentOfInertia", final unit = "kg.m2"); + type Inertia = MomentOfInertia; + type Torque = Real(final quantity = "Torque", final unit = "N.m"); + type FaradayConstant = Real(final quantity = "FaradayConstant", final unit = "C/mol"); + end SIunits; + annotation(version = "3.2.1", versionBuild = 4, versionDate = "2013-08-14", dateModified = "2015-09-30 09:15:00Z"); +end Modelica; + +package Modelica_Synchronous "Modelica_Synchronous (version 0.92 Build 2) - Basic synchronous input/output control blocks +that are triggered by clocks" + extends Modelica.Icons.Package; + + package Examples "Library of examples to demonstrate the usage of package Modelica_Synchronous" + extends Modelica.Icons.ExamplesPackage; + + package SimpleControlledDrive "Examples based on a simple controlled drive with different ways to define the sampling" + extends Modelica.Icons.ExamplesPackage; + + model ClockedWithDiscreteTextbookController "Simple controlled drive with discrete textbook controller (period is not used in the controller)" + extends Modelica.Icons.Example; + Modelica.Mechanics.Rotational.Components.Inertia load(J = 10, phi(fixed = true, start = 0), w(fixed = true, start = 0)); + Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed; + Modelica.Blocks.Sources.Ramp ramp(duration = 2); + Modelica.Blocks.Math.Feedback feedback; + Modelica.Mechanics.Rotational.Sources.Torque torque; + Modelica_Synchronous.RealSignals.Periodic.PI PI(Td = 1, x(fixed = true), kd = 110); + Modelica_Synchronous.RealSignals.Sampler.SampleClocked sample2; + Modelica_Synchronous.RealSignals.Sampler.Hold hold1; + Modelica_Synchronous.RealSignals.Sampler.Sample sample1; + Modelica_Synchronous.ClockSignals.Clocks.PeriodicRealClock periodicClock(period = 0.1); + equation + connect(speed.flange, load.flange_b); + connect(torque.flange, load.flange_a); + connect(feedback.y, PI.u); + connect(ramp.y, sample2.u); + connect(sample2.y, feedback.u1); + connect(PI.y, hold1.u); + connect(hold1.y, torque.tau); + connect(sample1.u, speed.w); + connect(feedback.u2, sample1.y); + connect(periodicClock.y, sample2.clock); + annotation(experiment(StopTime = 5)); + end ClockedWithDiscreteTextbookController; + end SimpleControlledDrive; + end Examples; + + package ClockSignals "Library of blocks for clocked signals" + extends Modelica.Icons.Package; + + package Clocks "Library of blocks that generate clocks" + extends Modelica.Icons.SourcesPackage; + + block PeriodicRealClock "Generates a periodic clock signal with a period defined by a Real number" + parameter Modelica.SIunits.Time period "Period of clock (defined as Real number)" annotation(Evaluate = true); + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialPeriodicClock; + equation + if useSolver then + y = Clock(Clock(period), solverMethod = solverMethod); + else + y = Clock(period); + end if; + end PeriodicRealClock; + end Clocks; + + package Interfaces "Library of connectors and partial blocks with clock signals" + extends Modelica.Icons.InterfacesPackage; + connector ClockInput = input Clock "'input Clock' as connector"; + connector ClockOutput = output Clock "'output Clock' as connector"; + + partial block PartialClock "Icon, connector, and solver method of a block that generates a clock" + parameter Boolean useSolver = false "= true, if solverMethod shall be explicitely defined" annotation(Evaluate = true); + parameter Modelica_Synchronous.Types.SolverMethod solverMethod = "ExplicitEuler" "Integration method used for discretized continuous-time partitions"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockOutput y; + end PartialClock; + + partial block PartialPeriodicClock "Icon, connector, and solver method of a block that generates a periodic clock" + extends Modelica_Synchronous.ClockSignals.Interfaces.PartialClock; + end PartialPeriodicClock; + + partial block ClockedBlockIcon "Basic graphical layout of block where at least one input or output is a clocked variable" end ClockedBlockIcon; + end Interfaces; + end ClockSignals; + + package RealSignals "Library of clocked blocks for Real signals" + extends Modelica.Icons.Package; + + package Sampler "Library of sampler and hold blocks for Real signals" + block Sample "Sample the continuous-time, Real input signal and provide it as clocked output signal (clock is infered)" + extends Modelica_Synchronous.RealSignals.Interfaces.PartialSISOSampler; + equation + y = sample(u); + end Sample; + + extends Modelica.Icons.Package; + + block SampleClocked "Sample the continuous-time, Real input signal and provide it as clocked output signal. The clock is provided as input signal" + extends Modelica_Synchronous.RealSignals.Interfaces.SamplerIcon; + Modelica.Blocks.Interfaces.RealInput u "Connector of continuous-time, Real input signal"; + Modelica.Blocks.Interfaces.RealOutput y "Connector of clocked, Real output signal"; + Modelica_Synchronous.ClockSignals.Interfaces.ClockInput clock "Output signal y is associated with this clock input"; + equation + y = sample(u, clock); + end SampleClocked; + + block Hold "Hold the clocked, Real input signal and provide it as continuous-time output signal (zero order hold)" + extends Modelica_Synchronous.RealSignals.Interfaces.PartialSISOHold; + equation + y = hold(u); + end Hold; + end Sampler; + + package Periodic "Library of blocks that are designed to operate only on periodically clocked signals (mainly described by z transforms)" + extends Modelica.Icons.Package; + + block PI "Discrete-time PI controller" + extends Modelica_Synchronous.RealSignals.Interfaces.PartialClockedSISO; + parameter Real kd "Gain of discrete PI controller"; + parameter Real Td(min = Modelica.Constants.small) "Time constant of discrete PI controller"; + output Real x(start = 0) "Discrete PI state"; + equation + when Clock() then + x = previous(x) + u / Td; + y = kd * (x + u); + end when; + end PI; + end Periodic; + + package Interfaces "Library of partial blocks for components with clocked Real signals" + extends Modelica.Icons.InterfacesPackage; + + partial block SamplerIcon "Basic graphical layout of block used for sampling of Real signals" end SamplerIcon; + + partial block PartialSISOSampler "Basic block used for sampling of Real signals" + extends Modelica_Synchronous.RealSignals.Interfaces.SamplerIcon; + Modelica.Blocks.Interfaces.RealInput u "Connector of continuous-time, Real input signal"; + Modelica.Blocks.Interfaces.RealOutput y "Connector of clocked, Real output signal"; + end PartialSISOSampler; + + partial block PartialSISOHold "Basic block used for zero order hold of Real signals" + parameter Real y_start = 0.0 "Value of output y before the first tick of the clock associated to input u"; + Modelica.Blocks.Interfaces.RealInput u(final start = y_start) "Connector of clocked, Real input signal"; + Modelica.Blocks.Interfaces.RealOutput y "Connector of continuous-time, Real output signal"; + end PartialSISOHold; + + partial block PartialClockedSISO "Block with clocked single input and clocked single output Real signals" + extends Modelica_Synchronous.ClockSignals.Interfaces.ClockedBlockIcon; + Modelica.Blocks.Interfaces.RealInput u "Connector of clocked, Real input signal"; + Modelica.Blocks.Interfaces.RealOutput y "Connector of clocked, Real output signal"; + end PartialClockedSISO; + end Interfaces; + end RealSignals; + + package Types "Library of types with choices, especially to build menus" + extends Modelica.Icons.Package; + type SolverMethod = String "Enumeration defining the integration method to solve differential equations in a clocked discretized continuous-time partition"; + end Types; + annotation(version = "0.92", versionBuild = 2, versionDate = "2013-09-19", dateModified = "2015-09-09 18:16:00Z"); +end Modelica_Synchronous; + +model ClockedWithDiscreteTextbookController_total "Simple controlled drive with discrete textbook controller (period is not used in the controller)" + extends Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController; + annotation(experiment(StopTime = 5)); +end ClockedWithDiscreteTextbookController_total; diff --git a/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mos b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mos new file mode 100644 index 00000000000..dfb3282ed85 --- /dev/null +++ b/simulation/modelica/synchronous/Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mos @@ -0,0 +1,22 @@ +// name: Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController +// keywords: synchronous features +// status: correct +// + +loadFile("Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController.mo"); getErrorString(); +simulate(Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController, startTime=0, stopTime=1, numberOfIntervals=0); getErrorString(); +val(hold1.y,0); +val(hold1.y,1); + +// Result: +// true +// "" +// record SimulationResult +// resultFile = "Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController_res.mat", +// simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica_Synchronous.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''", +// messages = "" +// end SimulationResult; +// "" +// 0.0 +// 5.0 +// endResult