Skip to content

Commit

Permalink
PDEModelica flag
Browse files Browse the repository at this point in the history
Calling PDEModelica specific functions only if enabled by grammar flag.
  • Loading branch information
Jan Šilar authored and OpenModelica-Hudson committed Feb 10, 2016
1 parent 9a9dd8a commit 186d401
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -4281,8 +4281,10 @@ algorithm
printVariabilityAsCorbaString(variability);
Print.printBuf(", direction = ");
printDirectionAsCorbaString(direction);
Print.printBuf(", isField = ");
printIsFieldAsCorbaString(isField);
if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then
Print.printBuf(", isField = ");
printIsFieldAsCorbaString(isField);
end if;
Print.printBuf(", arrayDim = ");
printArrayDimAsCorbaString(arrayDim);
Print.printBuf(" end Absyn.ATTR;");
Expand Down
18 changes: 13 additions & 5 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -2248,16 +2248,19 @@ algorithm
ErrorExt.rollBack("expandableConnectorsOrder");

//Discretization of PDEs:
// domainNLst = List.fold(els,InstUtil.findDomains,{});
eqs_1 = List.fold1(eqs_1, InstUtil.discretizePDE, domainFieldsLst,/* domainNLst,*/ {});
if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then
eqs_1 = List.fold1(eqs_1, InstUtil.discretizePDE, domainFieldsLst, {});
end if;

//Instantiate equations (see function "instEquation")
(cache,env5,ih,dae2,csets2,ci_state3,graph) =
instList(cache, env5, ih, pre, csets1, ci_state2, InstSection.instEquation, eqs_1, impl, InstTypes.alwaysUnroll, graph);
DAEUtil.verifyEquationsDAE(dae2);

//Discretization of initial equations of fields:
initeqs_1 = List.fold1(initeqs_1, InstUtil.discretizePDE, domainFieldsLst,/* domainNLst,*/ {});
if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then
initeqs_1 = List.fold1(initeqs_1, InstUtil.discretizePDE, domainFieldsLst,/* domainNLst,*/ {});
end if;
//Instantiate inital equations (see function "instInitialEquation")
(cache,env5,ih,dae3,csets3,ci_state4,graph) =
instList(cache, env5, ih, pre, csets2, ci_state3, InstSection.instInitialEquation, initeqs_1, impl, InstTypes.alwaysUnroll, graph);
Expand Down Expand Up @@ -3138,7 +3141,9 @@ algorithm
inInstDims, inImplInst, inCallingScope, outGraph, outSets, inStopOnError);
arrayUpdate(var_arr, idx, vars);
arrayUpdate(dae_arr, idx, dae);
domainFieldsList := InstUtil.optAppendField(domainFieldsList,fieldDomOpt);
if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then
domainFieldsList := InstUtil.optAppendField(domainFieldsList,fieldDomOpt);
end if;
end for;

outVars := List.flatten(arrayList(var_arr));
Expand Down Expand Up @@ -3564,7 +3569,10 @@ algorithm
(cache, dims) = InstUtil.elabArraydim(cache, env2, own_cref, t, ad, eq, impl,
NONE(), true, is_function_input, pre, info, inst_dims);

(dims, mod_1, outFieldDomOpt) = InstUtil.elabField(inCache, inEnv, name, attr, dims, mod_1, info);
//PDEModelica:
if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then
(dims, mod_1, outFieldDomOpt) = InstUtil.elabField(inCache, inEnv, name, attr, dims, mod_1, info);
end if;

// adrpo: 2011-11-18: see if the component is an INPUT or OUTPUT and class is a record
// and add it to the cache!
Expand Down
10 changes: 0 additions & 10 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -46,16 +46,6 @@ annotation(Documentation(info="<html>
</html>"));
end der;

function pder "Partial space derivative of the input expression in the first argument with respect to second argument"
input Real u(unit="'p");
input Real x(unit="'q");
output Real du(unit="'p/'q");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"???\">der()</a>
</html>"));
end pder;

impure function initial "True if in initialization phase"
output Boolean isInitial;
external "builtin";
Expand Down
22 changes: 16 additions & 6 deletions Compiler/FrontEnd/PDEModelicaBuiltin.mo
Expand Up @@ -31,12 +31,22 @@

/*PDEModelica extension built-ins*/

record DomainLineSegment1D
record DomainLineSegment1D "Record representing 1-dimensional domain where a partial differential equation hold."
record Region
end Region;
parameter Real L=1;
constant Integer N=10;
parameter Real dx = L / (N-1);
parameter Real[N] x = array(i*dx for i in 0:N-1);
Region left, right, interior;
parameter Real L(unit="m")=1 "length of the domain";
constant Integer N(unit="")=10 "number of grid nodes";
parameter Real dx = L / (N-1) "grid space step";
parameter Real[N] x(each unit="m") = array(i*dx for i in 0:N-1) "space coordinate";
Region left, right, interior "regions representing boundaries and the interior";
end DomainLineSegment1D;

function pder "Partial space derivative of the input expression in the first argument with respect to second argument"
input Real u(unit="'p");
input Real x(unit="'q");
output Real du(unit="'p/'q");
external "builtin";
annotation(Documentation(info="<html>
See <a href=\"???\">pder()</a>
</html>"));
end pder;
9 changes: 8 additions & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -4538,7 +4538,14 @@ algorithm
match (inString)
case ("") then Absyn.NONFIELD();
case ("nonfield") then Absyn.NONFIELD();
case ("field") then Absyn.FIELD();
case ("field")
equation
if not Flags.getConfigEnum(Flags.GRAMMAR) == Flags.PDEMODELICA then
Error.addMessage(Error.PDEModelica_ERROR,
{"Fields not supported in standard modelica. Enable PDEModelica usign flag --grammar=\"PDEModelica\"."});
fail();
end if;
then Absyn.FIELD();
end match;
end setElementIsField;

Expand Down
8 changes: 8 additions & 0 deletions Compiler/Util/Config.mo
Expand Up @@ -166,6 +166,14 @@ algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
end acceptOptimicaGrammar;

public function acceptPDEModelicaGrammar
"returns: true if Optimica grammar is accepted or false otherwise
usage: omc [+g=Modelica|MetaModelica|ParModelica|Optimica], default to 'Modelica'."
output Boolean outBoolean;
algorithm
outBoolean := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA);
end acceptPDEModelicaGrammar;

public function getAnnotationVersion
"returns what flag was given at start
omc [+annotationVersion=3.x]
Expand Down

0 comments on commit 186d401

Please sign in to comment.