@@ -42,7 +42,7 @@ namespace modmesh
4242/* *
4343 * Base class template for structured grid.
4444 */
45- template <size_t ND>
45+ template <uint8_t ND>
4646class StaticGridBase
4747 : public SpaceBase<ND>
4848{
@@ -180,217 +180,6 @@ class StaticGrid3d
180180{
181181}; /* end class StaticGrid3d */
182182
183- struct CellTypeBase
184- {
185- /* symbols for type id codes */
186- static constexpr const uint8_t NONCELLTYPE = 0 ; /* not a cell type */
187- static constexpr const uint8_t POINT = 1 ;
188- static constexpr const uint8_t LINE = 2 ;
189- static constexpr const uint8_t QUADRILATERAL = 3 ;
190- static constexpr const uint8_t TRIANGLE = 4 ;
191- static constexpr const uint8_t HEXAHEDRON = 5 ;
192- static constexpr const uint8_t TETRAHEDRON = 6 ;
193- static constexpr const uint8_t PRISM = 7 ;
194- static constexpr const uint8_t PYRAMID = 8 ;
195- /* number of all types; one larger than the last type id code */
196- static constexpr const uint8_t NTYPE = 8 ;
197-
198- // < Maximum number of nodes in a face.
199- static constexpr const uint8_t FCNND_MAX = 4 ;
200- // < Maximum number of cells in a face.
201- static constexpr const uint8_t FCNCL_MAX = 2 ;
202- // < Maximum number of nodes in a cell.
203- static constexpr const uint8_t CLNND_MAX = 8 ;
204- // < Maximum number of faces in a cell.
205- static constexpr const uint8_t CLNFC_MAX = 6 ;
206- }; /* end struct CellTypeBase */
207-
208- /* *
209- * Cell type for unstructured mesh.
210- */
211- template < uint8_t ND > struct CellType
212- : public CellTypeBase
213- , public SpaceBase<ND>
214- {
215-
216- static constexpr const uint8_t NDIM = SpaceBase<ND>::NDIM;
217-
218- /* NOLINTNEXTLINE(bugprone-easily-swappable-parameters) */
219- CellType (uint8_t id_in, uint8_t nnode_in, uint8_t nedge_in, uint8_t nsurface_in)
220- : m_id(id_in), m_nnode(nnode_in), m_nedge(nedge_in), m_nsurface(nsurface_in) {}
221-
222- uint8_t id () const { return m_id; }
223- uint8_t ndim () const { return NDIM; }
224- uint8_t nnode () const { return m_nnode; }
225- uint8_t nedge () const { return m_nedge; }
226- uint8_t nsurface () const { return m_nsurface; }
227-
228- uint8_t nface () const
229- {
230- if constexpr (2 == NDIM) { return nedge () ; }
231- else if constexpr (3 == NDIM) { return nsurface (); }
232- else { return 0 ; }
233- }
234-
235- const char * name () const
236- {
237- switch (id ()) {
238- case POINT /* 1 */ : return " point" ; break ;
239- case LINE /* 2 */ : return " line" ; break ;
240- case QUADRILATERAL /* 3 */ : return " quadrilateral" ; break ;
241- case TRIANGLE /* 4 */ : return " triangle" ; break ;
242- case HEXAHEDRON /* 5 */ : return " hexahedron" ; break ;
243- case TETRAHEDRON /* 6 */ : return " tetrahedron" ; break ;
244- case PRISM /* 7 */ : return " prism" ; break ;
245- case PYRAMID /* 8 */ : return " pyramid" ; break ;
246- case NONCELLTYPE /* 0 */ :
247- default /* other */ : return " noncelltype" ; break ;
248- }
249- }
250-
251- private:
252-
253- uint8_t m_id = NONCELLTYPE;
254- uint8_t m_nnode = 0 ;
255- uint8_t m_nedge = 0 ;
256- uint8_t m_nsurface = 0 ;
257-
258- }; /* end struct CellType */
259-
260- #define MM_DECL_CELL_TYPE (NAME, TYPE, NDIM, NNODE, NEDGE, NSURFACE ) \
261- struct NAME ##CellType : public CellType<NDIM> { \
262- NAME##CellType() : CellType<NDIM>(TYPE, NNODE, NEDGE, NSURFACE) {} \
263- }; \
264- static_assert (sizeof (NAME##CellType) == 4 );
265- // id, ndim, nnode, nedge, nsurface
266- MM_DECL_CELL_TYPE (Point , 1 , 0 , 1 , 0 , 0 ) // point/node/vertex
267- MM_DECL_CELL_TYPE (Line , 2 , 1 , 2 , 0 , 0 ) // line/edge
268- MM_DECL_CELL_TYPE (Quadrilateral, 3 , 2 , 4 , 4 , 0 )
269- MM_DECL_CELL_TYPE (Triangle , 4 , 2 , 3 , 3 , 0 )
270- MM_DECL_CELL_TYPE (Hexahedron , 5 , 3 , 8 , 12 , 6 ) // hexahedron/brick
271- MM_DECL_CELL_TYPE (Tetrahedron , 6 , 3 , 4 , 6 , 4 )
272- MM_DECL_CELL_TYPE (Prism , 7 , 3 , 6 , 9 , 5 )
273- MM_DECL_CELL_TYPE (Pyramid , 8 , 3 , 5 , 8 , 5 )
274- #undef MH_DECL_CELL_TYPE
275-
276- template < typename D /* derived type */ , uint8_t ND >
277- class StaticMeshBase
278- : public SpaceBase<ND>
279- , public std::enable_shared_from_this<D>
280- {
281-
282- private:
283-
284- class ctor_passkey {};
285-
286- public:
287-
288- using space_base = SpaceBase<ND>;
289- using int_type = typename space_base::int_type;
290- using uint_type = typename space_base::uint_type;
291- using real_type = typename space_base::real_type;
292-
293- static constexpr const auto NDIM = space_base::NDIM;
294- static constexpr const uint8_t FCMND = CellTypeBase::FCNND_MAX;
295- static constexpr const uint8_t FCMCL = CellTypeBase::FCNCL_MAX;
296- static constexpr const uint8_t CLMND = CellTypeBase::CLNND_MAX;
297- static constexpr const uint8_t CLMFC = CellTypeBase::CLNFC_MAX;
298- static constexpr const uint8_t FCNCL = 4 ;
299- static constexpr const uint8_t FCREL = 4 ;
300- static constexpr const uint8_t BFREL = 3 ;
301-
302- template < typename ... Args >
303- static std::shared_ptr<D> construct (Args && ... args)
304- {
305- return std::make_shared<D>(std::forward<Args>(args) ..., ctor_passkey ());
306- }
307-
308- StaticMeshBase (uint_type nnode, ctor_passkey const &)
309- : m_nnode(nnode), m_nface(0 ), m_ncell(0 )
310- , m_nbound(0 ), m_ngstnode(0 ), m_ngstface(0 ), m_ngstcell(0 )
311- , m_ndcrd(std::vector<size_t >{nnode, NDIM})
312- , m_fccnd(std::vector<size_t >{0 , NDIM})
313- , m_fcnml(std::vector<size_t >{0 , NDIM})
314- , m_fcara(std::vector<size_t >{0 })
315- , m_clcnd(std::vector<size_t >{0 , NDIM})
316- , m_clvol(std::vector<size_t >{0 })
317- , m_fctpn(std::vector<size_t >{0 })
318- , m_cltpn(std::vector<size_t >{0 })
319- , m_clgrp(std::vector<size_t >{0 })
320- , m_fcnds(std::vector<size_t >{0 , FCMND})
321- , m_fccls(std::vector<size_t >{0 , FCMCL})
322- , m_clnds(std::vector<size_t >{0 , CLMND})
323- , m_clfcs(std::vector<size_t >{0 , CLMFC})
324- {}
325- StaticMeshBase () = delete ;
326- StaticMeshBase (StaticMeshBase const & ) = delete ;
327- StaticMeshBase (StaticMeshBase &&) = delete ;
328- StaticMeshBase & operator =(StaticMeshBase const & ) = delete ;
329- StaticMeshBase & operator =(StaticMeshBase &&) = delete ;
330- ~StaticMeshBase () = default ;
331-
332- uint_type nnode () const { return m_nnode; }
333- uint_type nface () const { return m_nface; }
334- uint_type ncell () const { return m_ncell; }
335- uint_type nbound () const { return m_nbound; }
336- uint_type ngstnode () const { return m_ngstnode; }
337- uint_type ngstface () const { return m_ngstface; }
338- uint_type ngstcell () const { return m_ngstcell; }
339-
340- // Shape data.
341- private:
342-
343- uint_type m_nnode = 0 ; // /< Number of nodes (interior).
344- uint_type m_nface = 0 ; // /< Number of faces (interior).
345- uint_type m_ncell = 0 ; // /< Number of cells (interior).
346- uint_type m_nbound = 0 ; // /< Number of boundary faces.
347- uint_type m_ngstnode = 0 ; // /< Number of ghost nodes.
348- uint_type m_ngstface = 0 ; // /< Number of ghost faces.
349- uint_type m_ngstcell = 0 ; // /< Number of ghost cells.
350- // other block information.
351- bool m_use_incenter = false ; // /< While true, m_clcnd uses in-center for simplices.
352-
353- // Data arrays.
354- #define MM_DECL_StaticMesh_ARRAY (TYPE, NAME ) \
355- public: \
356- SimpleArray<TYPE> const & NAME () const { return m_ ## NAME; } \
357- SimpleArray<TYPE> & NAME () { return m_ ## NAME; } \
358- private: \
359- SimpleArray<TYPE> m_ ## NAME
360-
361- // geometry arrays.
362- MM_DECL_StaticMesh_ARRAY (real_type, ndcrd);
363- MM_DECL_StaticMesh_ARRAY (real_type, fccnd);
364- MM_DECL_StaticMesh_ARRAY (real_type, fcnml);
365- MM_DECL_StaticMesh_ARRAY (real_type, fcara);
366- MM_DECL_StaticMesh_ARRAY (real_type, clcnd);
367- MM_DECL_StaticMesh_ARRAY (real_type, clvol);
368- // meta arrays.
369- MM_DECL_StaticMesh_ARRAY (int_type, fctpn);
370- MM_DECL_StaticMesh_ARRAY (int_type, cltpn);
371- MM_DECL_StaticMesh_ARRAY (int_type, clgrp);
372- // connectivity arrays.
373- MM_DECL_StaticMesh_ARRAY (int_type, fcnds);
374- MM_DECL_StaticMesh_ARRAY (int_type, fccls);
375- MM_DECL_StaticMesh_ARRAY (int_type, clnds);
376- MM_DECL_StaticMesh_ARRAY (int_type, clfcs);
377-
378- #undef MM_DECL_StaticMesh_ARRAY
379-
380- }; /* end class StaticMeshBase */
381-
382- class StaticMesh2d
383- : public StaticMeshBase<StaticMesh2d, 2 >
384- {
385- using StaticMeshBase::StaticMeshBase;
386- }; /* end class StaticGrid2d */
387-
388- class StaticMesh3d
389- : public StaticMeshBase<StaticMesh3d, 3 >
390- {
391- using StaticMeshBase::StaticMeshBase;
392- }; /* end class StaticGrid3d */
393-
394183} /* end namespace modmesh */
395184
396185// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
0 commit comments