mpi/distribution/fish_poisson/fish_poisson.cc File Reference
#include "generic.h"
#include "poisson.h"
#include "meshes/fish_mesh.h"

Classes

class  RefineableFishPoissonProblem< ELEMENT >
 

Namespaces

 ConstSourceForPoisson
 Namespace for const source term in Poisson equation.
 

Functions

void ConstSourceForPoisson::source_function (const Vector< double > &x, double &source)
 Const source function. More...
 
void solve_with_incremental_adaptation ()
 
void solve_with_fully_automatic_adaptation ()
 
void solve_with_selected_refinement_pattern ()
 Solve 2D fish Poisson problem with a selected refinement pattern. More...
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Demonstrate how to solve 2D Poisson problem in fish-shaped domain with mesh adaptation.

550 {
551  // initialise MPI
552 #ifdef OOMPH_HAS_MPI
553  MPI_Helpers::init(argc,argv);
554 #endif
555 
556  // Solve using a pre-selected refinement pattern
558 
559  // Solve with adaptation, docing the intermediate steps
561 
562  // Solve directly, with fully automatic adaptation
564 
565 #ifdef OOMPH_HAS_MPI
566  MPI_Helpers::finalize();
567 #endif
568 
569 } // end of main
void solve_with_fully_automatic_adaptation()
Definition: mpi/distribution/fish_poisson/fish_poisson.cc:379
void solve_with_incremental_adaptation()
Definition: mpi/distribution/fish_poisson/fish_poisson.cc:211
void solve_with_selected_refinement_pattern()
Solve 2D fish Poisson problem with a selected refinement pattern.
Definition: mpi/distribution/fish_poisson/fish_poisson.cc:455

References solve_with_fully_automatic_adaptation(), solve_with_incremental_adaptation(), and solve_with_selected_refinement_pattern().

◆ solve_with_fully_automatic_adaptation()

void solve_with_fully_automatic_adaptation ( )

Demonstrate how to solve 2D Poisson problem in fish-shaped domain with fully automatic mesh adaptation

380 {
381  //Set up the problem with nine-node refineable Poisson elements
383 
384  // Setup labels for output
385  //------------------------
386  DocInfo doc_info, mesh_doc_info;
387  bool report_stats=true;
388 
389  // Set output directory
390  doc_info.set_directory("RESLT_fully_automatic");
391  mesh_doc_info.set_directory("RESLT_adapt_mesh");
392 
393  // Step number
394  doc_info.number()=0;
395  mesh_doc_info.number()=20;
396 
397  // Doc (default) refinement targets
398  //----------------------------------
399  problem.mesh_pt()->doc_adaptivity_targets(cout);
400 
401  // Solve/doc the problem with fully automatic adaptation
402  //------------------------------------------------------
403 
404  // Refine coarse original mesh first
405  //----------------------------------
406  problem.refine_uniformly();
407  problem.refine_uniformly();
408 
409  oomph_info << "-----------------------------------------" << std::endl;
410  oomph_info << "--- Distributing problem (fully auto) ---" << std::endl;
411  oomph_info << "-----------------------------------------" << std::endl;
412 
413  std::ifstream input_file;
414  std::ofstream output_file;
415  char filename[100];
416 
417  // Get the partition to be used from file
418  unsigned n_partition=problem.mesh_pt()->nelement();
419  Vector<unsigned> element_partition(n_partition,0);
420  sprintf(filename,"fish_fully_automatic_partition.dat");
421  input_file.open(filename);
422  std::string input_string;
423  for (unsigned e=0;e<n_partition;e++)
424  {
425  getline(input_file,input_string,'\n');
426  element_partition[e]=atoi(input_string.c_str());
427  }
428 
429  // Distribute and check halo schemes
430  problem.distribute(element_partition,mesh_doc_info,report_stats);
431  problem.check_halo_schemes(mesh_doc_info);
432 
433  //Maximum number of adaptations:
434  unsigned max_adapt=5;
435 
436  oomph_info << "Solve with max_adapt=" << max_adapt << std::endl;
437 
438  //Solve the problem; perform up to specified number of adaptations.
439  problem.newton_solve(max_adapt);
440 
441  //Output solution
442  oomph_info << "-----------------------" << std::endl;
443  oomph_info << "Now output the solution" << std::endl;
444  oomph_info << "-----------------------" << std::endl;
445  problem.doc_solution(doc_info);
446 
447  //increment doc_info number
448  doc_info.number()++;
449 
450 } // end black box
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Definition: algebraic_free_boundary_poisson.cc:81
Definition: oomph_utilities.h:499
void set_directory(const std::string &directory)
Definition: oomph_utilities.cc:298
unsigned & number()
Number used (e.g.) for labeling output files.
Definition: oomph_utilities.h:554
string filename
Definition: MergeRestartFiles.py:39
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213

References e(), MergeRestartFiles::filename, oomph::DocInfo::number(), oomph::oomph_info, problem, oomph::DocInfo::set_directory(), and oomph::Global_string_for_annotation::string().

Referenced by main().

◆ solve_with_incremental_adaptation()

void solve_with_incremental_adaptation ( )

Demonstrate how to solve 2D Poisson problem in fish-shaped domain with mesh adaptation. First we solve on the original coarse mesh. Next we do a few uniform refinement steps and re-solve. Finally, we enter into an automatic adapation loop.

212 {
213 
214  oomph_info << "Min/max about to start incremental\n";
215 
216  //Set up the problem with nine-node refineable Poisson elements
218 
219  // Setup labels for output
220  //------------------------
221  DocInfo doc_info, mesh_doc_info;
222  bool report_stats=true;
223 
224  // Set output directory
225  doc_info.set_directory("RESLT_incremental2");
226  mesh_doc_info.set_directory("RESLT_incr_mesh");
227 
228  // Step number
229  doc_info.number()=1;
230  mesh_doc_info.number()=10;
231 
232  // Increase minimum permitted error from default (10e-5) to 10e-4
233  problem.mesh_pt()->min_permitted_error()=1.0e-4;
234 
235  // Doc (default) refinement targets
236  //----------------------------------
237  problem.mesh_pt()->doc_adaptivity_targets(cout);
238 
239  // solve
240  problem.newton_solve();
241 
242  //Output solution
243  doc_info.label()="initial";
244  problem.doc_solution(doc_info);
245 
246  //Increment counter for solutions
247  doc_info.number()++;
248 
249  //Loop for refining uniformly
250  for (unsigned mym=0;mym<2;mym++)
251  {
252  //On the first step refine uniformly twice and then distribute
253  if (mym==0)
254  {
255  problem.refine_uniformly();
256  problem.refine_uniformly();
257 
258  oomph_info << "Distributing problem" << std::endl;
259  std::ifstream input_file;
260  std::ofstream output_file;
261  char filename[100];
262 
263  // Get the partition to be used from file
264  unsigned n_partition=problem.mesh_pt()->nelement();
265  Vector<unsigned> element_partition(n_partition,0);
266  sprintf(filename,"fish_incremental_partition.dat");
267  input_file.open(filename);
268  std::string input_string;
269  for (unsigned e=0;e<n_partition;e++)
270  {
271  getline(input_file,input_string,'\n');
272  element_partition[e]=atoi(input_string.c_str());
273  }
274 
275  // Distribute and check halo schemes
276  problem.distribute(element_partition,mesh_doc_info,report_stats);
277  problem.check_halo_schemes(mesh_doc_info);
278  }
279 
280  // another round of refinement
281  oomph_info << "Refine again..." << std::endl;
282  problem.refine_uniformly();
283 
284  // Solve the problem
285  oomph_info << "Solve again..." << std::endl;
286 
287  problem.newton_solve();
288 
289  //Output solution
290  doc_info.label()="after first solve after distribution and uniform refinement";
291  problem.doc_solution(doc_info);
292 
293  //Increment counter for solutions
294  doc_info.number()++;
295  }
296 
297  oomph_info << "Automatic adaptation starting" << std::endl << std::endl;
298 
299  // Now do (up to) four rounds of fully automatic adapation in response to
300  //-----------------------------------------------------------------------
301  // error estimate
302  //---------------
303  unsigned max_solve=4;
304  for (unsigned isolve=0;isolve<max_solve;isolve++)
305  {
306  oomph_info << "Adapting problem - isolve=" << isolve << std::endl;
307 
308  // Adapt problem/mesh
309  problem.adapt();
310 
311  // Re-solve the problem if the adaptation has changed anything
312 #ifdef OOMPH_HAS_MPI
313  // Make sure all processors know if refinement is taking place
314  // Adaptation only converges if ALL the processes have no
315  // refinement or unrefinement to perform
316  unsigned total_refined;
317  unsigned total_unrefined;
318  unsigned n_refined=problem.mesh_pt()->nrefined();
319  unsigned n_unrefined=problem.mesh_pt()->nunrefined();
320 
321  MPI_Allreduce(&n_refined,&total_refined,1,MPI_INT,MPI_SUM,
322  problem.communicator_pt()->mpi_comm());
323  n_refined=total_refined;
324 
325  MPI_Allreduce(&n_unrefined,&total_unrefined,1,MPI_INT,MPI_SUM,
326  problem.communicator_pt()->mpi_comm());
327  n_unrefined=total_unrefined;
328 #endif
329 
330  oomph_info << "---> " << n_refined << " elements to be refined, and "
331  << n_unrefined << " to be unrefined, in total." << std::endl;
332 
333  if ((n_refined!=0)||(n_unrefined!=0))
334  {
335  problem.newton_solve();
336  }
337  else
338  {
339  cout << "Mesh wasn't adapted --> we'll stop here" << std::endl;
340  break;
341  }
342 
343  //Output solution
344  doc_info.label()="solve after adapt";
345  problem.doc_solution(doc_info);
346 
347  //Increment counter for solutions
348  doc_info.number()++;
349  }
350 
351  // Loop for uniform unrefinement
352  for(unsigned myn=0;myn<10;myn++)
353  {
354  // Test the unrefine_uniformly command and re-solve
355  //-------------------------------------------------
356  problem.unrefine_uniformly();
357 
358  // Solve the problem
359  problem.newton_solve();
360 
361  //Output solution
362  doc_info.label()="solve after uniform unrefinement";
363  problem.doc_solution(doc_info);
364 
365  //Increment counter for solutions
366  doc_info.number()++;
367  }
368 
369  oomph_info << "Min/max end incremental\n";
370 
371 } // end of incremental
std::string & label()
String used (e.g.) for labeling output files.
Definition: oomph_utilities.h:572

References e(), MergeRestartFiles::filename, oomph::DocInfo::label(), oomph::DocInfo::number(), oomph::oomph_info, problem, oomph::DocInfo::set_directory(), and oomph::Global_string_for_annotation::string().

Referenced by main().

◆ solve_with_selected_refinement_pattern()

void solve_with_selected_refinement_pattern ( )

Solve 2D fish Poisson problem with a selected refinement pattern.

456 {
457  //Set up the problem with nine-node refineable Poisson elements
459 
460  // Setup labels for output
461  //------------------------
462  DocInfo doc_info, mesh_doc_info;
463  bool report_stats=true;
464 
465  // Set output directory
466  doc_info.set_directory("RESLT_select_refine");
467  mesh_doc_info.set_directory("RESLT_select_mesh");
468 
469  // Step number
470  doc_info.number()=0;
471  mesh_doc_info.number()=20;
472 
473  // Doc (default) refinement targets
474  //----------------------------------
475  problem.mesh_pt()->doc_adaptivity_targets(cout);
476 
477  // Refine coarse original mesh first
478  //----------------------------------
479  problem.refine_uniformly();
480  problem.refine_uniformly();
481 
482  // Distribute the problem and doc mesh info
483  oomph_info << "----------------------------------------" << std::endl;
484  oomph_info << "--- Distributing problem (selective) ---" << std::endl;
485  oomph_info << "----------------------------------------" << std::endl;
486 
487  std::ifstream input_file;
488  std::ofstream output_file;
489  char filename[100];
490 
491  // Get the partition to be used from file
492  unsigned n_partition=problem.mesh_pt()->nelement();
493  Vector<unsigned> element_partition(n_partition,0);
494  sprintf(filename,"fish_selective_partition.dat");
495  input_file.open(filename);
496  std::string input_string;
497  for (unsigned e=0;e<n_partition;e++)
498  {
499  getline(input_file,input_string,'\n');
500  element_partition[e]=atoi(input_string.c_str());
501  }
502 
503  // Distribute and check halo schemes
504  problem.distribute(element_partition,mesh_doc_info,report_stats);
505  problem.check_halo_schemes(mesh_doc_info);
506 
507  // Add some selective refinement on top of this
508  unsigned nsoln=3; // number of selective refinements - validate, 3
509 
510  for (unsigned isoln=0; isoln<nsoln; isoln++)
511  {
512  // Refine selected elements based upon y-coordinate
513  // of the central node of the element (node 4)
514  Vector<unsigned> more_middle_els;
515  unsigned nels=problem.mesh_pt()->nelement();
516  for (unsigned e=0; e<nels; e++)
517  {
518  FiniteElement* el_pt=dynamic_cast<FiniteElement*>
519  (problem.mesh_pt()->element_pt(e));
520  if ((el_pt->node_pt(4)->x(1)>=(-0.35)) &&
521  (el_pt->node_pt(4)->x(1)<=0.35))
522  {
523  more_middle_els.push_back(e);
524  }
525  }
526 
527  oomph_info << "--------------------------------" << std::endl;
528  oomph_info << "This time, refine " << more_middle_els.size()
529  << " selected elements" << std::endl;
530  oomph_info << "--------------------------------" << std::endl;
531  problem.refine_selected_elements(more_middle_els);
532 
533  // Now solve the problem
534  problem.newton_solve();
535 
536  // Doc the solution
537  problem.doc_solution(doc_info);
538 
539  // Increment doc_info number
540  doc_info.number()++;
541  }
542 
543 }
Definition: elements.h:1313
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition: elements.h:2175
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition: nodes.h:1060

References e(), MergeRestartFiles::filename, oomph::FiniteElement::node_pt(), oomph::DocInfo::number(), oomph::oomph_info, problem, oomph::DocInfo::set_directory(), oomph::Global_string_for_annotation::string(), and oomph::Node::x().

Referenced by main().