Skip to content

Commit

Permalink
[NB] Create new package Evaluation.mo (#10384)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Mar 10, 2023
1 parent 9c41269 commit 8033a9c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 35 deletions.
1 change: 1 addition & 0 deletions OMCompiler/Compiler/.cmake/meta_modelica_source_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ set(OMC_MM_BACKEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Modules/3_Post/NBJacobian.mo
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Modules/3_Post/NBSolve.mo
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Modules/3_Post/NBTearing.mo
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Modules/3_Post/NBEvaluation.mo
# "NBackend Util";
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Util/NBBackendUtil.mo
${CMAKE_CURRENT_SOURCE_DIR}/NBackEnd/Util/NBDifferentiate.mo
Expand Down
41 changes: 10 additions & 31 deletions OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public
import OldBackendDAE = BackendDAE;

// New Backend imports
import Evaluation = NBEvaluation;
import Replacements = NBReplacements;
import StrongComponent = NBStrongComponent;
import Solve = NBSolve;
Expand Down Expand Up @@ -2613,7 +2614,7 @@ public
record EQUATION_ATTRIBUTES
Option<Pointer<Equation>> derivative;
EquationKind kind;
EvaluationStages evalStages;
Evaluation.Stages evalStages;
Option<Pointer<Variable>> residualVar "also used to represent the equation itself";
end EQUATION_ATTRIBUTES;

Expand Down Expand Up @@ -2656,17 +2657,17 @@ public
oldAttributes := OldBackendDAE.EQUATION_ATTRIBUTES(
differentiated = Util.isSome(attributes.derivative),
kind = EquationKind.convert(attributes.kind),
evalStages = EvaluationStages.convert(attributes.evalStages));
evalStages = Evaluation.Stages.convert(attributes.evalStages));
end convert;
end EquationAttributes;

constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(NONE(), DYNAMIC_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(NONE(), BINDING_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(NONE(), INITIAL_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_DISCRETE = EQUATION_ATTRIBUTES(NONE(), DISCRETE_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_AUX = EQUATION_ATTRIBUTES(NONE(), AUX_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_EMPTY_DISCRETE = EQUATION_ATTRIBUTES(NONE(), EMPTY_EQUATION(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(NONE(), UNKNOWN_EQUATION_KIND(), DEFAULT_EVALUATION_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_DYNAMIC = EQUATION_ATTRIBUTES(NONE(), DYNAMIC_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_BINDING = EQUATION_ATTRIBUTES(NONE(), BINDING_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_INITIAL = EQUATION_ATTRIBUTES(NONE(), INITIAL_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_DISCRETE = EQUATION_ATTRIBUTES(NONE(), DISCRETE_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_AUX = EQUATION_ATTRIBUTES(NONE(), AUX_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_EMPTY_DISCRETE = EQUATION_ATTRIBUTES(NONE(), EMPTY_EQUATION(), NBEvaluation.DEFAULT_STAGES, NONE());
constant EquationAttributes EQ_ATTR_DEFAULT_UNKNOWN = EQUATION_ATTRIBUTES(NONE(), UNKNOWN_EQUATION_KIND(), NBEvaluation.DEFAULT_STAGES, NONE());

uniontype EquationKind
record BINDING_EQUATION end BINDING_EQUATION;
Expand Down Expand Up @@ -2718,28 +2719,6 @@ public
end isInitial;
end EquationKind;

uniontype EvaluationStages
record EVALUATION_STAGES
Boolean dynamicEval;
Boolean algebraicEval;
Boolean zerocrossEval;
Boolean discreteEval;
end EVALUATION_STAGES;

function convert
input EvaluationStages evalStages;
output OldBackendDAE.EvaluationStages oldEvalStages;
algorithm
oldEvalStages := OldBackendDAE.EVALUATION_STAGES(
dynamicEval = evalStages.dynamicEval,
algebraicEval = evalStages.algebraicEval,
zerocrossEval = evalStages.zerocrossEval,
discreteEval = evalStages.discreteEval);
end convert;
end EvaluationStages;

constant EvaluationStages DEFAULT_EVALUATION_STAGES = EVALUATION_STAGES(true,true,false,true);

uniontype EquationPointers
record EQUATION_POINTERS
UnorderedMap<ComponentRef, Integer> map "Map for cref->index";
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/NBackEnd/Classes/NBackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public
mainModules := (DAEMode.main, "DAE-Mode") :: mainModules;
end if;

// (do not change order SOLVE -> JACOBIAN)
postOptModules := {
(function Tearing.main(systemType = NBSystem.SystemType.ODE), "Tearing"),
(Partitioning.categorize, "Categorize"),
Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBSorting.mo
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public
// phase 2 tarjan
(phase2_adj, phase2_matching, super_nodes) := SuperNode.create(adj, matching, comps_indices, bucket);

// kabdelhak: this matching is superfluous, SuperNode.create always returns these types.
// kabdelhak: this match-statement is superfluous, SuperNode.create always returns these types.
// it is just safer if something is changed in the future
() := match phase2_adj
case Adjacency.Matrix.PSEUDO_ARRAY_ADJACENCY_MATRIX() algorithm
Expand Down Expand Up @@ -379,7 +379,7 @@ public
buckets := list(bucket_tpl for bucket_tpl guard(not PseudoBucket.emptyBucketTpl(bucket_tpl)) in buckets);
shift := listLength(algebraic_loops) + listLength(buckets);

//### 2. initialize super nodes ###
// ### 2. initialize super nodes ###
super_nodes := listArray(list(SuperNode.SINGLE(i) for i in 1:arrayLength(phase2_adj.m) + shift));

// ### 3. expand matching ###
Expand All @@ -395,7 +395,7 @@ public
phase2_matching.var_to_eqn[i] := i;
end for;

//### 4. adjust transposed matrix ###
// ### 4. adjust transposed matrix ###
// 4.1. enlarge transposed matrix by the maximum possible amount of new nodes
index := arrayLength(phase2_adj.mT) + 1;
phase2_adj.mT := Adjacency.Matrix.expandMatrix(phase2_adj.mT, shift);
Expand Down Expand Up @@ -441,7 +441,7 @@ public
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because of unknown adjacency matrix type."});
then fail();
end match;
/*
/*
print(Adjacency.Matrix.toString(adj, "before"));
print(Matching.toString(matching, "before"));
print(Adjacency.Matrix.toString(phase2_adj, "after"));
Expand Down
71 changes: 71 additions & 0 deletions OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBEvaluation.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package NBEvaluation
"file: NBEvaluation.mo
package: NBEvaluation
description: This file contains the functions to create and analyze the
evaluation dependency graph.
This graph is used for the different evaluation stages.
"

public
import BackendDAE = NBackendDAE;
import Module = NBModule;

protected
// Old Backend imports
import OldBackendDAE = BackendDAE;

public
uniontype Stages
record STAGES
Boolean dynamicEval;
Boolean algebraicEval;
Boolean zerocrossEval;
Boolean discreteEval;
end STAGES;

function convert
input Stages stages;
output OldBackendDAE.EvaluationStages oldEvalStages;
algorithm
oldEvalStages := OldBackendDAE.EVALUATION_STAGES(
dynamicEval = stages.dynamicEval,
algebraicEval = stages.algebraicEval,
zerocrossEval = stages.zerocrossEval,
discreteEval = stages.discreteEval);
end convert;
end Stages;

constant Stages DEFAULT_STAGES = STAGES(true, true, false, true);

annotation(__OpenModelica_Interface="backend");
end NBEvaluation;
1 change: 1 addition & 0 deletions OMCompiler/Compiler/boot/LoadCompilerSources.mos
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ if true then /* Suppress output */
"../NBackEnd/Modules/3_Post/NBJacobian.mo",
"../NBackEnd/Modules/3_Post/NBSolve.mo",
"../NBackEnd/Modules/3_Post/NBTearing.mo",
"../NBackEnd/Modules/3_Post/NBEvaluation.mo",
// "NBackend Util"
"../NBackEnd/Util/NBBackendUtil.mo",
"../NBackEnd/Util/NBDifferentiate.mo",
Expand Down

0 comments on commit 8033a9c

Please sign in to comment.