MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
check_fluid_eigenvectors.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 #define BOOST_TEST_DYN_LINK
22 #define BOOST_TEST_MODULE MAST_TESTS
23 #include <boost/test/unit_test.hpp>
24 
25 
26 // C++ includes
27 #include <memory>
28 #include <vector>
29 
30 // MAST includes
31 #include "base/mast_data_types.h"
32 
33 // libMesh includes
34 #include "libmesh/libmesh.h"
35 
36 
37 libMesh::LibMeshInit *_libmesh_init = nullptr;
38 const Real _frac = 1.e-6;
39 const Real _delta = 1.e-6;
40 const Real _tol = 1.e-6;
41 
42 struct GlobalTestFixture {
43 
45 
46  // create the libMeshInit function
48  new libMesh::LibMeshInit(boost::unit_test::framework::master_test_suite().argc,
49  boost::unit_test::framework::master_test_suite().argv);
50  }
51 
53 
54  delete _libmesh_init;
55  }
56 
57 };
58 
59 
60 #if BOOST_VERSION > 106100
61 BOOST_TEST_GLOBAL_FIXTURE( GlobalTestFixture );
62 #else
64 #endif
65 
66 
67 
68 // Test includes
70 #include "base/test_comparisons.h"
71 
72 
73 BOOST_FIXTURE_TEST_SUITE(ConservativeFluidElemEigenvectors, BuildFluidElem)
74 
75 
76 // sensitivity wrt rho is all zero. Hence, the first one tested is wrt u1
77 BOOST_AUTO_TEST_CASE(Eigenvectors) {
78 
79  this->init(false);
80 
82 
83  libMesh::Point
84  nvec;
85 
87  eig_vals_from_vec = RealVectorX::Zero(this->_dim+2),
88  eig_vals = RealVectorX::Zero(this->_dim+2);
89 
91  tmp = RealMatrixX::Zero(this->_dim+2, this->_dim+2),
92  jac = RealMatrixX::Zero(this->_dim+2, this->_dim+2),
93  l_eig_mat = RealMatrixX::Zero(this->_dim+2, this->_dim+2),
94  l_eig_mat_inv_tr = RealMatrixX::Zero(this->_dim+2, this->_dim+2);
95 
96  std::vector<RealMatrixX>
97  jacx(this->_dim);
98 
99  this->init_primitive_sol(p_sol);
100 
101  for (unsigned int i=0; i<this->_dim; i++) {
102 
103  jacx[i] = RealMatrixX::Zero(this->_dim+2, this->_dim+2);
104  this->_fluid_elem->calculate_advection_flux_jacobian(i, p_sol, jacx[i]);
105  }
106 
107  for (unsigned int i=0; i<this->_dim; i++) {
108 
109  // zero all values
110  nvec.zero();
111  jac.setZero();
112  eig_vals.setZero();
113  l_eig_mat.setZero();
114  l_eig_mat_inv_tr.setZero();
115 
116  nvec(i) = 1;
117 
118  for (unsigned int j=0 ; j<this->_dim; j++) {
119  jac += nvec(j) * jacx[j];
120  }
121 
122  this->_fluid_elem->calculate_advection_left_eigenvector_and_inverse_for_normal
123  (p_sol, nvec, eig_vals, l_eig_mat, l_eig_mat_inv_tr);
124 
125  // compare eigenvalues
126  tmp = l_eig_mat.transpose() * jac * l_eig_mat_inv_tr;
127  BOOST_CHECK(MAST::compare_vector(eig_vals, tmp.diagonal(), _tol));
128 
129  // compare the jacobian reconstruction
130  for (unsigned int j=0; j<l_eig_mat_inv_tr.cols(); j++)
131  l_eig_mat_inv_tr.col(j) *= eig_vals(j);
132  tmp = l_eig_mat_inv_tr * l_eig_mat.transpose();
133  BOOST_CHECK(MAST::compare_matrix(jac, tmp, _tol));
134  }
135 }
136 
137 BOOST_AUTO_TEST_SUITE_END()
const Real _delta
Class defines the conversion and some basic operations on primitive fluid variables used in calculati...
bool compare_vector(const RealVectorX &v0, const RealVectorX &v, const Real tol)
BOOST_FIXTURE_TEST_SUITE(PanelSmallDisturbanceFrequencyDomain2D, MAST::PanelInviscidSmallDisturbanceFrequencyDomain2DAnalysis) BOOST_AUTO_TEST_CASE(FreqDomainSensitivityWrtOmega)
bool compare_matrix(const RealMatrixX &m0, const RealMatrixX &m, const Real tol)
libMesh::Real Real
BOOST_GLOBAL_FIXTURE(GlobalTestFixture)
const Real _tol
Matrix< Real, Dynamic, Dynamic > RealMatrixX
libMesh::LibMeshInit * _libmesh_init
Matrix< Real, Dynamic, 1 > RealVectorX
BOOST_AUTO_TEST_CASE(Eigenvectors)
const Real _frac