t8  UNKNOWN
t8code is a C library to manage a forest of adaptive space-trees of general element classes in parallel.
t8_geometry_lagrange.hxx
Go to the documentation of this file.
1 /*
2  This file is part of t8code.
3  t8code is a C library to manage a collection (a forest) of multiple
4  connected adaptive space-trees of general element classes in parallel.
5 
6  Copyright (C) 2024 the developers
7 
8  t8code is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  t8code is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with t8code; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
29 #ifndef T8_GEOMETRY_LAGRANGE_HXX
30 #define T8_GEOMETRY_LAGRANGE_HXX
31 
32 #include <array>
33 #include <string>
34 #include <vector>
35 
36 #include <t8.h>
41 
42 #define T8_GEOMETRY_MAX_POLYNOMIAL_DEGREE 2
43 
77 {
78  public:
87  t8_geometry_lagrange (int dim);
88 
89  /* Base constructor with no arguments. We need this since it
90  * is called from derived class constructors.
91  * Sets dimension and name to invalid values. */
93  {
94  }
95 
96  virtual ~t8_geometry_lagrange ();
97 
102  inline t8_geometry_type_t
104  {
106  };
107 
129  void
130  t8_geom_evaluate (t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_points,
131  double *out_coords) const;
132 
142  virtual void
143  t8_geom_evaluate_jacobian (t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_points,
144  double *jacobian) const;
145 
153  virtual void
155 
156  private:
161  inline std::vector<double>
162  t8_geom_compute_basis (const double *ref_point) const;
163 
173  inline std::vector<double>
174  t8_geom_s2_basis (const double *ref_point) const;
175 
185  inline std::vector<double>
186  t8_geom_s3_basis (const double *ref_point) const;
187 
204  inline std::vector<double>
205  t8_geom_t3_basis (const double *ref_point) const;
206 
223  inline std::vector<double>
224  t8_geom_t6_basis (const double *ref_point) const;
225 
242  inline std::vector<double>
243  t8_geom_q4_basis (const double *ref_point) const;
244 
261  inline std::vector<double>
262  t8_geom_q9_basis (const double *ref_point) const;
263 
284  inline std::vector<double>
285  t8_geom_h8_basis (const double *ref_point) const;
286 
307  inline std::vector<double>
308  t8_geom_h27_basis (const double *ref_point) const;
309 
311  const int *degree;
312 };
313 
321 template <typename T>
322 std::vector<T>
323 flatten (const std::vector<std::vector<T>> &vec)
324 {
325  std::vector<T> flattened;
326  for (auto const &v : vec) {
327  flattened.insert (flattened.end (), v.begin (), v.end ());
328  }
329  return flattened;
330 }
331 
342  public:
351  t8_lagrange_element (t8_eclass_t eclass, uint32_t degree, std::vector<double> &nodes);
352 
360  {
361  t8_cmesh_destroy (&cmesh);
362  };
363 
370  get_type () const;
371 
378  std::vector<t8_eclass_t>
379  face_classes () const;
380 
387  std::vector<double>
388  get_node_coords (uint32_t node) const;
389 
396  std::vector<std::vector<double>>
397  get_node_coords (std::vector<uint32_t> &nodes) const;
398 
404  std::vector<std::vector<uint32_t>>
405  get_face_nodes () const;
406 
416  std::vector<t8_lagrange_element>
417  decompose () const;
418 
427  std::array<double, T8_ECLASS_MAX_DIM>
428  evaluate (const std::array<double, T8_ECLASS_MAX_DIM> &ref_point) const;
429 
436  std::vector<std::array<double, T8_ECLASS_MAX_DIM>>
437  sample (uint32_t n_point) const;
438 
475  std::array<double, T8_ECLASS_MAX_DIM>
476  map_on_face (t8_eclass eclass, const int face_id, const std::array<double, T8_ECLASS_MAX_DIM> &coord) const;
477 
485  void
486  write () const;
487 
488  private:
490  t8_eclass_t eclass;
492  const uint32_t degree;
494  const std::vector<double> nodes;
496  t8_cmesh_t cmesh;
498  static constexpr uint32_t lagrange_nodes[T8_ECLASS_COUNT][2] = { { 1, 1 }, { 2, 3 }, { 4, 9 }, { 3, 6 }, { 8, 27 } };
499 
501  create_uniform_forest (t8_cmesh_t cmesh, uint32_t level) const;
502 };
503 
504 #endif /* !T8_GEOMETRY_LAGRANGE_HXX */
A single coarse mesh cell with Lagrange geometry.
Definition: t8_geometry_lagrange.hxx:341
std::vector< std::vector< uint32_t > > get_face_nodes() const
Node labels on the faces of the element.
Definition: t8_geometry_lagrange.cxx:291
std::vector< t8_eclass_t > face_classes() const
Element classes of the faces of this element.
Definition: t8_geometry_lagrange.cxx:341
void write() const
Save the geometry into a VTK file.
Definition: t8_geometry_lagrange.cxx:488
~t8_lagrange_element()
Destroy the t8_lagrange_element object.
Definition: t8_geometry_lagrange.hxx:359
std::vector< std::array< double, T8_ECLASS_MAX_DIM > > sample(uint32_t n_point) const
Sample random points in the reference domain.
std::vector< t8_lagrange_element > decompose() const
Decompose the element into its faces.
Definition: t8_geometry_lagrange.cxx:393
t8_eclass_t get_type() const
Get the type of the element.
Definition: t8_geometry_lagrange.cxx:285
std::vector< double > get_node_coords(uint32_t node) const
Coordinates of the specified node.
Definition: t8_geometry_lagrange.cxx:373
t8_lagrange_element(t8_eclass_t eclass, uint32_t degree, std::vector< double > &nodes)
Construct a new t8_lagrange_element object.
Definition: t8_geometry_lagrange.cxx:266
std::array< double, T8_ECLASS_MAX_DIM > map_on_face(t8_eclass eclass, const int face_id, const std::array< double, T8_ECLASS_MAX_DIM > &coord) const
Map this element on the face of a higher-dimensional element.
Definition: t8_geometry_lagrange.cxx:418
std::array< double, T8_ECLASS_MAX_DIM > evaluate(const std::array< double, T8_ECLASS_MAX_DIM > &ref_point) const
Physical coordinates of a point given in the reference domain.
Definition: t8_geometry_lagrange.cxx:410
This structure holds the connectivity data of the coarse mesh.
Definition: t8_cmesh_types.h:88
This structure is private to the implementation.
Definition: t8_forest_types.h:69
Mapping with Lagrange basis functions.
Definition: t8_geometry_lagrange.hxx:77
virtual void t8_geom_evaluate_jacobian(t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_points, double *jacobian) const
Compute the Jacobian of the t8_geom_evaluate map at a point in the reference space.
Definition: t8_geometry_lagrange.cxx:64
virtual void t8_geom_load_tree_data(t8_cmesh_t cmesh, t8_gloidx_t gtreeid)
Update a possible internal data buffer for per tree data.
Definition: t8_geometry_lagrange.cxx:71
void t8_geom_evaluate(t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_points, double *out_coords) const
Maps points from the reference space to the physical space .
Definition: t8_geometry_lagrange.cxx:45
t8_geometry_type_t t8_geom_get_type() const
Get the type of this geometry.
Definition: t8_geometry_lagrange.hxx:103
Definition: t8_geometry_with_vertices.hxx:40
This is the administrative header file for t8code.
int64_t t8_gloidx_t
A type for global indexing that holds really big numbers.
Definition: t8.h:100
void t8_cmesh_destroy(t8_cmesh_t *pcmesh)
Verify that a coarse mesh has only one reference left and destroy it.
Definition: t8_cmesh.cxx:1241
We define here the datatypes needed for internal cmesh routines.
enum t8_eclass t8_eclass_t
This enumeration contains all possible element classes.
t8_eclass
This enumeration contains all possible element classes.
Definition: t8_eclass.h:39
@ T8_ECLASS_COUNT
This is no element class but can be used as the number of element classes.
Definition: t8_eclass.h:58
We define the forest of trees in this file.
@ T8_GEOMETRY_TYPE_LAGRANGE
The Lagrange geometry uses a mapping with Lagrange polynomials to approximate curved elements .
Definition: t8_geometry.h:43
enum t8_geometry_type t8_geometry_type_t
This enumeration contains all possible geometries.
std::vector< T > flatten(const std::vector< std::vector< T >> &vec)
Flatten a vector of vector into a single vector.
Definition: t8_geometry_lagrange.hxx:323
This header file provides a C interface for functions for the t8_geometry_with_vertices class.
Implements the inherited struct t8_geometry_with_vertices, which can be used for geometries that use ...