GetFEM  5.5
bgeot_torus.cc
1 /*===========================================================================
2 
3  Copyright (C) 2014-2026 Liang Jin Lim
4 
5  This file is a part of GetFEM
6 
7  GetFEM is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Lesser General Public License as published
9  by the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version along with the GCC Runtime Library
11  Exception either version 3.1 or (at your option) any later version.
12  This program is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  License and GCC Runtime Library Exception for more details.
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see https://www.gnu.org/licenses/.
18 
19 ===========================================================================*/
20 #include "getfem/bgeot_torus.h"
21 
22 namespace bgeot{
23 
24  /**torus_structure which extends a 2 dimensional structure with a radial dimension*/
26 
27  friend pconvex_structure torus_structure_descriptor(pconvex_structure);
28  };
29 
30  class torus_reference : public convex_of_reference{
31 
32  public :
33  scalar_type is_in(const base_node& point) const{
34  GMM_ASSERT1(point.size() >= 2, "Invalid dimension of pt " << point);
35  base_node point_2d = point;
36  point_2d.resize(2);
37  return ori_ref_convex_->is_in(point_2d);
38  }
39 
40  scalar_type is_in_face(bgeot::short_type f, const base_node& point) const{
41  GMM_ASSERT1(point.size() >= 2, "Invalid dimension of pt " << point);
42  base_node point2D = point;
43  point2D.resize(2);
44  return ori_ref_convex_->is_in_face(f, point2D);
45  }
46  torus_reference(bgeot::pconvex_ref ori_ref_convex) :
47  convex_of_reference(
48  torus_structure_descriptor(ori_ref_convex->structure()), ori_ref_convex->is_basic())
49  {
50  ori_ref_convex_ = ori_ref_convex;
51  convex<base_node>::points().resize(cvs->nb_points());
52  normals_.resize(ori_ref_convex->normals().size());
53 
54  const std::vector<base_small_vector> &ori_normals = ori_ref_convex->normals();
55  const stored_point_tab &ori_points = ori_ref_convex->points();
56  for(size_type n = 0; n < ori_normals.size(); ++n){
57  normals_[n] = ori_normals[n];
58  normals_[n].resize(3);
59  }
60 
61  std::copy(ori_points.begin(), ori_points.end(), convex<base_node>::points().begin());
62  for(size_type pt = 0; pt < convex<base_node>::points().size(); ++pt){
63  convex<base_node>::points()[pt].resize(3);
64  }
65  ppoints = store_point_tab(convex<base_node>::points());
66  }
67 
68  private:
69  bgeot::pconvex_ref ori_ref_convex_;
70  };
71 
72  DAL_SIMPLE_KEY(torus_structure_key, pconvex_structure);
73 
74  pconvex_structure torus_structure_descriptor(pconvex_structure ori_structure){
75 
76  dal::pstatic_stored_object_key
77  pk = std::make_shared<torus_structure_key>(ori_structure);
78  dal::pstatic_stored_object o = dal::search_stored_object(pk);
79  if (o) return std::dynamic_pointer_cast<const convex_structure>(o);
80 
81  auto p = std::make_shared<torus_structure>();
82  pconvex_structure pcvs(p);
83  p->Nc = dim_type(ori_structure->dim() + 1);
84  p->nbpt = ori_structure->nb_points();
85  p->nbf = ori_structure->nb_faces();
86 
87  p->faces_struct.resize(p->nbf);
88  p->faces.resize(p->nbf);
89 
90  for (short_type j = 0; j < p->nbf; ++j){
91  p->faces_struct[j] = ori_structure->faces_structure()[j];
92  short_type nbIndex = ori_structure->nb_points_of_face(j);
93  p->faces[j].resize(nbIndex);
94  p->faces[j] = ori_structure->ind_points_of_face(j);
95  }
96 
97  p->dir_points_.resize(ori_structure->ind_dir_points().size());
98  p->dir_points_ = ori_structure->ind_dir_points();
99 
100  p->basic_pcvs = basic_structure(ori_structure);
101 
102  dal::add_stored_object(pk, pcvs, dal::PERMANENT_STATIC_OBJECT);
103  return pcvs;
104  }
105 
106  DAL_SIMPLE_KEY(torus_reference_key, pconvex_ref);
107 
108  pconvex_ref ptorus_reference(pconvex_ref ori_convex_reference)
109  {
110  dal::pstatic_stored_object_key
111  pk = std::make_shared<torus_reference_key>(ori_convex_reference);
112  dal::pstatic_stored_object o = dal::search_stored_object(pk);
113 
114  if (o) return std::dynamic_pointer_cast<const bgeot::convex_of_reference>(o);
115  pconvex_ref p = std::make_shared<torus_reference>(ori_convex_reference);
116  dal::add_stored_object(pk, p, p->structure(), p->pspt(),
117  dal::PERMANENT_STATIC_OBJECT);
118  return p;
119  }
120 
121  void torus_geom_trans::poly_vector_val(const base_node &pt, bgeot::base_vector &val) const{
122  base_node pt_2d(pt);
123  pt_2d.resize(2);
124  poriginal_trans_->poly_vector_val(pt_2d, val);
125  }
126 
127  void torus_geom_trans::poly_vector_val(const base_node &pt, const bgeot::convex_ind_ct &ind_ct,
128  bgeot::base_vector &val) const{
129  base_node pt_2d(pt);
130  pt_2d.resize(2);
131  poriginal_trans_->poly_vector_val(pt_2d, ind_ct, val);
132  }
133 
134  void torus_geom_trans::poly_vector_grad(const base_node &pt, bgeot::base_matrix &pc) const{
135  base_node pt2D(pt);
136  pt2D.resize(2);
137  bgeot::base_matrix pc2D(nb_points(), 2);
138  poriginal_trans_->poly_vector_grad(pt2D, pc2D);
139 
140  bgeot::base_vector base_value;
141  poriginal_trans_->poly_vector_val(pt2D, base_value);
142 
143  pc.resize(nb_points(), 3);
144 
145  for (size_type i = 0; i < nb_points(); ++i){
146  for (bgeot::dim_type n = 0; n < 2; ++n) pc(i, n) = pc2D(i, n);
147  pc(i, 2) = base_value[i]; // radial direction, pc = base_x;
148  }
149  }
150 
152  const bgeot::convex_ind_ct &ind_ct, bgeot::base_matrix &pc) const{
153  base_node pt2D(pt);
154  pt2D.resize(2);
155  bgeot::base_matrix pc2D(ind_ct.size(), 2);
156  poriginal_trans_->poly_vector_grad(pt2D, pc2D);
157  pc.resize(ind_ct.size(), dim());
158  for (size_type i = 0; i < ind_ct.size(); ++i){
159  for (bgeot::dim_type n = 0; n < 2; ++n) pc(i, n) = pc2D(i, n);
160  }
161  }
162 
164  (const bgeot::base_matrix &G, const bgeot::base_matrix &pc, bgeot::base_matrix &K) const{
166  K(2, 2) = 0.0;
167  for (short_type j = 0; j < nb_points(); ++ j) K(2, 2) += G(0, j) * pc(j, 2);
168  for (short_type i = 0; i < 2; ++i) K(2, i) = K(i, 2) = 0;
169  }
170 
172  bgeot::base_matrix & /*pc*/) const{
173  GMM_ASSERT1(false, "Sorry, Hessian is not supported in axisymmetric transformation.");
174  }
175 
176  void torus_geom_trans::project_into_reference_convex(base_node &pt) const {
177  poriginal_trans_->project_into_reference_convex(pt);
178  }
179 
180  torus_geom_trans::torus_geom_trans(pgeometric_trans poriginal_trans)
181  : poriginal_trans_(poriginal_trans){
182  geometric_trans::is_lin = poriginal_trans_->is_linear();
183  geometric_trans::cvr = ptorus_reference(poriginal_trans_->convex_ref());
184  complexity_ = poriginal_trans_->complexity();
185  fill_standard_vertices();
186  name_ = poriginal_trans->debug_name();
187  }
188 
189  pgeometric_trans torus_geom_trans::get_original_transformation() const{
190  return poriginal_trans_;
191  }
192 
193  bool is_torus_structure(pconvex_structure cvs){
194  const torus_structure *cvs_torus = dynamic_cast<const torus_structure *>(cvs.get());
195  return cvs_torus != NULL;
196  }
197 
198  DAL_SIMPLE_KEY(torus_geom_trans_key, pgeometric_trans);
199 
200  pgeometric_trans torus_geom_trans_descriptor(pgeometric_trans poriginal_trans){
201  dal::pstatic_stored_object_key
202  pk = std::make_shared<torus_geom_trans_key>(poriginal_trans);
203  dal::pstatic_stored_object o = dal::search_stored_object(pk);
204 
205  if (o) return std::dynamic_pointer_cast<const torus_geom_trans>(o);
206 
207  bgeot::pgeometric_trans p = std::make_shared<torus_geom_trans>(poriginal_trans);
208  dal::add_stored_object(pk, p, dal::PERMANENT_STATIC_OBJECT);
209  return p;
210  }
211 
212  bool is_torus_geom_trans(pgeometric_trans pgt){
213  const torus_geom_trans *pgt_torus = dynamic_cast<const torus_geom_trans *>(pgt.get());
214  return pgt_torus != NULL;
215  }
216 
217 }
Provides mesh of torus.
Base class for reference convexes.
Structure of a convex.
dim_type dim() const
Dimension of the reference element.
size_type nb_points() const
Number of geometric nodes.
virtual void compute_K_matrix(const base_matrix &G, const base_matrix &pc, base_matrix &K) const
compute K matrix from multiplication of G with gradient
torus_structure which extends a 2 dimensional structure with a radial dimension
Definition: bgeot_torus.cc:25
Basic Geometric Tools.
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:72
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
pconvex_structure basic_structure(pconvex_structure cv)
Original structure (if concerned)
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies.
pstatic_stored_object search_stored_object(pstatic_stored_object_key k)
Gives a pointer to an object from a key pointer.
virtual void poly_vector_val(const base_node &, bgeot::base_vector &) const
Gives the value of the functions vector at a certain point.
Definition: bgeot_torus.cc:121
virtual void compute_K_matrix(const bgeot::base_matrix &, const bgeot::base_matrix &, bgeot::base_matrix &) const
compute K matrix from multiplication of G with gradient
Definition: bgeot_torus.cc:164
virtual void poly_vector_grad(const base_node &, bgeot::base_matrix &) const
Gives the gradient of the functions vector at a certain point.
Definition: bgeot_torus.cc:134
virtual void poly_vector_hess(const base_node &, bgeot::base_matrix &) const
Gives the hessian of the functions vector at a certain point.
Definition: bgeot_torus.cc:171