MAST
fsi_generalized_aero_force_assembly.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
32 #include "base/nonlinear_system.h"
37 #include "numerics/utility.h"
38 #include "mesh/geom_elem.h"
39 
40 
41 // libMesh includes
42 #include "libmesh/numeric_vector.h"
43 #include "libmesh/sparse_matrix.h"
44 #include "libmesh/dof_map.h"
45 #include "libmesh/petsc_nonlinear_solver.h"
46 #include "libmesh/petsc_vector.h"
47 
48 
49 
50 
51 
54 _fluid_complex_solver (nullptr),
55 _fluid_complex_assembly (nullptr),
56 _pressure_function (nullptr),
57 _freq_domain_pressure_function (nullptr),
58 _complex_displ (nullptr)
59 { }
60 
61 
62 
63 
64 
65 
67 
68 }
69 
70 
71 
72 
73 
74 void
77  MAST::ComplexSolverBase& complex_solver,
78  MAST::ComplexAssemblyBase& complex_assembly,
80  MAST::PressureFunction& pressure_func,
81  MAST::FrequencyDomainPressureFunction& freq_pressure_func,
82  MAST::ComplexMeshFieldFunction& displ_func) {
83 
84  libmesh_assert(!_fluid_complex_solver);
85 
86  _complex_displ = &displ_func;
87  _fluid_complex_solver = &complex_solver;
88  _fluid_complex_assembly = &complex_assembly;
89  _pressure_function = &pressure_func;
90  _freq_domain_pressure_function = &freq_pressure_func;
91 
92  this->set_elem_operation_object(fsi_elem_ops);
93  complex_solver.set_assembly(complex_assembly);
94  complex_assembly.set_elem_operation_object(fluid_elem_ops);
95 }
96 
97 
98 
99 
100 void
102 
105 
106  _elem_ops = nullptr;
107  _complex_displ = nullptr;
108  _pressure_function = nullptr;
110  _fluid_complex_solver = nullptr;
111  _fluid_complex_assembly = nullptr;
112 
115 }
116 
117 
118 
119 void
122 (std::vector<libMesh::NumericVector<Real>*>& basis,
123  ComplexMatrixX& mat,
124  MAST::Parameter* p) {
125 
126  // make sure the data provided is sane
127  libmesh_assert(_complex_displ);
128 
129 
130  // also create localized solution vectos for the bassis vectors
131  unsigned int
132  n_basis = (unsigned int)basis.size();
133 
134 
135  // iterate over each element, initialize it and get the relevant
136  // analysis quantities
137  RealVectorX sol;
138  ComplexVectorX vec;
139  RealMatrixX basis_mat;
140 
141  mat.setZero(n_basis, n_basis);
142 
143  std::vector<libMesh::dof_id_type> dof_indices;
144 
145 
146  std::unique_ptr<libMesh::NumericVector<Real> >
147  localized_solution,
148  localized_zero;
149  std::vector<libMesh::NumericVector<Real>*> localized_basis(n_basis);
150 
151  if (_base_sol)
152  localized_solution.reset(build_localized_vector(_system->system(),
153  *_base_sol).release());
154 
155  for (unsigned int i=0; i<n_basis; i++)
156  localized_basis[i] = build_localized_vector(_system->system(), *basis[i]).release();
157 
158  //create a zero-clone copy for the imaginary component of the solution
159  localized_zero.reset(localized_basis[0]->zero_clone().release());
160 
161 
162  // if a solution function is attached, initialize it
163  if (_sol_function && _base_sol)
165 
167  ops = dynamic_cast<MAST::FluidStructureAssemblyElemOperations&>(*_elem_ops);
168 
169  // iterate over each structural mode to calculate the
170  // fluid small-disturbance solution
171  for (unsigned int i=0; i<n_basis; i++) {
172 
173  // set up the fluid flexible-surface boundary condition for this mode
175  _complex_displ->init(*localized_basis[i], *localized_zero);
176 
177 
178  // solve the complex smamll-disturbance fluid-equations
180 
181  // use this solution to initialize the structural boundary conditions
183 
184  // use this solution to initialize the structural boundary conditions
187  _fluid_complex_solver->real_solution(p != nullptr),
188  _fluid_complex_solver->imag_solution(p != nullptr));
189 
190 
191  const libMesh::DofMap& dof_map = _system->system().get_dof_map();
192 
193  // assemble the complex small-disturbance force vector force vector
194  libMesh::MeshBase::const_element_iterator el =
195  _system->system().get_mesh().active_local_elements_begin();
196  const libMesh::MeshBase::const_element_iterator end_el =
197  _system->system().get_mesh().active_local_elements_end();
198 
199 
200 
201  for ( ; el != end_el; ++el) {
202 
203  const libMesh::Elem* elem = *el;
204 
205  dof_map.dof_indices (elem, dof_indices);
206 
207  MAST::GeomElem geom_elem;
208  ops.set_elem_data(elem->dim(), *elem, geom_elem);
209  geom_elem.init(*elem, *_system);
210 
211  ops.init(geom_elem);
212 
213  // get the solution
214  unsigned int ndofs = (unsigned int)dof_indices.size();
215  sol.setZero(ndofs);
216  vec.setZero(ndofs);
217  basis_mat.setZero(ndofs, n_basis);
218 
219  for (unsigned int i=0; i<dof_indices.size(); i++) {
220 
221  if (_base_sol)
222  sol(i) = (*localized_solution)(dof_indices[i]);
223 
224  for (unsigned int j=0; j<n_basis; j++)
225  basis_mat(i,j) = (*localized_basis[j])(dof_indices[i]);
226  }
227 
228 
229  ops.set_elem_solution(sol);
230  sol.setZero();
231  ops.set_elem_velocity(sol); // set to zero value
232  ops.set_elem_acceleration(sol); // set to zero value
233 
234 
235 // if (_sol_function)
236 // physics_elem->attach_active_solution_function(*_sol_function);
237 
239  ops.clear_elem();
240 
241  DenseRealVector v1;
242  RealVectorX v2;
243 
244  // constrain and set the real component
245  MAST::copy(v1, vec.real());
246  dof_map.constrain_element_vector(v1, dof_indices);
247  MAST::copy(v2, v1);
248  vec.real() = v2;
249 
250  // constrain and set the imag component
251  MAST::copy(v1, vec.imag());
252  dof_map.constrain_element_vector(v1, dof_indices);
253  MAST::copy(v2, v1);
254  vec.imag() = v2;
255 
256  // project the force vector on all the structural modes for the
257  // i^th column of the generalized aerodynamic force matrix
258  mat.col(i) += basis_mat.transpose() * vec;
259 
260 // physics_elem->detach_active_solution_function();
261  }
262  }
263 
264 
265 
266  // if a solution function is attached, clear it
267  if (_sol_function)
268  _sol_function->clear();
269 
270 
271  // delete the localized basis vectors
272  for (unsigned int i=0; i<basis.size(); i++)
273  delete localized_basis[i];
274 
275  // sum the matrix and provide it to each processor
276  // this assumes that the structural comm is a subset of fluid comm
277  MAST::parallel_sum(_system->system().comm(), mat);
278 }
279 
MAST::AssemblyElemOperations * _elem_ops
provides assembly elem operations for use by this class
MAST::NonlinearSystem & system()
MAST::FrequencyDomainPressureFunction * _freq_domain_pressure_function
small disturbance pressure function boundary condition for structures
virtual void set_elem_data(unsigned int dim, const libMesh::Elem &ref_elem, MAST::GeomElem &elem) const
sets the structural element y-vector if 1D element is used.
void init(const libMesh::NumericVector< Real > &steady_sol, const libMesh::NumericVector< Real > *small_dist_sol=nullptr)
initiate the mesh function for this solution
MAST::PressureFunction * _pressure_function
pressure function boundary condition for structures
virtual void clear_elem_operation_object()
clears the association of this object with the assembly element operation object. ...
void set_assembly(MAST::ComplexAssemblyBase &assemble)
sets the assembly object for this solver
void init(MAST::FluidStructureAssemblyElemOperations &fsi_elem_ops, MAST::ComplexSolverBase &complex_solver, MAST::ComplexAssemblyBase &complex_assembly, MAST::ComplexAssemblyElemOperations &fluid_elem_ops, MAST::PressureFunction &pressure_func, MAST::FrequencyDomainPressureFunction &freq_pressure_func, MAST::ComplexMeshFieldFunction &displ_func)
initializes for the given fluid and structural components.
Matrix< Complex, Dynamic, 1 > ComplexVectorX
uses a Gauss-Siedel method to solve the complex system of equations for a system. ...
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
virtual void set_elem_operation_object(MAST::AssemblyElemOperations &elem_ops)
attaches a element operation to this object, and associated this with the element operation object...
libMesh::NumericVector< Real > & imag_solution(bool if_sens=false)
virtual void set_elem_solution(const RealVectorX &sol)
sets the element solution
MAST::SystemInitialization * _system
System for which this assembly is performed.
void clear()
clear the solution and mesh function data structures
MAST::ComplexMeshFieldFunction * _complex_displ
flexible surface motion for fluid and structure
void clear_assembly()
clears the assembly object from this solver
libMesh::DenseVector< Real > DenseRealVector
virtual void init(const MAST::GeomElem &elem)
initializes the object for the geometric element elem.
virtual void solve_block_matrix(MAST::Parameter *p=nullptr)
solves the complex system of equations using block matrices.
Matrix< Real, Dynamic, Dynamic > RealMatrixX
void parallel_sum(const libMesh::Parallel::Communicator &c, RealMatrixX &mat)
Definition: utility.h:214
Matrix< Complex, Dynamic, Dynamic > ComplexMatrixX
virtual void clear_discipline_and_system()
clears association with a system to this discipline, and vice-a-versa
void copy(DenseRealMatrix &m1, const RealMatrixX &m2)
Definition: utility.h:167
void clear()
clear the solution
Matrix< Real, Dynamic, 1 > RealVectorX
void init(const libMesh::NumericVector< Real > &steady_sol, const libMesh::NumericVector< Real > &small_dist_sol_real, const libMesh::NumericVector< Real > &small_dist_sol_imag)
initiate the mesh function for this solution
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...
This class acts as a wrapper around libMesh::Elem for the purpose of providing a uniform interface fo...
Definition: geom_elem.h:59
virtual void set_elem_velocity(const RealVectorX &vel)
sets the element velocity
virtual void assemble_generalized_aerodynamic_force_matrix(std::vector< libMesh::NumericVector< Real > * > &basis, ComplexMatrixX &mat, MAST::Parameter *p=nullptr)
calculates the reduced order matrix given the basis provided in basis.
This provides a wrapper FieldFunction compatible class that interpolates the solution using libMesh&#39;s...
void init(const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > *dsol=nullptr)
initializes the data structures to perform the interpolation function of sol.
const libMesh::NumericVector< Real > * _base_sol
base solution about which this eigenproblem is defined.
virtual void clear_elem()
clears the element initialization
virtual void init(const libMesh::Elem &elem, const MAST::SystemInitialization &sys_init)
initialize the object for the specified reference elem.
Definition: geom_elem.cpp:128
libMesh::NumericVector< Real > & real_solution(bool if_sens=false)
void init(const libMesh::NumericVector< Real > &sol_re, const libMesh::NumericVector< Real > &sol_im)
virtual void set_elem_acceleration(const RealVectorX &accel)
sets the element acceleration
virtual void clear_discipline_and_system()
clears association with a system to this discipline, and vice-a-versa
const libMesh::NumericVector< Real > & base_sol(bool if_sens=false) const
MAST::MeshFieldFunction * _sol_function
system solution that will be initialized before each solution
MAST::ComplexSolverBase * _fluid_complex_solver
complex solver