Skip to content

Commit

Permalink
changed SimulationError exception class of cpp runtime
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24507 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Feb 10, 2015
1 parent 1aabc0b commit 40a760f
Show file tree
Hide file tree
Showing 38 changed files with 329 additions and 277 deletions.
104 changes: 48 additions & 56 deletions Compiler/Template/CodegenCpp.tpl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/DataExchange/SimData.cpp
Expand Up @@ -26,7 +26,7 @@ ISimVar* SimData::Get(string key)
return obj.get();
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(DATASTORAGE) << error_message("There is no such sim variable " + key));
throw ModelicaSimulationError(DATASTORAGE,"There is no such sim variable " + key);
}

void SimData::addOutputResults(string name,uBlas::vector<double> v)
Expand Down Expand Up @@ -72,7 +72,7 @@ void SimData::getOutputResults(string name,uBlas::vector<double>& v)
v = boost::ref(iter->second);
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(DATASTORAGE) << error_message("There is no such output variable " + name));
throw ModelicaSimulationError(DATASTORAGE,"There is no such output variable " + name);
}

extern "C" ISimData* createSimDataAnalyzation()
Expand Down
20 changes: 10 additions & 10 deletions SimulationRuntime/cpp/Core/Math/ArrayOperations.cpp
Expand Up @@ -25,26 +25,26 @@ void cat_array (int k,BaseArray<T>& a, vector<BaseArray<T>* >& x )
unsigned int n = x.size();
/* check dim sizes of all inputs */
if(n<1)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("No input arrays"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"No input arrays");

if(x[0]->getDims().size() < k)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Wrong dimension for input array"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong dimension for input array");

new_k_dim_size = x[0]->getDims()[k-1];
for(int i = 1; i < n; i++)
{
if(x[0]->getDims().size() != x[i]->getDims().size())
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Wrong dimension for input array"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong dimension for input array");
for(int j = 0; j < (k - 1); j++)
{
if (x[0]->getDims()[j] != x[i]->getDims()[j])
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Wrong size for input array"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
}
new_k_dim_size += x[i]->getDims()[k-1];
for(int j = k; j < x[0]->getDims().size(); j++)
{
if (x[0]->getDims()[j] != x[i]->getDims()[j])
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Wrong size for input array"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Wrong size for input array");
}
}
/* calculate size of sub and super structure in 1-dim data representation */
Expand All @@ -62,7 +62,7 @@ void cat_array (int k,BaseArray<T>& a, vector<BaseArray<T>* >& x )
vector<size_t> ex = x[0]->getDims();
ex[k-1] = new_k_dim_size;
if(ex.size()<k)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Error resizing concatenate array"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Error resizing concatenate array");
a.setDims( ex );

/* concatenation along k-th dimension */
Expand Down Expand Up @@ -106,7 +106,7 @@ void create_array_from_shape(const spec_type& sp,BaseArray<T>& s,BaseArray<T>& d

//Check if the dimension of passed indices match the dimension of target array
if(sp.second.size()!=s.getNumDims())
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Erro in create array from shape, number of dimensions does not match"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match");

T* data = new T[d.getNumElems()];

Expand Down Expand Up @@ -135,7 +135,7 @@ void create_array_from_shape(const spec_type& sp,BaseArray<T>& s,BaseArray<T>& d
}
if(index>(d.getNumElems()-1))
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Erro in create array from shape, number of dimensions does not match"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in create array from shape, number of dimensions does not match");
}
data[index] = s(idx);
idx.clear();
Expand Down Expand Up @@ -165,7 +165,7 @@ void transpose_array (BaseArray< T >& a, BaseArray< T >& x )

{
if(a.getNumDims()!=2 || x.getNumDims()!=2)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("Erro in transpose_array, number of dimensions does not match"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"Erro in transpose_array, number of dimensions does not match");

vector<size_t> ex = x.getDims();
std::swap( ex[0], ex[1] );
Expand Down Expand Up @@ -257,7 +257,7 @@ template <typename T>
T dot_array(BaseArray<T> & a, BaseArray<T> & b)
{
if(a.getNumDims()!=1 || b.getNumDims()!=1)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_ARRAY_FUNCTION) << error_message("error in dot array function. Wrong dimension"));
throw ModelicaSimulationError(MODEL_ARRAY_FUNCTION,"error in dot array function. Wrong dimension");

T* data1 = a.getData();
unsigned int nelems = a.getNumElems();
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/Math/Functions.cpp
Expand Up @@ -30,7 +30,7 @@ double division (const double &a,const double &b, const char* text)
else
{
std::string error_msg = "Division by zeror: ";
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(UTILITY) << error_message(error_msg+string(text)));
throw ModelicaSimulationError(UTILITY,error_msg+string(text));
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ int pivot(double *A, int n_rows, int n_cols, int *rowInd, int *colInd)
pivot = get_pivot_matrix_elt(A,row,row);
/* internal error, pivot element should never be zero if maxsearch succeeded */
if(pivot == 0)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(UTILITY) << error_message("pivot element is zero "));
throw ModelicaSimulationError(UTILITY,"pivot element is zero ");

/* perform one step of Gaussian Elimination */
for(i=row+1;i<n_rows;i++)
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Core/Math/SparseMatrix.cpp
Expand Up @@ -6,7 +6,7 @@ void sparse_matrix::build(sparse_inserter& ins) {
n=ins.content.rbegin()->first.first+1;
} else {
if(n-1!=ins.content.rbegin()->first.first) {
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("size doesn't match"));
throw ModelicaSimulationError(MATH_FUNCTION,"size doesn't match");
}
}
size_t n=ins.content.size();
Expand Down Expand Up @@ -42,11 +42,11 @@ int sparse_matrix::solve(const double* b, double * x) {
}
#else
void sparse_matrix::build(sparse_inserter& ins) {
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("no umfpack"));
throw ModelicaSimulationError(MATH_FUNCTION,"no umfpack");
}

int sparse_matrix::solve(const double* b, double * x) {
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("no umfpack"));
throw ModelicaSimulationError(MATH_FUNCTION,"no umfpack");
}

#endif
10 changes: 5 additions & 5 deletions SimulationRuntime/cpp/Core/Modelica/ModelicaSystem.cpp
Expand Up @@ -172,22 +172,22 @@ bool Modelica::checkForDiscreteEvents()

bool Modelica::stepCompleted(double time)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("stepCompleted is not yet implemented"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"stepCompleted is not yet implemented");
}

bool Modelica::checkConditions()
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("checkConditions is not yet implemented"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"checkConditions is not yet implemented");
}

void Modelica::getJacobian(SparseMatrix& matrix)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("giveJacobian is not yet implemented"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"giveJacobian is not yet implemented");
}

void Modelica::getStateSetJacobian(SparseMatrix& matrix)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("giveStateJacobian is not yet implemented"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"giveStateJacobian is not yet implemented");
}

bool Modelica::isODE()
Expand All @@ -207,7 +207,7 @@ int Modelica::getDimZeroFunc()

bool Modelica::provideSymbolicJacobian()
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("provideSymbolicJacobian is not yet implemented"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"provideSymbolicJacobian is not yet implemented");
}

void Modelica::saveAll()
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/SimController/CMakeLists.txt
Expand Up @@ -5,10 +5,10 @@ project(${SimControllerName})
IF(RUNTIME_STATIC_LINKING)
include_directories(${SUNDIALS_INCLUDE_DIR}/cvodes ${SUNDIALS_INCLUDE_DIR}/nvector ${SUNDIALS_INCLUDE_DIR}/sundials ${SUNDIALS_INCLUDE_DIR}/kinsol ${SUNDIALS_INCLUDE_DIR})
add_library(${SimControllerName} STATIC Configuration.cpp FactoryExport.cpp Initialization.cpp SimController.cpp SimManager.cpp)
target_link_libraries( ${SimControllerName} ${SystemName} ${OMCFactoryName} ${ExtensionUtilitiesName} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} )
target_link_libraries( ${SimControllerName} ${SystemName} ${OMCFactoryName} ${ExtensionUtilitiesName}${ModelicaUtilitiesName} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} )
ELSE(RUNTIME_STATIC_LINKING)
add_library(${SimControllerName} SHARED Configuration.cpp FactoryExport.cpp Initialization.cpp SimController.cpp SimManager.cpp)
target_link_libraries( ${SimControllerName} ${OMCFactoryName} ${ExtensionUtilitiesName} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} )
target_link_libraries( ${SimControllerName} ${OMCFactoryName} ${ExtensionUtilitiesName} ${ModelicaUtilitiesName} ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} )
ENDIF(RUNTIME_STATIC_LINKING)


Expand Down
17 changes: 9 additions & 8 deletions SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -69,7 +69,7 @@ std::pair<boost::shared_ptr<IMixedSystem>, boost::shared_ptr<ISimData> > SimCont
return system;
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(SIMMANAGER) << error_message("No Modelica Compiler configured"));
throw ModelicaSimulationError(SIMMANAGER,"No Modelica Compiler configured");
}

boost::shared_ptr<ISimData> SimController::getSimData(string modelname)
Expand Down Expand Up @@ -108,11 +108,11 @@ void SimController::StartVxWorks(boost::shared_ptr<IMixedSystem> mixedsystem, Si

_simMgr->initialize();
}
catch(boost::exception & ex)
catch( ModelicaSimulationError& ex)
{
ex << error_id(SIMMANAGER) << error_message(string("Simulation failed for ") + simsettings.outputfile_name);
printf("Fehler %s\n",diagnostic_information(ex).c_str());
throw;
string error = add_error_info(string("Simulation failed for ") + simsettings.outputfile_name,ex.what(),ex.getErrorID());
printf("Fehler %s\n",error.c_str());
throw ModelicaSimulationError(SIMMANAGER,error);
}
}

Expand Down Expand Up @@ -181,10 +181,11 @@ void SimController::Start(boost::shared_ptr<IMixedSystem> mixedsystem, SimSettin
}

}
catch(boost::exception & ex)
catch(ModelicaSimulationError & ex)
{
ex << error_id(SIMMANAGER) << error_message(string("Simulation failed for ") + simsettings.outputfile_name);
throw;

string error = add_error_info(string("Simulation failed for ") + simsettings.outputfile_name,ex.what(),ex.getErrorID());
throw ModelicaSimulationError(SIMMANAGER,error);
}
}

Expand Down
14 changes: 7 additions & 7 deletions SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Expand Up @@ -124,9 +124,9 @@ void SimManager::initialize()
// System zusammenbauen und einmal updaten
_initialization->initializeSystem();
}
catch (boost::exception& ex)
catch (std::exception& ex)
{
ex << error_id(SIMMANAGER);
//ex << error_id(SIMMANAGER);
throw;
}

Expand Down Expand Up @@ -203,7 +203,7 @@ void SimManager::runSingleStep(double cycletime)
{

if (_lastCycleTime && cycletime != _lastCycleTime)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(SIMMANAGER) << error_message("Cycle time can not be changed, if time events (samples) are present!"));
throw ModelicaSimulationError(SIMMANAGER,"Cycle time can not be changed, if time events (samples) are present!");
else
_lastCycleTime = cycletime;

Expand Down Expand Up @@ -245,7 +245,7 @@ void SimManager::computeSampleCycles()
{
if (iter->first != 0.0 || iter->second == 0.0)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(SIMMANAGER) << error_message("Time event not starting at t=0.0 or not cyclic!"));
throw ModelicaSimulationError(SIMMANAGER,"Time event not starting at t=0.0 or not cyclic!");
}
else
{
Expand All @@ -256,7 +256,7 @@ void SimManager::computeSampleCycles()
}
else
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(SIMMANAGER) << error_message("Sample time is not a multiple of the cycle time!"));
throw ModelicaSimulationError(SIMMANAGER,"Sample time is not a multiple of the cycle time!");
}

}
Expand Down Expand Up @@ -291,7 +291,7 @@ void SimManager::runSimulation()
writeProperties();
}
}
catch (boost::exception & ex)
catch (std::exception & ex)
{
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Simulation finish with errors at t= " << _tEnd;
Expand All @@ -302,7 +302,7 @@ void SimManager::runSimulation()
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_critical) << "SimManger simmgr_error: " + simmgr_error_simmgr_info;
*/
ex << error_id(SIMMANAGER);
//ex << error_id(SIMMANAGER);
throw;
}
#ifdef RUNTIME_PROFILING
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Core/Solver/SystemStateSelection.cpp
Expand Up @@ -14,7 +14,7 @@ SystemStateSelection::SystemStateSelection(IMixedSystem* system)

_state_selection = dynamic_cast<IStateSelection*>(system);
if ( !_state_selection)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("No state selection system"));
throw ModelicaSimulationError(MATH_FUNCTION,"No state selection system");

}

Expand Down Expand Up @@ -93,7 +93,7 @@ return true;

if((pivot(jac, _dimDummyStates[i], _dimStateCanditates[i], _rowPivot[i].get(), _colPivot[i].get()) != 0))
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("Error, singular Jacobian for dynamic state selection at time"));
throw ModelicaSimulationError(MATH_FUNCTION,"Error, singular Jacobian for dynamic state selection at time");
}

/* if we have a new set throw event for reinitialization
Expand Down Expand Up @@ -167,7 +167,7 @@ void SystemStateSelection::setAMatrix(int* newEnable, unsigned int index)
_state_selection->setAMatrix(index,A1);
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MATH_FUNCTION) << error_message("No A matrix availibale for state selection"));
throw ModelicaSimulationError(MATH_FUNCTION,"No A matrix availibale for state selection");
_state_selection->setStates(index,states);
delete [] states ;
delete [] states2 ;
Expand Down
Expand Up @@ -79,12 +79,12 @@ void AlgLoopDefaultImplementation::initialize()
}
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(ALGLOOP_EQ_SYSTEM) << error_message("AlgLoopDefaultImplementation::initialize(): Unknown _constraintType."));
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,"AlgLoopDefaultImplementation::initialize(): Unknown _constraintType.");

//nach default algloop verschieben
// Prüfen ob min. eine Bindungsgleichung vorhanden
if ( _dimAEq == 0 )
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(ALGLOOP_EQ_SYSTEM) << error_message("AlgLoop::initialize(): No constraint defined."));
throw ModelicaSimulationError(ALGLOOP_EQ_SYSTEM,"AlgLoop::initialize(): No constraint defined.");

};

Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Core/System/AlgLoopSolverFactory.cpp
Expand Up @@ -50,7 +50,7 @@ boost::shared_ptr<IAlgLoopSolver> AlgLoopSolverFactory::createAlgLoopSolver(IAlg
_algsolvers.push_back(algsolver);
return algsolver;
}
catch(boost::exception &arg)
catch(std::exception &arg)
{
//the linear solver was not found -> take the nonlinear solver
}
Expand All @@ -67,7 +67,7 @@ boost::shared_ptr<IAlgLoopSolver> AlgLoopSolverFactory::createAlgLoopSolver(IAlg
else
{
// TODO: Throw an error message here.
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_FACTORY) << error_message("AlgLoop solver is not available"));
throw ModelicaSimulationError(MODEL_FACTORY,"AlgLoop solver is not available");
}
}

Expand Up @@ -76,12 +76,12 @@ SystemDefaultImplementation::~SystemDefaultImplementation()
void SystemDefaultImplementation::Assert(bool cond,const string& msg)
{
if(!cond)
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message(msg));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,msg);
}

void SystemDefaultImplementation::Terminate(string msg)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message(msg));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,msg);
}

int SystemDefaultImplementation::getDimBoolean() const
Expand Down Expand Up @@ -346,7 +346,7 @@ void SystemDefaultImplementation::storeDelay(unsigned int expr_id, double expr_v

}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("invalid delay expression id"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"invalid delay expression id");
}

void SystemDefaultImplementation::storeTime(double time)
Expand All @@ -370,7 +370,7 @@ double SystemDefaultImplementation::delay(unsigned int expr_id,double expr_value
{
if(delayTime < 0.0)
{
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("Negative delay requested"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"Negative delay requested");
}
if(_time_buffer.size()==0) //occurs in the initialization phase
{
Expand Down Expand Up @@ -423,7 +423,7 @@ double SystemDefaultImplementation::delay(unsigned int expr_id,double expr_value
else
{
double test = _time_buffer.back();
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("time im delay buffer not found"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"time im delay buffer not found");
}
}
if(t0==ts)//found exact time
Expand All @@ -442,7 +442,7 @@ double SystemDefaultImplementation::delay(unsigned int expr_id,double expr_value
}
}
else
BOOST_THROW_EXCEPTION(ModelicaSimulationError() << error_id(MODEL_EQ_SYSTEM) << error_message("invalid delay expression id"));
throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"invalid delay expression id");
}

double& SystemDefaultImplementation::getRealStartValue(double& key)
Expand Down

0 comments on commit 40a760f

Please sign in to comment.