00001
00002
00003 #ifndef SOLID_PROBLEM_H
00004 #define SOLID_PROBLEM_H
00005
00006 #define DIM 3
00007 #define SML -1e10
00008 #define LRG 1e10
00009
00010 #define maxAssemblies 10
00011 #define maxSubAssemblies 10
00012 #define maxParts 10
00013 #define maxLevels 10
00014
00015 #define ChainLimit 10
00016 #define maxSubChains 10
00017 #define maxLinks 10
00018 #define LinkLimit 20
00019 #define maxJoints 2
00020 #define JointLimit 10
00021
00022 #define MAX_TURBINES 3
00023
00024 #include "MotionSolver.h"
00025 #include "MotionELCCoupledSolver.h"
00026 #include "TurbineMechanism.h"
00027
00028
00029 class MotionSpecific : public MotionELCCoupledSolver<DataType,DIM> {
00030 typedef MotionELCCoupledSolver<DataType,DIM> base;
00031 typedef MotionSolver<DataType,DIM> MotionSolverbase;
00032 public:
00033 MotionSpecific() : base() {
00034 num_turbines = 1;
00035 }
00036
00037 virtual void register_at(ControlDevice& Ctrl) {
00038 register_at(Ctrl,"");
00039 }
00040 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00041
00042 SLocCtrl = Ctrl.getSubDevice(prefix+"MotionSolver");
00043 RegisterAt(SLocCtrl,"FileType",brep_filetype);
00044 RegisterAt(SLocCtrl,"InputBrep",brep_filename);
00045 RegisterAt(SLocCtrl,"VelocityFile",vel_filename);
00046 RegisterAt(SLocCtrl,"OutputName",OutputName);
00047 RegisterAt(SLocCtrl,"CheckpointName",CheckpointName);
00048
00049 RegisterAt(SLocCtrl,"Scale",scale);
00050 RegisterAt(SLocCtrl,"Center(1)",xs[0]);
00051 RegisterAt(SLocCtrl,"Center(2)",xs[1]);
00052 RegisterAt(SLocCtrl,"Center(3)",xs[2]);
00053 RegisterAt(SLocCtrl,"RotationDuration",Tr);
00054 RegisterAt(SLocCtrl,"dt",dtret);
00055
00056 RegisterAt(SLocCtrl,"PrescribedMotion",prescribed);
00057 RegisterAt(SLocCtrl,"num_turbines",num_turbines);
00058 RegisterAt(SLocCtrl,"log_every",MotionSolverbase::log_every);
00059
00060 RegisterAt(SLocCtrl,"SceneName",SceneName);
00061 RegisterAt(SLocCtrl,"SAtimeStep",base::SAL);
00062
00063 for (register int i = 0; i < MAX_TURBINES; i++) {
00064 TurbineCtrls[i].register_at(SLocCtrl,prefix+"MotionSolver",i);
00065 }
00066
00067
00068 }
00069
00070 virtual bool specificSetup() {
00071 _Scene().setName(SceneName);
00072 for (register int i = 0; i < num_turbines; i++) {
00073 TurbineCtrls[i].print();
00074 }
00075
00076 for (register int i = 0; i < num_turbines; i++) {
00077 #ifdef MOTION_DEBUG_ON
00078 ( base::log() << "SolidProblem.h TurbineCtrls[" << i << "].tower_name = " << TurbineCtrls[i].tower_name << std::endl ).flush();
00079 #endif
00080 ( base::log() << "SolidProblem.h TurbineCtrls[" << i << "].tower_name = " << TurbineCtrls[i].tower_name << std::endl ).flush();
00081 Turbines[i].specificSetup(_Scene(),&TurbineCtrls[i]);
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 _Scene().printSummary();
00091
00092 #ifdef MOTION_DEBUG_ON
00093 ( base::log() << "\tSolidSolverSpecific specificSetup END\n";
00094 #endif
00095 return true;
00096 }
00097
00098 virtual void movement(double& t, double& dt) {
00099 #ifdef MOTION_DEBUG_ON
00100 ( base::log() << "\n\n*********\tSolidSolverSpecific movement aDVANCE bEGIN\n*********" << std::endl ).flush();
00101 ( base::log() << " time = " << t << " time*DataType(360.0/6.) = " << t*DataType(360.0/6.)
00102 << " time*DataType(360.0/6.)*d2r = " << t*DataType(360.0/6.)*d2r << std::endl
00103 << " steps = " << steps << " dt = " << dt << std::endl ).flush();
00104 #endif
00105
00106 for (register int i = 0; i < num_turbines; i++) {
00107 #ifdef MOTION_DEBUG_ON
00108 ( base::log() << "SolidProblem.h TurbineCtrls[" << i << "].tower_name = " << TurbineCtrls[i].tower_name << std::endl ).flush();
00109 #endif
00110 if (prescribed == 1) {
00111 Turbines[i].movement(&Turbines[i],&TurbineCtrls[i], t, dt);
00112 }
00113 else {
00114 Turbines[i].response(&Turbines[i],&TurbineCtrls[i], t, dt, MotionSolverbase::NSteps(), MotionSolverbase::LogEvery() );
00115 }
00116 }
00117
00118 if ( MotionSolverbase::NSteps() % MotionSolverbase::log_every == 0 ) {
00119 logKinetics();
00120 }
00121
00122 #ifdef MOTION_DEBUG_ON
00123 ( base::log() << "\n\n*********\tSolidSolverSpecific movement aDVANCE fINISHED\n*********" << std::endl ).flush();
00124 #endif
00125 }
00126
00127 virtual void logKinetics() {
00128 char fname[256];
00129 sprintf(fname,"%s_kinetics.json",CheckpointName.c_str());
00130 std::ofstream ofs;
00131 if ( ! fexists(fname) ) {
00132 ofs.open(fname, std::ios::out);
00133 ofs << "{\n";
00134 }
00135 else {
00136 ofs.open(fname, std::ios::app);
00137 }
00138 ofs << "\t\"" << MotionSolverbase::NSteps() << "\": {\n";
00139 ofs << "\t\t\"time\": " << MotionSolverbase::CurrentTime() << ",\n";
00140 for (register int i = 0; i < num_turbines; i++) {
00141 Turbines[i].logKinetics(&Turbines[i],&TurbineCtrls[i], ofs, MotionSolverbase::CurrentTime(), MotionSolverbase::NSteps());
00142 if (i<num_turbines-1) ofs << ",";
00143 ofs << "\n";
00144 }
00145 ofs << "\t}," << std::endl;
00146 ofs.close();
00147 }
00148
00149 virtual void Restart(double& t, double& dt) {
00150 MotionSolverbase::Restart(t,dt);
00151 #ifdef CHECKRESTART_DEBUG_ON
00152 ( base::log() << "\nRestarting Solid Problem t= " << t << " dt = " << dt << " pos = " << MotionSolverbase::pos << std::endl ).flush();
00153 #endif
00154
00155 char fname[256];
00156 sprintf(fname,"%s.cp",CheckpointName.c_str());
00157 std::ifstream ifs(fname, std::ios::in);
00158 if (ifs.is_open()) {
00159 ( base::log() << " OPEN\n").flush();
00160 }
00161 else {
00162 ( base::log() << " CLOSED\n").flush();
00163 }
00164 ifs.seekg(MotionSolverbase::pos);
00165 ( base::log() << " num_turbines = " << num_turbines << std::endl ).flush();
00166 for (register int i=0; i < num_turbines; i++) {
00167 Turbines[i].Restart(ifs,pos,t,dt);
00168 pos = ifs.tellg();
00169 }
00170
00171 pos = ifs.tellg();
00172
00173 #ifdef CHECKRESTART_DEBUG_ON
00174 ( base::log() << "\nDone Restarting Solid Problem t = " << t << " dt = " << dt << " pos = " << pos << std::endl ).flush();
00175 #endif
00176 ifs.close();
00177
00178 ( base::log() << "\n__________$ SolidProblem.h Restart() sendBoundaryRecievePressure() \n").flush();
00179 base::sendBoundaryReceivePressure();
00180 ( base::log() << "\n__________$ SolidProblem.h Restart() sendBoundaryRecievePressure() complete \n").flush();
00181 }
00182
00183 virtual void Checkpointing() {
00184 MotionSolverbase::Checkpointing();
00185 #ifdef CHECKRESTART_DEBUG_ON
00186 ( base::log() << "\nCHECKPOINTING Solid Problem " << std::endl ).flush();
00187 #endif
00188 char fname[256];
00189 sprintf(fname,"%s.cp",CheckpointName.c_str());
00190 std::ofstream ofs(fname, std::ios::app);
00191
00192 ( base::log() << "\n+++ CHECKPOINTING Solid Problem begun : appending at pos = " << ofs.tellp() << std::endl ).flush();
00193
00194 ( base::log() << " num_turbines = " << num_turbines << std::endl ).flush();
00195 for (register int i=0; i < num_turbines; i++) {
00196 Turbines[i].Checkpointing(ofs);
00197 }
00198
00199
00200
00201 #ifdef CHECKRESTART_DEBUG_ON
00202 ( base::log() << "\n+++ CHECKPOINTING Solid Problem COMPLETE pos = " << ofs.tellp() << std::endl ).flush();
00203 #endif
00204 ofs.close();
00205 }
00206
00207 int num_turbines;
00208 Turbine Turbines[MAX_TURBINES];
00209 TurbineControl TurbineCtrls[MAX_TURBINES];
00210
00211 bool prescribed;
00212
00213
00214
00215 ControlDevice SLocCtrl;
00216
00217 std::string SceneName;
00218 };
00219
00220 class SolidSolverObjects {
00221 public:
00222 SolidSolverObjects() {
00223 _MotionSpecific = new MotionSpecific();
00224 }
00225
00226 ~SolidSolverObjects() {
00227 delete _MotionSpecific;
00228 }
00229
00230 protected:
00231 MotionSpecific *_MotionSpecific;
00232 };
00233
00234 class SolidSolverSpecific : protected SolidSolverObjects, public MotionSpecific {
00235 typedef MotionSpecific base;
00236 public:
00237 SolidSolverSpecific() : SolidSolverObjects(), base() {}
00238
00239 ~SolidSolverSpecific() {
00240 delete _MotionSpecific;
00241 _MotionSpecific = (base *) 0;
00242 }
00243
00244 };
00245
00246
00247 #endif
00248
00249