MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
stress_assembly.hpp
Go to the documentation of this file.
1 /*
2 * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3 * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
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 #ifndef __mast_libmesh_stress_assembly_h__
21 #define __mast_libmesh_stress_assembly_h__
22 
23 // MAST includes
25 #include <mast/base/exceptions.hpp>
29 
30 // libMesh includes
31 #include <libmesh/nonlinear_implicit_system.h>
32 #include <libmesh/dof_map.h>
33 
34 namespace MAST {
35 namespace Base {
36 namespace Assembly {
37 namespace libMeshWrapper {
38 
39 template <typename ScalarType,
40  typename ElemOpsType>
42 
43 public:
44 
46  "Scalar type of assembly and element operations must be same");
47 
49  _e_ops (nullptr)
50  { }
51 
52  virtual ~StressAssembly() { }
53 
54  inline void set_elem_ops(ElemOpsType& e_ops) { _e_ops = &e_ops; }
55 
56  template <typename VecType,
57  typename IndexingType,
58  typename StorageType,
59  typename ContextType>
60  inline void assemble(ContextType &c,
61  const VecType &X,
62  const IndexingType &index,
63  StorageType &stress) {
64 
65  // iterate over each element, initialize it and get the relevant
66  // analysis quantities
68  sol_accessor(*c.sys, X);
69 
70  libMesh::MeshBase::const_element_iterator
71  el = c.mesh->active_local_elements_begin(),
72  end_el = c.mesh->active_local_elements_end();
73 
74  for ( ; el != end_el; ++el) {
75 
76  // set element in the context, which will be used for the initialization routines
77  c.elem = *el;
78 
79  sol_accessor.init(*c.elem);
80 
81  // perform the element level calculations
82  _e_ops->compute(c, sol_accessor, index, stress);
83  }
84  }
85 
86 
87  template <typename VecType,
88  typename IndexingType,
89  typename StorageType,
90  typename ContextType,
91  typename ScalarFieldType>
92  inline void sensitivity_assemble(ContextType &c,
93  const ScalarFieldType &f,
94  const VecType &X,
95  const VecType &dX,
96  const IndexingType &index,
97  StorageType &dstress) {
98 
99  // iterate over each element, initialize it and get the relevant
100  // analysis quantities
102  sol_accessor(*c.sys, X),
103  dsol_accessor(*c.sys, dX);
104 
105  libMesh::MeshBase::const_element_iterator
106  el = c.mesh->active_local_elements_begin(),
107  end_el = c.mesh->active_local_elements_end();
108 
109  for ( ; el != end_el; ++el) {
110 
111  // set element in the context, which will be used for the initialization routines
112  c.elem = *el;
113 
114  sol_accessor.init(*c.elem);
115  dsol_accessor.init(*c.elem);
116 
117  // perform the element level calculations
118  _e_ops->derivative(c, f, sol_accessor, dsol_accessor, index, dstress);
119  }
120  }
121 
122 
123 private:
124 
125  ElemOpsType *_e_ops;
126 };
127 
128 } // namespace libMeshWrapper
129 } // namespace Assembly
130 } // namespace Base
131 } // namespace MAST
132 
133 #endif // __mast_libmesh_stress_assembly_h__
void assemble(ContextType &c, const VecType &X, const IndexingType &index, StorageType &stress)
void init(const libMesh::Elem &e)
Definition: accessor.hpp:69
void sensitivity_assemble(ContextType &c, const ScalarFieldType &f, const VecType &X, const VecType &dX, const IndexingType &index, StorageType &dstress)
std::enable_if< Dim< 3, ScalarType >::typesource_load_multiplier(const SourceLoadFieldType *f, const SectionAreaType *s, ContextType &c) { Assert0(f, "Invalid pointer");Assert0(s, "Invalid pointer");return f-> value(c) *s -> value(c)