[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
grid_refinement_continuous.cpp
1 #include <deal.II/grid/grid_out.h>
2 #include <deal.II/grid/grid_in.h>
3 
4 #include <deal.II/numerics/vector_tools.h>
5 
6 #include "grid_refinement/gmsh_out.h"
7 #include "grid_refinement/msh_out.h"
8 #include "grid_refinement/size_field.h"
9 #include "grid_refinement/reconstruct_poly.h"
10 #include "grid_refinement/field.h"
11 
12 #include "grid_refinement_continuous.h"
13 
14 namespace PHiLiP {
15 
16 namespace GridRefinement {
17 
18 // Function class to rezero the solution on grid read
19 template <int dim, int nstate>
20 class InitialConditions : public dealii::Function<dim>
21 {
22 public:
23  InitialConditions() : dealii::Function<dim,double>(nstate){}
24 
25  double value(const dealii::Point<dim> &/* point */, const unsigned int /* istate */) const override
26  {
27  return 0.0;
28  }
29 };
30 
31 template <int dim, int nstate, typename real, typename MeshType>
34  std::shared_ptr< PHiLiP::Adjoint<dim, nstate, real, MeshType> > adj_input,
35  std::shared_ptr< PHiLiP::Physics::PhysicsBase<dim,nstate,real> > physics_input) :
36  GridRefinement_Continuous<dim,nstate,real,MeshType>(
37  gr_param_input,
38  adj_input,
39  adj_input->functional,
40  adj_input->dg,
41  physics_input){}
42 
43 template <int dim, int nstate, typename real, typename MeshType>
46  std::shared_ptr< PHiLiP::DGBase<dim, real, MeshType> > dg_input,
47  std::shared_ptr< PHiLiP::Physics::PhysicsBase<dim,nstate,real> > physics_input,
48  std::shared_ptr< PHiLiP::Functional<dim, nstate, real, MeshType> > functional_input) :
49  GridRefinement_Continuous<dim,nstate,real,MeshType>(
50  gr_param_input,
51  nullptr,
52  functional_input,
53  dg_input,
54  physics_input){}
55 
56 template <int dim, int nstate, typename real, typename MeshType>
59  std::shared_ptr< PHiLiP::DGBase<dim, real, MeshType> > dg_input,
60  std::shared_ptr< PHiLiP::Physics::PhysicsBase<dim,nstate,real> > physics_input) :
61  GridRefinement_Continuous<dim,nstate,real,MeshType>(
62  gr_param_input,
63  nullptr,
64  nullptr,
65  dg_input,
66  physics_input){}
67 
68 template <int dim, int nstate, typename real, typename MeshType>
71  // PHiLiP::Parameters::AllParameters const *const param_input,
72  std::shared_ptr< PHiLiP::DGBase<dim, real, MeshType> > dg_input) :
73  GridRefinement_Continuous<dim,nstate,real,MeshType>(
74  gr_param_input,
75  nullptr,
76  nullptr,
77  dg_input,
78  nullptr){}
79 
80 template <int dim, int nstate, typename real, typename MeshType>
83  std::shared_ptr< PHiLiP::Adjoint<dim, nstate, real, MeshType> > adj_input,
84  std::shared_ptr< PHiLiP::Functional<dim, nstate, real, MeshType> > functional_input,
85  std::shared_ptr< PHiLiP::DGBase<dim, real, MeshType> > dg_input,
86  std::shared_ptr< PHiLiP::Physics::PhysicsBase<dim,nstate,real> > physics_input) :
87  GridRefinementBase<dim,nstate,real,MeshType>(
88  gr_param_input,
89  adj_input,
90  functional_input,
91  dg_input,
92  physics_input)
93 {
94  std::cout << "Initializing grid_refinement with anisotropic = " << this->grid_refinement_param.anisotropic << std::endl;
95 
96  // sets the Field to default to either anisotropic or isotropic field
98  h_field = std::make_unique<FieldAnisotropic<dim,real>>();
99  }else{
100  h_field = std::make_unique<FieldIsotropic<dim,real>>();
101  }
102 
103  // set the initial complexity
105 
106  // copy the complexity vector (if any) from the parameters
108 
109  // adds first element if none hav been yet
110  complexity_vector.push_back(
111  complexity_initial
113  + this->grid_refinement_param.complexity_add);
114 
115  // set the intial target
117 }
118 
119 template <int dim, int nstate, typename real, typename MeshType>
121 {
123  RefinementTypeEnum refinement_type = this->grid_refinement_param.refinement_type;
124 
125  // store the previous solution space
126 
127  // compute the necessary size fields
128  field();
129 
130  // generate a new grid
131  if(refinement_type == RefinementTypeEnum::h){
132  refine_grid_h();
133  }else if(refinement_type == RefinementTypeEnum::p){
134  refine_grid_p();
135  }else if(refinement_type == RefinementTypeEnum::hp){
136  refine_grid_hp();
137  }
138 
139  // reinitialize the dg object with new coarse triangulation
140  this->dg->reinit();
141 
142  // interpolate the solution from the previous solution space
143  this->dg->allocate_system();
144 
145  // zeroing the solution
146  std::shared_ptr<dealii::Function<dim>> initial_conditions =
147  std::make_shared<InitialConditions<dim,nstate>>();
148 
149  dealii::LinearAlgebra::distributed::Vector<double> solution_no_ghost;
150  solution_no_ghost.reinit(this->dg->locally_owned_dofs, MPI_COMM_WORLD);
151  const auto mapping = *(this->dg->high_order_grid->mapping_fe_field);
152  dealii::VectorTools::interpolate(mapping, this->dg->dof_handler, *initial_conditions, solution_no_ghost);
153  this->dg->solution = solution_no_ghost;
154 
155  // increase the count
156  this->iteration++;
157 }
158 
159 template <int dim, int nstate, typename real, typename MeshType>
161 {
163  OutputType output_type = this->grid_refinement_param.output_type;
164 
165  // selecting the output type
166  if(output_type == OutputType::gmsh_out){
168  }else if(output_type == OutputType::msh_out){
169  refine_grid_msh();
170  }
171 
172 }
173 
174 template <int dim, int nstate, typename real, typename MeshType>
176 {
177  // physical grid stays the same, apply the update to the p_field
178  for(auto cell = this->dg->dof_handler.begin_active(); cell != this->dg->dof_handler.end(); ++cell)
179  if(cell->is_locally_owned())
180  cell->set_future_fe_index(round(p_field[cell->active_cell_index()]));
181 }
182 
183 template <int dim, int nstate, typename real, typename MeshType>
185 {
186  // NOT IMPLEMENTED
187  assert(0);
188 
189  // make a copy of the old grid and build a P1 continuous solution averaged at each of the nodes
190  // new P will be the weighted average of the integral over the new cell
191 }
192 
193 template <int dim, int nstate, typename real, typename MeshType>
195 {
196  const int iproc = dealii::Utilities::MPI::this_mpi_process(this->mpi_communicator);
197 
198  // now outputting this new field
199  std::string write_posname = "grid-" +
200  dealii::Utilities::int_to_string(this->iteration, 4) + "." +
201  dealii::Utilities::int_to_string(iproc, 4) + ".pos";
202  std::ofstream outpos(write_posname);
203 
204  // check for anisotropy
206  // polynomial order from max
207  const int poly_degree = this->dg->get_max_fe_degree();
208 
209  // using an anisotropic BAMG with merge
211  *(this->tria),
212  this->h_field->get_inverse_quadratic_metric_vector(),
213  outpos,
214  poly_degree);
215  }else{
216  // using a frontal approach to quad generation
218  *(this->tria),
219  this->h_field->get_scale_vector_dealii(),
220  outpos);
221  }
222 
223  // writing the geo file on the 1st processor and running
224  std::string output_name = "grid-" +
225  dealii::Utilities::int_to_string(this->iteration, 4) + ".msh";
226  if(iproc == 0){
227  // generating a vector of pos file names
228  std::vector<std::string> posname_vec;
229  for(unsigned int iproc = 0; iproc < dealii::Utilities::MPI::n_mpi_processes(this->mpi_communicator); ++iproc)
230  posname_vec.push_back("grid-" +
231  dealii::Utilities::int_to_string(this->iteration, 4) + "." +
232  dealii::Utilities::int_to_string(iproc, 4) + ".pos");
233 
234  std::string write_geoname = "grid-" +
235  dealii::Utilities::int_to_string(this->iteration, 4) + ".geo";
236  std::ofstream outgeo(write_geoname);
237 
238  // check for anisotropy
240  // using an anisotropic BAMG with merge
242  posname_vec,
243  outgeo);
244  }else{
245  // using a frontal approach to quad generation
247  posname_vec,
248  outgeo);
249  }
250 
251  // run gmsh with check for non-availibility
252  if(!GmshOut<dim,real>::call_gmsh(write_geoname, output_name))
253  return;
254  }
255 
256  // barrier
257  MPI_Barrier(this->mpi_communicator);
258 
259  // loading the mesh on all processors
260  this->tria->clear();
261  dealii::GridIn<dim> gridin;
262  gridin.attach_triangulation(*(this->tria));
263  std::ifstream f(output_name);
264  gridin.read_msh(f);
265 }
266 
267 template <int dim, int nstate, typename real, typename MeshType>
269 {
270  // geting the data output type
272  OutputDataType output_data_type = this->grid_refinement_param.output_data_type;
273 
274  // storage type for format of data vector
275  using StorageType = PHiLiP::GridRefinement::StorageType;
276  StorageType storage_type = StorageType::element;
277 
278  // file name and output file stream
279  std::string write_msh_name = "grid-a" +
280  dealii::Utilities::int_to_string(this->iteration, 4) + ".msh";
281 
282  std::ofstream out_msh(write_msh_name);
283 
284  // setting up output handler
285  PHiLiP::GridRefinement::MshOut<dim,real> msh_out(this->dg->dof_handler);
286 
287  // writing the field to output (if uncommented)
288  // std::cout << *(this->h_field) << std::endl;
289 
290  if(output_data_type == OutputDataType::size_field){
291  // outputting the h_field size (no orientation), single value
292  std::cout << "Writing the size_field to .msh file." << std::endl;
293 
294  // adding data to output
295  msh_out.add_data_vector(this->h_field->get_scale_vector(),
296  storage_type,
297  "size_field");
298 
299  }else if(output_data_type == OutputDataType::frame_field){
300  // outputting the h_field frame vectors (d, 1xd vectors)
301  std::cout << "Writing the frame_field to .msh file." << std::endl;
302 
303  // adding data to output
304  for(unsigned int j = 0; j < dim; ++j)
305  msh_out.add_data_vector(this->h_field->get_axis_vector(j),
306  storage_type,
307  "frame_field_" + std::to_string(j));
308 
309 
310  }else if(output_data_type == OutputDataType::metric_field){
311  // outputting the h_field using metric representation (dxd matrix)
312  std::cout << "Writing the metric_field to .msh file." << std::endl;
313 
314  // adding data to output
315  msh_out.add_data_vector(this->h_field->get_inverse_metric_vector(),
316  storage_type,
317  "Vinv");
318 
319  // msh_out.add_data_vector(this->h_field->get_metric_vector(),
320  // storage_type,
321  // "metric_field");
322 
323  // // for testing
324  // std::vector<dealii::SymmetricTensor<2,dim,real>> quadratic_metric_sym = this->h_field->get_quadratic_metric_vector();
325  // std::vector<dealii::Tensor<2,dim,real>> quadratic_metric;
326 
327  // quadratic_metric.reserve(quadratic_metric_sym.size());
328  // for(auto metric: quadratic_metric_sym)
329  // quadratic_metric.push_back(metric);
330 
331  // msh_out.add_data_vector(quadratic_metric,
332  // storage_type,
333  // "metric_field_sym");
334 
335  }
336 
337  // writing the msh file
338  msh_out.write_msh(out_msh);
339 
340  // full cycle-not yet implemented
341  std::cout << ".msh file written. (" << "/" << write_msh_name << ")" << std::endl;
342 
343  // allow to continue only if it will exit immediately afterwards
345  {
346  std::cout << "refine_grid_msh: read not supported, proceeding to results." << std::endl;
347  }else{
348  std::cout << "refine_grid_msh: read not supported, use option exit_after_refine to stop after .msh write." << std::endl;
349  throw;
350  }
351 }
352 
353 template <int dim, int nstate, typename real, typename MeshType>
355 {
358  RefinementTypeEnum refinement_type = this->grid_refinement_param.refinement_type;
359 
360  // updating the target complexity for this iteration
362 
363  // compute the necessary size fields
364  if(refinement_type == RefinementTypeEnum::h){
365  // mesh size and shape
366  if(this->error_indicator_type == ErrorIndicatorEnum::error_based){
367  field_h_error();
368  }else if(this->error_indicator_type == ErrorIndicatorEnum::hessian_based){
369  field_h_hessian();
370  }else if(this->error_indicator_type == ErrorIndicatorEnum::residual_based){
372  }else if(this->error_indicator_type == ErrorIndicatorEnum::adjoint_based){
373  field_h_adjoint();
374  }
375  }else if(refinement_type == RefinementTypeEnum::p){
376  // polynomial order distribution
377  if(this->error_indicator_type == ErrorIndicatorEnum::error_based){
378  field_p_error();
379  }else if(this->error_indicator_type == ErrorIndicatorEnum::hessian_based){
380  field_p_hessian();
381  }else if(this->error_indicator_type == ErrorIndicatorEnum::residual_based){
383  }else if(this->error_indicator_type == ErrorIndicatorEnum::adjoint_based){
384  field_p_adjoint();
385  }
386  }else if(refinement_type == RefinementTypeEnum::hp){
387  // combined refinement methods
388  if(this->error_indicator_type == ErrorIndicatorEnum::error_based){
389  field_hp_error();
390  }else if(this->error_indicator_type == ErrorIndicatorEnum::hessian_based){
392  }else if(this->error_indicator_type == ErrorIndicatorEnum::residual_based){
394  }else if(this->error_indicator_type == ErrorIndicatorEnum::adjoint_based){
396  }
397  }
398 }
399 
400 template <int dim, int nstate, typename real, typename MeshType>
402 {
403  // if the complexity vector needs to be expanded
404  while(complexity_vector.size() <= this->iteration)
405  complexity_vector.push_back(
406  complexity_vector.back()
409 
410  // copy the current iteration into the complexity target
412 
413  std::cout << "Complexity target = " << complexity_target << std::endl;
414 }
415 
416 template <int dim, int nstate, typename real, typename MeshType>
418 {
419  real complexity_sum;
420 
421  // two possible cases
422  if(this->dg->get_min_fe_degree() == this->dg->get_max_fe_degree()){
423  // case 1: uniform p-order, complexity relates to total dof
424  unsigned int poly_degree = this->dg->get_min_fe_degree();
425  return pow(poly_degree+1, dim) * this->tria->n_global_active_cells();
426  }else{
427  // case 2: non-uniform p-order, complexity related to the local sizes
428  for(auto cell = this->dg->dof_handler.begin_active(); cell != this->dg->dof_handler.end(); ++cell)
429  if(cell->is_locally_owned())
430  complexity_sum += pow(cell->active_fe_index()+1, dim);
431  }
432 
433  return dealii::Utilities::MPI::sum(complexity_sum, MPI_COMM_WORLD);
434 }
435 
436 template <int dim, int nstate, typename real, typename MeshType>
438 {
439  // gets the current size and copy it into field_h
440  // for isotropic, sets the size to be the h = volume ^ (1/dim)
441  this->h_field->reinit(this->tria->n_active_cells());
442  for(auto cell = this->dg->dof_handler.begin_active(); cell != this->dg->dof_handler.end(); ++cell)
443  if(cell->is_locally_owned())
444  this->h_field->set_scale(cell->active_cell_index(), pow(cell->measure(), 1.0/dim));
445 }
446 
447 template <int dim, int nstate, typename real, typename MeshType>
449 {
450  // gets the current polynomiala distribution and copies it into field_p
451  p_field.reinit(this->tria->n_active_cells());
452  for(auto cell = this->dg->dof_handler.begin_active(); cell != this->dg->dof_handler.end(); ++cell)
453  if(cell->is_locally_owned())
454  this->p_field[cell->active_cell_index()] = cell->active_fe_index();
455 }
456 
457 template <int dim, int nstate, typename real, typename MeshType>
459 {
460  real q = 2.0;
461 
462  dealii::Vector<real> B(this->tria->n_active_cells());
463  for(auto cell = this->dg->dof_handler.begin_active(); cell != this->dg->dof_handler.end(); ++cell){
464  if(!cell->is_locally_owned()) continue;
465 
466  // getting the central coordinate as average of vertices
467  dealii::Point<dim,real> center_point = cell->center();
468 
469  // evaluating the Hessian at this point (using default state)
470  dealii::SymmetricTensor<2,dim,real> hessian =
471  this->physics->manufactured_solution_function->hessian(center_point);
472 
473  // assuming 2D for now
474  // TODO: check generalization of this for different dimensions with eigenvalues
475  if(dim == 2)
476  B[cell->active_cell_index()] =
477  pow(abs(hessian[0][0]*hessian[1][1] - hessian[0][1]*hessian[1][0]), q/2);
478  }
479 
480  // checking if the polynomial order is uniform
481  if(this->dg->get_min_fe_degree() == this->dg->get_max_fe_degree()){
482  unsigned int poly_degree = this->dg->get_min_fe_degree();
483 
484  // building error based on exact hessian
486  this->complexity_target,
487  B,
488  this->dg->dof_handler,
489  this->h_field,
490  poly_degree);
491 
492  }else{
493  // call the non-uniform hp-version without the p-update
495 
496  // mapping
497  const dealii::hp::MappingCollection<dim> mapping_collection(*(this->dg->high_order_grid->mapping_fe_field));
498 
500  this->complexity_target,
501  B,
502  this->dg->dof_handler,
503  mapping_collection,
504  this->dg->fe_collection,
505  this->dg->volume_quadrature_collection,
506  this->volume_update_flags,
507  this->h_field,
508  this->p_field);
509 
510  }
511 }
512 
513 template <int dim, int nstate, typename real, typename MeshType>
515 {
516  // NOT IMPLEMENTED
517  assert(0);
518 }
519 template <int dim, int nstate, typename real, typename MeshType>
521 {
522  // NOT IMPLEMENTED
523  assert(0);
524 }
525 
526 template <int dim, int nstate, typename real, typename MeshType>
528 {
529  // beginning h_field computation
530  std::cout << "Beggining field_h() computation" << std::endl;
531 
532  // mapping
533  const dealii::hp::MappingCollection<dim> mapping_collection(*(this->dg->high_order_grid->mapping_fe_field));
534 
535  // using p+1 reconstruction
536  const unsigned int rel_order = 1;
537 
538  // construct object to reconstruct the derivatives onto A
539  ReconstructPoly<dim,nstate,real> reconstruct_poly(
540  this->dg->dof_handler,
541  mapping_collection,
542  this->dg->fe_collection,
543  this->dg->volume_quadrature_collection,
544  this->volume_update_flags);
545 
546  // constructing the largest directional derivatives
547  reconstruct_poly.reconstruct_directional_derivative(
548  this->dg->solution,
549  rel_order);
550  // reconstruct_poly.reconstruct_manufactured_derivative(
551  // this->physics->manufactured_solution_function,
552  // rel_order);
553 
554  // if anisotropic, setting the cell anisotropy
556  std::cout << "Setting cell anisotropy" << std::endl;
557 
558  // builds the anisotropy from Dolejsi's anisotropic ellipse size
559  this->h_field->set_anisotropy(
560  this->dg->dof_handler,
561  reconstruct_poly.derivative_value,
562  reconstruct_poly.derivative_direction,
563  rel_order);
564 
565  std::cout << "Applying anisotropy limits: \\rho = [" <<
567  this->grid_refinement_param.anisotropic_ratio_max << "]" << std::endl;
568 
569  this->h_field->apply_anisotropic_limit(
571  this->grid_refinement_param.anisotropic_ratio_max);
572 
573  }
574 
575  // vector to store the results for local scaling parameter
576  dealii::Vector<real> B(this->tria->n_active_cells());
577 
578  // looping over the vector and taking the product of the eigenvalues as the size measure
579  for(auto cell = this->dg->dof_handler.begin_active(); cell < this->dg->dof_handler.end(); ++cell)
580  if(cell->is_locally_owned()){
581  B[cell->active_cell_index()] = 1.0;
582  for(unsigned int d = 0; d < dim; ++d)
583  B[cell->active_cell_index()] *= reconstruct_poly.derivative_value[cell->active_cell_index()][d];
584  }
585 
586  // setting the current p-field
587 
588  // TODO: perform the call to calculate the continuous size field
589 
590  // checking if the polynomial order is uniform
591  if(this->dg->get_min_fe_degree() == this->dg->get_max_fe_degree()){
592  unsigned int poly_degree = this->dg->get_min_fe_degree();
593 
595  this->complexity_target,
596  B,
597  this->dg->dof_handler,
598  this->h_field,
599  poly_degree);
600 
601  }else{
602  // the case of non-uniform p
604 
606  this->complexity_target,
607  B,
608  this->dg->dof_handler,
609  mapping_collection,
610  this->dg->fe_collection,
611  this->dg->volume_quadrature_collection,
612  this->volume_update_flags,
613  this->h_field,
614  this->p_field);
615 
616  }
617 }
618 
619 template <int dim, int nstate, typename real, typename MeshType>
621 {
622  // NOT IMPLEMENTED
623  assert(0);
624 }
625 template <int dim, int nstate, typename real, typename MeshType>
627 {
628  // NOT IMPLEMENTED
629  assert(0);
630 }
631 
632 template <int dim, int nstate, typename real, typename MeshType>
634 {
635  // NOT IMPLEMENTED
636  assert(0);
637 }
638 template <int dim, int nstate, typename real, typename MeshType>
640 {
641  // NOT IMPLEMENTED
642  assert(0);
643 }
644 template <int dim, int nstate, typename real, typename MeshType>
646 {
647  // NOT IMPLEMENTED
648  assert(0);
649 }
650 
651 template <int dim, int nstate, typename real, typename MeshType>
653 {
654  // beginning h_field computation
655  std::cout << "Beggining anisotropic field_h() computation" << std::endl;
656 
657  // mapping
658  const dealii::hp::MappingCollection<dim> mapping_collection(*(this->dg->high_order_grid->mapping_fe_field));
659 
660  // using p+1 reconstruction
661  const unsigned int rel_order = 1;
662 
663  // construct object to reconstruct the derivatives onto A
664  ReconstructPoly<dim,nstate,real> reconstruct_poly(
665  this->dg->dof_handler,
666  mapping_collection,
667  this->dg->fe_collection,
668  this->dg->volume_quadrature_collection,
669  this->volume_update_flags);
670 
671  // constructing the largest directional derivatives
672  reconstruct_poly.reconstruct_directional_derivative(
673  this->dg->solution,
674  rel_order);
675 
676  // if anisotropic, setting the cell anisotropy
678  std::cout << "Setting cell anisotropy" << std::endl;
679 
680  // builds the anisotropy from Dolejsi's anisotropic ellipse size
681  this->h_field->set_anisotropy(
682  this->dg->dof_handler,
683  reconstruct_poly.derivative_value,
684  reconstruct_poly.derivative_direction,
685  rel_order);
686 
687  std::cout << "Applying anisotropy limits: \\rho = [" <<
689  this->grid_refinement_param.anisotropic_ratio_max << "]" << std::endl;
690 
691  this->h_field->apply_anisotropic_limit(
693  this->grid_refinement_param.anisotropic_ratio_max);
694 
695  }
696 
697  // getting the DWR (cell-wise indicator)
698  this->adjoint->fine_grid_adjoint();
699  this->adjoint->dual_weighted_residual();
700  dealii::Vector<real> dwr = this->adjoint->dual_weighted_residual_fine;
702 
703  // setting the current p-field and performing the size-field refinement step
704 
705  // checking if the polynomial order is uniform
706  if(this->dg->get_min_fe_degree() == this->dg->get_max_fe_degree()){
707  unsigned int poly_degree = this->dg->get_min_fe_degree();
708 
709  this->get_current_field_h();
711  this->complexity_target,
713  this->grid_refinement_param.c_max,
714  dwr,
715  this->dg->dof_handler,
716  mapping_collection,
717  this->dg->fe_collection,
718  this->dg->volume_quadrature_collection,
719  this->volume_update_flags,
720  this->h_field,
721  poly_degree);
722  // SizeField<dim,real>::adjoint_h_equal(
723  // this->complexity_target,
724  // dwr,
725  // this->dg->dof_handler,
726  // mapping_collection,
727  // this->dg->fe_collection,
728  // this->dg->volume_quadrature_collection,
729  // this->volume_update_flags,
730  // this->h_field,
731  // poly_degree);
732 
733  }else{
734  // the case of non-uniform p
736 
737  this->get_current_field_h();
739  this->complexity_target,
741  this->grid_refinement_param.c_max,
742  dwr,
743  this->dg->dof_handler,
744  mapping_collection,
745  this->dg->fe_collection,
746  this->dg->volume_quadrature_collection,
747  this->volume_update_flags,
748  this->h_field,
749  this->p_field);
750 
751  }
752 }
753 
754 template <int dim, int nstate, typename real, typename MeshType>
756 {
757  // NOT IMPLEMENTED
758  assert(0);
759 }
760 template <int dim, int nstate, typename real, typename MeshType>
762 {
763  // NOT IMPLEMENTED
764  assert(0);
765 }
766 
767 template <int dim, int nstate, typename real, typename MeshType>
768 std::vector< std::pair<dealii::Vector<real>, std::string> > GridRefinement_Continuous<dim,nstate,real,MeshType>::output_results_vtk_method()
769 {
770  std::vector< std::pair<dealii::Vector<real>, std::string> > data_out_vector;
771 
772  // getting the current field sizes
774  data_out_vector.push_back(
775  std::make_pair(
776  this->h_field->get_scale_vector_dealii(),
777  "h_field_curr"));
778 
780  data_out_vector.push_back(
781  std::make_pair(
782  p_field,
783  "p_field_curr"));
784 
785  // computing the (next) update to the fields
786  field();
787  data_out_vector.push_back(
788  std::make_pair(
789  this->h_field->get_scale_vector_dealii(),
790  "h_field_next"));
791 
792  data_out_vector.push_back(
793  std::make_pair(
794  p_field,
795  "p_field_next"));
796 
797  // if field is anisotropic
799  // also outputting the anisotropic ratio of each cell
800  data_out_vector.push_back(
801  std::make_pair(
802  this->h_field->get_max_anisotropic_ratio_vector_dealii(),
803  "anisotropic_ratio_next"));
804 
805  // reconstructing the directional derivatives again
806  // mapping
807  const dealii::hp::MappingCollection<dim> mapping_collection(*(this->dg->high_order_grid->mapping_fe_field));
808 
809  // using p+1 reconstruction
810  const unsigned int rel_order = 1;
811 
812  // construct object to reconstruct the derivatives onto A
813  ReconstructPoly<dim,nstate,real> reconstruct_poly(
814  this->dg->dof_handler,
815  mapping_collection,
816  this->dg->fe_collection,
817  this->dg->volume_quadrature_collection,
818  this->volume_update_flags);
819 
820  // constructing the largest directional derivatives
821  reconstruct_poly.reconstruct_directional_derivative(
822  this->dg->solution,
823  rel_order);
824  // reconstruct_poly.reconstruct_manufactured_derivative(
825  // this->physics->manufactured_solution_function,
826  // rel_order);
827 
828  // getting the derivative_values as a dealii vector (in order)
829  for(unsigned int i = 0; i < dim; ++i)
830  data_out_vector.push_back(
831  std::make_pair(
832  reconstruct_poly.get_derivative_value_vector_dealii(i),
833  "derivative_value_" + dealii::Utilities::int_to_string(i, 1)));
834 
835  }
836 
837  return data_out_vector;
838 
839 }
840 
841 // dealii::Triangulation<PHILIP_DIM>
847 
848 // dealii::parallel::shared::Triangulation<PHILIP_DIM>
854 
855 #if PHILIP_DIM != 1
856 // dealii::parallel::distributed::Triangulation<PHILIP_DIM>
862 #endif
863 
864 } // namespace GridRefinement
865 
866 } // namespace PHiLiP
Output class for GMSH .msh v4.1 file format.
Definition: msh_out.h:208
void field_h_error()
Generate mesh distribution based on manufactured solution.
static void adjoint_uniform_balan(const real complexity, const real r_max, const real c_max, const dealii::Vector< real > &eta, const dealii::DoFHandler< dim > &dof_handler, const dealii::hp::MappingCollection< dim > &mapping_collection, const dealii::hp::FECollection< dim > &fe_collection, const dealii::hp::QCollection< dim > &quadrature_collection, const dealii::UpdateFlags &update_flags, std::unique_ptr< Field< dim, real >> &h_field, const real &poly_degree)
Performs adjoint based size field adaptation for uniform polynomial distribution based on the method ...
Definition: size_field.cpp:272
void target_complexity()
Updates the complexity target based on the current refinement iteration.
std::unique_ptr< Field< dim, real > > h_field
Continuous representation of the mesh size and anisotropy distribution.
std::vector< std::array< dealii::Tensor< 1, dim, real >, dim > > derivative_direction
Derivative directions.
RefinementType refinement_type
Selected type of refinement to be performed.
void add_data_vector(std::vector< T > data, StorageType storage_type)
Add data vector of specified storage type and values.
Definition: msh_out.h:229
Polynomial Reconstruction Class.
ErrorIndicator
Types of error indicator to be used in the grid refinement.
static void isotropic_h(const real complexity, const dealii::Vector< real > &B, const dealii::DoFHandler< dim > &dof_handler, const dealii::hp::MappingCollection< dim > &mapping_collection, const dealii::hp::FECollection< dim > &fe_collection, const dealii::hp::QCollection< dim > &quadrature_collection, const dealii::UpdateFlags &update_flags, std::unique_ptr< Field< dim, real >> &h_field, const dealii::Vector< real > &p_field)
Computes the size field (element scale) for a potentially non-uniform - distribution.
Definition: size_field.cpp:70
double r_max
refinement factor for log DWR size field
PHiLiP::Parameters::GridRefinementParam grid_refinement_param
Grid refinement parameters.
OutputType
File type/interface to be used for access to external tools.
std::shared_ptr< PHiLiP::Adjoint< dim, nstate, real, MeshType > > adjoint
Adjoint object (if provided to factory)
Base class from which Advection, Diffusion, ConvectionDiffusion, and Euler is derived.
Definition: physics.h:34
Adjoint class.
Definition: adjoint.h:39
void refine_grid_msh()
Generates an output .msh file with matrix information about the target frame field.
std::shared_ptr< MeshType > tria
Triangulation object of templated mesh type.
Files for the baseline physics.
Definition: ADTypes.hpp:10
void write_msh(std::ostream &out)
Output formatted .msh v4.1 file with mesh description and data field.
Definition: msh_out.cpp:31
void refine_grid_p()
Updates the global polynomial distribution based on the target -field.
unsigned int iteration
Internal refinement steps iteration counter.
void reconstruct_directional_derivative(const dealii::LinearAlgebra::distributed::Vector< real > &solution, const unsigned int rel_order)
Construct the set of largest perpendicular directional derivatives.
GridRefinement_Continuous(PHiLiP::Parameters::GridRefinementParam gr_param_input, std::shared_ptr< PHiLiP::Adjoint< dim, nstate, real, MeshType > > adj_input, std::shared_ptr< PHiLiP::Physics::PhysicsBase< dim, nstate, real > > physics_input)
Constructor. Stores the adjoint object, physics and parameters.
void field_hp_error()
(NOT IMPLEMENTED) Generate mesh and polynomial distribution based on manufactured solution ...
OutputDataType
Method of data storage in the output file for continuous methods.
std::vector< std::array< real, dim > > derivative_value
Derivative values.
void field_hp_residual()
(NOT IMPLEMENTED) Generate mesh and polynomial distribution based on fine-grid residual distribution ...
void field_hp_hessian()
(NOT IMPLEMENTED) Generate mesh and polynomial distribution based on directional derivatives ...
void field()
Updates the continuous mesh and polynomial distribution.
void get_current_field_p()
Evaluates the polynomial distribution for the current mesh.
void refine_grid_gmsh()
Generates a new mesh based on GMSH using .pos and .geo files for i/o.
real current_complexity()
Evaluates the current complexity of the mesh.
bool anisotropic
Flag for performing anisotropic refinement.
void field_p_hessian()
(NOT IMPLEMENTED) Generate polynomial distribution based on directinal derivatives ...
static void write_geo(std::vector< std::string > &posFile_vec, std::ostream &out)
Writes the central .geo file for call to GMSH on main process with isotropic quad meshing...
Definition: gmsh_out.cpp:291
std::shared_ptr< PHiLiP::DGBase< dim, real, MeshType > > dg
Discontinuous Galerkin object.
void field_hp_adjoint()
(NOT IMPLEMENTED) Generate mesh and polynomial distribution based on dual-weighted residual distribut...
void field_p_residual()
(NOT IMPLEMENTED) Generate polynomial distribution based on fine-grid residual distribution ...
void refine_grid() override
Perform call to the grid refinement object of choice.
void field_p_error()
(NOT IMPLEMENTED) Generate polynomial distribution based on manufactured solution ...
dealii::Vector< real > p_field
Continuous representation of the polynomial distribution.
dealii::Vector< real > get_derivative_value_vector_dealii(const unsigned int index)
Gets the i^th largest componet of the directional derivative vector as a dealii::Vector.
static void write_pos_anisotropic(const dealii::Triangulation< dim, dim > &tria, const std::vector< dealii::SymmetricTensor< 2, dim, real >> &data, std::ostream &out, const int p_scale=1)
Write anisotropic tensor .pos file for use with GMSH.
Definition: gmsh_out.cpp:152
double complexity_add
additive constant to complexity between grid refinement iterations
static void write_geo_anisotropic(std::vector< std::string > &posFile_vec, std::ostream &out)
Writes the central .geo file for call to GMSH on main process with anisotropic quad meshing...
Definition: gmsh_out.cpp:333
RefinementType
Controls the type of refinement to be performed.
bool exit_after_refine
Flag to exit after call to refinement.
OutputDataType output_data_type
Selected data storage type.
static void isotropic_uniform(const real &complexity, const dealii::Vector< real > &B, const dealii::DoFHandler< dim > &dof_handler, std::unique_ptr< Field< dim, real >> &h_field, const real &poly_degree)
Computes the size field (element scale) for a uniform - distribution.
Definition: size_field.cpp:38
static void write_pos(const dealii::Triangulation< dim, dim > &tria, dealii::Vector< real > data, std::ostream &out)
Write scalar .pos file for use with GMSH.
Definition: gmsh_out.cpp:40
Parameters related to individual grid refinement run.
std::shared_ptr< PHiLiP::Physics::PhysicsBase< dim, nstate, real > > physics
Problem physics (if provided to factory, directly or indirectly)
real complexity_initial
Initial mesh complexity at construction.
void field_p_adjoint()
(NOT IMPLEMENTED) Generate polynomial distribution based on dual-weighted residual distribution ...
void field_h_adjoint()
Generate mesh distribution based on dual-weighted residual distribution.
std::vector< std::pair< dealii::Vector< real >, std::string > > output_results_vtk_method() override
Output refinement method dependent results.
double anisotropic_ratio_max
Maximum anisotropic ratio for continuous size field targets.
void refine_grid_h()
Performs call to global remeshing method.
void field_h_hessian()
Generate mesh distribution based on directional derivatives.
Functional base class.
Definition: functional.h:43
void refine_grid_hp()
(NOT IMPLEMENTED) Performs call to global remeshing method with updated polynomial distribution ...
static void adjoint_h_balan(const real complexity, const real r_max, const real c_max, const dealii::Vector< real > &eta, const dealii::DoFHandler< dim > &dof_handler, const dealii::hp::MappingCollection< dim > &mapping_collection, const dealii::hp::FECollection< dim > &fe_collection, const dealii::hp::QCollection< dim > &quadrature_collection, const dealii::UpdateFlags &update_flags, std::unique_ptr< Field< dim, real >> &h_field, const dealii::Vector< real > &p_field)
Performs adjoint based size field adaptation for non-uniform polynomial distribution based on the met...
Definition: size_field.cpp:307
double anisotropic_ratio_min
Minimum anisotropic ratio for continuous zie field targets.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
std::vector< double > complexity_vector
Vector of complexities to be used for initial continuous grid refinement iterations.
double complexity_scale
multiplier to complexity between grid refinement iterations
void get_current_field_h()
Evaluates the mesh size and ansitropy description for the current mesh.
std::vector< real > complexity_vector
Vector of complexity target goals for each iteration.
void field_h_residual()
(NOT IMPLEMENTED) Generate mesh distribution based on fine-grid residual distribution ...
MPI_Comm mpi_communicator
MPI communicator.
OutputType output_type
Selected file output type.