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