Skip to content

Commit

Permalink
solver method passed to the cpp runtime, (using cvode instead of dassl)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17203 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Sep 12, 2013
1 parent ae05b81 commit 9e27e36
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -1397,7 +1397,7 @@ algorithm
stoptime_str = realString(stoptime);
stepsize_str = realString(stepsize);

simflags2=Util.if_(ifcpp,stringAppendList({"-r ",libDir," ","-m ",compileDir," ","-R ",result_file," ","-c ",configDir," ","-s ",starttime_str," ","-e ",stoptime_str," ","-f ", stepsize_str }), simflags);
simflags2=Util.if_(ifcpp,stringAppendList({"-r ",libDir," ","-m ",compileDir," ","-R ",result_file," ","-c ",configDir," ","-s ",starttime_str," ","-e ",stoptime_str," ","-f ", stepsize_str," ","-i ",method_str }), simflags);
executable1=Util.if_(ifcpp,"OMCppSimulation",executable);
executableSuffixedExe = stringAppend(executable1, System.getExeExt());
logFile = stringAppend(executable1,".log");
Expand Down
4 changes: 4 additions & 0 deletions Makefile.common
Expand Up @@ -185,6 +185,10 @@ testlibrariemsl32:
(cd testsuite/simulation/libraries/msl32 && time $(MAKE) -f Makefile > testsuite-msl32-trace.txt 2>&1)
echo "log is in testsuite/simulation/libraries/msl32/testsuite-msl31-trace.txt"

testcpp:
(cd testsuite/openmodelica/cppruntime/ && time $(MAKE) -f Makefile > testsuite-cpp-trace.txt 2>&1)
echo "log is in testsuite/openmodelica/cppruntime/testsuite-cpp-trace.txt"

testfmi:
(cd testsuite/openmodelica/fmi && time $(MAKE) -f Makefile)

Expand Down
4 changes: 3 additions & 1 deletion SimulationRuntime/cpp/Core/SimController/Main.cpp
Expand Up @@ -33,6 +33,7 @@ int main(int argc, const char* argv[])
("start-time,s", po::value< double >()->default_value(0.0), "simulation start time")
("stop-time,e", po::value< double >()->default_value(1.0), "simulation stop time")
("step-size,f", po::value< double >()->default_value(1e-2), "simulation step size")
("solver,i", po::value< string >()->default_value("euler"), "solver method")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
Expand All @@ -45,6 +46,7 @@ int main(int argc, const char* argv[])
double starttime = vm["start-time"].as<double>();
double stoptime = vm["stop-time"].as<double>();
double stepsize = vm["step-size"].as<double>();
string solver = vm["solver"].as<string>();
if (vm.count("runtime-libray"))
{
//cout << "runtime library path set to " << vm["runtime-libray"].as<string>() << std::endl;
Expand Down Expand Up @@ -111,7 +113,7 @@ int main(int argc, const char* argv[])


//SimController to start simulation
SimSettings settings = {"Euler","Newton",starttime,stoptime,stepsize,0.0001,1,results_file_path.string()};
SimSettings settings = {solver,"Newton",starttime,stoptime,stepsize,0.0001,1,results_file_path.string()};
boost::shared_ptr<ISimController> sim_controller = boost::shared_ptr<ISimController>(new SimController(runtime_lib_path,modelica_path));
//create Modelica system
std::pair<boost::weak_ptr<IMixedSystem>,boost::weak_ptr<ISimData> > system = sim_controller->LoadSystem("ModelicaSystem");
Expand Down
Expand Up @@ -62,7 +62,7 @@ struct SolverOMCFactory : public ObjectFactory<CreationPolicy>
boost::shared_ptr<ISolver> createSolver(IMixedSystem* system, string solvername, boost::shared_ptr<ISolverSettings> solver_settings)
{

if(solvername.compare("Euler")==0)
if(solvername.compare("euler")==0)
{
PATH euler_path = ObjectFactory<CreationPolicy>::_library_path;
PATH euler_name(EULER_LIB);
Expand All @@ -74,16 +74,17 @@ struct SolverOMCFactory : public ObjectFactory<CreationPolicy>
}

}
else if(solvername.compare("Idas")==0)
else if(solvername.compare("idas")==0)
{

}
else if(solvername.compare("Ida")==0)
else if(solvername.compare("ida")==0)
{
}
else if(solvername.compare("CVode")==0)
else if((solvername.compare("cvode")==0)||(solvername.compare("dassl")==0))
{
PATH cvode_path = ObjectFactory<CreationPolicy>::_library_path;
solvername = "cvode"; //workound for dassl, using cvode instead
PATH cvode_path = ObjectFactory<CreationPolicy>::_library_path;
PATH cvode_name(CVODE_LIB);
cvode_path/=cvode_name;
LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(cvode_path.string(),*_solver_type_map);
Expand All @@ -101,7 +102,7 @@ struct SolverOMCFactory : public ObjectFactory<CreationPolicy>
iter = factories.find(solver_key);
if (iter ==factories.end())
{
throw std::invalid_argument("No such Solver");
throw std::invalid_argument("No such Solver " + solver_key);
}

boost::shared_ptr<ISolver> solver = boost::shared_ptr<ISolver>(iter->second.create(system,solver_settings.get())); ;
Expand Down
Expand Up @@ -27,7 +27,7 @@ struct SolverSettingsOMCFactory : public ObjectFactory<CreationPolicy>
{

string solver_settings_key;
if(solvername.compare("Euler")==0)
if(solvername.compare("euler")==0)
{
PATH euler_path = ObjectFactory<CreationPolicy>::_library_path;
PATH euler_name(EULER_LIB);
Expand All @@ -39,17 +39,18 @@ struct SolverSettingsOMCFactory : public ObjectFactory<CreationPolicy>
}
solver_settings_key.assign("createEulerSettings");
}
else if(solvername.compare("Idas")==0)
else if(solvername.compare("idas")==0)
{
solver_settings_key.assign("extension_export_idas");
}
else if(solvername.compare("Ida")==0)
else if(solvername.compare("ida")==0)
{
solver_settings_key.assign("extension_export_ida");
}
else if(solvername.compare("CVode")==0)
else if((solvername.compare("cvode")==0)||(solvername.compare("dassl")==0))
{
PATH cvode_path = ObjectFactory<CreationPolicy>::_library_path;
solvername = "cvode"; //workound for dassl, using cvode instead
PATH cvode_path = ObjectFactory<CreationPolicy>::_library_path;
PATH cvode_name(CVODE_LIB);
cvode_path/=cvode_name;
LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(cvode_path.string(),*_solver_type_map);
Expand All @@ -58,7 +59,7 @@ struct SolverSettingsOMCFactory : public ObjectFactory<CreationPolicy>
throw std::runtime_error("Failed loading CVode solver library!");
}

solver_settings_key.assign("extension_export_cvode");
solver_settings_key.assign("extension_export_cvode");
}
else
throw std::invalid_argument("Selected Solver is not available");
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Solver/CVode/FactoryExport.cpp
Expand Up @@ -26,9 +26,9 @@ extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export_cvode(boost::extens

BOOST_EXTENSION_TYPE_MAP_FUNCTION {
types.get<std::map<std::string, factory<ISolver,IMixedSystem*, ISolverSettings*> > >()
["CVodeSolver"].set<Cvode>();
["cvodeSolver"].set<Cvode>();
types.get<std::map<std::string, factory<ISolverSettings, IGlobalSettings* > > >()
["CVodeSettings"].set<CVodeSettings>();
["cvodeSettings"].set<CVodeSettings>();
}

#else
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Solver/Euler/FactoryExport.cpp
Expand Up @@ -38,9 +38,9 @@ extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export_euler(boost::extens

BOOST_EXTENSION_TYPE_MAP_FUNCTION {
types.get<std::map<std::string, factory<ISolver,IMixedSystem*, ISolverSettings*> > >()
["EulerSolver"].set<Euler>();
["eulerSolver"].set<Euler>();
types.get<std::map<std::string, factory<ISolverSettings, IGlobalSettings* > > >()
["EulerSettings"].set<EulerSettings>();
["eulerSettings"].set<EulerSettings>();
}

#else
Expand Down

0 comments on commit 9e27e36

Please sign in to comment.