OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBDAEMode.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package NBDAEMode | ||
| 37 | "file: NBDAEMode.mo | ||
| 38 | package: NBDAEMode | ||
| 39 | description: This file contains the functions which create the DAE-Mode data. | ||
| 40 | " | ||
| 41 | |||
| 42 | public | ||
| 43 | import Module = NBModule; | ||
| 44 | |||
| 45 | protected | ||
| 46 | // NF imports | ||
| 47 | import Variable = NFVariable; | ||
| 48 | |||
| 49 | // Backend imports | ||
| 50 | import BackendDAE = NBackendDAE; | ||
| 51 | import Causalize = NBCausalize; | ||
| 52 | import NBEquation.{Equation, EquationPointers, EqData, Iterator}; | ||
| 53 | import Inline = NBInline; | ||
| 54 | import Jacobian = NBJacobian; | ||
| 55 | import Partition = NBPartition; | ||
| 56 | import StrongComponent = NBStrongComponent; | ||
| 57 | import Tearing = NBTearing; | ||
| 58 | import BVariable = NBVariable; | ||
| 59 | import NBVariable.{VariablePointer, VariablePointers, VarData}; | ||
| 60 | |||
| 61 | public | ||
| 62 | function main extends Module.wrapper; | ||
| 63 | protected | ||
| 64 | Module.daeModeInterface func; | ||
| 65 | algorithm | ||
| 66 | try | ||
| 67 | 1 | func := getModule(); | |
| 68 | // for now just copy the dae | ||
| 69 | bdae := match bdae | ||
| 70 | local | ||
| 71 | list<Partition.Partition> ode; | ||
| 72 | EqData eqData; | ||
| 73 | VariablePointers variables; | ||
| 74 | |||
| 75 | case BackendDAE.MAIN(ode = ode, eqData = eqData as EqData.EQ_DATA_SIM(), varData = VarData.VAR_DATA_SIM(variables = variables)) | ||
| 76 | algorithm | ||
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
2 | bdae.dae := SOME(func(ode, variables, eqData.uniqueIndex)); |
| 78 | then bdae; | ||
| 79 | |||
| 80 | else algorithm | ||
| 81 | ✗ | Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed due to wrong BackendDAE record!"}); | |
| 82 | ✗ | then fail(); | |
| 83 | end match; | ||
| 84 | |||
| 85 | // fake causalize system to fulfill pipeline requirements | ||
| 86 | 1 | bdae := Causalize.main(bdae, NBPartition.Kind.DAE); | |
| 87 | else | ||
| 88 | ✗ | Error.addMessage(Error.INTERNAL_ERROR, {getInstanceName() + " failed."}); | |
| 89 | end try; | ||
| 90 | end main; | ||
| 91 | |||
| 92 | function getModule | ||
| 93 | "Returns the module function that was chosen by the user." | ||
| 94 | output Module.daeModeInterface func; | ||
| 95 | protected | ||
| 96 | String flag = "default"; //Flags.getConfigString(Flags.DAE_MODE) | ||
| 97 | algorithm | ||
| 98 | func := match flag | ||
| 99 | case "default" then daeModeDefault; | ||
| 100 | /* ... New dae mode modules have to be added here */ | ||
| 101 | else fail(); | ||
| 102 | end match; | ||
| 103 | end getModule; | ||
| 104 | |||
| 105 | protected | ||
| 106 | function daeModeDefault extends Module.daeModeInterface; | ||
| 107 | protected | ||
| 108 | list<Partition.Partition> new_partitions = {}; | ||
| 109 | algorithm | ||
| 110 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2 | for part in partitions loop |
| 111 | new_partitions := match part.association | ||
| 112 | local | ||
| 113 | Partition.Association association; | ||
| 114 | EquationPointers new_eqns; | ||
| 115 | VariablePointers new_vars; | ||
| 116 | |||
| 117 | case association as Partition.Association.CONTINUOUS() algorithm | ||
| 118 | // update association to continuous -> dae | ||
| 119 | 1 | association.kind := NBPartition.Kind.DAE; | |
| 120 | 1 | part.association := association; | |
| 121 | |||
| 122 | // get the new components | ||
| 123 | 1 | part.strongComponents := StrongComponent.sortDAEModeComponents(part.strongComponents, variables, uniqueIndex); | |
| 124 | |||
| 125 | // get the new equations and variables | ||
| 126 | (new_eqns, new_vars) := match part.strongComponents | ||
| 127 | local | ||
| 128 | array<StrongComponent> new_c; | ||
| 129 | list<Pointer<Equation>> eqns; | ||
| 130 | list<Pointer<Variable>> vars; | ||
| 131 | UnorderedSet<Pointer<Equation>> new_eqns_set; | ||
| 132 | UnorderedSet<Pointer<Variable>> new_vars_set; | ||
| 133 | |||
| 134 | case SOME(new_c) algorithm | ||
| 135 | 1 | new_eqns_set := UnorderedSet.new(Equation.hash, Equation.equalName); | |
| 136 | 1 | new_vars_set := UnorderedSet.new(BVariable.hash, BVariable.equalName); | |
| 137 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | for comp in new_c loop |
| 138 | 1 | eqns := StrongComponent.getEquations(comp); | |
| 139 | 1 | vars := StrongComponent.getVariables(comp); | |
| 140 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | for eqn in eqns loop UnorderedSet.add(eqn, new_eqns_set); end for; |
| 141 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | for var in vars loop UnorderedSet.add(var, new_vars_set); end for; |
| 142 | end for; | ||
| 143 | 1 | then (EquationPointers.fromList(UnorderedSet.toList(new_eqns_set)), VariablePointers.fromList(UnorderedSet.toList(new_vars_set))); | |
| 144 | ✗ | else (part.equations, part.unknowns); | |
| 145 | end match; | ||
| 146 | |||
| 147 | 1 | part.equations := new_eqns; | |
| 148 | 1 | part.daeUnknowns := SOME(part.unknowns); | |
| 149 | 1 | part.unknowns := new_vars; | |
| 150 | |||
| 151 | // accumulate new partitions | ||
| 152 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | then if Partition.Partition.isEmpty(part) then new_partitions else part :: new_partitions; |
| 153 | |||
| 154 | else new_partitions; | ||
| 155 | end match; | ||
| 156 | end for; | ||
| 157 | 1 | partitions := listReverse(new_partitions); | |
| 158 | end daeModeDefault; | ||
| 159 | |||
| 160 | annotation(__OpenModelica_Interface="nbackend"); | ||
| 161 | end NBDAEMode; | ||
| 162 |