28 void torus_fem::init(){
29 cvr = poriginal_fem_->ref_convex(0);
30 dim_ = cvr->structure()->dim();
31 is_standard_fem =
false;
32 is_equiv = real_element_defined =
true;
33 is_pol = poriginal_fem_->is_polynomial();
34 is_polycomp = poriginal_fem_->is_polynomialcomp();
35 is_lag = poriginal_fem_->is_lagrange();
36 es_degree = poriginal_fem_->estimated_degree();
40 nm <<
"FEM_TORUS(" << poriginal_fem_->debug_name() <<
")";
41 debug_name_ = nm.str();
44 GMM_ASSERT1(poriginal_fem_->target_dim() == 1,
"Vectorial fems not supported");
45 size_type nb_dof_origin = poriginal_fem_->nb_dof(0);
46 for (
size_type k = 0; k < nb_dof_origin; ++k)
50 poriginal_fem_->node_of_dof(0, k));
60 { GMM_ASSERT1(
false,
"No base values, real only element."); }
63 { GMM_ASSERT1(
false,
"No grad values, real only element."); }
66 GMM_ASSERT1(
false,
"No hess values, real only element.");
70 base_tensor &t,
bool)
const{
72 GMM_ASSERT1(!(poriginal_fem_->is_on_real_element()),
"Original FEM must not be real.");
75 poriginal_fem_->base_value(c.
xref(), u_orig);
76 if (!(poriginal_fem_->is_equivalent())){
77 base_tensor u_temp = u_orig;
78 u_orig.mat_transp_reduction(u_temp, c.
M(), 0);
88 bgeot::multi_index tensor_size(u_orig.sizes());
89 tensor_size[0] *= dim_;
90 tensor_size[1] = ntarget_dim;
91 t.adjust_sizes(tensor_size);
92 for (
size_type i = 0; i < u_orig.sizes()[0]; ++i) {
93 for (dim_type j = 0; j < dim_; ++j) {
94 t(i*dim_ + j, j) = u_orig(i, 0);
102 GMM_ASSERT1(!(poriginal_fem_->is_on_real_element()),
"Original FEM must not be real.");
104 bgeot::scalar_type radius = std::abs(c.
xreal()[0]);
106 bgeot::pstored_point_tab ppt = c.pgp()->get_ppoint_tab();
108 base_tensor u_origin = pfp->grad(c.ii());
110 GMM_ASSERT1(!u_origin.empty(),
"Original FEM is unable to provide grad base value!");
112 base_tensor n_origin = pfp->val(c.ii());
114 GMM_ASSERT1(!n_origin.empty(),
"Original FEM is unable to provide base value!");
118 const bgeot::multi_index &origin_size = u_origin.sizes();
119 bgeot::multi_index tensor_size(origin_size);
120 dim_type dim_size = is_scalar_ ? 1 : dim_;
121 tensor_size[0] *= dim_size;
122 tensor_size[1] = ntarget_dim;
123 tensor_size[2] = dim_ + 1;
124 u.adjust_sizes(tensor_size);
125 for (
size_type i = 0; i < origin_size[0]; ++i) {
126 for (dim_type j = 0; j < dim_size; ++j) {
127 for (dim_type k = 0; k < dim_; ++k) {
128 u(i*dim_size+j, j, k) = u_origin(i, 0, k);
133 t.mat_transp_reduction(u, c.B(), 2);
135 if(is_scalar_)
return;
137 for (
size_type i = 0; i < origin_size[0]; ++i) {
138 t(i*dim_size, dim_, dim_) = n_origin[i] / radius;
145 GMM_ASSERT1(
false,
"Hessian not yet implemented in torus fem.");
148 void torus_fem::set_to_scalar(
bool is_scalar){
149 if(is_scalar_ == is_scalar)
return;
151 is_scalar_ = is_scalar;
157 size_type nb_dof_origin = poriginal_fem_->nb_dof(0);
158 for (
size_type k = 0; k < nb_dof_origin; ++k){
159 add_node(poriginal_fem_->dof_types()[k], poriginal_fem_->node_of_dof(0, k));
165 size_type nb_dof_origin = poriginal_fem_->nb_dof(0);
166 for (
size_type k = 0; k < nb_dof_origin; ++k)
170 poriginal_fem_->node_of_dof(0, k));
176 pfem torus_fem::get_original_pfem()
const{
return poriginal_fem_;}
183 getfem::pfem pfem_torus = std::make_shared<torus_fem>(pf);
184 dal::pstatic_stored_object_key
185 pk = std::make_shared<torus_fem_key>(key_count);
191 const torus_fem *ptorus_fem =
dynamic_cast<const torus_fem*
>(pf.get());
195 void torus_mesh_fem::adapt_to_torus_(){
199 if(poriginal_fem == 0)
continue;
201 del_torus_fem(poriginal_fem);
203 pfem pf = new_torus_fem(poriginal_fem);
204 torus_fem *pf_torus =
dynamic_cast<torus_fem*
>(
const_cast<virtual_fem*
>(pf.get()));
205 pf_torus->set_to_scalar((Qdim != 3));
217 if(pf == 0)
continue;
219 if(pf_torus == 0)
continue;
220 pf_torus->set_to_scalar((Qdim != 3));
226 torus_mesh::torus_mesh(std::string name) :
mesh(std::move(name)){}
231 bgeot::vectors_to_base_matrix(G, points_of_convex(ic));
232 G.resize(2, G.ncols());
233 auto pgt_torus = std::dynamic_pointer_cast<const bgeot::torus_geom_trans>(trans_of_convex(ic));
234 GMM_ASSERT2(pgt_torus,
"Internal error, convex is not a torus transformation.");
238 void torus_mesh::adapt(
const getfem::mesh &original_mesh){
240 GMM_ASSERT1(original_mesh.dim() == 2,
"Adapting torus feature must be a 2d mesh");
245 void torus_mesh::adapt(){
249 for(
size_type pt = 0; pt < node_tab_copy.size(); ++pt){
250 node_tab_copy[pt].resize(3);
251 this->pts.add_node(node_tab_copy[pt]);
254 for(
size_type i = 0; i < this->convex_tab.size(); ++i){
256 = bgeot::torus_structure_descriptor(convex_tab[i].cstruct);
257 convex_tab[i].cstruct = pstructure;
260 for(
size_type i = 0; i < this->gtab.size(); ++i){
262 gtab[i] = pgeom_trans;