Skip to content

Commit

Permalink
- Implement feature #2542
Browse files Browse the repository at this point in the history
- Use:
  +replaceHomotopy      Replaces homotopy(actual, simplified) with the 
                        actual expression or the simplified expression. 
                        Good for debugging models which use homotopy. 
                        The default is to not replace homotopy.
                        Valid options:
                        * none (default)
                        * actual
                        * simplified
  Use with +replaceHomotopy=actual|simplified or setCommandLineOptions("+replaceHomotopy=actual|simplified") via scripting.
- Added testsuite/flattening/modelica/others/Homotopy.mos for testing the new facility.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18696 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Jan 20, 2014
1 parent 5d3e3be commit 095936b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
21 changes: 17 additions & 4 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -492,7 +492,7 @@ algorithm
Boolean impl,a,b,havereal,doVect;
Integer l,i,nmax;
Real r;
String expstr,str1,str2,s,msg;
String expstr,str1,str2,s,msg,replaceWith;
DAE.Dimension dim1,dim2;
Option<GlobalScript.SymbolTable> st,st_1,st_2;
DAE.Exp exp,e1_1,e2_1,exp_1,e_1,mexp,mexp_1,arrexp;
Expand Down Expand Up @@ -534,7 +534,7 @@ algorithm
// types. But since they are default, we can leave them out for now, unit=\"\" is not
// that interesting to find out.
case (cache,_,Absyn.INTEGER(value = i),impl,st,doVect,_,_,_)
then (cache,DAE.ICONST(i),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST()),st);
then (cache,DAE.ICONST(i),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST()),st);

case (cache,_,Absyn.REAL(value = r),impl,st,doVect,_,_,_)
then
Expand Down Expand Up @@ -663,7 +663,6 @@ algorithm
then
(cache,e_1,prop1,st);


//Check if 'String' is overloaded. This can be moved down the chain to avoid checking for normal types.
//However elab call prints error messags if it can not elaborate it even though the function might be overloaded.
case (cache,env, e as Absyn.CALL(function_ = Absyn.CREF_IDENT("String",_),functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect,pre,_,_)
Expand All @@ -672,9 +671,23 @@ algorithm
then
(cache,exp_1,prop,st_1);

// homotopy replacement (usually used for debugging only)
case (cache,env,Absyn.CALL(function_ = Absyn.CREF_IDENT("homotopy", _),functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect,pre,_,_)
equation
replaceWith = Flags.getConfigString(Flags.REPLACE_HOMOTOPY);
// replace homotopy if Flags.REPLACE_HOMOTOPY is "actual" or "simplified"
false = stringEq(replaceWith, "none");
true = boolOr(stringEq(replaceWith, "actual"), stringEq(replaceWith, "simplified"));
// TODO, handle empy args and nargs for homotopy!
{e1, e2} = args;
e = Util.if_(stringEq(replaceWith, "actual"), e1, e2);
(cache,e_1,prop,st_1) = elabExp(cache, env, e, impl, st, doVect, pre, info);
then
(cache,e_1,prop,st_1);

case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,doVect,pre,_,_)
equation
(cache,e_1,prop,st_1) = elabCall(cache,env, fn, args, nargs, impl, st,pre,info,Error.getNumErrorMessages());
(cache,e_1,prop,st_1) = elabCall(cache, env, fn, args, nargs, impl, st, pre, info, Error.getNumErrorMessages());
c = Types.propAllConst(prop);
(e_1,_) = ExpressionSimplify.simplify1(e_1);
then
Expand Down
14 changes: 12 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -822,7 +822,7 @@ constant ConfigFlag TEARING_HEURISTIC = CONFIG_FLAG(51, "tearingHeuristic",
("cellier5", Util.gettext("Modified cellier2, step 'count impossible assignments' before last step.")),
("cellier6", Util.gettext("Modified cellier4, step 'count impossible assignments' before last step.")),
("cellier7", Util.gettext("Modified cellier4, Two rounds, choose better potentials-set."))})),
Util.gettext("Sets the tearing heuristic to use for Cellier-tearing."));
Util.gettext("Sets the tearing heuristic to use for Cellier-tearing."));

constant ConfigFlag HPCOM_CODE = CONFIG_FLAG(52, "hpcomCode",
NONE(), EXTERNAL(), STRING_FLAG("openmp"), NONE(),
Expand All @@ -832,6 +832,15 @@ constant ConfigFlag REWRITE_RULES_FILE = CONFIG_FLAG(53, "rewriteRulesFile", NON
STRING_FLAG(""), NONE(),
Util.gettext("Activates user given rewrite rules for Absyn expressions. The rules are read from the given file and are of the form rewrite(fromExp, toExp);"));

constant ConfigFlag REPLACE_HOMOTOPY = CONFIG_FLAG(54, "replaceHomotopy",
NONE(), EXTERNAL(), STRING_FLAG("none"),
SOME(STRING_DESC_OPTION({
("none", Util.gettext("Default, do not replace homotopy.")),
("actual", Util.gettext("Replace homotopy(actual, simplified) with actual.")),
("simplified", Util.gettext("Replace homotopy(actual, simplified with simplified."))
})),
Util.gettext("Replaces homotopy(actual, simplified) with the actual expression or the simplified expression. Good for debugging models which use homotopy. The default is to not replace homotopy."));

// This is a list of all configuration flags. A flag can not be used unless it's
// in this list, and the list is checked at initialization so that all flags are
// sorted by index (and thus have unique indices).
Expand Down Expand Up @@ -888,7 +897,8 @@ constant list<ConfigFlag> allConfigFlags = {
HPCOM_SCHEDULER,
TEARING_HEURISTIC,
HPCOM_CODE,
REWRITE_RULES_FILE
REWRITE_RULES_FILE,
REPLACE_HOMOTOPY
};

public function new
Expand Down

0 comments on commit 095936b

Please sign in to comment.