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
32namespace 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//=========================================================================
53class ElasticallySupportedRingElement : public GeneralisedElement,
54 public GeneralCircle
55{
56
57public:
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) :
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(...).
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
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:
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
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(),
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)
118
119 // Load has now been set
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
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.
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.
160
161 } // end of unpin_yc()
162
163
164 /// Compute element residual vector (wrapper)
166 {
167 //Initialise residuals to zero
168 residuals.initialise(0.0);
169 //Create a dummy matrix
171 //Call the generic residuals function with flag set to 0
173 }
174
175
176 /// Compute element residual Vector and element Jacobian matrix (wrapper)
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
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)
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]
213
214 // Add residual to appropriate entry in the element's residual
215 // vector:
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
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:
235
236#ifdef PARANOID
238 {
239 throw OomphLibError(
240 "Load is pinned and yet n_dof=2?\n This is very fishy!\n",
243 }
244#endif
245
246 // Add entry into element Jacobian
248 }
249 }
250 } // end of get_residuals_generic(...)
251
252
253private:
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
261
262 /// Index of the location of the geometric Data in the element's
263 /// array of internal data
265
266 /// Flag to indicate that load data has been set
268
269};
270
271}
272
273#endif
void demo_fish_poisson(const string &directory_name)
Demonstrate how to solve 2D Poisson problem in deformable fish-shaped domain with mesh adaptation.
GeneralCircle "upgraded" to a GeneralisedElement: Circular ring whose position is given by.
void get_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Compute element residual Vector and element Jacobian matrix (wrapper)
unsigned Internal_geometric_data_index
Index of the location of the geometric Data in the element's array of internal data.
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)
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 ...
unsigned External_load_index
Index of the location of the load Data in the element's array of external data.
bool Load_data_has_been_set
Flag to indicate that load data has been set.
double K_stiff
Stiffness of the ring's "elastic" support.
void set_load_pt(Data *load_pt)
Set pointer to Data object that specifies the "load" on the ElasticallySupportedRingElement.
void pin_yc()
Pin the vertical displacement.
void unpin_yc()
Unpin the vertical displacement.
void get_residuals(Vector< double > &residuals)
Compute element residual vector (wrapper)
double & k_stiff()
Access function for the spring stiffness.
GeneralCircle in 2D space.
Definition circle.h:96
Vector< Data * > Geom_data_pt
Vector of pointers to Data items that affects the object's shape.
Definition circle.h:224
bool Must_clean_up
Do I need to clean up?
Definition circle.h:227
double & x_c()
Access function to x-coordinate of centre of circle.
Definition circle.h:205
double & y_c()
Access function to y-coordinate of centre of circle.
Definition circle.h:208
Definition circle.h:34