Version: 6.3.1

src/Tools/MeshCut/MeshCut_Utils.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2006-2011  EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MeshCut_Utils.hxx"
00021 
00022 #include <iostream>
00023 #include <string>
00024 #include <sstream>
00025 #include <cstdlib>
00026 #include <cstring>
00027 
00028 using namespace std;
00029 using namespace MESHCUT;
00030 
00031 //string pathUsers = (string) "/var/www/XMeshLab/users/";
00032 
00033 bool MESHCUT::estUnTypeMaille(std::string S)
00034 {
00035   if (S == (string) "POI1" || S == (string) "SEG2" || S == (string) "SEG3" || S == (string) "TRIA3" || S
00036       == (string) "TRIA6" || S == (string) "QUAD4" || S == (string) "QUAD8" || S == (string) "QUAD9" || S
00037       == (string) "TETRA4" || S == (string) "TETRA10" || S == (string) "PYRAM5" || S == (string) "PYRAM13" || S
00038       == (string) "PENTA6" || S == (string) "PENTA15" || S == (string) "HEXA8" || S == (string) "HEXA20" || S
00039       == (string) "HEXA27")
00040     return true;
00041   else
00042     return false;
00043 }
00044 
00045 void MESHCUT::ERREUR(const char* msg)
00046 {
00047   cout << endl << "====== ERROR ====== " << msg << endl << endl;
00048   exit(-1);
00049 }
00050 
00051 char* MESHCUT::string2char(std::string str)
00052 {
00053   // créer le buffer pour copier la chaîne
00054   size_t size = str.size() + 1;
00055   char* buffer = new char[size];
00056   // copier la chaîne
00057   strncpy(buffer, str.c_str(), size);
00058 
00059   // libérer la mémoire
00060   //delete [] buffer;
00061 
00062   return buffer;
00063 }
00064 
00065 std::string MESHCUT::int2string(int k)
00066 {
00067   std::stringstream oss;
00068   oss << k;
00069   return oss.str(); //  oss.seekp (ios_base::beg);
00070 }
00071 
00072 float MESHCUT::char2float(const char* ch)
00073 {
00074   return atof(ch);
00075 }
00076 
00077 std::string MESHCUT::float2string(float f)
00078 {
00079   stringstream buf;
00080   buf << fixed << f;
00081   string s = buf.str();
00082   return s;
00083 }
00084 
00085 bool MESHCUT::appartient(std::string e, std::string tableau[], int taille)
00086 {
00087   for (int i = 0; i < taille; i++)
00088     if (tableau[i] == e)
00089       return true;
00090   return false;
00091 }
00092 
00093 float MESHCUT::arrondi(float x)
00094 {
00095   if (x > 0 and x < 1.0e-5)
00096     return 0;
00097   else if (x < 0 and x > -1.0e-5)
00098     return 0;
00099   else
00100     return x;
00101 }
00102 
00103 int MESHCUT::numNoeudPointe(std::string b1, std::string b2, std::string b3)
00104 {
00105   if (b1 == "1" && b2 == "1" && b3 == "2")
00106     return 2;
00107   else if (b1 == "1" && b2 == "2" && b3 == "1")
00108     return 1;
00109   else if (b1 == "1" && b2 == "2" && b3 == "2")
00110     return 2;
00111   else if (b1 == "2" && b2 == "1" && b3 == "1")
00112     return 3;
00113   else if (b1 == "2" && b2 == "1" && b3 == "2")
00114     return 3;
00115   else if (b1 == "2" && b2 == "2" && b3 == "1")
00116     return 1;
00117   else
00118     return -1;
00119 }
00120 
00121 std::string MESHCUT::strip(std::string S)
00122 {
00123   if (S.empty())
00124     return S;
00125   int startIndex = S.find_first_not_of(" ");
00126   int endIndex = S.find_last_not_of(" ");
00127   return S.substr(startIndex, (endIndex - startIndex + 1));
00128 }
00129 
00130 std::string MESHCUT::entierSur10_g(int i)
00131 {
00132   if (i > 999999999)
00133     ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
00134   if (i < 10)
00135     return int2string(i) + (string) "         ";
00136   else if (i < 100)
00137     return int2string(i) + (string) "        ";
00138   else if (i < 1000)
00139     return int2string(i) + (string) "       ";
00140   else if (i < 10000)
00141     return int2string(i) + (string) "      ";
00142   else if (i < 100000)
00143     return int2string(i) + (string) "     ";
00144   else if (i < 1000000)
00145     return int2string(i) + (string) "    ";
00146   else if (i < 10000000)
00147     return int2string(i) + (string) "   ";
00148   else if (i < 100000000)
00149     return int2string(i) + (string) "  ";
00150   else if (i < 1000000000)
00151     return int2string(i) + (string) " ";
00152   else
00153     return int2string(i);
00154 }
00155 
00156 std::string MESHCUT::entierSur10_d(int i)
00157 {
00158   if (i > 999999999)
00159     ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
00160   if (i < 10)
00161     return (string) "         " + int2string(i);
00162   else if (i < 100)
00163     return (string) "        " + int2string(i);
00164   else if (i < 1000)
00165     return (string) "       " + int2string(i);
00166   else if (i < 10000)
00167     return (string) "      " + int2string(i);
00168   else if (i < 100000)
00169     return (string) "     " + int2string(i);
00170   else if (i < 1000000)
00171     return (string) "    " + int2string(i);
00172   else if (i < 10000000)
00173     return (string) "   " + int2string(i);
00174   else if (i < 100000000)
00175     return (string) "  " + int2string(i);
00176   else if (i < 1000000000)
00177     return (string) " " + int2string(i);
00178   else
00179     return int2string(i);
00180 }
00181 
00182 std::string MESHCUT::typeEnsight(std::string type)
00183 {
00184   if (type == (string) "POI1")
00185     return (string) "point";
00186   else if (type == (string) "SEG2")
00187     return (string) "bar2";
00188   else if (type == (string) "SEG3")
00189     return (string) "bar2";// ATTENTION, triche!
00190   else if (type == (string) "TRIA3")
00191     return (string) "tria3";
00192   else if (type == (string) "TRIA6")
00193     return (string) "tria3";// ATTENTION, triche!
00194   else if (type == (string) "QUAD4")
00195     return (string) "quad4";
00196   else if (type == (string) "QUAD8")
00197     return (string) "quad4"; // ATTENTION, triche!
00198   else if (type == (string) "QUAD9")
00199     ERREUR("Type QUAD9 not supported by Ensight");
00200   else if (type == (string) "TETRA4")
00201     return (string) "tetra4";
00202   else if (type == (string) "TETRA10")
00203     return (string) "tetra4"; // ATTENTION, triche!
00204   else if (type == (string) "PYRAM5")
00205     return (string) "pyramid5";
00206   else if (type == (string) "PYRAM13")
00207     return (string) "pyramid5"; // ATTENTION, triche!
00208   else if (type == (string) "PENTA6")
00209     return (string) "penta6";
00210   else if (type == (string) "PENTA15")
00211     return (string) "penta6"; // ATTENTION, triche!
00212   else if (type == (string) "HEXA8")
00213     return (string) "hexa8";
00214   else if (type == (string) "HEXA20")
00215     return (string) "hexa8"; // ATTENTION, triche!
00216   else if (type == (string) "HEXA27")
00217     ERREUR("Type HEXA27 not supported by Ensight");
00218   else
00219     ERREUR("Type of element not accepted (method \"typeEnsight\"");
00220   return (string) "";
00221 }
00222 
00223 int MESHCUT::Nnoeuds(TYPE_MAILLE type)
00224 {
00225   switch (type)
00226   {
00227     case POI1:
00228       {
00229         return 1;
00230         break;
00231       }
00232     case SEG2:
00233       {
00234         return 2;
00235         break;
00236       }
00237     case SEG3:
00238       {
00239         return 3;
00240         break;
00241       }
00242     case TRIA3:
00243       {
00244         return 3;
00245         break;
00246       }
00247     case TRIA6:
00248       {
00249         return 6;
00250         break;
00251       }
00252     case QUAD4:
00253       {
00254         return 4;
00255         break;
00256       }
00257     case QUAD8:
00258       {
00259         return 8;
00260         break;
00261       }
00262       //case QUAD9:                   { return 9; break; }
00263     case TETRA4:
00264       {
00265         return 4;
00266         break;
00267       }
00268     case TETRA10:
00269       {
00270         return 10;
00271         break;
00272       }
00273     case PYRAM5:
00274       {
00275         return 5;
00276         break;
00277       }
00278     case PYRAM13:
00279       {
00280         return 13;
00281         break;
00282       }
00283     case PENTA6:
00284       {
00285         return 6;
00286         break;
00287       }
00288     case PENTA15:
00289       {
00290         return 15;
00291         break;
00292       }
00293     case HEXA8:
00294       {
00295         return 8;
00296         break;
00297       }
00298     case HEXA20:
00299       {
00300         return 20;
00301         break;
00302       }
00303       //case HEXA27:                      { return 27;    break; }
00304     default:
00305       ERREUR("Type of elem not accepted (method Nnoeuds)");
00306   }
00307   return 0;
00308 }
00309 
00310 int MESHCUT::NnoeudsGeom(TYPE_MAILLE type)
00311 {
00312   switch (type)
00313   {
00314     case POI1:
00315       {
00316         return 1;
00317         break;
00318       }
00319     case SEG2:
00320       {
00321         return 2;
00322         break;
00323       }
00324     case SEG3:
00325       {
00326         return 2;
00327         break;
00328       }
00329     case TRIA3:
00330       {
00331         return 3;
00332         break;
00333       }
00334     case TRIA6:
00335       {
00336         return 3;
00337         break;
00338       }
00339     case QUAD4:
00340       {
00341         return 4;
00342         break;
00343       }
00344     case QUAD8:
00345       {
00346         return 4;
00347         break;
00348       }
00349       //case QUAD9:                   { return 9; break; }
00350     case TETRA4:
00351       {
00352         return 4;
00353         break;
00354       }
00355     case TETRA10:
00356       {
00357         return 4;
00358         break;
00359       }
00360     case PYRAM5:
00361       {
00362         return 5;
00363         break;
00364       }
00365     case PYRAM13:
00366       {
00367         return 5;
00368         break;
00369       }
00370     case PENTA6:
00371       {
00372         return 6;
00373         break;
00374       }
00375     case PENTA15:
00376       {
00377         return 6;
00378         break;
00379       }
00380     case HEXA8:
00381       {
00382         return 8;
00383         break;
00384       }
00385     case HEXA20:
00386       {
00387         return 8;
00388         break;
00389       }
00390       //case HEXA27:                      { return 27;    break; }
00391     default:
00392       ERREUR("Type of elem not accepted (method NnoeudsGeom)");
00393   }
00394   return 0;
00395 }
00396 
00397 int MESHCUT::codeGMSH(std::string type)
00398 {
00399   if (type == (string) "POI1")
00400     ERREUR("POI1 not taken into account by GMSH");
00401   else if (type == (string) "SEG2")
00402     return 1;
00403   else if (type == (string) "SEG3")
00404     return 8;
00405   else if (type == (string) "TRIA3")
00406     return 2;
00407   else if (type == (string) "TRIA6")
00408     return 9;
00409   else if (type == (string) "QUAD4")
00410     return 3;
00411   else if (type == (string) "QUAD8")
00412     return 16;
00413   else if (type == (string) "QUAD9")
00414     return 10;
00415   else if (type == (string) "TETRA4")
00416     return 4;
00417   else if (type == (string) "TETRA10")
00418     return 11;
00419   else if (type == (string) "PYRAM5")
00420     return 7;
00421   else if (type == (string) "PENTA6")
00422     return 6;
00423   else if (type == (string) "PENTA15")
00424     return 18;
00425   else if (type == (string) "HEXA8")
00426     return 5;
00427   else if (type == (string) "HEXA20")
00428     return 17;
00429   else if (type == (string) "HEXA27")
00430     return 12;
00431   else
00432     ERREUR("Type of elem not accepted (method codeGMSH)");
00433   return 0;
00434 }
00435 
00436 std::string MESHCUT::floatEnsight(float x)
00437 {
00438   char buf[12];
00439   string s;
00440   if (x < 0.0)
00441     sprintf(buf, "%1.5E", x);
00442   else
00443     sprintf(buf, " %1.5E", x);
00444   s = (string) buf;
00445   s.erase(10, 1);
00446   return s;
00447 }
00448 
00449 bool MESHCUT::typeComplexe(std::string type)
00450 {
00451   if (type == (string) "SEG3")
00452     return true;
00453   else if (type == (string) "TRIA6")
00454     return true;
00455   else if (type == (string) "QUAD8")
00456     return true;
00457   else if (type == (string) "QUAD9")
00458     return true;
00459   else if (type == (string) "TETRA10")
00460     return true;
00461   else if (type == (string) "PYRAM13")
00462     return true;
00463   else if (type == (string) "PENTA15")
00464     return true;
00465   else if (type == (string) "HEXA20")
00466     return true;
00467   else if (type == (string) "HEXA27")
00468     return true;
00469   else
00470     return false;
00471 }
00472 
00473 std::string MESHCUT::ASTER8(std::string s)
00474 {
00475   if (s.size() == 0)
00476     return (s + (string) "        ");
00477   else if (s.size() == 1)
00478     return (s + (string) "       ");
00479   else if (s.size() == 2)
00480     return (s + (string) "      ");
00481   else if (s.size() == 3)
00482     return (s + (string) "     ");
00483   else if (s.size() == 4)
00484     return (s + (string) "    ");
00485   else if (s.size() == 5)
00486     return (s + (string) "   ");
00487   else if (s.size() == 6)
00488     return (s + (string) "  ");
00489   else if (s.size() == 7)
00490     return (s + (string) " ");
00491   else if (s.size() == 8)
00492     return (s);
00493   else
00494     ERREUR("More than 8 char for an ASTER string");
00495   return (s);
00496 }
00497 
00510 float MESHCUT::dObservateur(float a, float b, float c)
00511 {
00512   return (max(a, b) / 2.0 + c);
00513 }
00514 
00515 int MESHCUT::copieFichier(std::string source, std::string cible)
00516 {
00517   FILE *fsource, *fcible;
00518   char buffer[512];
00519   int NbLu;
00520   if ((fsource = fopen(string2char(source), "rb")) == NULL)
00521     return -1;
00522   if ((fcible = fopen(string2char(cible), "wb")) == NULL)
00523     {
00524       fclose(fsource);
00525       return -2;
00526     }
00527   while ((NbLu = fread(buffer, 1, 512, fsource)) != 0)
00528     fwrite(buffer, 1, NbLu, fcible);
00529   fclose(fcible);
00530   fclose(fsource);
00531   return 0;
00532 }
00533 
00534 med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
00535 {
00536   med_geometry_type typeBanaliseMED;
00537 
00538   switch (TYPE)
00539   {
00540     case POI1:
00541       typeBanaliseMED = MED_POINT1;
00542       break; // Attention, piège !
00543     case SEG2:
00544       typeBanaliseMED = MED_SEG2;
00545       break;
00546     case SEG3:
00547       typeBanaliseMED = MED_SEG3;
00548       break;
00549     case TRIA3:
00550       typeBanaliseMED = MED_TRIA3;
00551       break;
00552     case TRIA6:
00553       typeBanaliseMED = MED_TRIA6;
00554       break;
00555     case QUAD4:
00556       typeBanaliseMED = MED_QUAD4;
00557       break;
00558     case QUAD8:
00559       typeBanaliseMED = MED_QUAD8;
00560       break;
00561     case TETRA4:
00562       typeBanaliseMED = MED_TETRA4;
00563       break;
00564     case TETRA10:
00565       typeBanaliseMED = MED_TETRA10;
00566       break;
00567     case PYRAM5:
00568       typeBanaliseMED = MED_PYRA5;
00569       break; // Attention, piège !
00570     case PYRAM13:
00571       typeBanaliseMED = MED_PYRA13;
00572       break; // Attention, piège !
00573     case PENTA6:
00574       typeBanaliseMED = MED_PENTA6;
00575       break;
00576     case PENTA15:
00577       typeBanaliseMED = MED_PENTA15;
00578       break;
00579     case HEXA8:
00580       typeBanaliseMED = MED_HEXA8;
00581       break;
00582     case HEXA20:
00583       typeBanaliseMED = MED_HEXA20;
00584       break;
00585     default:
00586       ERREUR("Method InstanceMGE, unknown type ");
00587   }
00588   return typeBanaliseMED;
00589 }
00590 
00591 int MESHCUT::chrono()
00592 {
00593   return clock() / CLOCKS_PER_SEC;
00594 }
00595 
00596 TYPE_MAILLE MESHCUT::typeMaille(std::string type)
00597 {
00598   if (type == (string) "POI1")
00599     return POI1;
00600   else if (type == (string) "SEG2")
00601     return SEG2;
00602   else if (type == (string) "SEG3")
00603     return SEG3;
00604   else if (type == (string) "TRIA3")
00605     return TRIA3;
00606   else if (type == (string) "TRIA6")
00607     return TRIA6;
00608   else if (type == (string) "QUAD4")
00609     return QUAD4;
00610   else if (type == (string) "QUAD8")
00611     return QUAD8;
00612   else if (type == (string) "TETRA4")
00613     return TETRA4;
00614   else if (type == (string) "TETRA10")
00615     return TETRA10;
00616   else if (type == (string) "PYRAM5")
00617     return PYRAM5;
00618   else if (type == (string) "PYRAM13")
00619     return PYRAM13;
00620   else if (type == (string) "PENTA6")
00621     return PENTA6;
00622   else if (type == (string) "PENTA15")
00623     return PENTA15;
00624   else if (type == (string) "HEXA8")
00625     return HEXA8;
00626   else if (type == (string) "HEXA20")
00627     return HEXA20;
00628   else
00629     ERREUR("ERROR method typeMaille, unknown type");
00630   return POI1;
00631 }
00632 
00633 std::string MESHCUT::MGE2string(med_geometry_type MGE)
00634 {
00635   if (MGE == MED_NONE)
00636     return (string) "NOEUD";
00637   else if (MGE == MED_POINT1)
00638     return (string) "POI1";
00639   else if (MGE == MED_SEG2)
00640     return (string) "SEG2";
00641   else if (MGE == MED_SEG3)
00642     return (string) "SEG3";
00643   else if (MGE == MED_TRIA3)
00644     return (string) "TRIA3";
00645   else if (MGE == MED_TRIA6)
00646     return (string) "TRIA6";
00647   else if (MGE == MED_QUAD4)
00648     return (string) "QUAD4";
00649   else if (MGE == MED_QUAD8)
00650     return (string) "QUAD8";
00651   else if (MGE == MED_TETRA4)
00652     return (string) "TETRA4";
00653   else if (MGE == MED_TETRA10)
00654     return (string) "TETRA10";
00655   else if (MGE == MED_PYRA5)
00656     return (string) "PYRAM5";
00657   else if (MGE == MED_PYRA13)
00658     return (string) "PYRAM13";
00659   else if (MGE == MED_PENTA6)
00660     return (string) "PENTA6";
00661   else if (MGE == MED_PENTA15)
00662     return (string) "PENTA15";
00663   else if (MGE == MED_HEXA8)
00664     return (string) "HEXA8";
00665   else if (MGE == MED_HEXA20)
00666     return (string) "HEXA20";
00667   else
00668     ERREUR("ERROR method MGE2string, unknown type");
00669   return (string) "NOEUD";
00670 }
00671 
00672 std::string MESHCUT::TM2string(TYPE_MAILLE MGE)
00673 {
00674   if (MGE == POI1)
00675     return (string) "POI1";
00676   else if (MGE == SEG2)
00677     return (string) "SEG2";
00678   else if (MGE == SEG3)
00679     return (string) "SEG3";
00680   else if (MGE == TRIA3)
00681     return (string) "TRIA3";
00682   else if (MGE == TRIA6)
00683     return (string) "TRIA6";
00684   else if (MGE == QUAD4)
00685     return (string) "QUAD4";
00686   else if (MGE == QUAD8)
00687     return (string) "QUAD8";
00688   else if (MGE == TETRA4)
00689     return (string) "TETRA4";
00690   else if (MGE == TETRA10)
00691     return (string) "TETRA10";
00692   else if (MGE == PYRAM5)
00693     return (string) "PYRAM5";
00694   else if (MGE == PYRAM13)
00695     return (string) "PYRAM13";
00696   else if (MGE == PENTA6)
00697     return (string) "PENTA6";
00698   else if (MGE == PENTA15)
00699     return (string) "PENTA15";
00700   else if (MGE == HEXA8)
00701     return (string) "HEXA8";
00702   else if (MGE == HEXA20)
00703     return (string) "HEXA20";
00704   else
00705     ERREUR("ERROR method TM2string, unknown type");
00706   return (string) "POI1";
00707 }
00708 
00709 TYPE_MAILLE MESHCUT::string2TM(std::string stm)
00710 {
00711   if (stm == (string) "POI1")
00712     return POI1;
00713   else if (stm == (string) "SEG2")
00714     return SEG2;
00715   else if (stm == (string) "SEG3")
00716     return SEG3;
00717   else if (stm == (string) "TRIA3")
00718     return TRIA3;
00719   else if (stm == (string) "TRIA6")
00720     return TRIA6;
00721   else if (stm == (string) "QUAD4")
00722     return QUAD4;
00723   else if (stm == (string) "QUAD8")
00724     return QUAD8;
00725   else if (stm == (string) "TETRA4")
00726     return TETRA4;
00727   else if (stm == (string) "TETRA10")
00728     return TETRA10;
00729   else if (stm == (string) "PYRAM5")
00730     return PYRAM5;
00731   else if (stm == (string) "PYRAM13")
00732     return PYRAM13;
00733   else if (stm == (string) "PENTA6")
00734     return PENTA6;
00735   else if (stm == (string) "PENTA15")
00736     return PENTA15;
00737   else if (stm == (string) "HEXA8")
00738     return HEXA8;
00739   else if (stm == (string) "HEXA20")
00740     return HEXA20;
00741   else
00742     ERREUR("ERROR method string2TM, unknown type");
00743   return POI1;
00744 }
00745 
00746 std::string MESHCUT::coordIndex_ILS(TYPE_MAILLE tm)
00747 {
00748   if (tm == SEG2)
00749     return (string) " 0,1 ";
00750   else if (tm == SEG3)
00751     return (string) " 0,1 "; // Idem SEG2
00752   else if (tm == TRIA3)
00753     return (string) " 0,1,2,0 ";
00754   else if (tm == TRIA6)
00755     return (string) " 0,1,2,0 ";
00756   else if (tm == QUAD4)
00757     return (string) " 0,1,2,3,0 ";
00758   else if (tm == QUAD8)
00759     return (string) " 0,1,2,3,0 ";
00760   else if (tm == TETRA4)
00761     return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
00762   else if (tm == TETRA10)
00763     return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
00764   else if (tm == PYRAM5)
00765     return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
00766   else if (tm == PYRAM13)
00767     return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
00768   else if (tm == PENTA6)
00769     return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
00770   else if (tm == PENTA15)
00771     return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
00772   else if (tm == HEXA8)
00773     return (string) " 0,1,2,3,0,-1, 4,5,6,7,4,-1, 0,4,-1, 1,5,-1, 2,6,-1, 3,7,-1 ";
00774   else if (tm == HEXA20)
00775     return (string) " 0,1,2,3,0,-1, 4,5,6,7,4,-1, 0,4,-1, 1,5,-1, 2,6,-1, 3,7,-1 ";
00776   else
00777     return (string) "";
00778 }
00779 
00780 std::string MESHCUT::coordIndex_IFS(TYPE_MAILLE tm)
00781 {
00782   if (tm == SEG2)
00783     return (string) "  ";
00784   else if (tm == SEG3)
00785     return (string) "  "; // Idem SEG2
00786   else if (tm == TRIA3)
00787     return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
00788   else if (tm == TRIA6)
00789     return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
00790   else if (tm == QUAD4)
00791     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
00792   else if (tm == QUAD8)
00793     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
00794   else if (tm == TETRA4)
00795     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 0,3,1,0,-1, 0,1,3,0,-1, 1,3,2,1,-1, 1,2,3,1,-1, 0,2,3,0,-1, 0,3,2,0,-1 ";
00796   else if (tm == TETRA10)
00797     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 0,3,1,0,-1, 0,1,3,0,-1, 1,3,2,1,-1, 1,2,3,1,-1, 0,2,3,0,-1, 0,3,2,0,-1 ";
00798   else if (tm == PYRAM5)
00799     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 0,1,4,0,-1, 0,4,1,0,-1, 1,2,4,1,-1, 1,4,2,1,-1, 2,4,3,2,-1, 2,3,4,2,-1, 3,4,0,3,-1, 3,0,4,3,-1 ";
00800   else if (tm == PYRAM13)
00801     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 0,1,4,0,-1, 0,4,1,0,-1, 1,2,4,1,-1, 1,4,2,1,-1, 2,4,3,2,-1, 2,3,4,2,-1, 3,4,0,3,-1, 3,0,4,3,-1 ";
00802   else if (tm == PENTA6)
00803     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 3,4,5,3,-1, 3,5,4,3,-1, 0,1,4,3,0,-1, 0,3,4,1,0,-1, 1,4,5,2,1,-1, 1,2,5,4,1,-1, 0,3,5,2,0,-1, 0,2,5,3,0,-1 ";
00804   else if (tm == PENTA15)
00805     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 3,4,5,3,-1, 3,5,4,3,-1, 0,1,4,3,0,-1, 0,3,4,1,0,-1, 1,4,5,2,1,-1, 1,2,5,4,1,-1, 0,3,5,2,0,-1, 0,2,5,3,0,-1 ";
00806   else if (tm == HEXA8)
00807     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 1,5,6,2,1,-1, 1,2,6,5,1,-1, 5,4,7,6,5,-1, 5,6,7,4,5,-1, 4,0,3,7,4,-1, 4,7,3,0,4,-1, 0,4,5,1,0,-1, 0,1,5,4,0,-1, 3,7,6,2,3,-1, 3,2,6,7,3,-1 ";
00808   else if (tm == HEXA20)
00809     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 1,5,6,2,1,-1, 1,2,6,5,1,-1, 5,4,7,6,5,-1, 5,6,7,4,5,-1, 4,0,3,7,4,-1, 4,7,3,0,4,-1, 0,4,5,1,0,-1, 0,1,5,4,0,-1, 3,7,6,2,3,-1, 3,2,6,7,3,-1 ";
00810   else
00811     return (string) "";
00812 }
00813 
00814 std::string MESHCUT::SIGNE(double x)
00815 {
00816   if (x < 0)
00817     return "-";
00818   else if (x > 0)
00819     return "+";
00820   else
00821     return "0";
00822 }
00823 
00824 void MESHCUT::champType(std::string type, med_entity_type MEM, med_geometry_type MGE, med_idt fid, med_idt fidout,
00825                         char *maa, char *nomChamp, char *nomChampMoy, med_field_type typeChamp, char *compChamp,
00826                         char *unitChamp, med_int nCompChamp, std::map<std::string, int> REFGAUSS, int ichamp)
00827 {
00828 
00829   bool debug = true;
00830   int ipt, nmailles, ngauss, imaille, igauss, icomp;
00831   //  int ival, ngpdt;
00832   med_int nval, numdt, numo, nPasTemps;
00833   char dtunit[MED_SNAME_SIZE + 1] = "";
00834   char locname[MED_NAME_SIZE + 1] = "";
00835   char nomprofil[MED_NAME_SIZE + 1] = "";
00836   med_float dt = 0.0;
00837   med_float *valr = NULL;
00838   med_float *valr2 = NULL;
00839   med_bool local;
00840   //  med_int nbrefmaa;
00841   med_field_type fieldType;
00842 
00843   if (MEDfieldInfo(fid, ichamp, nomChamp, maa, &local, &fieldType, compChamp, unitChamp, dtunit, &nPasTemps) < 0)
00844     ERREUR("Error MEDfieldInfo");
00845   cout << type << " : " << (int) nPasTemps << " timestep  " << endl;
00846 
00847   for (ipt = 1; ipt <= nPasTemps; ipt++)
00848     {
00849       //for (ipt=1; ipt<=min(nPasTemps,1); ipt++) {
00850       if (debug)
00851         cout << endl;
00852       if (debug)
00853         cout << "************************************************************" << endl;
00854       if (debug)
00855         cout << "                    FIELD " << ichamp << endl;
00856       if (debug)
00857         cout << "          " << nomChamp << endl;
00858       if (debug)
00859         cout << "          " << type << "   ---   Timestep " << ipt << endl;
00860       if (debug)
00861         cout << "************************************************************" << endl;
00862       if (debug)
00863         cout << endl;
00864 
00865       if (MEDfieldComputingStepInfo(fid, nomChamp, ipt, &numdt, &numo, &dt) < 0)
00866         {
00867           cout << endl;
00868           cout << endl << "####################################################################" << endl;
00869           cout << "                   ERROR MEDpasdetempsInfo                         " << endl;
00870           cout << endl << "####################################################################" << endl;
00871           cout << "                  Field: " << (string) nomChamp << endl;
00872           cout << "                  Geometrie: " << MGE2string(MGE) << endl;
00873           cout << "                  Timestep " << ipt << " ignored" << endl;
00874 
00875           continue;
00876         }
00877 
00878       med_int profilesize, nintegrationpoint;
00879       nval = MEDfieldnValueWithProfile(fid, nomChamp, numdt, numo, MEM, MGE, ipt, MED_COMPACT_PFLMODE, nomprofil,
00880                                        &profilesize, locname, &nintegrationpoint);
00881       if (debug)
00882         cout << "     Number of values in this timestep: " << (int) nval << endl;
00883 
00884       if (typeChamp == MED_FLOAT64)
00885         valr = (med_float*) calloc(nCompChamp * nval, sizeof(med_float));
00886       else
00887         ERREUR("Type of field not taken into account");
00888 
00889       if (MEDfieldValueWithProfileRd(fid, maa, numdt, numo, MEM, MGE, MED_COMPACT_PFLMODE, nomprofil,
00890                                      MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0)
00891         {
00892           cout << endl;
00893           cout << endl << "####################################################################" << endl;
00894           cout << "                         ERROR MEDchampLire                        " << endl;
00895           cout << endl << "####################################################################" << endl;
00896           cout << endl;
00897           cout << "   Field: " << (string) nomChamp << endl;
00898           cout << "   Geometry: " << MGE2string(MGE) << endl;
00899           cout << "   Timestep " << ipt << " ignored" << endl;
00900           cout << endl << endl;
00901           continue;
00902         }
00903 
00904       if (debug)
00905         cout << "       profile  = " << (string) nomprofil << endl;
00906       // Localisation du champ aux points de Gauss
00907       if (debug)
00908         cout << "       locname = " << (string) locname << endl;
00909 
00910       if (REFGAUSS[(string) locname])
00911         {
00912           ngauss = REFGAUSS[(string) locname];
00913           if (debug)
00914             cout << "       " << ngauss << " Gauss points by element)" << endl;
00915         }
00916       else
00917         ngauss = 1;
00918 
00919       nmailles = nval / ngauss;
00920       if (debug)
00921         cout << "      Nbre de mailles: " << nmailles << endl;
00922 
00923       if (debug)
00924         {
00925           cout << endl << "       Liste des valeurs du champ brut aux 3 premiers éléments:" << endl;
00926           for (imaille = 0; imaille < min(nmailles, 3); imaille++)
00927             {
00928               cout << "         Maille " << imaille << endl;
00929               for (igauss = 0; igauss < ngauss; igauss++)
00930                 {
00931                   cout << "             PG " << igauss << " : ";
00932                   for (icomp = 0; icomp < nCompChamp; icomp++)
00933                     cout << " " << *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
00934                   cout << endl;
00935                 }
00936               cout << endl;
00937             }
00938           cout << endl;
00939         }
00940 
00941       if (ngauss > 1)
00942         {
00943 
00944           valr2 = (med_float*) calloc(nCompChamp * nmailles, sizeof(med_float));
00945 
00946           if (debug)
00947             cout << endl << "       Moyenne sur les PG des mailles" << endl;
00948           for (imaille = 0; imaille < nmailles; imaille++)
00949             {
00950               for (icomp = 0; icomp < nCompChamp; icomp++)
00951                 {
00952                   float valCompMaille = 0.0;
00953                   for (igauss = 0; igauss < ngauss; igauss++)
00954                     valCompMaille += *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
00955                   *(valr2 + imaille * nCompChamp + icomp) = valCompMaille / ngauss;
00956 
00957                 }
00958             }
00959 
00960           //cout << endl << "Nom champ moy = " <<  (string)nomChampMoy << endl;
00961           //cout << endl << "Type champ = " <<  typeChamp << endl;
00962           //cout << endl << "Comp champ = " <<  (string)compChamp << endl;
00963           //cout << endl << "Unit champ = " <<  (string)unitChamp << endl;
00964           //cout << endl << "N comp champ = " <<  nCompChamp << endl;
00965 
00966           if (MEDfieldValueWithProfileWr(fidout, nomChampMoy, numdt, numo, dt, MEM, MGE, MED_COMPACT_PFLMODE,
00967                                          nomprofil, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00968                                          (med_int) nmailles, (unsigned char*) valr2) < 0)
00969             {
00970               cout << endl;
00971               cout << endl << "********************************************************************" << endl;
00972               cout << "********************                         ***********************" << endl;
00973               cout << "********************   ERROR MEDchampEcr     ***********************" << endl;
00974               cout << "********************                         ***********************" << endl;
00975               cout << "********************************************************************" << endl;
00976               cout << endl;
00977               cout << "   Champ: " << (string) nomChampMoy << endl;
00978               cout << "   Géométrie: " << MGE2string(MGE) << endl;
00979               cout << "   Pas de temps " << ipt << " ignoré" << endl;
00980               cout << endl << endl;
00981               continue;
00982             }
00983 
00984           if (debug)
00985             cout << "    Writing mean values in new field: OK " << endl;
00986 
00987           // Restitution du champ moyenné
00988           if (debug)
00989             {
00990               cout << endl << "       Liste des valeurs du champ moyenné aux 3 premiers éléments:" << endl;
00991               for (imaille = 0; imaille < min(nmailles, 3); imaille++)
00992                 {
00993                   cout << "         Maille " << imaille << endl;
00994                   for (icomp = 0; icomp < nCompChamp; icomp++)
00995                     cout << " " << *(valr2 + imaille * nCompChamp + icomp);
00996                   cout << endl;
00997                 }
00998               cout << endl;
00999             }
01000 
01001         }
01002 
01003       free(valr);
01004       free(valr2);
01005 
01006     } // boucle sur les pas de temps
01007 
01008   cout << endl;
01009 }
01010 
01011 std::string MESHCUT::nomMaille(TYPE_MAILLE tm, int nl)
01012 {
01013   return (TM2string(tm) + (string) "_" + int2string(nl));
01014 }
01015 
01016 bool MESHCUT::appartientVN(int n, std::vector<int> V)
01017 {
01018   bool app = false;
01019   for (unsigned int i = 0; i < V.size(); i++)
01020     if (n == V[i])
01021       {
01022         app = true;
01023         break;
01024       }
01025   return app;
01026 }
01027 
01028 float MESHCUT::distance2(float x1, float y1, float z1, float x2, float y2, float z2)
01029 {
01030   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
01031 }
01032 
01036 void MESHCUT::conversionCNX(int *CNXtm, TYPE_MAILLE tm, int N)
01037 {
01038 
01039   int n = Nnoeuds(tm);
01040 
01041   if (tm == TETRA4)
01042     {
01043       for (int i = 0; i < N; i++)
01044         {
01045           int i1 = CNXtm[i * n + 1];
01046           int i2 = CNXtm[i * n + 2];
01047           CNXtm[i * n + 1] = i2;
01048           CNXtm[i * n + 2] = i1;
01049         }
01050     }
01051   else if (tm == PYRAM5)
01052     {
01053       for (int i = 0; i < N; i++)
01054         {
01055           int i1 = CNXtm[i * n + 1];
01056           int i3 = CNXtm[i * n + 3];
01057           CNXtm[i * n + 1] = i3;
01058           CNXtm[i * n + 3] = i1;
01059         }
01060     }
01061   else if (tm == PENTA6)
01062     {
01063       for (int i = 0; i < N; i++)
01064         {
01065           int i0 = CNXtm[i * n + 0];
01066           int i1 = CNXtm[i * n + 1];
01067           int i2 = CNXtm[i * n + 2];
01068           int i3 = CNXtm[i * n + 3];
01069           int i4 = CNXtm[i * n + 4];
01070           int i5 = CNXtm[i * n + 5];
01071           CNXtm[i * n + 0] = i3;
01072           CNXtm[i * n + 1] = i4;
01073           CNXtm[i * n + 2] = i5;
01074           CNXtm[i * n + 3] = i0;
01075           CNXtm[i * n + 4] = i1;
01076           CNXtm[i * n + 5] = i2;
01077         }
01078     }
01079 
01080   else if (tm == HEXA8)
01081     {
01082       for (int i = 0; i < N; i++)
01083         {
01084           int i0 = CNXtm[i * n + 0];
01085           int i1 = CNXtm[i * n + 1];
01086           int i2 = CNXtm[i * n + 2];
01087           int i3 = CNXtm[i * n + 3];
01088           int i4 = CNXtm[i * n + 4];
01089           int i5 = CNXtm[i * n + 5];
01090           int i6 = CNXtm[i * n + 6];
01091           int i7 = CNXtm[i * n + 7];
01092           CNXtm[i * n + 0] = i4;
01093           CNXtm[i * n + 1] = i5;
01094           CNXtm[i * n + 2] = i6;
01095           CNXtm[i * n + 3] = i7;
01096           CNXtm[i * n + 4] = i0;
01097           CNXtm[i * n + 5] = i1;
01098           CNXtm[i * n + 6] = i2;
01099           CNXtm[i * n + 7] = i3;
01100         }
01101     }
01102 }
01103 
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS