1 // Copyright (C) 2006-2016 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"
31 using namespace MESHCUT;
33 //string pathUsers = (string) "/var/www/XMeshLab/users/";
35 bool MESHCUT::estUnTypeMaille(std::string S)
37 if (S == (string) "POI1" || S == (string) "SEG2" || S == (string) "SEG3" || S == (string) "TRIA3" || S
38 == (string) "TRIA6" || S == (string) "QUAD4" || S == (string) "QUAD8" || S == (string) "QUAD9" || S
39 == (string) "TETRA4" || S == (string) "TETRA10" || S == (string) "PYRAM5" || S == (string) "PYRAM13" || S
40 == (string) "PENTA6" || S == (string) "PENTA15" || S == (string) "HEXA8" || S == (string) "HEXA20" || S
47 void MESHCUT::ERREUR(const char* msg)
49 cout << endl << "====== ERROR ====== " << msg << endl << endl;
53 char* MESHCUT::string2char(std::string str)
55 // créer le buffer pour copier la chaîne
56 size_t size = str.size() + 1;
57 char* buffer = new char[size];
59 strncpy(buffer, str.c_str(), size);
67 std::string MESHCUT::int2string(int k)
69 std::stringstream oss;
71 return oss.str(); // oss.seekp (ios_base::beg);
74 float MESHCUT::char2float(const char* ch)
79 std::string MESHCUT::float2string(float f)
87 bool MESHCUT::appartient(std::string e, std::string tableau[], int taille)
89 for (int i = 0; i < taille; i++)
95 float MESHCUT::arrondi(float x)
97 if (x > 0 && x < 1.0e-5)
99 else if (x < 0 && x > -1.0e-5)
105 int MESHCUT::numNoeudPointe(std::string b1, std::string b2, std::string b3)
107 if (b1 == "1" && b2 == "1" && b3 == "2")
109 else if (b1 == "1" && b2 == "2" && b3 == "1")
111 else if (b1 == "1" && b2 == "2" && b3 == "2")
113 else if (b1 == "2" && b2 == "1" && b3 == "1")
115 else if (b1 == "2" && b2 == "1" && b3 == "2")
117 else if (b1 == "2" && b2 == "2" && b3 == "1")
123 std::string MESHCUT::strip(std::string S)
127 int startIndex = S.find_first_not_of(" ");
128 int endIndex = S.find_last_not_of(" ");
129 return S.substr(startIndex, (endIndex - startIndex + 1));
132 std::string MESHCUT::entierSur10_g(int i)
135 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
137 return int2string(i) + (string) " ";
139 return int2string(i) + (string) " ";
141 return int2string(i) + (string) " ";
143 return int2string(i) + (string) " ";
145 return int2string(i) + (string) " ";
146 else if (i < 1000000)
147 return int2string(i) + (string) " ";
148 else if (i < 10000000)
149 return int2string(i) + (string) " ";
150 else if (i < 100000000)
151 return int2string(i) + (string) " ";
152 else if (i < 1000000000)
153 return int2string(i) + (string) " ";
155 return int2string(i);
158 std::string MESHCUT::entierSur10_d(int i)
161 ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
163 return (string) " " + int2string(i);
165 return (string) " " + int2string(i);
167 return (string) " " + int2string(i);
169 return (string) " " + int2string(i);
171 return (string) " " + int2string(i);
172 else if (i < 1000000)
173 return (string) " " + int2string(i);
174 else if (i < 10000000)
175 return (string) " " + int2string(i);
176 else if (i < 100000000)
177 return (string) " " + int2string(i);
178 else if (i < 1000000000)
179 return (string) " " + int2string(i);
181 return int2string(i);
184 std::string MESHCUT::typeEnsight(std::string type)
186 if (type == (string) "POI1")
187 return (string) "point";
188 else if (type == (string) "SEG2")
189 return (string) "bar2";
190 else if (type == (string) "SEG3")
191 return (string) "bar2";// ATTENTION, triche!
192 else if (type == (string) "TRIA3")
193 return (string) "tria3";
194 else if (type == (string) "TRIA6")
195 return (string) "tria3";// ATTENTION, triche!
196 else if (type == (string) "QUAD4")
197 return (string) "quad4";
198 else if (type == (string) "QUAD8")
199 return (string) "quad4"; // ATTENTION, triche!
200 else if (type == (string) "QUAD9")
201 ERREUR("Type QUAD9 not supported by Ensight");
202 else if (type == (string) "TETRA4")
203 return (string) "tetra4";
204 else if (type == (string) "TETRA10")
205 return (string) "tetra4"; // ATTENTION, triche!
206 else if (type == (string) "PYRAM5")
207 return (string) "pyramid5";
208 else if (type == (string) "PYRAM13")
209 return (string) "pyramid5"; // ATTENTION, triche!
210 else if (type == (string) "PENTA6")
211 return (string) "penta6";
212 else if (type == (string) "PENTA15")
213 return (string) "penta6"; // ATTENTION, triche!
214 else if (type == (string) "HEXA8")
215 return (string) "hexa8";
216 else if (type == (string) "HEXA20")
217 return (string) "hexa8"; // ATTENTION, triche!
218 else if (type == (string) "HEXA27")
219 ERREUR("Type HEXA27 not supported by Ensight");
221 ERREUR("Type of element not accepted (method \"typeEnsight\"");
225 int MESHCUT::Nnoeuds(TYPE_MAILLE type)
264 //case QUAD9: { return 9; break; }
305 //case HEXA27: { return 27; break; }
307 ERREUR("Type of elem not accepted (method Nnoeuds)");
312 int MESHCUT::NnoeudsGeom(TYPE_MAILLE type)
351 //case QUAD9: { return 9; break; }
392 //case HEXA27: { return 27; break; }
394 ERREUR("Type of elem not accepted (method NnoeudsGeom)");
399 int MESHCUT::codeGMSH(std::string type)
401 if (type == (string) "POI1")
402 ERREUR("POI1 not taken into account by GMSH");
403 else if (type == (string) "SEG2")
405 else if (type == (string) "SEG3")
407 else if (type == (string) "TRIA3")
409 else if (type == (string) "TRIA6")
411 else if (type == (string) "QUAD4")
413 else if (type == (string) "QUAD8")
415 else if (type == (string) "QUAD9")
417 else if (type == (string) "TETRA4")
419 else if (type == (string) "TETRA10")
421 else if (type == (string) "PYRAM5")
423 else if (type == (string) "PENTA6")
425 else if (type == (string) "PENTA15")
427 else if (type == (string) "HEXA8")
429 else if (type == (string) "HEXA20")
431 else if (type == (string) "HEXA27")
434 ERREUR("Type of elem not accepted (method codeGMSH)");
438 std::string MESHCUT::floatEnsight(float x)
443 sprintf(buf, "%1.5E", x);
445 sprintf(buf, " %1.5E", x);
451 bool MESHCUT::typeComplexe(std::string type)
453 if (type == (string) "SEG3")
455 else if (type == (string) "TRIA6")
457 else if (type == (string) "QUAD8")
459 else if (type == (string) "QUAD9")
461 else if (type == (string) "TETRA10")
463 else if (type == (string) "PYRAM13")
465 else if (type == (string) "PENTA15")
467 else if (type == (string) "HEXA20")
469 else if (type == (string) "HEXA27")
475 std::string MESHCUT::ASTER8(std::string s)
478 return (s + (string) " ");
479 else if (s.size() == 1)
480 return (s + (string) " ");
481 else if (s.size() == 2)
482 return (s + (string) " ");
483 else if (s.size() == 3)
484 return (s + (string) " ");
485 else if (s.size() == 4)
486 return (s + (string) " ");
487 else if (s.size() == 5)
488 return (s + (string) " ");
489 else if (s.size() == 6)
490 return (s + (string) " ");
491 else if (s.size() == 7)
492 return (s + (string) " ");
493 else if (s.size() == 8)
496 ERREUR("More than 8 char for an ASTER string");
501 * Distance à laquelle doit se tenir l'observateur sur un axe
502 * pour voir sous 90° un objet centré de dimensions a et b selon les deux autres axes.
503 * Si on ne tient pas compte de la dimension de l'objet selon l'axe choisi,
504 * la formule d_obs=max(a,b)/2 donne la cote
505 * qui permet de voir l'objet plat dans un angle de 90°.
506 * A cela il faut ajouter la dimension de l'objet selon l'axe d'observation = c.
508 * @param a dimensions de l'objet selon un des axes normal à l'axe d'observation
509 * @param b dimensions de l'objet selon l'autre axe normal à l'axe d'observation
510 * @param c est la dimension de l'objet selon l'axe d'observation
512 float MESHCUT::dObservateur(float a, float b, float c)
514 return (max(a, b) / 2.0 + c);
517 int MESHCUT::copieFichier(std::string source, std::string cible)
519 FILE *fsource, *fcible;
522 if ((fsource = fopen(string2char(source), "rb")) == NULL)
524 if ((fcible = fopen(string2char(cible), "wb")) == NULL)
529 while ((NbLu = fread(buffer, 1, 512, fsource)) != 0)
530 fwrite(buffer, 1, NbLu, fcible);
536 med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
538 med_geometry_type typeBanaliseMED = MED_NONE;
543 typeBanaliseMED = MED_POINT1;
544 break; // Attention, piège !
546 typeBanaliseMED = MED_SEG2;
549 typeBanaliseMED = MED_SEG3;
552 typeBanaliseMED = MED_TRIA3;
555 typeBanaliseMED = MED_TRIA6;
558 typeBanaliseMED = MED_QUAD4;
561 typeBanaliseMED = MED_QUAD8;
564 typeBanaliseMED = MED_TETRA4;
567 typeBanaliseMED = MED_TETRA10;
570 typeBanaliseMED = MED_PYRA5;
571 break; // Attention, piège !
573 typeBanaliseMED = MED_PYRA13;
574 break; // Attention, piège !
576 typeBanaliseMED = MED_PENTA6;
579 typeBanaliseMED = MED_PENTA15;
582 typeBanaliseMED = MED_HEXA8;
585 typeBanaliseMED = MED_HEXA20;
588 ERREUR("Method InstanceMGE, unknown type ");
590 return typeBanaliseMED;
593 int MESHCUT::salome_chrono()
595 return clock() / CLOCKS_PER_SEC;
598 TYPE_MAILLE MESHCUT::typeMaille(std::string type)
600 if (type == (string) "POI1")
602 else if (type == (string) "SEG2")
604 else if (type == (string) "SEG3")
606 else if (type == (string) "TRIA3")
608 else if (type == (string) "TRIA6")
610 else if (type == (string) "QUAD4")
612 else if (type == (string) "QUAD8")
614 else if (type == (string) "TETRA4")
616 else if (type == (string) "TETRA10")
618 else if (type == (string) "PYRAM5")
620 else if (type == (string) "PYRAM13")
622 else if (type == (string) "PENTA6")
624 else if (type == (string) "PENTA15")
626 else if (type == (string) "HEXA8")
628 else if (type == (string) "HEXA20")
631 ERREUR("ERROR method typeMaille, unknown type");
635 std::string MESHCUT::MGE2string(med_geometry_type MGE)
638 return (string) "NOEUD";
639 else if (MGE == MED_POINT1)
640 return (string) "POI1";
641 else if (MGE == MED_SEG2)
642 return (string) "SEG2";
643 else if (MGE == MED_SEG3)
644 return (string) "SEG3";
645 else if (MGE == MED_TRIA3)
646 return (string) "TRIA3";
647 else if (MGE == MED_TRIA6)
648 return (string) "TRIA6";
649 else if (MGE == MED_QUAD4)
650 return (string) "QUAD4";
651 else if (MGE == MED_QUAD8)
652 return (string) "QUAD8";
653 else if (MGE == MED_TETRA4)
654 return (string) "TETRA4";
655 else if (MGE == MED_TETRA10)
656 return (string) "TETRA10";
657 else if (MGE == MED_PYRA5)
658 return (string) "PYRAM5";
659 else if (MGE == MED_PYRA13)
660 return (string) "PYRAM13";
661 else if (MGE == MED_PENTA6)
662 return (string) "PENTA6";
663 else if (MGE == MED_PENTA15)
664 return (string) "PENTA15";
665 else if (MGE == MED_HEXA8)
666 return (string) "HEXA8";
667 else if (MGE == MED_HEXA20)
668 return (string) "HEXA20";
670 ERREUR("ERROR method MGE2string, unknown type");
671 return (string) "NOEUD";
674 std::string MESHCUT::TM2string(TYPE_MAILLE MGE)
677 return (string) "POI1";
678 else if (MGE == SEG2)
679 return (string) "SEG2";
680 else if (MGE == SEG3)
681 return (string) "SEG3";
682 else if (MGE == TRIA3)
683 return (string) "TRIA3";
684 else if (MGE == TRIA6)
685 return (string) "TRIA6";
686 else if (MGE == QUAD4)
687 return (string) "QUAD4";
688 else if (MGE == QUAD8)
689 return (string) "QUAD8";
690 else if (MGE == TETRA4)
691 return (string) "TETRA4";
692 else if (MGE == TETRA10)
693 return (string) "TETRA10";
694 else if (MGE == PYRAM5)
695 return (string) "PYRAM5";
696 else if (MGE == PYRAM13)
697 return (string) "PYRAM13";
698 else if (MGE == PENTA6)
699 return (string) "PENTA6";
700 else if (MGE == PENTA15)
701 return (string) "PENTA15";
702 else if (MGE == HEXA8)
703 return (string) "HEXA8";
704 else if (MGE == HEXA20)
705 return (string) "HEXA20";
707 ERREUR("ERROR method TM2string, unknown type");
708 return (string) "POI1";
711 TYPE_MAILLE MESHCUT::string2TM(std::string stm)
713 if (stm == (string) "POI1")
715 else if (stm == (string) "SEG2")
717 else if (stm == (string) "SEG3")
719 else if (stm == (string) "TRIA3")
721 else if (stm == (string) "TRIA6")
723 else if (stm == (string) "QUAD4")
725 else if (stm == (string) "QUAD8")
727 else if (stm == (string) "TETRA4")
729 else if (stm == (string) "TETRA10")
731 else if (stm == (string) "PYRAM5")
733 else if (stm == (string) "PYRAM13")
735 else if (stm == (string) "PENTA6")
737 else if (stm == (string) "PENTA15")
739 else if (stm == (string) "HEXA8")
741 else if (stm == (string) "HEXA20")
744 ERREUR("ERROR method string2TM, unknown type");
748 std::string MESHCUT::coordIndex_ILS(TYPE_MAILLE tm)
751 return (string) " 0,1 ";
753 return (string) " 0,1 "; // Idem SEG2
754 else if (tm == TRIA3)
755 return (string) " 0,1,2,0 ";
756 else if (tm == TRIA6)
757 return (string) " 0,1,2,0 ";
758 else if (tm == QUAD4)
759 return (string) " 0,1,2,3,0 ";
760 else if (tm == QUAD8)
761 return (string) " 0,1,2,3,0 ";
762 else if (tm == TETRA4)
763 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
764 else if (tm == TETRA10)
765 return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
766 else if (tm == PYRAM5)
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 == PYRAM13)
769 return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
770 else if (tm == PENTA6)
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 == PENTA15)
773 return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
774 else if (tm == HEXA8)
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 ";
776 else if (tm == HEXA20)
777 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 ";
782 std::string MESHCUT::coordIndex_IFS(TYPE_MAILLE tm)
787 return (string) " "; // Idem SEG2
788 else if (tm == TRIA3)
789 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
790 else if (tm == TRIA6)
791 return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
792 else if (tm == QUAD4)
793 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
794 else if (tm == QUAD8)
795 return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
796 else if (tm == TETRA4)
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 == TETRA10)
799 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 ";
800 else if (tm == PYRAM5)
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 == PYRAM13)
803 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 ";
804 else if (tm == PENTA6)
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 == PENTA15)
807 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 ";
808 else if (tm == HEXA8)
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 ";
810 else if (tm == HEXA20)
811 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 ";
816 std::string MESHCUT::SIGNE(double x)
826 void MESHCUT::champType(std::string type, med_entity_type MEM, med_geometry_type MGE, med_idt fid, med_idt fidout,
827 char *maa, char *nomChamp, char *nomChampMoy, med_field_type typeChamp, char *compChamp,
828 char *unitChamp, med_int nCompChamp, std::map<std::string, int> REFGAUSS, int ichamp)
832 int ipt, nmailles, ngauss, imaille, igauss, icomp;
834 med_int nval, numdt, numo, nPasTemps;
835 char dtunit[MED_SNAME_SIZE + 1] = "";
836 char locname[MED_NAME_SIZE + 1] = "";
837 char nomprofil[MED_NAME_SIZE + 1] = "";
839 med_float *valr = NULL;
840 med_float *valr2 = NULL;
843 med_field_type fieldType;
845 if (MEDfieldInfo(fid, ichamp, nomChamp, maa, &local, &fieldType, compChamp, unitChamp, dtunit, &nPasTemps) < 0)
846 ERREUR("Error MEDfieldInfo");
847 cout << type << " : " << (int) nPasTemps << " timestep " << endl;
849 for (ipt = 1; ipt <= nPasTemps; ipt++)
851 //for (ipt=1; ipt<=min(nPasTemps,1); ipt++) {
855 cout << "************************************************************" << endl;
857 cout << " FIELD " << ichamp << endl;
859 cout << " " << nomChamp << endl;
861 cout << " " << type << " --- Timestep " << ipt << endl;
863 cout << "************************************************************" << endl;
867 if (MEDfieldComputingStepInfo(fid, nomChamp, ipt, &numdt, &numo, &dt) < 0)
870 cout << endl << "####################################################################" << endl;
871 cout << " ERROR MEDpasdetempsInfo " << endl;
872 cout << endl << "####################################################################" << endl;
873 cout << " Field: " << (string) nomChamp << endl;
874 cout << " Geometrie: " << MGE2string(MGE) << endl;
875 cout << " Timestep " << ipt << " ignored" << endl;
880 med_int profilesize, nintegrationpoint;
881 nval = MEDfieldnValueWithProfile(fid, nomChamp, numdt, numo, MEM, MGE, ipt, MED_COMPACT_PFLMODE, nomprofil,
882 &profilesize, locname, &nintegrationpoint);
884 cout << " Number of values in this timestep: " << (int) nval << endl;
886 if (typeChamp == MED_FLOAT64)
887 valr = (med_float*) calloc(nCompChamp * nval, sizeof(med_float));
889 ERREUR("Type of field not taken into account");
891 if (MEDfieldValueWithProfileRd(fid, maa, numdt, numo, MEM, MGE, MED_COMPACT_PFLMODE, nomprofil,
892 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0)
895 cout << endl << "####################################################################" << endl;
896 cout << " ERROR MEDchampLire " << endl;
897 cout << endl << "####################################################################" << endl;
899 cout << " Field: " << (string) nomChamp << endl;
900 cout << " Geometry: " << MGE2string(MGE) << endl;
901 cout << " Timestep " << ipt << " ignored" << endl;
902 cout << endl << endl;
907 cout << " profile = " << (string) nomprofil << endl;
908 // Localisation du champ aux points de Gauss
910 cout << " locname = " << (string) locname << endl;
912 if (REFGAUSS[(string) locname])
914 ngauss = REFGAUSS[(string) locname];
916 cout << " " << ngauss << " Gauss points by element)" << endl;
921 nmailles = nval / ngauss;
923 cout << " Nbre de mailles: " << nmailles << endl;
927 cout << endl << " Liste des valeurs du champ brut aux 3 premiers éléments:" << endl;
928 for (imaille = 0; imaille < std::min(nmailles, 3); imaille++)
930 cout << " Maille " << imaille << endl;
931 for (igauss = 0; igauss < ngauss; igauss++)
933 cout << " PG " << igauss << " : ";
934 for (icomp = 0; icomp < nCompChamp; icomp++)
935 cout << " " << *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
946 valr2 = (med_float*) calloc(nCompChamp * nmailles, sizeof(med_float));
949 cout << endl << " Moyenne sur les PG des mailles" << endl;
950 for (imaille = 0; imaille < nmailles; imaille++)
952 for (icomp = 0; icomp < nCompChamp; icomp++)
954 float valCompMaille = 0.0;
955 for (igauss = 0; igauss < ngauss; igauss++)
956 valCompMaille += *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
957 *(valr2 + imaille * nCompChamp + icomp) = valCompMaille / ngauss;
962 //cout << endl << "Nom champ moy = " << (string)nomChampMoy << endl;
963 //cout << endl << "Type champ = " << typeChamp << endl;
964 //cout << endl << "Comp champ = " << (string)compChamp << endl;
965 //cout << endl << "Unit champ = " << (string)unitChamp << endl;
966 //cout << endl << "N comp champ = " << nCompChamp << endl;
968 if (MEDfieldValueWithProfileWr(fidout, nomChampMoy, numdt, numo, dt, MEM, MGE, MED_COMPACT_PFLMODE,
969 nomprofil, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
970 (med_int) nmailles, (unsigned char*) valr2) < 0)
973 cout << endl << "********************************************************************" << endl;
974 cout << "******************** ***********************" << endl;
975 cout << "******************** ERROR MEDchampEcr ***********************" << endl;
976 cout << "******************** ***********************" << endl;
977 cout << "********************************************************************" << endl;
979 cout << " Champ: " << (string) nomChampMoy << endl;
980 cout << " Géométrie: " << MGE2string(MGE) << endl;
981 cout << " Pas de temps " << ipt << " ignoré" << endl;
982 cout << endl << endl;
987 cout << " Writing mean values in new field: OK " << endl;
989 // Restitution du champ moyenné
992 cout << endl << " Liste des valeurs du champ moyenné aux 3 premiers éléments:" << endl;
993 for (imaille = 0; imaille < min(nmailles, 3); imaille++)
995 cout << " Maille " << imaille << endl;
996 for (icomp = 0; icomp < nCompChamp; icomp++)
997 cout << " " << *(valr2 + imaille * nCompChamp + icomp);
1008 } // boucle sur les pas de temps
1013 std::string MESHCUT::nomMaille(TYPE_MAILLE tm, int nl)
1015 return (TM2string(tm) + (string) "_" + int2string(nl));
1018 bool MESHCUT::appartientVN(int n, std::vector<int> V)
1021 for (unsigned int i = 0; i < V.size(); i++)
1030 float MESHCUT::distance2(float x1, float y1, float z1, float x2, float y2, float z2)
1032 return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
1036 * Conversion HL-MED d'une table de connectivités
1038 void MESHCUT::conversionCNX(int *CNXtm, TYPE_MAILLE tm, int N)
1041 int n = Nnoeuds(tm);
1045 for (int i = 0; i < N; i++)
1047 int i1 = CNXtm[i * n + 1];
1048 int i2 = CNXtm[i * n + 2];
1049 CNXtm[i * n + 1] = i2;
1050 CNXtm[i * n + 2] = i1;
1053 else if (tm == PYRAM5)
1055 for (int i = 0; i < N; i++)
1057 int i1 = CNXtm[i * n + 1];
1058 int i3 = CNXtm[i * n + 3];
1059 CNXtm[i * n + 1] = i3;
1060 CNXtm[i * n + 3] = i1;
1063 else if (tm == PENTA6)
1065 for (int i = 0; i < N; i++)
1067 int i0 = CNXtm[i * n + 0];
1068 int i1 = CNXtm[i * n + 1];
1069 int i2 = CNXtm[i * n + 2];
1070 int i3 = CNXtm[i * n + 3];
1071 int i4 = CNXtm[i * n + 4];
1072 int i5 = CNXtm[i * n + 5];
1073 CNXtm[i * n + 0] = i3;
1074 CNXtm[i * n + 1] = i4;
1075 CNXtm[i * n + 2] = i5;
1076 CNXtm[i * n + 3] = i0;
1077 CNXtm[i * n + 4] = i1;
1078 CNXtm[i * n + 5] = i2;
1082 else if (tm == HEXA8)
1084 for (int i = 0; i < N; i++)
1086 int i0 = CNXtm[i * n + 0];
1087 int i1 = CNXtm[i * n + 1];
1088 int i2 = CNXtm[i * n + 2];
1089 int i3 = CNXtm[i * n + 3];
1090 int i4 = CNXtm[i * n + 4];
1091 int i5 = CNXtm[i * n + 5];
1092 int i6 = CNXtm[i * n + 6];
1093 int i7 = CNXtm[i * n + 7];
1094 CNXtm[i * n + 0] = i4;
1095 CNXtm[i * n + 1] = i5;
1096 CNXtm[i * n + 2] = i6;
1097 CNXtm[i * n + 3] = i7;
1098 CNXtm[i * n + 4] = i0;
1099 CNXtm[i * n + 5] = i1;
1100 CNXtm[i * n + 6] = i2;
1101 CNXtm[i * n + 7] = i3;