PRISMS-PF  v2.1
refine.cc
Go to the documentation of this file.
1 //mesh refinement methods for MatrixFreePDE class
2 
3 #include "../../include/matrixFreePDE.h"
4 #include <deal.II/distributed/grid_refinement.h>
5 
6 //default implementation of adaptive mesh refinement
7 template <int dim, int degree>
8 void MatrixFreePDE<dim,degree>::adaptiveRefine(unsigned int currentIncrement){
9 if (userInputs.h_adaptivity == true){
10  if ( (currentIncrement == 0) ){
11  computing_timer.enter_section("matrixFreePDE: AMR");
12  unsigned int numDoF_preremesh = totalDOFs;
13  for (unsigned int remesh_index=0; remesh_index < (userInputs.max_refinement_level-userInputs.min_refinement_level); remesh_index++){
14 
15  adaptiveRefineCriterion();
16  refineGrid();
17  reinit();
18 
19  // If the mesh hasn't changed from the previous cycle, stop remeshing
20  if (totalDOFs == numDoF_preremesh) break;
21  numDoF_preremesh = totalDOFs;
22  }
23  computing_timer.exit_section("matrixFreePDE: AMR");
24  }
25  else if ( (currentIncrement%userInputs.skip_remeshing_steps==0) ){
26 
27  computing_timer.enter_section("matrixFreePDE: AMR");
28 
29  // Apply constraints before remeshing
30  for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
31  constraintsDirichletSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
32  constraintsOtherSet[fieldIndex]->distribute(*solutionSet[fieldIndex]);
33  solutionSet[fieldIndex]->update_ghost_values();
34  }
35  adaptiveRefineCriterion();
36  refineGrid();
37  reinit();
38  computing_timer.exit_section("matrixFreePDE: AMR");
39  }
40 }
41 }
42 
43 //default implementation of adaptive mesh criterion
44 template <int dim, int degree>
46  //Kelly error estimation criterion
47  //estimate cell wise errors for mesh refinement
48 //#if hAdaptivity==true
49 //#ifdef adaptivityType
50 //#if adaptivityType=="KELLY"
51 // Vector<float> estimated_error_per_cell (triangulation.n_locally_owned_active_cells());
52 // KellyErrorEstimator<dim>::estimate (*dofHandlersSet_nonconst[refinementDOF],
53 // QGaussLobatto<dim-1>(degree+1),
54 // typename FunctionMap<dim>::type(),
55 // *solutionSet[refinementDOF],
56 // estimated_error_per_cell,
57 // ComponentMask(),
58 // 0,
59 // 1,
60 // triangulation.locally_owned_subdomain());
61 // //flag cells for refinement
62 // parallel::distributed::GridRefinement::refine_and_coarsen_fixed_fraction (triangulation,
63 // estimated_error_per_cell,
64 // topRefineFraction,
65 // bottomCoarsenFraction);
66 //#endif
67 //#endif
68 //#endif
69 
70 //Custom defined estimation criterion
71 
72 std::vector<std::vector<double> > errorOutV;
73 
74 
75 QGaussLobatto<dim> quadrature(degree+1);
76 FEValues<dim> fe_values (*FESet[userInputs.refine_criterion_fields[0]], quadrature, update_values);
77 const unsigned int num_quad_points = quadrature.size();
78 
79 std::vector<double> errorOut(num_quad_points);
80 
81 typename DoFHandler<dim>::active_cell_iterator cell = dofHandlersSet_nonconst[userInputs.refine_criterion_fields[0]]->begin_active(), endc = dofHandlersSet_nonconst[userInputs.refine_criterion_fields[0]]->end();
82 
83 typename parallel::distributed::Triangulation<dim>::active_cell_iterator t_cell = triangulation.begin_active();
84 
85 for (;cell!=endc; ++cell){
86  if (cell->is_locally_owned()){
87  fe_values.reinit (cell);
88 
89  for (unsigned int field_index=0; field_index<userInputs.refine_criterion_fields.size(); field_index++){
90  fe_values.get_function_values(*solutionSet[userInputs.refine_criterion_fields[field_index]], errorOut);
91  errorOutV.push_back(errorOut);
92  }
93 
94  bool mark_refine = false;
95 
96  for (unsigned int q_point=0; q_point<num_quad_points; ++q_point){
97  for (unsigned int field_index=0; field_index<userInputs.refine_criterion_fields.size(); field_index++){
98  if ((errorOutV[field_index][q_point]>userInputs.refine_window_min[field_index]) && (errorOutV[field_index][q_point]<userInputs.refine_window_max[field_index])){
99  mark_refine = true;
100  break;
101  }
102  }
103  }
104 
105  errorOutV.clear();
106 
107  //limit the maximal and minimal refinement depth of the mesh
108  unsigned int current_level = t_cell->level();
109 
110  if ( (mark_refine && current_level < userInputs.max_refinement_level) ){
111  cell->set_refine_flag();
112  }
113  else if (!mark_refine && current_level > userInputs.min_refinement_level) {
114  cell->set_coarsen_flag();
115  }
116 
117  }
118  ++t_cell;
119 }
120 
121 }
122 
123 
124 //refine grid method
125 template <int dim, int degree>
127 
128 //prepare and refine
129 triangulation.prepare_coarsening_and_refinement();
130 for(unsigned int fieldIndex=0; fieldIndex<fields.size(); fieldIndex++){
131  // The following lines were from an earlier version.
132  // residualSet is cleared in reinit(), so I don't see the reason for the pointer assignment
133  // Changing to the new version has no impact on the solution.
134  //(*residualSet[fieldIndex])=(*solutionSet[fieldIndex]);
135  //soltransSet[fieldIndex]->prepare_for_coarsening_and_refinement(*residualSet[fieldIndex]);
136 
137  soltransSet[fieldIndex]->prepare_for_coarsening_and_refinement(*solutionSet[fieldIndex]);
138 }
139 triangulation.execute_coarsening_and_refinement();
140 
141 }
142 
143 #include "../../include/matrixFreePDE_template_instantiations.h"
void adaptiveRefine(unsigned int _currentIncrement)
Definition: refine.cc:8
virtual void adaptiveRefineCriterion()
Definition: refine.cc:45
void refineGrid()
Definition: refine.cc:126