00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_FEM_INPUTDATA_H
00023 #define MECHSYS_FEM_INPUTDATA_H
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include "config.h"
00027 #else
00028 #ifndef REAL
00029 #define REAL double
00030 #endif
00031 #endif
00032
00033 #include <sstream>
00034 #include <fstream>
00035
00036 #include "util/util.h"
00037 #include "util/array.h"
00038 #include "util/string.h"
00039 #include "util/exception.h"
00040 #include "util/lineparser.h"
00041 #include "util/fileparser.h"
00042 #include "numerical/integschemesctes.h"
00043
00044 namespace FEM
00045 {
00046
00048
00052 class InputData
00053 {
00054 public:
00055 enum LinSolver_T { lsLAPACK, lsUMFPACK, lsSUPERLU };
00056
00057 String fullPATH;
00058 String projNAME;
00059 String projDESC;
00060
00061 String fnNODE;
00062 String fnFACE;
00063 String fnELE;
00064 String fnNBC;
00065 String fnFBC;
00066 String fnATT;
00067 String fnINI;
00068
00069 int nSTAGES;
00070 Array<int> nDIV;
00071 Array<REAL> dTIME;
00072 String solNAME;
00073 Array<String> solCTES;
00074 IntegSchemesCtes intSC;
00075 REAL CoordsMult;
00076
00077 LinSolver_T linSOLVER;
00078
00079 Array<int> outNODES;
00080 Array<int> outELEMS;
00081 Array<int> outSTAGES;
00082 Array<int> DoOutSTAGE;
00083 Array<String> fnOutNODES;
00084 Array<String> fnOutELEMS;
00085 Array<String> fnOutSTAGES;
00086 String fnOutVTK;
00087 String outSubFldr;
00088 bool vtkOutScalar1;
00089 bool vtkOutScalar2;
00090 bool vtkOutTensor1;
00091 bool vtkOutTensor2;
00092 bool vtkOutTensor3;
00093 bool vtkOutAllIncs;
00094 bool vtkOutEssen;
00095 bool vtkOutNatur;
00096 public:
00097 void ParseInputArgs (int argc, char **argv, String & MainFilename, bool & IsConsole, bool & IsSilent, bool & IsHelpMsg);
00098 void ReadMainFile (String const & MainFilename);
00099 void WriteMainFile (String const & MainFilename, bool DoOverwrite=false);
00100 String InitialMessage ();
00101 String HelpMessage ();
00102 };
00103
00104
00106
00107
00108 inline void InputData::ParseInputArgs (int argc, char **argv, String & MainFilename, bool & IsConsole, bool & IsSilent, bool & IsHelpMsg)
00109 {
00120
00121 MainFilename = "";
00122 IsConsole = true;
00123 IsSilent = false;
00124 IsHelpMsg = false;
00125
00126
00127 if (argc==1)
00128 return;
00129
00130
00131 if (argc==2)
00132 {
00133 if ((strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0))
00134 IsHelpMsg = true;
00135 else
00136 MainFilename = argv[1];
00137 }
00138
00139
00140 if (argc==3)
00141 {
00142 if (strcmp(argv[1],"--nogui")==0)
00143 {
00144
00145 IsConsole = true;
00146 MainFilename = argv[2];
00147 }
00148 else if (strcmp(argv[1],"--silent")==0)
00149 {
00150
00151 IsConsole = true;
00152 IsSilent = true;
00153 MainFilename = argv[2];
00154 }
00155 else
00156 throw new Warning("%s",HelpMessage().GetSTL().c_str());
00157 }
00158
00159
00160 if (argc>=4)
00161 throw new Warning("%s",HelpMessage().GetSTL().c_str());
00162
00163 }
00164
00165 inline void InputData::ReadMainFile(String const & MainFilename)
00166 {
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 FileParser FP(MainFilename);
00200
00201
00202 fullPATH.clear();
00203 projNAME.clear();
00204 projDESC.clear();
00205
00206
00207 fnNODE.clear();
00208 fnFACE.clear();
00209 fnELE .clear();
00210 fnNBC .clear();
00211 fnFBC .clear();
00212 fnATT .clear();
00213 fnINI .clear();
00214
00215
00216 nSTAGES = 0;
00217 nDIV .resize(0);
00218 dTIME .resize(0);
00219 solNAME = "Unknown";
00220 solCTES .resize(0);
00221 CoordsMult = 1.0;
00222 linSOLVER = lsLAPACK;
00223
00224
00225 outNODES .resize(0);
00226 outELEMS .resize(0);
00227 outSTAGES .resize(0);
00228 DoOutSTAGE .resize(0);
00229 fnOutNODES .resize(0);
00230 fnOutELEMS .resize(0);
00231 fnOutSTAGES.resize(0);
00232 fnOutVTK .clear();
00233 outSubFldr .clear();
00234 vtkOutScalar1 = false;
00235 vtkOutScalar2 = false;
00236 vtkOutTensor1 = true;
00237 vtkOutTensor2 = true;
00238 vtkOutTensor3 = false;
00239 vtkOutAllIncs = false;
00240 vtkOutEssen = true;
00241 vtkOutNatur = true;
00242
00243
00244 String tmp_fnNODE;
00245 String tmp_fnFACE;
00246 String tmp_fnELE;
00247 String tmp_fnNBC;
00248 String tmp_fnFBC;
00249 String tmp_fnATT;
00250 String tmp_fnINI;
00251
00252
00253 while (!FP.IsEOF())
00254 {
00255 FP.JumpCommentsOrBlanks();
00256 LineParser LP(FP.GetCurrentLine());
00257 FP.Advance();
00258 String key; LP>>key;
00259 if (key=="PROJECT")
00260 {
00261 String subkey; LP>>subkey;
00262 if (subkey=="NAME") LP>>projNAME;
00263 else if (subkey=="DESC")
00264 {
00265 String val;
00266 while (LP>>val) { projDESC.append(val); projDESC.append(String(" ")); }
00267 projDESC.append(String("#"));
00268 }
00269 else throw new Fatal(_("Main file format invalid <PROJECT>"));
00270 }
00271 else if (key=="FILE")
00272 {
00273 String subkey; LP>>subkey;
00274 if (subkey=="NODE") LP>>tmp_fnNODE;
00275 else if (subkey=="FACE") LP>>tmp_fnFACE;
00276 else if (subkey=="ELE") LP>>tmp_fnELE;
00277 else if (subkey=="NBC") LP>>tmp_fnNBC;
00278 else if (subkey=="FBC") LP>>tmp_fnFBC;
00279 else if (subkey=="ATT") LP>>tmp_fnATT;
00280 else if (subkey=="INI") LP>>tmp_fnINI;
00281 else throw new Fatal(_("Main file format invalid <FILE>"));
00282 }
00283 else if (key=="SOLVER")
00284 {
00285 String subkey; LP>>subkey;
00286 if (subkey=="NSTAGES") LP>>nSTAGES;
00287 else if (subkey=="NDIV")
00288 {
00289 int val;
00290 while (LP>>val) nDIV.push_back(val);
00291 }
00292 else if (subkey=="DTIME")
00293 {
00294 REAL val;
00295 while (LP>>val) dTIME.push_back(val);
00296 }
00297 else if (subkey=="SCHEME")
00298 {
00299 LP>>solNAME; String val;
00300 while (LP>>val) solCTES.push_back(val);
00301 }
00302 else if (subkey=="LINSOLVER")
00303 {
00304 String val; LP>>val;
00305 if (val=="LAPACK" ) { linSOLVER = lsLAPACK; }
00306 else if (val=="UMFPACK") { linSOLVER = lsUMFPACK; }
00307 else if (val=="SUPERLU") { linSOLVER = lsSUPERLU; }
00308 else throw new Fatal(_("InputData::ReadMainFile: < SOLVER LINSOLVER %s > is invalid"),val.GetSTL().c_str());
00309 }
00310 else if (subkey=="SUBSCHEME")
00311 {
00312 String str;
00313 while (LP>>str)
00314 {
00315 String ssubkey;
00316 LineParser lp(str);
00317 lp.ReplaceAllChars('=',' ');
00318 lp>>ssubkey;
00319 if (ssubkey=="type") { String val; lp>>val; intSC.Type (val); }
00320 else if (ssubkey=="ndiv") { int val; lp>>val; intSC.FE_ndiv (val); }
00321 else if (ssubkey=="maxSS") { int val; lp>>val; intSC.ME_maxSS (val); }
00322 else if (ssubkey=="STOL") { REAL val; lp>>val; intSC.ME_STOL (val); }
00323 else if (ssubkey=="dTini") { REAL val; lp>>val; intSC.ME_dTini (val); }
00324 else if (ssubkey=="mMin") { REAL val; lp>>val; intSC.ME_mMin (val); }
00325 else if (ssubkey=="mMax") { REAL val; lp>>val; intSC.ME_mMax (val); }
00326 else throw new Fatal(_("InputData::ReadMainFile: < SOLVER SUBSCHEME %s > is invalid"), ssubkey.c_str());
00327 }
00328 }
00329 else if (subkey=="COORDSMULT") LP>>CoordsMult;
00330 else throw new Fatal(_("Main file format invalid <SOLVER>"));
00331 }
00332 else if (key=="OUTPUT")
00333 {
00334 String subkey; LP>>subkey;
00335 if (subkey=="NODES")
00336 {
00337 int val;
00338 while (LP>>val) outNODES.push_back(val);
00339 }
00340 else if (subkey=="ELEMS")
00341 {
00342 int val;
00343 while (LP>>val) outELEMS.push_back(val);
00344 }
00345 else if (subkey=="STAGES")
00346 {
00347 int val;
00348 while (LP>>val) outSTAGES.push_back(val);
00349 }
00350 else if (subkey=="SCALAR1") { String val; LP>>val; vtkOutScalar1 = Util::Str2Bool(val); }
00351 else if (subkey=="SCALAR2") { String val; LP>>val; vtkOutScalar2 = Util::Str2Bool(val); }
00352 else if (subkey=="TENSOR1") { String val; LP>>val; vtkOutTensor1 = Util::Str2Bool(val); }
00353 else if (subkey=="TENSOR2") { String val; LP>>val; vtkOutTensor2 = Util::Str2Bool(val); }
00354 else if (subkey=="TENSOR3") { String val; LP>>val; vtkOutTensor3 = Util::Str2Bool(val); }
00355 else if (subkey=="ALLINCS") { String val; LP>>val; vtkOutAllIncs = Util::Str2Bool(val); }
00356 else if (subkey=="ESSENTIAL") { String val; LP>>val; vtkOutEssen = Util::Str2Bool(val); }
00357 else if (subkey=="NATURAL") { String val; LP>>val; vtkOutNatur = Util::Str2Bool(val); }
00358 else if (subkey=="SUBFLDR") LP>>outSubFldr;
00359 else throw new Fatal(_("Main file format invalid <OUTPUT>"));
00360 }
00361 else throw new Fatal(_("Main file format invalid"));
00362 }
00363
00364
00365 String fname(projNAME); fname.append(String(".main"));
00366 Array<String> pieces;
00367 LineParser LP(MainFilename); LP.SeparatedLine(fname, pieces);
00368 fullPATH = pieces[0];
00369
00370
00371 fnNODE=fullPATH; fnNODE.append(tmp_fnNODE); fnNODE.append(String(".node"));
00372 fnFACE=fullPATH; fnFACE.append(tmp_fnFACE); fnFACE.append(String(".face"));
00373 fnELE =fullPATH; fnELE .append(tmp_fnELE); fnELE .append(String(".ele"));
00374 fnNBC =fullPATH; fnNBC .append(tmp_fnNBC); fnNBC .append(String(".nbc"));
00375 fnFBC =fullPATH; fnFBC .append(tmp_fnFBC); fnFBC .append(String(".fbc"));
00376 fnATT =fullPATH; fnATT .append(tmp_fnATT); fnATT .append(String(".att"));
00377 fnINI =fullPATH; fnINI .append(tmp_fnINI); fnINI .append(String(".ini"));
00378
00379
00380 if (outSubFldr.empty()) outSubFldr.append(_("./"));
00381 else outSubFldr.append(_("/"));
00382
00383
00384 fnOutVTK=fullPATH; fnOutVTK.append(outSubFldr); fnOutVTK.append(solNAME); fnOutVTK.append(_(".vtk"));
00385
00386
00387 fnOutNODES.resize(outNODES.size());
00388 for (size_t i=0; i<outNODES.size(); ++i)
00389 {
00390 fnOutNODES[i].append(fullPATH);
00391 fnOutNODES[i].append(outSubFldr); String buf; buf.Printf(String("node-%d-%s"),outNODES[i],solNAME.c_str());
00392 fnOutNODES[i].append(buf);
00393 }
00394
00395
00396 fnOutELEMS.resize(outELEMS.size());
00397 for (size_t i=0; i<outELEMS.size(); ++i)
00398 {
00399 fnOutELEMS[i].append(fullPATH);
00400 fnOutELEMS[i].append(outSubFldr); String buf; buf.Printf(String("elem-%d-%s"),outELEMS[i],solNAME.c_str());
00401 fnOutELEMS[i].append(buf);
00402 }
00403
00404
00405 if (nSTAGES<=0) throw new Fatal(_("InputData::ReadMainFile: Number of stages (%d) is incorrect. It must be greater than 0"),nSTAGES);
00406
00407
00408 fnOutSTAGES.resize(nSTAGES);
00409 for (int i=0; i<nSTAGES; ++i)
00410 {
00411 fnOutSTAGES[i].append(fullPATH);
00412 fnOutSTAGES[i].append(outSubFldr); String buf; buf.Printf(String("stage-%d-%s"),i+1,solNAME.c_str());
00413 fnOutSTAGES[i].append(buf);
00414 }
00415
00416
00417 if (outSTAGES.size()>0) DoOutSTAGE.resize(nSTAGES,0);
00418 else DoOutSTAGE.resize(nSTAGES,1);
00419 for (size_t i=0; i<outSTAGES.size(); ++i)
00420 {
00421 int s = outSTAGES[i];
00422 if (s==-1) { for (int j=0; j<nSTAGES; ++j) DoOutSTAGE[j]=0; break; }
00423 if (s<1 || s>nSTAGES) throw new Fatal(_("InputData::ReadMainFile: Output stage (%d) is invalid. It must be inside [1,%d]"),s,nSTAGES);
00424 DoOutSTAGE[s-1] = 1;
00425 }
00426
00427
00428 if (nDIV.size()!=static_cast<size_t>(nSTAGES))
00429 {
00430 if (nDIV.size()==0) { nDIV.resize(1); nDIV[0]=10; }
00431 else if (nDIV.size()==1) nDIV.resize(nSTAGES, nDIV[0]);
00432 else
00433 throw new Fatal(_("InputData::ReadMainFile: < SOLVER NDIV > The number (%d) of nDIV's must correspond the number of stages (%d). For example: nSTAGES=2, nDIV={40,40}"),
00434 nDIV.size(), nSTAGES);
00435 }
00436
00437
00438 if (dTIME.size()!=static_cast<size_t>(nSTAGES))
00439 {
00440 if (dTIME.size()==0) { dTIME.resize(1); dTIME[0]=-1; }
00441 else if (dTIME.size()==1) dTIME.resize(nSTAGES, dTIME[0]);
00442 else
00443 throw new Fatal(_("InputData::ReadMainFile: < SOLVER DTIME > The number (%d) of dTIME's must correspond the number of stages (%d). For example: nSTAGES=2, dTIME={40,40}"),
00444 dTIME.size(), nSTAGES);
00445 }
00446
00447 }
00448
00449 inline void InputData::WriteMainFile(String const & MainFilename, bool DoOverwrite)
00450 {
00451
00452 if (!DoOverwrite)
00453 if (FileParser::CheckForFile(MainFilename))
00454 throw new Warning(_("File < %s > exists"), MainFilename.c_str());
00455
00456
00457 std::ofstream OF(MainFilename.GetSTL().c_str(), std::ios::out);
00458
00459
00460 LineParser LP(projDESC);
00461 Array<String> desc_lines;
00462 LP.SeparatedLine("#", desc_lines);
00463
00464
00465 Array<String> tmp_fnNODE; LP.Set(fnNODE); LP.SeparatedLine(fullPATH, tmp_fnNODE);
00466 Array<String> tmp_fnFACE; LP.Set(fnFACE); LP.SeparatedLine(fullPATH, tmp_fnFACE);
00467 Array<String> tmp_fnELE; LP.Set(fnELE); LP.SeparatedLine(fullPATH, tmp_fnELE);
00468 Array<String> tmp_fnNBC; LP.Set(fnNBC); LP.SeparatedLine(fullPATH, tmp_fnNBC);
00469 Array<String> tmp_fnFBC; LP.Set(fnFBC); LP.SeparatedLine(fullPATH, tmp_fnFBC);
00470 Array<String> tmp_fnATT; LP.Set(fnATT); LP.SeparatedLine(fullPATH, tmp_fnATT);
00471 Array<String> tmp_fnINI; LP.Set(fnINI); LP.SeparatedLine(fullPATH, tmp_fnINI);
00472
00473
00474 OF << "################################### " <<projNAME<< ".main\n";
00475 OF << "\n";
00476 OF << "# project\n";
00477 OF << "PROJECT NAME " <<projNAME<< " # .main\n"; for (size_t i=0; i<desc_lines.size(); ++i)
00478 OF << "PROJECT DESC " <<desc_lines[i]<< "\n";
00479 OF << "\n";
00480 OF << "# filenames\n";
00481 OF << "FILE NODE " <<tmp_fnNODE[tmp_fnNODE.size()-1]<< " # .node\n";
00482 OF << "FILE FACE " <<tmp_fnFACE[tmp_fnFACE.size()-1]<< " # .face\n";
00483 OF << "FILE ELE " <<tmp_fnELE [tmp_fnELE .size()-1]<< " # .ele\n";
00484 OF << "FILE NBC " <<tmp_fnNBC [tmp_fnNBC .size()-1]<< " # .nbc\n";
00485 OF << "FILE FBC " <<tmp_fnFBC [tmp_fnFBC .size()-1]<< " # .fbc\n";
00486 OF << "FILE ATT " <<tmp_fnATT [tmp_fnATT .size()-1]<< " # .att\n";
00487 OF << "FILE INI " <<tmp_fnINI [tmp_fnINI .size()-1]<< " # .ini\n";
00488 OF << "\n";
00489 OF << "# solver\n";
00490 OF << "SOLVER NDIV " << " "; for (size_t i=0; i< nDIV.size(); ++i) { OF<< nDIV[i]<<" "; } OF<<" # number of divisions of stage increment\n";
00491 OF << "SOLVER DTIME " << " "; for (size_t i=0; i< nDIV.size(); ++i) { OF<< dTIME[i]<<" "; } OF<<" # time increments of stage increment\n";
00492 if (solNAME.size()>0)
00493 { OF << "SOLVER SCHEME " <<solNAME<< " "; for (size_t i=0; i< solCTES.size(); ++i) { OF<< solCTES[i]<<" "; } OF<<"\n"; }
00494 OF << "\n";
00495 OF << "# output\n";
00496 OF << "OUTPUT NODES "; for (size_t i=0; i<outNODES.size(); ++i) { OF<<outNODES[i]<<" "; } OF<<"\n";
00497 OF << "OUTPUT ELEMS "; for (size_t i=0; i<outELEMS.size(); ++i) { OF<<outELEMS[i]<<" "; } OF<<"\n";
00498 }
00499
00500 inline String InputData::InitialMessage()
00501 {
00502 std::ostringstream oss;
00503 oss << _("MechSys/FEM, Copyright (C) 2005 Dorival M. Pedroso, Raul D. Durand\n");
00504 oss << _(" MechSys/FEM comes with ABSOLUTELY NO WARRANTY.\n");
00505 oss << _(" This is free software, and you are welcome\n");
00506 oss << _(" to redistribute it under certain conditions.\n");
00507 return oss.str();
00508 }
00509
00510 inline String InputData::HelpMessage()
00511 {
00512 std::ostringstream oss;
00513 oss << InitialMessage() << std::endl;
00514 oss << _("Command line options:\n");
00515 oss << _(" $ ./fem => GUI session \n");
00516 oss << _(" $ ./fem -h => shows help message and exit \n");
00517 oss << _(" $ ./fem --help => shows help message and exit \n");
00518 oss << _(" $ ./fem projname.main => GUI session using projname \n");
00519 oss << _(" $ ./fem --nogui projname.main => Console session using projname \n");
00520 oss << _(" $ ./fem --silent projname.main => Silent console session using projname \n");
00521 oss << std::endl;
00522 return oss.str();
00523 }
00524
00525 };
00526
00527 #endif // MECHSYS_FEM_INPUTDATA_H
00528
00529