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