1 // Copyright (C) 2007-2015 CEA/DEN, 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
19 // File : SauvMedConvertor.cxx
20 // Created : Tue Aug 16 14:43:20 2011
21 // Author : Edward AGAPOV (eap)
24 #include "SauvMedConvertor.hxx"
26 #include "CellModel.hxx"
27 #include "MEDFileMesh.hxx"
28 #include "MEDFileField.hxx"
29 #include "MEDFileData.hxx"
30 #include "MEDCouplingFieldDouble.hxx"
49 #include <rpc/types.h>
53 using namespace SauvUtilities;
54 using namespace ParaMEDMEM;
58 // for ASCII file reader
59 const int GIBI_MaxOutputLen = 150; // max length of a line in the sauve file
60 const int GIBI_BufferSize = 16184; // for buffered reading
62 using namespace INTERP_KERNEL;
64 const size_t MaxMedCellType = NORM_ERROR;
65 const size_t NbGibiCellTypes = 47;
66 const TCellType GibiTypeToMed[NbGibiCellTypes] =
68 /*1 */ NORM_POINT1 ,/*2 */ NORM_SEG2 ,/*3 */ NORM_SEG3 ,/*4 */ NORM_TRI3 ,/*5 */ NORM_ERROR ,
69 /*6 */ NORM_TRI6 ,/*7 */ NORM_ERROR ,/*8 */ NORM_QUAD4 ,/*9 */ NORM_ERROR ,/*10*/ NORM_QUAD8 ,
70 /*11*/ NORM_ERROR ,/*12*/ NORM_ERROR ,/*13*/ NORM_ERROR ,/*14*/ NORM_HEXA8 ,/*15*/ NORM_HEXA20 ,
71 /*16*/ NORM_PENTA6 ,/*17*/ NORM_PENTA15,/*18*/ NORM_ERROR ,/*19*/ NORM_ERROR ,/*20*/ NORM_ERROR ,
72 /*21*/ NORM_ERROR ,/*22*/ NORM_ERROR ,/*23*/ NORM_TETRA4 ,/*24*/ NORM_TETRA10,/*25*/ NORM_PYRA5 ,
73 /*26*/ NORM_PYRA13 ,/*27*/ NORM_ERROR ,/*28*/ NORM_ERROR ,/*29*/ NORM_ERROR ,/*30*/ NORM_ERROR ,
74 /*31*/ NORM_ERROR ,/*32*/ NORM_ERROR ,/*33*/ NORM_ERROR ,/*34*/ NORM_ERROR ,/*35*/ NORM_ERROR ,
75 /*36*/ NORM_ERROR ,/*37*/ NORM_ERROR ,/*38*/ NORM_ERROR ,/*39*/ NORM_ERROR ,/*40*/ NORM_ERROR ,
76 /*41*/ NORM_ERROR ,/*42*/ NORM_ERROR ,/*43*/ NORM_ERROR ,/*44*/ NORM_ERROR ,/*45*/ NORM_ERROR ,
77 /*46*/ NORM_ERROR ,/*47*/ NORM_ERROR
80 //================================================================================
82 * \brief Return dimension of a group
84 //================================================================================
86 unsigned getDim( const Group* grp )
88 return SauvUtilities::getDimension( grp->_groups.empty() ? grp->_cellType : grp->_groups[0]->_cellType );
91 //================================================================================
93 * \brief Converts connectivity of quadratic elements
95 //================================================================================
97 inline void ConvertQuadratic( const INTERP_KERNEL::NormalizedCellType type,
100 if ( const int * conn = getGibi2MedQuadraticInterlace( type ))
102 Cell* ma = const_cast<Cell*>(&aCell);
103 std::vector< Node* > new_nodes( ma->_nodes.size() );
104 for (std:: size_t i = 0; i < new_nodes.size(); ++i )
105 new_nodes[ i ] = ma->_nodes[ conn[ i ]];
106 ma->_nodes.swap( new_nodes );
110 //================================================================================
112 * \brief Returns a vector of pairs of node indices to inverse a med volume element
114 //================================================================================
116 void getReverseVector (const INTERP_KERNEL::NormalizedCellType type,
117 std::vector<std::pair<int,int> > & swapVec )
125 swapVec[0] = std::make_pair( 1, 2 );
129 swapVec[0] = std::make_pair( 1, 3 );
133 swapVec[0] = std::make_pair( 1, 2 );
134 swapVec[1] = std::make_pair( 4, 5 );
138 swapVec[0] = std::make_pair( 1, 3 );
139 swapVec[1] = std::make_pair( 5, 7 );
143 swapVec[0] = std::make_pair( 1, 2 );
144 swapVec[1] = std::make_pair( 4, 6 );
145 swapVec[2] = std::make_pair( 8, 9 );
149 swapVec[0] = std::make_pair( 1, 3 );
150 swapVec[1] = std::make_pair( 5, 8 );
151 swapVec[2] = std::make_pair( 6, 7 );
152 swapVec[3] = std::make_pair( 10, 12 );
156 swapVec[0] = std::make_pair( 1, 2 );
157 swapVec[1] = std::make_pair( 4, 5 );
158 swapVec[2] = std::make_pair( 6, 8 );
159 swapVec[3] = std::make_pair( 9, 11 );
163 swapVec[0] = std::make_pair( 1, 3 );
164 swapVec[1] = std::make_pair( 5, 7 );
165 swapVec[2] = std::make_pair( 8, 11 );
166 swapVec[3] = std::make_pair( 9, 10 );
167 swapVec[4] = std::make_pair( 12, 15 );
168 swapVec[5] = std::make_pair( 13, 14 );
169 swapVec[6] = std::make_pair( 17, 19 );
171 // case NORM_SEG3: no need to reverse edges
172 // swapVec.resize(1);
173 // swapVec[0] = std::make_pair( 1, 2 );
177 swapVec[0] = std::make_pair( 1, 2 );
178 swapVec[1] = std::make_pair( 3, 5 );
182 swapVec[0] = std::make_pair( 1, 3 );
183 swapVec[1] = std::make_pair( 4, 7 );
184 swapVec[2] = std::make_pair( 5, 6 );
190 //================================================================================
192 * \brief Inverses element orientation using vector of indices to swap
194 //================================================================================
196 inline void reverse(const Cell & aCell, const std::vector<std::pair<int,int> > & swapVec )
198 Cell* ma = const_cast<Cell*>(&aCell);
199 for ( unsigned i = 0; i < swapVec.size(); ++i )
200 std::swap( ma->_nodes[ swapVec[i].first ],
201 ma->_nodes[ swapVec[i].second ]);
202 if ( swapVec.empty() )
205 ma->_reverse = false;
207 //================================================================================
209 * \brief Comparator of cells by number used for ordering cells within a med group
211 struct TCellByIDCompare
213 bool operator () (const Cell* i1, const Cell* i2) const
215 return i1->_number < i2->_number;
218 typedef std::map< const Cell*, unsigned, TCellByIDCompare > TCellToOrderMap;
220 //================================================================================
222 * \brief Fill Group::_relocTable if necessary
224 //================================================================================
226 void setRelocationTable( Group* grp, TCellToOrderMap& cell2order )
228 if ( !grp->_isProfile ) return;
230 // check if relocation table is necessary
231 bool isRelocated = false;
232 unsigned newOrder = 0;
233 TCellToOrderMap::iterator c2oIt = cell2order.begin(), c2oEnd = cell2order.end();
234 for ( ; !isRelocated && c2oIt != c2oEnd; ++c2oIt, ++newOrder )
235 isRelocated = ( c2oIt->second != newOrder );
239 grp->_relocTable.resize( cell2order.size() );
240 for ( newOrder = 0, c2oIt = cell2order.begin(); c2oIt != c2oEnd; ++c2oIt, ++newOrder )
241 grp->_relocTable[ c2oIt->second ] = newOrder;
246 namespace // define default GAUSS points
248 typedef std::vector<double> TDoubleVector;
249 typedef double* TCoordSlice;
251 //---------------------------------------------------------------
252 //! Shape function definitions
253 //---------------------------------------------------------------
258 TDoubleVector myRefCoord;
260 TShapeFun(TInt theDim = 0, TInt theNbRef = 0)
261 :myDim(theDim),myNbRef(theNbRef),myRefCoord(theNbRef*theDim) {}
263 TInt GetNbRef() const { return myNbRef; }
265 TCoordSlice GetCoord(TInt theRefId) { return &myRefCoord[0] + theRefId * myDim; }
267 //---------------------------------------------------------------
269 * \brief Description of family of integration points
271 //---------------------------------------------------------------
274 int myType; //!< element geometry (EGeometrieElement or med_geometrie_element)
275 TDoubleVector myRefCoords; //!< description of reference points
276 TDoubleVector myCoords; //!< coordinates of Gauss points
277 TDoubleVector myWeights; //!< weights, len(weights)==<nb of gauss points>
280 * \brief Creates definition of gauss points family
281 * \param geomType - element geometry (EGeometrieElement or med_geometrie_element)
282 * \param nbPoints - nb gauss point
283 * \param variant - [1-3] to choose the variant of definition
285 * Throws in case of invalid parameters
286 * variant == 1 refers to "Fonctions de forme et points d'integration
287 * des elements finis" v7.4 by J. PELLET, X. DESROCHES, 15/09/05
288 * variant == 2 refers to the same doc v6.4 by J.P. LEFEBVRE, X. DESROCHES, 03/07/03
289 * variant == 3 refers to the same doc v6.4, second variant for 2D elements
291 TGaussDef(const int geomType, const int nbPoints, const int variant=1);
293 int dim() const { return SauvUtilities::getDimension( NormalizedCellType( myType )); }
294 int nbPoints() const { return myWeights.capacity(); }
297 void add(const double x, const double weight);
298 void add(const double x, const double y, const double weight);
299 void add(const double x, const double y, const double z, const double weight);
300 void setRefCoords(const TShapeFun& aShapeFun) { myRefCoords = aShapeFun.myRefCoord; }
302 struct TSeg2a: TShapeFun {
305 struct TSeg3a: TShapeFun {
308 struct TTria3a: TShapeFun {
311 struct TTria6a: TShapeFun {
314 struct TTria3b: TShapeFun {
317 struct TTria6b: TShapeFun {
320 struct TQuad4a: TShapeFun {
323 struct TQuad8a: TShapeFun {
326 struct TQuad4b: TShapeFun {
329 struct TQuad8b: TShapeFun {
332 struct TTetra4a: TShapeFun {
335 struct TTetra10a: TShapeFun {
338 struct TTetra4b: TShapeFun {
341 struct TTetra10b: TShapeFun {
344 struct THexa8a: TShapeFun {
347 struct THexa20a: TShapeFun {
348 THexa20a(TInt theDim = 3, TInt theNbRef = 20);
350 struct THexa27a: THexa20a {
353 struct THexa8b: TShapeFun {
356 struct THexa20b: TShapeFun {
357 THexa20b(TInt theDim = 3, TInt theNbRef = 20);
359 struct TPenta6a: TShapeFun {
362 struct TPenta6b: TShapeFun {
365 struct TPenta15a: TShapeFun {
368 struct TPenta15b: TShapeFun {
371 struct TPyra5a: TShapeFun {
374 struct TPyra5b: TShapeFun {
377 struct TPyra13a: TShapeFun {
380 struct TPyra13b: TShapeFun {
384 void TGaussDef::add(const double x, const double weight)
387 THROW_IK_EXCEPTION("TGaussDef: dim() != 1");
388 if ( myWeights.capacity() == myWeights.size() )
389 THROW_IK_EXCEPTION("TGaussDef: Extra gauss point");
390 myCoords.push_back( x );
391 myWeights.push_back( weight );
393 void TGaussDef::add(const double x, const double y, const double weight)
396 THROW_IK_EXCEPTION("TGaussDef: dim() != 2");
397 if ( myWeights.capacity() == myWeights.size() )
398 THROW_IK_EXCEPTION("TGaussDef: Extra gauss point");
399 myCoords.push_back( x );
400 myCoords.push_back( y );
401 myWeights.push_back( weight );
403 void TGaussDef::add(const double x, const double y, const double z, const double weight)
406 THROW_IK_EXCEPTION("TGaussDef: dim() != 3");
407 if ( myWeights.capacity() == myWeights.size() )
408 THROW_IK_EXCEPTION("TGaussDef: Extra gauss point");
409 myCoords.push_back( x );
410 myCoords.push_back( y );
411 myCoords.push_back( z );
412 myWeights.push_back( weight );
415 //---------------------------------------------------------------
416 TSeg2a::TSeg2a():TShapeFun(1,2)
418 TInt aNbRef = GetNbRef();
419 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
420 TCoordSlice aCoord = GetCoord(aRefId);
422 case 0: aCoord[0] = -1.0; break;
423 case 1: aCoord[0] = 1.0; break;
427 //---------------------------------------------------------------
428 TSeg3a::TSeg3a():TShapeFun(1,3)
430 TInt aNbRef = GetNbRef();
431 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
432 TCoordSlice aCoord = GetCoord(aRefId);
434 case 0: aCoord[0] = -1.0; break;
435 case 1: aCoord[0] = 1.0; break;
436 case 2: aCoord[0] = 0.0; break;
440 //---------------------------------------------------------------
444 TInt aNbRef = GetNbRef();
445 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
446 TCoordSlice aCoord = GetCoord(aRefId);
448 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
449 case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
450 case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
454 //---------------------------------------------------------------
455 TTria6a::TTria6a():TShapeFun(2,6)
457 TInt aNbRef = GetNbRef();
458 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
459 TCoordSlice aCoord = GetCoord(aRefId);
461 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
462 case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
463 case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
465 case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
466 case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break;
467 case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; break;
471 //---------------------------------------------------------------
475 TInt aNbRef = GetNbRef();
476 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
477 TCoordSlice aCoord = GetCoord(aRefId);
479 case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break;
480 case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break;
481 case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break;
485 //---------------------------------------------------------------
489 TInt aNbRef = GetNbRef();
490 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
491 TCoordSlice aCoord = GetCoord(aRefId);
493 case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break;
494 case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break;
495 case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break;
497 case 3: aCoord[0] = 0.5; aCoord[1] = 0.0; break;
498 case 4: aCoord[0] = 0.5; aCoord[1] = 0.5; break;
499 case 5: aCoord[0] = 0.0; aCoord[1] = 0.5; break;
503 //---------------------------------------------------------------
507 TInt aNbRef = GetNbRef();
508 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
509 TCoordSlice aCoord = GetCoord(aRefId);
511 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
512 case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
513 case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
514 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break;
518 //---------------------------------------------------------------
522 TInt aNbRef = GetNbRef();
523 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
524 TCoordSlice aCoord = GetCoord(aRefId);
526 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
527 case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
528 case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
529 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break;
531 case 4: aCoord[0] = -1.0; aCoord[1] = 0.0; break;
532 case 5: aCoord[0] = 0.0; aCoord[1] = -1.0; break;
533 case 6: aCoord[0] = 1.0; aCoord[1] = 0.0; break;
534 case 7: aCoord[0] = 0.0; aCoord[1] = 1.0; break;
538 //---------------------------------------------------------------
542 TInt aNbRef = GetNbRef();
543 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
544 TCoordSlice aCoord = GetCoord(aRefId);
546 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
547 case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
548 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break;
549 case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
553 //---------------------------------------------------------------
557 TInt aNbRef = GetNbRef();
558 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
559 TCoordSlice aCoord = GetCoord(aRefId);
561 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break;
562 case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break;
563 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break;
564 case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break;
566 case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break;
567 case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; break;
568 case 6: aCoord[0] = 0.0; aCoord[1] = 1.0; break;
569 case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; break;
573 //---------------------------------------------------------------
574 TTetra4a::TTetra4a():
577 TInt aNbRef = GetNbRef();
578 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
579 TCoordSlice aCoord = GetCoord(aRefId);
581 case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
582 case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
583 case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
584 case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
588 //---------------------------------------------------------------
589 TTetra10a::TTetra10a():
592 TInt aNbRef = GetNbRef();
593 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
594 TCoordSlice aCoord = GetCoord(aRefId);
596 case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
597 case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
598 case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
599 case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
601 case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
602 case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
603 case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
605 case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
606 case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
607 case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
611 //---------------------------------------------------------------
612 TTetra4b::TTetra4b():
615 TInt aNbRef = GetNbRef();
616 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
617 TCoordSlice aCoord = GetCoord(aRefId);
619 case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
620 case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
621 case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
622 case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
626 //---------------------------------------------------------------
627 TTetra10b::TTetra10b():
630 TInt aNbRef = GetNbRef();
631 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
632 TCoordSlice aCoord = GetCoord(aRefId);
634 case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
635 case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
636 case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
637 case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
639 case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
640 case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
641 case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
643 case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
644 case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
645 case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
649 //---------------------------------------------------------------
653 TInt aNbRef = GetNbRef();
654 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
655 TCoordSlice aCoord = GetCoord(aRefId);
657 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
658 case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
659 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
660 case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
661 case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
662 case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
663 case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
664 case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
668 //---------------------------------------------------------------
669 THexa20a::THexa20a(TInt theDim, TInt theNbRef):
670 TShapeFun(theDim,theNbRef)
672 TInt aNbRef = myRefCoord.size();
673 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
674 TCoordSlice aCoord = GetCoord(aRefId);
676 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
677 case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
678 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
679 case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
680 case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
681 case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
682 case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
683 case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
685 case 8: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
686 case 9: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break;
687 case 10: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
688 case 11: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break;
689 case 12: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
690 case 13: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
691 case 14: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
692 case 15: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
693 case 16: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
694 case 17: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
695 case 18: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
696 case 19: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
700 //---------------------------------------------------------------
701 THexa27a::THexa27a():
704 TInt aNbRef = myRefCoord.size();
705 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
706 TCoordSlice aCoord = GetCoord(aRefId);
708 case 20: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break;
709 case 21: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
710 case 22: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
711 case 23: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
712 case 24: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
713 case 25: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
714 case 26: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
718 //---------------------------------------------------------------
722 TInt aNbRef = GetNbRef();
723 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
724 TCoordSlice aCoord = GetCoord(aRefId);
726 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
727 case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
728 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
729 case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
730 case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
731 case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
732 case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
733 case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
737 //---------------------------------------------------------------
738 THexa20b::THexa20b(TInt theDim, TInt theNbRef):
739 TShapeFun(theDim,theNbRef)
741 TInt aNbRef = myRefCoord.size();
742 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
743 TCoordSlice aCoord = GetCoord(aRefId);
745 case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
746 case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
747 case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
748 case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
749 case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
750 case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
751 case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
752 case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
754 case 11: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break;
755 case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break;
756 case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break;
757 case 8: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break;
758 case 16: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
759 case 19: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
760 case 18: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
761 case 17: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
762 case 15: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break;
763 case 14: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
764 case 13: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break;
765 case 12: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
769 //---------------------------------------------------------------
770 TPenta6a::TPenta6a():
773 TInt aNbRef = myRefCoord.size();
774 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
775 TCoordSlice aCoord = GetCoord(aRefId);
777 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
778 case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break;
779 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
780 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
781 case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
782 case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
786 //---------------------------------------------------------------
787 TPenta6b::TPenta6b():
790 TInt aNbRef = myRefCoord.size();
791 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
792 TCoordSlice aCoord = GetCoord(aRefId);
794 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
795 case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break;
796 case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
797 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
798 case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
799 case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
803 //---------------------------------------------------------------
804 TPenta15a::TPenta15a():
807 TInt aNbRef = myRefCoord.size();
808 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
809 TCoordSlice aCoord = GetCoord(aRefId);
811 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
812 case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break;
813 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
814 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
815 case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
816 case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
818 case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
819 case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
820 case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
821 case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
822 case 10: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
823 case 11: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
824 case 12: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
825 case 13: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
826 case 14: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
830 //---------------------------------------------------------------
831 TPenta15b::TPenta15b():
834 TInt aNbRef = myRefCoord.size();
835 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
836 TCoordSlice aCoord = GetCoord(aRefId);
838 case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
839 case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break;
840 case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
841 case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
842 case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
843 case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
845 case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
846 case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
847 case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
848 case 12: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
849 case 14: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
850 case 13: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
851 case 11: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
852 case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
853 case 9: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
857 //---------------------------------------------------------------
861 TInt aNbRef = myRefCoord.size();
862 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
863 TCoordSlice aCoord = GetCoord(aRefId);
865 case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
866 case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
867 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
868 case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
869 case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
873 //---------------------------------------------------------------
877 TInt aNbRef = myRefCoord.size();
878 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
879 TCoordSlice aCoord = GetCoord(aRefId);
881 case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
882 case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
883 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
884 case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
885 case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
889 //---------------------------------------------------------------
890 TPyra13a::TPyra13a():
893 TInt aNbRef = myRefCoord.size();
894 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
895 TCoordSlice aCoord = GetCoord(aRefId);
897 case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
898 case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
899 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
900 case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
901 case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
903 case 5: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
904 case 6: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
905 case 7: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break;
906 case 8: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break;
907 case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
908 case 10: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
909 case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
910 case 12: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break;
914 //---------------------------------------------------------------
915 TPyra13b::TPyra13b():
918 TInt aNbRef = myRefCoord.size();
919 for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
920 TCoordSlice aCoord = GetCoord(aRefId);
922 case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
923 case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break;
924 case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break;
925 case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break;
926 case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break;
928 case 8: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
929 case 7: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break;
930 case 6: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break;
931 case 5: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break;
932 case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
933 case 12: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break;
934 case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break;
935 case 10: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break;
940 * \brief Fill definition of gauss points family
943 TGaussDef::TGaussDef(const int geom, const int nbGauss, const int variant)
946 myCoords .reserve( nbGauss * dim() );
947 myWeights.reserve( nbGauss );
953 if (geom == NORM_SEG2) setRefCoords( TSeg2a() );
954 else setRefCoords( TSeg3a() );
957 add( 0.0, 2.0 ); break;
960 const double a = 0.577350269189626;
962 add( -a, 1.0 ); break;
965 const double a = 0.774596669241;
966 const double P1 = 1./1.8;
967 const double P2 = 1./1.125;
973 const double a = 0.339981043584856, b = 0.861136311594053;
974 const double P1 = 0.652145154862546, P2 = 0.347854845137454 ;
978 add( -b, P2 ); break;
981 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for SEG"<<nbGauss);
987 if ( variant == 1 ) {
988 if (geom == NORM_TRI3) setRefCoords( TTria3b() );
989 else setRefCoords( TTria6b() );
992 add( 1/3., 1/3., 1/2. ); break;
995 // what about COT3 ???
996 add( 1/6., 1/6., 1/6. );
997 add( 2/3., 1/6., 1/6. );
998 add( 1/6., 2/3., 1/6. ); break;
1001 add( 1/5., 1/5., 25/(24*4.) );
1002 add( 3/5., 1/5., 25/(24*4.) );
1003 add( 1/5., 3/5., 25/(24*4.) );
1004 add( 1/3., 1/3., -27/(24*4.) ); break;
1007 const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
1008 const double a = 0.445948490915965, b = 0.091576213509771;
1010 add( 1-2*b, b, P2 );
1011 add( b, 1-2*b, P2 );
1012 add( a, 1-2*a, P1 );
1014 add( 1-2*a, a, P1 ); break;
1017 const double A = 0.470142064105115;
1018 const double B = 0.101286507323456;
1019 const double P1 = 0.066197076394253;
1020 const double P2 = 0.062969590272413;
1021 add( 1/3., 1/3., 9/80. );
1023 add( 1-2*A, A, P1 );
1024 add( A, 1-2*A, P1 );
1026 add( 1-2*B, B, P2 );
1027 add( B, 1-2*B, P2 ); break;
1030 const double A = 0.063089014491502;
1031 const double B = 0.249286745170910;
1032 const double C = 0.310352451033785;
1033 const double D = 0.053145049844816;
1034 const double P1 = 0.025422453185103;
1035 const double P2 = 0.058393137863189;
1036 const double P3 = 0.041425537809187;
1038 add( 1-2*A, A, P1 );
1039 add( A, 1-2*A, P1 );
1041 add( 1-2*B, B, P2 );
1042 add( B, 1-2*B, P2 );
1045 add( 1-C-D, C, P3 );
1046 add( 1-C-D, D, P3 );
1047 add( C, 1-C-D, P3 );
1048 add( D, 1-C-D, P3 ); break;
1051 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 1: "
1055 else if ( variant == 2 ) {
1056 if (geom == NORM_TRI3) setRefCoords( TTria3a() );
1057 else setRefCoords( TTria6a() );
1058 switch ( nbGauss ) {
1060 add( -1/3., -1/3., 2. ); break;
1063 add( -2/3., 1/3., 2/3. );
1064 add( -2/3., -2/3., 2/3. );
1065 add( 1/3., -2/3., 2/3. ); break;
1068 const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
1069 const double A = 0.445948490915965, B = 0.091576213509771;
1070 add( 2*B-1, 1-4*B, 4*P2 );
1071 add( 2*B-1, 2*B-1, 4*P2 );
1072 add( 1-4*B, 2*B-1, 4*P2 );
1073 add( 1-4*A, 2*A-1, 4*P1 );
1074 add( 2*A-1, 1-4*A, 4*P1 );
1075 add( 2*A-1, 2*A-1, 4*P1 ); break;
1078 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 2: "
1082 else if ( variant == 3 ) {
1083 if (geom == NORM_TRI3) setRefCoords( TTria3b() );
1084 else setRefCoords( TTria6b() );
1085 switch ( nbGauss ) {
1087 add( 1/3., 1/3., -27/96 );
1088 add( 0.2 , 0.2 , 25/96 );
1089 add( 0.6 , 0.2 , 25/96 );
1090 add( 0.2 , 0.6 , 25/96 ); break;
1093 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 3: "
1101 if ( variant == 1 ) {
1102 if (geom == NORM_QUAD4) setRefCoords( TQuad4b() );
1103 else setRefCoords( TQuad8b() );
1104 switch ( nbGauss ) {
1106 add( 0, 0, 4 ); break;
1109 const double a = 1/sqrt(3.);
1113 add( -a, a, 1 ); break;
1115 case 5: { // out from the 3 specs
1116 const double a = 0.774596669241483;
1121 add( 0, 0, 2.0 ); break;
1124 const double a = 0.774596669241483;
1125 add( -a, -a, 25/81. );
1126 add( a, -a, 25/81. );
1127 add( a, a, 25/81. );
1128 add( -a, a, 25/81. );
1129 add( 0., -a, 40/81. );
1130 add( a, 0., 40/81. );
1131 add( 0., a, 40/81. );
1132 add( -a, 0., 40/81. );
1133 add( 0., 0., 64/81. ); break;
1136 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
1140 else if ( variant == 2 ) {
1141 if (geom == NORM_QUAD4) setRefCoords( TQuad4a() );
1142 else setRefCoords( TQuad8a() );
1143 switch ( nbGauss ) {
1145 const double a = 1/sqrt(3.);
1149 add( a, a, 1 ); break;
1152 const double a = 0.774596669241483;
1153 add( -a, a, 25/81. );
1154 add( -a, -a, 25/81. );
1155 add( a, -a, 25/81. );
1156 add( a, a, 25/81. );
1157 add( -a, 0., 40/81. );
1158 add( 0., -a, 40/81. );
1159 add( a, 0., 40/81. );
1160 add( 0., a, 40/81. );
1161 add( 0., 0., 64/81. ); break;
1164 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
1168 else if ( variant == 3 ) {
1169 if (geom == NORM_QUAD4) setRefCoords( TQuad4b() );
1170 else setRefCoords( TQuad8b() );
1171 switch ( nbGauss ) {
1173 const double a = 3/sqrt(3.);
1177 add( a, a, 1 ); break;
1180 const double a = sqrt(3/5.), c1 = 5/9., c2 = 8/9.;
1181 const double c12 = c1*c2, c22 = c2*c2, c1c2 = c1*c2;
1183 add( -a, 0., c1c2 );
1185 add( 0., -a, c1c2 );
1190 add( a, a, c12 ); break;
1193 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 3: "
1201 if (geom == NORM_TETRA4) setRefCoords( TTetra4a() );
1202 else setRefCoords( TTetra10a() );
1203 switch ( nbGauss ) {
1205 const double a = (5 - sqrt(5.))/20., b = (5 + 3*sqrt(5.))/20.;
1206 add( a, a, a, 1/24. );
1207 add( a, a, b, 1/24. );
1208 add( a, b, a, 1/24. );
1209 add( b, a, a, 1/24. ); break;
1212 const double a = 0.25, b = 1/6., c = 0.5;
1213 add( a, a, a, -2/15. );
1214 add( b, b, b, 3/40. );
1215 add( b, b, c, 3/40. );
1216 add( b, c, b, 3/40. );
1217 add( c, b, b, 3/40. ); break;
1220 const double a = 0.25;
1221 const double b1 = (7 + sqrt(15.))/34., c1 = (13 + 3*sqrt(15.))/34., d = (5 - sqrt(15.))/20.;
1222 const double b2 = (7 - sqrt(15.))/34., c2 = (13 - 3*sqrt(15.))/34., e = (5 + sqrt(15.))/20.;
1223 const double P1 = (2665 - 14*sqrt(15.))/226800.;
1224 const double P2 = (2665 + 14*sqrt(15.))/226800.;
1225 add( a, a, a, 8/405.);//_____
1226 add( b1, b1, b1, P1 );
1227 add( b1, b1, c1, P1 );
1228 add( b1, c1, b1, P1 );
1229 add( c1, b1, b1, P1 );//_____
1230 add( b2, b2, b2, P2 );
1231 add( b2, b2, c2, P2 );
1232 add( b2, c2, b2, P2 );
1233 add( c2, b2, b2, P2 );//_____
1234 add( d, d, e, 5/567.);
1235 add( d, e, d, 5/567.);
1236 add( e, d, d, 5/567.);
1237 add( d, e, e, 5/567.);
1238 add( e, d, e, 5/567.);
1239 add( e, e, d, 5/567.);
1243 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TETRA: "<<nbGauss);
1249 if (geom == NORM_PYRA5) setRefCoords( TPyra5a() );
1250 else setRefCoords( TPyra13a() );
1251 switch ( nbGauss ) {
1253 const double h1 = 0.1531754163448146;
1254 const double h2 = 0.6372983346207416;
1255 add( .5, 0., h1, 2/15. );
1256 add( 0., .5, h1, 2/15. );
1257 add( -.5, 0., h1, 2/15. );
1258 add( 0., -.5, h1, 2/15. );
1259 add( 0., 0., h2, 2/15. ); break;
1262 const double p1 = 0.1024890634400000 ;
1263 const double p2 = 0.1100000000000000 ;
1264 const double p3 = 0.1467104129066667 ;
1265 const double a = 0.5702963741068025 ;
1266 const double h1 = 0.1666666666666666 ;
1267 const double h2 = 0.08063183038464675;
1268 const double h3 = 0.6098484849057127 ;
1269 add( a, 0., h1, p1 );
1270 add( 0., a, h1, p1 );
1271 add( -a, 0., h1, p1 );
1272 add( 0., -a, h1, p1 );
1273 add( 0., 0., h2, p2 );
1274 add( 0., 0., h3, p3 ); break;
1277 const double a1 = 0.788073483;
1278 const double b6 = 0.499369002;
1279 const double b1 = 0.848418011;
1280 const double c8 = 0.478508449;
1281 const double c1 = 0.652816472;
1282 const double d12 = 0.032303742;
1283 const double d1 = 1.106412899;
1284 double z = 1/2., fz = b1/2*(1 - z);
1285 add( 0., 0., z, a1 ); // 1
1286 add( fz, fz, z, b6 ); // 2
1287 add( -fz, fz, z, b6 ); // 3
1288 add( -fz, -fz, z, b6 ); // 4
1289 add( fz, -fz, z, b6 ); // 5
1291 add( 0., 0., z, b6 ); // 6
1293 add( 0., 0., z, b6 ); // 7
1294 z = (1 - c1)/2.; fz = c1*(1 - z);
1295 add( fz, 0., z, c8 ); // 8
1296 add( 0., fz, z, c8 ); // 9
1297 add( -fz, 0., z, c8 ); // 10
1298 add( 0., -fz, z, c8 ); // 11
1299 z = (1 + c1)/2.; fz = c1*(1 - z);
1300 add( fz, 0., z, c8 ); // 12
1301 add( 0., fz, z, c8 ); // 13
1302 add( -fz, 0., z, c8 ); // 14
1303 add( 0., -fz, z, c8 ); // 15
1304 z = (1 - d1)/2., fz = d1/2*(1 - z);
1305 add( fz, fz, z, d12); // 16
1306 add( -fz, fz, z, d12); // 17
1307 add( -fz, -fz, z, d12); // 18
1308 add( fz, -fz, z, d12); // 19
1309 z = 1/2.; fz = d1*(1 - z);
1310 add( fz, 0., z, d12); // 20
1311 add( 0., fz, z, d12); // 21
1312 add( -fz, 0., z, d12); // 22
1313 add( 0., -fz, z, d12); // 23
1314 z = (1 + d1)/2., fz = d1/2*(1 - z);
1315 add( fz, fz, z, d12); // 24
1316 add( -fz, fz, z, d12); // 25
1317 add( -fz, -fz, z, d12); // 26
1318 add( fz, -fz, z, d12); // 27
1322 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for PYRA: "<<nbGauss);
1327 if (geom == NORM_PENTA6) setRefCoords( TPenta6a() );
1328 else setRefCoords( TPenta15a() );
1329 switch ( nbGauss ) {
1331 const double a = sqrt(3.)/3.;
1332 add( -a, .5, .5, 1/6. );
1333 add( -a, 0., .5, 1/6. );
1334 add( -a, .5, 0., 1/6. );
1335 add( a, .5, .5, 1/6. );
1336 add( a, 0., .5, 1/6. );
1337 add( a, .5, 0., 1/6. ); break;
1340 const double a = 0.577350269189626;
1341 add( -a, 1/3., 1/3., -27/96. );
1342 add( -a, 0.6, 0.2, 25/96. );
1343 add( -a, 0.2, 0.6, 25/96. );
1344 add( -a, 0.2, 0.2, 25/96. );
1345 add( +a, 1/3., 1/3., -27/96. );
1346 add( +a, 0.6, 0.2, 25/96. );
1347 add( +a, 0.2, 0.6, 25/96. );
1348 add( +a, 0.2, 0.2, 25/96. ); break;
1351 const double d = sqrt(3/5.), c1 = 5/9., c2 = 8/9.; // d <=> alfa
1352 const double a = (6 + sqrt(15.))/21.;
1353 const double b = (6 - sqrt(15.))/21.;
1354 const double P1 = (155 + sqrt(15.))/2400.;
1355 const double P2 = (155 - sqrt(15.))/2400.; //___
1356 add( -d, 1/3., 1/3., c1*9/80. );//___
1357 add( -d, a, a, c1*P1 );
1358 add( -d, 1-2*a, a, c1*P1 );
1359 add( -d, a, 1-2*a, c1*P1 );//___
1360 add( -d, b, b, c1*P2 );
1361 add( -d, 1-2*b, b, c1*P2 );
1362 add( -d, b, 1-2*b, c1*P2 );//___
1363 add( 0., 1/3., 1/3., c2*9/80. );//___
1364 add( 0., a, a, c2*P1 );
1365 add( 0., 1-2*a, a, c2*P1 );
1366 add( 0., a, 1-2*a, c2*P1 );//___
1367 add( 0., b, b, c2*P2 );
1368 add( 0., 1-2*b, b, c2*P2 );
1369 add( 0., b, 1-2*b, c2*P2 );//___
1370 add( d, 1/3., 1/3., c1*9/80. );//___
1371 add( d, a, a, c1*P1 );
1372 add( d, 1-2*a, a, c1*P1 );
1373 add( d, a, 1-2*a, c1*P1 );//___
1374 add( d, b, b, c1*P2 );
1375 add( d, 1-2*b, b, c1*P2 );
1376 add( d, b, 1-2*b, c1*P2 );//___
1380 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for PENTA: " <<nbGauss);
1386 if (geom == NORM_HEXA8) setRefCoords( THexa8a() );
1387 else setRefCoords( THexa20a() );
1388 switch ( nbGauss ) {
1390 const double a = sqrt(3.)/3.;
1391 add( -a, -a, -a, 1. );
1392 add( -a, -a, a, 1. );
1393 add( -a, a, -a, 1. );
1394 add( -a, a, a, 1. );
1395 add( a, -a, -a, 1. );
1396 add( a, -a, a, 1. );
1397 add( a, a, -a, 1. );
1398 add( a, a, a, 1. ); break;
1401 const double a = sqrt(3/5.), c1 = 5/9., c2 = 8/9.;
1402 const double c12 = c1*c1, c13 = c1*c1*c1;
1403 const double c22 = c2*c2, c23 = c2*c2*c2;
1404 add( -a, -a, -a, c13 ); // 1
1405 add( -a, -a, 0., c12*c2 ); // 2
1406 add( -a, -a, a, c13 ); // 3
1407 add( -a, 0., -a, c12*c2 ); // 4
1408 add( -a, 0., 0., c1*c22 ); // 5
1409 add( -a, 0., a, c12*c2 ); // 6
1410 add( -a, a, -a, c13 ); // 7
1411 add( -a, a, 0., c12*c2 ); // 8
1412 add( -a, a, a, c13 ); // 9
1413 add( 0., -a, -a, c12*c2 ); // 10
1414 add( 0., -a, 0., c1*c22 ); // 11
1415 add( 0., -a, a, c12*c2 ); // 12
1416 add( 0., 0., -a, c1*c22 ); // 13
1417 add( 0., 0., 0., c23 ); // 14
1418 add( 0., 0., a, c1*c22 ); // 15
1419 add( 0., a, -a, c12*c2 ); // 16
1420 add( 0., a, 0., c1*c22 ); // 17
1421 add( 0., a, a, c12*c2 ); // 18
1422 add( a, -a, -a, c13 ); // 19
1423 add( a, -a, 0., c12*c2 ); // 20
1424 add( a, -a, a, c13 ); // 21
1425 add( a, 0., -a, c12*c2 ); // 22
1426 add( a, 0., 0., c1*c22 ); // 23
1427 add( a, 0., a, c12*c2 ); // 24
1428 add( a, a, -a, c13 ); // 25
1429 add( a, a, 0., c12*c2 ); // 26
1430 add( a, a, a, c13 ); // 27
1434 THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for PENTA: " <<nbGauss);
1439 THROW_IK_EXCEPTION("TGaussDef: unexpected EGeometrieElement: "<< geom);
1442 if ( myWeights.capacity() != myWeights.size() )
1443 THROW_IK_EXCEPTION("TGaussDef: Not all gauss points defined");
1447 //================================================================================
1449 * \brief Return dimension for the given cell type
1451 //================================================================================
1453 unsigned SauvUtilities::getDimension( INTERP_KERNEL::NormalizedCellType type )
1455 return type == NORM_ERROR ? -1 : INTERP_KERNEL::CellModel::GetCellModel( type ).getDimension();
1458 //================================================================================
1460 * \brief Returns interlace array to transform a quadratic GIBI element to a MED one.
1461 * i-th array item gives node index in GIBI connectivity for i-th MED node
1463 //================================================================================
1465 const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::NormalizedCellType type )
1467 static std::vector<const int*> conn;
1468 static const int hexa20 [] = {0,6,4,2, 12,18,16,14, 7,5,3,1, 19,17,15,13, 8,11,10,9};
1469 static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,8,7};
1470 static const int pyra13 [] = {0,2,4,6, 12, 1,3,5,7, 8,9,10,11};
1471 static const int tetra10[] = {0,2,4, 9, 1,3,5, 6,7,8};
1472 static const int quad8 [] = {0,2,4,6, 1,3,5,7};
1473 static const int tria6 [] = {0,2,4, 1,3,5};
1474 static const int seg3 [] = {0,2,1};
1477 conn.resize( MaxMedCellType + 1, 0 );
1478 conn[ NORM_HEXA20 ] = hexa20;
1479 conn[ NORM_PENTA15] = penta15;
1480 conn[ NORM_PYRA13 ] = pyra13;
1481 conn[ NORM_TETRA10] = tetra10;
1482 conn[ NORM_SEG3 ] = seg3;
1483 conn[ NORM_TRI6 ] = tria6;
1484 conn[ NORM_QUAD8 ] = quad8;
1486 return conn[ type ];
1489 //================================================================================
1491 * \brief Avoid coping sortedNodeIDs
1493 //================================================================================
1495 Cell::Cell(const Cell& ma)
1496 : _nodes(ma._nodes), _reverse(ma._reverse), _sortedNodeIDs(0), _number(ma._number)
1498 if ( ma._sortedNodeIDs )
1500 _sortedNodeIDs = new int[ _nodes.size() ];
1501 std::copy( ma._sortedNodeIDs, ma._sortedNodeIDs + _nodes.size(), _sortedNodeIDs );
1505 //================================================================================
1507 * \brief Rerturn the i-th link of face
1509 //================================================================================
1511 SauvUtilities::Link Cell::link(int i) const
1513 int i2 = ( i + 1 ) % _nodes.size();
1515 return std::make_pair( _nodes[i2]->_number, _nodes[i]->_number );
1517 return std::make_pair( _nodes[i]->_number, _nodes[i2]->_number );
1520 //================================================================================
1522 * \brief creates if needed and return _sortedNodeIDs
1524 //================================================================================
1526 const TID* Cell::getSortedNodes() const
1528 if ( !_sortedNodeIDs )
1530 size_t l=_nodes.size();
1531 _sortedNodeIDs = new int[ l ];
1533 for (size_t i=0; i!=l; ++i)
1534 _sortedNodeIDs[i]=_nodes[i]->_number;
1535 std::sort( _sortedNodeIDs, _sortedNodeIDs + l );
1537 return _sortedNodeIDs;
1540 //================================================================================
1542 * \brief Compare sorted ids of cell nodes
1544 //================================================================================
1546 bool Cell::operator< (const Cell& ma) const
1548 if ( _nodes.size() == 1 )
1549 return _nodes[0] < ma._nodes[0];
1551 const int* v1 = getSortedNodes();
1552 const int* v2 = ma.getSortedNodes();
1553 for ( const int* vEnd = v1 + _nodes.size(); v1 < vEnd; ++v1, ++v2 )
1559 //================================================================================
1561 * \brief Dump a Cell
1563 //================================================================================
1565 std::ostream& SauvUtilities::operator<< (std::ostream& os, const SauvUtilities::Cell& ma)
1567 os << "cell " << ma._number << " (" << ma._nodes.size() << " nodes) : < " << ma._nodes[0]->_number;
1568 for( size_t i=1; i!=ma._nodes.size(); ++i)
1569 os << ", " << ma._nodes[i]->_number;
1571 os << " > sortedNodes: ";
1572 if ( ma._sortedNodeIDs ) {
1574 for( size_t i=0; i!=ma._nodes.size(); ++i)
1575 os << ( i ? ", " : "" ) << ma._sortedNodeIDs[i];
1585 //================================================================================
1587 * \brief Return nb of elements in the group
1589 //================================================================================
1591 int Group::size() const
1594 if ( !_relocTable.empty() )
1595 sizze = _relocTable.size();
1596 else if ( _medGroup )
1597 sizze = _medGroup->getNumberOfTuples();
1598 else if ( !_cells.empty() )
1599 sizze = _cells.size();
1601 for ( size_t i = 0; i < _groups.size(); ++i )
1602 sizze += _groups[i]->size();
1606 //================================================================================
1608 * \brief Conver gibi element type to med one
1610 //================================================================================
1612 INTERP_KERNEL::NormalizedCellType SauvUtilities::gibi2medGeom( size_t gibiType )
1614 if ( gibiType < 1 || gibiType > NbGibiCellTypes )
1617 return GibiTypeToMed[ gibiType - 1 ];
1620 //================================================================================
1622 * \brief Conver med element type to gibi one
1624 //================================================================================
1626 int SauvUtilities::med2gibiGeom( INTERP_KERNEL::NormalizedCellType medGeomType )
1628 for ( unsigned int i = 0; i < NbGibiCellTypes; i++ )
1629 if ( GibiTypeToMed[ i ] == medGeomType )
1635 //================================================================================
1637 * \brief Remember the file name
1639 //================================================================================
1641 FileReader::FileReader(const char* fileName):_fileName(fileName),_iRead(0),_nbToRead(0)
1645 //================================================================================
1647 * \brief Constructor of ASCII sauve file reader
1649 //================================================================================
1651 ASCIIReader::ASCIIReader(const char* fileName)
1652 :FileReader(fileName),
1657 //================================================================================
1659 * \brief Return true
1661 //================================================================================
1663 bool ASCIIReader::isASCII() const
1668 //================================================================================
1670 * \brief Try to open an ASCII file
1672 //================================================================================
1674 bool ASCIIReader::open()
1677 _file = ::_open (_fileName.c_str(), _O_RDONLY|_O_BINARY);
1679 _file = ::open (_fileName.c_str(), O_RDONLY);
1683 _start = new char [GIBI_BufferSize]; // working buffer beginning
1684 //_tmpBuf = new char [GIBI_MaxOutputLen];
1691 //THROW_IK_EXCEPTION("Can't open file "<<_fileName << " fd: " << _file);
1693 return (_file >= 0);
1696 //================================================================================
1698 * \brief Close the file
1700 //================================================================================
1702 ASCIIReader::~ASCIIReader()
1710 //delete [] _tmpBuf;
1717 //================================================================================
1719 * \brief Return a next line of the file
1721 //================================================================================
1723 bool ASCIIReader::getNextLine (char* & line, bool raiseOEF /*= true*/ )
1725 if ( getLine( line )) return true;
1727 THROW_IK_EXCEPTION("Unexpected EOF on ln "<<_lineNb);
1731 //================================================================================
1733 * \brief Read a next line of the file if necessary
1735 //================================================================================
1737 bool ASCIIReader::getLine(char* & line)
1739 bool aResult = true;
1740 // Check the state of the buffer;
1741 // if there is too little left, read the next portion of data
1742 int nBytesRest = _eptr - _ptr;
1743 if (nBytesRest < GIBI_MaxOutputLen)
1747 // move the remaining portion to the buffer beginning
1748 for ( int i = 0; i < nBytesRest; ++i )
1749 _start[i] = _ptr[i];
1750 //memcpy (_tmpBuf, _ptr, nBytesRest);
1751 //memcpy (_start, _tmpBuf, nBytesRest);
1758 const int nBytesRead = ::read (_file,
1759 &_start [nBytesRest],
1760 GIBI_BufferSize - nBytesRest);
1761 nBytesRest += nBytesRead;
1762 _eptr = &_start [nBytesRest];
1764 // Check the buffer for the end-of-line
1768 // Check for end-of-the-buffer, the ultimate criterion for termination
1771 if (nBytesRest <= 0)
1777 // seek the line-feed character
1780 if (ptr[-1] == '\r')
1788 // Output the result
1796 //================================================================================
1798 * \brief Prepare for iterating over given nb of values
1799 * \param nbToRead - nb of fields to read
1800 * \param nbPosInLine - nb of fields in one line
1801 * \param width - field width
1802 * \param shift - shift from line beginning to the field start
1804 //================================================================================
1806 void ASCIIReader::init( int nbToRead, int nbPosInLine, int width, int shift /*= 0*/ )
1808 _nbToRead = nbToRead;
1809 _nbPosInLine = nbPosInLine;
1815 getNextLine( _curPos );
1816 _curPos = _curPos + _shift;
1825 //================================================================================
1827 * \brief Prepare for iterating over given nb of string values
1829 //================================================================================
1831 void ASCIIReader::initNameReading(int nbValues, int width /*= 8*/)
1833 init( nbValues, 72 / ( width + 1 ), width, 1 );
1836 //================================================================================
1838 * \brief Prepare for iterating over given nb of integer values
1840 //================================================================================
1842 void ASCIIReader::initIntReading(int nbValues)
1844 init( nbValues, 10, 8 );
1847 //================================================================================
1849 * \brief Prepare for iterating over given nb of real values
1851 //================================================================================
1853 void ASCIIReader::initDoubleReading(int nbValues)
1855 init( nbValues, 3, 22 );
1857 // Correction 2 of getDouble(): set "C" numeric locale to read numbers
1858 // with dot decimal point separator, as it is in SAUVE files
1859 _curLocale = setlocale(LC_NUMERIC, "C");
1862 //================================================================================
1864 * \brief Return true if not all values have been read
1866 //================================================================================
1868 bool ASCIIReader::more() const
1870 bool result = false;
1871 if ( _iRead < _nbToRead)
1873 if ( _curPos ) result = true;
1878 //================================================================================
1880 * \brief Go to the nex value
1882 //================================================================================
1884 void ASCIIReader::next()
1887 THROW_IK_EXCEPTION("SauvUtilities::ASCIIReader::next(): no more() values to read");
1890 if ( _iRead < _nbToRead )
1892 if ( _iPos >= _nbPosInLine )
1894 getNextLine( _curPos );
1895 _curPos = _curPos + _shift;
1900 _curPos = _curPos + _width + _shift;
1906 if ( !_curLocale.empty() )
1908 setlocale(LC_NUMERIC, _curLocale.c_str());
1914 //================================================================================
1916 * \brief Return the current integer value
1918 //================================================================================
1920 int ASCIIReader::getInt() const
1922 // fix for two glued ints (issue 0021009):
1923 // Line nb | File contents
1924 // ------------------------------------------------------------------------------------
1925 // 53619905 | 1 2 6 8
1926 // 53619906 | SCALAIRE
1927 // 53619907 | -63312600499 1 0 0 0 -2 0 2
1928 // where -63312600499 is actualy -633 and 12600499
1929 char hold=_curPos[_width];
1930 _curPos[_width] = '\0';
1931 int result = atoi( _curPos );
1932 _curPos[_width] = hold;
1934 //return atoi(str());
1937 //================================================================================
1939 * \brief Return the current float value
1941 //================================================================================
1943 float ASCIIReader::getFloat() const
1948 //================================================================================
1950 * \brief Return the current double value
1952 //================================================================================
1954 double ASCIIReader::getDouble() const
1956 //std::string aStr (_curPos);
1958 // Correction: add missing 'E' specifier
1959 // int aPosStart = aStr.find_first_not_of(" \t");
1960 // if (aPosStart < (int)aStr.length()) {
1961 // int aPosSign = aStr.find_first_of("+-", aPosStart + 1); // pass the leading symbol, as it can be a sign
1962 // if (aPosSign < (int)aStr.length()) {
1963 // if (aStr[aPosSign - 1] != 'e' && aStr[aPosSign - 1] != 'E')
1964 // aStr.insert(aPosSign, "E", 1);
1968 // Different Correction (more optimal)
1970 // 0.00000000000000E+00 -2.37822406690632E+01 6.03062748797469E+01
1971 // 7.70000000000000-100 7.70000000000000+100 7.70000000000000+100
1972 //0123456789012345678901234567890123456789012345678901234567890123456789
1973 const size_t posE = 18;
1974 std::string aStr (_curPos);
1975 if ( aStr.find('E') < 0 && aStr.find('e') < 0 )
1977 if ( aStr.size() < posE+1 )
1978 THROW_IK_EXCEPTION("No more doubles (line #" << lineNb() << ")");
1979 aStr.insert( posE, "E", 1 );
1980 return atof(aStr.c_str());
1982 return atof( _curPos );
1985 //================================================================================
1987 * \brief Return the current string value
1989 //================================================================================
1991 std::string ASCIIReader::getName() const
1994 while (( _curPos[len-1] == ' ' || _curPos[len-1] == 0) && len > 0 )
1996 return std::string( _curPos, len );
1999 //================================================================================
2001 * \brief Constructor of a binary sauve file reader
2003 //================================================================================
2005 XDRReader::XDRReader(const char* fileName) :FileReader(fileName), _xdrs_file(NULL)
2009 //================================================================================
2011 * \brief Close the XDR sauve file
2013 //================================================================================
2015 XDRReader::~XDRReader()
2020 xdr_destroy((XDR*)_xdrs);
2022 ::fclose(_xdrs_file);
2028 //================================================================================
2030 * \brief Return false
2032 //================================================================================
2034 bool XDRReader::isASCII() const
2039 //================================================================================
2041 * \brief Try to open an XRD file
2043 //================================================================================
2045 bool XDRReader::open()
2047 bool xdr_ok = false;
2050 if ((_xdrs_file = ::fopen(_fileName.c_str(), "rb")))
2052 if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
2055 _xdrs = (XDR *)malloc(sizeof(XDR));
2056 xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
2058 const int maxsize = 10;
2059 char icha[maxsize+1];
2061 if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
2063 icha[maxsize] = '\0';
2064 xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
2068 xdr_destroy((XDR*)_xdrs);
2078 //================================================================================
2082 //================================================================================
2084 bool XDRReader::getNextLine (char* &, bool )
2089 //================================================================================
2091 * \brief Prepare for iterating over given nb of values
2092 * \param nbToRead - nb of fields to read
2093 * \param width - field width
2095 //================================================================================
2097 void XDRReader::init( int nbToRead, int width/*=0*/ )
2099 if(_iRead < _nbToRead)
2101 std::cout << "_iRead, _nbToRead : " << _iRead << " " << _nbToRead << std::endl;
2102 std::cout << "Unfinished iteration before new one !" << std::endl;
2103 THROW_IK_EXCEPTION("SauvUtilities::XDRReader::init(): Unfinished iteration before new one !");
2106 _nbToRead = nbToRead;
2110 //================================================================================
2112 * \brief Prepare for iterating over given nb of string values
2114 //================================================================================
2116 void XDRReader::initNameReading(int nbValues, int width)
2118 init( nbValues, width );
2119 _xdr_kind = _xdr_kind_char;
2122 unsigned int nels = nbValues*width;
2123 _xdr_cvals = (char*)malloc((nels+1)*sizeof(char));
2125 xdr_string((XDR*)_xdrs, &_xdr_cvals, nels);
2127 _xdr_cvals[nels] = '\0';
2131 //================================================================================
2133 * \brief Prepare for iterating over given nb of integer values
2135 //================================================================================
2137 void XDRReader::initIntReading(int nbValues)
2140 _xdr_kind = _xdr_kind_int;
2144 unsigned int nels = nbValues;
2145 unsigned int actual_nels;
2146 _xdr_ivals = (int*)malloc(nels*sizeof(int));
2147 xdr_array((XDR*)_xdrs, (char **)&_xdr_ivals, &actual_nels, nels, sizeof(int), (xdrproc_t)xdr_int);
2152 //================================================================================
2154 * \brief Prepare for iterating over given nb of real values
2156 //================================================================================
2158 void XDRReader::initDoubleReading(int nbValues)
2161 _xdr_kind = _xdr_kind_double;
2165 unsigned int nels = nbValues;
2166 unsigned int actual_nels;
2167 _xdr_dvals = (double*)malloc(nels*sizeof(double));
2168 xdr_array((XDR*)_xdrs, (char **)&_xdr_dvals, &actual_nels, nels, sizeof(double), (xdrproc_t)xdr_double);
2173 //================================================================================
2175 * \brief Return true if not all values have been read
2177 //================================================================================
2179 bool XDRReader::more() const
2181 return _iRead < _nbToRead;
2184 //================================================================================
2186 * \brief Go to the nex value
2188 //================================================================================
2190 void XDRReader::next()
2193 THROW_IK_EXCEPTION("SauvUtilities::XDRReader::next(): no more() values to read");
2196 if ( _iRead < _nbToRead )
2201 if(_xdr_kind == _xdr_kind_char) free(_xdr_cvals);
2202 if(_xdr_kind == _xdr_kind_int) free(_xdr_ivals);
2203 if(_xdr_kind == _xdr_kind_double) free(_xdr_dvals);
2204 _xdr_kind = _xdr_kind_null;
2208 //================================================================================
2210 * \brief Return the current integer value
2212 //================================================================================
2214 int XDRReader::getInt() const
2216 if(_iRead < _nbToRead)
2218 return _xdr_ivals[_iRead];
2224 xdr_int((XDR*)_xdrs, &result);
2230 //================================================================================
2232 * \brief Return the current float value
2234 //================================================================================
2236 float XDRReader::getFloat() const
2240 xdr_float((XDR*)_xdrs, &result);
2245 //================================================================================
2247 * \brief Return the current double value
2249 //================================================================================
2251 double XDRReader::getDouble() const
2253 if(_iRead < _nbToRead)
2255 return _xdr_dvals[_iRead];
2261 xdr_double((XDR*)_xdrs, &result);
2267 //================================================================================
2269 * \brief Return the current string value
2271 //================================================================================
2273 std::string XDRReader::getName() const
2276 char* s = _xdr_cvals + _iRead*_width;
2277 while (( s[len-1] == ' ' || s[len-1] == 0) && len > 0 )
2279 return std::string( s, len );
2282 //================================================================================
2284 * \brief Throw an exception if not all needed data is present
2286 //================================================================================
2288 void IntermediateMED::checkDataAvailability() const
2290 if ( _spaceDim == 0 )
2291 THROW_IK_EXCEPTION("Wrong file format"); // it is the first record in the sauve file
2293 if ( _groups.empty() )
2294 THROW_IK_EXCEPTION("No elements have been read");
2296 if ( _points.empty() || _nbNodes == 0 )
2297 THROW_IK_EXCEPTION("Nodes of elements are not filled");
2299 if ( _coords.empty() )
2300 THROW_IK_EXCEPTION("Node coordinates are missing");
2302 if ( _coords.size() < _nbNodes * _spaceDim )
2303 THROW_IK_EXCEPTION("Nodes and coordinates mismatch");
2306 //================================================================================
2308 * \brief Safely adds a new Group
2310 //================================================================================
2312 Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsToFix)
2314 if ( _groups.size() == _groups.capacity() ) // re-allocation would occure
2316 std::vector<Group> newGroups( _groups.size() );
2317 newGroups.push_back( Group() );
2319 for ( size_t i = 0; i < _groups.size(); ++i )
2321 // avoid copying _cells
2322 std::vector<const Cell*> cells;
2323 cells.swap( _groups[i]._cells );
2324 newGroups[i] = _groups[i];
2325 newGroups[i]._cells.swap( cells );
2327 // correct pointers to sub-groups
2328 for ( size_t j = 0; j < _groups[i]._groups.size(); ++j )
2330 int iG = _groups[i]._groups[j] - &_groups[0];
2331 newGroups[i]._groups[j] = & newGroups[ iG ];
2337 for ( size_t i = 0; i < groupsToFix->size(); ++i )
2338 if ( (*groupsToFix)[i] )
2340 int iG = (*groupsToFix)[i] - &_groups[0];
2341 (*groupsToFix)[i] = & newGroups[ iG ];
2344 // fix field supports
2345 for ( int isNode = 0; isNode < 2; ++isNode )
2347 std::vector<DoubleField* >& fields = isNode ? _nodeFields : _cellFields;
2348 for ( size_t i = 0; i < fields.size(); ++i )
2350 if ( !fields[i] ) continue;
2351 for ( size_t j = 0; j < fields[i]->_sub.size(); ++j )
2352 if ( fields[i]->_sub[j]._support )
2354 int iG = fields[i]->_sub[j]._support - &_groups[0];
2355 fields[i]->_sub[j]._support = & newGroups[ iG ];
2357 if ( fields[i]->_group )
2359 int iG = fields[i]->_group - &_groups[0];
2360 fields[i]->_group = & newGroups[ iG ];
2365 _groups.swap( newGroups );
2369 _groups.push_back( Group() );
2371 return &_groups.back();
2374 //================================================================================
2376 * \brief Makes ParaMEDMEM::MEDFileData from self
2378 //================================================================================
2380 ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
2382 MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh > mesh = makeMEDFileMesh();
2383 MEDCouplingAutoRefCountObjectPtr< MEDFileFields > fields = makeMEDFileFields(mesh);
2385 MEDCouplingAutoRefCountObjectPtr< MEDFileMeshes > meshes = MEDFileMeshes::New();
2386 MEDCouplingAutoRefCountObjectPtr< MEDFileData > medData = MEDFileData::New();
2387 meshes->pushMesh( mesh );
2388 medData->setMeshes( meshes );
2389 if ( fields ) medData->setFields( fields );
2391 return medData.retn();
2394 //================================================================================
2396 * \brief Creates ParaMEDMEM::MEDFileUMesh from its data
2398 //================================================================================
2400 ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
2402 // check if all needed piles are present
2403 checkDataAvailability();
2406 setGroupLongNames();
2408 // fix element orientation
2409 if ( _spaceDim == 2 || _spaceDim == 1 )
2411 else if ( _spaceDim == 3 )
2415 decreaseHierarchicalDepthOfSubgroups();
2416 eraseUselessGroups();
2417 //detectMixDimGroups();
2420 _points.numberNodes();
2423 // make the med mesh
2425 MEDFileUMesh* mesh = MEDFileUMesh::New();
2427 DataArrayDouble *coords = getCoords();
2428 setConnectivity( mesh, coords );
2433 if ( !mesh->getName().c_str() || strlen( mesh->getName().c_str() ) == 0 )
2434 mesh->setName( "MESH" );
2439 //================================================================================
2441 * \brief Set long names to groups
2443 //================================================================================
2445 void IntermediateMED::setGroupLongNames()
2447 // IMP 0020434: mapping GIBI names to MED names
2448 // set med names to objects (mesh, fields, support, group or other)
2450 std::set<int> treatedGroups;
2452 std::list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_mail.begin();
2453 for (; itGIBItoMED != _listGIBItoMED_mail.end(); itGIBItoMED++)
2455 if ( (int)_groups.size() < itGIBItoMED->gibi_id ) continue;
2457 SauvUtilities::Group & grp = _groups[itGIBItoMED->gibi_id - 1];
2459 // if there are several names for grp then the 1st name is the name
2460 // of grp and the rest ones are names of groups referring grp (issue 0021311)
2461 const bool isRefName = !treatedGroups.insert( itGIBItoMED->gibi_id ).second;
2464 grp._name = _mapStrings[ itGIBItoMED->med_id ];
2466 else if ( !grp._refNames.empty() && grp._refNames.back().empty() )
2468 for ( unsigned i = 0; i < grp._refNames.size(); ++i )
2469 if ( grp._refNames[i].empty() )
2470 grp._refNames[i] = _mapStrings[ (*itGIBItoMED).med_id ];
2474 grp._refNames.push_back( _mapStrings[ (*itGIBItoMED).med_id ]);
2479 //================================================================================
2481 * \brief Set long names to fields
2483 //================================================================================
2485 void IntermediateMED::setFieldLongNames(std::set< std::string >& usedNames)
2487 std::list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_cham.begin();
2488 for (; itGIBItoMED != _listGIBItoMED_cham.end(); itGIBItoMED++)
2490 if (itGIBItoMED->gibi_pile == PILE_FIELD)
2492 _cellFields[itGIBItoMED->gibi_id - 1]->_name = _mapStrings[itGIBItoMED->med_id];
2494 else if (itGIBItoMED->gibi_pile == PILE_NODES_FIELD)
2496 _nodeFields[itGIBItoMED->gibi_id - 1]->_name = _mapStrings[itGIBItoMED->med_id];
2498 } // iterate on _listGIBItoMED_cham
2500 for (itGIBItoMED =_listGIBItoMED_comp.begin(); itGIBItoMED != _listGIBItoMED_comp.end(); itGIBItoMED++)
2502 std::string medName = _mapStrings[itGIBItoMED->med_id];
2503 std::string gibiName = _mapStrings[itGIBItoMED->gibi_id];
2505 bool name_found = false;
2506 for ( int isNodal = 0; isNodal < 2 && !name_found; ++isNodal )
2508 std::vector<DoubleField* > & fields = isNodal ? _nodeFields : _cellFields;
2509 for ( size_t ifi = 0; ifi < fields.size() && !name_found; ifi++)
2511 if (medName.find( fields[ifi]->_name + "." ) == 0 )
2513 std::vector<DoubleField::_Sub_data>& aSubDs = fields[ifi]->_sub;
2514 int nbSub = aSubDs.size();
2515 for (int isu = 0; isu < nbSub; isu++)
2516 for (int ico = 0; ico < aSubDs[isu].nbComponents(); ico++)
2518 if (aSubDs[isu].compName(ico) == gibiName)
2520 std::string medNameCompo = medName.substr( fields[ifi]->_name.size() + 1 );
2521 fields[ifi]->_sub[isu].compName(ico) = medNameCompo;
2527 } // iterate on _listGIBItoMED_comp
2529 for ( size_t i = 0; i < _nodeFields.size() ; i++)
2530 usedNames.insert( _nodeFields[i]->_name );
2531 for ( size_t i = 0; i < _cellFields.size() ; i++)
2532 usedNames.insert( _cellFields[i]->_name );
2535 //================================================================================
2537 * \brief Decrease hierarchical depth of subgroups
2539 //================================================================================
2541 void IntermediateMED::decreaseHierarchicalDepthOfSubgroups()
2543 for (size_t i=0; i!=_groups.size(); ++i)
2545 Group& grp = _groups[i];
2546 for (size_t j = 0; j < grp._groups.size(); ++j )
2548 Group & sub_grp = *grp._groups[j];
2549 if ( !sub_grp._groups.empty() )
2551 // replace j with its 1st subgroup
2552 grp._groups[j] = sub_grp._groups[0];
2553 // push back the rest subs
2554 grp._groups.insert( grp._groups.end(), ++sub_grp._groups.begin(), sub_grp._groups.end() );
2557 // remove empty sub-_groups
2558 std::vector< Group* > newSubGroups;
2559 newSubGroups.reserve( grp._groups.size() );
2560 for (size_t j = 0; j < grp._groups.size(); ++j )
2561 if ( !grp._groups[j]->empty() )
2562 newSubGroups.push_back( grp._groups[j] );
2563 if ( newSubGroups.size() < grp._groups.size() )
2564 grp._groups.swap( newSubGroups );
2568 //================================================================================
2570 * \brief Erase _groups that won't be converted
2572 //================================================================================
2574 void IntermediateMED::eraseUselessGroups()
2576 // propagate _isProfile=true to sub-groups of composite groups
2577 // for (size_t int i=0; i!=_groups.size(); ++i)
2579 // Group* grp = _groups[i];
2580 // if ( grp->_isProfile && !grp->_groups.empty() )
2581 // for (size_t j = 0; j < grp->_groups.size(); ++j )
2582 // grp->_groups[j]->_isProfile=true;
2584 std::set<Group*> groups2convert;
2585 // keep not named sub-groups of field supports
2586 for (size_t i=0; i!=_groups.size(); ++i)
2588 Group& grp = _groups[i];
2589 if ( grp._isProfile && !grp._groups.empty() )
2590 groups2convert.insert( grp._groups.begin(), grp._groups.end() );
2593 // keep named groups and their subgroups
2594 for (size_t i=0; i!=_groups.size(); ++i)
2596 Group& grp = _groups[i];
2597 if ( !grp._name.empty() && !grp.empty() )
2599 groups2convert.insert( &grp );
2600 groups2convert.insert( grp._groups.begin(), grp._groups.end() );
2603 // erase groups that are not in groups2convert and not _isProfile
2604 for (size_t i=0; i!=_groups.size(); ++i)
2606 Group* grp = &_groups[i];
2607 if ( !grp->_isProfile && !groups2convert.count( grp ) )
2609 grp->_cells.clear();
2610 grp->_groups.clear();
2615 //================================================================================
2617 * \brief Detect _groups of mixed dimension
2619 //================================================================================
2621 void IntermediateMED::detectMixDimGroups()
2623 //hasMixedCells = false;
2624 for ( size_t i=0; i < _groups.size(); ++i )
2626 Group& grp = _groups[i];
2627 if ( grp._groups.size() < 2 )
2630 // check if sub-groups have different dimension
2631 unsigned dim1 = getDim( &grp );
2632 for ( size_t j = 1; j < grp._groups.size(); ++j )
2634 unsigned dim2 = getDim( grp._groups[j] );
2638 grp._groups.clear();
2639 if ( !grp._name.empty() )
2640 std::cout << "Erase a group with elements of different dim |" << grp._name << "|"<< std::endl;
2647 //================================================================================
2649 * \brief Fix connectivity of elements in 2D space
2651 //================================================================================
2653 void IntermediateMED::orientElements2D()
2655 std::set<Cell>::const_iterator elemIt, elemEnd;
2656 std::vector< std::pair<int,int> > swapVec;
2658 // ------------------------------------
2659 // fix connectivity of quadratic edges
2660 // ------------------------------------
2661 std::set<Cell>& quadEdges = _cellsByType[ INTERP_KERNEL::NORM_SEG3 ];
2662 if ( !quadEdges.empty() )
2664 elemIt = quadEdges.begin(), elemEnd = quadEdges.end();
2665 for ( ; elemIt != elemEnd; ++elemIt )
2666 ConvertQuadratic( INTERP_KERNEL::NORM_SEG3, *elemIt );
2669 CellsByDimIterator faceIt( *this, 2 );
2670 while ( const std::set<Cell > * faces = faceIt.nextType() )
2672 TCellType cellType = faceIt.type();
2673 bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
2675 getReverseVector( cellType, swapVec );
2677 // ------------------------------------
2678 // fix connectivity of quadratic faces
2679 // ------------------------------------
2681 for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ )
2682 ConvertQuadratic( cellType, *elemIt );
2684 // --------------------------
2685 // orient faces clockwise
2686 // --------------------------
2687 // COMMENTED for issue 0022612 note 17739
2688 // int iQuad = isQuadratic ? 2 : 1;
2689 // for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ )
2691 // // look for index of the most left node
2692 // int iLeft = 0, iNode, nbNodes = elemIt->_nodes.size() / iQuad;
2693 // double x, minX = nodeCoords( elemIt->_nodes[0] )[0];
2694 // for ( iNode = 1; iNode < nbNodes; ++iNode )
2695 // if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX )
2696 // minX = x, iLeft = iNode;
2698 // // indeces of the nodes neighboring the most left one
2699 // int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1;
2700 // int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1;
2701 // // find components of prev-left and left-next vectors
2702 // double xP = nodeCoords( elemIt->_nodes[ iPrev ])[ 0 ];
2703 // double yP = nodeCoords( elemIt->_nodes[ iPrev ])[ 1 ];
2704 // double xN = nodeCoords( elemIt->_nodes[ iNext ])[ 0 ];
2705 // double yN = nodeCoords( elemIt->_nodes[ iNext ])[ 1 ];
2706 // double xL = nodeCoords( elemIt->_nodes[ iLeft ])[ 0 ];
2707 // double yL = nodeCoords( elemIt->_nodes[ iLeft ])[ 1 ];
2708 // double xPL = xL - xP, yPL = yL - yP; // components of prev-left vector
2709 // double xLN = xN - xL, yLN = yN - yL; // components of left-next vector
2710 // // normalise y of the vectors
2711 // double modPL = sqrt ( xPL * xPL + yPL * yPL );
2712 // double modLN = sqrt ( xLN * xLN + yLN * yLN );
2713 // if ( modLN > std::numeric_limits<double>::min() &&
2714 // modPL > std::numeric_limits<double>::min() )
2718 // // summary direction of neighboring links must be positive
2719 // bool clockwise = ( yPL + yLN > 0 );
2720 // if ( !clockwise )
2721 // reverse( *elemIt, swapVec );
2727 //================================================================================
2729 * \brief Fix connectivity of elements in 3D space
2731 //================================================================================
2733 void IntermediateMED::orientElements3D()
2735 // set _reverse flags of faces
2736 // COMMENTED for issue 0022612 note 17739
2739 // -----------------
2741 // -----------------
2743 std::set<Cell>::const_iterator elemIt, elemEnd;
2744 std::vector< std::pair<int,int> > swapVec;
2746 for ( int dim = 1; dim <= 3; ++dim )
2748 CellsByDimIterator cellsIt( *this, dim );
2749 while ( const std::set<Cell > * elems = cellsIt.nextType() )
2751 TCellType cellType = cellsIt.type();
2752 bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
2753 getReverseVector( cellType, swapVec );
2755 elemIt = elems->begin(), elemEnd = elems->end();
2756 for ( ; elemIt != elemEnd; elemIt++ )
2758 // GIBI connectivity -> MED one
2760 ConvertQuadratic( cellType, *elemIt );
2763 if ( elemIt->_reverse )
2764 reverse ( *elemIt, swapVec );
2769 // COMMENTED for issue 0022612 note 17739
2773 //================================================================================
2775 * \brief Orient equally (by setting _reverse flag) all connected faces in 3D space
2777 //================================================================================
2779 void IntermediateMED::orientFaces3D()
2781 // fill map of links and their faces
2782 std::set<const Cell*> faces;
2783 std::map<const Cell*, Group*> fgm;
2784 std::map<Link, std::list<const Cell*> > linkFacesMap;
2785 std::map<Link, std::list<const Cell*> >::iterator lfIt, lfIt2;
2787 for (size_t i=0; i!=_groups.size(); ++i)
2789 Group& grp = _groups[i];
2790 if ( !grp._cells.empty() && getDimension( grp._cellType ) == 2 )
2791 for ( size_t j = 0; j < grp._cells.size(); ++j )
2792 if ( faces.insert( grp._cells[j] ).second )
2794 for ( size_t k = 0; k < grp._cells[j]->_nodes.size(); ++k )
2795 linkFacesMap[ grp._cells[j]->link( k ) ].push_back( grp._cells[j] );
2796 fgm.insert( std::make_pair( grp._cells[j], &grp ));
2799 // dump linkFacesMap
2800 // for ( lfIt = linkFacesMap.begin(); lfIt!=linkFacesMap.end(); lfIt++) {
2801 // cout<< "LINK: " << lfIt->first.first << "-" << lfIt->first.second << std::endl;
2802 // std::list<const Cell*> & fList = lfIt->second;
2803 // std::list<const Cell*>::iterator fIt = fList.begin();
2804 // for ( ; fIt != fList.end(); fIt++ )
2805 // cout << "\t" << **fIt << fgm[*fIt]->nom << std::endl;
2808 // Each oriented link must appear in one face only, else a face is reversed.
2810 std::queue<const Cell*> faceQueue; /* the queue contains well oriented faces
2811 whose neighbors orientation is to be checked */
2812 bool manifold = true;
2813 while ( !linkFacesMap.empty() )
2815 if ( faceQueue.empty() )
2817 assert( !linkFacesMap.begin()->second.empty() );
2818 faceQueue.push( linkFacesMap.begin()->second.front() );
2820 while ( !faceQueue.empty() )
2822 const Cell* face = faceQueue.front();
2825 // loop on links of <face>
2826 for ( int i = 0; i < (int)face->_nodes.size(); ++i )
2828 Link link = face->link( i );
2829 // find the neighbor faces
2830 lfIt = linkFacesMap.find( link );
2831 int nbFaceByLink = 0;
2832 std::list< const Cell* > ml;
2833 if ( lfIt != linkFacesMap.end() )
2835 std::list<const Cell*> & fList = lfIt->second;
2836 std::list<const Cell*>::iterator fIt = fList.begin();
2837 assert( fIt != fList.end() );
2838 for ( ; fIt != fList.end(); fIt++, nbFaceByLink++ )
2840 ml.push_back( *fIt );
2841 if ( *fIt != face ) // wrongly oriented neighbor face
2843 const Cell* badFace = *fIt;
2844 // reverse and remove badFace from linkFacesMap
2845 for ( int j = 0; j < (int)badFace->_nodes.size(); ++j )
2847 Link badlink = badFace->link( j );
2848 if ( badlink == link ) continue;
2849 lfIt2 = linkFacesMap.find( badlink );
2850 if ( lfIt2 != linkFacesMap.end() )
2852 std::list<const Cell*> & ff = lfIt2->second;
2853 std::list<const Cell*>::iterator lfIt3 = find( ff.begin(), ff.end(), badFace );
2854 // check if badFace has been found,
2855 // else we can't erase it
2856 // case of degenerated face in edge
2857 if (lfIt3 != ff.end())
2861 linkFacesMap.erase( lfIt2 );
2865 badFace->_reverse = true; // reverse
2866 //INFOS_MED( "REVERSE " << *badFace );
2867 faceQueue.push( badFace );
2870 linkFacesMap.erase( lfIt );
2872 // add good neighbors to the queue
2873 Link revLink( link.second, link.first );
2874 lfIt = linkFacesMap.find( revLink );
2875 if ( lfIt != linkFacesMap.end() )
2877 std::list<const Cell*> & fList = lfIt->second;
2878 std::list<const Cell*>::iterator fIt = fList.begin();
2879 for ( ; fIt != fList.end(); fIt++, nbFaceByLink++ )
2881 ml.push_back( *fIt );
2883 faceQueue.push( *fIt );
2885 linkFacesMap.erase( lfIt );
2887 if ( nbFaceByLink > 2 )
2891 std::list<const Cell*>::iterator ii = ml.begin();
2892 std::cout << nbFaceByLink << " faces by 1 link:" << std::endl;
2893 for( ; ii!= ml.end(); ii++ )
2894 std::cout << "in sub-mesh <" << fgm[ *ii ]->_name << "> " << **ii << std::endl;
2898 } // loop on links of the being checked face
2899 } // loop on the face queue
2900 } // while ( !linkFacesMap.empty() )
2903 std::cout << " -> Non manifold mesh, faces orientation may be incorrect" << std::endl;
2906 //================================================================================
2908 * \brief Orient volumes according to MED conventions:
2909 * normal of a bottom (first) face should be outside
2911 //================================================================================
2913 void IntermediateMED::orientVolumes()
2915 std::set<Cell>::const_iterator elemIt, elemEnd;
2916 std::vector< std::pair<int,int> > swapVec;
2918 CellsByDimIterator cellsIt( *this, 3 );
2919 while ( const std::set<Cell > * elems = cellsIt.nextType() )
2921 TCellType cellType = cellsIt.type();
2922 elemIt = elems->begin(), elemEnd = elems->end();
2923 int nbBottomNodes = 0;
2930 nbBottomNodes = 3; break;
2935 nbBottomNodes = 4; break;
2938 getReverseVector( cellType, swapVec );
2940 for ( ; elemIt != elemEnd; elemIt++ )
2942 // find a normal to the bottom face
2944 n[0] = nodeCoords( elemIt->_nodes[0]); // 3 bottom nodes
2945 n[1] = nodeCoords( elemIt->_nodes[1]);
2946 n[2] = nodeCoords( elemIt->_nodes[2]);
2947 n[3] = nodeCoords( elemIt->_nodes[nbBottomNodes]); // a top node
2948 double vec01[3]; // vector n[0]-n[1]
2949 vec01[0] = n[1][0] - n[0][0];
2950 vec01[1] = n[1][1] - n[0][1];
2951 vec01[2] = n[1][2] - n[0][2];
2952 double vec02 [3]; // vector n[0]-n[2]
2953 vec02[0] = n[2][0] - n[0][0];
2954 vec02[1] = n[2][1] - n[0][1];
2955 vec02[2] = n[2][2] - n[0][2];
2956 double normal [3]; // vec01 ^ vec02
2957 normal[0] = vec01[1] * vec02[2] - vec01[2] * vec02[1];
2958 normal[1] = vec01[2] * vec02[0] - vec01[0] * vec02[2];
2959 normal[2] = vec01[0] * vec02[1] - vec01[1] * vec02[0];
2960 // check if the 102 angle is convex
2961 if ( nbBottomNodes > 3 )
2963 const double* n3 = nodeCoords( elemIt->_nodes[nbBottomNodes-1] );// last bottom node
2964 double vec03 [3]; // vector n[0]-n3
2965 vec03[0] = n3[0] - n[0][0];
2966 vec03[1] = n3[1] - n[0][1];
2967 vec03[2] = n3[2] - n[0][2];
2968 if ( fabs( normal[0]+normal[1]+normal[2] ) <= std::numeric_limits<double>::max() ) // vec01 || vec02
2970 normal[0] = vec01[1] * vec03[2] - vec01[2] * vec03[1]; // vec01 ^ vec03
2971 normal[1] = vec01[2] * vec03[0] - vec01[0] * vec03[2];
2972 normal[2] = vec01[0] * vec03[1] - vec01[1] * vec03[0];
2976 double vec [3]; // normal ^ vec01
2977 vec[0] = normal[1] * vec01[2] - normal[2] * vec01[1];
2978 vec[1] = normal[2] * vec01[0] - normal[0] * vec01[2];
2979 vec[2] = normal[0] * vec01[1] - normal[1] * vec01[0];
2980 double dot2 = vec[0]*vec03[0] + vec[1]*vec03[1] + vec[2]*vec03[2]; // vec*vec03
2981 if ( dot2 < 0 ) // concave -> reverse normal
2989 // direction from top to bottom
2991 tbDir[0] = n[0][0] - n[3][0];
2992 tbDir[1] = n[0][1] - n[3][1];
2993 tbDir[2] = n[0][2] - n[3][2];
2995 // compare 2 directions: normal and top-bottom
2996 double dot = normal[0]*tbDir[0] + normal[1]*tbDir[1] + normal[2]*tbDir[2];
2997 if ( dot < 0. ) // need reverse
2998 reverse( *elemIt, swapVec );
3000 } // loop on volumes of one geometry
3001 } // loop on 3D geometry types
3005 //================================================================================
3007 * \brief Assign new IDs to nodes by skipping not used nodes and return their number
3009 //================================================================================
3011 int NodeContainer::numberNodes()
3014 for ( size_t i = 0; i < _nodes.size(); ++i )
3015 for ( size_t j = 0; j < _nodes[i].size(); ++j )
3016 if ( _nodes[i][j].isUsed() )
3017 _nodes[i][j]._number = id++;
3022 //================================================================================
3024 * \brief Assign new IDs to elements
3026 //================================================================================
3028 void IntermediateMED::numberElements()
3030 std::set<Cell>::const_iterator elemIt, elemEnd;
3032 // numbering _cells of type NORM_POINT1 by node number
3034 const std::set<Cell>& points = _cellsByType[ INTERP_KERNEL::NORM_POINT1 ];
3035 elemIt = points.begin(), elemEnd = points.end();
3036 for ( ; elemIt != elemEnd; ++elemIt )
3037 elemIt->_number = elemIt->_nodes[0]->_number;
3040 // numbering 1D-3D _cells
3041 for ( int dim = 1; dim <= 3; ++dim )
3043 // check if re-numeration is needed (to try to keep elem oreder as in sauve file )
3044 bool ok = true, renumEntity = false;
3045 CellsByDimIterator cellsIt( *this, dim );
3046 int prevNbElems = 0;
3047 while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
3049 TID minNumber = std::numeric_limits<TID>::max(), maxNumber = 0;
3050 for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
3052 if ( elemIt->_number < minNumber ) minNumber = elemIt->_number;
3053 if ( elemIt->_number > maxNumber ) maxNumber = elemIt->_number;
3055 TID typeSize = typeCells->size();
3056 if ( typeSize != maxNumber - minNumber + 1 )
3058 if ( prevNbElems != 0 ) {
3059 if ( minNumber == 1 )
3061 else if ( prevNbElems+1 != (int)minNumber )
3064 prevNbElems += typeSize;
3067 if ( ok && renumEntity ) // each geom type was numerated separately
3069 cellsIt.init( dim );
3070 prevNbElems = cellsIt.nextType()->size(); // no need to renumber the first type
3071 while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
3073 for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
3074 elemIt->_number += prevNbElems;
3075 prevNbElems += typeCells->size();
3081 cellsIt.init( dim );
3082 while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
3083 for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
3084 elemIt->_number = cellID++;
3089 //================================================================================
3091 * \brief Creates coord array
3093 //================================================================================
3095 ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords()
3097 DataArrayDouble* coordArray = DataArrayDouble::New();
3098 coordArray->alloc( _nbNodes, _spaceDim );
3099 double * coordPrt = coordArray->getPointer();
3100 for ( int i = 0, nb = _points.size(); i < nb; ++i )
3102 Node* n = getNode( i+1 );
3105 const double* nCoords = nodeCoords( n );
3106 std::copy( nCoords, nCoords+_spaceDim, coordPrt );
3107 coordPrt += _spaceDim;
3113 //================================================================================
3115 * \brief Sets connectivity of elements to the mesh
3116 * \param mesh - mesh to fill in
3117 * \param coords - coordinates that must be shared by all meshes of different dim
3119 //================================================================================
3121 void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh* mesh,
3122 ParaMEDMEM::DataArrayDouble* coords )
3126 mesh->setCoords( coords );
3128 std::set<Cell>::const_iterator elemIt, elemEnd;
3129 for ( int dim = 3; dim > 0; --dim )
3131 CellsByDimIterator dimCells( *this, dim );
3134 while ( const std::set<Cell > * cells = dimCells.nextType() )
3135 nbOfCells += cells->size();
3136 if ( nbOfCells == 0 )
3139 if ( !meshDim ) meshDim = dim;
3141 MEDCouplingUMesh* dimMesh = MEDCouplingUMesh::New();
3142 dimMesh->setCoords( coords );
3143 dimMesh->setMeshDimension( dim );
3144 dimMesh->allocateCells( nbOfCells );
3146 int prevNbCells = 0;
3147 dimCells.init( dim );
3148 while ( const std::set<Cell > * cells = dimCells.nextType() )
3150 // fill connectivity array to take into account order of elements in the sauv file
3151 const int nbCellNodes = cells->begin()->_nodes.size();
3152 std::vector< TID > connectivity( cells->size() * nbCellNodes );
3153 int * nodalConnOfCell;
3154 for ( elemIt = cells->begin(), elemEnd = cells->end(); elemIt != elemEnd; ++elemIt )
3156 const Cell& cell = *elemIt;
3157 const int index = cell._number - 1 - prevNbCells;
3158 nodalConnOfCell = &connectivity[ index * nbCellNodes ];
3159 if ( cell._reverse )
3160 for ( int i = nbCellNodes-1; i >= 0; --i )
3161 *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
3163 for ( int i = 0; i < nbCellNodes; ++i )
3164 *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
3166 prevNbCells += cells->size();
3169 TCellType cellType = dimCells.type();
3170 nodalConnOfCell = &connectivity[0];
3171 for ( size_t i = 0; i < cells->size(); ++i, nodalConnOfCell += nbCellNodes )
3172 dimMesh->insertNextCell( cellType, nbCellNodes, nodalConnOfCell );
3174 dimMesh->finishInsertingCells();
3175 mesh->setMeshAtLevel( dim - meshDim, dimMesh );
3180 //================================================================================
3182 * \brief Fill in the mesh with groups
3183 * \param mesh - mesh to fill in
3185 //================================================================================
3187 void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
3189 bool isMeshNameSet = false;
3190 const int meshDim = mesh->getMeshDimension();
3191 for ( int dim = 0; dim <= meshDim; ++dim )
3193 const int meshDimRelToMaxExt = ( dim == 0 ? 1 : dim - meshDim );
3195 std::vector<const DataArrayInt *> medGroups;
3196 std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > refGroups;
3197 for ( size_t i = 0; i < _groups.size(); ++i )
3199 Group& grp = _groups[i];
3200 if ( (int)getDim( &grp ) != dim &&
3201 grp._groups.empty() ) // to allow groups on diff dims
3203 // convert only named groups or field supports
3204 if ( grp.empty() || (grp._name.empty() && !grp._isProfile ))
3206 //if ( grp._medGroup ) continue; // already converted
3208 // sort cells by ID and remember their initial order in the group
3209 TCellToOrderMap cell2order;
3210 unsigned orderInGroup = 0;
3211 std::vector< Group* > groupVec;
3212 if ( grp._groups.empty() ) groupVec.push_back( & grp );
3213 else groupVec = grp._groups;
3214 for ( size_t iG = 0; iG < groupVec.size(); ++iG )
3216 Group* aG = groupVec[ iG ];
3217 if ( (int)getDim( aG ) != dim )
3219 for ( size_t iC = 0; iC < aG->_cells.size(); ++iC )
3220 cell2order.insert( cell2order.end(), std::make_pair( aG->_cells[iC], orderInGroup++ ));
3222 if ( cell2order.empty() )
3224 bool isSelfIntersect = ( orderInGroup != cell2order.size() );
3225 if ( isSelfIntersect ) // self intersecting group
3227 std::ostringstream msg;
3228 msg << "Self intersecting sub-mesh: id = " << i+1
3229 << ", name = |" << grp._name << "|" << std::endl
3230 << " nb unique elements = " << cell2order.size() << std::endl
3231 << " total nb elements = " << orderInGroup;
3232 if ( grp._isProfile )
3234 THROW_IK_EXCEPTION( msg.str() );
3238 std::cout << msg.str() << std::endl;
3241 // create a med group
3242 grp._medGroup = DataArrayInt::New();
3243 grp._medGroup->setName( grp._name.c_str() );
3244 grp._medGroup->alloc( cell2order.size(), /*nbOfCompo=*/1 );
3245 int * idsPtr = grp._medGroup->getPointer();
3246 TCellToOrderMap::iterator cell2orderIt, cell2orderEnd = cell2order.end();
3247 for ( cell2orderIt = cell2order.begin(); cell2orderIt != cell2orderEnd; ++cell2orderIt )
3248 *idsPtr++ = (*cell2orderIt).first->_number - 1;
3250 // try to set the mesh name
3251 if ( !isMeshNameSet &&
3253 !grp._name.empty() &&
3254 grp.size() == mesh->getSizeAtLevel( meshDimRelToMaxExt ))
3256 mesh->setName( grp._name.c_str() );
3257 isMeshNameSet = true;
3259 if ( !grp._name.empty() )
3261 medGroups.push_back( grp._medGroup );
3263 // set relocation table
3264 setRelocationTable( &grp, cell2order );
3266 // Issue 0021311. Use case: a gibi group has references (recorded in pile 1)
3267 // and several names (pile 27) refer (pile 10) to this group.
3268 // We create a copy of this group per each named reference
3269 std::set<std::string> uniqueNames;
3270 uniqueNames.insert( grp._name );
3271 for ( unsigned iRef = 0 ; iRef < grp._refNames.size(); ++iRef )
3272 if ( !grp._refNames[ iRef ].empty() &&
3273 uniqueNames.insert( grp._refNames[ iRef ]).second ) // for name uniqueness (23155)
3275 refGroups.push_back( grp._medGroup->deepCpy() );
3276 refGroups.back()->setName( grp._refNames[ iRef ].c_str() );
3277 medGroups.push_back( refGroups.back() );
3280 mesh->setGroupsAtLevel( meshDimRelToMaxExt, medGroups );
3284 //================================================================================
3286 * \brief Return true if the group is on all elements and return its relative dimension
3288 //================================================================================
3290 bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
3292 int dim = getDim( grp );
3302 CellsByDimIterator dimCells( *this, dim );
3303 while ( const std::set<Cell > * cells = dimCells.nextType() )
3304 nbElems += cells->size();
3307 for ( ; meshDim > 0; --meshDim )
3309 dimCells.init( meshDim );
3310 if ( dimCells.nextType() )
3313 dimRel = dim - meshDim;
3316 bool onAll = ( nbElems == grp->size() );
3320 //================================================================================
3322 * \brief Makes fields from own data
3324 //================================================================================
3326 ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFileUMesh* mesh)
3328 if ( _nodeFields.empty() && _cellFields.empty() ) return 0;
3331 std::set< std::string > usedFieldNames;
3332 setFieldLongNames(usedFieldNames);
3334 MEDFileFields* fields = MEDFileFields::New();
3336 for ( size_t i = 0; i < _nodeFields.size(); ++i )
3337 setFields( _nodeFields[i], fields, mesh, i+1, usedFieldNames );
3339 for ( size_t i = 0; i < _cellFields.size(); ++i )
3340 setFields( _cellFields[i], fields, mesh, i+1, usedFieldNames );
3345 //================================================================================
3347 * \brief Make med fields from a SauvUtilities::DoubleField
3349 //================================================================================
3351 void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
3352 ParaMEDMEM::MEDFileFields* medFields,
3353 ParaMEDMEM::MEDFileUMesh* mesh,
3355 std::set< std::string >& usedFieldNames)
3357 bool sameNbGauss = true;
3358 if ( !fld || !fld->isMedCompatible( sameNbGauss )) return;
3361 fld->splitSubWithDiffNbGauss();
3363 // if ( !fld->hasCommonSupport() ):
3364 // each sub makes MEDFileFieldMultiTS
3366 // unite several subs into a MEDCouplingFieldDouble
3368 const bool uniteSubs = fld->hasCommonSupport() && sameNbGauss;
3370 std::cout << "Castem field #" << castemID << " <" << fld->_name
3371 << "> is incompatible with MED format, so we split it into several fields:" << std::endl;
3373 for ( size_t iSub = 0; iSub < fld->_sub.size(); )
3376 if ( !uniteSubs || fld->_name.empty() )
3377 makeFieldNewName( usedFieldNames, fld );
3380 DataArrayDouble * values = DataArrayDouble::New();
3381 values->alloc( fld->getNbTuples(iSub), fld->_sub[iSub].nbComponents() );
3384 double * valPtr = values->getPointer();
3387 int nbElems = fld->_group->size();
3388 for ( int elemShift = 0; elemShift < nbElems && iSub < fld->_sub.size(); )
3389 elemShift += fld->setValues( valPtr, iSub++, elemShift );
3390 setTS( fld, values, medFields, mesh );
3394 fld->setValues( valPtr, iSub );
3395 setTS( fld, values, medFields, mesh, iSub++ );
3397 std::cout << fld->_name << " with compoments";
3398 for ( size_t i = 0; i < (size_t)fld->_sub[iSub-1].nbComponents(); ++i )
3399 std::cout << " " << fld->_sub[iSub-1]._comp_names[ i ];
3400 std::cout << std::endl;
3405 //================================================================================
3407 * \brief Store value array of a field into med fields
3409 //================================================================================
3411 void IntermediateMED::setTS( SauvUtilities::DoubleField* fld,
3412 ParaMEDMEM::DataArrayDouble* values,
3413 ParaMEDMEM::MEDFileFields* medFields,
3414 ParaMEDMEM::MEDFileUMesh* mesh,
3417 // treat a field support
3418 const Group* support = fld->getSupport( iSub );
3420 const bool onAll = isOnAll( support, dimRel );
3421 if ( !onAll && support->_name.empty() )
3423 const_cast<Group*>(support)->_name += "PFL_" + fld->_name;
3424 support->_medGroup->setName( support->_name.c_str() );
3427 // make and fill a time-stamp
3429 MEDCouplingFieldDouble * timeStamp = MEDCouplingFieldDouble::New( fld->getMedType( iSub ),
3430 fld->getMedTimeDisc() );
3431 timeStamp->setName( fld->_name.c_str() );
3432 timeStamp->setDescription( fld->_description.c_str() );
3436 MEDCouplingAutoRefCountObjectPtr
3437 < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
3438 timeStamp->setMesh( dimMesh );
3440 else if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_NODES )
3442 DataArrayDouble * coo = mesh->getCoords();
3443 MEDCouplingAutoRefCountObjectPtr
3444 <DataArrayDouble> subCoo = coo->selectByTupleId(support->_medGroup->begin(),
3445 support->_medGroup->end());
3446 MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh =
3447 MEDCouplingUMesh::Build0DMeshFromCoords( subCoo );
3448 timeStamp->setMesh( nodeSubMesh );
3452 MEDCouplingAutoRefCountObjectPtr
3453 < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
3454 MEDCouplingAutoRefCountObjectPtr
3455 <MEDCouplingMesh> subMesh = dimMesh->buildPart(support->_medGroup->begin(),
3456 support->_medGroup->end());
3457 timeStamp->setMesh( subMesh);
3460 for ( size_t i = 0; i < (size_t)fld->_sub[iSub].nbComponents(); ++i )
3461 values->setInfoOnComponent( i, fld->_sub[iSub]._comp_names[ i ].c_str() );
3462 timeStamp->setArray( values );
3465 if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT )
3467 TGaussDef gaussDef( fld->_sub[iSub]._support->_cellType,
3468 fld->_sub[iSub].nbGauss() );
3469 timeStamp->setGaussLocalizationOnType( fld->_sub[iSub]._support->_cellType,
3470 gaussDef.myRefCoords,
3472 gaussDef.myWeights );
3474 // get a field to add the time-stamp
3475 bool isNewMedField = false;
3476 if ( !fld->_curMedField || fld->_name != fld->_curMedField->getName() )
3478 fld->_curMedField = MEDFileFieldMultiTS::New();
3479 isNewMedField = true;
3483 const int nbTS = fld->_curMedField->getNumberOfTS();
3485 timeStamp->setOrder( nbTS );
3487 // add the time-stamp
3488 timeStamp->checkCoherency();
3490 fld->_curMedField->appendFieldNoProfileSBT( timeStamp );
3492 fld->_curMedField->appendFieldProfile( timeStamp, mesh, dimRel, support->_medGroup );
3493 timeStamp->decrRef();
3495 if ( isNewMedField ) // timeStamp must be added before this
3497 medFields->pushField( fld->_curMedField );
3501 //================================================================================
3503 * \brief Make a new unique name for a field
3505 //================================================================================
3507 void IntermediateMED::makeFieldNewName(std::set< std::string >& usedNames,
3508 SauvUtilities::DoubleField* fld )
3510 std::string base = fld->_name;
3517 std::string::size_type pos = base.rfind('_');
3518 if ( pos != std::string::npos )
3519 base = base.substr( 0, pos+1 );
3527 fld->_name = base + SauvUtilities::toString( i++ );
3529 while( !usedNames.insert( fld->_name ).second );
3532 //================================================================================
3534 * \brief Split sub-components with different nb of gauss points into several sub-components
3535 * \param [in,out] fld - a field to split if necessary
3537 //================================================================================
3539 void DoubleField::splitSubWithDiffNbGauss()
3541 for ( size_t iSub = 0; iSub < _sub.size(); ++iSub )
3543 if ( _sub[iSub].isSameNbGauss() ) continue;
3545 _sub.insert( _sub.begin() + iSub + 1, 1, _Sub_data() );
3546 _Sub_data & subToSplit = _sub[iSub];
3547 _Sub_data & subNew = _sub[iSub+1];
3549 while ( subToSplit._nb_gauss[ 0 ] == subToSplit._nb_gauss[ iDiff ] )
3551 subNew._support = subToSplit._support;
3552 subNew._comp_names.assign( subToSplit._comp_names.begin() + iDiff,
3553 subToSplit._comp_names.end() );
3554 subNew._nb_gauss.assign ( subToSplit._nb_gauss.begin() + iDiff,
3555 subToSplit._nb_gauss.end() );
3556 subToSplit._comp_names.resize( iDiff );
3557 subToSplit._nb_gauss.resize ( iDiff );
3561 //================================================================================
3563 * \brief Return a vector ready to fill in
3565 //================================================================================
3567 std::vector< double >& DoubleField::addComponent( int nb_values )
3569 _comp_values.push_back( std::vector< double >() );
3570 std::vector< double >& res = _comp_values.back();
3571 res.resize( nb_values );
3575 DoubleField::~DoubleField()
3578 _curMedField->decrRef();
3581 //================================================================================
3583 * \brief Returns a supporting group
3585 //================================================================================
3587 const Group* DoubleField::getSupport( const int iSub ) const
3589 return _group ? _group : _sub[iSub]._support;
3592 //================================================================================
3594 * \brief Return true if each sub-component is a time stamp
3596 //================================================================================
3598 bool DoubleField::isMultiTimeStamps() const
3600 if ( _sub.size() < 2 )
3602 bool sameSupports = true;
3603 Group* grpp1 = _sub[0]._support;// grpp NOT grp because XDR under Windows defines grp...
3604 for ( size_t i = 1; i < _sub.size() && sameSupports; ++i )
3605 sameSupports = ( grpp1 == _sub[i]._support );
3607 return sameSupports;
3610 //================================================================================
3612 * \brief True if the field can be converted into the med field
3614 //================================================================================
3616 bool DoubleField::isMedCompatible(bool& sameNbGauss) const
3618 for ( size_t iSub = 0; iSub < _sub.size(); ++iSub )
3620 if ( !getSupport(iSub) || !getSupport(iSub)->_medGroup )
3621 THROW_IK_EXCEPTION("SauvReader INTERNAL ERROR: NULL field support");
3624 if ( !_sub[iSub].isSameNbGauss() )
3626 std::cout << "Field <" << _name << "> : different nb of gauss points in components" << std::endl;
3627 sameNbGauss = false;
3634 //================================================================================
3636 * \brief return true if all sub-components has same components and same nbGauss
3638 //================================================================================
3640 bool DoubleField::hasSameComponentsBySupport() const
3642 std::vector< _Sub_data >::const_iterator sub_data = _sub.begin();
3643 const _Sub_data& first_sub_data = *sub_data;
3644 for ( ++sub_data ; sub_data != _sub.end(); ++sub_data )
3646 if ( first_sub_data._comp_names != sub_data->_comp_names )
3647 return false; // diff names of components
3649 if ( first_sub_data._nb_gauss != sub_data->_nb_gauss &&
3650 first_sub_data._support->_cellType == sub_data->_support->_cellType)
3651 return false; // diff nb of gauss points on same cell type
3656 //================================================================================
3658 * \brief Return type of MEDCouplingFieldDouble
3660 //================================================================================
3662 ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const
3664 using namespace INTERP_KERNEL;
3666 const Group* grp = hasCommonSupport() ? _group : _sub[iSub]._support;
3667 if ( _sub[iSub].nbGauss() > 1 )
3669 const CellModel& cm = CellModel::GetCellModel( _sub[iSub]._support->_cellType );
3670 return (int) cm.getNumberOfNodes() == _sub[iSub].nbGauss() ? ON_GAUSS_NE : ON_GAUSS_PT;
3674 return getDim( grp ) == 0 ? ON_NODES : ON_CELLS;
3678 //================================================================================
3680 * \brief Return TypeOfTimeDiscretization
3682 //================================================================================
3684 ParaMEDMEM::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
3690 // CONST_ON_TIME_INTERVAL = 7
3693 //================================================================================
3695 * \brief Return nb tuples to be used to allocate DataArrayDouble
3697 //================================================================================
3699 int DoubleField::getNbTuples( const int iSub ) const
3702 if ( hasCommonSupport() && !_group->_groups.empty() )
3703 for ( size_t i = 0; i < _group->_groups.size(); ++i )
3704 nb += _sub[i].nbGauss() * _sub[i]._support->size();
3706 nb = _sub[iSub].nbGauss() * getSupport(iSub)->size();
3710 //================================================================================
3712 * \brief Store values of a sub-component and return nb of elements in the iSub
3714 //================================================================================
3716 int DoubleField::setValues( double * valPtr, const int iSub, const int elemShift ) const
3718 // find values for iSub
3720 for ( int iS = 0; iS < iSub; ++iS )
3721 iComp += _sub[iS].nbComponents();
3722 const std::vector< double > * compValues = &_comp_values[ iComp ];
3726 const std::vector< unsigned >& relocTable = getSupport( iSub )->_relocTable;
3728 const int nbElems = _sub[iSub]._support->size();
3729 const int nbGauss = _sub[iSub].nbGauss();
3730 const int nbComponents = _sub[iSub].nbComponents();
3731 const int nbValsByElem = nbComponents * nbGauss;
3735 for ( iComp = 0; iComp < nbComponents; ++iComp )
3736 nbVals += compValues[iComp].size();
3737 const bool isConstField = ( nbVals == nbComponents ); // one value per component (issue 22321)
3738 if ( !isConstField && nbVals != nbElems * nbValsByElem )
3739 THROW_IK_EXCEPTION("SauvMedConvertor.cxx: support size mismatches field size");
3741 // compute nb values in previous subs
3743 for ( int iS = iSub-1, shift = elemShift; shift > 0; --iS)
3745 int nbE = _sub[iS]._support->size();
3747 valsShift += nbE * _sub[iS].nbComponents() * _sub[iS].nbGauss();
3751 for ( int iE = 0; iE < nbElems; ++iE )
3753 int iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
3754 for ( iComp = 0; iComp < nbComponents; ++iComp )
3755 valPtr[ iMed + iComp ] = compValues[iComp][ 0 ];
3758 for ( int iE = 0; iE < nbElems; ++iE )
3760 int iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
3761 for ( iComp = 0; iComp < nbComponents; ++iComp )
3762 for ( int iG = 0; iG < nbGauss; ++iG )
3763 valPtr[ iMed + iG * nbComponents + iComp ] = compValues[iComp][ iE * nbGauss + iG ];
3768 //================================================================================
3770 * \brief Destructor of IntermediateMED
3772 //================================================================================
3774 IntermediateMED::~IntermediateMED()
3776 for ( size_t i = 0; i < _nodeFields.size(); ++i )
3777 if ( _nodeFields[i] )
3778 delete _nodeFields[i];
3779 _nodeFields.clear();
3781 for ( size_t i = 0; i < _cellFields.size(); ++i )
3782 if ( _cellFields[i] )
3783 delete _cellFields[i];
3784 _cellFields.clear();
3786 for ( size_t i = 0; i < _groups.size(); ++i )
3787 if ( _groups[i]._medGroup )
3788 _groups[i]._medGroup->decrRef();
3791 //================================================================================
3793 * \brief CellsByDimIterator constructor
3795 CellsByDimIterator::CellsByDimIterator( const IntermediateMED & medi, int dimm)
3801 * \brief Initialize iteration on cells of given dimention
3803 void CellsByDimIterator::init(const int dimm)
3806 myTypeEnd = INTERP_KERNEL::NORM_HEXA20 + 1;
3810 * \brief return next set of Cell's of required dimension
3812 const std::set< Cell > * CellsByDimIterator::nextType()
3814 while ( ++myCurType < myTypeEnd )
3815 if ( !myImed->_cellsByType[myCurType].empty() && ( myDim < 0 || dim(false) == myDim ))
3816 return & myImed->_cellsByType[myCurType];
3820 * \brief return dimension of cells returned by the last or further next()
3822 int CellsByDimIterator::dim(const bool last) const
3824 int typp = myCurType;
3826 while ( typp < myTypeEnd && myImed->_cellsByType[typp].empty() )
3828 return typp < myTypeEnd ? getDimension( TCellType( typp )) : 4;
3830 // END CellsByDimIterator ========================================================