fish_poisson_node_update.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-2024 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 // Driver for solution of 2D Poisson equation in fish-shaped domain with
27 // adaptivity and mesh updates
28 
29 // Generic oomph-lib headers
30 #include "generic.h"
31 
32 // The Poisson equations
33 #include "poisson.h"
34 
35 // The fish mesh
36 #include "meshes/fish_mesh.h"
37 
38 using namespace std;;
39 
40 using namespace oomph;
41 
42 //============ start_of_namespace=====================================
43 /// Namespace for const source term in Poisson equation
44 //====================================================================
45 namespace ConstSourceForPoisson
46 {
47 
48  /// Strength of source function: default value -1.0
49  double Strength=-1.0;
50 
51 /// Const source function
52  void get_source(const Vector<double>& x, double& source)
53  {
54  source = Strength;
55  }
56 
57 } // end of namespace
58 
59 
60 
61 
62 //======start_of_problem_class========================================
63 /// Refineable Poisson problem in fish-shaped domain.
64 /// Template parameter identifies the element type.
65 //====================================================================
66 template<class ELEMENT>
67 class RefineableFishPoissonProblem : public Problem
68 {
69 
70 public:
71 
72  /// Constructor
74 
75  /// Destructor: Empty
77 
78  /// Update the problem specs after solve (empty)
80 
81  /// Update the problem specs before solve (empty)
83 
84  /// Overloaded version of the problem's access function to
85  /// the mesh. Recasts the pointer to the base Mesh object to
86  /// the actual mesh type.
87  RefineableFishMesh<ELEMENT>* mesh_pt()
88  {
89  return dynamic_cast<RefineableFishMesh<ELEMENT>*>(Problem::mesh_pt());
90  }
91 
92  /// Doc the solution. Output directory and labels are specified
93  /// by DocInfo object
94  void doc_solution(DocInfo& doc_info);
95 
96 }; // end of problem class
97 
98 
99 
100 
101 
102 //===========start_of_constructor=========================================
103 /// Constructor for adaptive Poisson problem in fish-shaped
104 /// domain.
105 //========================================================================
106 template<class ELEMENT>
108 {
109 
110  // Build fish mesh -- this is a coarse base mesh consisting
111  // of four elements. We'll refine/adapt the mesh later.
112  Problem::mesh_pt()=new RefineableFishMesh<ELEMENT>;
113 
114  // Create/set error estimator
115  mesh_pt()->spatial_error_estimator_pt()=new Z2ErrorEstimator;
116 
117  // Set the boundary conditions for this problem: All nodes are
118  // free by default -- just pin the ones that have Dirichlet conditions
119  // here. Since the boundary values are never changed, we set
120  // them here rather than in actions_before_newton_solve().
121  unsigned num_bound = mesh_pt()->nboundary();
122  for(unsigned ibound=0;ibound<num_bound;ibound++)
123  {
124  unsigned num_nod= mesh_pt()->nboundary_node(ibound);
125  for (unsigned inod=0;inod<num_nod;inod++)
126  {
127  // Pin the single scalar value at this node
128  mesh_pt()->boundary_node_pt(ibound,inod)->pin(0);
129 
130  // Assign the homogenous boundary condition to the one
131  // and only nodal value
132  mesh_pt()->boundary_node_pt(ibound,inod)->set_value(0,0.0);
133  }
134  }
135 
136  // Loop over elements and set pointers to source function
137  unsigned n_element = mesh_pt()->nelement();
138  for(unsigned i=0;i<n_element;i++)
139  {
140  // Upcast from FiniteElement to the present element
141  ELEMENT *el_pt = dynamic_cast<ELEMENT*>(mesh_pt()->element_pt(i));
142 
143  //Set the source function pointer
144  el_pt->source_fct_pt() = &ConstSourceForPoisson::get_source;
145  }
146 
147  // Setup the equation numbering scheme
148  cout <<"Number of equations: " << assign_eqn_numbers() << std::endl;
149 
150 } // end of constructor
151 
152 
153 
154 
155 //=======start_of_doc=====================================================
156 /// Doc the solution in tecplot format.
157 //========================================================================
158 template<class ELEMENT>
160 {
161 
162  ofstream some_file;
163  char filename[100];
164 
165  // Number of plot points in each coordinate direction.
166  unsigned npts;
167  npts=5;
168 
169  // Output solution
170  sprintf(filename,"%s/soln%i.dat",doc_info.directory().c_str(),
171  doc_info.number());
172  some_file.open(filename);
173  mesh_pt()->output(some_file,npts);
174  some_file.close();
175 
176  // Output boundaries
177  sprintf(filename,"%s/boundaries%i.dat",doc_info.directory().c_str(),
178  doc_info.number());
179  some_file.open(filename);
180  mesh_pt()->output_boundaries(some_file);
181  some_file.close();
182 
183 } // end of doc
184 
185 
186 
187 
188 
189 
190 
191 //=================start_of_main==========================================
192 /// Demonstrate how to solve 2D Poisson problem in
193 /// fish-shaped domain with black-box mesh adaptation
194 /// and domain updates in response to changes in the domain
195 /// shape.
196 //========================================================================
197 int main()
198 {
199 
200  //Set up the problem with 9 node refineable Poisson elements
202 
203  // Setup labels for output
204  //------------------------
205  DocInfo doc_info;
206 
207  // Set output directory
208  doc_info.set_directory("RESLT");
209 
210  // Adjust the domain shape by changing the width of the fish
211  //----------------------------------------------------------
212  unsigned nstep=3;
213  for (unsigned i=0;i<nstep;i++)
214  {
215  // Get pointer to GeomObject that defines the position of the
216  // fish's back:
217  GeomObject* fish_back_pt=problem.mesh_pt()->fish_back_pt();
218 
219  // Recast to pointer to Circle object to get access to the member function
220  // that sets the y-position of the Circle's centre and decrease its
221  // value, making the fish narrower
222  dynamic_cast<Circle*>(fish_back_pt)->y_c()-=0.1;
223 
224  // Update the domain shape in response to the changes in its
225  // boundary
226  problem.mesh_pt()->node_update();
227 
228  // Solve the problem, allowing for up to two levels of refinement
229  problem.newton_solve(2);
230 
231  //Output solution
232  problem.doc_solution(doc_info);
233 
234  //Increment counter for solutions
235  doc_info.number()++;
236  }
237 
238 } // end of main
239 
Refineable Poisson problem in fish-shaped domain. Template parameter identifies the element type.
virtual ~RefineableFishPoissonProblem()
Destructor: Empty.
void actions_before_newton_solve()
Update the problem specs before solve (empty)
RefineableFishPoissonProblem()
Constructor.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
RefineableFishMesh< ELEMENT > * mesh_pt()
Overloaded version of the problem's access function to the mesh. Recasts the pointer to the base Mesh...
void doc_solution(DocInfo &doc_info)
Doc the solution. Output directory and labels are specified by DocInfo object.
int main()
Demonstrate how to solve 2D Poisson problem in fish-shaped domain with black-box mesh adaptation and ...
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.