22 #include <boost/test/unit_test.hpp> 25 #include "tests/fluid/build_conservative_fluid_elem.h" 26 #include "tests/base/test_comparisons.h" 27 #include "examples/base/rigid_surface_motion.h" 34 #include "libmesh/dof_map.h" 47 libmesh_assert_equal_to(v.
_mesh->n_elem(), 1);
48 libMesh::Elem& e = **v.
_mesh->local_elements_begin();
53 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
67 const unsigned int ndofs = 16;
71 x_base =RealVectorX::Zero(ndofs);
74 x = ComplexVectorX::Zero(ndofs),
75 res0 = ComplexVectorX::Zero(ndofs),
76 res = ComplexVectorX::Zero(ndofs);
79 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
80 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
86 elem->set_velocity(x_base);
89 for (
unsigned int i=0; i<4; i++) {
90 for (
unsigned int j=0; j<4; j++) {
94 elem->set_solution(x_base);
99 elem->set_complex_solution(x);
103 elem->internal_residual(
true, res0, jac_x);
106 for (
unsigned int i=0; i<ndofs; i++) {
110 x = ComplexVectorX::Zero(ndofs);
113 elem->set_complex_solution(x);
117 elem->internal_residual(
false, res, dummy);
120 jac_x_fd.col(i) = (res-res0)/delta;
124 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Real Perturbation **");
127 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Real Perturbation **");
130 if (fabs(omega) > 0.) {
132 for (
unsigned int i=0; i<ndofs; i++) {
136 x = ComplexVectorX::Zero(ndofs);
138 x(i) += delta * iota;
139 elem->set_complex_solution(x);
143 elem->internal_residual(
false, res, dummy);
146 jac_x_fd.col(i) = (res-res0)/delta/iota;
150 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Imaginary Perturbation **");
153 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Imaginary Perturbation **");
167 libmesh_assert_equal_to(v.
_mesh->n_elem(), 1);
168 libMesh::Elem& e = **v.
_mesh->local_elements_begin();
173 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
188 const unsigned int ndofs = 16;
192 x_base =RealVectorX::Zero(ndofs);
195 x = ComplexVectorX::Zero(ndofs),
196 res0 = ComplexVectorX::Zero(ndofs),
197 res = ComplexVectorX::Zero(ndofs);
200 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
201 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
206 bc_map.insert(std::pair<libMesh::boundary_id_type, MAST::BoundaryConditionBase*>
210 elem->set_velocity(x_base);
213 for (
unsigned int i=0; i<4; i++) {
214 for (
unsigned int j=0; j<4; j++) {
218 elem->set_solution(x_base);
223 elem->set_complex_solution(x);
227 elem->side_external_residual(
true, res0, jac_x, bc_map);
230 for (
unsigned int i=0; i<ndofs; i++) {
234 x = ComplexVectorX::Zero(ndofs);
237 elem->set_complex_solution(x);
241 elem->side_external_residual(
false, res, dummy, bc_map);
244 jac_x_fd.col(i) = (res-res0)/delta;
248 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Real Perturbation **");
251 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Real Perturbation **");
256 if (fabs(omega) > 0.) {
257 for (
unsigned int i=0; i<ndofs; i++) {
261 x = ComplexVectorX::Zero(ndofs);
264 elem->set_complex_solution(x);
268 elem->side_external_residual(
false, res, dummy, bc_map);
271 jac_x_fd.col(i) = (res-res0)/delta/iota;
275 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Imaginary Perturbation **");
278 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Imaginary Perturbation **");
292 libmesh_assert_equal_to(v.
_mesh->n_elem(), 1);
293 libMesh::Elem& e = **v.
_mesh->local_elements_begin();
298 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
311 const unsigned int ndofs = 16;
315 x_base =RealVectorX::Zero(ndofs);
318 x = ComplexVectorX::Zero(ndofs),
319 res0 = ComplexVectorX::Zero(ndofs),
320 res = ComplexVectorX::Zero(ndofs);
323 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
324 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
329 bc_map.insert(std::pair<libMesh::boundary_id_type, MAST::BoundaryConditionBase*>
333 elem->set_velocity(x_base);
336 for (
unsigned int i=0; i<4; i++) {
337 for (
unsigned int j=0; j<4; j++) {
341 elem->set_solution(x_base);
346 elem->set_complex_solution(x);
350 elem->side_external_residual(
true, res0, jac_x, bc_map);
353 for (
unsigned int i=0; i<ndofs; i++) {
357 x = ComplexVectorX::Zero(ndofs);
360 elem->set_complex_solution(x);
364 elem->side_external_residual(
false, res, dummy, bc_map);
367 jac_x_fd.col(i) = (res-res0)/delta;
371 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Real Perturbation**");
374 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Real Perturbation**");
379 if (fabs(omega) > 0.) {
381 for (
unsigned int i=0; i<ndofs; i++) {
385 x = ComplexVectorX::Zero(ndofs);
387 x(i) += delta * iota;
388 elem->set_complex_solution(x);
392 elem->side_external_residual(
false, res, dummy, bc_map);
395 jac_x_fd.col(i) = (res-res0)/delta/iota;
399 BOOST_TEST_MESSAGE(
"** Checking Real Part of Jacobian with Imaginary Perturbation **");
402 BOOST_TEST_MESSAGE(
"** Checking Imaginary Part of Jacobian with Imaginary Perturbation **");
458 libmesh_assert_equal_to(_mesh->n_elem(), 1);
459 libMesh::Elem& e = **_mesh->local_elements_begin();
464 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
466 elem->freq = _freq_function;
467 elem->sensitivity_param = _omega;
479 const unsigned int ndofs = 16;
483 x_base =RealVectorX::Zero(ndofs);
486 x = ComplexVectorX::Zero(ndofs),
487 res0 = ComplexVectorX::Zero(ndofs),
488 res_sens = ComplexVectorX::Zero(ndofs),
489 res_sens_fd = ComplexVectorX::Zero(ndofs);
492 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
493 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
499 elem->set_velocity(x_base);
502 for (
unsigned int i=0; i<4; i++) {
503 for (
unsigned int j=0; j<4; j++) {
504 x_base(i*4+j) = _base_sol(i);
507 elem->set_solution(x_base);
512 elem->set_complex_solution(x);
513 elem->set_complex_solution(x,
true);
517 elem->internal_residual(
true, res0, jac_x);
520 elem->internal_residual_sensitivity(
false, res_sens, dummy);
523 *_omega = ((1. + delta) * (*_omega)());
525 elem->internal_residual(
false, res_sens_fd, dummy);
527 res_sens_fd /= delta;
530 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
533 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
544 bc_map.insert(std::pair<libMesh::boundary_id_type, MAST::BoundaryConditionBase*>
549 libmesh_assert_equal_to(_mesh->n_elem(), 1);
550 libMesh::Elem& e = **_mesh->local_elements_begin();
555 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
557 elem->freq = _freq_function;
558 elem->sensitivity_param = _omega;
570 const unsigned int ndofs = 16;
574 x_base =RealVectorX::Zero(ndofs);
577 x = ComplexVectorX::Zero(ndofs),
578 res0 = ComplexVectorX::Zero(ndofs),
579 res_sens = ComplexVectorX::Zero(ndofs),
580 res_sens_fd = ComplexVectorX::Zero(ndofs);
583 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
584 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
590 elem->set_velocity(x_base);
593 for (
unsigned int i=0; i<4; i++) {
594 for (
unsigned int j=0; j<4; j++) {
595 x_base(i*4+j) = _base_sol(i);
598 elem->set_solution(x_base);
603 elem->set_complex_solution(x);
604 elem->set_complex_solution(x,
true);
608 elem->side_external_residual(
true, res0, jac_x, bc_map);
611 elem->side_external_residual_sensitivity(
false, res_sens, dummy, bc_map);
614 *_omega = ((1. + delta) * (*_omega)());
616 elem->side_external_residual(
false, res_sens_fd, dummy, bc_map);
618 res_sens_fd /= delta;
621 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
624 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
636 bc_map.insert(std::pair<libMesh::boundary_id_type, MAST::BoundaryConditionBase*>
641 libmesh_assert_equal_to(_mesh->n_elem(), 1);
642 libMesh::Elem& e = **_mesh->local_elements_begin();
647 std::unique_ptr<MAST::FrequencyDomainLinearizedConservativeFluidElem>
649 elem->freq = _freq_function;
650 elem->sensitivity_param = _omega;
662 const unsigned int ndofs = 16;
666 x_base =RealVectorX::Zero(ndofs);
669 x = ComplexVectorX::Zero(ndofs),
670 res0 = ComplexVectorX::Zero(ndofs),
671 res_sens = ComplexVectorX::Zero(ndofs),
672 res_sens_fd = ComplexVectorX::Zero(ndofs);
675 jac_x = ComplexMatrixX::Zero(ndofs, ndofs),
676 jac_x_fd = ComplexMatrixX::Zero(ndofs, ndofs),
682 elem->set_velocity(x_base);
685 for (
unsigned int i=0; i<4; i++) {
686 for (
unsigned int j=0; j<4; j++) {
687 x_base(i*4+j) = _base_sol(i);
690 elem->set_solution(x_base);
695 elem->set_complex_solution(x);
696 elem->set_complex_solution(x,
true);
700 elem->side_external_residual(
true, res0, jac_x, bc_map);
703 elem->side_external_residual_sensitivity(
false, res_sens, dummy, bc_map);
706 *_omega = ((1. + delta) * (*_omega)());
708 elem->side_external_residual(
false, res_sens_fd, dummy, bc_map);
710 res_sens_fd /= delta;
713 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
716 BOOST_TEST_MESSAGE(
"** Checking Real Part of Internal Residual Sensitivity **");
721 BOOST_AUTO_TEST_SUITE_END()
MAST::ConservativeFluidDiscipline * _discipline
MAST::BoundaryConditionBase * _far_field
void check_moving_wall_jacobian(MAST::BuildConservativeFluidElem &v, Real omega)
Matrix< Complex, Dynamic, 1 > ComplexVectorX
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)
MAST::ConservativeFluidSystemInitialization * _fluid_sys
std::multimap< libMesh::boundary_id_type, MAST::BoundaryConditionBase * > SideBCMapType
MAST::FrequencyFunction * _freq_function
frequency object
libMesh::ParallelMesh * _mesh
Matrix< Complex, Dynamic, Dynamic > ComplexMatrixX
BOOST_AUTO_TEST_CASE(InternalForceJacobianZeroFreq)
Matrix< Real, Dynamic, 1 > RealVectorX
MAST::BoundaryConditionBase * _slip_wall
void check_internal_force_jacobian(MAST::BuildConservativeFluidElem &v, Real omega)
void check_far_field_jacobian(MAST::BuildConservativeFluidElem &v, Real omega)