62 #include "ac/sys_sysinfo.h"
80 const std::string& sInFName,
81 const std::string& sOutFName,
82 unsigned int nThreads,
84 :
Solver(HPar, sInFName, sOutFName, nThreads, bPar),
86 pXPrimePrime(0), pLambda(0),
99 silent_cerr(
"Prepare() must be called first" << std::endl);
111 #ifdef USE_MULTITHREAD
119 int mpi_finalize = 0;
144 #ifdef USE_MULTITHREAD
151 #if defined(USE_UMFPACK)
154 #elif defined(USE_Y12)
161 silent_cerr(
"unable to select a CC-capable solver"
168 silent_cout(
"Creating multithread solver "
169 "with " << nThreads <<
" threads "
176 MultiThreadDataManager,
177 MultiThreadDataManager(
HP,
192 silent_cout(
"Creating scalar solver "
274 pdWorkSpace+((iNumPreviousVectors)+ivec)*iNumDofs));
351 pResTest = pResTestScale;
470 External::SendInitial();
475 pNLS->SetExternal(External::REGULAR);
483 Out <<
"Interrupted during first step." << std::endl;
523 silent_cerr(
"Start() must be called after Prepare()" << std::endl);
544 silent_cerr(
"Started() must be called first" << std::endl);
556 <<
"End of simulation at time "
557 <<
dTime <<
" after "
558 <<
lStep <<
" steps;" << std::endl
560 <<
"total iterations: " <<
iTotIter << std::endl
562 <<
"total error: " <<
dTotErr << std::endl);
572 <<
"Simulation is stopped by RTAI task" << std::endl
573 <<
"Simulation ended at time "
574 <<
dTime <<
" after "
575 <<
lStep <<
" steps;" << std::endl
576 <<
"total iterations: " <<
iTotIter << std::endl
578 <<
"total error: " <<
dTotErr << std::endl);
584 || (MPI_Finalized(&mpi_finalize), mpi_finalize)
593 <<
"Interrupted!" << std::endl
594 <<
"Simulation ended at time "
595 <<
dTime <<
" after "
596 <<
lStep <<
" steps;" << std::endl
597 <<
"total iterations: " <<
iTotIter << std::endl
599 <<
"total error: " <<
dTotErr << std::endl);
615 IfStepIsToBeRepeated:
636 <<
lStep <<
" after "
639 goto IfStepIsToBeRepeated;
644 <<
"Max iterations number "
646 <<
" has been reached during"
647 " step " <<
lStep <<
';'
651 <<
" cannot be reduced"
652 " further;" << std::endl
653 <<
"aborting..." << std::endl);
663 <<
"Simulation diverged after "
664 <<
iStIter <<
" iterations, before "
665 "reaching max iteration number "
667 <<
" during step " <<
lStep <<
';'
671 <<
" cannot be reduced"
672 " further;" << std::endl
673 <<
"aborting..." << std::endl);
681 silent_cerr(
"Simulation ended during a regular step:\n"
682 << eos.
what() <<
"\n");
693 <<
"Simulation ended at time "
694 <<
dTime <<
" after "
695 <<
lStep <<
" steps;" << std::endl
696 <<
"total iterations: " <<
iTotIter << std::endl
698 <<
"total error: " <<
dTotErr << std::endl);
719 Out <<
"Step " <<
lStep
731 silent_cout(
"Step " << std::setw(5) <<
lStep
734 <<
" " << std::setw(4) <<
iStIter
735 <<
" " << std::setw(13) <<
dTest
743 <<
" has been successfully completed "
744 "in " <<
iStIter <<
" iterations" << std::endl);
794 out <<
"begin: inverse dynamics;" << std::endl;
797 out <<
" # initial time: " <<
pDM->
dGetTime() <<
";"
807 out <<
" initial time: " <<
pDM->
dGetTime()<<
";" << std::endl
808 <<
" final time: " <<
dFinalTime <<
";" << std::endl
821 out <<
", test, norm" ;
824 out <<
", test, minmax" ;
829 silent_cerr(
"unhandled nonlinear solver test type" << std::endl);
840 out <<
", test, norm" ;
843 out <<
", test, minmax" ;
865 out <<
" # nonlinear solver: matrix free;" << std::endl;
869 out <<
" nonlinear solver: newton raphson";
873 out <<
", keep jacobian matrix";
876 out <<
", honor element requests";
879 out <<
";" << std::endl;
883 out <<
"end: multistep;" << std::endl << std::endl;
911 dw2 = this->dw1[2] + this->dw2[2];
929 const char* sKeyWords[] = {
931 "inverse" "dynamics",
941 "modify" "residual" "test",
942 "full" "residual" "test",
949 "fictitious" "steps" ,
976 "interface" "solver",
979 "interface" "linear" "solver",
985 "nonlinear" "solver",
992 "full" "jacobian" "matrix",
1001 "fully" "actuated" "collocated",
1002 "fully" "actuated" "non" "collocated",
1003 "underdetermined" "underactuated" "collocated",
1004 "underdetermined" "fully" "actuated",
1059 INTERFACELINEARSOLVER,
1093 silent_cerr(
"Error: <begin> expected at line "
1094 << HP.
GetLineData() <<
"; aborting..." << std::endl);
1099 silent_cerr(
"Error: <begin: inverse dynamics;> expected at line "
1100 << HP.
GetLineData() <<
"; aborting..." << std::endl);
1111 bool bModResTest(
false);
1113 #ifdef USE_MULTITHREAD
1114 bool bSolverThreads(
false);
1115 unsigned nSolverThreads(0);
1123 switch (CurrKeyWord) {
1136 silent_cerr(
"warning: final time " <<
dFinalTime
1137 <<
" is less than initial time "
1139 <<
"this will cause the simulation"
1140 " to abort" << std::endl);
1150 silent_cerr(
"warning, null initial time step"
1151 " is not allowed" << std::endl);
1154 silent_cerr(
"warning, negative initial time step"
1155 " is not allowed;" << std::endl
1157 <<
" will be considered" << std::endl);
1167 silent_cerr(
"warning, null minimum time step"
1168 " is not allowed" << std::endl);
1172 silent_cerr(
"warning, negative minimum time step"
1173 " is not allowed;" << std::endl
1175 <<
" will be considered" << std::endl);
1191 silent_cout(
"no max time step limit will be"
1192 " considered" << std::endl);
1194 silent_cerr(
"negative max time step"
1195 " is not allowed" << std::endl);
1202 switch (WhenToAbort) {
1206 "Simulation will abort after"
1207 " data input" << std::endl);
1213 "Simulation will abort after"
1214 " initial assembly" << std::endl);
1220 "Simulation will abort after"
1221 " derivatives solution" << std::endl);
1224 case FICTITIOUSSTEPS:
1228 "Simulation will abort after"
1229 " dummy steps solution" << std::endl);
1233 silent_cerr(
"Don't know when to abort,"
1234 " so I'm going to abort now" << std::endl);
1242 bool setOutput =
false;
1244 while (HP.
IsArg()) {
1246 switch (OutputFlag) {
1265 case JACOBIANMATRIX:
1278 silent_cerr(
"Unknown output flag "
1280 <<
"; ignored" << std::endl);
1311 silent_cerr(
"warning, residual tolerance "
1313 "using default value " << dTol
1332 silent_cerr(
"unknown test "
1341 silent_cerr(
"it's a nonsense "
1342 "to scale a disabled test; "
1359 if (dSolutionTol != 0.) {
1372 silent_cerr(
"unknown test "
1381 }
else if (dTol == 0.) {
1382 silent_cerr(
"need solution tolerance "
1383 "with null residual tolerance"
1388 if (dSolutionTol < 0.) {
1390 silent_cerr(
"warning, solution tolerance "
1392 "solution test is disabled"
1396 if (dTol == 0. && dSolutionTol == 0.) {
1397 silent_cerr(
"both residual and solution "
1398 "tolerances are zero" << std::endl);
1403 <<
", " << dSolutionTol << std::endl);
1408 case MAXITERATIONS: {
1412 silent_cerr(
"warning, max iterations "
1413 "< 1 is illegal; using default value "
1426 case MODIFY_RES_TEST:
1428 silent_cerr(
"\"modify residual test\" "
1429 "not supported by schur data manager "
1431 <<
"; ignored" << std::endl);
1435 "Modify residual test" << std::endl);
1451 case NEWTONRAPHSON: {
1452 pedantic_cout(
"Newton Raphson is deprecated; use "
1453 "\"nonlinear solver: newton raphson "
1454 "[ , modified, <steps> ]\" instead"
1466 "Newton-Raphson will be used; "
1467 "matrix will be assembled "
1470 <<
" iterations" << std::endl);
1474 silent_cerr(
"warning: unknown case; "
1475 "using default" << std::endl);
1488 silent_cerr(
"\"end: inverse dynamics;\" expected "
1490 <<
"; aborting..." << std::endl);
1501 silent_cerr(
"\"solver\" keyword at line "
1503 <<
" is deprecated; "
1504 "use \"linear solver\" instead"
1510 case INTERFACESOLVER:
1511 silent_cerr(
"\"interface solver\" keyword at line "
1513 <<
" is deprecated; "
1514 "use \"interface linear solver\" "
1515 "instead" << std::endl);
1516 case INTERFACELINEARSOLVER:
1520 silent_cerr(
"Interface solver only allowed "
1521 "when compiled with MPI support" << std::endl);
1525 case NONLINEARSOLVER:
1540 silent_cerr(
"unknown nonlinear solver "
1558 pedantic_cout(
"Use of deprecated \"keep jacobian\" at line " << HP.
GetLineData() << std::endl);
1561 }
else if (HP.
IsKeyWord(
"keep" "jacobian" "matrix")) {
1569 "assembled at most "
1574 if (HP.
IsKeyWord(
"honor" "element" "requests")) {
1578 "request to update "
1579 "the preconditioner"
1601 silent_cerr(
"unknown iterative "
1621 "steps for iterative "
1652 case FULLJACOBIANMATRIX:
1658 "before recomputing "
1659 "the preconditioner: "
1663 if (HP.
IsKeyWord(
"honor" "element" "requests")) {
1667 "request to update "
1668 "the preconditioner"
1677 silent_cerr(
"unknown "
1700 #ifdef USE_MULTITHREAD
1704 silent_cerr(
"got " << n <<
" CPUs "
1713 silent_cerr(
"configure with "
1714 "--enable-multithread "
1715 "for multithreaded assembly"
1720 #ifdef USE_MULTITHREAD
1725 #ifdef USE_MULTITHREAD
1726 bool bAssembly =
false;
1727 bool bSolver =
false;
1730 #endif // USE_MULTITHREAD
1733 #ifdef USE_MULTITHREAD
1736 #endif // USE_MULTITHREAD
1739 #ifdef USE_MULTITHREAD
1742 #endif // USE_MULTITHREAD
1745 #ifdef USE_MULTITHREAD
1747 #endif // USE_MULTITHREAD
1750 #ifdef USE_MULTITHREAD
1751 if (bAll || bAssembly) {
1755 if (bAll || bSolver) {
1756 bSolverThreads =
true;
1757 nSolverThreads = nt;
1760 silent_cerr(
"configure with "
1761 "--enable-multithread "
1762 "for multithreaded assembly"
1815 silent_cerr(
"inverse dynamics: unrecognized problem type at line " << HP.
GetLineData() << std::endl);
1820 silent_cerr(
"inverse dynamics: semicolon expected at line " << HP.
GetLineData() << std::endl);
1826 silent_cerr(
"unknown description at line "
1846 pedantic_cout(
"No time step control strategy defined; defaulting to NoChange time step control" );
1867 #ifdef USE_MULTITHREAD
1868 if (bSolverThreads) {
1870 silent_cerr(
"linear solver "
1872 <<
" does not support "
1873 "threaded solution" << std::endl);
void SetScale(VectorHandler &XScale) const
void ReadLinSol(LinSol &cs, HighParser &HP, bool bAllowEmpty)
integer * GetDofsList(DofType who) const
virtual void IDSetTest(NonlinearSolverTestRange *pResTest, NonlinearSolverTestRange *pSolTest, bool bFullResTest)
#define DEBUG_LEVEL_MATCH(level)
std::string outputCounterPrefix
std::ostream & RestartLinSol(std::ostream &out, const LinSol &cs)
RTSolverBase * ReadRTSolver(Solver *pS, MBDynParser &HP)
unsigned GetSolverFlags(void) const
StepIntegrator * pCurrStepIntegrator
virtual void SetScale(const VectorHandler *pScl)
bool outputCounter(void) const
#define MBDYN_EXCEPT_ARGS
void SetOutputMeter(DriveCaller *pOM)
#define DEBUGCOUTFNAME(fname)
virtual integer GetInt(integer iDefval=0)
void SetOutputFlags(unsigned OF)
virtual bool Advance(void)
virtual void OutputTypes(const bool fpred)
doublereal dGetTime(void) const
virtual bool Output(long lStep, const doublereal &dTime, const doublereal &dTimeStep, bool force=false) const
const char * what(void) const
std::string sOutputFileName
virtual void Wait(void)=0
bool outputMsg(void) const
#define SAFEDELETEARR(pnt)
StepIntegrator::StepChange CurrStep
integer iDummyStepsNumber
doublereal dDummyStepsRatio
virtual void SetDriveHandler(const DriveHandler *driveHandler)=0
bool SetNumThreads(unsigned nt)
StepIntegrator * pDerivativeSteps
virtual integer GetIntegratorMaxIters(void) const
const DriveHandler * pGetDrvHdl(void) const
integer iNumPreviousVectors
void SetDataManager(DataManager *pDatMan)
NonlinearSolver::Type NonlinearSolverType
InverseSolver(MBDynParser &HP, const std::string &sInputFileName, const std::string &sOutputFileName, unsigned int nThreads, bool bParallel=false)
virtual ~InverseSolver(void)
integer iIterationsBeforeAssembly
InverseDynamics::Type GetProblemType(void) const
bool outputStep(void) const
virtual void StopCommanded(void)=0
std::deque< MyVectorHandler * > qXPrime
virtual bool GetYesNoOrBool(bool bDefval=false)
DriveCaller * pOutputMeter
std::string sInputFileName
virtual integer TotalAssembledJacobian(void)
void SetupSolmans(integer iStates, bool bCanBeParallel=false)
void mbdyn_signal_init(int pre)
bool SetSolver(SolverType t, unsigned f=SOLVER_FLAGS_NONE)
MatrixFreeSolver::SolverType MFSolverType
static const integer iDefaultMaxIterations
void SetValue(VectorHandler &X, VectorHandler &XP)
void LinkToSolution(VectorHandler &XCurr, VectorHandler &XPrimeCurr)
virtual void SetDrvHdl(const DriveHandler *pDH)
NonlinearSolverTest::Type SolTest
std::ostream & GetOutFile(void) const
std::ostream & Restart(std::ostream &out, DataManager::eRestart type) const
void AddOutputFlags(unsigned OF)
#define SAFENEW(pnt, item)
static const integer iDefaultIterationsBeforeAssembly
bool AddSolverFlags(unsigned f)
NonlinearSolver *const AllocateNonlinearSolver()
virtual bool IsKeyWord(const char *sKeyWord)
StepIntegrator * pRegularSteps
doublereal dInitialTimeStep
static const doublereal dDefaultMaxTimeStep
virtual bool Prepare(void)
virtual doublereal GetIntegratorDTol(void) const
virtual void OutputPrepare(void)
void ReadData(MBDynParser &HP)
MyVectorHandler * pLambda
virtual void SetTest(NonlinearSolverTest *pr, NonlinearSolverTest *ps)
virtual bool IsStopCommanded(void)
doublereal dIterertiveTau
virtual MathParser & GetMathParser(void)
doublereal dIterertiveEtaMax
int mbdyn_stop_at_end_of_time_step(void)
#define ASSERT(expression)
StepIntegrator * pDummySteps
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
DriveCaller * pGetDriveCaller(void) const
InverseDynamics::Type ProblemType
void SetTime(const doublereal &dTime, const doublereal &dTimeStep=-1., const integer &iStep=-1, bool bServePending=true)
virtual doublereal dGetNewStepTime(StepIntegrator::StepChange currStep, doublereal iPerformedIters)=0
virtual DriveCaller * pCopy(void) const =0
virtual void SetDriveHandler(const DriveHandler *pDH)
static const doublereal dDefaultTol
Dof * pGetDofsList(void) const
std::deque< MyVectorHandler * > qX
integer HowManyDofs(DofType who) const
virtual int GetWord(void)
NonlinearSolverTest::Type ResTest
virtual integer GetIntegratorNumPreviousStates(void) const
std::ostream & GetLogFile(void) const
std::string outputCounterPostfix
Preconditioner::PrecondType PcType
void Set(const DriveCaller *pDC)
doublereal dGet(const doublereal &dVar) const
MyVectorHandler * pXPrime
TimeStepControl * ReadTimeStepData(Solver *s, MBDynParser &HP)
#define SAFENEWARR(pnt, item, sz)
DriveCaller * GetDriveCaller(bool bDeferred=false)
doublereal dGetInitialMaxTimeStep() const
virtual void Init(integer iMaxIterations, doublereal dMinTimeStep, const DriveOwner &MaxTimeStep, doublereal dInitialTimeStep)=0
const char *const GetSolverName(void) const
void GetWeight(InverseDynamics::Order iOrder, doublereal &dw1, doublereal &dw2) const
integer iIterativeMaxSteps
virtual HighParser::ErrOut GetLineData(void) const
Table & GetSymbolTable(void) const
virtual void Setup(void)=0
doublereal dDerivativesCoef
void CreatePartition(void)
#define DEBUGLCOUT(level, msg)
void mbdyn_set_stop_at_end_of_time_step(void)
MyVectorHandler * pXPrimePrime
integer iGetNumDofs(void) const
virtual integer GetIntegratorNumUnknownStates(void) const
virtual doublereal GetIntegratorDSolTol(void) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)