Skip to content

Commit

Permalink
-fix for linking new windows boost libraries in Simulation.exe
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12187 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Jun 21, 2012
1 parent cda4cb3 commit 58c5b51
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenCpp.tpl
Expand Up @@ -144,7 +144,7 @@ FUNCTIONFILE=Functions.cpp

.PHONY: <%lastIdentOfPath(modelInfo.name)%>
<%lastIdentOfPath(modelInfo.name)%>: $(MAINFILE)
<%\t%>$(CXX) -shared -I. -o $(MODELICA_SYSTEM_LIB) $(MAINFILE) $(FUNCTIONFILE) <%algloopcppfilenames(odeEquations,algebraicEquations,whenClauses,parameterEquations,simCode)%> $(CFLAGS) $(LDFLAGS) -lSystem -lMath -lModelicaExternalC -Wl,-Bstatic -Wl,-Bdynamic
<%\t%>$(CXX) -shared -I. -o $(MODELICA_SYSTEM_LIB) $(MAINFILE) $(FUNCTIONFILE) <%algloopcppfilenames(odeEquations,algebraicEquations,whenClauses,parameterEquations,simCode)%> $(CFLAGS) $(LDFLAGS) -lSystem -lModelicaExternalC -Wl,-Bstatic -Wl,-Bdynamic

>>
end simulationMakefile;
Expand Down
157 changes: 84 additions & 73 deletions SimulationRuntime/cpp/Source/SimManager/Main.cpp
Expand Up @@ -5,86 +5,97 @@
#include "LibrariesConfig.h"
namespace fs = boost::filesystem;



int nargc=3;
int lib_index= 1;
int modelica_index = 2;


#if defined(_MSC_VER) || defined(__MINGW32__)
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, const char* argv[])
#endif
{
if(argc < 3)
throw std::invalid_argument("No runtime library path and Modelica system library path defined");

fs::path libraries_path = fs::path( argv[1] ) ;
fs::path modelica_path = fs::path( argv[2] ) ;

//std::cout << libraries_path << " end" << std::endl;
try
{

Configuration config(libraries_path);

IGlobalSettings* global_settings = config.getGlobalSettings();
//Load Modelica sytem library
type_map types;

fs::path modelica_system_name(MODELICASYSTEM_LIB);
fs::path modelica_system_path = modelica_path;
modelica_system_path/=modelica_system_name;

fs::path default_system_name(SYSTEM_LIB);
fs::path default_system_path = libraries_path;
default_system_path/=default_system_name;

if(!load_single_library(types, default_system_path.string()))
throw std::invalid_argument("System default library could not be loaded");


if(!load_single_library(types, modelica_system_path.string()))
throw std::invalid_argument("ModelicaSystem library could not be loaded");
std::map<std::string, factory<IDAESystem,IGlobalSettings&> >::iterator iter;
std::map<std::string, factory<IDAESystem,IGlobalSettings&> >& factories(types.get());
iter = factories.find("ModelicaSystem");
if (iter ==factories.end())
{
throw std::invalid_argument("No Modelica system found");
}


//create Modelica system
boost::shared_ptr<IDAESystem> system(iter->second.create(*global_settings));

//create selected solver
IDAESolver* solver = config.createSolver(system.get());

boost::shared_ptr<ISystemProperties> properties = boost::dynamic_pointer_cast<ISystemProperties>(system);
if((properties->isODE()) && !(properties->isAlgebraic()) && (properties->isExplicit()))
{

// Command for integration: Since integration is done "at once" the solver is only called once. Hence it is both, first and last
// call to the solver at the same time. Furthermore it is supposed to be a regular call (not a recall)
IDAESolver::SOLVERCALL command = IDAESolver::SOLVERCALL(IDAESolver::FIRST_CALL|IDAESolver::LAST_CALL|IDAESolver::REGULAR_CALL|IDAESolver::RECORDCALL);
// The simulation entity is supposed to set start and end time
solver->setStartTime(global_settings->getStartTime());
solver->setEndTime(global_settings->getEndTime());
solver->setInitStepSize(config.getSolverSettings()->gethInit());
// Call the solver
solver->solve(command);

}
// Get the status of the solver (is the interation done sucessfully?)
IDAESolver::SOLVERSTATUS status = solver->getSolverStatus();
//Todo: use flags for simulation outputs
//solver->writeSimulationInfo(std::cout);
//solver->reportErrorMessage(std::cout);
return 0;
}
catch(std::exception& ex)
{
std::string error = ex.what();
std::cout << "Simulation stopped: "<< std::endl << error << std::endl;
return 1;
}
if(argc < nargc)
throw std::invalid_argument("No runtime library path and Modelica system library path defined");

fs::path libraries_path = fs::path( argv[lib_index] ) ;
fs::path modelica_path = fs::path( argv[modelica_index] ) ;
libraries_path.make_preferred();
modelica_path.make_preferred();
//std::cout << libraries_path << " end" << std::endl;
try
{

Configuration config(libraries_path);

IGlobalSettings* global_settings = config.getGlobalSettings();
//Load Modelica sytem library


fs::path modelica_system_name(MODELICASYSTEM_LIB);
fs::path modelica_system_path = modelica_path;
modelica_system_path/=modelica_system_name;

fs::path default_system_name(SYSTEM_LIB);
fs::path default_system_path = libraries_path;
default_system_path/=default_system_name;

default_system_path.make_preferred();
modelica_system_path.make_preferred();
type_map types;
if(!load_single_library(types, default_system_path.string()))
throw std::invalid_argument("System default library could not be loaded");

if(!load_single_library(types, modelica_system_path.string()))
throw std::invalid_argument("ModelicaSystem library could not be loaded");

std::map<std::string, factory<IDAESystem,IGlobalSettings&> >::iterator iter;
std::map<std::string, factory<IDAESystem,IGlobalSettings&> >& factories(types.get());
iter = factories.find("ModelicaSystem");
if (iter ==factories.end())
{
throw std::invalid_argument("No Modelica system found");
}


//create Modelica system
boost::shared_ptr<IDAESystem> system(iter->second.create(*global_settings));

//create selected solver
IDAESolver* solver = config.createSolver(system.get());

boost::shared_ptr<ISystemProperties> properties = boost::dynamic_pointer_cast<ISystemProperties>(system);
if((properties->isODE()) && !(properties->isAlgebraic()) && (properties->isExplicit()))
{

// Command for integration: Since integration is done "at once" the solver is only called once. Hence it is both, first and last
// call to the solver at the same time. Furthermore it is supposed to be a regular call (not a recall)
IDAESolver::SOLVERCALL command = IDAESolver::SOLVERCALL(IDAESolver::FIRST_CALL|IDAESolver::LAST_CALL|IDAESolver::REGULAR_CALL|IDAESolver::RECORDCALL);
// The simulation entity is supposed to set start and end time
solver->setStartTime(global_settings->getStartTime());
solver->setEndTime(global_settings->getEndTime());
solver->setInitStepSize(config.getSolverSettings()->gethInit());
// Call the solver
solver->solve(command);

}
// Get the status of the solver (is the interation done sucessfully?)
IDAESolver::SOLVERSTATUS status = solver->getSolverStatus();
//Todo: use flags for simulation outputs
//solver->writeSimulationInfo(std::cout);
//solver->reportErrorMessage(std::cout);
return 0;
}
catch(std::exception& ex)
{
std::string error = ex.what();
std::cout << "Simulation stopped: "<< std::endl << error << std::endl;
return 1;
}
}


8 changes: 8 additions & 0 deletions SimulationRuntime/cpp/Source/SimManager/stdafx.h
Expand Up @@ -4,6 +4,14 @@
//

#pragma once
#ifndef BOOST_THREAD_USE_DLL
#define BOOST_THREAD_USE_DLL
#endif
#ifndef BOOST_ALL_DYN_LINK
#define BOOST_ALL_DYN_LINK
#endif


#include <string>
#include <sstream>

Expand Down

0 comments on commit 58c5b51

Please sign in to comment.