Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/OpenModelica/OMCompiler
- Loading branch information
Showing
24 changed files
with
429 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package CodegenCppInit | ||
|
||
import interface SimCodeTV; | ||
import CodegenUtil.*; | ||
|
||
template modelInitXMLFile(SimCode simCode, String numRealVars, String numIntVars, String numBoolVars) | ||
::= | ||
match simCode | ||
case SIMCODE(modelInfo = MODELINFO(__)) then | ||
let variables = modelVariablesXML(modelInfo, varToArrayIndexMapping, '<%numRealVars%> - 1', '<%numIntVars%> - 1', '<%numBoolVars%> - 1') | ||
let algLoops = (listAppend(allEquations,initialEquations) |> eq => algLoopXML(eq, simCode, varToArrayIndexMapping, '<%numRealVars%> - 1') ;separator="\n") | ||
let jacobianMatrixes = jacobianMatrixesXML(simCode.jacobianMatrixes) | ||
<< | ||
<?xml version="1.0" encoding="UTF8"?> | ||
<ModelDescription modelName="<%dotPath(modelInfo.name)%>"> | ||
<ModelVariables> | ||
<%variables%> | ||
</ModelVariables> | ||
<AlgLoops> | ||
<%algLoops%> | ||
</AlgLoops> | ||
<Jacobian> | ||
<%jacobianMatrixes%> | ||
</Jacobian> | ||
</ModelDescription> | ||
>> | ||
end modelInitXMLFile; | ||
|
||
template modelVariablesXML(ModelInfo modelInfo, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferencesReal, String indexForUndefinedReferencesInt, String indexForUndefinedReferencesBool) | ||
"Generates the xml code for the variable defintions." | ||
::= | ||
match modelInfo | ||
case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numAlgVars= numAlgVars, numDiscreteReal = numDiscreteReal, numOptimizeConstraints = numOptimizeConstraints)) then | ||
<< | ||
<%vars.stateVars |> var => scalarVariableXML(var, varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
<%vars.derivativeVars |> var => scalarVariableXML(var, varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
<%vars.algVars |> var => scalarVariableXML(var, varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
<%vars.discreteAlgVars |> var => scalarVariableXML(var, varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
<%/*vars.realOptimizeConstraintsVars | ||
|> var hasindex i0 => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty*/%> | ||
<%/*vars.realOptimizeFinalConstraintsVars | ||
|> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty*/%> | ||
<%vars.paramVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
<%vars.aliasVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesReal) ;separator="\n";empty%> | ||
|
||
<%vars.intAlgVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesInt) ;separator="\n";empty%> | ||
<%vars.intParamVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesInt) ;separator="\n";empty%> | ||
<%vars.intAliasVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesInt) ;separator="\n";empty%> | ||
|
||
<%vars.boolAlgVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesBool) ;separator="\n";empty%> | ||
<%vars.boolParamVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesBool) ;separator="\n";empty%> | ||
<%vars.boolAliasVars |> var => scalarVariableXML(var,varToArrayIndexMapping, indexForUndefinedReferencesBool) ;separator="\n";empty%> | ||
>> | ||
/* | ||
<%vars.stringAlgVars |> var hasindex i0 => ScalarVariable(var,i0,"sAlg") ;separator="\n";empty%> | ||
<%vars.stringParamVars |> var hasindex i0 => ScalarVariable(var,i0,"sPar") ;separator="\n";empty%> | ||
<%vars.stringAliasVars |> var hasindex i0 => ScalarVariable(var,i0,"sAli") ;separator="\n";empty%> | ||
*/ | ||
end modelVariablesXML; | ||
|
||
template scalarVariableXML(SimVar simVar, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferences) | ||
"Generates code for ScalarVariable file for FMU target." | ||
::= | ||
match simVar | ||
case SIMVAR(__) then | ||
<< | ||
<ScalarVariable <%scalarVariableAttributeXML(simVar, varToArrayIndexMapping, indexForUndefinedReferences)%>> | ||
<%ScalarVariableType(unit, displayUnit, minValue, maxValue, initialValue, nominalValue, isFixed, type_)%> | ||
</ScalarVariable> | ||
>> | ||
end scalarVariableXML; | ||
|
||
template scalarVariableAttributeXML(SimVar simVar, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferences) | ||
"Generates code for ScalarVariable Attribute file for FMU target." | ||
::= | ||
match simVar | ||
case SIMVAR(source = SOURCE(info = info)) then | ||
let valueReference = SimCodeUtil.getVarIndexListByMapping(varToArrayIndexMapping,name,indexForUndefinedReferences) | ||
let variability = getVariablity(varKind) | ||
let description = if comment then 'description = "<%Util.escapeModelicaStringToXmlString(comment)%>"' | ||
<< | ||
name = "<%Util.escapeModelicaStringToXmlString(crefStrNoUnderscore(name))%>" valueReference = "<%valueReference%>" <%description%> variability = "<%variability%>" isProtected = "<%isProtected%>" | ||
>> | ||
end scalarVariableAttributeXML; | ||
|
||
template algLoopXML(SimEqSystem eqs, SimCode simCode, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferences) | ||
::= | ||
<< | ||
<% | ||
match(eqs) | ||
case(SES_LINEAR(lSystem = ls as LINEARSYSTEM(__))) then | ||
<< | ||
<Linear eqIdx="<%ls.index%>" sparse="true" size="<%listLength(ls.vars)%>"> | ||
<Vars> | ||
<%ls.vars |> v as SIMVAR(__) => '<Var type="double" index="<%SimCodeUtil.getVarIndexListByMapping(varToArrayIndexMapping,v.name,indexForUndefinedReferences)%>" />' ;separator="\n"%> | ||
</Vars> | ||
</Linear> | ||
>> | ||
case(SES_NONLINEAR(nlSystem = nls as NONLINEARSYSTEM(__))) then | ||
<< | ||
<NonLinear eqIdx="<%nls.index%>" size="<%listLength(nls.crefs)%>"> | ||
<Vars> | ||
<%nls.crefs |> name => '<Var type="double" index="<%SimCodeUtil.getVarIndexListByMapping(varToArrayIndexMapping,name,indexForUndefinedReferences)%>" />' ;separator="\n"%> | ||
</Vars> | ||
<NominalVars> | ||
<!-- Maybe Expressions here --> | ||
</NominalVars> | ||
</NonLinear> | ||
>> | ||
else | ||
'' | ||
%> | ||
>> | ||
end algLoopXML; | ||
|
||
template jacobianMatrixesXML(list<JacobianMatrix> JacobianMatrixes) | ||
::= | ||
let jacMats = (JacobianMatrixes |> (mat, vars, name, (sparsepattern,_), colorList, maxColor, jacIndex) => | ||
jacobianMatrixXML(jacIndex, mat, vars, name, sparsepattern, colorList, maxColor) | ||
;separator="\n";empty) | ||
<< | ||
<%jacMats%> | ||
>> | ||
end jacobianMatrixesXML; | ||
|
||
template jacobianMatrixXML(Integer indexJacobian, list<JacobianColumn> jacobianColumn, list<SimVar> seedVars, String matrixName, list<tuple<Integer,list<Integer>>> sparsepattern, list<list<Integer>> colorList, Integer maxColor) | ||
::= | ||
let indexColumn = (jacobianColumn |> (eqs,vars,indxColumn) => indxColumn; separator="\n") | ||
let jacvals = (sparsepattern |> (index,indexes) hasindex index0 => | ||
'<Column> | ||
<%(indexes |> i_index hasindex index1 => | ||
( | ||
match indexColumn case "1" then '<Entry indexX="<%index%>" indexY="0" valueIndex="0"/>' | ||
else '<Entry indexX="<%index%>" indexY="<%i_index%>" valueIndex="<%i_index%>"/>' | ||
);separator="\n" | ||
)%> | ||
</Column>' | ||
;separator="\n" | ||
) | ||
<< | ||
<Matrix name="<%matrixName%>"> | ||
<Column> | ||
<%jacvals%> | ||
</Column> | ||
</Matrix> | ||
>> | ||
end jacobianMatrixXML; | ||
|
||
|
||
annotation(__OpenModelica_Interface="backend"); | ||
end CodegenCppInit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Find the header files of the scorep compiler wrapper. | ||
# | ||
# Sets the usual variables expected for find_package scripts: | ||
# | ||
# SCOREP_INCLUDE_DIR - header location | ||
# SCOREP_FOUND - true if pugixml was found. | ||
# | ||
# To influence the behaviour, you can use the following variable: | ||
# SCOREP_HOME - the folder that contains the scorep include folder | ||
|
||
find_path (SCOREP_INCLUDE_DIR NAMES scorep/SCOREP_User.h PATHS ${SCOREP_HOME}/include) | ||
|
||
include (FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (SCOREP DEFAULT_MSG SCOREP_INCLUDE_DIR) | ||
|
||
if (NOT SCOREP_FOUND) | ||
message (FATAL_ERROR "ScoreP includes not found") | ||
endif(NOT SCOREP_FOUND) | ||
|
||
message(STATUS "ScoreP includes ${SCOREP_INCLUDE_DIR}") | ||
|
||
mark_as_advanced (SCOREP_INCLUDE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <Core/ModelicaDefine.h> | ||
#include <Core/Modelica.h> | ||
#include <Core/DataExchange/XmlPropertyReader.h> | ||
#include <boost/property_tree/xml_parser.hpp> | ||
#include <boost/property_tree/ptree.hpp> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
XmlPropertyReader::XmlPropertyReader(std::string propertyFile) : IPropertyReader(), propertyFile(propertyFile) | ||
{ | ||
} | ||
|
||
XmlPropertyReader::~XmlPropertyReader() | ||
{ | ||
|
||
} | ||
|
||
void XmlPropertyReader::readInitialValues(boost::shared_ptr<ISimVars> sim_vars) | ||
{ | ||
using boost::property_tree::ptree; | ||
std::ifstream file(propertyFile.c_str()); | ||
|
||
if(file) | ||
{ | ||
double *realVars = sim_vars->getRealVarsVector(); | ||
int *intVars = sim_vars->getIntVarsVector(); | ||
bool *boolVars = sim_vars->getBoolVarsVector(); | ||
|
||
ptree tree; | ||
read_xml(file, tree); | ||
|
||
ptree modelDescription = tree.get_child("ModelDescription"); | ||
|
||
BOOST_FOREACH(ptree::value_type const& vars, modelDescription.get_child("ModelVariables")) | ||
{ | ||
if(vars.first == "ScalarVariable") | ||
{ | ||
int refIdx = vars.second.get<int>("<xmlattr>.valueReference"); | ||
BOOST_FOREACH(ptree::value_type const& var, vars.second.get_child("")) | ||
{ | ||
if(var.first == "Real") | ||
{ | ||
boost::optional<float> v = var.second.get_optional<float>("<xmlattr>.start"); | ||
std::cerr << "Setting real variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
realVars[refIdx] = *v; | ||
} | ||
else if(var.first == "Int") | ||
{ | ||
boost::optional<int> v = var.second.get_optional<int>("<xmlattr>.start"); | ||
std::cerr << "Setting int variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
intVars[refIdx] = *v; | ||
} | ||
else if(var.first == "Boolean") | ||
{ | ||
boost::optional<bool> v = var.second.get_optional<bool>("<xmlattr>.start"); | ||
std::cerr << "Setting bool variable for " << vars.second.get<std::string>("<xmlattr>.name") << " with reference " << refIdx << " to " << *v << std::endl; | ||
if(v) | ||
realVars[refIdx] = *v; | ||
} | ||
} | ||
} | ||
sim_vars->setRealVarsVector(realVars); | ||
sim_vars->setIntVarsVector(intVars); | ||
sim_vars->setBoolVarsVector(boolVars); | ||
} | ||
|
||
file.close(); | ||
} | ||
} | ||
|
||
std::string XmlPropertyReader::getPropertyFile() | ||
{ | ||
return propertyFile; | ||
} | ||
|
||
void XmlPropertyReader::setPropertyFile(std::string file) | ||
{ | ||
propertyFile = file; | ||
} |
Oops, something went wrong.