3 #include "anisotropic_mesh_adaptation_cases.h" 4 #include "flow_solver/flow_solver_factory.h" 5 #include "mesh/mesh_adaptation/anisotropic_mesh_adaptation.h" 6 #include "mesh/mesh_adaptation/fe_values_shape_hessian.h" 7 #include <deal.II/grid/grid_in.h> 12 template <
int dim,
int nstate>
15 const dealii::ParameterHandler ¶meter_handler_input)
17 , parameter_handler(parameter_handler_input)
20 template <
int dim,
int nstate>
24 dealii::hp::MappingCollection<dim> mapping_collection(mapping);
25 const dealii::UpdateFlags update_flags = dealii::update_jacobian_pushed_forward_grads | dealii::update_inverse_jacobians;
28 dealii::MappingQGeneric<dim, dim> mapping2(dg.
high_order_grid->dof_handler_grid.get_fe().degree);
29 dealii::hp::MappingCollection<dim> mapping_collection2(mapping2);
33 for(
const auto &cell : dg.
dof_handler.active_cell_iterators())
35 if(! cell->is_locally_owned()) {
continue;}
37 const unsigned int i_fele = cell->active_fe_index();
38 const unsigned int i_quad = i_fele;
39 const unsigned int i_mapp = 0;
40 fe_values_collection_volume.
reinit(cell, i_quad, i_mapp, i_fele);
41 fe_values_collection_volume2.reinit(cell, i_quad, i_mapp, i_fele);
42 const dealii::FEValues<dim,dim> &fe_values_volume = fe_values_collection_volume.get_present_fe_values();
43 const dealii::FEValues<dim,dim> &fe_values_volume2 = fe_values_collection_volume2.get_present_fe_values();
45 const unsigned int n_dofs_cell = fe_values_volume.dofs_per_cell;
46 const unsigned int n_quad_pts = fe_values_volume.n_quadrature_points;
47 for(
unsigned int iquad = 0; iquad < n_quad_pts; ++iquad)
49 fe_values_shape_hessian.
reinit(fe_values_volume, iquad);
51 for(
unsigned int idof = 0; idof < n_dofs_cell; ++idof)
53 const unsigned int istate = fe_values_volume.get_fe().system_to_component_index(idof).first;
54 dealii::Tensor<2,dim,double> shape_hessian_dealii = fe_values_volume2.shape_hessian_component(idof, iquad, istate);
56 dealii::Tensor<2,dim,double> shape_hessian_philip = fe_values_shape_hessian.
shape_hessian_component(idof, iquad, istate, fe_values_volume.get_fe());
58 dealii::Tensor<2,dim,double> shape_hessian_diff = shape_hessian_dealii;
59 shape_hessian_diff -= shape_hessian_philip;
61 if(shape_hessian_diff.norm() > 1.0e-8)
63 std::cout<<
"Dealii's FEValues shape_hessian = "<<shape_hessian_dealii<<std::endl;
64 std::cout<<
"PHiLiP's FEValues shape_hessian = "<<shape_hessian_philip<<std::endl;
65 std::cout<<
"Frobenius norm of diff = "<<shape_hessian_diff.norm()<<std::endl;
66 std::cout<<
"Aborting.."<<std::endl<<std::flush;
73 pcout<<
"PHiLiP's physical shape hessian matches that computed by dealii."<<std::endl;
76 template <
int dim,
int nstate>
79 std::shared_ptr< Functional<dim, nstate, double> > functional
81 return (functional->evaluate_functional());
84 template <
int dim,
int nstate>
94 std::unique_ptr<AnisotropicMeshAdaptation<dim, nstate, double>> anisotropic_mesh_adaptation =
95 std::make_unique<AnisotropicMeshAdaptation<dim, nstate, double>> (flow_solver->dg, normLp, complexity, use_goal_oriented_approach);
101 for(
unsigned int cycle = 0; cycle < n_adaptation_cycles; ++cycle)
103 anisotropic_mesh_adaptation->adapt_mesh();
110 const dealii::Point<dim> coordinates_of_highest_refined_cell = flow_solver->dg->coordinates_of_highest_refined_cell(
false);
112 pcout<<
"Coordinates of highest refined cell = "<<coordinates_of_highest_refined_cell<<std::endl;
114 dealii::Point<dim> expected_coordinates_of_highest_refined_cell;
115 for(
unsigned int i=0; i < dim; ++i) {
116 expected_coordinates_of_highest_refined_cell[i] = 0.5;
118 const double distance_val = expected_coordinates_of_highest_refined_cell.distance(coordinates_of_highest_refined_cell);
119 pcout<<
"Distance to the expected coordinates of the highest refined cell = "<<distance_val<<std::endl;
122 if(distance_val < 0.1) {
return test_val;}
125 const double functional_exact = 0.5625;
126 const double error_initial = abs(functional_initial-functional_exact);
127 const double error_final = abs(functional_final-functional_exact);
129 if( !(error_final < error_initial) ) {
130 pcout<<
"Functional error has not decreased after adaptation. Test failed."<<std::endl;
131 pcout<<
"error_initial = "<<error_initial<<std::endl;
132 pcout<<
"error_final = "<<error_final<<std::endl;
dealii::Tensor< 2, dim, double > shape_hessian_component(const unsigned int idof, const unsigned int iquad, const unsigned int istate, const dealii::FESystem< dim, dim > &fe_ref) const
Evaluates hessian of shape functions w.r.t. phyical quadrature points.
Test to check anisotropic mesh adaptation.
int total_mesh_adaptation_cycles
Total/maximum number of mesh adaptation cycles while solving a problem.
Files for the baseline physics.
Main parameter class that contains the various other sub-parameter classes.
MeshAdaptationParam mesh_adaptation_param
Constains parameters for mesh adaptation.
void reinit(const dealii::FEValues< dim, dim > &fe_values_volume, const unsigned int iquad)
Store inverse jacobian and 3rd order tensors which will be the same for a combination of cell/physica...
static std::unique_ptr< FlowSolver< dim, nstate > > select_flow_case(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Factory to return the correct flow solver given input file.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
const dealii::ParameterHandler & parameter_handler
Parameter handler.
double norm_Lp_anisotropic_adaptation
Lp norm w.r.t. which the optimization is performed in the continuous mesh framework.
std::shared_ptr< HighOrderGrid< dim, real, MeshType > > high_order_grid
High order grid that will provide the MappingFEField.
Class to evaluate hessians of shape functions w.r.t. physical quadrature points.
static std::shared_ptr< Functional< dim, nstate, real, MeshType > > create_Functional(PHiLiP::Parameters::AllParameters const *const param, std::shared_ptr< PHiLiP::DGBase< dim, real, MeshType > > dg)
Create standard functional object from constant parameter file.
dealii::DoFHandler< dim > dof_handler
Finite Element Collection to represent the high-order grid.
double evaluate_functional(std::shared_ptr< DGBase< dim, double >> dg) const
Evaluates .
bool use_goal_oriented_mesh_adaptation
Flag to use goal oriented mesh adaptation.
dealii::ConditionalOStream pcout
ConditionalOStream.
AnisotropicMeshAdaptationCases(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler ¶meter_handler_input)
Constructor.
double mesh_complexity_anisotropic_adaptation
Continuous equivalent of number of vertices/elements. Used in anisotropic mesh adaptation.
DGBase is independent of the number of state variables.
void verify_fe_values_shape_hessian(const DGBase< dim, double > &dg) const
Checks PHiLiP::FEValuesShapeHessian for MappingFEField with dealii's shape hessian for MappingQGeneri...
dealii::hp::QCollection< dim > volume_quadrature_collection
Finite Element Collection to represent the high-order grid.
const dealii::hp::FECollection< dim > fe_collection
Finite Element Collection for p-finite-element to represent the solution.
Base class of all the tests.
int run_test() const
Runs the test related to anisotropic mesh adaptation.