1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/rtsolver.h,v 1.13 2017/01/12 14:46:10 masarati Exp $ */ 2 /* 3 * MBDyn (C) is a multibody analysis code. 4 * http://www.mbdyn.org 5 * 6 * Copyright (C) 1996-2017 7 * 8 * Pierangelo Masarati <masarati@aero.polimi.it> 9 * Paolo Mantegazza <mantegazza@aero.polimi.it> 10 * 11 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano 12 * via La Masa, 34 - 20156 Milano, Italy 13 * http://www.aero.polimi.it 14 * 15 * Changing this copyright notice is forbidden. 16 * 17 * This program is free software; you can redistribute it and/or modify 18 * it under the terms of the GNU General Public License as published by 19 * the Free Software Foundation (version 2 of the License). 20 * 21 * 22 * This program is distributed in the hope that it will be useful, 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * GNU General Public License for more details. 26 * 27 * You should have received a copy of the GNU General Public License 28 * along with this program; if not, write to the Free Software 29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 */ 31 32 #ifndef RTSOLVER_H 33 #define RTSOLVER_H 34 35 /* RTSolverBase - begin */ 36 37 class Solver; 38 39 class RTSolverBase { 40 public: 41 enum RTMode { 42 MBRT_UNKNOWN = -1, 43 44 MBRT_WAITPERIOD, 45 MBRT_SEMAPHORE, 46 MBRT_IO, 47 48 MBRT_LASTMODE 49 }; 50 51 protected: 52 Solver *pS; 53 54 RTMode eRTMode; 55 56 /* if eRTMode == MBRT_WAITPERIOD */ 57 unsigned long lRTPeriod; 58 59 unsigned long RTStackSize; 60 bool bRTAllowNonRoot; 61 int RTCpuMap; 62 63 bool bNoOutput; 64 RTWaitPeriod(void)65 bool RTWaitPeriod(void) const { 66 return (eRTMode == MBRT_WAITPERIOD); 67 }; 68 RTSemWait(void)69 bool RTSemWait(void) const { 70 return (eRTMode == MBRT_SEMAPHORE); 71 }; 72 RTBlockingIO(void)73 bool RTBlockingIO(void) const { 74 return (eRTMode == MBRT_IO); 75 }; 76 77 volatile int RTSteps; 78 79 public: 80 RTSolverBase(Solver *pS, 81 RTMode eRTMode, 82 unsigned long lRTPeriod, 83 unsigned long RTStackSize, 84 bool bRTAllowNonRoot, 85 int RTCpuMap, 86 bool bNoOutput = true); 87 virtual ~RTSolverBase(void); 88 89 // write contribution to restart file 90 virtual std::ostream& Restart(std::ostream& out) const = 0; 91 // very first setup, to be always performed 92 virtual void Setup(void) = 0; 93 // initialization to be performed only if real-time is requested 94 virtual void Init(void); 95 // check whether stop is commanded by real-time 96 virtual bool IsStopCommanded(void); 97 // to be performed when stop is commanded by someone else 98 virtual void StopCommanded(void) = 0; 99 // write real-time related message when stop commanded by someone else 100 virtual void Log(void) = 0; 101 // wait for period to expire 102 virtual void Wait(void) = 0; 103 }; 104 105 /* RTSolverBase - end */ 106 107 extern void 108 ReadRTParams(Solver *pS, MBDynParser& HP, 109 RTSolverBase::RTMode& eRTMode, 110 unsigned long& lRTPeriod, 111 unsigned long& RTStackSize, 112 bool& bRTAllowNonRoot, 113 int& RTCpuMap); 114 115 extern RTSolverBase * 116 ReadRTSolver(Solver *pS, MBDynParser& HP); 117 118 #endif // RTSOLVER_H 119 120