1 // Copyright (C) 2006-2014 EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MeshCut_Utils.hxx"
30 using namespace MESHCUT;
32 //string pathUsers = (string) "/var/www/XMeshLab/users/";
34 bool MESHCUT::estUnTypeMaille(std::string S)
36 if (S == (string) "POI1" || S == (string) "SEG2" || S == (string) "SEG3" || S == (string) "TRIA3" || S
37 == (string) "TRIA6" || S == (string) "QUAD4" || S == (string) "QUAD8" || S == (string) "QUAD9" || S
38 == (string) "TETRA4" || S == (string) "TETRA10" || S == (string) "PYRAM5" || S == (string) "PYRAM13" || S
39 == (string) "PENTA6" || S == (string) "PENTA15" || S == (string) "HEXA8" || S == (string) "HEXA20" || S
46 void MESHCUT::ERREUR(const char* msg)
48 cout << endl << "====== ERROR ====== " << msg << endl << endl;
52 char* MESHCUT::string2char(std::string str)
54 // créer le buffer pour copier la chaîne
55 size_t size = str.size() + 1;
56 char* buffer = new char[size];
58 strncpy(buffer, str.c_str(), size);
66 std::string MESHCUT::int2string(int k)
68 std::stringstream oss;
70 return oss.str(); // oss.seekp (ios_base::beg);
73 float MESHCUT::char2float(const char* ch)
78 std::string MESHCUT::float2string(float f)
86 bool MESHCUT::appartient(std::string e, std::string tableau[], int taille)
88 for (int i = 0; i < taille; i++)
94 float MESHCUT::arrondi(float x)
96 if (x > 0 && x < 1.0e-5)
98 else if (x < 0 && x > -1.0e-5)
104 int MESHCUT::numNoeudPointe(std::string b1, std::string b2, std::string b3)
106 if (b1 == "1" && b2 == "1" && b3 == "2")
108 else if (b1 == "1" && b2 == "2" && b3 == "1")
110 else if (b1 == "1" && b2 == "2" && b3 == "2")
112 else if (b1 == "2" && b2 == "1" && b3 == "1")
114 else if (b1 == "2" && b2 == "1" && b3 == "2")
116 else if (b1 == "2" && b2 == "2" && b3 == "1")
122 std::string MESHCUT::strip(std::string S)
126 int startIndex = S.find_first_not_of(" ");
127 int endIndex = S.find_last_not_of(" ");
128 return S.substr(startIndex, (endIndex - startIndex + 1));
131 std::string MESHCUT::entierSur10_g(int i)
134 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
136 return int2string(i) + (string) " ";
138 return int2string(i) + (string) " ";
140 return int2string(i) + (string) " ";
142 return int2string(i) + (string) " ";
144 return int2string(i) + (string) " ";
145 else if (i < 1000000)
146 return int2string(i) + (string) " ";
147 else if (i < 10000000)
148 return int2string(i) + (string) " ";
149 else if (i < 100000000)
150 return int2string(i) + (string) " ";
151 else if (i < 1000000000)
152 return int2string(i) + (string) " ";
154 return int2string(i);
157 std::string MESHCUT::entierSur10_d(int i)
160 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
162 return (string) " " + int2string(i);
164 return (string) " " + int2string(i);
166 return (string) " " + int2string(i);
168 return (string) " " + int2string(i);
170 return (string) " " + int2string(i);
171 else if (i < 1000000)
172 return (string) " " + int2string(i);
173 else if (i < 10000000)
174 return (string) " " + int2string(i);
175 else if (i < 100000000)
176 return (string) " " + int2string(i);
177 else if (i < 1000000000)
178 return (string) " " + int2string(i);
180 return int2string(i);
183 std::string MESHCUT::typeEnsight(std::string type)
185 if (type == (string) "POI1")
186 return (string) "point";
187 else if (type == (string) "SEG2")
188 return (string) "bar2";
189 else if (type == (string) "SEG3")
190 return (string) "bar2";// ATTENTION, triche!
191 else if (type == (string) "TRIA3")
192 return (string) "tria3";
193 else if (type == (string) "TRIA6")
194 return (string) "tria3";// ATTENTION, triche!
195 else if (type == (string) "QUAD4")
196 return (string) "quad4";
197 else if (type == (string) "QUAD8")
198 return (string) "quad4"; // ATTENTION, triche!
199 else if (type == (string) "QUAD9")
200 ERREUR("Type QUAD9 not supported by Ensight");
201 else if (type == (string) "TETRA4")
202 return (string) "tetra4";
203 else if (type == (string) "TETRA10")
204 return (string) "tetra4"; // ATTENTION, triche!
205 else if (type == (string) "PYRAM5")
206 return (string) "pyramid5";
207 else if (type == (string) "PYRAM13")
208 return (string) "pyramid5"; // ATTENTION, triche!
209 else if (type == (string) "PENTA6")
210 return (string) "penta6";
211 else if (type == (string) "PENTA15")
212 return (string) "penta6"; // ATTENTION, triche!
213 else if (type == (string) "HEXA8")
214 return (string) "hexa8";
215 else if (type == (string) "HEXA20")
216 return (string) "hexa8"; // ATTENTION, triche!
217 else if (type == (string) "HEXA27")
218 ERREUR("Type HEXA27 not supported by Ensight");
220 ERREUR("Type of element not accepted (method \"typeEnsight\"");
224 int MESHCUT::Nnoeuds(TYPE_MAILLE type)
263 //case QUAD9: { return 9; break; }
304 //case HEXA27: { return 27; break; }
306 ERREUR("Type of elem not accepted (method Nnoeuds)");
311 int MESHCUT::NnoeudsGeom(TYPE_MAILLE type)
350 //case QUAD9: { return 9; break; }
391 //case HEXA27: { return 27; break; }
393 ERREUR("Type of elem not accepted (method NnoeudsGeom)");
398 int MESHCUT::codeGMSH(std::string type)
400 if (type == (string) "POI1")
401 ERREUR("POI1 not taken into account by GMSH");
402 else if (type == (string) "SEG2")
404 else if (type == (string) "SEG3")
406 else if (type == (string) "TRIA3")
408 else if (type == (string) "TRIA6")
410 else if (type == (string) "QUAD4")
412 else if (type == (string) "QUAD8")
414 else if (type == (string) "QUAD9")
416 else if (type == (string) "TETRA4")
418 else if (type == (string) "TETRA10")
420 else if (type == (string) "PYRAM5")
422 else if (type == (string) "PENTA6")
424 else if (type == (string) "PENTA15")
426 else if (type == (string) "HEXA8")
428 else if (type == (string) "HEXA20")
430 else if (type == (string) "HEXA27")
433 ERREUR("Type of elem not accepted (method codeGMSH)");
437 std::string MESHCUT::floatEnsight(float x)
442 sprintf(buf, "%1.5E", x);
444 sprintf(buf, " %1.5E", x);
450 bool MESHCUT::typeComplexe(std::string type)
452 if (type == (string) "SEG3")
454 else if (type == (string) "TRIA6")
456 else if (type == (string) "QUAD8")
458 else if (type == (string) "QUAD9")
460 else if (type == (string) "TETRA10")
462 else if (type == (string) "PYRAM13")
464 else if (type == (string) "PENTA15")
466 else if (type == (string) "HEXA20")
468 else if (type == (string) "HEXA27")
474 std::string MESHCUT::ASTER8(std::string s)
477 return (s + (string) " ");
478 else if (s.size() == 1)
479 return (s + (string) " ");
480 else if (s.size() == 2)
481 return (s + (string) " ");
482 else if (s.size() == 3)
483 return (s + (string) " ");
484 else if (s.size() == 4)
485 return (s + (string) " ");
486 else if (s.size() == 5)
487 return (s + (string) " ");
488 else if (s.size() == 6)
489 return (s + (string) " ");
490 else if (s.size() == 7)
491 return (s + (string) " ");
492 else if (s.size() == 8)
495 ERREUR("More than 8 char for an ASTER string");
500 * Distance à laquelle doit se tenir l'observateur sur un axe
501 * pour voir sous 90° un objet centré de dimensions a et b selon les deux autres axes.
502 * Si on ne tient pas compte de la dimension de l'objet selon l'axe choisi,
503 * la formule d_obs=max(a,b)/2 donne la cote
504 * qui permet de voir l'objet plat dans un angle de 90°.
505 * A cela il faut ajouter la dimension de l'objet selon l'axe d'observation = c.
507 * @param a dimensions de l'objet selon un des axes normal à l'axe d'observation
508 * @param b dimensions de l'objet selon l'autre axe normal à l'axe d'observation
509 * @param c est la dimension de l'objet selon l'axe d'observation
511 float MESHCUT::dObservateur(float a, float b, float c)
513 return (max(a, b) / 2.0 + c);
516 int MESHCUT::copieFichier(std::string source, std::string cible)
518 FILE *fsource, *fcible;
521 if ((fsource = fopen(string2char(source), "rb")) == NULL)
523 if ((fcible = fopen(string2char(cible), "wb")) == NULL)
528 while ((NbLu = fread(buffer, 1, 512, fsource)) != 0)
529 fwrite(buffer, 1, NbLu, fcible);
535 med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
537 med_geometry_type typeBanaliseMED;
542 typeBanaliseMED = MED_POINT1;
543 break; // Attention, piège !
545 typeBanaliseMED = MED_SEG2;
548 typeBanaliseMED = MED_SEG3;
551 typeBanaliseMED = MED_TRIA3;
554 typeBanaliseMED = MED_TRIA6;
557 typeBanaliseMED = MED_QUAD4;
560 typeBanaliseMED = MED_QUAD8;
563 typeBanaliseMED = MED_TETRA4;
566 typeBanaliseMED = MED_TETRA10;
569 typeBanaliseMED = MED_PYRA5;
570 break; // Attention, piège !
572 typeBanaliseMED = MED_PYRA13;
573 break; // Attention, piège !
575 typeBanaliseMED = MED_PENTA6;
578 typeBanaliseMED = MED_PENTA15;
581 typeBanaliseMED = MED_HEXA8;
584 typeBanaliseMED = MED_HEXA20;
587 ERREUR("Method InstanceMGE, unknown type ");
589 return typeBanaliseMED;
592 int MESHCUT::chrono()
594 return clock() / CLOCKS_PER_SEC;
597 TYPE_MAILLE MESHCUT::typeMaille(std::string type)
599 if (type == (string) "POI1")
601 else if (type == (string) "SEG2")
603 else if (type == (string) "SEG3")
605 else if (type == (string) "TRIA3")
607 else if (type == (string) "TRIA6")
609 else if (type == (string) "QUAD4")
611 else if (type == (string) "QUAD8")
613 else if (type == (string) "TETRA4")
615 else if (type == (string) "TETRA10")
617 else if (type == (string) "PYRAM5")
619 else if (type == (string) "PYRAM13")
621 else if (type == (string) "PENTA6")
623 else if (type == (string) "PENTA15")
625 else if (type == (string) "HEXA8")
627 else if (type == (string) "HEXA20")
630 ERREUR("ERROR method typeMaille, unknown type");
634 std::string MESHCUT::MGE2string(med_geometry_type MGE)
637 return (string) "NOEUD";
638 else if (MGE == MED_POINT1)
639 return (string) "POI1";
640 else if (MGE == MED_SEG2)
641 return (string) "SEG2";
642 else if (MGE == MED_SEG3)
643 return (string) "SEG3";
644 else if (MGE == MED_TRIA3)
645 return (string) "TRIA3";
646 else if (MGE == MED_TRIA6)
647 return (string) "TRIA6";
648 else if (MGE == MED_QUAD4)
649 return (string) "QUAD4";
650 else if (MGE == MED_QUAD8)
651 return (string) "QUAD8";
652 else if (MGE == MED_TETRA4)
653 return (string) "TETRA4";
654 else if (MGE == MED_TETRA10)
655 return (string) "TETRA10";
656 else if (MGE == MED_PYRA5)
657 return (string) "PYRAM5";
658 else if (MGE == MED_PYRA13)
659 return (string) "PYRAM13";
660 else if (MGE == MED_PENTA6)
661 return (string) "PENTA6";
662 else if (MGE == MED_PENTA15)
663 return (string) "PENTA15";
664 else if (MGE == MED_HEXA8)
665 return (string) "HEXA8";
666 else if (MGE == MED_HEXA20)
667 return (string) "HEXA20";
669 ERREUR("ERROR method MGE2string, unknown type");
670 return (string) "NOEUD";
673 std::string MESHCUT::TM2string(TYPE_MAILLE MGE)
676 return (string) "POI1";
677 else if (MGE == SEG2)
678 return (string) "SEG2";
679 else if (MGE == SEG3)
680 return (string) "SEG3";
681 else if (MGE == TRIA3)
682 return (string) "TRIA3";
683 else if (MGE == TRIA6)
684 return (string) "TRIA6";
685 else if (MGE == QUAD4)
686 return (string) "QUAD4";
687 else if (MGE == QUAD8)
688 return (string) "QUAD8";
689 else if (MGE == TETRA4)
690 return (string) "TETRA4";
691 else if (MGE == TETRA10)
692 return (string) "TETRA10";
693 else if (MGE == PYRAM5)
694 return (string) "PYRAM5";
695 else if (MGE == PYRAM13)
696 return (string) "PYRAM13";
697 else if (MGE == PENTA6)
698 return (string) "PENTA6";
699 else if (MGE == PENTA15)
700 return (string) "PENTA15";
701 else if (MGE == HEXA8)
702 return (string) "HEXA8";
703 else if (MGE == HEXA20)
704 return (string) "HEXA20";
706 ERREUR("ERROR method TM2string, unknown type");
707 return (string) "POI1";
710 TYPE_MAILLE MESHCUT::string2TM(std::string stm)
712 if (stm == (string) "POI1")
714 else if (stm == (string) "SEG2")
716 else if (stm == (string) "SEG3")
718 else if (stm == (string) "TRIA3")
720 else if (stm == (string) "TRIA6")
722 else if (stm == (string) "QUAD4")
724 else if (stm == (string) "QUAD8")
726 else if (stm == (string) "TETRA4")
728 else if (stm == (string) "TETRA10")
730 else if (stm == (string) "PYRAM5")
732 else if (stm == (string) "PYRAM13")
734 else if (stm == (string) "PENTA6")
736 else if (stm == (string) "PENTA15")
738 else if (stm == (string) "HEXA8")
740 else if (stm == (string) "HEXA20")
743 ERREUR("ERROR method string2TM, unknown type");
747 std::string MESHCUT::coordIndex_ILS(TYPE_MAILLE tm)
750 return (string) " 0,1 ";
752 return (string) " 0,1 "; // Idem SEG2
753 else if (tm == TRIA3)
754 return (string) " 0,1,2,0 ";
755 else if (tm == TRIA6)
756 return (string) " 0,1,2,0 ";
757 else if (tm == QUAD4)
758 return (string) " 0,1,2,3,0 ";
759 else if (tm == QUAD8)
760 return (string) " 0,1,2,3,0 ";
761 else if (tm == TETRA4)
762 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
763 else if (tm == TETRA10)
764 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
765 else if (tm == PYRAM5)
766 return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
767 else if (tm == PYRAM13)
768 return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
769 else if (tm == PENTA6)
770 return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
771 else if (tm == PENTA15)
772 return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
773 else if (tm == HEXA8)
774 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 ";
775 else if (tm == HEXA20)
776 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 ";
781 std::string MESHCUT::coordIndex_IFS(TYPE_MAILLE tm)
786 return (string) " "; // Idem SEG2
787 else if (tm == TRIA3)
788 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
789 else if (tm == TRIA6)
790 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
791 else if (tm == QUAD4)
792 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
793 else if (tm == QUAD8)
794 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
795 else if (tm == TETRA4)
796 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 ";
797 else if (tm == TETRA10)
798 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 ";
799 else if (tm == PYRAM5)
800 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 ";
801 else if (tm == PYRAM13)
802 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 ";
803 else if (tm == PENTA6)
804 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 ";
805 else if (tm == PENTA15)
806 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 ";
807 else if (tm == HEXA8)
808 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 ";
809 else if (tm == HEXA20)
810 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 ";
815 std::string MESHCUT::SIGNE(double x)
825 void MESHCUT::champType(std::string type, med_entity_type MEM, med_geometry_type MGE, med_idt fid, med_idt fidout,
826 char *maa, char *nomChamp, char *nomChampMoy, med_field_type typeChamp, char *compChamp,
827 char *unitChamp, med_int nCompChamp, std::map<std::string, int> REFGAUSS, int ichamp)
831 int ipt, nmailles, ngauss, imaille, igauss, icomp;
833 med_int nval, numdt, numo, nPasTemps;
834 char dtunit[MED_SNAME_SIZE + 1] = "";
835 char locname[MED_NAME_SIZE + 1] = "";
836 char nomprofil[MED_NAME_SIZE + 1] = "";
838 med_float *valr = NULL;
839 med_float *valr2 = NULL;
842 med_field_type fieldType;
844 if (MEDfieldInfo(fid, ichamp, nomChamp, maa, &local, &fieldType, compChamp, unitChamp, dtunit, &nPasTemps) < 0)
845 ERREUR("Error MEDfieldInfo");
846 cout << type << " : " << (int) nPasTemps << " timestep " << endl;
848 for (ipt = 1; ipt <= nPasTemps; ipt++)
850 //for (ipt=1; ipt<=min(nPasTemps,1); ipt++) {
854 cout << "************************************************************" << endl;
856 cout << " FIELD " << ichamp << endl;
858 cout << " " << nomChamp << endl;
860 cout << " " << type << " --- Timestep " << ipt << endl;
862 cout << "************************************************************" << endl;
866 if (MEDfieldComputingStepInfo(fid, nomChamp, ipt, &numdt, &numo, &dt) < 0)
869 cout << endl << "####################################################################" << endl;
870 cout << " ERROR MEDpasdetempsInfo " << endl;
871 cout << endl << "####################################################################" << endl;
872 cout << " Field: " << (string) nomChamp << endl;
873 cout << " Geometrie: " << MGE2string(MGE) << endl;
874 cout << " Timestep " << ipt << " ignored" << endl;
879 med_int profilesize, nintegrationpoint;
880 nval = MEDfieldnValueWithProfile(fid, nomChamp, numdt, numo, MEM, MGE, ipt, MED_COMPACT_PFLMODE, nomprofil,
881 &profilesize, locname, &nintegrationpoint);
883 cout << " Number of values in this timestep: " << (int) nval << endl;
885 if (typeChamp == MED_FLOAT64)
886 valr = (med_float*) calloc(nCompChamp * nval, sizeof(med_float));
888 ERREUR("Type of field not taken into account");
890 if (MEDfieldValueWithProfileRd(fid, maa, numdt, numo, MEM, MGE, MED_COMPACT_PFLMODE, nomprofil,
891 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0)
894 cout << endl << "####################################################################" << endl;
895 cout << " ERROR MEDchampLire " << endl;
896 cout << endl << "####################################################################" << endl;
898 cout << " Field: " << (string) nomChamp << endl;
899 cout << " Geometry: " << MGE2string(MGE) << endl;
900 cout << " Timestep " << ipt << " ignored" << endl;
901 cout << endl << endl;
906 cout << " profile = " << (string) nomprofil << endl;
907 // Localisation du champ aux points de Gauss
909 cout << " locname = " << (string) locname << endl;
911 if (REFGAUSS[(string) locname])
913 ngauss = REFGAUSS[(string) locname];
915 cout << " " << ngauss << " Gauss points by element)" << endl;
920 nmailles = nval / ngauss;
922 cout << " Nbre de mailles: " << nmailles << endl;
926 cout << endl << " Liste des valeurs du champ brut aux 3 premiers éléments:" << endl;
927 for (imaille = 0; imaille < min(nmailles, 3); imaille++)
929 cout << " Maille " << imaille << endl;
930 for (igauss = 0; igauss < ngauss; igauss++)
932 cout << " PG " << igauss << " : ";
933 for (icomp = 0; icomp < nCompChamp; icomp++)
934 cout << " " << *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
945 valr2 = (med_float*) calloc(nCompChamp * nmailles, sizeof(med_float));
948 cout << endl << " Moyenne sur les PG des mailles" << endl;
949 for (imaille = 0; imaille < nmailles; imaille++)
951 for (icomp = 0; icomp < nCompChamp; icomp++)
953 float valCompMaille = 0.0;
954 for (igauss = 0; igauss < ngauss; igauss++)
955 valCompMaille += *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
956 *(valr2 + imaille * nCompChamp + icomp) = valCompMaille / ngauss;
961 //cout << endl << "Nom champ moy = " << (string)nomChampMoy << endl;
962 //cout << endl << "Type champ = " << typeChamp << endl;
963 //cout << endl << "Comp champ = " << (string)compChamp << endl;
964 //cout << endl << "Unit champ = " << (string)unitChamp << endl;
965 //cout << endl << "N comp champ = " << nCompChamp << endl;
967 if (MEDfieldValueWithProfileWr(fidout, nomChampMoy, numdt, numo, dt, MEM, MGE, MED_COMPACT_PFLMODE,
968 nomprofil, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
969 (med_int) nmailles, (unsigned char*) valr2) < 0)
972 cout << endl << "********************************************************************" << endl;
973 cout << "******************** ***********************" << endl;
974 cout << "******************** ERROR MEDchampEcr ***********************" << endl;
975 cout << "******************** ***********************" << endl;
976 cout << "********************************************************************" << endl;
978 cout << " Champ: " << (string) nomChampMoy << endl;
979 cout << " Géométrie: " << MGE2string(MGE) << endl;
980 cout << " Pas de temps " << ipt << " ignoré" << endl;
981 cout << endl << endl;
986 cout << " Writing mean values in new field: OK " << endl;
988 // Restitution du champ moyenné
991 cout << endl << " Liste des valeurs du champ moyenné aux 3 premiers éléments:" << endl;
992 for (imaille = 0; imaille < min(nmailles, 3); imaille++)
994 cout << " Maille " << imaille << endl;
995 for (icomp = 0; icomp < nCompChamp; icomp++)
996 cout << " " << *(valr2 + imaille * nCompChamp + icomp);
1007 } // boucle sur les pas de temps
1012 std::string MESHCUT::nomMaille(TYPE_MAILLE tm, int nl)
1014 return (TM2string(tm) + (string) "_" + int2string(nl));
1017 bool MESHCUT::appartientVN(int n, std::vector<int> V)
1020 for (unsigned int i = 0; i < V.size(); i++)
1029 float MESHCUT::distance2(float x1, float y1, float z1, float x2, float y2, float z2)
1031 return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
1035 * Conversion HL-MED d'une table de connectivités
1037 void MESHCUT::conversionCNX(int *CNXtm, TYPE_MAILLE tm, int N)
1040 int n = Nnoeuds(tm);
1044 for (int i = 0; i < N; i++)
1046 int i1 = CNXtm[i * n + 1];
1047 int i2 = CNXtm[i * n + 2];
1048 CNXtm[i * n + 1] = i2;
1049 CNXtm[i * n + 2] = i1;
1052 else if (tm == PYRAM5)
1054 for (int i = 0; i < N; i++)
1056 int i1 = CNXtm[i * n + 1];
1057 int i3 = CNXtm[i * n + 3];
1058 CNXtm[i * n + 1] = i3;
1059 CNXtm[i * n + 3] = i1;
1062 else if (tm == PENTA6)
1064 for (int i = 0; i < N; i++)
1066 int i0 = CNXtm[i * n + 0];
1067 int i1 = CNXtm[i * n + 1];
1068 int i2 = CNXtm[i * n + 2];
1069 int i3 = CNXtm[i * n + 3];
1070 int i4 = CNXtm[i * n + 4];
1071 int i5 = CNXtm[i * n + 5];
1072 CNXtm[i * n + 0] = i3;
1073 CNXtm[i * n + 1] = i4;
1074 CNXtm[i * n + 2] = i5;
1075 CNXtm[i * n + 3] = i0;
1076 CNXtm[i * n + 4] = i1;
1077 CNXtm[i * n + 5] = i2;
1081 else if (tm == HEXA8)
1083 for (int i = 0; i < N; i++)
1085 int i0 = CNXtm[i * n + 0];
1086 int i1 = CNXtm[i * n + 1];
1087 int i2 = CNXtm[i * n + 2];
1088 int i3 = CNXtm[i * n + 3];
1089 int i4 = CNXtm[i * n + 4];
1090 int i5 = CNXtm[i * n + 5];
1091 int i6 = CNXtm[i * n + 6];
1092 int i7 = CNXtm[i * n + 7];
1093 CNXtm[i * n + 0] = i4;
1094 CNXtm[i * n + 1] = i5;
1095 CNXtm[i * n + 2] = i6;
1096 CNXtm[i * n + 3] = i7;
1097 CNXtm[i * n + 4] = i0;
1098 CNXtm[i * n + 5] = i1;
1099 CNXtm[i * n + 6] = i2;
1100 CNXtm[i * n + 7] = i3;