20 #ifndef __mast_optimization_topology_simp_libmesh_output_sensitivity_h__ 21 #define __mast_optimization_topology_simp_libmesh_output_sensitivity_h__ 33 #include <libmesh/nonlinear_implicit_system.h> 34 #include <libmesh/dof_map.h> 38 namespace Optimization {
41 namespace libMeshWrapper {
43 template <
typename ScalarType,
44 typename ResidualElemOpsType,
45 typename OutputElemOpsType>
50 static_assert(std::is_same<ScalarType,
51 typename ResidualElemOpsType::scalar_t>::
value,
52 "Scalar type of assembly and element operations must be same");
53 static_assert(std::is_same<ScalarType,
54 typename OutputElemOpsType::scalar_t>::
value,
55 "Scalar type of assembly and element operations must be same");
66 OutputElemOpsType &output_ops) {
76 template <
typename Vec1Type,
82 const Vec2Type &density,
83 const Vec1Type &X_adj,
84 const FilterType &filter,
86 std::vector<ScalarType> &sens) {
89 Assert2(density.size() == c.rho_sys->n_dofs(),
90 density.size(), c.rho_sys->n_dofs(),
91 "Density coefficients must be provided for whole mesh");
93 dvs.
size(), sens.size(),
94 "DV and sensitivity vectors must have same size");
97 n_density_dofs = c.rho_sys->n_dofs(),
102 std::unique_ptr<Vec2Type>
103 v (MAST::Numerics::Utility::build<Vec2Type>(*c.rho_sys).release()),
104 v_filtered (MAST::Numerics::Utility::build<Vec2Type>(*c.rho_sys).release());
109 sol_accessor (*c.sys, X),
110 adj_accessor (*c.sys, X_adj);
113 density_accessor (*c.rho_sys, density);
115 using elem_vector_t =
typename ResidualElemOpsType::vector_t;
116 using elem_matrix_t =
typename ResidualElemOpsType::matrix_t;
125 libMesh::MeshBase::const_element_iterator
126 el = c.mesh->active_local_elements_begin(),
127 end_el = c.mesh->active_local_elements_end();
131 for ( ; el != end_el; ++el) {
137 sol_accessor.init(*c.elem);
138 density_accessor.
init(*c.elem);
139 adj_accessor.init(*c.elem);
141 const std::vector<libMesh::dof_id_type>
146 for (
uint_t i=0; i<n_nodes; i++) {
162 drho.setZero(density_dof_ids.size());
165 dres_e.setZero(sol_accessor.n_dofs());
187 + adj_accessor.dot(dres_e));
194 filter.compute_reverse_filtered_values(*v, *v_filtered);
219 #endif // __mast_optimization_topology_simp_libmesh_output_sensitivity_h__ ScalarType get(const std::vector< ScalarType > &v, uint_t i)
void init(const libMesh::Elem &e)
uint_t local_begin() const
void finalize(ValType &m)
const std::vector< libMesh::dof_id_type > & dof_indices() const
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)
void set_elem_ops(ResidualElemOpsType &e_ops, OutputElemOpsType &output_ops)
bool is_design_parameter_dof_id(const uint_t i) const
void assemble(ContextType &c, const Vec1Type &X, const Vec2Type &density, const Vec1Type &X_adj, const FilterType &filter, const MAST::Optimization::DesignParameterVector< ScalarType > &dvs, std::vector< ScalarType > &sens)
output derivative is defined as a
ResidualElemOpsType * _e_ops
const MAST::Base::ParameterData & get_data_for_parameter(const MAST::Optimization::DesignParameter< ScalarType > &p) const
#define Assert0(cond, msg)
uint_t n_linear_basis_nodes_on_elem(const libMesh::Elem &e)
identifies number of ndoes on element
void add(std::vector< ScalarType > &v, uint_t i, ScalarType s)
#define Assert2(cond, v1, v2, msg)
void comm_sum(const libMesh::Parallel::Communicator &comm, real_t &v)
OutputElemOpsType * _output_e_ops
uint_t get_dv_id_for_topology_dof(const uint_t id) const
AssembleOutputSensitivity()
virtual ~AssembleOutputSensitivity()