Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedKamp committed Jun 17, 2015
2 parents 562f2cb + ca33ed1 commit d92fe2e
Show file tree
Hide file tree
Showing 24 changed files with 429 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -87,6 +87,7 @@ SimulationRuntime/c/util/java_interface/src/org/openmodelica/corba/parser/OMCorb
SimulationRuntime/cpp/Makefile
SimulationRuntime/cpp/Build/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
SimulationRuntime/ParModelica/Makefile
SimulationRuntime/ParModelica/auto/Makefile
SimulationRuntime/ParModelica/explicit/Makefile
Expand All @@ -109,6 +110,7 @@ Compiler/Template/CodegenC.mo.log
Compiler/Template/CodegenCSharp.mo
Compiler/Template/CodegenCpp.mo
Compiler/Template/CodegenCppHpcom.mo
Compiler/Template/CodegenCppInit.mo
Compiler/Template/CodegenFMU.mo
Compiler/Template/CodegenFMU1.mo
Compiler/Template/CodegenFMU2.mo
Expand All @@ -134,6 +136,7 @@ Compiler/Template/TaskSystemDump.mo
Compiler/Template/TplCodegen.mo
Compiler/Template/Unparsing.mo
Compiler/Template/VisualXMLTpl.mo
Compiler/Template/*.err.mo
Compiler/boot/LoadCompilerInterface.mos
Compiler/boot/Makefile
Compiler/boot/Makefile.depends
Expand Down
118 changes: 75 additions & 43 deletions Compiler/Template/CodegenCpp.tpl

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions Compiler/Template/CodegenCppInit.tpl
@@ -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;
11 changes: 8 additions & 3 deletions Compiler/Template/Makefile.common
@@ -1,6 +1,6 @@
.PHONY : all

GENERATED_FILES=AbsynDumpTpl.mo CodegenUtil.mo CodegenC.mo CodegenFMUCommon.mo CodegenFMU.mo CodegenFMU1.mo CodegenFMU2.mo CodegenCSharp.mo CodegenQSS.mo CodegenCpp.mo CodegenCppHpcom.mo CodegenFMUCpp.mo CodegenModelica.mo DAEDumpTpl.mo ExpressionDumpTpl.mo GraphvizDump.mo GraphMLDumpTpl.mo NFInstDumpTpl.mo SimCodeDump.mo Unparsing.mo SCodeDumpTpl.mo CodegenAdevs.mo CodegenSparseFMI.mo CodegenXML.mo CodegenJava.mo CodegenJS.mo TplCodegen.mo TaskSystemDump.mo GenerateAPIFunctionsTpl.mo VisualXMLTpl.mo
GENERATED_FILES=AbsynDumpTpl.mo CodegenUtil.mo CodegenC.mo CodegenFMUCommon.mo CodegenFMU.mo CodegenFMU1.mo CodegenFMU2.mo CodegenCSharp.mo CodegenQSS.mo CodegenCpp.mo CodegenCppHpcom.mo CodegenFMUCpp.mo CodegenCppInit.mo CodegenModelica.mo DAEDumpTpl.mo ExpressionDumpTpl.mo GraphvizDump.mo GraphMLDumpTpl.mo NFInstDumpTpl.mo SimCodeDump.mo Unparsing.mo SCodeDumpTpl.mo CodegenAdevs.mo CodegenSparseFMI.mo CodegenXML.mo CodegenJava.mo CodegenJS.mo TplCodegen.mo TaskSystemDump.mo GenerateAPIFunctionsTpl.mo VisualXMLTpl.mo

all : $(GENERATED_FILES)

Expand Down Expand Up @@ -82,13 +82,13 @@ CodegenQSS.mo : CodegenQSS.tpl SimCodeTV.mo CodegenC.tpl CodegenUtil.tpl
$(OMC) $< > $@.log || (cat $@.log && false)
@echo " "

CodegenCpp.mo : CodegenCpp.tpl SimCodeTV.mo
CodegenCpp.mo : CodegenCpp.tpl SimCodeTV.mo CodegenUtil.tpl CodegenCppInit.tpl
@echo " ** CodegenCpp template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
@echo " "

CodegenCppHpcom.mo : CodegenCppHpcom.tpl SimCodeTV.mo CodegenCpp.tpl CodegenUtil.tpl
@echo " ** CodegenCppHpcom.mo template compilation ** "
@echo " ** CodegenCppHpcom template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
@echo " "

Expand All @@ -97,6 +97,11 @@ CodegenFMUCpp.mo : CodegenFMUCpp.tpl SimCodeTV.mo CodegenC.tpl CodegenUtil.tpl C
$(OMC) $< > $@.log || (cat $@.log && false)
@echo " "

CodegenCppInit.mo : CodegenCppInit.tpl SimCodeTV.mo CodegenUtil.tpl
@echo " ** CodegenCppInit template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
@echo " "

ExpressionDumpTpl.mo : ExpressionDumpTpl.tpl ExpressionDumpTV.mo DAEDumpTpl.tpl
@echo " ** ExpressionDumpTpl template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
Expand Down
1 change: 1 addition & 0 deletions Compiler/boot/LoadCompilerSources.mos
Expand Up @@ -205,6 +205,7 @@ if true then /* Suppress output */
"../Template/CodegenFMU2.mo",
"../Template/CodegenFMUCommon.mo",
"../Template/CodegenFMUCpp.mo",
"../Template/CodegenCppInit.mo",
"../Template/CodegenCSharp.mo",
"../Template/CodegenJava.mo",
"../Template/CodegenJS.mo",
Expand Down
1 change: 1 addition & 0 deletions Makefile.omdev.mingw
Expand Up @@ -63,6 +63,7 @@ CMINPACKLIB_SHARED = OFF
CONFIG_REVISION = $(shell git describe --match "v*.*" --always)

revision:
test ! -e .git || cp -puf common/pre-commit.sh `git rev-parse --git-dir`/hooks/pre-commit
@echo Current revision: $(CONFIG_REVISION)
ifeq ($(CONFIG_REVISION),)
@if test -f revision.h; \
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/CMake/FindPugiXML.cmake
Expand Up @@ -21,4 +21,4 @@ else (PUGIXML_FOUND)
message (STATUS "No PugiXML found")
endif(PUGIXML_FOUND)

mark_as_advanced (PUGIXML_LIBRARY PUGIXML_INCLUDE_DIR)
mark_as_advanced (PUGIXML_LIBRARY PUGIXML_INCLUDE_DIR)
22 changes: 22 additions & 0 deletions SimulationRuntime/cpp/CMake/FindScoreP.cmake
@@ -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)
4 changes: 4 additions & 0 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -121,8 +121,12 @@ ENDIF(USE_PARALLEL_OUTPUT)
# Handle ScoreP
IF(USE_SCOREP)
ADD_DEFINITIONS(-DUSE_SCOREP)
FIND_PACKAGE(ScoreP)
SET(SCOREP_INCLUDE_ ${SCOREP_INCLUDE_DIR})
MESSAGE(STATUS "ScoreP enabled")
include_directories(${SCOREP_INCLUDE_DIR})
ELSE(USE_SCOREP)
SET(SCOREP_INCLUDE_ ".")
MESSAGE(STATUS "ScoreP disabled")
ENDIF(USE_SCOREP)

Expand Down
6 changes: 4 additions & 2 deletions SimulationRuntime/cpp/Core/DataExchange/CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.8.6)

project(${DataExchangeName})

add_library(${DataExchangeName} SHARED SimData.cpp FactoryExport.cpp )
add_library(${DataExchangeName} SHARED SimData.cpp FactoryExport.cpp XmlPropertyReader.cpp)

IF(NOT BOOST_STATIC_LINKING)
target_link_libraries (${DataExchangeName} ${Boost_LIBRARIES})
Expand All @@ -11,7 +11,7 @@ ENDIF(NOT BOOST_STATIC_LINKING)
include_directories(${SUNDIALS_INCLUDE_DIR}/cvodes ${SUNDIALS_INCLUDE_DIR}/nvector ${SUNDIALS_INCLUDE_DIR}/sundials ${SUNDIALS_INCLUDE_DIR})
add_precompiled_header(${DataExchangeName} Include/Core/Modelica.h)

add_library(${DataExchangeName}_static STATIC SimData.cpp )
add_library(${DataExchangeName}_static STATIC SimData.cpp XmlPropertyReader.cpp)

IF(NOT BOOST_STATIC_LINKING)
target_link_libraries (${DataExchangeName}_static ${Boost_LIBRARIES})
Expand All @@ -29,6 +29,8 @@ install (FILES ${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/IHistory.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/SimData.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/Writer.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/SimDouble.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/XmlPropertyReader.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/IPropertyReader.h
DESTINATION include/omc/cpp/Core/DataExchange)


Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/DataExchange/SimData.cpp
Expand Up @@ -4,7 +4,7 @@
*/

#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <Core/Modelica.h>
#include <Core/DataExchange/SimData.h>

SimData::SimData(void)
Expand Down
81 changes: 81 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
@@ -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;
}

0 comments on commit d92fe2e

Please sign in to comment.