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
About
People
Contact/Get involved
Publications
Acknowledgements
Copyright
Picture show
Go
demo_drivers
interaction
free_boundary_poisson
circle_as_generalised_element.h
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
#ifndef CIRCLE_AS_GEN_ELEMENT_HEADER
27
#define CIRCLE_AS_GEN_ELEMENT_HEADER
28
29
#include "
circle.h
"
30
31
32
namespace
oomph
33
{
34
35
//////////////////////////////////////////////////////////////////////////
36
//////////////////////////////////////////////////////////////////////////
37
//////////////////////////////////////////////////////////////////////////
38
39
40
//===========start_of_general_circle=========================================
41
/// GeneralCircle "upgraded" to a GeneralisedElement: Circular
42
/// ring whose position is given by
43
/// \f[ x = X_c + R \cos(\zeta) \f]
44
/// \f[ y = Y_c + R \sin(\zeta) \f]
45
/// The ring's vertical position \f$ Y_c \f$ is
46
/// determined by "pseudo elasticity":
47
/// \f[ 0 = f_{load} - Y_c \ k_{stiff} \f]
48
/// This simulates the case where the centre of the ring is mounted on
49
/// an elastic spring of stiffness \f$ k_{stiff} \f$ and loaded by
50
/// the force \f$ f_{load}. \f$ The "load" is specified by the
51
/// Data object \c load_pt().
52
//=========================================================================
53
class
ElasticallySupportedRingElement
:
public
GeneralisedElement,
54
public
GeneralCircle
55
{
56
57
public
:
58
59
/// Constructor: Build ring from doubles that describe
60
/// the geometry: x and y positions of centre and the radius.
61
/// Initialise stiffness to 1.0. By default, no load is set.
62
ElasticallySupportedRingElement
(
const
double
&
x_c
,
const
double
&
y_c
,
63
const
double
&
r
) :
64
GeneralCircle
(
x_c
,
y_c
,
r
),
K_stiff
(1.0),
Load_data_has_been_set
(
false
)
65
{
66
// The geometric data is internal to the element -- we copy the pointers
67
// to the GeomObject's geometric data to the element's internal
68
// data to ensure that any unknown values of geometric data are
69
// given global equation numbers. The add_internal_data(...)
70
// function returns the index by which the added Data item
71
// is accessible from internal_data_pt(...).
72
Internal_geometric_data_index
=
add_internal_data
(
Geom_data_pt
[0]);
73
74
// Geometric Data for the GeomObject has been set up (and pinned) in
75
// constructor for geometric object. Now free the y-position
76
// of the centre because we want to determine it as an unknown
77
internal_data_pt
(
Internal_geometric_data_index
)->unpin(1);
78
79
// Change cleanup responsibilities: The GeomData will now be killed
80
// by the GeneralisedElement when it wipes its internal Data
81
Must_clean_up
=
false
;
82
}
83
84
85
/// Destructor:
86
virtual
~ElasticallySupportedRingElement
()
87
{
88
// The GeomObject's GeomData is mirrored in the element's
89
// Internal Data and therefore gets wiped in the
90
// destructor of GeneralisedElement --> No need to kill it here
91
}
92
93
94
/// Set pointer to Data object that specifies the "load"
95
/// on the ElasticallySupportedRingElement
96
void
set_load_pt
(
Data
*
load_pt
)
97
{
98
#ifdef PARANOID
99
if
(
load_pt
->nvalue()!=1)
100
{
101
std::ostringstream
error_stream
;
102
error_stream
<<
"The data object that stores the load on the "
103
<<
"ElasticallySupportedRingElement\n"
104
<<
"should only contain a single data value\n"
105
<<
"This one contains "
<<
load_pt
->nvalue() << std::endl;
106
107
throw
OomphLibError
(
error_stream
.str(),
108
OOMPH_CURRENT_FUNCTION
,
109
OOMPH_EXCEPTION_LOCATION
);
110
}
111
#endif
112
113
// Add load to the element's external data and store
114
// its index within that storage scheme: Following this assignment,
115
// the load Data is accessible from
116
// GeneralisedElement::external_data_pt(External_load_index)
117
External_load_index
=
add_external_data
(
load_pt
);
118
119
// Load has now been set
120
Load_data_has_been_set
=
true
;
121
122
}
// end of set_load_pt(...)
123
124
125
/// "Load" acting on the ring
126
double
load
()
127
{
128
// Return the load if it has been set
129
if
(
Load_data_has_been_set
)
130
{
131
return
external_data_pt
(
External_load_index
)->value(0);
132
}
133
// ...otherwise return zero load
134
else
135
{
136
return
0.0;
137
}
138
}
// end of load()
139
140
141
/// Access function for the spring stiffness
142
double
&
k_stiff
() {
return
K_stiff
;}
143
144
145
/// Pin the vertical displacement
146
void
pin_yc
()
147
{
148
// Vertical position of centre is stored as value 1 in the
149
// element's one and only internal Data object.
150
internal_data_pt
(
Internal_geometric_data_index
)->pin(1);
151
}
152
153
154
/// Unpin the vertical displacement
155
void
unpin_yc
()
156
{
157
// Vertical position of centre is stored as value 1 in the
158
// element's one and only internal Data object.
159
internal_data_pt
(
Internal_geometric_data_index
)->unpin(1);
160
161
}
// end of unpin_yc()
162
163
164
/// Compute element residual vector (wrapper)
165
void
get_residuals
(
Vector<double>
&
residuals
)
166
{
167
//Initialise residuals to zero
168
residuals
.initialise(0.0);
169
//Create a dummy matrix
170
DenseMatrix<double>
dummy
(1);
171
//Call the generic residuals function with flag set to 0
172
fill_in_generic_residual_contribution
(
residuals
,
dummy
,0);
173
}
174
175
176
/// Compute element residual Vector and element Jacobian matrix (wrapper)
177
void
get_jacobian
(
Vector<double>
&
residuals
,
178
DenseMatrix<double>
&
jacobian
)
179
{
180
//Initialise residuals to zero
181
residuals
.initialise(0.0);
182
//Initialise the jacobian matrix to zero
183
jacobian
.initialise(0.0);
184
//Call the generic routine with the flag set to 1
185
fill_in_generic_residual_contribution
(
residuals
,
jacobian
,1);
186
187
}
// end of get_jacobian(...)
188
189
190
protected
:
191
192
193
/// Compute element residual Vector (only if flag=0) and also
194
/// the element Jacobian matrix (if flag=1)
195
void
fill_in_generic_residual_contribution
(
Vector<double>
&
residuals
,
196
DenseMatrix<double>
&
jacobian
,
197
unsigned
flag
)
198
{
199
//Find out how may dofs there are in the element
200
unsigned
n_dof
=
ndof
();
201
//If everything is pinned return straight away
202
if
(
n_dof
==0)
return
;
203
204
// Pseudo-elastic force balance to determine the position of the
205
// ring's centre for a given load.
206
207
// What's the local equation number of the force balance equation
208
// [It's the equation that "determines" the value of the internal
209
// dof, y_c, which is stored as the second value of the one-and-only
210
// internal data object in this element]
211
int
local_eqn_number_for_yc
=
212
internal_local_eqn
(
Internal_geometric_data_index
,1);
213
214
// Add residual to appropriate entry in the element's residual
215
// vector:
216
residuals
[
local_eqn_number_for_yc
]=
load
()-
K_stiff
*
y_c
();
217
218
// Work out Jacobian:
219
if
(
flag
)
220
{
221
// Derivative of residual w.r.t. the internal dof, i.e. the vertical
222
// position of the ring's centre: d residual[0]/d y_c
223
jacobian
(
local_eqn_number_for_yc
,
local_eqn_number_for_yc
) = -
K_stiff
;
224
225
226
// Derivative with respect to external dof, i.e. the applied
227
// load: d residual[0]/d load -- but only if the load is an unknown
228
if
(
n_dof
==2)
229
{
230
// What's the local equation number of the load parameter?
231
// It's stored as the 0th value in the the element's
232
// one-and-only external data item:
233
int
local_eqn_number_for_load
=
234
external_local_eqn
(
External_load_index
,0);
235
236
#ifdef PARANOID
237
if
(
local_eqn_number_for_load
<0)
238
{
239
throw
OomphLibError
(
240
"Load is pinned and yet n_dof=2?\n This is very fishy!\n"
,
241
OOMPH_CURRENT_FUNCTION
,
242
OOMPH_EXCEPTION_LOCATION
);
243
}
244
#endif
245
246
// Add entry into element Jacobian
247
jacobian
(
local_eqn_number_for_yc
,
local_eqn_number_for_load
) = 1.0;
248
}
249
}
250
}
// end of get_residuals_generic(...)
251
252
253
private
:
254
255
/// Stiffness of the ring's "elastic" support
256
double
K_stiff
;
257
258
/// Index of the location of the load Data in the element's
259
/// array of external data
260
unsigned
External_load_index
;
261
262
/// Index of the location of the geometric Data in the element's
263
/// array of internal data
264
unsigned
Internal_geometric_data_index
;
265
266
/// Flag to indicate that load data has been set
267
bool
Load_data_has_been_set
;
268
269
};
270
271
}
272
273
#endif
demo_fish_poisson
void demo_fish_poisson(const string &directory_name)
Demonstrate how to solve 2D Poisson problem in deformable fish-shaped domain with mesh adaptation.
Definition
algebraic_free_boundary_poisson.cc:460
circle.h
oomph::ElasticallySupportedRingElement
GeneralCircle "upgraded" to a GeneralisedElement: Circular ring whose position is given by.
Definition
circle_as_generalised_element.h:55
oomph::ElasticallySupportedRingElement::get_jacobian
void get_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Compute element residual Vector and element Jacobian matrix (wrapper)
Definition
circle_as_generalised_element.h:177
oomph::ElasticallySupportedRingElement::~ElasticallySupportedRingElement
virtual ~ElasticallySupportedRingElement()
Destructor:
Definition
circle_as_generalised_element.h:86
oomph::ElasticallySupportedRingElement::load
double load()
"Load" acting on the ring
Definition
circle_as_generalised_element.h:126
oomph::ElasticallySupportedRingElement::Internal_geometric_data_index
unsigned Internal_geometric_data_index
Index of the location of the geometric Data in the element's array of internal data.
Definition
circle_as_generalised_element.h:264
oomph::ElasticallySupportedRingElement::fill_in_generic_residual_contribution
void fill_in_generic_residual_contribution(Vector< double > &residuals, DenseMatrix< double > &jacobian, unsigned flag)
Compute element residual Vector (only if flag=0) and also the element Jacobian matrix (if flag=1)
Definition
circle_as_generalised_element.h:195
oomph::ElasticallySupportedRingElement::ElasticallySupportedRingElement
ElasticallySupportedRingElement(const double &x_c, const double &y_c, const double &r)
Constructor: Build ring from doubles that describe the geometry: x and y positions of centre and the ...
Definition
circle_as_generalised_element.h:62
oomph::ElasticallySupportedRingElement::External_load_index
unsigned External_load_index
Index of the location of the load Data in the element's array of external data.
Definition
circle_as_generalised_element.h:260
oomph::ElasticallySupportedRingElement::Load_data_has_been_set
bool Load_data_has_been_set
Flag to indicate that load data has been set.
Definition
circle_as_generalised_element.h:267
oomph::ElasticallySupportedRingElement::K_stiff
double K_stiff
Stiffness of the ring's "elastic" support.
Definition
circle_as_generalised_element.h:256
oomph::ElasticallySupportedRingElement::set_load_pt
void set_load_pt(Data *load_pt)
Set pointer to Data object that specifies the "load" on the ElasticallySupportedRingElement.
Definition
circle_as_generalised_element.h:96
oomph::ElasticallySupportedRingElement::pin_yc
void pin_yc()
Pin the vertical displacement.
Definition
circle_as_generalised_element.h:146
oomph::ElasticallySupportedRingElement::unpin_yc
void unpin_yc()
Unpin the vertical displacement.
Definition
circle_as_generalised_element.h:155
oomph::ElasticallySupportedRingElement::get_residuals
void get_residuals(Vector< double > &residuals)
Compute element residual vector (wrapper)
Definition
circle_as_generalised_element.h:165
oomph::ElasticallySupportedRingElement::k_stiff
double & k_stiff()
Access function for the spring stiffness.
Definition
circle_as_generalised_element.h:142
oomph::GeneralCircle
GeneralCircle in 2D space.
Definition
circle.h:96
oomph::GeneralCircle::Geom_data_pt
Vector< Data * > Geom_data_pt
Vector of pointers to Data items that affects the object's shape.
Definition
circle.h:224
oomph::GeneralCircle::Must_clean_up
bool Must_clean_up
Do I need to clean up?
Definition
circle.h:227
oomph::GeneralCircle::x_c
double & x_c()
Access function to x-coordinate of centre of circle.
Definition
circle.h:205
oomph::GeneralCircle::y_c
double & y_c()
Access function to y-coordinate of centre of circle.
Definition
circle.h:208
oomph
Definition
circle.h:34