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_FILESDATA_H
00023 #define MECHSYS_FEM_FILESDATA_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 <iomanip>
00034 #include <fstream>
00035
00036 #include "util/array.h"
00037 #include "util/string.h"
00038 #include "util/numstreams.h"
00039 #include "fem/inputdata.h"
00040 #include "util/fileparser.h"
00041 #include "util/lineparser.h"
00042 #include "util/exception.h"
00043
00044 using Util::_8s;
00045 using Util::_6;
00046 using Util::_a;
00047
00048 namespace FEM
00049 {
00050
00052
00056 class FilesData
00057 {
00058 public:
00059
00060 struct Node;
00061 struct Face;
00062 struct Element;
00063 struct BryCond;
00064 struct Attribute;
00065 struct Stage;
00066
00067 void ReadNodes (FEM::InputData const & ID);
00068 void ReadFaces (FEM::InputData const & ID);
00069 void ReadElements (FEM::InputData const & ID);
00070 void ReadNodeBry (FEM::InputData const & ID);
00071 void ReadFaceBry (FEM::InputData const & ID);
00072 void ReadAttributes (FEM::InputData const & ID);
00073 void ReadInitialValues (FEM::InputData const & ID);
00074 void ReadAllFiles (FEM::InputData const & ID)
00075 {
00076 ReadNodes (ID);
00077 ReadFaces (ID);
00078 ReadElements (ID);
00079 ReadNodeBry (ID);
00080 ReadFaceBry (ID);
00081 ReadAttributes (ID);
00082 ReadInitialValues (ID);
00083 }
00084
00085 void WriteNodes (FEM::InputData const & ID, bool DoOverwrite=false);
00086 void WriteFaces (FEM::InputData const & ID, bool DoOverwrite=false);
00087 void WriteElements (FEM::InputData const & ID, bool DoOverwrite=false);
00088 void WriteNodeBry (FEM::InputData const & ID, bool DoOverwrite=false);
00089 void WriteFaceBry (FEM::InputData const & ID, bool DoOverwrite=false);
00090 void WriteAttributes (FEM::InputData const & ID, bool DoOverwrite=false);
00091 void WriteInitialValues (FEM::InputData const & ID, bool DoOverwrite=false);
00092 void WriteAllFiles (FEM::InputData const & ID, bool DoOverwrite=false)
00093 {
00094 WriteNodes (ID, DoOverwrite);
00095 WriteFaces (ID, DoOverwrite);
00096 WriteElements (ID, DoOverwrite);
00097 WriteNodeBry (ID, DoOverwrite);
00098 WriteFaceBry (ID, DoOverwrite);
00099 WriteAttributes (ID, DoOverwrite);
00100 WriteInitialValues (ID, DoOverwrite);
00101 }
00102 void WriteNodes (String const & fnNODE, bool DoOverwrite=false);
00103 void WriteFaces (String const & fnFACE, bool DoOverwrite=false);
00104 void WriteElements (String const & fnELE, bool DoOverwrite=false);
00105 void WriteNodeBry (String const & fnNBC, bool DoOverwrite=false);
00106 void WriteFaceBry (String const & fnFBC, bool DoOverwrite=false);
00107 void WriteAttributes (String const & fnATT, bool DoOverwrite=false);
00108 void WriteInitialValues (String const & fnINI, bool DoOverwrite=false);
00109
00110 void SetupDependentValues()
00111 {
00112 _fill_nodes_idx_info ();
00113 _fill_faces_idx_info ();
00114 _fill_elements_idx_info();
00115 }
00116 public:
00117
00118 Array<FilesData::Node> Nodes;
00119 Array<FilesData::Face> Faces;
00120 Array<FilesData::Element> Elements;
00121 Array<FilesData::Element> EmbElements;
00122 Array<FilesData::Stage> Stages;
00123 private:
00124
00125 void _fill_nodes_idx_info ();
00126 void _fill_faces_idx_info ();
00127 void _fill_elements_idx_info();
00128 };
00129
00130
00131
00132 struct FilesData::Node
00133 {
00134 int Num;
00135 REAL X;
00136 REAL Y;
00137 REAL Z;
00138 int BryMark;
00139 int IdxBry;
00140
00141 };
00142
00143 struct FilesData::Face
00144 {
00145 int Num;
00146 Array<int> Connects;
00147 int BryMark;
00148 int OwnerElement;
00149 int IdxBry;
00150
00151 };
00152
00153 struct FilesData::Element
00154 {
00155 int Num;
00156 Array<int> Connects;
00157 int AttMark;
00158 int IdxAtt;
00159 Array<Array<REAL> > IniVals;
00160 };
00161
00162 struct FilesData::BryCond
00163 {
00164 int BryMark;
00165 Array<String> Names;
00166 Array<REAL> Values;
00167 };
00168
00169 struct FilesData::Attribute
00170 {
00171 int AttMark;
00172 String EleName;
00173 bool IsActive;
00174 String ModelName;
00175 String MatFilename;
00176 Array<REAL> Properties;
00177 Array<REAL> ModelPrms;
00178 };
00179
00180 struct FilesData::Stage
00181 {
00182 Array<BryCond> NodeBrys;
00183 Array<BryCond> FaceBrys;
00184 Array<Attribute> Attributes;
00185 };
00186
00187
00188
00189
00190 std::ostream & operator<< (std::ostream & os, FilesData::Node const & node);
00191 std::ostream & operator<< (std::ostream & os, Array<FilesData::Node> const & nodes);
00192
00193 std::ostream & operator<< (std::ostream & os, FilesData::Element const & ele);
00194 std::ostream & operator<< (std::ostream & os, Array<FilesData::Element> const & eles);
00195
00196 std::ostream & operator<< (std::ostream & os, FilesData::Face const & face);
00197 std::ostream & operator<< (std::ostream & os, Array<FilesData::Face> const & faces);
00198
00199 std::ostream & operator<< (std::ostream & os, FilesData::BryCond const & BC);
00200 std::ostream & operator<< (std::ostream & os, Array<FilesData::BryCond> const & BCs);
00201
00202 std::ostream & operator<< (std::ostream & os, FilesData::Attribute const & Att);
00203 std::ostream & operator<< (std::ostream & os, Array<FilesData::Attribute> const & Atts);
00204
00205 std::ostream & operator<< (std::ostream & os, Array<FilesData::Stage> const & S);
00206
00207
00209
00210 bool operator== (FilesData::BryCond const & a, int const & b)
00211 {
00212 return a.BryMark == b;
00213 }
00214
00215 bool operator== (FilesData::Attribute const & a, int const & b)
00216 {
00217 return a.AttMark == b;
00218 }
00219
00220 inline void FilesData::ReadNodes(FEM::InputData const & ID)
00221 {
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 FileParser FP(ID.fnNODE);
00241
00242
00243 int n_nodes;
00244 FP.ReadNextValue(n_nodes);
00245
00246
00247 Nodes.resize(n_nodes);
00248 for (int i=0; i<n_nodes; ++i)
00249 {
00250
00251 FP.JumpCommentsOrBlanks();
00252 String str_line = FP.GetCurrentLine(); FP.Advance();
00253
00254
00255 LineParser LP(str_line);
00256 LP >> Nodes[i].Num >> Nodes[i].X >> Nodes[i].Y >> Nodes[i].Z;
00257 if (!(LP >> Nodes[i].BryMark)) Nodes[i].BryMark=0;
00258
00259
00260 Nodes[i].X *= ID.CoordsMult;
00261 Nodes[i].Y *= ID.CoordsMult;
00262 Nodes[i].Z *= ID.CoordsMult;
00263 }
00264 #ifdef DO_DEBUG // {{{
00265 std::cout << "FilesData::ReadNodes: <" << n_nodes << "> nodes read" << std::endl;
00266 #endif // }}}
00267 }
00268
00269 inline void FilesData::ReadFaces(FEM::InputData const & ID)
00270 {
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 FileParser FP(ID.fnFACE);
00281
00282
00283 int n_faces;
00284 FP.ReadNextValue(n_faces);
00285
00286
00287 Faces.resize(n_faces);
00288 for (int i=0; i<n_faces; ++i)
00289 {
00290
00291 FP.JumpCommentsOrBlanks();
00292 String str_line = FP.GetCurrentLine(); FP.Advance();
00293
00294
00295 LineParser LP(str_line);
00296 int n_connect_nodes;
00297 LP >> Faces[i].Num >> n_connect_nodes;
00298 Faces[i].Connects.resize(n_connect_nodes);
00299 for (int j=0; j<n_connect_nodes; ++j)
00300 {
00301 if (!(LP>>Faces[i].Connects[j])) throw new Fatal(_("FilesData::ReadFaces: <.face> Face # (%d) must have (%d) nodes connected"),i,j);
00302 }
00303 if (!(LP>>Faces[i].BryMark)) throw new Fatal(_("FilesData::ReadFaces: <.face> Face # (%d) must have a column for BryMark") ,i);
00304 if (!(LP>>Faces[i].OwnerElement)) throw new Fatal(_("FilesData::ReadFaces: <.face> Face # (%d) must have a column for OwnerElement"),i);
00305 }
00306 #ifdef DO_DEBUG // {{{
00307 std::cout << "FilesData::ReadFaces: <" << n_faces << "> faces read" << std::endl;
00308 #endif // }}}
00309 }
00310
00311 inline void FilesData::ReadElements(FEM::InputData const & ID)
00312 {
00313
00314
00315
00316
00317
00318
00319
00320
00321 FileParser FP(ID.fnELE);
00322
00323
00324 int n_elements;
00325 FP.ReadNextValue(n_elements);
00326
00327
00328 Elements.resize(n_elements);
00329 for (int i=0; i<n_elements; ++i)
00330 {
00331
00332 FP.JumpCommentsOrBlanks();
00333 String str_line = FP.GetCurrentLine(); FP.Advance();
00334
00335
00336 LineParser LP(str_line);
00337 int n_connect_nodes;
00338 LP >> Elements[i].Num >> n_connect_nodes;
00339 Elements[i].Connects.resize(n_connect_nodes);
00340 for (int j=0; j<n_connect_nodes; ++j)
00341 {
00342 LP >> Elements[i].Connects[j];
00343 }
00344 LP >> Elements[i].AttMark;
00345 }
00346
00347 #ifdef DO_DEBUG // {{{
00348 std::cout << "FilesData::ReadElements: <" << n_elements << "> elements read" << std::endl;
00349 #endif // }}}
00350
00351
00352 int n_emb_elements;
00353 bool has_embeddeds = false;
00354 try {
00355 FP.ReadNextValue(n_emb_elements);
00356 has_embeddeds = true;
00357 }
00358 catch (Exception * e)
00359 {
00360 delete e;
00361 }
00362
00363 if (has_embeddeds)
00364 {
00365
00366 EmbElements.resize(n_emb_elements);
00367 for (int i=0; i<n_emb_elements; ++i)
00368 {
00369
00370 FP.JumpCommentsOrBlanks();
00371 String str_line = FP.GetCurrentLine(); FP.Advance();
00372
00373
00374 LineParser LP(str_line);
00375 int n_connect_nodes;
00376 LP >> EmbElements[i].Num >> n_connect_nodes;
00377 EmbElements[i].Connects.resize(n_connect_nodes);
00378 for (int j=0; j<n_connect_nodes; ++j)
00379 {
00380 LP >> EmbElements[i].Connects[j];
00381 }
00382 LP >> EmbElements[i].AttMark;
00383 }
00384 }
00385
00386 }
00387
00388 inline void FilesData::ReadNodeBry(FEM::InputData const & ID)
00389 {
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 FileParser FP(ID.fnNBC);
00408
00409
00410 int n_stages;
00411 FP.ReadNextValue(n_stages);
00412
00413
00414 int n_bry_marks;
00415 FP.ReadNextValue(n_bry_marks);
00416
00417
00418 if (Stages.size()!=0)
00419 {
00420 if (Stages.size()!=static_cast<size_t>(n_stages))
00421 throw new Fatal(_("FilesData::ReadNodeBry: number of stages must be equal to (%d)"), Stages.size());
00422 }
00423 else
00424 Stages.resize(n_stages);
00425
00426
00427 if (n_stages<ID.nSTAGES)
00428 throw new Fatal(_("FilesData::ReadNodeBry: number of stages must be greater than or equal to (NSTAGES=%d)"), ID.nSTAGES);
00429
00430
00431 if (n_bry_marks==0) return;
00432
00433
00434 for (int i=0; i<n_stages; ++i)
00435 {
00436
00437 int i_stage_p1;
00438 FP.ReadNextValue(i_stage_p1);
00439
00440
00441 Array<BryCond> & BCs = Stages[i].NodeBrys;
00442 BCs.resize(n_bry_marks);
00443
00444
00445 for (int j=0; j<n_bry_marks; ++j)
00446 {
00447
00448 FP.JumpCommentsOrBlanks();
00449 String str_line = FP.GetCurrentLine(); FP.Advance();
00450
00451
00452 LineParser LP(str_line);
00453 LP.ReplaceAllChars('=',' ');
00454
00455
00456 LP >> BCs[j].BryMark;
00457 String lvalue;
00458 REAL rvalue;
00459 while (LP >> lvalue)
00460 {
00461 if (!(std::isalpha(lvalue[0])))
00462 throw new Fatal(_("FilesData::ReadNodeBry: (.nbc) file format invalid: nBrys=%d Stage=%d BryMark=%d"), n_bry_marks, i+1, BCs[j].BryMark);
00463 if (!(LP >> rvalue))
00464 throw new Fatal(_("FilesData::ReadNodeBry: (.nbc) file format invalid: nBrys=%d Stage=%d BryMark=%d"), n_bry_marks, i+1, BCs[j].BryMark);
00465 BCs[j].Names.push_back(lvalue);
00466 BCs[j].Values.push_back(rvalue);
00467 }
00468 }
00469 }
00470
00471 #ifdef DO_DEBUG // {{{
00472 std::cout << "FilesData::ReadNodeBry: <" << n_bry_marks << "> boundary marks read" << std::endl;
00473 #endif // }}}
00474 }
00475
00476 inline void FilesData::ReadFaceBry(FEM::InputData const & ID)
00477 {
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 FileParser FP(ID.fnFBC);
00496
00497
00498 int n_stages;
00499 FP.ReadNextValue(n_stages);
00500
00501
00502 int n_bry_marks;
00503 FP.ReadNextValue(n_bry_marks);
00504
00505
00506 if (Stages.size()!=0)
00507 {
00508 if (Stages.size()!=static_cast<size_t>(n_stages))
00509 throw new Fatal(_("FilesData::ReadFaceBry: number of stages must be equal to (%d)"), Stages.size());
00510 }
00511 else
00512 Stages.resize(n_stages);
00513
00514
00515 if (n_stages<ID.nSTAGES)
00516 throw new Fatal(_("FilesData::ReadFaceBry: number of stages must be greater than or equal to (NSTAGES=%d)"), ID.nSTAGES);
00517
00518
00519 if (n_bry_marks==0) return;
00520
00521
00522 for (int i=0; i<n_stages; ++i)
00523 {
00524
00525 int i_stage_p1;
00526 FP.ReadNextValue(i_stage_p1);
00527
00528
00529 Array<BryCond> & BCs = Stages[i].FaceBrys;
00530 BCs.resize(n_bry_marks);
00531
00532
00533 for (int j=0; j<n_bry_marks; ++j)
00534 {
00535
00536 FP.JumpCommentsOrBlanks();
00537 String str_line = FP.GetCurrentLine(); FP.Advance();
00538
00539
00540 LineParser LP(str_line);
00541 LP.ReplaceAllChars('=',' ');
00542
00543
00544 LP >> BCs[j].BryMark;
00545 String lvalue;
00546 REAL rvalue;
00547 while (LP >> lvalue)
00548 {
00549 if (!(std::isalpha(lvalue[0])))
00550 throw new Fatal(_("FilesData::ReadFaceBry: Invalid name (not alpha) for DOF key name. Stage=%d, BryMark=%d"), i+1, BCs[j].BryMark);
00551 if (!(LP >> rvalue))
00552 throw new Fatal(_("FilesData::ReadFaceBry: Could not read rvalue for Stage=%d and BryMark=%d"), i+1, BCs[j].BryMark);
00553 BCs[j].Names.push_back(lvalue);
00554 BCs[j].Values.push_back(rvalue);
00555 }
00556 }
00557 }
00558 #ifdef DO_DEBUG // {{{
00559 std::cout << "FilesData::ReadFaceBry: <" << n_bry_marks << "> boundary marks read" << std::endl;
00560 #endif // }}}
00561 }
00562
00563 inline void FilesData::ReadAttributes(FEM::InputData const & ID)
00564 {
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581 FileParser FP(ID.fnATT);
00582
00583
00584 int n_stages;
00585 FP.ReadNextValue(n_stages);
00586
00587
00588 int n_att_marks;
00589 FP.ReadNextValue(n_att_marks);
00590
00591
00592 if (Stages.size()!=0)
00593 {
00594 if (Stages.size()!=static_cast<size_t>(n_stages))
00595 throw new Fatal(_("FilesData::ReadAttributes: number of stages must be equal to (%d)"), Stages.size());
00596 }
00597 else
00598 Stages.resize(n_stages);
00599
00600
00601 if (n_stages<ID.nSTAGES)
00602 throw new Fatal(_("FilesData::ReadAttributes: number of stages must be greater than or equal to (NSTAGES=%d)"), ID.nSTAGES);
00603
00604
00605 for (int i=0; i<n_stages; ++i)
00606 {
00607
00608 int i_stage_p1;
00609 FP.ReadNextValue(i_stage_p1);
00610
00611
00612 Array<Attribute> & Atts = Stages[i].Attributes;
00613 Atts.resize(n_att_marks);
00614
00615
00616 for (int j=0; j<n_att_marks; ++j)
00617 {
00618
00619 FP.JumpCommentsOrBlanks();
00620 String str_line = FP.GetCurrentLine(); FP.Advance();
00621
00622
00623 LineParser LP(str_line);
00624 String str_active_inactive;
00625 LP >> Atts[j].AttMark >> Atts[j].EleName >> str_active_inactive >> Atts[j].ModelName >> Atts[j].MatFilename;
00626 REAL prop_value;
00627 while (LP>>prop_value) Atts[j].Properties.push_back(prop_value);
00628 if ( str_active_inactive=="true" ) Atts[j].IsActive = true;
00629 else if ( str_active_inactive=="false" ) Atts[j].IsActive = false;
00630 else
00631 throw new Fatal(_("FilesData::ReadAttributes: Active/Inactive word is invalid < %s >"), str_active_inactive.c_str());
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 std::ostringstream oss;
00648 oss << ID.fullPATH << Atts[j].MatFilename;
00649 FileParser matFP(oss.str());
00650 matFP.FindKeyAndFillArray(Atts[j].ModelName, Atts[j].ModelPrms);
00651 }
00652 }
00653 #ifdef DO_DEBUG // {{{
00654 std::cout << "FilesData::ReadAttributes: <" << n_att_marks << "> attribute marks read" << std::endl;
00655 #endif // }}}
00656 }
00657
00658 inline void FilesData::ReadInitialValues(FEM::InputData const & ID)
00659 {
00660
00661
00662
00663
00664
00665
00666
00667
00668 FileParser FP(ID.fnINI);
00669
00670
00671 int n_elements;
00672 FP.ReadNextValue(n_elements);
00673 if (static_cast<size_t>(n_elements)!=Elements.size())
00674 throw new Fatal(_("FilesData::ReadInitialValues: The number of elements inside (.ini) file must be equal to (%d)"),Elements.size());
00675
00676
00677 for (int i=0; i<n_elements; ++i)
00678 {
00679
00680 FP.JumpCommentsOrBlanks();
00681 String str_line = FP.GetCurrentLine(); FP.Advance();
00682
00683
00684 LineParser LP(str_line);
00685 int elem_num;
00686 int n_ini_data;
00687 LP.StructuredLine(elem_num, n_ini_data, Elements[i].IniVals);
00688 }
00689 #ifdef DO_DEBUG // {{{
00690 std::cout << "FilesData::ReadInitialValues: <" << n_elements << "> elements initial values read" << std::endl;
00691 #endif // }}}
00692 }
00693
00694 inline void FilesData::_fill_nodes_idx_info()
00695 {
00696 if (Stages.size()>0)
00697 {
00698
00699 FilesData::Stage const & S = Stages[0];
00700
00701
00702 for (size_t i=0; i<Nodes.size(); ++i)
00703 {
00704
00705 Array<FilesData::BryCond>::const_iterator it;
00706
00707
00708 if (Nodes[i].BryMark==0)
00709 Nodes[i].IdxBry = -1;
00710 else
00711 {
00712
00713 it = std::find(S.NodeBrys.begin(), S.NodeBrys.end(), Nodes[i].BryMark);
00714 if (it==S.NodeBrys.end())
00715 throw new Fatal(_("FilesData::_fill_nodes_idx_info: Could not find NodeBryMark (%d) inside .nbc file"), Nodes[i].BryMark);
00716 Nodes[i].IdxBry = it-S.NodeBrys.begin();
00717 }
00718 }
00719 }
00720 else
00721 throw new Fatal(_("FilesData::_fill_nodes_idx_info: Stages.size() is not greater than 0"));
00722 }
00723
00724 inline void FilesData::_fill_faces_idx_info()
00725 {
00726 if (Stages.size()>0)
00727 {
00728
00729 FilesData::Stage const & S = Stages[0];
00730
00731
00732 for (size_t i=0; i<Faces.size(); ++i)
00733 {
00734
00735 Array<FilesData::BryCond>::const_iterator it;
00736
00737
00738 if (Faces[i].BryMark==0)
00739 Faces[i].IdxBry = -1;
00740 else
00741 {
00742
00743 it = std::find(S.FaceBrys.begin(), S.FaceBrys.end(), Faces[i].BryMark);
00744 if (it==S.FaceBrys.end())
00745 throw new Fatal(_("FilesData::_fill_faces_idx_info: Could not find FaceBryMark (%d) .fbc file"), Faces[i].BryMark);
00746 Faces[i].IdxBry = it-S.FaceBrys.begin();
00747 }
00748 }
00749 }
00750 else
00751 throw new Fatal(_("FilesData::_fill_faces_idx_info: Stages.size() is not greater than 0"));
00752 }
00753
00754 inline void FilesData::_fill_elements_idx_info()
00755 {
00756 if (Stages.size()>0)
00757 {
00758
00759 FilesData::Stage const & S = Stages[0];
00760
00761
00762 for (size_t i=0; i<Elements.size(); ++i)
00763 {
00764
00765 Array<FilesData::Attribute>::const_iterator it;
00766
00767
00768 it = std::find(S.Attributes.begin(), S.Attributes.end(), Elements[i].AttMark);
00769 if (it==S.Attributes.end())
00770 throw new Fatal(_("FilesData::_fill_elements_idx_info: Could not find ElementAttMark (%d) inside .att file"), Elements[i].AttMark);
00771
00772
00773 Elements[i].IdxAtt = it-S.Attributes.begin();
00774 }
00775
00776
00777 for (size_t i=0; i<EmbElements.size(); ++i)
00778 {
00779
00780 Array<FilesData::Attribute>::const_iterator it;
00781
00782
00783 it = std::find(S.Attributes.begin(), S.Attributes.end(), EmbElements[i].AttMark);
00784 if (it==S.Attributes.end())
00785 throw new Fatal(_("FilesData::_fill_elements_idx_info: Could not find AttMark(.ele)="), EmbElements[i].AttMark, _(" inside Stages[0].Attributes(.att)"));
00786
00787
00788 EmbElements[i].IdxAtt = it-S.Attributes.begin();
00789 }
00790 }
00791 else
00792 throw new Fatal(_("FilesData::_fill_elements_idx_info: Stages.size() is not greater than 0"));
00793 }
00794
00795
00796
00797 std::ostream & operator<< (std::ostream & os, FilesData::Node const & node)
00798 {
00799 os << _6()<< node.Num << _8s()<< node.X << _8s()<< node.Y << _8s()<< node.Z << _6()<< node.BryMark << _6()<< node.IdxBry << std::endl;
00800 return os;
00801 }
00802
00803 std::ostream & operator<< (std::ostream & os, Array<FilesData::Node> const & nodes)
00804 {
00805 os << _("Number of nodes = ") << nodes.size() << std::endl;
00806 for (size_t i=0; i<nodes.size(); ++i)
00807 os << nodes[i];
00808 return os;
00809 }
00810
00811 std::ostream & operator<< (std::ostream & os, FilesData::Face const & face)
00812 {
00813 os << _6()<< face.Num << _6()<< face.Connects.size();
00814 for (size_t i=0; i<face.Connects.size(); ++i)
00815 os << _6()<< face.Connects[i];
00816 os << _6()<< face.BryMark << _6()<< face.OwnerElement << _6()<< face.IdxBry << std::endl;
00817 return os;
00818 }
00819
00820 std::ostream & operator<< (std::ostream & os, Array<FilesData::Face> const & faces)
00821 {
00822 os << _("Number of faces = ") << faces.size() << std::endl;
00823 for (size_t i=0; i<faces.size(); ++i)
00824 os << faces[i];
00825 return os;
00826 }
00827
00828 std::ostream & operator<< (std::ostream & os, FilesData::Element const & ele)
00829 {
00830 os << _6()<< ele.Num << _6()<< ele.Connects.size();
00831 for (size_t i=0; i<ele.Connects.size(); ++i)
00832 os << _6()<< ele.Connects[i];
00833 os << _6()<< ele.AttMark << _6()<< ele.IdxAtt;
00834
00835 for (size_t j=0; j<ele.IniVals.size(); ++j)
00836 {
00837 os << " { ";
00838 for (size_t k=0; k<ele.IniVals[j].size(); k++)
00839 {
00840 os << ele.IniVals[j][k] << " ";
00841 }
00842 os << "} ";
00843 }
00844 os << std::endl;
00845 return os;
00846 }
00847
00848 std::ostream & operator<< (std::ostream & os, Array<FilesData::Element> const & eles)
00849 {
00850 os << _("Number of elements = ") << eles.size() << std::endl;
00851 for (size_t i=0; i<eles.size(); ++i)
00852 os << eles[i];
00853 return os;
00854 }
00855
00856 std::ostream & operator<< (std::ostream & os, FilesData::BryCond const & BC)
00857 {
00858 os << _6()<< BC.BryMark << " ";
00859 for (size_t i=0; i<BC.Names.size(); ++i)
00860 {
00861 os << BC.Names[i] << "=" << BC.Values[i];
00862 if (i!=BC.Names.size()-1) os << " ";
00863 }
00864 os << std::endl;
00865 return os;
00866 }
00867
00868 std::ostream & operator<< (std::ostream & os, Array<FilesData::BryCond> const & BCs)
00869 {
00870 os << _("Number of boundary conditions = ") << BCs.size() << std::endl;
00871 for (size_t i=0; i<BCs.size(); ++i)
00872 os << " " << BCs[i];
00873 return os;
00874 }
00875
00876 std::ostream & operator<< (std::ostream & os, FilesData::Attribute const & Att)
00877 {
00878 os << _6()<< Att.AttMark << Att.EleName << _a() << Att.IsActive << Att.ModelName << Att.MatFilename;
00879
00880 std::cout << " { ";
00881 for (size_t i=0; i<Att.Properties.size(); ++i)
00882 os << _8s()<< Att.Properties[i];
00883
00884 std::cout << " } ";
00885 for (size_t i=0; i<Att.ModelPrms.size(); ++i)
00886 os << _8s()<< Att.ModelPrms[i];
00887 os << std::endl;
00888 return os;
00889 }
00890
00891 std::ostream & operator<< (std::ostream & os, Array<FilesData::Attribute> const & Atts)
00892 {
00893 os << _("Number of attributes = ") << Atts.size() << std::endl;
00894 for (size_t i=0; i<Atts.size(); ++i)
00895 os << " " << Atts[i];
00896 return os;
00897 }
00898
00899 std::ostream & operator<< (std::ostream & os, Array<FilesData::Stage> const & S)
00900 {
00901 os << _("Number of stages = ") << S.size() << std::endl;
00902
00903
00904 os << _(" Node boundary conditions:\n");
00905 for (size_t i=0; i<S.size(); ++i)
00906 os << " " << S[i].NodeBrys;
00907
00908
00909 os << _(" Face boundary conditions:\n");
00910 for (size_t i=0; i<S.size(); ++i)
00911 os << " " << S[i].FaceBrys;
00912
00913
00914 os << _(" Element attributes:\n");
00915 for (size_t i=0; i<S.size(); ++i)
00916 os << " " << S[i].Attributes;
00917
00918 return os;
00919 }
00920
00921
00922
00923 inline void FilesData::WriteNodes(FEM::InputData const & ID, bool DoOverwrite)
00924 {
00925 WriteNodes(ID.fnNODE, DoOverwrite);
00926 }
00927
00928 inline void FilesData::WriteNodes(String const & fnNODE, bool DoOverwrite)
00929 {
00930
00931 if (!DoOverwrite)
00932 if (FileParser::CheckForFile(fnNODE))
00933 throw new Warning(_("File < %s > exists"), fnNODE.c_str());
00934
00935
00936 std::ofstream OF(fnNODE.GetSTL().c_str(), std::ios::out);
00937
00938
00939 OF << "################################################### .node\n";
00940 OF << Nodes.size() << " # number of nodes\n";
00941 for (size_t i=0; i<Nodes.size(); ++i)
00942 {
00943 OF << Nodes[i].Num << _8s()<< Nodes[i].X << _8s()<< Nodes[i].Y << _8s()<< Nodes[i].Z;
00944 if (Nodes[i].BryMark!=0) OF << " " << Nodes[i].BryMark;
00945 OF << std::endl;
00946 }
00947
00948
00949 OF.close();
00950 }
00951
00952 inline void FilesData::WriteFaces(FEM::InputData const & ID, bool DoOverwrite)
00953 {
00954 WriteFaces(ID.fnFACE, DoOverwrite);
00955 }
00956
00957 inline void FilesData::WriteFaces(String const & fnFACE, bool DoOverwrite)
00958 {
00959
00960 if (!DoOverwrite)
00961 if (FileParser::CheckForFile(fnFACE))
00962 throw new Warning(_("File < %s > exists"), fnFACE.c_str());
00963
00964
00965 std::ofstream OF(fnFACE.GetSTL().c_str(), std::ios::out);
00966
00967
00968 OF << "################################################### .face\n";
00969 OF << Faces.size() << " # number of faces\n";
00970 for (size_t i=0; i<Faces.size(); ++i)
00971 {
00972 OF << Faces[i].Num << " " << Faces[i].Connects.size() << " ";
00973 for (size_t j=0; j<Faces[i].Connects.size(); ++j)
00974 OF << Faces[i].Connects[j] << " ";
00975 OF << " " << Faces[i].BryMark << " " << Faces[i].OwnerElement << std::endl;
00976 }
00977
00978
00979 OF.close();
00980 }
00981
00982 inline void FilesData::WriteElements(FEM::InputData const & ID, bool DoOverwrite)
00983 {
00984 WriteElements(ID.fnELE, DoOverwrite);
00985 }
00986
00987 inline void FilesData::WriteElements(String const & fnELE, bool DoOverwrite)
00988 {
00989
00990 if (!DoOverwrite)
00991 if (FileParser::CheckForFile(fnELE))
00992 throw new Warning(_("File < %s > exists"), fnELE.c_str());
00993
00994
00995 std::ofstream OF(fnELE.GetSTL().c_str(), std::ios::out);
00996
00997
00998 OF << "################################################### .ele\n";
00999 OF << Elements.size() << " # number of elements\n";
01000 for (size_t i=0; i<Elements.size(); ++i)
01001 {
01002 OF << Elements[i].Num << " " << Elements[i].Connects.size() << " ";
01003 for (size_t j=0; j<Elements[i].Connects.size(); ++j)
01004 OF << Elements[i].Connects[j] << " ";
01005 OF << " " << Elements[i].AttMark << std::endl;
01006 }
01007
01008
01009 OF.close();
01010 }
01011
01012 inline void FilesData::WriteNodeBry(FEM::InputData const & ID, bool DoOverwrite)
01013 {
01014 WriteNodeBry(ID.fnNBC, DoOverwrite);
01015 }
01016
01017 inline void FilesData::WriteNodeBry(String const & fnNBC, bool DoOverwrite)
01018 {
01019 if (Stages.size()>0)
01020 {
01021
01022 if (!DoOverwrite)
01023 if (FileParser::CheckForFile(fnNBC))
01024 throw new Warning(_("File < %s > exists"), fnNBC.c_str());
01025
01026
01027 std::ofstream OF(fnNBC.GetSTL().c_str(), std::ios::out);
01028
01029
01030 OF << "################################################### .nbc\n";
01031 OF << Stages.size() << " # number of stages\n";
01032 OF << Stages[0].NodeBrys.size() << " # number of boundary marks\n";
01033 OF << std::endl;
01034 for (size_t i=0; i<Stages.size(); ++i)
01035 {
01036 OF << i+1 << " # stage\n";
01037 Array<BryCond> & BCs = Stages[i].NodeBrys;
01038 for (size_t j=0; j<BCs.size(); ++j)
01039 {
01040 OF << BCs[j].BryMark << " ";
01041 for (size_t k=0; k<BCs[j].Names.size(); ++k)
01042 OF << BCs[j].Names[k] << "=" << BCs[j].Values[k] << " ";
01043 OF << std::endl;
01044 }
01045 OF << std::endl;
01046 }
01047
01048
01049 OF.close();
01050 }
01051 else
01052 throw new Fatal(_("FilesData::WriteNodeBry: Stages.size() is not greater than 0"));
01053 }
01054
01055 inline void FilesData::WriteFaceBry(FEM::InputData const & ID, bool DoOverwrite)
01056 {
01057 WriteFaceBry(ID.fnFBC, DoOverwrite);
01058 }
01059
01060 inline void FilesData::WriteFaceBry(String const & fnFBC, bool DoOverwrite)
01061 {
01062 if (Stages.size()>0)
01063 {
01064
01065 if (!DoOverwrite)
01066 if (FileParser::CheckForFile(fnFBC))
01067 throw new Warning(_("File < %s > exists"), fnFBC.c_str());
01068
01069
01070 std::ofstream OF(fnFBC.GetSTL().c_str(), std::ios::out);
01071
01072
01073 OF << "################################################### .fbc\n";
01074 OF << Stages.size() << " # number of stages\n";
01075 OF << Stages[0].FaceBrys.size() << " # number of boundary marks\n";
01076 OF << std::endl;
01077 for (size_t i=0; i<Stages.size(); ++i)
01078 {
01079 OF << i+1 << " # stage\n";
01080 Array<BryCond> & BCs = Stages[i].FaceBrys;
01081 for (size_t j=0; j<BCs.size(); ++j)
01082 {
01083 OF << BCs[j].BryMark << " ";
01084 for (size_t k=0; k<BCs[j].Names.size(); ++k)
01085 OF << BCs[j].Names[k] << "=" << BCs[j].Values[k] << " ";
01086 OF << std::endl;
01087 }
01088 OF << std::endl;
01089 }
01090
01091
01092 OF.close();
01093 }
01094 else
01095 throw new Fatal(_("FilesData::WriteFaceBry: Stages.size() is not greater than 0"));
01096 }
01097
01098 inline void FilesData::WriteAttributes(FEM::InputData const & ID, bool DoOverwrite)
01099 {
01100 WriteAttributes(ID.fnATT, DoOverwrite);
01101 }
01102
01103 inline void FilesData::WriteAttributes(String const & fnATT, bool DoOverwrite)
01104 {
01105 if (Stages.size()>0)
01106 {
01107
01108 if (!DoOverwrite)
01109 if (FileParser::CheckForFile(fnATT))
01110 throw new Warning(_("File < %s > exists"), fnATT.c_str());
01111
01112
01113 std::ofstream OF(fnATT.GetSTL().c_str(), std::ios::out);
01114
01115
01116 OF << "################################################### .att\n";
01117 OF << Stages.size() << " # number of stages\n";
01118 OF << Stages[0].Attributes.size() << " # number of attributes\n";
01119 OF << std::endl;
01120 for (size_t i=0; i<Stages.size(); ++i)
01121 {
01122 OF << i+1 << " # stage\n";
01123 Array<Attribute> & Atts = Stages[i].Attributes;
01124 for (size_t j=0; j<Atts.size(); ++j)
01125 {
01126 OF << Atts[j].AttMark <<" "<< Atts[j].EleName <<" "<< _a()<<Atts[j].IsActive <<" "<< Atts[j].ModelName <<" "<< Atts[j].MatFilename <<" ";
01127 for (size_t k=0; k<Atts[j].Properties.size(); ++k)
01128 OF << Atts[j].Properties[k] << " ";
01129 OF << std::endl;
01130 }
01131 OF << std::endl;
01132 }
01133
01134
01135 OF.close();
01136 }
01137 else
01138 throw new Fatal(_("FilesData::WriteAttributes: Stages.size() is not greater than 0"));
01139 }
01140
01141 inline void FilesData::WriteInitialValues(FEM::InputData const & ID, bool DoOverwrite)
01142 {
01143 WriteInitialValues(ID.fnINI, DoOverwrite);
01144 }
01145
01146 inline void FilesData::WriteInitialValues(String const & fnINI, bool DoOverwrite)
01147 {
01148
01149 if (!DoOverwrite)
01150 if (FileParser::CheckForFile(fnINI))
01151 throw new Warning(_("File < %s > exists"), fnINI.c_str());
01152
01153
01154 std::ofstream OF(fnINI.GetSTL().c_str(), std::ios::out);
01155
01156
01157 OF << "################################################### .ini\n";
01158 OF << Elements.size() << " # number of elements\n";
01159 for (size_t i=0; i<Elements.size(); ++i)
01160 {
01161 OF << Elements[i].Num << " " << Elements[i].IniVals.size();
01162 for (size_t j=0; j<Elements[i].IniVals.size(); ++j)
01163 {
01164 OF << " { ";
01165 for (size_t k=0; k<Elements[i].IniVals[j].size(); ++k)
01166 OF << Elements[i].IniVals[j][k] << " ";
01167 OF << " } ";
01168 }
01169 OF << std::endl;
01170 }
01171
01172
01173 OF.close();
01174 }
01175
01176 };
01177
01178 #endif // MECHSYS_FEM_FILESDATA_H
01179
01180