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