MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
ks_stress_output.cpp
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 
21 // MAST includes
24 #include "base/assembly_base.h"
26 #include "base/nonlinear_system.h"
32 #include "mesh/geom_elem.h"
33 
34 // libMesh includes.
35 #include "libmesh/parallel.h"
36 
39 
40 }
41 
42 
43 
44 
46 
47 }
48 
49 
50 
51 
52 void
54 
55  libmesh_assert(!_if_stress_plot_mode);
56  libmesh_assert(!_primal_data_initialized);
57  libmesh_assert_greater(_sigma0, 0.);
58 
59  Real
60  e_val = 0.,
61  JxW = 0.;
62 
63  _JxW_val = 0.;
64  _sigma_vm_int = 0.;
65  _sigma_vm_p_norm = 0.;
66 
67  // first find the data with the maximum value, to be used for scaling
68 
69  // iterate over all element data
70  std::map<const libMesh::dof_id_type, std::vector<MAST::StressStrainOutputBase::Data*> >::const_iterator
71  map_it = _stress_data.begin(),
72  map_end = _stress_data.end();
73 
74  for ( ; map_it != map_end; map_it++) {
75 
76  std::vector<MAST::StressStrainOutputBase::Data*>::const_iterator
77  vec_it = map_it->second.begin(),
78  vec_end = map_it->second.end();
79 
80  for ( ; vec_it != vec_end; vec_it++) {
81 
82  // ask this data point for the von Mises stress value
83  e_val = (*vec_it)->von_Mises_stress();
84  JxW = (*vec_it)->quadrature_point_JxW();
85 
86  // we do not use absolute value here, since von Mises stress
87  // is >= 0.
88  _sigma_vm_int += exp(_p_norm_stress * (e_val-_sigma0)/_sigma0) * JxW;
89  _JxW_val += JxW;
90  }
91  }
92 
93  // sum over all processors, since part of the mesh will exist on the
94  // other processors.
95  if (!_skip_comm_sum) {
96 
97  _system->system().comm().sum(_sigma_vm_int);
98  _system->system().comm().sum(_JxW_val);
99  }
100 
103 }
104 
105 
106 
107 
108 void
111  const libMesh::dof_id_type e_id,
112  Real& dsigma_vm_val_df) const {
113 
114  libmesh_assert(!_if_stress_plot_mode);
115  libmesh_assert(_primal_data_initialized);
116  libmesh_assert_greater(_sigma0, 0.);
117 
118  Real
119  e_val = 0.,
120  de_val = 0.,
121  num_sens = 0.,
122  JxW = 0.;
123 
124  dsigma_vm_val_df = 0.;
125 
126  // iterate over all element data
127  std::map<const libMesh::dof_id_type, std::vector<MAST::StressStrainOutputBase::Data*> >::const_iterator
128  map_it = _stress_data.find(e_id),
129  map_end = _stress_data.end();
130 
131  libmesh_assert(map_it != map_end);
132 
133  std::vector<MAST::StressStrainOutputBase::Data*>::const_iterator
134  vec_it = map_it->second.begin(),
135  vec_end = map_it->second.end();
136 
137  for ( ; vec_it != vec_end; vec_it++) {
138 
139  // ask this data point for the von Mises stress value
140  e_val = (*vec_it)->von_Mises_stress();
141  de_val = (*vec_it)->dvon_Mises_stress_dp(f);
142  JxW = (*vec_it)->quadrature_point_JxW();
143 
144  num_sens += _p_norm_stress * de_val/_sigma0 * exp(_p_norm_stress * (e_val-_sigma0)/_sigma0) * JxW;
145  }
146 
147  dsigma_vm_val_df = 1./_p_norm_stress / (_sigma_vm_int/_JxW_val) * num_sens / _JxW_val;
148 }
149 
150 
151 
152 
153 
154 void
157  const libMesh::dof_id_type e_id,
158  Real& dsigma_vm_val_df) const {
159 
160  libmesh_assert(!_if_stress_plot_mode);
161  libmesh_assert(_primal_data_initialized);
162  libmesh_assert_greater(_sigma0, 0.);
163 
164  Real
165  e_val = 0.,
166  JxW_Vn = 0.,
167  num_sens = 0.,
168  denom_sens = 0.;
169 
170  dsigma_vm_val_df = 0.;
171 
172  // iterate over all element data
173  std::map<const libMesh::dof_id_type, std::vector<MAST::StressStrainOutputBase::Data*> >::const_iterator
174  map_it = _boundary_stress_data.find(e_id),
175  map_end = _boundary_stress_data.end();
176 
177  libmesh_assert(map_it != map_end);
178 
179  std::vector<MAST::StressStrainOutputBase::Data*>::const_iterator
180  vec_it = map_it->second.begin(),
181  vec_end = map_it->second.end();
182 
183  for ( ; vec_it != vec_end; vec_it++) {
184 
185  // ask this data point for the von Mises stress value
186  e_val = (*vec_it)->von_Mises_stress();
187  JxW_Vn = (*vec_it)->quadrature_point_JxW();
188 
189  denom_sens += JxW_Vn;
190  num_sens += exp(_p_norm_stress * (e_val-_sigma0)/_sigma0) * JxW_Vn;
191  }
192 
193  dsigma_vm_val_df = 1./_p_norm_stress / (_sigma_vm_int/_JxW_val) *
194  (num_sens / _JxW_val - _sigma_vm_int / pow(_JxW_val, 2.) * denom_sens);
195 }
196 
197 
198 
199 
200 void
202  RealVectorX& dq_dX) const {
203  libmesh_assert(!_if_stress_plot_mode);
204  libmesh_assert(_primal_data_initialized);
205  libmesh_assert_greater(_sigma0, 0.);
206 
207  Real
208  e_val = 0.,
209  JxW = 0.;
210 
212  num_sens = RealVectorX::Zero(dq_dX.size()),
213  de_val = RealVectorX::Zero(dq_dX.size());
214  dq_dX.setZero();
215 
216  // first find the data with the maximum value, to be used for scaling
217 
218  // iterate over all element data
219  std::map<const libMesh::dof_id_type, std::vector<MAST::StressStrainOutputBase::Data*> >::const_iterator
220  map_it = _stress_data.find(e_id),
221  map_end = _stress_data.end();
222 
223  // make sure that the data exists
224  libmesh_assert(map_it != map_end);
225 
226  std::vector<MAST::StressStrainOutputBase::Data*>::const_iterator
227  vec_it = map_it->second.begin(),
228  vec_end = map_it->second.end();
229 
230 
231  for ( ; vec_it != vec_end; vec_it++) {
232 
233  // ask this data point for the von Mises stress value
234  e_val = (*vec_it)->von_Mises_stress();
235  de_val = (*vec_it)->dvon_Mises_stress_dX();
236  JxW = (*vec_it)->quadrature_point_JxW();
237 
238  num_sens += _p_norm_stress * de_val/_sigma0 * exp(_p_norm_stress * (e_val-_sigma0)/_sigma0) * JxW;
239  }
240 
241  dq_dX = 1./_p_norm_stress / (_sigma_vm_int/_JxW_val) * num_sens / _JxW_val;
242 }
243 
244 
245 
246 
MAST::NonlinearSystem & system()
Data structure provides the mechanism to store stress and strain output from a structural analysis...
virtual void functional_boundary_sensitivity_for_elem(const MAST::FunctionBase &f, const libMesh::dof_id_type e_id, Real &dsigma_vm_val_df) const
calculates and returns the boundary sensitivity of von Mises p-norm functional for the element e...
std::map< const libMesh::dof_id_type, std::vector< MAST::StressStrainOutputBase::Data * > > _boundary_stress_data
vector of stress with the associated location details
Real _sigma0
reference stress value used in scaling volume.
libMesh::Real Real
bool _primal_data_initialized
primal data, needed for sensitivity and adjoints
Real _p_norm_stress
norm to be used for calculation of output stress function.
KSStressStrainOutput()
default constructor
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...
bool _skip_comm_sum
If an output has contrinutions only from local processor then the user can request that the global co...
std::map< const libMesh::dof_id_type, std::vector< MAST::StressStrainOutputBase::Data * > > _stress_data
vector of stress with the associated location details
virtual void functional_for_all_elems()
calculates and returns the von Mises p-norm functional for all the elements that this object currentl...
Matrix< Real, Dynamic, 1 > RealVectorX
virtual void functional_sensitivity_for_elem(const MAST::FunctionBase &f, const libMesh::dof_id_type e_id, Real &dsigma_vm_val_df) const
calculates and returns the sensitivity of von Mises p-norm functional for the element e...
bool _if_stress_plot_mode
identifies the mode in which evaluation is peformed.
MAST::SystemInitialization * _system