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