Salome HOME
Merge branch 'gn/evol_01'
[modules/homard.git] / src / FrontTrack / FrontTrack_NodeGroups.cxx
1 // File      : FrontTrack_NodeGroups.cxx
2 // Created   : Tue Apr 25 19:17:47 2017
3 // Author    : Edward AGAPOV (eap)
4
5 #include "FrontTrack_NodeGroups.hxx"
6 #include "FrontTrack_Projector.hxx"
7 #include "FrontTrack_Utils.hxx"
8
9 #include <MEDCouplingMemArray.hxx>
10 #include <XAO_BrepGeometry.hxx>
11 #include <XAO_Xao.hxx>
12
13 #include <BRepBndLib.hxx>
14 #include <Bnd_Box.hxx>
15 #include <TopExp.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopTools_IndexedMapOfShape.hxx>
18 #include <TopoDS_Shape.hxx>
19
20 namespace
21 {
22   //================================================================================
23   /*!
24    * \brief Initialize FT_Projector's with all sub-shapes of given type
25    *  \param [in] theMainShape - the shape to explore
26    *  \param [in] theSubType - the type of sub-shapes
27    *  \param [out] theProjectors - the projectors
28    */
29   //================================================================================
30
31   void getProjectors( const TopoDS_Shape&           theMainShape,
32                       const TopAbs_ShapeEnum        theSubType,
33                       std::vector< FT_Projector > & theProjectors )
34   {
35     TopTools_IndexedMapOfShape subShapes;
36     TopExp::MapShapes( theMainShape, theSubType, subShapes );
37
38     theProjectors.resize( subShapes.Size() );
39     for ( int i = 1; i <= subShapes.Size(); ++i )
40       theProjectors[ i-1 ].setBoundaryShape( subShapes( i ));
41   }
42 }
43
44 //================================================================================
45 /*!
46  * \brief Load node groups from files
47  *  \param [in] theNodeFiles - an array of names of files describing groups of nodes that
48  *         will be moved onto geometry
49  *  \param [in] theXaoGeom - the whole geometry to project on
50  *  \param [inout] theNodeCoords - array of node coordinates
51  */
52 //================================================================================
53
54 void FT_NodeGroups::read( const std::vector< std::string >& theNodeFiles,
55                           const XAO::Xao*                   theXao,
56                           MEDCoupling::DataArrayDouble*     theNodeCoords )
57 {
58   // get projectors for all boundary sub-shapes;
59   // index of a projector in the vector corresponds to a XAO index of a sub-shape
60   XAO::BrepGeometry* xaoGeom = dynamic_cast<XAO::BrepGeometry*>( theXao->getGeometry() );
61   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_EDGE, _projectors[0] );
62   getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_FACE, _projectors[1] );
63
64   _nodesOnGeom.resize( theNodeFiles.size() );
65
66   // read node IDs and look for projectors to boundary sub-shapes by group name
67   FT_Utils::XaoGroups xaoGroups( theXao );
68   for ( size_t i = 0; i < theNodeFiles.size(); ++i )
69   {
70     _nodesOnGeom[i].read( theNodeFiles[i], xaoGroups, theNodeCoords, _projectors );
71   }
72 }
73
74 //================================================================================
75 /*!
76  * \brief Project and move nodes of a given group of nodes
77  */
78 //================================================================================
79
80 void FT_NodeGroups::projectAndMove( const int groupIndex )
81 {
82   _nodesOnGeom[ groupIndex ].projectAndMove();
83 }
84
85 //================================================================================
86 /*!
87  * \brief Return true if all nodes were successfully relocated
88  */
89 //================================================================================
90
91 bool FT_NodeGroups::isOK() const
92 {
93   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
94     if ( ! _nodesOnGeom[ i ].isOK() )
95       return false;
96
97   return true;
98 }
99
100 //================================================================================
101 /*!
102  * \brief Print some statistics on node groups
103  */
104 //================================================================================
105
106 void FT_NodeGroups::dumpStat() const
107 {
108   for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
109   {
110     std::cout << _nodesOnGeom[i].getShapeDim() << "D "
111               << _nodesOnGeom[i].nbNodes() << " nodes" << std::endl;
112   }
113 }