fish_poisson.cc
Go to the documentation of this file.
1 //LIC// ====================================================================
2 //LIC// This file forms part of oomph-lib, the object-oriented,
3 //LIC// multi-physics finite-element library, available
4 //LIC// at http://www.oomph-lib.org.
5 //LIC//
6 //LIC// Version 1.0; svn revision $LastChangedRevision$
7 //LIC//
8 //LIC// $LastChangedDate$
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 // Driver for solution of 2D Poisson equation in fish-shaped domain with
31 // adaptivity
32 
33 
34 // Generic oomph-lib headers
35 #include "generic.h"
36 
37 // The Poisson equations
38 #include "poisson.h"
39 
40 // The fish mesh
41 #include "meshes/fish_mesh.h"
42 
43 using namespace std;
44 
45 using namespace oomph;
46 
47 
48 //============ start_of_namespace=====================================
49 /// Namespace for const source term in Poisson equation
50 //====================================================================
52 {
53 
54  /// Strength of source function: default value -1.0
55  double Strength=-1.0;
56 
57 /// Const source function
58  void source_function(const Vector<double>& x, double& source)
59  {
60  source = Strength;
61  }
62 
63 } // end of namespace
64 
65 
66 
67 
68 //======start_of_problem_class========================================
69 /// Refineable Poisson problem in fish-shaped domain.
70 /// Template parameter identifies the element type.
71 //====================================================================
72 template<class ELEMENT>
73 class RefineableFishPoissonProblem : public Problem
74 {
75 
76 public:
77 
78  /// Constructor
80 
81  /// Destructor: Empty
83 
84  /// Update the problem specs after solve (empty)
86 
87  /// Update the problem specs before solve (empty)
89 
90  /// \short Overloaded version of the problem's access function to
91  /// the mesh. Recasts the pointer to the base Mesh object to
92  /// the actual mesh type.
93  RefineableFishMesh<ELEMENT>* mesh_pt()
94  {
95  return dynamic_cast<RefineableFishMesh<ELEMENT>*>(Problem::mesh_pt());
96  }
97 
98  /// \short Doc the solution. Output directory and labels are specified
99  /// by DocInfo object
100  void doc_solution(DocInfo& doc_info);
101 
102 }; // end of problem class
103 
104 
105 
106 
107 
108 //===========start_of_constructor=========================================
109 /// Constructor for adaptive Poisson problem in fish-shaped
110 /// domain.
111 //========================================================================
112 template<class ELEMENT>
114 {
115 
116  // Build fish mesh -- this is a coarse base mesh consisting
117  // of four elements. We'll refine/adapt the mesh later.
118  Problem::mesh_pt()=new RefineableFishMesh<ELEMENT>;
119 
120  // Create/set error estimator
121  mesh_pt()->spatial_error_estimator_pt()=new Z2ErrorEstimator;
122 
123  // Set the boundary conditions for this problem: All nodes are
124  // free by default -- just pin the ones that have Dirichlet conditions
125  // here. Since the boundary values are never changed, we set
126  // them here rather than in actions_before_newton_solve().
127  unsigned n_bound = mesh_pt()->nboundary();
128  for(unsigned i=0;i<n_bound;i++)
129  {
130  unsigned n_node = mesh_pt()->nboundary_node(i);
131  for (unsigned n=0;n<n_node;n++)
132  {
133  // Pin the single scalar value at this node
134  mesh_pt()->boundary_node_pt(i,n)->pin(0);
135 
136  // Assign the homogenous boundary condition for the one and only
137  // nodal value
138  mesh_pt()->boundary_node_pt(i,n)->set_value(0,0.0);
139  }
140  }
141 
142  // Loop over elements and set pointers to source function
143  unsigned n_element = mesh_pt()->nelement();
144  for(unsigned e=0;e<n_element;e++)
145  {
146  // Upcast from FiniteElement to the present element
147  ELEMENT *el_pt = dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(e));
148 
149  //Set the source function pointer
150  el_pt->source_fct_pt() = &ConstSourceForPoisson::source_function;
151  }
152 
153  // Setup the equation numbering scheme
154  cout <<"Number of equations: " << assign_eqn_numbers() << std::endl;
155 
156 } // end of constructor
157 
158 
159 
160 
161 //=======start_of_doc=====================================================
162 /// Doc the solution in tecplot format.
163 //========================================================================
164 template<class ELEMENT>
166 {
167 
168  ofstream some_file;
169  char filename[100];
170 
171  // Number of plot points in each coordinate direction.
172  unsigned npts;
173  npts=5;
174 
175  // Output solution
176  sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
177  doc_info.number());
178  some_file.open(filename);
179  mesh_pt()->output(some_file,npts);
180  some_file.close();
181 
182 } // end of doc
183 
184 
185 
186 
187 
188 
189 //=====================start_of_incremental===============================
190 /// Demonstrate how to solve 2D Poisson problem in
191 /// fish-shaped domain with mesh adaptation. First we solve on the original
192 /// coarse mesh. Next we do a few uniform refinement steps and re-solve.
193 /// Finally, we enter into an automatic adapation loop.
194 //========================================================================
196 {
197 
198  //Set up the problem with nine-node refineable Poisson elements
200 
201  // Setup labels for output
202  //------------------------
203  DocInfo doc_info;
204 
205  // Set output directory
206  doc_info.set_directory("RESLT_incremental");
207 
208  // Step number
209  doc_info.number()=0;
210 
211 
212  // Doc (default) refinement targets
213  //----------------------------------
214  problem.mesh_pt()->doc_adaptivity_targets(cout);
215 
216  // Solve/doc the problem on the initial, very coarse mesh
217  //-------------------------------------------------------
218 
219  // Solve the problem
220  problem.newton_solve();
221 
222  //Output solution
223  problem.doc_solution(doc_info);
224 
225  //Increment counter for solutions
226  doc_info.number()++;
227 
228 
229  // Do three rounds of uniform mesh refinement and re-solve
230  //--------------------------------------------------------
231  problem.refine_uniformly();
232  problem.refine_uniformly();
233  problem.refine_uniformly();
234 
235  // Solve the problem
236  problem.newton_solve();
237 
238  //Output solution
239  problem.doc_solution(doc_info);
240 
241  //Increment counter for solutions
242  doc_info.number()++;
243 
244 
245  // Now do (up to) four rounds of fully automatic adapation in response to
246  //-----------------------------------------------------------------------
247  // error estimate
248  //---------------
249  unsigned max_solve=4;
250  for (unsigned isolve=0;isolve<max_solve;isolve++)
251  {
252  // Adapt problem/mesh
253  problem.adapt();
254 
255  // Re-solve the problem if the adaptation has changed anything
256  if ((problem.mesh_pt()->nrefined() !=0)||
257  (problem.mesh_pt()->nunrefined()!=0))
258  {
259  problem.newton_solve();
260  }
261  else
262  {
263  cout << "Mesh wasn't adapted --> we'll stop here" << std::endl;
264  break;
265  }
266 
267  //Output solution
268  problem.doc_solution(doc_info);
269 
270  //Increment counter for solutions
271  doc_info.number()++;
272  }
273 
274 
275 } // end of incremental
276 
277 
278 
279 
280 
281 
282 //================================start_black_box=========================
283 /// Demonstrate how to solve 2D Poisson problem in
284 /// fish-shaped domain with fully automatic mesh adaptation
285 //========================================================================
287 {
288 
289  //Set up the problem with nine-node refineable Poisson elements
291 
292  // Setup labels for output
293  //------------------------
294  DocInfo doc_info;
295 
296  // Set output directory
297  doc_info.set_directory("RESLT_fully_automatic");
298 
299  // Step number
300  doc_info.number()=0;
301 
302 
303  // Doc (default) refinement targets
304  //----------------------------------
305  problem.mesh_pt()->doc_adaptivity_targets(cout);
306 
307 
308  // Solve/doc the problem with fully automatic adaptation
309  //------------------------------------------------------
310 
311  // Maximum number of adaptations:
312  unsigned max_adapt=5;
313 
314  // Solve the problem; perform up to specified number of adaptations.
315  problem.newton_solve(max_adapt);
316 
317  //Output solution
318  problem.doc_solution(doc_info);
319 
320 } // end black box
321 
322 
323 
324 
325 //=================start_of_main==========================================
326 /// Demonstrate how to solve 2D Poisson problem in
327 /// fish-shaped domain with mesh adaptation.
328 //========================================================================
329 int main()
330 {
331  // Solve with adaptation, docing the intermediate steps
333 
334  // Solve directly, with fully automatic adaptation
336 
337 } // end of main
338 
339 
340 
341 
342 // //Do few unrefinements and keep doc-ing
343 // for (unsigned i=0;i<5;i++)
344 // {
345 // problem.unrefine_uniformly();
346 
347 // //Output solution
348 // problem.doc_solution(doc_info);
349 
350 // //Increment counter for solutions
351 // doc_info.number()++;
352 // }
void solve_with_incremental_adaptation()
void solve_with_fully_automatic_adaptation()
void actions_after_newton_solve()
Update the problem specs after solve (empty)
Definition: fish_poisson.cc:85
void source_function(const Vector< double > &x, double &source)
Const source function.
Definition: fish_poisson.cc:58
double Strength
Strength of source function: default value -1.0.
Definition: fish_poisson.cc:55
RefineableFishPoissonProblem()
Constructor.
virtual ~RefineableFishPoissonProblem()
Destructor: Empty.
Definition: fish_poisson.cc:82
void actions_before_newton_solve()
Update the problem specs before solve (empty)
Definition: fish_poisson.cc:88
void doc_solution(DocInfo &doc_info)
Doc the solution. Output directory and labels are specified by DocInfo object.
Namespace for const source term in Poisson equation.
Definition: fish_poisson.cc:51
int main()
RefineableFishMesh< ELEMENT > * mesh_pt()
Overloaded version of the problem&#39;s access function to the mesh. Recasts the pointer to the base Mesh...
Definition: fish_poisson.cc:93