GetFEM++  5.3
bgeot_torus.cc
1 /*===========================================================================
2 
3  Copyright (C) 2014-2017 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, write to the Free Software Foundation,
18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 ===========================================================================*/
21 #include "getfem/bgeot_torus.h"
22 
23 namespace bgeot{
24 
25  /**torus_structure which extends a 2 dimensional structure with a radial dimension*/
27 
28  friend pconvex_structure torus_structure_descriptor(pconvex_structure);
29  };
30 
31  class torus_reference : public convex_of_reference{
32 
33  public :
34  scalar_type is_in(const base_node& point) const{
35  GMM_ASSERT1(point.size() >= 2, "Invalid dimension of pt " << point);
36  base_node point_2d = point;
37  point_2d.resize(2);
38  return ori_ref_convex_->is_in(point_2d);
39  }
40 
41  scalar_type is_in_face(bgeot::short_type f, const base_node& point) const{
42  GMM_ASSERT1(point.size() >= 2, "Invalid dimension of pt " << point);
43  base_node point2D = point;
44  point2D.resize(2);
45  return ori_ref_convex_->is_in_face(f, point2D);
46  }
47  torus_reference(bgeot::pconvex_ref ori_ref_convex) :
49  torus_structure_descriptor(ori_ref_convex->structure()), ori_ref_convex->is_basic())
50  {
51  ori_ref_convex_ = ori_ref_convex;
52  convex<base_node>::points().resize(cvs->nb_points());
53  normals_.resize(ori_ref_convex->normals().size());
54 
55  const std::vector<base_small_vector> &ori_normals = ori_ref_convex->normals();
56  const stored_point_tab &ori_points = ori_ref_convex->points();
57  for(size_type n = 0; n < ori_normals.size(); ++n){
58  normals_[n] = ori_normals[n];
59  normals_[n].resize(3);
60  }
61 
62  std::copy(ori_points.begin(), ori_points.end(), convex<base_node>::points().begin());
63  for(size_type pt = 0; pt < convex<base_node>::points().size(); ++pt){
64  convex<base_node>::points()[pt].resize(3);
65  }
66  ppoints = store_point_tab(convex<base_node>::points());
67  }
68 
69  private:
70  bgeot::pconvex_ref ori_ref_convex_;
71  };
72 
73  DAL_SIMPLE_KEY(torus_structure_key, pconvex_structure);
74 
75  pconvex_structure torus_structure_descriptor(pconvex_structure ori_structure){
76 
77  dal::pstatic_stored_object_key
78  pk = std::make_shared<torus_structure_key>(ori_structure);
79  dal::pstatic_stored_object o = dal::search_stored_object(pk);
80  if (o) return std::dynamic_pointer_cast<const convex_structure>(o);
81 
82  auto p = std::make_shared<torus_structure>();
83  pconvex_structure pcvs(p);
84  p->Nc = dim_type(ori_structure->dim() + 1);
85  p->nbpt = ori_structure->nb_points();
86  p->nbf = ori_structure->nb_faces();
87 
88  p->faces_struct.resize(p->nbf);
89  p->faces.resize(p->nbf);
90 
91  for (short_type j = 0; j < p->nbf; ++j){
92  p->faces_struct[j] = ori_structure->faces_structure()[j];
93  short_type nbIndex = ori_structure->nb_points_of_face(j);
94  p->faces[j].resize(nbIndex);
95  p->faces[j] = ori_structure->ind_points_of_face(j);
96  }
97 
98  p->dir_points_.resize(ori_structure->ind_dir_points().size());
99  p->dir_points_ = ori_structure->ind_dir_points();
100 
101  p->basic_pcvs = basic_structure(ori_structure);
102 
103  dal::add_stored_object(pk, pcvs, dal::PERMANENT_STATIC_OBJECT);
104  return pcvs;
105  }
106 
107  DAL_SIMPLE_KEY(torus_reference_key, pconvex_ref);
108 
109  pconvex_ref ptorus_reference(pconvex_ref ori_convex_reference)
110  {
111  dal::pstatic_stored_object_key
112  pk = std::make_shared<torus_reference_key>(ori_convex_reference);
113  dal::pstatic_stored_object o = dal::search_stored_object(pk);
114 
115  if (o) return std::dynamic_pointer_cast<const bgeot::convex_of_reference>(o);
116  pconvex_ref p = std::make_shared<torus_reference>(ori_convex_reference);
117  dal::add_stored_object(pk, p, p->structure(), p->pspt(),
118  dal::PERMANENT_STATIC_OBJECT);
119  return p;
120  }
121 
122  void torus_geom_trans::poly_vector_val(const base_node &pt, bgeot::base_vector &val) const{
123  base_node pt_2d(pt);
124  pt_2d.resize(2);
125  poriginal_trans_->poly_vector_val(pt_2d, val);
126  }
127 
128  void torus_geom_trans::poly_vector_val(const base_node &pt, const bgeot::convex_ind_ct &ind_ct,
129  bgeot::base_vector &val) const{
130  base_node pt_2d(pt);
131  pt_2d.resize(2);
132  poriginal_trans_->poly_vector_val(pt_2d, ind_ct, val);
133  }
134 
135  void torus_geom_trans::poly_vector_grad(const base_node &pt, bgeot::base_matrix &pc) const{
136  base_node pt2D(pt);
137  pt2D.resize(2);
138  bgeot::base_matrix pc2D(nb_points(), 2);
139  poriginal_trans_->poly_vector_grad(pt2D, pc2D);
140 
141  bgeot::base_vector base_value;
142  poriginal_trans_->poly_vector_val(pt2D, base_value);
143 
144  pc.resize(nb_points(), 3);
145 
146  for (size_type i = 0; i < nb_points(); ++i){
147  for (bgeot::dim_type n = 0; n < 2; ++n) pc(i, n) = pc2D(i, n);
148  pc(i, 2) = base_value[i]; // radial direction, pc = base_x;
149  }
150  }
151 
153  const bgeot::convex_ind_ct &ind_ct, bgeot::base_matrix &pc) const{
154  base_node pt2D(pt);
155  pt2D.resize(2);
156  bgeot::base_matrix pc2D(ind_ct.size(), 2);
157  poriginal_trans_->poly_vector_grad(pt2D, pc2D);
158  pc.resize(ind_ct.size(), dim());
159  for (size_type i = 0; i < ind_ct.size(); ++i){
160  for (bgeot::dim_type n = 0; n < 2; ++n) pc(i, n) = pc2D(i, n);
161  }
162  }
163 
165  (const bgeot::base_matrix &G, const bgeot::base_matrix &pc, bgeot::base_matrix &K) const{
167  K(2, 2) = 0.0;
168  for (short_type j = 0; j < nb_points(); ++ j) K(2, 2) += G(0, j) * pc(j, 2);
169  for (short_type i = 0; i < 2; ++i) K(2, i) = K(i, 2) = 0;
170  }
171 
173  bgeot::base_matrix & /*pc*/) const{
174  GMM_ASSERT1(false, "Sorry, Hessian is not supported in axisymmetric transformation.");
175  }
176 
177  torus_geom_trans::torus_geom_trans(pgeometric_trans poriginal_trans)
178  : poriginal_trans_(poriginal_trans){
179  geometric_trans::is_lin = poriginal_trans_->is_linear();
180  geometric_trans::cvr = ptorus_reference(poriginal_trans_->convex_ref());
181  complexity_ = poriginal_trans_->complexity();
182  fill_standard_vertices();
183  }
184 
185  pgeometric_trans torus_geom_trans::get_original_transformation() const{
186  return poriginal_trans_;
187  }
188 
189  bool is_torus_structure(pconvex_structure cvs){
190  const torus_structure *cvs_torus = dynamic_cast<const torus_structure *>(cvs.get());
191  return cvs_torus != NULL;
192  }
193 
194  DAL_SIMPLE_KEY(torus_geom_trans_key, pgeometric_trans);
195 
196  pgeometric_trans torus_geom_trans_descriptor(pgeometric_trans poriginal_trans){
197  dal::pstatic_stored_object_key
198  pk = std::make_shared<torus_geom_trans_key>(poriginal_trans);
199  dal::pstatic_stored_object o = dal::search_stored_object(pk);
200 
201  if (o) return std::dynamic_pointer_cast<const torus_geom_trans>(o);
202 
203  bgeot::pgeometric_trans p = std::make_shared<torus_geom_trans>(poriginal_trans);
204  dal::add_stored_object(pk, p, dal::PERMANENT_STATIC_OBJECT);
205  return p;
206  }
207 
208  bool is_torus_geom_trans(pgeometric_trans pgt){
209  const torus_geom_trans *pgt_torus = dynamic_cast<const torus_geom_trans *>(pgt.get());
210  return pgt_torus != NULL;
211  }
212 
213 }
friend pconvex_structure basic_structure(pconvex_structure cv)
Original structure (if concerned)
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
Point tab storage.
generic definition of a convex ( bgeot::convex_structure + vertices coordinates ) ...
Definition: bgeot_convex.h:50
pstatic_stored_object search_stored_object(pstatic_stored_object_key k)
Gives a pointer to an object from a key pointer.
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:49
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies.
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:165
short_type nb_points() const
Number of vertices.
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:172
Structure of a convex.
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:135
Base class for reference convexes.
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:79
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:122
dim_type dim() const
Dimension of the convex.
Basic Geometric Tools.
An adaptor that adapts a two dimensional geometric_trans to include radial dimension.
Definition: bgeot_torus.h:48
Provides mesh of torus.
torus_structure which extends a 2 dimensional structure with a radial dimension
Definition: bgeot_torus.cc:26
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation