Changeset e8fbdf6 in OpenModelica
- Timestamp:
- 2016-04-06T13:19:25+02:00 (8 years ago)
- Branches:
- Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, master, omlib-staging
- Children:
- df3f1c94
- Parents:
- 41d4cef
- git-author:
- Rüdiger Franke <rdgfranke@…> (04/06/16 13:19:25)
- git-committer:
- hudson <openmodelica@…> (04/06/16 13:19:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SimulationRuntime/cpp/Solver/Newton/Newton.cpp
r325d842 re8fbdf6 98 98 dimRHS = 1, // Dimension of right hand side of linear system (=b) 99 99 info = 0; // Retrun-flag of Fortran code 100 101 100 int 102 totStps = 0; // Total number of steps 101 totSteps = 0; // Total number of steps taken 102 double 103 atol = _newtonSettings->getAtol(), 104 rtol = _newtonSettings->getRtol(); 103 105 104 106 // If initialize() was not called yet … … 106 108 initialize(); 107 109 108 // Get initializeialvalues from system110 // Get current values from system 109 111 _algLoop->getReal(_y); 110 //_algLoop->evaluate(command);111 _algLoop->getRHS(_f);112 112 113 113 // Reset status flag 114 114 _iterationStatus = CONTINUE; 115 115 116 while(_iterationStatus == CONTINUE) { 117 _iterationStatus = DONE; 116 while (_iterationStatus == CONTINUE) { 118 117 // Check stopping criterion 119 118 calcFunction(_y,_f); 120 if (totStps) { 119 if (totSteps) { 120 _iterationStatus = DONE; 121 121 for (int i=0; i<_dimSys; ++i) { 122 if (fabs(_f[i]) > _newtonSettings->getAtol() +_newtonSettings->getRtol() * ( fabs(_f[i]))) {122 if (fabs(_f[i]) > atol + fabs(_y[i]) * rtol) { 123 123 _iterationStatus = CONTINUE; 124 124 break; … … 126 126 } 127 127 } 128 else129 _iterationStatus = CONTINUE;130 131 // New right hand side132 //calcFunction(_y,_f);133 128 134 129 if (_iterationStatus == CONTINUE) { 135 if (totSt ps < _newtonSettings->getNewtMax()) {130 if (totSteps < _newtonSettings->getNewtMax()) { 136 131 // Determination of Jacobian (Fortran-format) 137 if (_algLoop->isLinear()&&!_algLoop->isLinearTearing()) { 138 //calcFunction(_yHelp,_fHelp); 132 if (_algLoop->isLinear() && !_algLoop->isLinearTearing()) { 139 133 const matrix_t& A = _algLoop->getSystemMatrix(); 140 134 const double* jac = A.data().begin(); … … 144 138 _algLoop->setReal(_y); 145 139 if (info != 0) 146 throw ModelicaSimulationError(ALGLOOP_SOLVER,"error solving linear tearing system"); 140 throw ModelicaSimulationError(ALGLOOP_SOLVER, 141 "error solving linear system (dgesv info: " + to_string(info) + ")"); 147 142 else 148 143 _iterationStatus = DONE; 149 144 } 150 145 else if (_algLoop->isLinearTearing()) { 151 long int dimRHS = 1; // Dimension of right hand side of linear system(=b)152 153 long int info = 0; // Retrun-flag of Fortran code146 long int dimRHS = 1; // Dimension of right hand side (=b) 147 148 long int info = 0; // Return-flag of Fortran code 154 149 155 150 _algLoop->setReal(_zeroVec); … … 169 164 _algLoop->evaluate(); 170 165 if (info != 0) 171 throw ModelicaSimulationError(ALGLOOP_SOLVER, "error solving linear tearing system"); 166 throw ModelicaSimulationError(ALGLOOP_SOLVER, 167 "error solving linear tearing system (dgesv info: " + to_string(info) + ")"); 172 168 else 173 169 _iterationStatus = DONE; … … 179 175 dgesv_(&_dimSys, &dimRHS, _jac, &_dimSys, _iHelp, _f, &_dimSys, &info); 180 176 181 if (info != 0) { 182 // TODO: Throw an error message here. 183 _iterationStatus = SOLVERERROR; 184 break; 185 } 177 if (info != 0) 178 throw ModelicaSimulationError(ALGLOOP_SOLVER, 179 "error solving nonlinear system (iteration: " + to_string(totSteps) 180 + ", dgesv info: " + to_string(info) + ")"); 186 181 187 182 // Increase counter 188 ++ totSt ps;183 ++ totSteps; 189 184 190 185 // New solution … … 193 188 } 194 189 } 195 else { 196 _iterationStatus = SOLVERERROR; 197 throw ModelicaSimulationError(ALGLOOP_SOLVER,"error solving non linear system"); 198 199 } 190 else 191 throw ModelicaSimulationError(ALGLOOP_SOLVER, 192 "error solving nonlinear system (iteration limit: " + to_string(totSteps) + ")"); 200 193 } 201 194 }
Note: See TracChangeset
for help on using the changeset viewer.