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-2022 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 
38 
39 
40 //===========start_of_general_circle=========================================
54 //=========================================================================
56  public GeneralCircle
57 {
58 
59 public:
60 
64  ElasticallySupportedRingElement(const double& x_c, const double& y_c,
65  const double& r) :
67  {
68  // The geometric data is internal to the element -- we copy the pointers
69  // to the GeomObject's geometric data to the element's internal
70  // data to ensure that any unknown values of geometric data are
71  // given global equation numbers. The add_internal_data(...)
72  // function returns the index by which the added Data item
73  // is accessible from internal_data_pt(...).
75 
76  // Geometric Data for the GeomObject has been set up (and pinned) in
77  // constructor for geometric object. Now free the y-position
78  // of the centre because we want to determine it as an unknown
80 
81  // Change cleanup responsibilities: The GeomData will now be killed
82  // by the GeneralisedElement when it wipes its internal Data
83  Must_clean_up=false;
84  }
85 
86 
89  {
90  // The GeomObject's GeomData is mirrored in the element's
91  // Internal Data and therefore gets wiped in the
92  // destructor of GeneralisedElement --> No need to kill it here
93  }
94 
95 
98  void set_load_pt(Data* load_pt)
99  {
100 #ifdef PARANOID
101  if (load_pt->nvalue()!=1)
102  {
103  std::ostringstream error_stream;
104  error_stream << "The data object that stores the load on the "
105  << "ElasticallySupportedRingElement\n"
106  << "should only contain a single data value\n"
107  << "This one contains " << load_pt->nvalue() << std::endl;
108 
109  throw OomphLibError(error_stream.str(),
112  }
113 #endif
114 
115  // Add load to the element's external data and store
116  // its index within that storage scheme: Following this assignment,
117  // the load Data is accessible from
118  // GeneralisedElement::external_data_pt(External_load_index)
120 
121  // Load has now been set
123 
124  } // end of set_load_pt(...)
125 
126 
128  double load()
129  {
130  // Return the load if it has been set
132  {
134  }
135  // ...otherwise return zero load
136  else
137  {
138  return 0.0;
139  }
140  } // end of load()
141 
142 
144  double& k_stiff() {return K_stiff;}
145 
146 
148  void pin_yc()
149  {
150  // Vertical position of centre is stored as value 1 in the
151  // element's one and only internal Data object.
153  }
154 
155 
157  void unpin_yc()
158  {
159  // Vertical position of centre is stored as value 1 in the
160  // element's one and only internal Data object.
162 
163  } // end of unpin_yc()
164 
165 
167  void get_residuals(Vector<double> &residuals)
168  {
169  //Initialise residuals to zero
170  residuals.initialise(0.0);
171  //Create a dummy matrix
172  DenseMatrix<double> dummy(1);
173  //Call the generic residuals function with flag set to 0
174  fill_in_generic_residual_contribution(residuals,dummy,0);
175  }
176 
177 
179  void get_jacobian(Vector<double> &residuals,
180  DenseMatrix<double> &jacobian)
181  {
182  //Initialise residuals to zero
183  residuals.initialise(0.0);
184  //Initialise the jacobian matrix to zero
185  jacobian.initialise(0.0);
186  //Call the generic routine with the flag set to 1
187  fill_in_generic_residual_contribution(residuals,jacobian,1);
188 
189  } // end of get_jacobian(...)
190 
191 
192  protected:
193 
194 
198  DenseMatrix<double> &jacobian,
199  unsigned flag)
200  {
201  //Find out how may dofs there are in the element
202  unsigned n_dof = ndof();
203  //If everything is pinned return straight away
204  if (n_dof==0) return;
205 
206  // Pseudo-elastic force balance to determine the position of the
207  // ring's centre for a given load.
208 
209  // What's the local equation number of the force balance equation
210  // [It's the equation that "determines" the value of the internal
211  // dof, y_c, which is stored as the second value of the one-and-only
212  // internal data object in this element]
213  int local_eqn_number_for_yc =
215 
216  // Add residual to appropriate entry in the element's residual
217  // vector:
218  residuals[local_eqn_number_for_yc]=load()-K_stiff*y_c();
219 
220  // Work out Jacobian:
221  if (flag)
222  {
223  // Derivative of residual w.r.t. the internal dof, i.e. the vertical
224  // position of the ring's centre: d residual[0]/d y_c
225  jacobian(local_eqn_number_for_yc,local_eqn_number_for_yc) = -K_stiff;
226 
227 
228  // Derivative with respect to external dof, i.e. the applied
229  // load: d residual[0]/d load -- but only if the load is an unknown
230  if (n_dof==2)
231  {
232  // What's the local equation number of the load parameter?
233  // It's stored as the 0th value in the the element's
234  // one-and-only external data item:
235  int local_eqn_number_for_load =
237 
238 #ifdef PARANOID
239  if (local_eqn_number_for_load<0)
240  {
241  throw OomphLibError(
242  "Load is pinned and yet n_dof=2?\n This is very fishy!\n",
245  }
246 #endif
247 
248  // Add entry into element Jacobian
249  jacobian(local_eqn_number_for_yc,local_eqn_number_for_load) = 1.0;
250  }
251  }
252  } // end of get_residuals_generic(...)
253 
254 
255 private:
256 
258  double K_stiff;
259 
263 
267 
270 
271 };
272 
273 }
274 
275 #endif
Definition: nodes.h:86
void pin(const unsigned &i)
Pin the i-th stored variable.
Definition: nodes.h:385
void unpin(const unsigned &i)
Unpin the i-th stored variable.
Definition: nodes.h:391
unsigned nvalue() const
Return number of values stored in data object (incl pinned ones).
Definition: nodes.h:483
double value(const unsigned &i) const
Definition: nodes.h:293
void initialise(const T &val)
Initialize all values in the matrix to val.
Definition: matrices.h:514
Definition: circle_as_generalised_element.h:57
void get_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Compute element residual Vector and element Jacobian matrix (wrapper)
Definition: circle_as_generalised_element.h:179
virtual ~ElasticallySupportedRingElement()
Destructor:
Definition: circle_as_generalised_element.h:88
double load()
"Load" acting on the ring
Definition: circle_as_generalised_element.h:128
double & k_stiff()
Access function for the spring stiffness.
Definition: circle_as_generalised_element.h:144
unsigned Internal_geometric_data_index
Definition: circle_as_generalised_element.h:266
void fill_in_generic_residual_contribution(Vector< double > &residuals, DenseMatrix< double > &jacobian, unsigned flag)
Definition: circle_as_generalised_element.h:197
ElasticallySupportedRingElement(const double &x_c, const double &y_c, const double &r)
Definition: circle_as_generalised_element.h:64
unsigned External_load_index
Definition: circle_as_generalised_element.h:262
bool Load_data_has_been_set
Flag to indicate that load data has been set.
Definition: circle_as_generalised_element.h:269
double K_stiff
Stiffness of the ring's "elastic" support.
Definition: circle_as_generalised_element.h:258
void set_load_pt(Data *load_pt)
Definition: circle_as_generalised_element.h:98
void pin_yc()
Pin the vertical displacement.
Definition: circle_as_generalised_element.h:148
void unpin_yc()
Unpin the vertical displacement.
Definition: circle_as_generalised_element.h:157
void get_residuals(Vector< double > &residuals)
Compute element residual vector (wrapper)
Definition: circle_as_generalised_element.h:167
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: elements.h:73
unsigned ndof() const
Return the number of equations/dofs in the element.
Definition: elements.h:835
Data *& external_data_pt(const unsigned &i)
Return a pointer to i-th external data object.
Definition: elements.h:659
Data *& internal_data_pt(const unsigned &i)
Return a pointer to i-th internal data object.
Definition: elements.h:622
unsigned add_external_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:307
int internal_local_eqn(const unsigned &i, const unsigned &j) const
Definition: elements.h:267
int external_local_eqn(const unsigned &i, const unsigned &j)
Definition: elements.h:311
unsigned add_internal_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:62
Definition: oomph_definitions.h:222
void initialise(const _Tp &__value)
Iterate over all values and set to the desired value.
Definition: oomph-lib/src/generic/Vector.h:167
r
Definition: UniformPSDSelfTest.py:20
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86