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