MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
solid_1D_section_property.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 // BOOST includes
22 #include <boost/test/unit_test.hpp>
23 
24 
25 // MAST includes
26 #include "tests/structural/build_structural_elem_1D.h"
27 #include "tests/structural/build_structural_elem_2D.h"
28 #include "tests/base/test_comparisons.h"
29 #include "tests/structural/build_structural_elem_1D.h"
31 #include "elasticity/structural_discipline.h"
35 #include "base/parameter.h"
40 
41 
42 // libMesh includes
43 #include "libmesh/dof_map.h"
44 
45 
46 
47 template <typename ValType>
48 void check_material_property (ValType& v) {
49 
50  const Real
51  delta = 1.e-8,
52  tol = 1.e-2;
53 
54 
55 
56  // get reference to the element in this mesh
57  const libMesh::Elem& elem = **(v._mesh->local_elements_begin());
58 
59  // now create the structural element
60  std::unique_ptr<MAST::StructuralElementBase>
61  e(MAST::build_structural_element(*v._structural_sys,
62  elem,
63  *v._p_card).release());
64 
65 
67  mat0,
68  dmat,
69  dmatdp;
70 
71  Real
72  p0 = 0.,
73  dp = 0.;
74 
75 
76  libMesh::Point pt;
77 
78 
79 
80  for (unsigned int jj=0; jj<3; jj++) {
81 
82 
83  std::unique_ptr<MAST::FieldFunction<RealMatrixX > > mat_stiff;
84 
85  switch (jj) {
86  case 0: {
87  BOOST_TEST_MESSAGE("**** Sensitivity for A matrix **");
88  mat_stiff = v._p_card->stiffness_A_matrix(*e);
89  }
90  break;
91 
92  case 1: {
93  BOOST_TEST_MESSAGE("**** Sensitivity for B matrix **");
94  mat_stiff = v._p_card->stiffness_B_matrix(*e);
95  }
96  break;
97 
98  case 2: {
99  BOOST_TEST_MESSAGE("**** Sensitivity for D matrix **");
100  mat_stiff = v._p_card->stiffness_D_matrix(*e);
101  }
102  break;
103 
104  default:
105  break;
106  }
107 
108  // now, check the sensitivity with respect to various parameters
109 
110  // NOTE:
111  // First, we will set the dX/dp = 0, so that the derivative of the output
112  // quantity is only the partial derivative wrt the parameter.
113  //
114 
115  (*mat_stiff)(pt, 0., mat0);
116 
117 
118  for (unsigned int i=0; i<v._params_for_sensitivity.size(); i++) {
119 
120  MAST::Parameter& f = *v._params_for_sensitivity[i];
121 
122  // get the analytical sensitivity
123  mat_stiff->derivative( f,
124  pt,
125  0,
126  dmatdp);
127 
128  // identify the perturbation in the parameter
129  p0 = f();
130  (fabs(p0) > 0)? dp=std::max(delta*p0, delta) : dp=delta;
131  f() += dp;
132 
133  (*mat_stiff)(pt, 0., dmat);
134 
135  // reset the parameter value
136  f() = p0;
137 
138  dmat -= mat0;
139  dmat /= dp;
140 
141  // compare and benchmark the values
142  BOOST_TEST_MESSAGE(" ** dprop/dp wrt : " << f.name() << " **");
143  BOOST_CHECK(MAST::compare_matrix ( dmat, dmatdp, tol));
144  }
145  }
146 }
147 
148 
149 BOOST_FIXTURE_TEST_SUITE (Structural1DSectionPropertyEvaluation,
151 
152 
153 BOOST_AUTO_TEST_CASE (Property1DSensitivityIndependentOffset) {
154 
155  this->init(false, false); // nonlinear strain does not influence this
156  check_material_property<MAST::BuildStructural1DElem>(*this);
157 }
158 
159 
160 BOOST_AUTO_TEST_CASE (Property1DSensitivityDependentOffset) {
161 
162  this->init(true, false); // nonlinear strain does not influence this
163  check_material_property<MAST::BuildStructural1DElem>(*this);
164 }
165 
166 
167 BOOST_AUTO_TEST_SUITE_END()
168 
169 
170 BOOST_FIXTURE_TEST_SUITE (Structural2DSectionPropertyEvaluation,
171  MAST::BuildStructural2DElem)
172 
173 
174 BOOST_AUTO_TEST_CASE (Property2DSensitivityIndependentOffsetQUAD4) {
175 
176  this->init(false, false, libMesh::QUAD4);
177  check_material_property<MAST::BuildStructural2DElem>(*this);
178 }
179 
180 
181 BOOST_AUTO_TEST_CASE (Property2DSensitivityDependentOffsetQUAD4) {
182 
183  this->init(true, false, libMesh::QUAD4);
184  check_material_property<MAST::BuildStructural2DElem>(*this);
185 }
186 
187 
188 BOOST_AUTO_TEST_CASE (Property2DSensitivityIndependentOffsetTRI3) {
189 
190  this->init(false, false, libMesh::TRI3);
191  check_material_property<MAST::BuildStructural2DElem>(*this);
192 }
193 
194 
195 BOOST_AUTO_TEST_CASE (Property2DSensitivityDependentOffsetTRI3) {
196 
197  this->init(true, false, libMesh::TRI3);
198  check_material_property<MAST::BuildStructural2DElem>(*this);
199 }
200 
201 
202 
203 BOOST_AUTO_TEST_SUITE_END()
204 
205 
const std::string & name() const
returns the name of this function
Definition: function_base.h:60
This is a scalar function whose value can be changed and one that can be used as a design variable in...
Definition: parameter.h:35
bool compare_matrix(const RealMatrixX &m0, const RealMatrixX &m, const Real tol)
libMesh::Real Real
void check_material_property(ValType &v)
Matrix< Real, Dynamic, Dynamic > RealMatrixX
std::unique_ptr< MAST::StructuralElementBase > build_structural_element(MAST::SystemInitialization &sys, const MAST::GeomElem &elem, const MAST::ElementPropertyCardBase &p)
builds the structural element for the specified element type
BOOST_AUTO_TEST_CASE(Property1DSensitivityDependentOffset)
BOOST_FIXTURE_TEST_SUITE(Structural1DSectionPropertyEvaluation, MAST::BuildStructural1DElem) BOOST_AUTO_TEST_CASE(Property1DSensitivityIndependentOffset)