MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
eigenproblem_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_eigenproblem_assembly_h__
21 #define __mast_libmesh_eigenproblem_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  _finalize_jac (true),
50  _e_ops (nullptr)
51  { }
52 
53  virtual ~EigenProblemAssembly() { }
54 
55  inline void set_finalize_jac(bool f) { _finalize_jac = f;}
56 
57  inline void set_elem_ops(ElemOpsType& e_ops) { _e_ops = &e_ops; }
58 
59  template <typename VecType, typename MatType, typename ContextType>
60  inline void assemble(ContextType &c,
61  const VecType &X,
62  MatType &A,
63  MatType &B) {
64 
67 
68  // iterate over each element, initialize it and get the relevant
69  // analysis quantities
71  sol_accessor(*c.sys, X);
72 
73  using elem_vector_t = typename ElemOpsType::vector_t;
74  using elem_matrix_t = typename ElemOpsType::matrix_t;
75 
76  elem_matrix_t
77  A_e,
78  B_e;
79 
80 
81 
82  libMesh::MeshBase::const_element_iterator
83  el = c.mesh->active_local_elements_begin(),
84  end_el = c.mesh->active_local_elements_end();
85 
86  for ( ; el != end_el; ++el) {
87 
88  // set element in the context, which will be used for the initialization routines
89  c.elem = *el;
90 
91  sol_accessor.init(*c.elem);
92 
93  A_e.setZero(sol_accessor.n_dofs(), sol_accessor.n_dofs());
94  B_e.setZero(sol_accessor.n_dofs(), sol_accessor.n_dofs());
95 
96  // perform the element level calculations
97  _e_ops->compute(c, sol_accessor, A_e, B_e);
98 
99  // constrain the quantities to account for hanging dofs,
100  // Dirichlet constraints, etc.
102  <ScalarType, MatType, elem_matrix_t>
103  (A, c.sys->get_dof_map(), sol_accessor.dof_indices(), A_e);
104 
106  <ScalarType, MatType, elem_matrix_t>
107  (B, c.sys->get_dof_map(), sol_accessor.dof_indices(), B_e);
108  }
109 
110  // parallel matrix require finalization of communication
111  if (_finalize_jac) {
112 
115  }
116  }
117 
118 
119  template <typename VecType,
120  typename MatType,
121  typename ContextType,
122  typename ScalarFieldType>
123  inline void sensitivity_assemble(ContextType &c,
124  const ScalarFieldType &f,
125  const VecType &X,
126  MatType &A,
127  MatType &B) {
128 
131 
132  // iterate over each element, initialize it and get the relevant
133  // analysis quantities
135  sol_accessor(*c.sys, X);
136 
137  using elem_vector_t = typename ElemOpsType::vector_t;
138  using elem_matrix_t = typename ElemOpsType::matrix_t;
139 
140  elem_matrix_t
141  A_e,
142  B_e;
143 
144  libMesh::MeshBase::const_element_iterator
145  el = c.mesh->active_local_elements_begin(),
146  end_el = c.mesh->active_local_elements_end();
147 
148  for ( ; el != end_el; ++el) {
149 
150  // set element in the context, which will be used for the initialization routines
151  c.elem = *el;
152 
153  sol_accessor.init(*c.elem);
154 
155  A_e.setZero(sol_accessor.n_dofs(), sol_accessor.n_dofs());
156  B_e.setZero(sol_accessor.n_dofs(), sol_accessor.n_dofs());
157 
158  // perform the element level calculations
159  _e_ops->derivative(c, f, sol_accessor, A_e, B_e);
160 
161  // constrain the quantities to account for hanging dofs,
162  // Dirichlet constraints, etc.
164  <ScalarType, MatType, elem_matrix_t>
165  (A, c.sys->get_dof_map(), sol_accessor.dof_indices(), A_e);
166 
168  <ScalarType, MatType, elem_matrix_t>
169  (B, c.sys->get_dof_map(), sol_accessor.dof_indices(), B_e);
170  }
171 
172  // parallel matrix require finalization of communication
173  if (_finalize_jac) {
174 
177  }
178  }
179 
180 private:
181 
183  ElemOpsType *_e_ops;
184 };
185 
186 } // namespace libMeshWrapper
187 } // namespace Assembly
188 } // namespace Base
189 } // namespace MAST
190 
191 #endif // __mast_libmesh_eigenproblem_assembly_h__
void init(const libMesh::Elem &e)
Definition: accessor.hpp:69
void setZero(ValType &m)
Definition: utility.hpp:44
void sensitivity_assemble(ContextType &c, const ScalarFieldType &f, const VecType &X, MatType &A, MatType &B)
void assemble(ContextType &c, const VecType &X, MatType &A, MatType &B)
void finalize(ValType &m)
Definition: utility.hpp:252
const std::vector< libMesh::dof_id_type > & dof_indices() const
Definition: accessor.hpp:55
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)
std::enable_if< std::is_same< ScalarType, real_t >::value, void >::type constrain_and_add_matrix(MatType &m, const libMesh::DofMap &dof_map, std::vector< libMesh::dof_id_type > &dof_indices, SubMatType &m_sub)
Definition: utility.hpp:132