Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedKamp committed Jul 1, 2015
2 parents b38ffe3 + 74f231c commit 69ba949
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 188 deletions.
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -8041,6 +8041,18 @@ algorithm
end match;
end dimNotFixed;

function isArrayWithUnknownDimension
input DAE.Type ty;
output Boolean b;
algorithm
b := match ty
case DAE.T_ARRAY() then max(
match d case DAE.DIM_UNKNOWN() then true; else false; end match
for d in getDimensions(ty));
else false;
end match;
end isArrayWithUnknownDimension;

public function stripTypeVars
"Strips the attribute variables from a type, and returns both the stripped
type and the attribute variables."
Expand Down
24 changes: 15 additions & 9 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -4547,15 +4547,11 @@ match ty
let expPart = daeExp(right, context, &preExp, &varDecls, &auxFunction)
match expTypeFromExpShort(right)
case "boolean" then
let tvar = tempDecl("boolean_array", &varDecls)
//let &preExp += 'cast_integer_array_to_real(&<%expPart%>, &<%tvar%>);<%\n%>'
<<
<%preExp%>
copy_boolean_array_data_mem(<%expPart%>, &<%cref(left)%>);
>>
case "integer" then
let tvar = tempDecl("integer_array", &varDecls)
//let &preExp += 'cast_integer_array_to_real(&<%expPart%>, &<%tvar%>);<%\n%>'
<<
<%preExp%>
copy_integer_array_data_mem(<%expPart%>, &<%cref(left)%>);
Expand Down Expand Up @@ -5605,7 +5601,7 @@ template funArgDefinition(Variable var)
::=
let &auxFunction = buffer ""
match var
case VARIABLE(__) then '<%varType(var)%> <%contextCref(name,contextFunction,&auxFunction)%>'
case VARIABLE(__) then ('<%varType(var)%> <%contextCref(name,contextFunction,&auxFunction)%>' + (if var.instDims then " = {0}"))
case FUNCTION_PTR(__) then 'modelica_fnptr _<%name%>'
end funArgDefinition;

Expand Down Expand Up @@ -6900,11 +6896,12 @@ template varOutput(Variable var)
case FUNCTION_PTR(__) then
'if (out<%funArgName(var)%>) { *out<%funArgName(var)%> = (modelica_fnptr)<%funArgName(var)%>; }<%\n%>'
case VARIABLE(ty=T_ARRAY(__)) then
'if (out<%funArgName(var)%>) { copy_<%expTypeShort(var.ty)%>_array_data(<%funArgName(var)%>, out<%funArgName(var)%>); }<%\n%>'
// If the dim_size is NULL, the output is an array with unknown dimensions. Copy the array.
'if (out<%funArgName(var)%>) { if (out<%funArgName(var)%>->dim_size == NULL) {copy_<%expTypeShort(var.ty)%>_array(<%funArgName(var)%>, out<%funArgName(var)%>);} else {copy_<%expTypeShort(var.ty)%>_array_data(<%funArgName(var)%>, out<%funArgName(var)%>);} }<%\n%>'
case VARIABLE(__) then
/*Seems like we still get an array var with the wrong type here. It have instdims though >_<. TODO I guess*/
if instDims then
'if (out<%funArgName(var)%>) { copy_<%expTypeShort(var.ty)%>_array_data(<%funArgName(var)%>, out<%funArgName(var)%>); }<%\n%>'
'if (out<%funArgName(var)%>) { if (out<%funArgName(var)%>->dim_size == NULL) {copy_<%expTypeShort(var.ty)%>_array(<%funArgName(var)%>, out<%funArgName(var)%>);} else {copy_<%expTypeShort(var.ty)%>_array_data(<%funArgName(var)%>, out<%funArgName(var)%>);} }<%\n%>'
else
'if (out<%funArgName(var)%>) { *out<%funArgName(var)%> = <%funArgName(var)%>; }<%\n%>'
else error(sourceInfo(), 'varOutput:error Unknown variable type as output')
Expand Down Expand Up @@ -7765,7 +7762,12 @@ template tupleReturnVariableUpdates(Exp inExp, Context context, Text &varDecls,
>> /*varCopy end*/
'&<%rhsStr%>'
case CREF(__) then
'&<%daeExpCrefLhs(inExp, context, &preExp, &varDecls, &auxFunction)%>'
let res = daeExpCrefLhs(inExp, context, &preExp, &varDecls, &auxFunction)
if isArrayWithUnknownDimension(ty)
then
let &preExp += '<%res%>.dim_size = NULL;<%\n%>'
'&<%res%>'
else '&<%res%>'
else
error(sourceInfo(), 'tupleReturnVariableUpdates: Unhandled expression. <%ExpressionDump.printExpStr(inExp)%>')
end tupleReturnVariableUpdates;
Expand Down Expand Up @@ -9578,7 +9580,10 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
""
case T_TUPLE(types=t::_)
case t
then tempDecl(expTypeArrayIf(t),&varDecls)
then
let tvar2 = tempDecl(expTypeArrayIf(t),&varDecls)
let &preExp += if isArrayType(t) then '<%tvar2%>.dim_size = 0;<%\n%>'
tvar2
let &preExp += 'SIM_PROF_TICK_FN(<%funName%>_index);<%\n%>'
let &preExp += if tvar then '<%tvar%> = <%res%>;<%\n%>' else '<%res%>;<%\n%>'
let &preExp += 'SIM_PROF_ACC_FN(<%funName%>_index);<%\n%>'
Expand Down Expand Up @@ -9824,6 +9829,7 @@ template daeExpTsub(Exp inExp, Context context, Text &preExp,
case TSUB(exp=CALL(attr=CALL_ATTR(ty=T_TUPLE(types=tys)))) then
let v = tempDecl(expTypeArrayIf(listGet(tys,ix)), &varDecls)
let additionalOutputs = List.restOrEmpty(tys) |> ty hasindex i1 fromindex 2 => if intEq(i1,ix) then ', &<%v%>' else ", NULL"
let &preExp += if isArrayType(listGet(tys,ix)) then '<%v%>.dim_size = 0;<%\n%>'
let res = daeExpCallTuple(exp, additionalOutputs, context, &preExp, &varDecls, &auxFunction)
let &preExp += '<%res%>;<%\n%>'
v
Expand Down
4 changes: 4 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -3343,6 +3343,10 @@ package Types
input String name;
output Integer index;
end lookupIndexInMetaRecord;
function isArrayWithUnknownDimension
input DAE.Type ty;
output Boolean b;
end isArrayWithUnknownDimension;
end Types;

package FMI
Expand Down
50 changes: 25 additions & 25 deletions Compiler/Util/Flags.mo
Expand Up @@ -321,13 +321,13 @@ constant DebugFlag DUMP_SIMCODE = DEBUG_FLAG(77, "dumpSimCode", false,
constant DebugFlag DUMP_INITIAL_SYSTEM = DEBUG_FLAG(78, "dumpinitialsystem", false,
Util.gettext("Dumps the initial equation system."));
constant DebugFlag GRAPH_INST = DEBUG_FLAG(79, "graphInst", false,
Util.gettext("Do graph based instantation."));
Util.gettext("Do graph based instantiation."));
constant DebugFlag GRAPH_INST_RUN_DEP = DEBUG_FLAG(80, "graphInstRunDep", false,
Util.gettext("Run scode dependency analysis. Use with -d=graphInst"));
constant DebugFlag GRAPH_INST_GEN_GRAPH = DEBUG_FLAG(81, "graphInstGenGraph", false,
Util.gettext("Dumps a graph of the program. Use with -d=graphInst"));
constant DebugFlag GRAPH_INST_SHOW_GRAPH = DEBUG_FLAG(82, "graphInstShowGraph", false,
Util.gettext("Diplay a graph of the program interactively. Use with -d=graphInst"));
Util.gettext("Display a graph of the program interactively. Use with -d=graphInst"));
constant DebugFlag DUMP_CONST_REPL = DEBUG_FLAG(83, "dumpConstrepl", false,
Util.gettext("Dump the found replacements for constants."));
constant DebugFlag PEDANTIC = DEBUG_FLAG(84, "pedantic", false,
Expand Down Expand Up @@ -411,9 +411,9 @@ constant DebugFlag GRAPHML = DEBUG_FLAG(122, "graphml", false,
constant DebugFlag USEMPI = DEBUG_FLAG(123, "useMPI", false,
Util.gettext("Add MPI init and finalize to main method (CPPruntime). "));
constant DebugFlag DUMP_CSE = DEBUG_FLAG(124, "dumpCSE", false,
Util.gettext("Additional ouput for CSE module."));
Util.gettext("Additional output for CSE module."));
constant DebugFlag DUMP_CSE_VERBOSE = DEBUG_FLAG(125, "dumpCSE_verbose", false,
Util.gettext("Additional ouput for CSE module."));
Util.gettext("Additional output for CSE module."));
constant DebugFlag ADD_DER_ALIASES = DEBUG_FLAG(126, "addDerAliases", false,
Util.gettext("Adds for every der-call an alias equation e.g. dx = der(x). It's a work-a-round flag,
which helps im some cases to simulate the models e.g.
Expand All @@ -427,7 +427,7 @@ constant DebugFlag NO_PARTITIONING = DEBUG_FLAG(129, "disablePartitioning", fals
constant DebugFlag ADVANCE_TEARING = DEBUG_FLAG(130, "advanceTearing", false,
Util.gettext("Using ExpressionSolve in adjacencyRowEnhanced"));
constant DebugFlag CONSTJAC = DEBUG_FLAG(131, "constjac", false,
Util.gettext("solves linear systems with const jacobian and variable b-Vector symbolically"));
Util.gettext("solves linear systems with constant Jacobian and variable b-Vector symbolically"));
constant DebugFlag REDUCE_DYN_OPT = DEBUG_FLAG(132, "reduceDynOpt", false,
Util.gettext("remove eqs which not need for the calculations of cost and constraints"));
constant DebugFlag VISUAL_XML = DEBUG_FLAG(133, "visxml", false,
Expand All @@ -445,7 +445,7 @@ constant DebugFlag RUNTIME_STATIC_LINKING = DEBUG_FLAG(138, "runtimeStaticLinkin
constant DebugFlag DYNAMIC_TEARING_INFO = DEBUG_FLAG(139, "dynamicTearingInfo", false,
Util.gettext("Dumps information about the strict and casual sets of the tearing system."));
constant DebugFlag SORT_EQNS_AND_VARS = DEBUG_FLAG(140, "sortEqnsAndVars", false,
Util.gettext("Heuristical sorting for equations and variables. Influenced: removeSimpleEquations and tearing."));
Util.gettext("Heuristic sorting for equations and variables. Influenced: removeSimpleEquations and tearing."));
constant DebugFlag DUMP_SIMPLIFY_LOOPS = DEBUG_FLAG(141, "dumpSimplifyLoops", false,
Util.gettext("Dump between steps of simplifyLoops"));
constant DebugFlag DUMP_RTEARING = DEBUG_FLAG(142, "dumpRecursiveTearing", false,
Expand Down Expand Up @@ -804,22 +804,22 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("relaxSystem",Util.notrans("DESCRIBE ME")),
("countOperations", Util.gettext("Count the mathematic operations of the system.")),
("dumpComponentsGraphStr", Util.notrans("DESCRIBE ME")),
("generateSymbolicJacobian", Util.gettext("Generates symbolic jacobian matrix, where der(x) is differentiated w.r.t. x. This matrix can be used to simulate with dasslColorSymJac.")),
("generateSymbolicLinearization", Util.gettext("Generates symbolic linearization matrixes A,B,C,D for linear model:\n\t\t:math:`\\dot{x} = Ax + Bu`\n\t:math:`ty = Cx +Du`")),
("generateSymbolicJacobian", Util.gettext("Generates symbolic Jacobian matrix, where der(x) is differentiated w.r.t. x. This matrix can be used to simulate with dasslColorSymJac.")),
("generateSymbolicLinearization", Util.gettext("Generates symbolic linearization matrices A,B,C,D for linear model:\n\t\t:math:`\\dot{x} = Ax + Bu`\n\t:math:`ty = Cx +Du`")),
("removeUnusedFunctions", Util.gettext("Removed all unused functions from functionTree.")),
("simplifyTimeIndepFuncCalls", Util.gettext("Simplifies time independent built in function calls like pre(param) -> param, der(param) -> 0.0, change(param) -> false, edge(param) -> false.")),
("inputDerivativesUsed", Util.gettext("Checks if derivatives of inputs are need to calculate the model.")),
("simplifysemiLinear", Util.gettext("Simplifies calls to semiLinear.")),
("removeConstants", Util.gettext("Remove all constants in the system.")),
("detectJacobianSparsePattern", Util.gettext("Detects the sparse pattern for Jacobian A.")),
("calculateStrongComponentJacobians", Util.gettext("Generates analytical jacobian for non-linear strong components.")),
("calculateStateSetsJacobians", Util.gettext("Generates analytical jacobian for dynamic state selection sets.")),
("calculateStrongComponentJacobians", Util.gettext("Generates analytical Jacobian for non-linear strong components.")),
("calculateStateSetsJacobians", Util.gettext("Generates analytical Jacobian for dynamic state selection sets.")),
("addInitialStmtsToAlgorithms", Util.gettext("Expands all algorithms with initial statements for outputs.")),
("reshufflePost", Util.gettext("Reshuffles algebraic loops.")),
("CSE", Util.gettext("Common Subexpression Elimination")),
("dumpDAE", Util.gettext("dumps the DAE representation of the current transformation state")),
("dumpDAEXML", Util.gettext("dumps the DAE as xml representation of the current transformation state")),
("addTimeAsState", Util.gettext("Experimental feature: this repaces each occurrence of variable time with a new introduced state $time with equation der($time) = 1.0"))
("addTimeAsState", Util.gettext("Experimental feature: this replaces each occurrence of variable time with a new introduced state $time with equation der($time) = 1.0"))
})),
Util.gettext("Sets the post optimization modules to use in the back end. See --help=optmodules for more info."));

Expand Down Expand Up @@ -1000,11 +1000,11 @@ constant ConfigFlag REPLACE_HOMOTOPY = CONFIG_FLAG(54, "replaceHomotopy",

constant ConfigFlag GENERATE_SYMBOLIC_JACOBIAN = CONFIG_FLAG(55, "generateSymbolicJacobian",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Generates symbolic jacobian matrix, where der(x) is differentiated w.r.t. x. This matrix can be utilise by dassl with the runtime option: -dasslJacobian=coloredSymbolical|symbolical."));
Util.gettext("Generates symbolic Jacobian matrix, where der(x) is differentiated w.r.t. x. This matrix can be utilise by dassl with the runtime option: -dasslJacobian=coloredSymbolical|symbolical."));

constant ConfigFlag GENERATE_SYMBOLIC_LINEARIZATION = CONFIG_FLAG(56, "generateSymbolicLinearization",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Generates symbolic linearization matrixes A,B,C,D for linear model:\n\t\t:math:`\\dot x = Ax + Bu`\n\t\t:math:`y = Cx +Du`"));
Util.gettext("Generates symbolic linearization matrices A,B,C,D for linear model:\n\t\t:math:`\\dot x = Ax + Bu`\n\t\t:math:`y = Cx +Du`"));

constant ConfigFlag INT_ENUM_CONVERSION = CONFIG_FLAG(57, "intEnumConversion",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Expand Down Expand Up @@ -1057,7 +1057,7 @@ constant ConfigFlag REMOVE_SIMPLE_EQUATIONS = CONFIG_FLAG(67, "removeSimpleEquat
NONE(), EXTERNAL(), STRING_FLAG("default"),
SOME(STRING_DESC_OPTION({
("none", Util.gettext("Disables module")),
("default", Util.gettext("Performs alias elimination and removes constant variables. Dafault case uses in preOpt phase the fastAcausal and in postOpt phase the causal implementation.")),
("default", Util.gettext("Performs alias elimination and removes constant variables. Default case uses in preOpt phase the fastAcausal and in postOpt phase the causal implementation.")),
("causal", Util.gettext("Performs alias elimination and removes constant variables. Causal implementation.")),
("fastAcausal", Util.gettext("Performs alias elimination and removes constant variables. fastImplementation fastAcausal.")),
("allAcausal", Util.gettext("Performs alias elimination and removes constant variables. Implementation allAcausal.")),
Expand All @@ -1071,20 +1071,20 @@ constant ConfigFlag DYNAMIC_TEARING = CONFIG_FLAG(68, "dynamicTearing",

constant ConfigFlag SYM_EULER = CONFIG_FLAG(69, "symEuler",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Rewritte the ode system for inplicit euler."));
Util.gettext("Rewrite the ode system for implicit euler."));

constant ConfigFlag ADD_TIME_AS_STATE = CONFIG_FLAG(70,
"addTimeAsState", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Experimental feature: this repaces each occurrence of variable time with a new introduced state $time with equation der($time) = 1.0"));
Util.gettext("Experimental feature: this replaces each occurrence of variable time with a new introduced state $time with equation der($time) = 1.0"));

constant ConfigFlag LOOP2CON = CONFIG_FLAG(71, "loop2con",
NONE(), EXTERNAL(), STRING_FLAG("none"),
SOME(STRING_DESC_OPTION({
("none", Util.gettext("Disables module")),
("lin", Util.gettext("linear loops --> constraints.")),
("noLin", Util.gettext("no linear loops --> constraints.")),
("all", Util.gettext("loops --> constraints."))})),
Util.gettext("Specifies method that transform loops in constraints. hint: using intial guess from file!"));
("lin", Util.gettext("linear loops --> constraints")),
("noLin", Util.gettext("no linear loops --> constraints")),
("all", Util.gettext("loops --> constraints"))})),
Util.gettext("Specifies method that transform loops in constraints. hint: using initial guess from file!"));

constant ConfigFlag FORCE_TEARING = CONFIG_FLAG(72, "forceTearing",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Expand All @@ -1093,16 +1093,16 @@ constant ConfigFlag FORCE_TEARING = CONFIG_FLAG(72, "forceTearing",
constant ConfigFlag SIMPLIFY_LOOPS = CONFIG_FLAG(73, "simplifyLoops",
NONE(), EXTERNAL(), INT_FLAG(0),
SOME(STRING_DESC_OPTION({
("0", Util.gettext("do nonthing.")),
("1", Util.gettext("special modification of residula expressions.")),
("2", Util.gettext("special modification of residula expressions with helper variables."))
("0", Util.gettext("do nothing")),
("1", Util.gettext("special modification of residual expressions")),
("2", Util.gettext("special modification of residual expressions with helper variables"))
})),
Util.gettext("simplify algebraic loops."));
Util.gettext("simplify algebraic loops"));

constant ConfigFlag RTEARING = CONFIG_FLAG(74, "recursiveTearing",
NONE(), EXTERNAL(), INT_FLAG(0),
SOME(STRING_DESC_OPTION({
("0", Util.gettext("do nonthing.")),
("0", Util.gettext("do nothing")),
("1", Util.gettext("linear tearing set of size 1")),
("2", Util.gettext("linear tearing"))
})),
Expand Down
2 changes: 1 addition & 1 deletion Compiler/boot/Makefile.common
Expand Up @@ -41,7 +41,7 @@ bootstrap-from-tarball: $(PATCHES)
tar xJf bootstrap-sources.tar.xz
# Patch _main.c to avoid a new tarball
$(PATCH_SOURCES)
cd build && for x in ../patches/*.patch; do patch -i "$$x" "`basename $$x | sed 's/\([.][0-9]*\)\?[.]patch/.c/'`" || exit 1; done
cd build && for x in ../patches/*.patch; do patch -i "$$x" "`basename $$x | $(SED) 's/\([.][0-9]*\)\?[.]patch/.c/'`" || exit 1; done
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC=.omc
@echo "Bootstrapping phase 1/3 completed"
$(MAKE) -f $(defaultMakefileTarget) clean OMC=$(BOOTSTRAP_OMC)
Expand Down

0 comments on commit 69ba949

Please sign in to comment.