Skip to content

Commit 3f42307

Browse files
committed
added getNominalReal to Algoop interface and hybrj solver in cpp runtime
add empty as output format to cpp runtime time and cpp template git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20017 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 483db26 commit 3f42307

File tree

14 files changed

+129
-49
lines changed

14 files changed

+129
-49
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
434434
<<
435435
#include "Modelica.h"
436436
#include "OMCpp<%fileNamePrefix%>WriteOutput.h"
437+
437438
<%lastIdentOfPath(modelInfo.name)%>WriteOutput::<%lastIdentOfPath(modelInfo.name)%>WriteOutput(IGlobalSettings* globalSettings,boost::shared_ptr<IAlgLoopSolverFactory> nonlinsolverfactory,boost::shared_ptr<ISimData> simData)
438439
: <%lastIdentOfPath(modelInfo.name)%>(globalSettings,nonlinsolverfactory,simData)
439440
{
@@ -969,7 +970,7 @@ let moLib = makefileParams.compileDir
969970
let home = makefileParams.omhome
970971
<<
971972
#!/bin/sh
972-
exec ./OMCpp<%fileNamePrefix%>Main -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%> $*
973+
exec ./OMCpp<%fileNamePrefix%>Main -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%> -o <%settings.outputFormat%> $*
973974
>>
974975
end match)
975976
case "win32"
@@ -986,7 +987,7 @@ let moLib = makefileParams.compileDir
986987
let home = makefileParams.omhome
987988
<<
988989
@echo off
989-
<%moLib%>/OMCpp<%fileNamePrefix%>Main.exe -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%>
990+
<%moLib%>/OMCpp<%fileNamePrefix%>Main.exe -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%> -o <%settings.outputFormat%>
990991
>>
991992
end match)
992993
end simulationMainRunScrip;
@@ -3149,6 +3150,45 @@ case SES_NONLINEAR(__) then
31493150
end giveAlgloopvars;
31503151
31513152
3153+
template giveAlgloopNominalvars(SimEqSystem eq,SimCode simCode,Context context)
3154+
"Generates a non linear equation system."
3155+
::=
3156+
match eq
3157+
case SES_NONLINEAR(__) then
3158+
let size = listLength(crefs)
3159+
<<
3160+
3161+
<%crefs |> name hasindex i0 =>
3162+
let namestr = giveAlgloopNominalvars2(name,simCode,context)
3163+
<<
3164+
vars[<%i0%>] = <%namestr%>;
3165+
>>
3166+
;separator="\n"
3167+
%>
3168+
>>
3169+
case SES_LINEAR(__) then
3170+
<<
3171+
<%vars |> SIMVAR(__) hasindex i0 => 'vars[<%i0%>] =<%cref1(name,simCode,context)%>;' ;separator="\n"%><%inlineVars(contextSimulationNonDiscrete,vars)%>
3172+
>>
3173+
3174+
end giveAlgloopNominalvars;
3175+
3176+
3177+
template giveAlgloopNominalvars2(ComponentRef inCref,SimCode simCode,Context context)
3178+
"Generates a non linear equation system."
3179+
::=
3180+
cref2simvar(inCref, simCode) |> var =>
3181+
match var
3182+
case SIMVAR(nominalValue=SOME(exp)) then
3183+
let &preExp = buffer "" //dummy ... the value is always a constant
3184+
let &varDecls = buffer ""
3185+
let expPart = daeExp(exp, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
3186+
<<
3187+
<%expPart%>
3188+
>>
3189+
else
3190+
"1.0"
3191+
end giveAlgloopNominalvars2;
31523192
31533193
31543194
template writeAlgloopvars(list<list<SimEqSystem>> continousEquations,list<SimEqSystem> discreteEquations,list<SimWhenClause> whenClauses,list<SimEqSystem> parameterEquations,SimCode simCode,Context context)
@@ -3278,7 +3318,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
32783318
<<
32793319
void <%lastIdentOfPath(modelInfo.name)%>WriteOutput::writeOutput(const IWriteOutput::OUTPUT command)
32803320
{
3281-
3321+
32823322
//Write head line
32833323
if (command & IWriteOutput::HEAD_LINE)
32843324
{
@@ -3685,6 +3725,16 @@ void <%modelname%>Algloop<%index%>::getReal(double* vars)
36853725
<%giveAlgloopvars(eq,simCode,context)%>
36863726
};
36873727
3728+
/// Provide nominal variables with given index to the system
3729+
void <%modelname%>Algloop<%index%>::getNominalReal(double* vars)
3730+
{
3731+
3732+
<%giveAlgloopNominalvars(eq,simCode,context)%>
3733+
};
3734+
3735+
3736+
3737+
36883738
/// Set variables with given index to the system
36893739
void <%modelname%>Algloop<%index%>::setReal(const double* vars)
36903740
{
@@ -3820,6 +3870,8 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
38203870
virtual void initialize();
38213871
/// Provide variables with given index to the system
38223872
virtual void getReal(double* vars) ;
3873+
/// Provide variables with given index to the system
3874+
virtual void getNominalReal(double* vars) ;
38233875
/// Set variables with given index to the system
38243876
virtual void setReal(const double* vars) ;
38253877
/// Update transfer behavior of the system of equations according to command given by solver

SimulationRuntime/cpp/Core/SimController/SimController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void SimController::Start(boost::weak_ptr<IMixedSystem> mixedsystem,SimSettings
8282
global_settings->setResultsFileName(simsettings.outputfile_name);
8383
global_settings->setSelectedNonLinSSolver(simsettings.nonlinear_solver_name);
8484
global_settings->setSelectedSolver(simsettings.solver_name);
85-
85+
global_settings->setOutputFormat(simsettings.outputFormat);
8686
simMgr = boost::shared_ptr<SimManager>(new SimManager(mixedsystem.lock(),_config.get()));
8787
ISolverSettings* solver_settings = _config->getSolverSettings();
8888
solver_settings->setLowerLimit(simsettings.lower_limit);

SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GlobalSettings::GlobalSettings()
1313
,_resultsfile_name("results.csv")
1414
,_endless_sim(false)
1515
{
16-
16+
1717
}
1818

1919
GlobalSettings::~GlobalSettings()
@@ -54,7 +54,16 @@ void GlobalSettings::sethOutput(double h)
5454
{
5555
_endless_sim = endles;
5656
}
57-
///< Write out results ([false,true]; default: true)
57+
58+
OutputFormat GlobalSettings::getOutputFormat()
59+
{
60+
return _outputFormat;
61+
}
62+
void GlobalSettings::setOutputFormat(OutputFormat format)
63+
{
64+
_outputFormat=format;
65+
}
66+
///< Write out results ([false,true]; default: true)
5867
bool GlobalSettings::getResultsOutput()
5968
{
6069
return _resultsOutput;
@@ -112,7 +121,7 @@ initializes settings object by an xml file
112121
*/
113122
void GlobalSettings::load(std::string xml_file)
114123
{
115-
try
124+
/*try
116125
{
117126
118127
std::ifstream ifs(xml_file.c_str());
@@ -129,7 +138,7 @@ void GlobalSettings::load(std::string xml_file)
129138
{
130139
std::string error = ex.what();
131140
cout<< error <<std::endl;
132-
}
141+
}*/
133142

134143
}
135144
void GlobalSettings::setRuntimeLibrarypath(string path)

SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class GlobalSettings : public IGlobalSettings
3131
///path for simulation results in textfile
3232
virtual string getOutputPath();
3333
virtual void setOutputPath(string);
34+
virtual OutputFormat getOutputFormat();
35+
virtual void setOutputFormat(OutputFormat format);
36+
3437
//solver used for simulation
3538
virtual string getSelectedSolver();
3639
virtual void setSelectedSolver(string);
@@ -58,9 +61,12 @@ class GlobalSettings : public IGlobalSettings
5861
_selected_nonlin_solver,
5962
_resultsfile_name,
6063
_runtimeLibraryPath;
61-
64+
OutputFormat _outputFormat;
65+
66+
6267
//Serialization of settings class
63-
friend class boost::serialization::access;
68+
69+
/*friend class boost::serialization::access;
6470
template<class archive>
6571
void serialize(archive& ar, const unsigned int version)
6672
@@ -86,4 +92,5 @@ class GlobalSettings : public IGlobalSettings
8692
8793
8894
}
95+
*/
8996
};

SimulationRuntime/cpp/Core/SimulationSettings/stdafx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <boost/range/adaptor/map.hpp>
4343
#include <boost/range/algorithm/copy.hpp>
4444
#include <boost/math/tools/real_cast.hpp>
45+
4546
using std::vector;
4647
using std::map;
4748
using std::string;
@@ -55,6 +56,7 @@ using boost::shared_ptr;
5556
using boost::weak_ptr;
5657
using boost::get;
5758
using boost::unordered_map;
59+
5860
typedef ublas::shallow_array_adaptor<double> adaptor_t;
5961
typedef ublas::vector<double, adaptor_t> shared_vector_t;
6062
typedef ublas::matrix<double, adaptor_t> shared_matrix_t;

SimulationRuntime/cpp/Core/Solver/SolverDefaultImplementation.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,36 +180,16 @@ void SolverDefaultImplementation::setZeroState()
180180

181181
void SolverDefaultImplementation::writeToFile(const int& stp, const double& t, const double& h)
182182
{
183-
IWriteOutput* writeoutput_system = dynamic_cast<IWriteOutput*>(_system);
184-
//if (_outputStream && _settings->_globalSettings->_resultsOutput)
185-
//{
186-
// // Reset curser within output stream to last valid position (before zero crossing)
187-
// if(_outputCommand & IContinuous::RESET)
188-
// if(stp == 1)
189-
// _outputStream->seekp(_curserPosition);
190-
191-
// if(_outputCommand & IContinuous::WRITE)
192-
// {
193-
// // In the first step, tell (inital) curser position within output stream
194-
// if(stp == 1)
195-
// _curserPosition = _outputStream->tellp();
196-
197-
// // Write current step, time and step size into output stream
198-
// *_outputStream << stp << "\t" << t << "\t" << h;
199-
200-
// // Write out output stream
201-
// _system->writeOutput(_outputCommand);
202-
//
203-
// // Write a line break into output stream
204-
// *_outputStream << std::endl;
205-
// }
206-
//}
207-
183+
if(_settings->getGlobalSettings()->getOutputFormat()!= EMPTY)
184+
{
185+
IWriteOutput* writeoutput_system = dynamic_cast<IWriteOutput*>(_system);
186+
208187
if(_outputCommand & IWriteOutput::WRITEOUT)
209188
{
210189
writeoutput_system->writeOutput(_outputCommand);
211190

212191
}
192+
}
213193
}
214194
void SolverDefaultImplementation::updateEventState()
215195
{

SimulationRuntime/cpp/Include/Core/SimController/ISimController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct SimSettings
2020
double upper_limit;
2121
double tolerance;
2222
string outputfile_name;
23+
OutputFormat outputFormat;
2324

2425
};
2526

SimulationRuntime/cpp/Include/Core/SimulationSettings/IGlobalSettings.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Copyright (c) 2008, OSMC
1414
*****************************************************************************/
1515
#include <string.h>
1616
using std::string;
17-
17+
enum OutputFormat {CSV, MAT, EMPTY};
1818
class IGlobalSettings
1919
{
20-
enum {CSV, MAT};
20+
2121
public:
2222
virtual ~IGlobalSettings() {}
2323
///< Start time of integration (default: 0.0)
@@ -32,6 +32,8 @@ class IGlobalSettings
3232
///< Write out results ([false,true]; default: true)
3333
virtual bool getResultsOutput()=0;
3434
virtual void setResultsOutput(bool)=0;
35+
virtual OutputFormat getOutputFormat() = 0;
36+
virtual void setOutputFormat(OutputFormat) = 0;
3537
virtual bool useEndlessSim()=0;
3638
virtual void useEndlessSim(bool)=0;
3739
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)

SimulationRuntime/cpp/Include/Core/System/IAlgLoop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class IAlgLoop
4343

4444
/// Provide variables of given data type
4545
virtual void getReal(double* lambda) = 0;
46-
46+
/// Provide nominal values of given data type
47+
virtual void getNominalReal(double* lambda) = 0;
4748
/// Set variables with given data type
4849
virtual void setReal(const double* lambda) = 0;
4950

SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class FMUGlobalSettings : public IGlobalSettings
2525
virtual bool getInfoOutput() { return false; }
2626
virtual void setInfoOutput(bool) {}
2727
virtual string getOutputPath() { return "./"; }
28+
virtual OutputFormat getOutputFormat(){return CSV;}
29+
virtual void setOutputFormat(OutputFormat) {}
2830
virtual void setOutputPath(string) {}
2931
virtual string getSelectedSolver() { return "Euler"; }
3032
virtual void setSelectedSolver(string) {}

0 commit comments

Comments
 (0)