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