1 // Copyright (C) 2006-2011 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.
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"
29 using namespace MESHCUT;
31 //string pathUsers = (string) "/var/www/XMeshLab/users/";
33 bool MESHCUT::estUnTypeMaille(std::string S)
35 if (S == (string) "POI1" || S == (string) "SEG2" || S == (string) "SEG3" || S == (string) "TRIA3" || S
36 == (string) "TRIA6" || S == (string) "QUAD4" || S == (string) "QUAD8" || S == (string) "QUAD9" || S
37 == (string) "TETRA4" || S == (string) "TETRA10" || S == (string) "PYRAM5" || S == (string) "PYRAM13" || S
38 == (string) "PENTA6" || S == (string) "PENTA15" || S == (string) "HEXA8" || S == (string) "HEXA20" || S
45 void MESHCUT::ERREUR(const char* msg)
47 cout << endl << "====== ERROR ====== " << msg << endl << endl;
51 char* MESHCUT::string2char(std::string str)
53 // créer le buffer pour copier la chaîne
54 size_t size = str.size() + 1;
55 char* buffer = new char[size];
57 strncpy(buffer, str.c_str(), size);
65 std::string MESHCUT::int2string(int k)
67 std::stringstream oss;
69 return oss.str(); // oss.seekp (ios_base::beg);
72 float MESHCUT::char2float(const char* ch)
77 std::string MESHCUT::float2string(float f)
85 bool MESHCUT::appartient(std::string e, std::string tableau[], int taille)
87 for (int i = 0; i < taille; i++)
93 float MESHCUT::arrondi(float x)
95 if (x > 0 and x < 1.0e-5)
97 else if (x < 0 and x > -1.0e-5)
103 int MESHCUT::numNoeudPointe(std::string b1, std::string b2, std::string b3)
105 if (b1 == "1" && b2 == "1" && b3 == "2")
107 else if (b1 == "1" && b2 == "2" && b3 == "1")
109 else if (b1 == "1" && b2 == "2" && b3 == "2")
111 else if (b1 == "2" && b2 == "1" && b3 == "1")
113 else if (b1 == "2" && b2 == "1" && b3 == "2")
115 else if (b1 == "2" && b2 == "2" && b3 == "1")
121 std::string MESHCUT::strip(std::string S)
125 int startIndex = S.find_first_not_of(" ");
126 int endIndex = S.find_last_not_of(" ");
127 return S.substr(startIndex, (endIndex - startIndex + 1));
130 std::string MESHCUT::entierSur10_g(int i)
133 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
135 return int2string(i) + (string) " ";
137 return int2string(i) + (string) " ";
139 return int2string(i) + (string) " ";
141 return int2string(i) + (string) " ";
143 return int2string(i) + (string) " ";
144 else if (i < 1000000)
145 return int2string(i) + (string) " ";
146 else if (i < 10000000)
147 return int2string(i) + (string) " ";
148 else if (i < 100000000)
149 return int2string(i) + (string) " ";
150 else if (i < 1000000000)
151 return int2string(i) + (string) " ";
153 return int2string(i);
156 std::string MESHCUT::entierSur10_d(int i)
159 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
161 return (string) " " + int2string(i);
163 return (string) " " + int2string(i);
165 return (string) " " + int2string(i);
167 return (string) " " + int2string(i);
169 return (string) " " + int2string(i);
170 else if (i < 1000000)
171 return (string) " " + int2string(i);
172 else if (i < 10000000)
173 return (string) " " + int2string(i);
174 else if (i < 100000000)
175 return (string) " " + int2string(i);
176 else if (i < 1000000000)
177 return (string) " " + int2string(i);
179 return int2string(i);
182 std::string MESHCUT::typeEnsight(std::string type)
184 if (type == (string) "POI1")
185 return (string) "point";
186 else if (type == (string) "SEG2")
187 return (string) "bar2";
188 else if (type == (string) "SEG3")
189 return (string) "bar2";// ATTENTION, triche!
190 else if (type == (string) "TRIA3")
191 return (string) "tria3";
192 else if (type == (string) "TRIA6")
193 return (string) "tria3";// ATTENTION, triche!
194 else if (type == (string) "QUAD4")
195 return (string) "quad4";
196 else if (type == (string) "QUAD8")
197 return (string) "quad4"; // ATTENTION, triche!
198 else if (type == (string) "QUAD9")
199 ERREUR("Type QUAD9 not supported by Ensight");
200 else if (type == (string) "TETRA4")
201 return (string) "tetra4";
202 else if (type == (string) "TETRA10")
203 return (string) "tetra4"; // ATTENTION, triche!
204 else if (type == (string) "PYRAM5")
205 return (string) "pyramid5";
206 else if (type == (string) "PYRAM13")
207 return (string) "pyramid5"; // ATTENTION, triche!
208 else if (type == (string) "PENTA6")
209 return (string) "penta6";
210 else if (type == (string) "PENTA15")
211 return (string) "penta6"; // ATTENTION, triche!
212 else if (type == (string) "HEXA8")
213 return (string) "hexa8";
214 else if (type == (string) "HEXA20")
215 return (string) "hexa8"; // ATTENTION, triche!
216 else if (type == (string) "HEXA27")
217 ERREUR("Type HEXA27 not supported by Ensight");
219 ERREUR("Type of element not accepted (method \"typeEnsight\"");
223 int MESHCUT::Nnoeuds(TYPE_MAILLE type)
262 //case QUAD9: { return 9; break; }
303 //case HEXA27: { return 27; break; }
305 ERREUR("Type of elem not accepted (method Nnoeuds)");
310 int MESHCUT::NnoeudsGeom(TYPE_MAILLE type)
349 //case QUAD9: { return 9; break; }
390 //case HEXA27: { return 27; break; }
392 ERREUR("Type of elem not accepted (method NnoeudsGeom)");
397 int MESHCUT::codeGMSH(std::string type)
399 if (type == (string) "POI1")
400 ERREUR("POI1 not taken into account by GMSH");
401 else if (type == (string) "SEG2")
403 else if (type == (string) "SEG3")
405 else if (type == (string) "TRIA3")
407 else if (type == (string) "TRIA6")
409 else if (type == (string) "QUAD4")
411 else if (type == (string) "QUAD8")
413 else if (type == (string) "QUAD9")
415 else if (type == (string) "TETRA4")
417 else if (type == (string) "TETRA10")
419 else if (type == (string) "PYRAM5")
421 else if (type == (string) "PENTA6")
423 else if (type == (string) "PENTA15")
425 else if (type == (string) "HEXA8")
427 else if (type == (string) "HEXA20")
429 else if (type == (string) "HEXA27")
432 ERREUR("Type of elem not accepted (method codeGMSH)");
436 std::string MESHCUT::floatEnsight(float x)
441 sprintf(buf, "%1.5E", x);
443 sprintf(buf, " %1.5E", x);
449 bool MESHCUT::typeComplexe(std::string type)
451 if (type == (string) "SEG3")
453 else if (type == (string) "TRIA6")
455 else if (type == (string) "QUAD8")
457 else if (type == (string) "QUAD9")
459 else if (type == (string) "TETRA10")
461 else if (type == (string) "PYRAM13")
463 else if (type == (string) "PENTA15")
465 else if (type == (string) "HEXA20")
467 else if (type == (string) "HEXA27")
473 std::string MESHCUT::ASTER8(std::string s)
476 return (s + (string) " ");
477 else if (s.size() == 1)
478 return (s + (string) " ");
479 else if (s.size() == 2)
480 return (s + (string) " ");
481 else if (s.size() == 3)
482 return (s + (string) " ");
483 else if (s.size() == 4)
484 return (s + (string) " ");
485 else if (s.size() == 5)
486 return (s + (string) " ");
487 else if (s.size() == 6)
488 return (s + (string) " ");
489 else if (s.size() == 7)
490 return (s + (string) " ");
491 else if (s.size() == 8)
494 ERREUR("More than 8 char for an ASTER string");
499 * Distance à laquelle doit se tenir l'observateur sur un axe
500 * pour voir sous 90° un objet centré de dimensions a et b selon les deux autres axes.
501 * Si on ne tient pas compte de la dimension de l'objet selon l'axe choisi,
502 * la formule d_obs=max(a,b)/2 donne la cote
503 * qui permet de voir l'objet plat dans un angle de 90°.
504 * A cela il faut ajouter la dimension de l'objet selon l'axe d'observation = c.
506 * @param a dimensions de l'objet selon un des axes normal à l'axe d'observation
507 * @param b dimensions de l'objet selon l'autre axe normal à l'axe d'observation
508 * @param c est la dimension de l'objet selon l'axe d'observation
510 float MESHCUT::dObservateur(float a, float b, float c)
512 return (max(a, b) / 2.0 + c);
515 int MESHCUT::copieFichier(std::string source, std::string cible)
517 FILE *fsource, *fcible;
520 if ((fsource = fopen(string2char(source), "rb")) == NULL)
522 if ((fcible = fopen(string2char(cible), "wb")) == NULL)
527 while ((NbLu = fread(buffer, 1, 512, fsource)) != 0)
528 fwrite(buffer, 1, NbLu, fcible);
534 med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
536 med_geometry_type typeBanaliseMED;
541 typeBanaliseMED = MED_POINT1;
542 break; // Attention, piège !
544 typeBanaliseMED = MED_SEG2;
547 typeBanaliseMED = MED_SEG3;
550 typeBanaliseMED = MED_TRIA3;
553 typeBanaliseMED = MED_TRIA6;
556 typeBanaliseMED = MED_QUAD4;
559 typeBanaliseMED = MED_QUAD8;
562 typeBanaliseMED = MED_TETRA4;
565 typeBanaliseMED = MED_TETRA10;
568 typeBanaliseMED = MED_PYRA5;
569 break; // Attention, piège !
571 typeBanaliseMED = MED_PYRA13;
572 break; // Attention, piège !
574 typeBanaliseMED = MED_PENTA6;
577 typeBanaliseMED = MED_PENTA15;
580 typeBanaliseMED = MED_HEXA8;
583 typeBanaliseMED = MED_HEXA20;
586 ERREUR("Method InstanceMGE, unknown type ");
588 return typeBanaliseMED;
591 int MESHCUT::chrono()
593 return clock() / CLOCKS_PER_SEC;
596 TYPE_MAILLE MESHCUT::typeMaille(std::string type)
598 if (type == (string) "POI1")
600 else if (type == (string) "SEG2")
602 else if (type == (string) "SEG3")
604 else if (type == (string) "TRIA3")
606 else if (type == (string) "TRIA6")
608 else if (type == (string) "QUAD4")
610 else if (type == (string) "QUAD8")
612 else if (type == (string) "TETRA4")
614 else if (type == (string) "TETRA10")
616 else if (type == (string) "PYRAM5")
618 else if (type == (string) "PYRAM13")
620 else if (type == (string) "PENTA6")
622 else if (type == (string) "PENTA15")
624 else if (type == (string) "HEXA8")
626 else if (type == (string) "HEXA20")
629 ERREUR("ERROR method typeMaille, unknown type");
633 std::string MESHCUT::MGE2string(med_geometry_type MGE)
636 return (string) "NOEUD";
637 else if (MGE == MED_POINT1)
638 return (string) "POI1";
639 else if (MGE == MED_SEG2)
640 return (string) "SEG2";
641 else if (MGE == MED_SEG3)
642 return (string) "SEG3";
643 else if (MGE == MED_TRIA3)
644 return (string) "TRIA3";
645 else if (MGE == MED_TRIA6)
646 return (string) "TRIA6";
647 else if (MGE == MED_QUAD4)
648 return (string) "QUAD4";
649 else if (MGE == MED_QUAD8)
650 return (string) "QUAD8";
651 else if (MGE == MED_TETRA4)
652 return (string) "TETRA4";
653 else if (MGE == MED_TETRA10)
654 return (string) "TETRA10";
655 else if (MGE == MED_PYRA5)
656 return (string) "PYRAM5";
657 else if (MGE == MED_PYRA13)
658 return (string) "PYRAM13";
659 else if (MGE == MED_PENTA6)
660 return (string) "PENTA6";
661 else if (MGE == MED_PENTA15)
662 return (string) "PENTA15";
663 else if (MGE == MED_HEXA8)
664 return (string) "HEXA8";
665 else if (MGE == MED_HEXA20)
666 return (string) "HEXA20";
668 ERREUR("ERROR method MGE2string, unknown type");
669 return (string) "NOEUD";
672 std::string MESHCUT::TM2string(TYPE_MAILLE MGE)
675 return (string) "POI1";
676 else if (MGE == SEG2)
677 return (string) "SEG2";
678 else if (MGE == SEG3)
679 return (string) "SEG3";
680 else if (MGE == TRIA3)
681 return (string) "TRIA3";
682 else if (MGE == TRIA6)
683 return (string) "TRIA6";
684 else if (MGE == QUAD4)
685 return (string) "QUAD4";
686 else if (MGE == QUAD8)
687 return (string) "QUAD8";
688 else if (MGE == TETRA4)
689 return (string) "TETRA4";
690 else if (MGE == TETRA10)
691 return (string) "TETRA10";
692 else if (MGE == PYRAM5)
693 return (string) "PYRAM5";
694 else if (MGE == PYRAM13)
695 return (string) "PYRAM13";
696 else if (MGE == PENTA6)
697 return (string) "PENTA6";
698 else if (MGE == PENTA15)
699 return (string) "PENTA15";
700 else if (MGE == HEXA8)
701 return (string) "HEXA8";
702 else if (MGE == HEXA20)
703 return (string) "HEXA20";
705 ERREUR("ERROR method TM2string, unknown type");
706 return (string) "POI1";
709 TYPE_MAILLE MESHCUT::string2TM(std::string stm)
711 if (stm == (string) "POI1")
713 else if (stm == (string) "SEG2")
715 else if (stm == (string) "SEG3")
717 else if (stm == (string) "TRIA3")
719 else if (stm == (string) "TRIA6")
721 else if (stm == (string) "QUAD4")
723 else if (stm == (string) "QUAD8")
725 else if (stm == (string) "TETRA4")
727 else if (stm == (string) "TETRA10")
729 else if (stm == (string) "PYRAM5")
731 else if (stm == (string) "PYRAM13")
733 else if (stm == (string) "PENTA6")
735 else if (stm == (string) "PENTA15")
737 else if (stm == (string) "HEXA8")
739 else if (stm == (string) "HEXA20")
742 ERREUR("ERROR method string2TM, unknown type");
746 std::string MESHCUT::coordIndex_ILS(TYPE_MAILLE tm)
749 return (string) " 0,1 ";
751 return (string) " 0,1 "; // Idem SEG2
752 else if (tm == TRIA3)
753 return (string) " 0,1,2,0 ";
754 else if (tm == TRIA6)
755 return (string) " 0,1,2,0 ";
756 else if (tm == QUAD4)
757 return (string) " 0,1,2,3,0 ";
758 else if (tm == QUAD8)
759 return (string) " 0,1,2,3,0 ";
760 else if (tm == TETRA4)
761 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
762 else if (tm == TETRA10)
763 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
764 else if (tm == PYRAM5)
765 return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
766 else if (tm == PYRAM13)
767 return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
768 else if (tm == PENTA6)
769 return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
770 else if (tm == PENTA15)
771 return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
772 else if (tm == HEXA8)
773 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 ";
774 else if (tm == HEXA20)
775 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 ";
780 std::string MESHCUT::coordIndex_IFS(TYPE_MAILLE tm)
785 return (string) " "; // Idem SEG2
786 else if (tm == TRIA3)
787 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
788 else if (tm == TRIA6)
789 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
790 else if (tm == QUAD4)
791 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
792 else if (tm == QUAD8)
793 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
794 else if (tm == TETRA4)
795 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 ";
796 else if (tm == TETRA10)
797 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 ";
798 else if (tm == PYRAM5)
799 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 ";
800 else if (tm == PYRAM13)
801 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 ";
802 else if (tm == PENTA6)
803 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 ";
804 else if (tm == PENTA15)
805 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 ";
806 else if (tm == HEXA8)
807 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 ";
808 else if (tm == HEXA20)
809 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 ";
814 std::string MESHCUT::SIGNE(double x)
824 void MESHCUT::champType(std::string type, med_entity_type MEM, med_geometry_type MGE, med_idt fid, med_idt fidout,
825 char *maa, char *nomChamp, char *nomChampMoy, med_field_type typeChamp, char *compChamp,
826 char *unitChamp, med_int nCompChamp, std::map<std::string, int> REFGAUSS, int ichamp)
830 int ipt, nmailles, ngauss, imaille, igauss, icomp;
832 med_int nval, numdt, numo, nPasTemps;
833 char dtunit[MED_SNAME_SIZE + 1] = "";
834 char locname[MED_NAME_SIZE + 1] = "";
835 char nomprofil[MED_NAME_SIZE + 1] = "";
837 med_float *valr = NULL;
838 med_float *valr2 = NULL;
841 med_field_type fieldType;
843 if (MEDfieldInfo(fid, ichamp, nomChamp, maa, &local, &fieldType, compChamp, unitChamp, dtunit, &nPasTemps) < 0)
844 ERREUR("Error MEDfieldInfo");
845 cout << type << " : " << (int) nPasTemps << " timestep " << endl;
847 for (ipt = 1; ipt <= nPasTemps; ipt++)
849 //for (ipt=1; ipt<=min(nPasTemps,1); ipt++) {
853 cout << "************************************************************" << endl;
855 cout << " FIELD " << ichamp << endl;
857 cout << " " << nomChamp << endl;
859 cout << " " << type << " --- Timestep " << ipt << endl;
861 cout << "************************************************************" << endl;
865 if (MEDfieldComputingStepInfo(fid, nomChamp, ipt, &numdt, &numo, &dt) < 0)
868 cout << endl << "####################################################################" << endl;
869 cout << " ERROR MEDpasdetempsInfo " << endl;
870 cout << endl << "####################################################################" << endl;
871 cout << " Field: " << (string) nomChamp << endl;
872 cout << " Geometrie: " << MGE2string(MGE) << endl;
873 cout << " Timestep " << ipt << " ignored" << endl;
878 med_int profilesize, nintegrationpoint;
879 nval = MEDfieldnValueWithProfile(fid, nomChamp, numdt, numo, MEM, MGE, ipt, MED_COMPACT_PFLMODE, nomprofil,
880 &profilesize, locname, &nintegrationpoint);
882 cout << " Number of values in this timestep: " << (int) nval << endl;
884 if (typeChamp == MED_FLOAT64)
885 valr = (med_float*) calloc(nCompChamp * nval, sizeof(med_float));
887 ERREUR("Type of field not taken into account");
889 if (MEDfieldValueWithProfileRd(fid, maa, numdt, numo, MEM, MGE, MED_COMPACT_PFLMODE, nomprofil,
890 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0)
893 cout << endl << "####################################################################" << endl;
894 cout << " ERROR MEDchampLire " << endl;
895 cout << endl << "####################################################################" << endl;
897 cout << " Field: " << (string) nomChamp << endl;
898 cout << " Geometry: " << MGE2string(MGE) << endl;
899 cout << " Timestep " << ipt << " ignored" << endl;
900 cout << endl << endl;
905 cout << " profile = " << (string) nomprofil << endl;
906 // Localisation du champ aux points de Gauss
908 cout << " locname = " << (string) locname << endl;
910 if (REFGAUSS[(string) locname])
912 ngauss = REFGAUSS[(string) locname];
914 cout << " " << ngauss << " Gauss points by element)" << endl;
919 nmailles = nval / ngauss;
921 cout << " Nbre de mailles: " << nmailles << endl;
925 cout << endl << " Liste des valeurs du champ brut aux 3 premiers éléments:" << endl;
926 for (imaille = 0; imaille < min(nmailles, 3); imaille++)
928 cout << " Maille " << imaille << endl;
929 for (igauss = 0; igauss < ngauss; igauss++)
931 cout << " PG " << igauss << " : ";
932 for (icomp = 0; icomp < nCompChamp; icomp++)
933 cout << " " << *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
944 valr2 = (med_float*) calloc(nCompChamp * nmailles, sizeof(med_float));
947 cout << endl << " Moyenne sur les PG des mailles" << endl;
948 for (imaille = 0; imaille < nmailles; imaille++)
950 for (icomp = 0; icomp < nCompChamp; icomp++)
952 float valCompMaille = 0.0;
953 for (igauss = 0; igauss < ngauss; igauss++)
954 valCompMaille += *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
955 *(valr2 + imaille * nCompChamp + icomp) = valCompMaille / ngauss;
960 //cout << endl << "Nom champ moy = " << (string)nomChampMoy << endl;
961 //cout << endl << "Type champ = " << typeChamp << endl;
962 //cout << endl << "Comp champ = " << (string)compChamp << endl;
963 //cout << endl << "Unit champ = " << (string)unitChamp << endl;
964 //cout << endl << "N comp champ = " << nCompChamp << endl;
966 if (MEDfieldValueWithProfileWr(fidout, nomChampMoy, numdt, numo, dt, MEM, MGE, MED_COMPACT_PFLMODE,
967 nomprofil, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
968 (med_int) nmailles, (unsigned char*) valr2) < 0)
971 cout << endl << "********************************************************************" << endl;
972 cout << "******************** ***********************" << endl;
973 cout << "******************** ERROR MEDchampEcr ***********************" << endl;
974 cout << "******************** ***********************" << endl;
975 cout << "********************************************************************" << endl;
977 cout << " Champ: " << (string) nomChampMoy << endl;
978 cout << " Géométrie: " << MGE2string(MGE) << endl;
979 cout << " Pas de temps " << ipt << " ignoré" << endl;
980 cout << endl << endl;
985 cout << " Writing mean values in new field: OK " << endl;
987 // Restitution du champ moyenné
990 cout << endl << " Liste des valeurs du champ moyenné aux 3 premiers éléments:" << endl;
991 for (imaille = 0; imaille < min(nmailles, 3); imaille++)
993 cout << " Maille " << imaille << endl;
994 for (icomp = 0; icomp < nCompChamp; icomp++)
995 cout << " " << *(valr2 + imaille * nCompChamp + icomp);
1006 } // boucle sur les pas de temps
1011 std::string MESHCUT::nomMaille(TYPE_MAILLE tm, int nl)
1013 return (TM2string(tm) + (string) "_" + int2string(nl));
1016 bool MESHCUT::appartientVN(int n, std::vector<int> V)
1019 for (unsigned int i = 0; i < V.size(); i++)
1028 float MESHCUT::distance2(float x1, float y1, float z1, float x2, float y2, float z2)
1030 return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
1034 * Conversion HL-MED d'une table de connectivités
1036 void MESHCUT::conversionCNX(int *CNXtm, TYPE_MAILLE tm, int N)
1039 int n = Nnoeuds(tm);
1043 for (int i = 0; i < N; i++)
1045 int i1 = CNXtm[i * n + 1];
1046 int i2 = CNXtm[i * n + 2];
1047 CNXtm[i * n + 1] = i2;
1048 CNXtm[i * n + 2] = i1;
1051 else if (tm == PYRAM5)
1053 for (int i = 0; i < N; i++)
1055 int i1 = CNXtm[i * n + 1];
1056 int i3 = CNXtm[i * n + 3];
1057 CNXtm[i * n + 1] = i3;
1058 CNXtm[i * n + 3] = i1;
1061 else if (tm == PENTA6)
1063 for (int i = 0; i < N; i++)
1065 int i0 = CNXtm[i * n + 0];
1066 int i1 = CNXtm[i * n + 1];
1067 int i2 = CNXtm[i * n + 2];
1068 int i3 = CNXtm[i * n + 3];
1069 int i4 = CNXtm[i * n + 4];
1070 int i5 = CNXtm[i * n + 5];
1071 CNXtm[i * n + 0] = i3;
1072 CNXtm[i * n + 1] = i4;
1073 CNXtm[i * n + 2] = i5;
1074 CNXtm[i * n + 3] = i0;
1075 CNXtm[i * n + 4] = i1;
1076 CNXtm[i * n + 5] = i2;
1080 else if (tm == HEXA8)
1082 for (int i = 0; i < N; i++)
1084 int i0 = CNXtm[i * n + 0];
1085 int i1 = CNXtm[i * n + 1];
1086 int i2 = CNXtm[i * n + 2];
1087 int i3 = CNXtm[i * n + 3];
1088 int i4 = CNXtm[i * n + 4];
1089 int i5 = CNXtm[i * n + 5];
1090 int i6 = CNXtm[i * n + 6];
1091 int i7 = CNXtm[i * n + 7];
1092 CNXtm[i * n + 0] = i4;
1093 CNXtm[i * n + 1] = i5;
1094 CNXtm[i * n + 2] = i6;
1095 CNXtm[i * n + 3] = i7;
1096 CNXtm[i * n + 4] = i0;
1097 CNXtm[i * n + 5] = i1;
1098 CNXtm[i * n + 6] = i2;
1099 CNXtm[i * n + 7] = i3;