1 // HOMARD HOMARD : implementation of HOMARD idl descriptions
3 // Copyright (C) 2011-2021 CEA/DEN, EDF R&D
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // Author : Gerald NICOLAS, EDF
25 #ifndef _SMESH_HOMARD_ADAPT_HXX_
26 #define _SMESH_HOMARD_ADAPT_HXX_
28 // C'est le ASSERT de SALOMELocalTrace/utilities.h dans KERNEL
30 #define VERIFICATION(condition) \
31 if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
32 #endif /* VERIFICATION */
35 #if defined HOMARDIMPL_EXPORTS || defined HOMARDImpl_EXPORTS
36 #define HOMARDIMPL_EXPORT __declspec( dllexport )
38 #define HOMARDIMPL_EXPORT __declspec( dllimport )
41 #define HOMARDIMPL_EXPORT
44 // La gestion des repertoires
61 #include <TopoDS_Shape.hxx>
62 #include <Bnd_Box.hxx>
63 #include <NCollection_DataMap.hxx>
64 #include <TColStd_DataMapOfIntegerInteger.hxx>
67 #pragma warning ( disable: 4251 )
70 namespace MEDCoupling {
71 class DataArrayDouble;
79 namespace SMESHHOMARDImpl
82 class HOMARDIMPL_EXPORT HOMARD_Boundary
89 void SetName( const char* Name );
90 std::string GetName() const;
92 std::string GetDumpPython() const;
95 void SetType( int Type );
98 void SetMeshName( const char* MeshName );
99 std::string GetMeshName() const;
101 void SetDataFile( const char* DataFile );
102 std::string GetDataFile() const;
104 void SetCylinder( double X0, double X1, double X2, double X3,
105 double X4, double X5, double X6 );
106 void SetSphere( double X0, double X1, double X2, double X3 );
107 void SetConeR( double Xcentre1, double Ycentre1, double Zcentre1, double Rayon1,
108 double Xcentre2, double Ycentre2, double Zcentre2, double Rayon2);
109 void SetConeA( double Xaxe, double Yaxe, double Zaxe, double Angle,
110 double Xcentre, double Ycentre, double ZCentre);
111 void SetTorus( double X0, double X1, double X2, double X3,
112 double X4, double X5, double X6, double X7 );
114 std::vector<double> GetCoords() const;
116 void SetLimit( double X0, double X1, double X2 );
117 std::vector<double> GetLimit() const;
119 void AddGroup( const char* LeGroupe);
120 void SetGroups(const std::list<std::string>& ListGroup );
121 const std::list<std::string>& GetGroups() const;
123 // Liens avec les autres structures
124 std::string GetCaseCreation() const;
125 void SetCaseCreation( const char* NomCasCreation );
129 std::string _NomCasCreation;
130 std::string _DataFile;
131 std::string _MeshName;
133 double _Xmin, _Xmax, _Ymin, _Ymax, _Zmin, _Zmax;
134 double _Xaxe, _Yaxe, _Zaxe;
135 double _Xcentre, _Ycentre, _Zcentre, _rayon;
136 double _Xincr, _Yincr, _Zincr;
137 double _Xcentre1, _Ycentre1, _Zcentre1, _Rayon1;
138 double _Xcentre2, _Ycentre2, _Zcentre2, _Rayon2;
141 std::list<std::string> _ListGroupSelected;
145 class HOMARDIMPL_EXPORT HOMARD_Cas
152 void SetName( const char* Name );
153 std::string GetName() const;
155 std::string GetDumpPython() const;
158 int SetDirName( const char* NomDir );
159 std::string GetDirName() const;
161 int GetNumberofIter();
163 void SetConfType( int ConfType );
164 const int GetConfType() const;
166 void SetBoundingBox( const std::vector<double>& extremas );
167 const std::vector<double>& GetBoundingBox() const;
169 void AddGroup( const char* Group);
170 void SetGroups( const std::list<std::string>& ListGroup );
171 const std::list<std::string>& GetGroups() const;
174 void AddBoundary( const char* Boundary );
175 void AddBoundaryGroup( const char* Boundary, const char* Group );
176 const std::list<std::string>& GetBoundaryGroup() const;
177 void SupprBoundaryGroup();
179 // Liens avec les autres structures
180 std::string GetIter0Name() const;
182 void AddIteration( const char* NomIteration );
183 const std::list<std::string>& GetIterations() const;
184 void SupprIterations();
192 std::vector<double> _Boite; // cf HomardQTCommun pour structure du vecteur
193 std::list<std::string> _ListGroup;
194 std::list<std::string> _ListBoundaryGroup;
196 typedef std::string IterName;
197 typedef std::list<IterName> IterNames;
201 class HOMARDIMPL_EXPORT HomardDriver
204 HomardDriver(const std::string siter, const std::string siterp1);
207 void TexteInit( const std::string DirCompute, const std::string LogFile, const std::string Langue );
208 void TexteInfo( int TypeBila, int NumeIter );
209 void TexteMajCoords( int NumeIter );
210 void CreeFichierDonn();
213 void TexteMaillage( const std::string NomMesh, const std::string MeshFile, int apres );
214 void TexteMaillageHOMARD( const std::string Dir, const std::string liter, int apres );
215 void TexteConfRaffDera( int ConfType, int TypeAdap, int TypeRaff, int TypeDera );
216 void TexteZone( int NumeZone, int ZoneType, int TypeUse, double x0, double x1, double x2, double x3, double x4, double x5, double x6, double x7, double x8 );
217 void TexteGroup( const std::string GroupName );
218 void TexteField( const std::string FieldName, const std::string FieldFile,
219 int TimeStep, int Rank,
220 int TypeThR, double ThreshR, int TypeThC, double ThreshC,
221 int UsField, int UsCmpI );
222 void TexteCompo( int NumeComp, const std::string NomCompo);
224 void TexteBoundaryOption( int BoundaryOption );
225 void TexteBoundaryCAOGr( const std::string GroupName );
226 void TexteBoundaryDi( const std::string MeshName, const std::string MeshFile );
227 void TexteBoundaryDiGr( const std::string GroupName );
228 void TexteBoundaryAn( const std::string NameBoundary, int NumeBoundary, int BoundaryType, double x0, double x1, double x2, double x3, double x4, double x5, double x6, double x7 );
229 void TexteBoundaryAnGr( const std::string NameBoundary, int NumeBoundary, const std::string GroupName );
231 void TexteFieldInterp( const std::string FieldFile, const std::string MeshFile );
232 void TexteFieldInterpAll();
233 void TexteFieldInterpNameType( int NumeChamp, const std::string FieldName, const std::string TypeInterp, int TimeStep, int Rank );
234 void TexteAdvanced( int NivMax, double DiamMin, int AdapInit, int LevelOutput );
235 void TexteInfoCompute( int MessInfo );
241 std::string _HOMARD_Exec;
243 std::string _NomFichierConfBase;
244 std::string _NomFichierConf;
245 std::string _NomFichierDonn;
247 std::string _siterp1;
254 class HOMARD_Iteration;
255 class HOMARD_Hypothesis;
257 //! persistence entity type
258 typedef enum { Case, Zone, Hypothesis, Iteration, Boundary } SignatureType;
260 //! get persistence signature
261 HOMARDIMPL_EXPORT std::string GetSignature( SignatureType type );
263 //! get data separator
264 HOMARDIMPL_EXPORT std::string separator();
266 //! dump boundary to the string
267 HOMARDIMPL_EXPORT std::string Dump( const SMESHHOMARDImpl::HOMARD_Boundary& boundary );
268 //! dump case to the string
269 HOMARDIMPL_EXPORT std::string Dump( const SMESHHOMARDImpl::HOMARD_Cas& cas );
270 //! dump iteration to the string
271 HOMARDIMPL_EXPORT std::string Dump( const SMESHHOMARDImpl::HOMARD_Iteration& iteration );
272 //! dump hypothesis to the string
273 HOMARDIMPL_EXPORT std::string Dump( const SMESHHOMARDImpl::HOMARD_Hypothesis& hypothesis );
275 //! restore boundary from the string
276 HOMARDIMPL_EXPORT bool Restore( SMESHHOMARDImpl::HOMARD_Boundary& boundary, const std::string& stream );
277 //! restore case from the string
278 HOMARDIMPL_EXPORT bool Restore( SMESHHOMARDImpl::HOMARD_Cas& cas, const std::string& stream );
279 //! restore hypothesis from the string
280 HOMARDIMPL_EXPORT bool Restore( SMESHHOMARDImpl::HOMARD_Hypothesis& hypothesis, const std::string& stream );
281 //! restore iteration from the string
282 HOMARDIMPL_EXPORT bool Restore( SMESHHOMARDImpl::HOMARD_Iteration& iteration, const std::string& stream );
284 class HOMARDIMPL_EXPORT HOMARD_Gen
291 class HOMARDIMPL_EXPORT HOMARD_Hypothesis
295 ~HOMARD_Hypothesis();
298 void SetName( const char* Name );
299 std::string GetName() const;
302 void SetAdapType( int TypeAdap );
303 int GetAdapType() const;
304 void SetRefinTypeDera( int TypeRaff, int TypeDera );
305 int GetRefinType() const;
306 int GetUnRefType() const;
308 void SetField( const char* FieldName );
309 std::string GetFieldName() const;
310 void SetUseField( int UsField );
311 int GetUseField() const;
313 void SetUseComp( int UsCmpI );
314 int GetUseComp() const;
315 void AddComp( const char* NomComp );
316 void SupprComp( const char* NomComp );
318 const std::list<std::string>& GetComps() const;
320 void SetRefinThr( int TypeThR, double ThreshR );
321 int GetRefinThrType() const;
322 double GetThreshR() const;
323 void SetUnRefThr( int TypeThC, double ThreshC );
324 int GetUnRefThrType() const;
325 double GetThreshC() const;
327 void SetNivMax( int NivMax );
328 const int GetNivMax() const;
330 void SetDiamMin( double DiamMin );
331 const double GetDiamMin() const;
333 void SetAdapInit( int AdapInit );
334 const int GetAdapInit() const;
336 void SetExtraOutput( int ExtraOutput );
337 const int GetExtraOutput() const;
339 void AddGroup( const char* Group);
340 void SupprGroup( const char* Group );
342 void SetGroups(const std::list<std::string>& ListGroup );
343 const std::list<std::string>& GetGroups() const;
345 void SetTypeFieldInterp( int TypeFieldInterp );
346 int GetTypeFieldInterp() const;
347 void AddFieldInterpType( const char* FieldInterp, int TypeInterp );
348 void SupprFieldInterp( const char* FieldInterp );
349 void SupprFieldInterps();
350 const std::list<std::string>& GetFieldInterps() const;
352 // Liens avec les autres structures
353 void SetCaseCreation( const char* NomCasCreation );
354 std::string GetCaseCreation() const;
356 void LinkIteration( const char* NomIter );
357 void UnLinkIteration( const char* NomIter );
358 void UnLinkIterations();
359 const std::list<std::string>& GetIterations() const;
361 void AddZone( const char* NomZone, int TypeUse );
362 void SupprZone( const char* NomZone );
364 const std::list<std::string>& GetZones() const;
368 std::string _NomCasCreation;
370 int _TypeAdap; // -1 pour une adapation Uniforme,
371 // 0 si l adaptation depend des zones,
384 int _TypeFieldInterp; // 0 pour aucune interpolation,
385 // 1 pour interpolation de tous les champs,
392 std::list<std::string> _ListIter;
393 std::list<std::string> _ListZone;
394 std::list<std::string> _ListComp;
395 std::list<std::string> _ListGroupSelected;
396 std::list<std::string> _ListFieldInterp;
399 class HOMARDIMPL_EXPORT HOMARD_Iteration
406 void SetName( const char* Name );
407 std::string GetName() const;
410 void SetDirNameLoc( const char* NomDir );
411 std::string GetDirNameLoc() const;
413 void SetNumber( int NumIter );
414 int GetNumber() const;
416 void SetState( int etat );
417 int GetState() const;
419 void SetMeshName( const char* NomMesh );
420 std::string GetMeshName() const;
422 void SetMeshFile( const char* MeshFile );
423 std::string GetMeshFile() const;
425 void SetFieldFile( const char* FieldFile );
426 std::string GetFieldFile() const;
427 // Instants pour le champ de pilotage
428 void SetTimeStep( int TimeStep );
429 void SetTimeStepRank( int TimeStep, int Rank );
430 void SetTimeStepRankLast();
431 int GetTimeStep() const;
433 // Instants pour un champ a interpoler
434 void SetFieldInterpTimeStep( const char* FieldInterp, int TimeStep );
435 void SetFieldInterpTimeStepRank( const char* FieldInterp, int TimeStep, int Rank );
436 const std::list<std::string>& GetFieldInterpsTimeStepRank() const;
437 void SetFieldInterp( const char* FieldInterp );
438 const std::list<std::string>& GetFieldInterps() const;
439 void SupprFieldInterps();
441 void SetLogFile( const char* LogFile );
442 std::string GetLogFile() const;
444 void SetFileInfo( const char* FileInfo );
445 std::string GetFileInfo() const;
447 // Liens avec les autres iterations
448 void LinkNextIteration( const char* NomIteration );
449 void UnLinkNextIteration( const char* NomIteration );
450 void UnLinkNextIterations();
451 const std::list<std::string>& GetIterations() const;
453 void SetIterParentName( const char* iterParent );
454 std::string GetIterParentName() const;
456 // Liens avec les autres structures
457 void SetCaseName( const char* NomCas );
458 std::string GetCaseName() const;
460 void SetHypoName( const char* NomHypo );
461 std::string GetHypoName() const;
464 void SetInfoCompute( int MessInfo );
465 int GetInfoCompute() const;
471 std::string _NomMesh;
472 std::string _MeshFile;
473 std::string _FieldFile;
476 std::string _LogFile;
477 std::string _IterParent;
478 std::string _NomHypo;
481 std::list<std::string> _mesIterFilles;
482 std::string _FileInfo;
484 // La liste des champs retenus par l'hypothese
485 std::list<std::string> _ListFieldInterp;
486 // La liste des triplets (champs, pas de temps, numero d'ordre) retenus par l'iteration
487 std::list<std::string> _ListFieldInterpTSR;
497 * \brief Relocate nodes to lie on geometry
498 * \param [in] theInputMedFile - a MED file holding a mesh including nodes that will be
499 * moved onto the geometry
500 * \param [in] theOutputMedFile - a MED file to create, that will hold a modified mesh
501 * \param [in] theInputNodeFiles - an array of names of files describing groups of nodes that
502 * will be moved onto the geometry
503 * \param [in] theXaoFileName - a path to a file in XAO format holding the geometry and
504 * the geometrical groups.
505 * \param [in] theIsParallel - if \c true, all processors are used to treat boundary shapes
508 void track( const std::string& theInputMedFile,
509 const std::string& theOutputMedFile,
510 const std::vector< std::string > & theInputNodeFiles,
511 const std::string& theXaoFileName,
512 bool theIsParallel=true);
517 struct FT_RealProjector;
520 * \brief Projector of a point to a boundary shape. Wrapper of a real projection algo
526 FT_Projector(const TopoDS_Shape& shape = TopoDS_Shape());
527 FT_Projector(const FT_Projector& other);
530 // initialize with a boundary shape, compute the bounding box
531 void setBoundaryShape(const TopoDS_Shape& shape);
533 // return the boundary shape
534 const TopoDS_Shape& getShape() const { return _shape; }
536 // return the bounding box
537 const Bnd_Box getBoundingBox() const { return _bndBox; }
540 // create a real projector
541 void prepareForProjection();
543 // return true if a previously found solution can be used to speed up the projection
544 bool canUsePrevSolution() const;
546 // return true if projection is not needed
547 bool isPlanarBoundary() const;
550 // switch a mode of usage of prevSolution.
551 // If projection fails, to try to project without usage of prevSolution.
552 // By default this mode is off
553 void tryWithoutPrevSolution( bool toTry ) { _tryWOPrevSolution = toTry; }
555 // project a point to the boundary shape
556 bool project( const gp_Pnt& point,
557 const double maxDist2,
560 const double* prevSolution = 0);
562 // project a point to the boundary shape and check if the projection is within the shape boundary
563 bool projectAndClassify( const gp_Pnt& point,
564 const double maxDist2,
567 const double* prevSolution = 0);
569 // check if a point lies on the boundary shape
570 bool isOnShape( const gp_Pnt& point,
573 const double* prevSolution = 0);
577 FT_RealProjector* _realProjector;
580 bool _tryWOPrevSolution;
585 // Check if a file exists
586 bool fileExists( const std::string& path );
588 // Check if a file can be created/overwritten
589 bool canWrite( const std::string& path );
591 // Transform anything printable to a string
592 template< typename T> std::string toStr( const T& t )
594 std::ostringstream s;
599 //--------------------------------------------------------------------------------------------
601 * \brief Return projectors by group name
605 XaoGroups( const XAO::Xao* xao );
607 int getProjectors( const std::string& groupName,
609 const std::vector< FT_Projector > & allProjectors,
610 std::vector< const FT_Projector* > & groupProjectors ) const;
613 typedef std::multimap< std::string, XAO::Group* > TGroupByNameMap;
614 TGroupByNameMap _xaoGroups[ 2 ]; // by dim
616 } // namespace FT_Utils
619 * \brief Node group and geometry to project onto
625 // read node IDs form a file and try to find a boundary sub-shape by name
626 void read( const std::string& nodesFile,
627 const FT_Utils::XaoGroups& xaoGroups,
628 MEDCoupling::DataArrayDouble* nodeCoords,
629 std::vector< FT_Projector > * allProjectorsByDim);
631 // chose boundary shapes by evaluating distance between nodes and shapes
632 //void choseShape( const std::vector< FT_Utils::ShapeAndBndBox >& shapeAndBoxList );
634 // project nodes to the shapes and move them to new positions
635 void projectAndMove();
637 // return true if all nodes were successfully relocated
638 bool isOK() const { return _OK; }
640 // return dimension of boundary shapes
641 int getShapeDim() const { return _shapeDim; }
643 // return nb of nodes to move
644 int nbNodes() const { return _nodes.size(); }
649 // put nodes in the order for optimal projection
650 void putNodesInOrder();
652 // get node coordinates
653 gp_Pnt getPoint( const int nodeID );
655 // change node coordinates
656 void moveNode( const int nodeID, const gp_Pnt& xyz );
659 // Ids of a node to move and its 2 or 4 neighbors
663 std::vector< int > _neighborNodes;
665 double _params[2]; // parameters on shape (U or UV) found by projection
666 double *_nearParams; // _params of a neighbor already projected node
668 FT_NodeToMove(): _nearParams(0) {}
671 std::vector< std::string > _groupNames;
672 int _shapeDim; // dimension of boundary shapes
673 std::vector< FT_NodeToMove > _nodes; // ids of nodes to move and their neighbors
674 std::vector< FT_Projector > _projectors; // FT_Projector's initialized with boundary shapes
675 std::vector< FT_Projector > * _allProjectors; // FT_Projector's for all shapes of _shapeDim
676 MEDCoupling::DataArrayDouble* _nodeCoords;
677 bool _OK; // projecting is successful
679 // map of { FT_NodeToMove::_neighborNodes[i] } to { FT_NodeToMove* }
680 // this map is used to find neighbor nodes
681 typedef NCollection_DataMap< int, std::vector< FT_NodeToMove* > > TNodeIDToLinksMap;
682 TNodeIDToLinksMap _neigborsMap;
683 std::vector<int> _nodesOrder;
688 * \brief Container of node groups.
694 // Load node groups from files
695 void read( const std::vector< std::string >& nodeFiles,
696 const XAO::Xao* xaoGeom,
697 MEDCoupling::DataArrayDouble* nodeCoords );
699 // return number of groups of nodes to move
700 int nbOfGroups() const { return _nodesOnGeom.size(); }
702 // Move nodes of a group in parallel mode
703 void operator() ( const int groupIndex ) const
705 const_cast< FT_NodeGroups* >( this )->projectAndMove( groupIndex );
708 // Project and move nodes of a given group of nodes
709 void projectAndMove( const int groupIndex );
711 // return true if all nodes were successfully relocated
714 // print some statistics on node groups
715 void dumpStat() const;
719 std::vector< FT_NodesOnGeom > _nodesOnGeom;
720 std::vector< FT_Projector > _projectors[2]; // curves and surfaces separately
724 }; // namespace SMESHHOMARDImpl