MAST
fe_base.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2019 Manav Bhatia
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 // MAST includes
21 #include "mesh/fe_base.h"
22 #include "mesh/geom_elem.h"
24 #include "base/nonlinear_system.h"
25 
26 
28 _sys (sys),
29 _extra_quadrature_order (0),
30 _init_second_order_derivatives (false),
31 _initialized (false),
32 _elem (nullptr),
33 _fe (nullptr),
34 _qrule (nullptr) {
35 
36 }
37 
38 
40 
41  if (_fe)
42  delete _fe;
43 
44  if (_qrule)
45  delete _qrule;
46 }
47 
48 
49 void
51 
53 }
54 
55 
56 void
58 
60 }
61 
62 
63 void
65  bool init_grads,
66  const std::vector<libMesh::Point>* pts) {
67 
68  libmesh_assert(!_initialized);
69 
70 
71  _elem = &elem;
72  const unsigned int
73  nv = _sys.n_vars();
74  libMesh::FEType
75  fe_type = _sys.fetype(0); // all variables are assumed to be of same type
76 
77 
78  for (unsigned int i=1; i != nv; ++i)
79  libmesh_assert(fe_type == _sys.fetype(i));
80 
81  const libMesh::Elem*
82  q_elem = nullptr;
83 
84  if (elem.use_local_elem())
85  q_elem = &elem.get_quadrature_local_elem();
86  else
87  q_elem = &elem.get_quadrature_elem();
88 
89  // Create an adequate quadrature rule
90  _fe = libMesh::FEBase::build(q_elem->dim(), fe_type).release();
91  _fe->get_phi();
92  _fe->get_xyz();
93  _fe->get_JxW();
94  if (init_grads) {
95  _fe->get_dphi();
96  _fe->get_dphidxi();
97  _fe->get_dphideta();
98  _fe->get_dphidzeta();
99  }
100  if (_init_second_order_derivatives) _fe->get_d2phi();
101 
102  if (pts == nullptr) {
103  _qrule = fe_type.default_quadrature_rule
104  (q_elem->dim(),
105  _sys.system().extra_quadrature_order+_extra_quadrature_order).release(); // system extra quadrature
106  _fe->attach_quadrature_rule(_qrule);
107  _fe->reinit(q_elem);
108  }
109  else {
110  _fe->reinit(q_elem, pts);
111  _qpoints = *pts;
112  }
113 
114  // now initialize the global xyz locations if the element uses a locally
115  // defined element.
116  if (elem.use_local_elem()) {
117 
118  const std::vector<libMesh::Point>
119  local_xyz = _fe->get_xyz();
120 
121  unsigned int
122  n = (unsigned int) local_xyz.size();
123  _global_xyz.resize(n);
124 
125  for (unsigned int i=0; i<n; i++)
126  elem.transform_point_to_global_coordinate(local_xyz[i], _global_xyz[i]);
127  }
128 
129  _initialized = true;
130 }
131 
132 
133 
134 
135 
136 void
138  unsigned int s,
139  bool if_calculate_dphi) {
140 
141  libmesh_assert(!_initialized);
142 
143  _elem = &elem;
144 
145  const unsigned int
146  nv = _sys.n_vars();
147 
148  libmesh_assert (nv);
149  libMesh::FEType fe_type = _sys.fetype(0); // all variables are assumed to be of same type
150 
151  for (unsigned int i=1; i != nv; ++i)
152  libmesh_assert(fe_type == _sys.fetype(i));
153 
154  const libMesh::Elem*
155  q_elem = nullptr;
156 
157  if (elem.use_local_elem())
158  q_elem = &elem.get_quadrature_local_elem();
159  else
160  q_elem = &elem.get_quadrature_elem();
161 
162  // Create an adequate quadrature rule
163  _fe = libMesh::FEBase::build(q_elem->dim(), fe_type).release();
164  _qrule = fe_type.default_quadrature_rule
165  (q_elem->dim()-1,
166  _sys.system().extra_quadrature_order+_extra_quadrature_order).release(); // system extra quadrature
167  _fe->attach_quadrature_rule(_qrule);
168  _fe->get_phi();
169  _fe->get_xyz();
170  _fe->get_JxW();
171  _fe->get_normals();
172  if (if_calculate_dphi) {
173 
174  _fe->get_dphi();
175  if (_init_second_order_derivatives) _fe->get_d2phi();
176  }
177 
178  _fe->reinit(q_elem, s);
179 
180 
181  // now initialize the global xyz locations and normals
182  _local_normals = _fe->get_normals();
183  if (elem.use_local_elem()) {
184 
185  const std::vector<libMesh::Point>
186  &local_xyz = _fe->get_xyz();
187 
188  unsigned int
189  n = (unsigned int) local_xyz.size();
190  _global_xyz.resize(n);
191  _global_normals.resize(n);
192 
193  for (unsigned int i=0; i<n; i++) {
194 
195  elem.transform_point_to_global_coordinate(local_xyz[i], _global_xyz[i]);
197  }
198  }
199  else {
201  _global_xyz = _fe->get_xyz();
202  }
203 
204 
205  _initialized = true;
206 }
207 
208 
209 
210 
211 libMesh::FEType
213 
214  libmesh_assert(_initialized);
215  return _fe->get_fe_type();
216 }
217 
218 
219 const std::vector<Real>&
221 
222  libmesh_assert(_initialized);
223  return _fe->get_JxW();
224 }
225 
226 
227 const std::vector<libMesh::Point>&
229 
230  libmesh_assert(_initialized);
231  if (_elem->use_local_elem())
232  return _global_xyz;
233  else
234  return _fe->get_xyz();
235 }
236 
237 
238 unsigned int
240 
241  libmesh_assert(_initialized);
242  return _fe->n_shape_functions();
243 }
244 
245 
246 const std::vector<std::vector<Real> >&
248 
249  libmesh_assert(_initialized);
250  return _fe->get_phi();
251 }
252 
253 
254 const std::vector<std::vector<libMesh::RealVectorValue> >&
256 
257  libmesh_assert(_initialized);
258  return _fe->get_dphi();
259 }
260 
261 
262 const std::vector<std::vector<libMesh::RealTensorValue>>&
264 
265  libmesh_assert(_initialized);
266  return _fe->get_d2phi();
267 }
268 
269 
270 const std::vector<Real>&
272 
273  libmesh_assert(_initialized);
274  return _fe->get_dxidx();
275 }
276 
277 
278 const std::vector<Real>&
280 
281  libmesh_assert(_initialized);
282  return _fe->get_dxidy();
283 }
284 
285 
286 const std::vector<Real>&
288 
289  libmesh_assert(_initialized);
290  return _fe->get_dxidz();
291 }
292 
293 
294 const std::vector<Real>&
296 
297  libmesh_assert(_initialized);
298  return _fe->get_detadx();
299 }
300 
301 
302 const std::vector<Real>&
304 
305  libmesh_assert(_initialized);
306  return _fe->get_detady();
307 }
308 
309 
310 const std::vector<Real>&
312 
313  libmesh_assert(_initialized);
314  return _fe->get_detadz();
315 }
316 
317 
318 const std::vector<Real>&
320 
321  libmesh_assert(_initialized);
322  return _fe->get_dzetadx();
323 }
324 
325 
326 const std::vector<Real>&
328 
329  libmesh_assert(_initialized);
330  return _fe->get_dzetady();
331 }
332 
333 
334 const std::vector<Real>&
336 
337  libmesh_assert(_initialized);
338  return _fe->get_dzetadz();
339 }
340 
341 
342 const std::vector<libMesh::RealVectorValue>&
344 
345  libmesh_assert(_initialized);
346  return _fe->get_dxyzdxi();
347 }
348 
349 
350 const std::vector<libMesh::RealVectorValue>&
352 
353  libmesh_assert(_initialized);
354  return _fe->get_dxyzdeta();
355 }
356 
357 
358 const std::vector<libMesh::RealVectorValue>&
360 
361  libmesh_assert(_initialized);
362  return _fe->get_dxyzdzeta();
363 }
364 
365 
366 const std::vector<std::vector<Real> >&
368 
369  libmesh_assert(_initialized);
370  return _fe->get_dphidxi();
371 }
372 
373 
374 const std::vector<std::vector<Real> >&
376 
377  libmesh_assert(_initialized);
378  return _fe->get_dphideta();
379 }
380 
381 
382 const std::vector<std::vector<Real> >&
384 
385  libmesh_assert(_initialized);
386  return _fe->get_dphidzeta();
387 }
388 
389 
390 const std::vector<libMesh::Point>&
392 
393  libmesh_assert(_initialized);
394  return _global_normals;
395 }
396 
397 
398 const std::vector<libMesh::Point>&
400 
401  libmesh_assert(_initialized);
402  return _local_normals;
403 }
404 
405 
406 const std::vector<libMesh::Point>&
408 
409  libmesh_assert(_initialized);
410  if (_qrule) // qrule was used
411  return _qrule->get_points();
412  else // points were specified
413  return _qpoints;
414 }
415 
416 
417 const libMesh::QBase&
419 
420  libmesh_assert(_initialized);
421  return *_qrule;
422 }
423 
virtual const std::vector< Real > & get_detadz() const
Definition: fe_base.cpp:311
virtual ~FEBase()
Definition: fe_base.cpp:39
bool use_local_elem() const
Vector and matrix quantities defined on one- and two-dimensional elements that are oriented in two or...
Definition: geom_elem.cpp:314
virtual const std::vector< Real > & get_dzetadx() const
Definition: fe_base.cpp:319
MAST::NonlinearSystem & system()
std::vector< libMesh::Point > _global_normals
Definition: fe_base.h:189
virtual const std::vector< libMesh::RealVectorValue > & get_dxyzdzeta() const
Definition: fe_base.cpp:359
libMesh::QBase * _qrule
Definition: fe_base.h:185
virtual const std::vector< Real > & get_JxW() const
Definition: fe_base.cpp:220
virtual const std::vector< Real > & get_dxidy() const
Definition: fe_base.cpp:279
virtual const std::vector< Real > & get_dxidz() const
Definition: fe_base.cpp:287
virtual const libMesh::QBase & get_qrule() const
Definition: fe_base.cpp:418
FEBase(const MAST::SystemInitialization &sys)
Definition: fe_base.cpp:27
virtual const std::vector< Real > & get_detadx() const
Definition: fe_base.cpp:295
virtual const std::vector< libMesh::Point > & get_xyz() const
physical location of the quadrature point in the global coordinate system for the reference element ...
Definition: fe_base.cpp:228
bool _init_second_order_derivatives
Definition: fe_base.h:181
virtual const std::vector< std::vector< Real > > & get_dphidzeta() const
Definition: fe_base.cpp:383
virtual const std::vector< libMesh::Point > & get_qpoints() const
Definition: fe_base.cpp:407
virtual const std::vector< libMesh::RealVectorValue > & get_dxyzdeta() const
Definition: fe_base.cpp:351
virtual const std::vector< Real > & get_dzetady() const
Definition: fe_base.cpp:327
std::vector< libMesh::Point > _local_normals
Definition: fe_base.h:188
std::vector< libMesh::Point > _qpoints
Definition: fe_base.h:186
bool _initialized
Definition: fe_base.h:182
virtual void init_for_side(const MAST::GeomElem &elem, unsigned int s, bool if_calculate_dphi)
Initializes the quadrature and finite element for element side integration.
Definition: fe_base.cpp:137
virtual const std::vector< Real > & get_dzetadz() const
Definition: fe_base.cpp:335
const libMesh::FEType & fetype(unsigned int i) const
const MAST::SystemInitialization & _sys
Definition: fe_base.h:179
void set_evaluate_second_order_derivatives(bool f)
sets the flag for evaluation of second order derivative
Definition: fe_base.cpp:57
virtual const std::vector< std::vector< Real > > & get_dphideta() const
Definition: fe_base.cpp:375
libMesh::FEBase * _fe
Definition: fe_base.h:184
void set_extra_quadrature_order(int n)
this is used, in addition to libMesh::System::extra_quadrature_order to set the quadrature rule...
Definition: fe_base.cpp:50
virtual const std::vector< std::vector< Real > > & get_dphidxi() const
Definition: fe_base.cpp:367
virtual unsigned int n_shape_functions() const
Definition: fe_base.cpp:239
virtual const std::vector< libMesh::Point > & get_normals_for_reference_coordinate() const
normals defined in the global coordinate system for the reference element
Definition: fe_base.cpp:391
std::vector< libMesh::Point > _global_xyz
Definition: fe_base.h:187
void transform_point_to_global_coordinate(const libMesh::Point &local_pt, libMesh::Point &global_pt) const
Definition: geom_elem.cpp:238
virtual const std::vector< Real > & get_detady() const
Definition: fe_base.cpp:303
virtual const std::vector< Real > & get_dxidx() const
Definition: fe_base.cpp:271
This class acts as a wrapper around libMesh::Elem for the purpose of providing a uniform interface fo...
Definition: geom_elem.h:59
virtual void init(const MAST::GeomElem &elem, bool init_grads, const std::vector< libMesh::Point > *pts=nullptr)
Initializes the quadrature and finite element for element volume integration.
Definition: fe_base.cpp:64
virtual const std::vector< std::vector< libMesh::RealVectorValue > > & get_dphi() const
Definition: fe_base.cpp:255
virtual const std::vector< libMesh::RealVectorValue > & get_dxyzdxi() const
Definition: fe_base.cpp:343
virtual const libMesh::Elem & get_quadrature_elem() const
Definition: geom_elem.cpp:72
virtual const std::vector< std::vector< libMesh::RealTensorValue > > & get_d2phi() const
Definition: fe_base.cpp:263
virtual const std::vector< std::vector< Real > > & get_phi() const
Definition: fe_base.cpp:247
virtual const libMesh::Elem & get_quadrature_local_elem() const
Definition: geom_elem.cpp:81
libMesh::FEType get_fe_type() const
Definition: fe_base.cpp:212
void transform_vector_to_global_coordinate(const libMesh::Point &local_vec, libMesh::Point &global_vec) const
Definition: geom_elem.cpp:258
virtual const std::vector< libMesh::Point > & get_normals_for_local_coordinate() const
normals defined in the coordinate system for the local reference element.
Definition: fe_base.cpp:399
const MAST::GeomElem * _elem
Definition: fe_base.h:183
unsigned int _extra_quadrature_order
Definition: fe_base.h:180