Toggle navigation
Documentation
Big picture
The finite element method
The data structure
Not-so-quick guide
Optimisation
Order of action functions
Example codes and tutorials
List of example codes and tutorials
Meshing
Solvers
MPI parallel processing
Post-processing/visualisation
Other
Change log
Creating documentation
Coding conventions
Index
FAQ
Get it
Installation guide
Get code from subversion repository
Get code as tar file
Copyright
About
People
Contact/Get involved
Publications
Acknowledgements
Picture show
Go
demo_drivers
poisson
fish_poisson2
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
//============ start_of_namespace=====================================
46
/// Namespace for const source term in Poisson equation
47
//====================================================================
48
namespace
ConstSourceForPoisson
49
{
50
51
/// Strength of source function: default value -1.0
52
double
Strength
=-1.0;
53
54
/// Const source function
55
void
get_source
(
const
Vector<double>& x,
double
& source)
56
{
57
source =
Strength
;
58
}
59
60
}
// end of namespace
61
62
63
64
65
//======start_of_problem_class========================================
66
/// Poisson problem in fish-shaped domain.
67
/// Template parameter identifies the element type.
68
//====================================================================
69
template
<
class
ELEMENT>
70
class
FishPoissonProblem
:
public
Problem
71
{
72
73
public
:
74
75
/// Constructor
76
FishPoissonProblem
();
77
78
/// Destructor: Empty
79
virtual
~FishPoissonProblem
(){}
80
81
/// Update the problem specs after solve (empty)
82
void
actions_after_newton_solve
() {}
83
84
/// Update the problem specs before solve (empty)
85
void
actions_before_newton_solve
() {}
86
87
/// \short Overloaded version of the problem's access function to
88
/// the mesh. Recasts the pointer to the base Mesh object to
89
/// the actual mesh type.
90
FishMesh<ELEMENT>*
mesh_pt
()
91
{
92
return
dynamic_cast<
FishMesh<ELEMENT>*
>
(Problem::mesh_pt());
93
}
94
95
/// \short Doc the solution. Output directory and labels are specified
96
/// by DocInfo object
97
void
doc_solution(DocInfo& doc_info);
98
99
};
// end of problem class
100
101
102
103
104
105
//===========start_of_constructor=========================================
106
/// Constructor for Poisson problem in fish-shaped
107
/// domain.
108
//========================================================================
109
template
<
class
ELEMENT>
110
FishPoissonProblem<ELEMENT>::FishPoissonProblem
()
111
{
112
113
// Build fish mesh -- this is a coarse base mesh consisting
114
// of four elements.
115
Problem::mesh_pt()=
new
FishMesh<ELEMENT>;
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 and
131
// 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>
159
void
FishPoissonProblem<ELEMENT>::doc_solution
(DocInfo& doc_info)
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
}
// end of doc
177
178
179
180
181
182
183
//=====================start_of_main======================================
184
/// Demonstrate how to solve 2D Poisson problem in
185
/// fish-shaped domain.
186
//========================================================================
187
int
main
()
188
{
189
190
//Set up the problem with 4 node Poisson elements
191
FishPoissonProblem<QPoissonElement<2,2>
> problem;
192
193
// Setup labels for output
194
//------------------------
195
DocInfo doc_info;
196
197
// Set output directory
198
doc_info.set_directory(
"RESLT"
);
199
200
// Step number
201
doc_info.number()=0;
202
203
204
// Solve/doc the problem
205
//----------------------
206
207
// Solve the problem
208
problem.newton_solve();
209
210
//Output solution
211
problem.
doc_solution
(doc_info);
212
213
//Increment counter for solutions
214
doc_info.number()++;
215
216
217
}
// end of main
218
219
220
main
int main()
Definition:
fish_poisson_no_adapt.cc:187
std
ConstSourceForPoisson::Strength
double Strength
Strength of source function: default value -1.0.
Definition:
fish_poisson_adapt.cc:53
oomph
ConstSourceForPoisson::get_source
void get_source(const Vector< double > &x, double &source)
Const source function.
Definition:
fish_poisson_adapt.cc:56
FishPoissonProblem
Definition:
fish_poisson_no_adapt.cc:70
FishPoissonProblem::actions_after_newton_solve
void actions_after_newton_solve()
Update the problem specs after solve (empty)
Definition:
fish_poisson_no_adapt.cc:82
FishPoissonProblem::~FishPoissonProblem
virtual ~FishPoissonProblem()
Destructor: Empty.
Definition:
fish_poisson_no_adapt.cc:79
FishPoissonProblem::mesh_pt
FishMesh< ELEMENT > * mesh_pt()
Overloaded version of the problem's access function to the mesh. Recasts the pointer to the base Mesh...
Definition:
fish_poisson_no_adapt.cc:90
FishPoissonProblem::doc_solution
void doc_solution(DocInfo &doc_info)
Doc the solution. Output directory and labels are specified by DocInfo object.
Definition:
fish_poisson_no_adapt.cc:159
FishPoissonProblem::FishPoissonProblem
FishPoissonProblem()
Constructor.
Definition:
fish_poisson_no_adapt.cc:110
FishPoissonProblem::actions_before_newton_solve
void actions_before_newton_solve()
Update the problem specs before solve (empty)
Definition:
fish_poisson_no_adapt.cc:85
ConstSourceForPoisson
Namespace for const source term in Poisson equation.
Definition:
fish_poisson_adapt.cc:49