MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
output_derivative.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_output_derivative_h__
21 #define __mast_libmesh_output_derivative_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 
35 namespace MAST {
36 namespace Base {
37 namespace Assembly {
38 namespace libMeshWrapper {
39 
44 template <typename ScalarType,
45  typename ElemOpsType>
47 
48 public:
49 
51  "Scalar type of assembly and element operations must be same");
52 
54  _e_ops (nullptr)
55  { }
56 
57  virtual ~OutputDerivative() { }
58 
59  inline void set_elem_ops(ElemOpsType& e_ops) { _e_ops = &e_ops; }
60 
61  template <typename VecType, typename ContextType>
62  inline void assemble(ContextType &c,
63  const VecType &X,
64  VecType &dqdX) {
65 
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 
75  elem_vector_t dqdX_e;
76 
77  libMesh::MeshBase::const_element_iterator
78  el = c.mesh->active_local_elements_begin(),
79  end_el = c.mesh->active_local_elements_end();
80 
81  for ( ; el != end_el; ++el) {
82 
83  // set element in the context, which will be used for the initialization routines
84  c.elem = *el;
85 
86  sol_accessor.init(*c.elem);
87 
88  dqdX_e.setZero(sol_accessor.n_dofs());
89 
90  // perform the element level calculations
91  _e_ops->derivativeX(c, sol_accessor, dqdX_e);
92 
93  // constrain the quantities to account for hanging dofs,
94  // Dirichlet constraints, etc.
96  <ScalarType, VecType, elem_vector_t>
97  (dqdX, c.sys->get_dof_map(), sol_accessor.dof_indices(), dqdX_e);
98  }
99 
100  // parallel matrix/vector require finalization of communication
102  }
103 
104 private:
105 
107  ElemOpsType *_e_ops;
108 };
109 
110 } // namespace libMeshWrapper
111 } // namespace Assembly
112 } // namespace Base
113 } // namespace MAST
114 
115 #endif // __mast_libmesh_output_derivative_h__
void init(const libMesh::Elem &e)
Definition: accessor.hpp:69
void assemble(ContextType &c, const VecType &X, VecType &dqdX)
void setZero(ValType &m)
Definition: utility.hpp:44
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)
provides a method for global assembly of derivative of output functional with respect to the solution...
std::enable_if< std::is_same< ScalarType, real_t >::value, void >::type constrain_and_add_vector(VecType &v, const libMesh::DofMap &dof_map, std::vector< libMesh::dof_id_type > &dof_indices, SubVecType &v_sub)
Definition: utility.hpp:113