old_for_doc.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// Copyright (C) 2006-2025 Matthias Heil and Andrew Hazel
7//LIC//
8//LIC// This library is free software; you can redistribute it and/or
9//LIC// modify it under the terms of the GNU Lesser General Public
10//LIC// License as published by the Free Software Foundation; either
11//LIC// version 2.1 of the License, or (at your option) any later version.
12//LIC//
13//LIC// This library is distributed in the hope that it will be useful,
14//LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15//LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16//LIC// Lesser General Public License for more details.
17//LIC//
18//LIC// You should have received a copy of the GNU Lesser General Public
19//LIC// License along with this library; if not, write to the Free Software
20//LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21//LIC// 02110-1301 USA.
22//LIC//
23//LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24//LIC//
25//LIC//====================================================================
26//###########################################################
27// OLD VERSION OF CODE -- KEEP ALIVE BECAUSE IT ALLOWS
28// PLOT OF COUPLED AND UNCOUPLED SOLUTIONS!
29//###########################################################
30
31// Driver for solution of "free boundary" 2D Poisson equation in
32// fish-shaped domain with adaptivity
33
34
35// Generic oomph-lib headers
36#include "generic.h"
37
38// The Poisson equations
39#include "poisson.h"
40
41// The fish mesh
42#include "meshes/fish_mesh.h"
43
44// Circle as generalised element:
46
47using namespace std;
48
49using namespace oomph;
50
51///////////////////////////////////////////////////////////////////////
52///////////////////////////////////////////////////////////////////////
53///////////////////////////////////////////////////////////////////////
54
55
56
57//====================================================================
58/// Namespace for const source term in Poisson equation
59//====================================================================
61{
62 /// Strength of source function: default value 1.0
63 double Strength=1.0;
64
65/// Const source function
66 void get_source(const Vector<double>& x, double& source)
67 {
69 }
70
71}
72
73
74////////////////////////////////////////////////////////////////////////
75////////////////////////////////////////////////////////////////////////
76////////////////////////////////////////////////////////////////////////
77
78
79
80//====================================================================
81/// Refineable Poisson problem in deformable fish-shaped domain.
82/// Template parameter identifies the element.
83//====================================================================
84template<class ELEMENT>
85class RefineableFishPoissonProblem : public Problem
86{
87
88public:
89
90 /// Constructor: Bool flag specifies if position of fish back is
91 /// prescribed or computed from the coupled problem. String specifies
92 /// output directory
94
95 /// Destructor
97
98 /// Update after Newton step: Update in response to possible changes
99 /// in the wall shape
101 {
102 fish_mesh_pt()->node_update();
103 }
104
105
106 /// Update the problem specs before solve: Update nodal positions
108 {
109 fish_mesh_pt()->node_update();
110 }
111
112 /// Update the problem specs after solve (empty)
114
115 //Access function for the fish mesh
120
121 /// Return value of the "load" on the elastically supported ring
122 /// that represents the fish's back
123 double& load()
124 {
125 return *Load_pt->value_pt(0);
126 }
127
128 /// Return value of the vertical displacement of the ring that
129 /// represents the fish's back
130 double& y_c()
131 {
132 return static_cast<ElasticallySupportedRingElement*>(fish_mesh_pt()->
133 fish_back_pt())->y_c();
134 }
135
136 /// Doc the solution
138
139 /// Access to DocInfo object
141
142private:
143
144 /// Node at which the solution of the Poisson equation is documented
145 /// This solution at this node is also used as the "load" on the ring
146 /// that represents the fish's back
148
149 /// Trace file
151
152 /// Pointer to fish mesh
154
155 /// Pointer to single-element mesh that stores the GeneralisedElement
156 /// that represents the fish's back
158
159 /// Pointer to data item that stores the "load" on the fish back
160 Data* Load_pt;
161
162 /// Is the position of the fish's back prescribed?
163 bool Fix_position;
164
165 /// Doc info object
167
168};
169
170
171
172
173
174//========================================================================
175/// Constructor for adaptive Poisson problem in deformable fish-shaped
176/// domain. Pass flag if position of fish back is fixed, and the output
177/// directory.
178//========================================================================
179template<class ELEMENT>
181 bool fix_position, string directory_name) : Fix_position(fix_position)
182{
183
184 // Set output directory
185 Doc_info.set_directory(directory_name);
186
187 // Initialise step number
188 Doc_info.number()=0;
189
190 // Open trace file
191 char filename[100];
192 snprintf(filename, sizeof(filename), "%s/trace.dat",directory_name.c_str());
193 Trace_file.open(filename);
195 << "VARIABLES=\"load\",\"y<sub>circle</sub>\",\"u<sub>control</sub>\""
196 << std::endl;
197
198 // Set coordinates and radius for the circle that will become the fish back
199 double x_c=0.5;
200 double y_c=0.0;
201 double r_back=1.0;
202
203 // Build geometric object that will become the fish back
205
206 // Build fish mesh with geometric object that specifies the fish back
208
209 // Add the fish mesh to the problem's collection of submeshes:
211
212 // Build mesh that will store only the geometric wall element
214
215 // So far, the mesh is completely empty. Let's add the
216 // one (and only!) GeneralisedElement which represents the shape
217 // of the fish's back to it:
218 Fish_back_mesh_pt->add_element_pt(dynamic_cast<GeneralisedElement*>(
219 Fish_mesh_pt->fish_back_pt()));
220
221 // Add the fish back mesh to the problem's collection of submeshes:
223
224 // Now build global mesh from the submeshes
226
227 // Create/set error estimator
228 fish_mesh_pt()->spatial_error_estimator_pt()=new Z2ErrorEstimator;
229
230
231 // Choose a node at which the solution is documented: Choose
232 // the central node that is shared by all four elements in
233 // the base mesh because it exists at all refinement levels.
234
235 // How many nodes does element 0 have?
236 unsigned nnod=fish_mesh_pt()->finite_element_pt(0)->nnode();
237
238 // The central node is the last node in element 0:
239 Doc_node_pt=fish_mesh_pt()->finite_element_pt(0)->node_pt(nnod-1);
240
241 // Doc
242 cout << std::endl << "Control node is located at: "
243 << Doc_node_pt->x(0) << " " << Doc_node_pt->x(1) << std::endl << std::endl;
244
245 // Position of fish back is prescribed
246 if (Fix_position)
247 {
248 // Create the load data object
249 Load_pt=new Data(1);
250
251 // Pin the prescribed load
252 Load_pt->pin(0);
253
254 // Pin the vertical displacement
255 dynamic_cast<ElasticallySupportedRingElement*>(
256 Fish_mesh_pt->fish_back_pt())->pin_yc();
257
258 }
259 // Coupled problem: The position of the fish back is determined
260 // via the solution of the Poisson equation: The solution at
261 // the control node acts as the load for the displacement of the
262 // fish back
263 else
264 {
265 // Use the solution (value 0) at the control node as the load
266 // that acts on the ring. [Note: Node == Data by inheritance]
268 }
269
270
271 // Set the pointer to the Data object that specifies the
272 // load on the fish's back
273 dynamic_cast<ElasticallySupportedRingElement*>(Fish_mesh_pt->fish_back_pt())->
274 set_load_pt(Load_pt);
275
276
277 // Set the boundary conditions for this problem: All nodes are
278 // free by default -- just pin the ones that have Dirichlet conditions
279 // here.
280 unsigned num_bound = fish_mesh_pt()->nboundary();
281 for(unsigned ibound=0;ibound<num_bound;ibound++)
282 {
283 unsigned num_nod= fish_mesh_pt()->nboundary_node(ibound);
284 for (unsigned inod=0;inod<num_nod;inod++)
285 {
286 fish_mesh_pt()->boundary_node_pt(ibound,inod)->pin(0);
287 }
288 }
289
290
291 // Set homogeneous boundary conditions on all boundaries
292 for(unsigned ibound=0;ibound<num_bound;ibound++)
293 {
294 // Loop over the nodes on boundary
295 unsigned num_nod=fish_mesh_pt()->nboundary_node(ibound);
296 for (unsigned inod=0;inod<num_nod;inod++)
297 {
298 fish_mesh_pt()->boundary_node_pt(ibound,inod)->set_value(0,0.0);
299 }
300 }
301
302 /// Loop over elements and set pointers to source function
303 unsigned n_element = fish_mesh_pt()->nelement();
304 for(unsigned i=0;i<n_element;i++)
305 {
306 // Upcast from FiniteElement to the present element
307 ELEMENT *el_pt = dynamic_cast<ELEMENT*>(fish_mesh_pt()->element_pt(i));
308
309 //Set the source function pointer
310 el_pt->source_fct_pt() = &ConstSourceForPoisson::get_source;
311 }
312
313 // Do equation numbering
314 cout << "Number of equations: " << assign_eqn_numbers() << std::endl;
315
316}
317
318
319
320//========================================================================
321/// Destructor for Poisson problem in deformable fish-shaped domain.
322//========================================================================
323template<class ELEMENT>
325{
326 // Close trace file
327 Trace_file.close();
328
329}
330
331
332
333
334//========================================================================
335/// Doc the solution in tecplot format.
336//========================================================================
337template<class ELEMENT>
339{
340
342 char filename[100];
343
344 // Number of plot points in each coordinate direction.
345 unsigned npts;
346 npts=5;
347
348
349 // Output solution
350 snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
351 Doc_info.number());
352 some_file.open(filename);
353 fish_mesh_pt()->output(some_file,npts);
354 some_file.close();
355
356 // Write "load" on the fish's back, vertical position of the
357 // fish back, and solution at control node to trace file
358 Trace_file
359 << static_cast<ElasticallySupportedRingElement*>(fish_mesh_pt()->
360 fish_back_pt())->load()
361 << " "
362 << static_cast<ElasticallySupportedRingElement*>(fish_mesh_pt()->
363 fish_back_pt())->y_c()
364 << " " << Doc_node_pt->value(0) << std::endl;
365}
366
367
368
369
370
371
372
373////////////////////////////////////////////////////////////////////////
374////////////////////////////////////////////////////////////////////////
375////////////////////////////////////////////////////////////////////////
376
377
378//========================================================================
379/// Demonstrate how to solve 2D Poisson problem in deformable
380/// fish-shaped domain with mesh adaptation.
381//========================================================================
382template<class ELEMENT>
384{
385
386 // Set up the problem with prescribed displacement of fish back
387 bool fix_position=true;
389
390
391 // Change/doc targets for mesh adaptation
392 if (CommandLineArgs::Argc>1)
393 {
394 problem.fish_mesh_pt()->max_permitted_error()=0.05;
395 problem.fish_mesh_pt()->min_permitted_error()=0.005;
396 }
397 else
398 {
399 problem.fish_mesh_pt()->max_permitted_error()=0.005;
400 problem.fish_mesh_pt()->min_permitted_error()=0.0005;
401 }
402 problem.fish_mesh_pt()->doc_adaptivity_targets(cout);
403
404
405 // Do some uniform mesh refinement first
406 //--------------------------------------
407 problem.refine_uniformly();
408 problem.refine_uniformly();
409
410 // Initial value for the vertical displacement of the fish's back
411 problem.y_c()=-0.3;
412
413 // Loop for different fish shapes
414 //-------------------------------
415
416 // Number of steps
417 unsigned nstep=5;
418 if (CommandLineArgs::Argc>1) nstep=1;
419
420 // Increment in displacement
421 double dyc=0.6/double(nstep-1);
422
423 // Loop over different fish shapes
424 for (unsigned istep=0;istep<nstep;istep++)
425 {
426 // Solve/doc
427 unsigned max_solve=2;
428 problem.newton_solve(max_solve);
429 problem.doc_solution();
430
431 //Increment counter for solutions
432 problem.doc_info().number()++;
433
434 // Change vertical displacement
435 problem.y_c()+=dyc;
436 }
437
438}
439
440
441//========================================================================
442/// Demonstrate how to solve coupled "elastic" 2D Poisson problem in deformable
443/// fish-shaped domain with mesh adaptation.
444//========================================================================
445template<class ELEMENT>
447{
448
449 //Set up the problem with "elastic" fish back
450 bool fix_position=false;
452
453 // Change/doc targets for mesh adaptation
454 if (CommandLineArgs::Argc>1)
455 {
456 problem.fish_mesh_pt()->max_permitted_error()=0.05;
457 problem.fish_mesh_pt()->min_permitted_error()=0.005;
458 }
459 problem.fish_mesh_pt()->doc_adaptivity_targets(cout);
460
461
462 // Do some uniform mesh refinement first
463 problem.refine_uniformly();
464 problem.refine_uniformly();
465
466 // Initial guess for "load" on fish back
467 problem.load()=0.0;
468
469 // Solve/doc fully coupled problem
470 unsigned max_solve=2;
471 problem.newton_solve(max_solve);
472 problem.doc_solution();
473
474}
475
476
477
478
479
480//========================================================================
481/// Driver for "elastic" fish poisson solver with adaptation.
482/// If there are any command line arguments, we regard this as a
483/// validation run and reduce the targets for the mesh adaptation.
484//========================================================================
485int main(int argc, char* argv[])
486{
487
488 // Store command line arguments
489 CommandLineArgs::setup(argc,argv);
490
491 // Shorthand for element type
493
494 // Compute solution of Poisson equation in various domains -- prescribed
495 // boundary shape.
497
498 // Compute coupled "elastic" coupled solution directly
499 demo_elastic_fish_poisson<ELEMENT>("RESLT_coupled");
500
501}
502
503
void demo_fish_poisson(const string &directory_name)
Demonstrate how to solve 2D Poisson problem in deformable fish-shaped domain with mesh adaptation.
int main()
Driver.
Definition circle.cc:40
Refineable Poisson problem in deformable fish-shaped domain. Template parameter identify the elements...
RefineableFishPoissonProblem(const bool &fix_position, const string &directory_name, const unsigned &i_case)
Constructor: Bool flag specifies if position of fish back is prescribed or computed from the coupled ...
virtual ~RefineableFishPoissonProblem()
Destructor.
double & load()
Return value of the "load" on the elastically supported ring that represents the fish's back.
double & y_c()
Return value of the vertical displacement of the ring that represents the fish's back.
bool Fix_position
Is the position of the fish back prescribed?
DocInfo & doc_info()
Access to DocInfo object.
void actions_before_newton_solve()
Update the problem specs before solve: Update nodal positions.
Node * Doc_node_pt
Node at which the solution of the Poisson equation is documented.
void doc_solution()
Doc the solution.
MacroElementNodeUpdateRefineableFishMesh< ELEMENT > * Fish_mesh_pt
Pointer to fish mesh.
AlgebraicRefineableFishMesh< ELEMENT > * fish_mesh_pt()
void actions_after_newton_solve()
Update the problem specs after solve (empty)
void actions_before_newton_convergence_check()
Update after Newton step: Update in response to possible changes in the wall shape.
Data * Load_pt
Pointer to data item that stores the "load" on the fish back.
Mesh * Fish_back_mesh_pt
Pointer to single-element mesh that stores the GeneralisedElement that represents the fish back.
MacroElementNodeUpdateRefineableFishMesh< ELEMENT > * fish_mesh_pt()
AlgebraicRefineableFishMesh< ELEMENT > * Fish_mesh_pt
Pointer to fish mesh.
GeneralCircle "upgraded" to a GeneralisedElement: Circular ring whose position is given by.
Namespace for const source term in Poisson equation.
void get_source(const Vector< double > &x, double &source)
Const source function.
double Strength
Strength of source function: default value 1.0.
Definition circle.h:34
void demo_elastic_fish_poisson(const string &directory_name)
Demonstrate how to solve coupled "elastic" 2D Poisson problem in deformable fish-shaped domain with m...
void demo_fish_poisson(const string &directory_name)
Demonstrate how to solve 2D Poisson problem in deformable fish-shaped domain with mesh adaptation.