MAST
stress_temperature_adjoint.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 
21 // MAST includes
25 #include "base/nonlinear_system.h"
26 #include "base/assembly_base.h"
27 #include "mesh/fe_base.h"
28 #include "mesh/geom_elem.h"
29 
30 // libMesh includes
31 #include "libmesh/dof_map.h"
32 #include "libmesh/numeric_vector.h"
33 
36 _stress (stress),
37 _thermal_assembly (nullptr) {
38 
39 }
40 
41 
42 
44 
45 }
46 
47 
48 void
51 
52  libmesh_assert(!_thermal_assembly);
53  _thermal_assembly = &thermal_assembly;
54 }
55 
56 
57 
58 void
60 set_structural_solutions(const libMesh::NumericVector<Real>& sol,
61  const libMesh::NumericVector<Real>& adj_sol) {
62 
64  sol).release());
66  adj_sol).release());
67 }
68 
69 
70 void
72 
73  // This solves for the adjoint of stress with dependence on temperature.
74  // The sol vector here is the temperature solution since this is called
75  // from within the thermal system assembly, but the stress object
76  // requires the structural solution. Hence, the sol vector is ignored.
77  // Instead, the structural solution is extracted and provided to the
78  // element
79 
80 
81  libmesh_assert(_physics_elem);
82 
85 
86  std::vector<libMesh::dof_id_type> dof_indices;
87  const libMesh::DofMap& dof_map = _system->system().get_dof_map();
88 
89  dof_map.dof_indices (&p_elem->elem().get_reference_elem(), dof_indices);
90 
92  str_sol = RealVectorX::Zero(dof_indices.size());
93 
94  // get the element structural solution
95  for (unsigned int i=0; i<dof_indices.size(); i++)
96  str_sol(i) = (*_structural_sol)(dof_indices[i]);
97 
98  _physics_elem->set_solution(str_sol);
99 }
100 
101 
102 void
104 
105  libmesh_assert(_physics_elem);
106  libmesh_assert(!_stress.stress_plot_mode());
107  libmesh_assert(_stress.primal_data_initialized());
108 
109 
110 
111  dq_dX.setZero();
112 
113  const libMesh::Elem& e = _physics_elem->elem().get_reference_elem();
114 
116 
119 
120  std::vector<libMesh::dof_id_type> dof_indices;
121  const libMesh::DofMap& dof_map = _system->system().get_dof_map();
122 
123  dof_map.dof_indices (&e, dof_indices);
124 
126  str_adj = RealVectorX::Zero(dof_indices.size());
127 
129  mat = RealMatrixX::Zero(dof_indices.size(), dq_dX.size());
130 
131  // get the element structural adjoint solution
132  for (unsigned int i=0; i<dof_indices.size(); i++)
133  str_adj(i) = (*_structural_adjoint)(dof_indices[i]);
134 
135 
137 
138  std::unique_ptr<MAST::FEBase> fe(_physics_elem->elem().init_fe(true, false));
139 
141  p_elem->thermal_residual_temperature_derivative(*fe, mat);
142  }
143 
145  dq_dX += str_adj.transpose() * mat;
146  }
147 }
148 
149 
150 
MAST::NonlinearSystem & system()
Data structure provides the mechanism to store stress and strain output from a structural analysis...
virtual bool if_evaluate_for_element(const MAST::GeomElem &elem) const
checks to see if the object has been told about the subset of elements and if the specified element i...
const MAST::GeomElem & elem() const
Definition: elem_base.h:117
virtual void output_derivative_for_elem(RealVectorX &dq_dX)
calculates the derivative of p-norm von Mises stress for the norm identified using set_p_val()...
MAST::StressStrainOutputBase & _stress
virtual void thermal_residual_temperature_derivative(const MAST::FEBase &fe_thermal, RealMatrixX &m)=0
virtual const libMesh::Elem & get_reference_elem() const
Definition: geom_elem.cpp:54
StressTemperatureAdjoint(MAST::StressStrainOutputBase &stress)
default constructor
Matrix< Real, Dynamic, Dynamic > RealMatrixX
MAST::BoundaryConditionBase * get_thermal_load_for_elem(const MAST::GeomElem &elem)
Matrix< Real, Dynamic, 1 > RealVectorX
virtual void functional_state_derivartive_for_elem(const libMesh::dof_id_type e_id, RealVectorX &dq_dX) const
calculates and returns the derivative of von Mises p-norm functional wrt state vector for the specifi...
std::unique_ptr< libMesh::NumericVector< Real > > build_localized_vector(const libMesh::System &sys, const libMesh::NumericVector< Real > &global) const
localizes the parallel vector so that the local copy stores all values necessary for calculation of t...
void set_thermal_assembly(MAST::AssemblyBase &thermal_assembly)
void set_structural_solutions(const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > &adj_sol)
virtual void calculate_stress_temperature_derivative(MAST::FEBase &fe_thermal, MAST::StressStrainOutputBase &output)=0
virtual void set_solution(const RealVectorX &vec, bool if_sens=false)
stores vec as solution for element level calculations, or its sensitivity if if_sens is true...
Definition: elem_base.cpp:62
virtual void set_elem_solution(const RealVectorX &sol)
sets the element solution
std::unique_ptr< libMesh::NumericVector< Real > > _structural_sol
virtual std::unique_ptr< MAST::FEBase > init_fe(bool init_grads, bool init_second_order_derivative, int extra_quadrature_order=0) const
initializes the finite element shape function and quadrature object with the order of quadrature rule...
Definition: geom_elem.cpp:142
std::unique_ptr< libMesh::NumericVector< Real > > _structural_adjoint
MAST::SystemInitialization * _system