Version: 9.16.0
SMESH_RegularGrid.hxx
Go to the documentation of this file.
1// Copyright (C) 2016-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19// File : SMESH_RegularGrid.hxx
20// Created : Sun March 24 09:58 2024
21// Author : Cesar Conopoima (cce)
22
23
24#ifndef __SMESH_RegularGrid_HXX__
25#define __SMESH_RegularGrid_HXX__
26
27//OCC
28#include <Precision.hxx>
29#include <NCollection_Array1.hxx>
30#include <gp_Pnt.hxx>
31#include <TopExp.hxx>
32#include <TopExp_Explorer.hxx>
33#include <TopTools_DataMapOfShapeReal.hxx>
34#include <TopTools_ListIteratorOfListOfShape.hxx>
35#include <TopTools_MapOfShape.hxx>
36#include <TopoDS.hxx>
37
38//STD
39#include <functional>
40#include <memory>
41#include <vector>
42#include <map>
43
44#include "SMESH_Utils.hxx"
45#include "SMDS_MeshNode.hxx"
46
49class Adaptor3d_Curve;
50class gp_Pnt;
51class gp_XYZ;
52
53template <typename T>
54std::vector<T> operator+(std::vector<T> const &x, std::vector<T> const &y)
55{
56 std::vector<T> vec;
57 vec.reserve(x.size() + y.size());
58 vec.insert(vec.end(), x.begin(), x.end());
59 vec.insert(vec.end(), y.begin(), y.end());
60 return vec;
61}
62
63namespace SMESHUtils
64{
73 {
74 public:
75
76 SMESH_RegularGrid( const int id, const int nx, const int ny, const int nz = 1 );
77 void SetNode( const std::shared_ptr<gp_Pnt>& point, const int iIndex, const int jIndex, const int zIndex = 0 );
78 void SetNode( const SMDS_MeshNode* point, const int iIndex, const int jIndex, const int zIndex = 0 );
79 void SetNode( const SMDS_MeshNode* point, const int index );
80 const std::shared_ptr<gp_Pnt> GetNode( const int index ) const { return myCoordinates[index]; };
81 const std::shared_ptr<gp_Pnt> GetNode( const int iIndex, const int jIndex, const int zIndex );
82 int nx() const { return mnx; };
83 int ny() const { return mny; };
84 int nz() const { return mnz; };
85 int Size() { return mns;};
86 NCollection_Array1<std::shared_ptr<gp_Pnt>>::Iterator CoordinateBegin() { return NCollection_Array1<std::shared_ptr<gp_Pnt>>::Iterator( myCoordinates ); };
87 int id() const { return myId; };
88
89 /*
90 *
91 * o------TOP (j=ny-1)----o
92 * | |
93 * | |
94 * | |
95 * LEFT (i=0) RIGHT(i=nx-1)
96 * | |
97 * | |
98 * | |
99 * o------BOTTOM(j=0)-----o
100 */
102 {
107 NONE
108 };
109
111 {
119 V7
120 };
121 /* Define vertex numeration convention
122 *
123 * V7 V6
124 * +--------+--------+--------+
125 * / / / /|
126 * +--------+--------+--------+ |
127 * / / / /| |
128 * +--------+--------+--------+ | +
129 * / / / V5 /| |/|
130 * V4 +--------+--------+--------+ | + |
131 * | | | |/| |
132 * | | | + | +
133 * | | |/| |/|
134 * + | | + |
135 * | | | |/| |
136 * | +-------+----------+-| + | + V2
137 * | / V3 |/| |/
138 * + / | +
139 * | / | |/
140 * | / | +
141 * |/ |/
142 * +--------+--------+--------+
143 * V0 V1
144 *
145 * Canonical cartesian axis orientation
146 *
147 * ^ ^ j (or y)
148 * k (or z)| /
149 * | /
150 * |/
151 * +------> i (or x)
152 *
153 *
154 */
155
157 {
158 B_BOTTOM, /*k=0 move (i,j)*/
159 B_RIGHT, /*i=mnx move (j,k)*/
160 B_BACK, /*j=mny move (i,k)*/
161 B_LEFT, /*i=0 move (j,k) */
162 B_FRONT, /*j=0 move (i,k)*/
163 B_TOP, /*k=mnz move (i,j) */
164 B_NONE
165 };
166
167 /*
168 * +--------+--------+--------+
169 * / / / /|
170 * +--------+--------+--------+ |
171 * / / Top / /| |
172 * +--------+--------+--------+ | +
173 * / / / /| |/|
174 * +--------+--------+--------+ | + |
175 * | | | | |/| | <- Right
176 * | | | | + | +
177 * | | | |/| |/|
178 * +--------+--------+--------+ | + |
179 * Left -> | | Front | | |/| |
180 * | | | | + | +
181 * | | | |/| |/
182 * +--------+--------+--------+ | +
183 * | | | | |/
184 * | | | | +
185 * | | | |/
186 * +--------+--------+--------+
187 * ^
188 * |
189 * Bottom
190 *
191 * Canonical cartesian axis orientation
192 *
193 * ^ ^ j (or y)
194 * k (or z)| /
195 * | /
196 * |/
197 * +------> i (or x)
198 *
199 *
200 */
201
202 // \brief Given a grid and a potentially neighbor grid return the vector describing the interface used by the cgns mesh format
203 // \remark the interface vector has the follow information:
204 // id the target range the donor range the transformation
205 // {edgeId, ibegin,jbegin, iend,jend, transformation}
206 // \remark As interfaces are unique, the dual interface (interaction of the neighbor grid and the current one) is also defined
207 // \param the neighbor grid
208 // \return the interface vector filled
209 void GetEdgeInterfaces( SMESH_RegularGrid * grid, std::vector<int>& interface );
210
211 // \brief Given a grid and a potentially neighbor grid return the vector describing the interface used by the cgns mesh format
212 // \remark the interface vector has the follow information:
213 // id the target range the donor range the transformation
214 // {edgeId, ibegin,jbegin,kbegin, iend,jend,kend, transformation}
215 // \remark As interfaces are unique, the dual interface (interaction of the neighbor grid and the current one) is also defined
216 // \param the neighbor grid
217 // \return the interface vector filled
218 void GetFaceInterfaces( SMESH_RegularGrid * grid, std::vector<int>& interface );
219
220 // \brief Fill the allRanges vector with the boundaries of the grid
221 template<typename T>
222 void getAllEdgeIndexLimits( std::vector<std::vector<T>>& allRanges );
223
224 // \brief Fill the allRanges vector with the boundaries of the grid
225 template<typename T>
226 void getAllFaceIndexLimits( std::vector<std::vector<T>>& allRanges );
227
228 // \brief Get limits of the edge in the order (ibegin,jbegin,iend,jend)+1 because index in CGNS are not zero based
229 template<typename T>
230 std::vector<T> getEdgeIndexLimits( const EdgeType edge ) const;
231
232 // \brief Get limits of the edge in the order (iend,jend,ibegin,jbegin)+1 because index in CGNS are not zero based
233 std::vector<int> getEdgeIndexLimitsInverted( const EdgeType edge ) const;
234
235 // \brief Get limits of the face in the order (ibegin,jbegin,kbegin,iend,jend,kend)+1 because index in CGNS are not zero based
236 template<typename T>
237 std::vector<T> getFaceIndexLimits( SMESH_RegularGrid::FaceType face ) const;
238
239 // \brief Return the faceType to which the passed geometrical face belongs to
240 SMESH_RegularGrid::FaceType getFaceTypeByGeomFace( TopoDS_Shape shapeFace ) const;
241
242 // \brief Return the edgeType to which the passed geometrical edge belongs to
243 SMESH_RegularGrid::EdgeType getEdgeTypeByGeomEdge( TopoDS_Shape shapeEdge ) const;
244
246
247 protected:
248
249 // Utility functions
250
251 // \brief Given one of the edge types and a grid determine whether or not they are adjacent on that side
252 // \remark There are three types of interfaces.
253 // 1) end to end intersection, both sides are exactly the same
254 // 2) one of the sides is smaller than the other but the grid are conform so the intersection is given exactly node by node
255 // 3) the same for 2) but nodes are not coincident
256 // \param edge, the edge where we are checking for interface
257 // \param grid, a neighbor grid
258 // \return interface, the interface vector filled in case an interface was found
259 void GetCommontInterface( EdgeType edge, SMESH_RegularGrid * grid, std::vector<int>& interface );
260 void GetCommontInterface( FaceType face, SMESH_RegularGrid * grid, std::vector<int>& interface );
261
262 // \brief Accessor method to interfaces already computed by other grid
263 // \param edge, the edge where we are checking for interface
264 // \param grid, a neighbor grid
265 // \param interface, the interface vector filled in case an interface was found
266 bool GetPrecomputedInterface( EdgeType edge, const SMESH_RegularGrid * grid, std::vector<int>& interface );
267
268 // \brief Accessor method to interfaces already computed by other grid
269 // \param face, the face where we are checking for interface
270 // \param grid, a neighbor grid
271 // \param interface, the interface vector filled in case an interface was found
272 bool GetPrecomputedInterface( FaceType face, const SMESH_RegularGrid * grid, std::vector<int>& interface );
273
274 // \brief Set the interface found between two neighbor grids.
275 // \remark fill the inner map between edges and grids used to recover precomputed interfaces with GetPrecomputedInterface method
276 void setInterface( SMESH_RegularGrid::EdgeType edge, const int gridId, std::vector<int>& interface );
277
278 // \brief Set the interface found between two neighbor grids.
279 // \remark fill the inner map between edges and grids used to recover precomputed interfaces with GetPrecomputedInterface method
280 void setInterface( SMESH_RegularGrid::FaceType face, const int gridId, std::vector<int>& interface );
281
282 // \brief Get the coordinate indexes defining the limit of the edge
283 std::pair<int,int> getEdgeLimits( const SMESH_RegularGrid::EdgeType edge ) const;
284
285 // \brief Get the coordinate indexes defining the limit of the face
286 std::tuple<int,int,int,int> getFaceLimits( const SMESH_RegularGrid::FaceType face ) const;
287
288 // \brief Get limits of the edge in the order (ibegin,jbegin,iend,jend)+1 because index in CGNS are not zero based
289 std::vector<int> getEdgeIndexLimits( const int start, const int end ) const;
290 std::vector<int> getFaceIndexLimits( const int start, const int end ) const;
291
292 // \brief Compute the transformation vector following the rules of the cgns format
293 std::vector<int> computeTransformation( const SMESH_RegularGrid::EdgeType edge, SMESH_RegularGrid::EdgeType gridDonorEdge, std::vector<int>& interfaceRange, std::vector<int>& interfaceDonor ) const;
294
295 // \brief Compute the transformation vector following the rules of the cgns format
296 std::vector<int> computeTransformation( const SMESH_RegularGrid::FaceType face, SMESH_RegularGrid::FaceType gridDonorFace, std::vector<int>& interfaceRange, std::vector<int>& interfaceDonor ) const;
297
298 // \brief Number of nodes on the edge
299 int getEdgeSize(const EdgeType edge ) const;
300
301 // \brief Number of nodes on the face
302 int getFaceSize(const FaceType face ) const;
303
304 // \brief Coordinate index of the given vertex
305 int getFaceCoordinateIndex( const VertexType v ) const;
306
307 // \brief Given the index of a coordinate return his (i,j,k) location in the grid
308 // \param the index in the coordinates vector
309 // \return a tuple with the (i,j,k) coordinates of the point in the grid
310 std::tuple<int,int,int> GetIJK( const int index ) const;
311
312 // \brief Iterator function to execute the 'fSide' function for each edge side of the grid
313 // \remark utility function to be used as:
314 // grid->foreachGridSide( [&]( EdgeType edge )
315 // {
316 // // Inner logic to be execute for each side of the grid
317 // });
318 template<typename FUNCTION>
319 void foreachGridSide( const FUNCTION& fSide ) const;
320
321 // \brief Iterator function to execute the 'fSide' function for each face side of the grid
322 // \remark utility function to be used as:
323 // grid->foreachGridFace( [&]( FaceType face )
324 // {
325 // // Inner logic to be execute for each face side of the grid
326 // });
327 template<typename FUNCTION>
328 void foreachGridFace( const FUNCTION& fSide ) const;
329
330 // \brief Iterator function to execute the lambda function with argument for each grid point and index in the gridEdge
331 // \remark utility function to be used as:
332 // grid->foreachNodeOnSide( gridEdge, [&]( (const std::shared_ptr<gp_Pnt> , const int nodeIndex ) )
333 // {
334 // // Inner logic to be execute for each node and index of the passed grid edge side
335 // });
336 void foreachNodeOnSide( SMESH_RegularGrid::EdgeType edge, const std::function<void(const std::shared_ptr<gp_Pnt> point, const int index )>& function ) const;
337
338 // \brief Iterator function to execute the lambda function with argument for each grid point and index in the gridFace
339 // \remark utility function to be used as:
340 // grid->foreachNodeOnFace( gridFace, [&]( (const std::shared_ptr<gp_Pnt>, const int nodeIndex ) )
341 // {
342 // // Inner logic to be execute for each node and index of the passed grid face side
343 // });
344 void foreachNodeOnFace( SMESH_RegularGrid::FaceType face, const std::function<void(const std::shared_ptr<gp_Pnt> point, const int index )>& function ) const;
345
346 // \brief Get all the indices of nodes in an edge side
347 // \param edge, the edge of the grid
348 // \return the index of all the nodes in the edge
349 std::vector<int> nodesOfSide( SMESH_RegularGrid::EdgeType edge ) const;
350
351 // \brief Get all the indices of nodes in an face side
352 // \param face, the face of the grid
353 // \return the index of all the nodes in the face
354 std::vector<int> nodesOfFace( SMESH_RegularGrid::FaceType face ) const;
355
356 // This function transforms the index limits of a face based on the position of the left bottom corner.
357 // It ensures that the face limits are correctly oriented by swapping indices if necessary.
358 // Auxiliary for the GetCommontInterface function
359 void transformIndexLimits(FaceType face,
360 std::vector<int>& faceLimits,
361 const std::shared_ptr<gp_Pnt>& V0,
362 const std::shared_ptr<gp_Pnt>& V1,
363 const std::shared_ptr<gp_Pnt>& V2,
364 const std::shared_ptr<gp_Pnt>& V3);
365
366 private:
367 int myId;
368 int mnx,mny,mnz,mns;
369 NCollection_Array1<std::shared_ptr<gp_Pnt>> myCoordinates;
370
371 std::map<SMESH_RegularGrid::EdgeType,std::map<int,std::vector<int>>> myInterfaceMap;
372 std::map<SMESH_RegularGrid::FaceType,std::map<int,std::vector<int>>> myFaceInterafaceMap;
373 };
374}
375
376#endif
std::vector< T > operator+(std::vector< T > const &x, std::vector< T > const &y)
Definition: SMESH_RegularGrid.hxx:54
#define SMESHUtils_EXPORT
Definition: SMESH_Utils.hxx:37
IMAP::const_iterator end(const IMAP &m)
Definition: StdMeshers_Projection_2D.cxx:106
Definition: SMDS_MeshNode.hxx:36
Define a regular grid of nx,ny,nz dimension.
Definition: SMESH_RegularGrid.hxx:73
EdgeType
Definition: SMESH_RegularGrid.hxx:102
@ RIGHT
Definition: SMESH_RegularGrid.hxx:104
@ TOP
Definition: SMESH_RegularGrid.hxx:105
@ BOTTOM
Definition: SMESH_RegularGrid.hxx:103
@ LEFT
Definition: SMESH_RegularGrid.hxx:106
VertexType
Definition: SMESH_RegularGrid.hxx:111
@ V3
Definition: SMESH_RegularGrid.hxx:115
@ V1
Definition: SMESH_RegularGrid.hxx:113
@ V5
Definition: SMESH_RegularGrid.hxx:117
@ V4
Definition: SMESH_RegularGrid.hxx:116
@ V0
Definition: SMESH_RegularGrid.hxx:112
@ V2
Definition: SMESH_RegularGrid.hxx:114
@ V6
Definition: SMESH_RegularGrid.hxx:118
NCollection_Array1< std::shared_ptr< gp_Pnt > >::Iterator CoordinateBegin()
Definition: SMESH_RegularGrid.hxx:86
int myId
Definition: SMESH_RegularGrid.hxx:367
int ny() const
Definition: SMESH_RegularGrid.hxx:83
int nz() const
Definition: SMESH_RegularGrid.hxx:84
std::map< SMESH_RegularGrid::EdgeType, std::map< int, std::vector< int > > > myInterfaceMap
Definition: SMESH_RegularGrid.hxx:371
int nx() const
Definition: SMESH_RegularGrid.hxx:82
int mns
Definition: SMESH_RegularGrid.hxx:368
int id() const
Definition: SMESH_RegularGrid.hxx:87
int Size()
Definition: SMESH_RegularGrid.hxx:85
std::map< SMESH_RegularGrid::FaceType, std::map< int, std::vector< int > > > myFaceInterafaceMap
Definition: SMESH_RegularGrid.hxx:372
FaceType
Definition: SMESH_RegularGrid.hxx:157
@ B_BACK
Definition: SMESH_RegularGrid.hxx:160
@ B_LEFT
Definition: SMESH_RegularGrid.hxx:161
@ B_BOTTOM
Definition: SMESH_RegularGrid.hxx:158
@ B_RIGHT
Definition: SMESH_RegularGrid.hxx:159
@ B_TOP
Definition: SMESH_RegularGrid.hxx:163
@ B_FRONT
Definition: SMESH_RegularGrid.hxx:162
NCollection_Array1< std::shared_ptr< gp_Pnt > > myCoordinates
Definition: SMESH_RegularGrid.hxx:369
const std::shared_ptr< gp_Pnt > GetNode(const int index) const
Definition: SMESH_RegularGrid.hxx:80
Definition: SMESH_BoostTxtArchive.hxx:35