circle.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-2023 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_HEADER
27 #define CIRCLE_HEADER
28 
29 
30 // Generic oomph-lib headers
31 #include "generic.h"
32 
33 namespace oomph
34 {
35 
36 //=====start_of_circle=====================================================
37 /// Simple circle in 2D space.
38 /// \f[ x = X_c + R \cos(\zeta) \f]
39 /// \f[ y = Y_c + R \sin(\zeta) \f]
40 //=========================================================================
41 class SimpleCircle : public GeomObject
42 {
43 
44 public:
45 
46  /// Constructor: Pass x and y-coords of centre and radius
47  SimpleCircle(const double& x_c, const double& y_c,
48  const double& r) : GeomObject(1,2), X_c(x_c), Y_c(y_c), R(r)
49  {}
50 
51  /// Position Vector at Lagrangian coordinate zeta
52  void position(const Vector<double>& zeta, Vector<double>& r) const
53  {
54  // Position vector
55  r[0] = X_c+R*cos(zeta[0]);
56  r[1] = Y_c+R*sin(zeta[0]);
57  }
58 
59  /// Position Vector at Lagrangian coordinate zeta at time level t
60  /// (t=0: present; t>0: previous level). Steady object, so we
61  /// simply forward the call to the steady version.
62  void position(const unsigned& t, const Vector<double>& zeta,
63  Vector<double>& r) const
64  {position(zeta,r);}
65 
66 protected:
67 
68  /// X-coordinate of centre
69  double X_c;
70 
71  /// Y-coordinate of centre
72  double Y_c;
73 
74  /// Radius
75  double R;
76 
77 }; // end of SimpleCircle class
78 
79 
80 
81 
82 /// ////////////////////////////////////////////////////////////////////
83 /// ////////////////////////////////////////////////////////////////////
84 /// ////////////////////////////////////////////////////////////////////
85 
86 
87 
88 //=========================================================================
89 /// GeneralCircle in 2D space.
90 /// \f[ x = X_c + R \cos(\zeta) \f]
91 /// \f[ y = Y_c + R \sin(\zeta) \f]
92 /// The three parameters \f$ X_c, Y_c \f$ and \f$ R \f$ are represented
93 /// by Data and can therefore be unknowns in the problem.
94 //=========================================================================
95 class GeneralCircle : public GeomObject
96 {
97 
98 public:
99 
100  /// Constructor: Pass x and y-coords of centre and radius (all pinned)
101  GeneralCircle(const double& x_c, const double& y_c,
102  const double& r) : GeomObject(1,2)
103  {
104  // Create Data: We have one Data item with 3 values. The Data object
105  // stores the x position of the circle's centre as value 0,
106  // the y position of the circle's centre as value 1, and the
107  // circle's radius as value 2.
108  Geom_data_pt.resize(1);
109  Geom_data_pt[0] = new Data(3);
110 
111  // Assign data: X_c -- the value is free by default: Need to pin it.
112 
113  // Pin the data
114  Geom_data_pt[0]->pin(0);
115  // Give it a value:
116  Geom_data_pt[0]->set_value(0,x_c);
117 
118  // Assign data: Y_c -- the value is free by default: Need to pin it.
119 
120  // Pin the data
121  Geom_data_pt[0]->pin(1);
122  // Give it a value:
123  Geom_data_pt[0]->set_value(1,y_c);
124 
125  // Assign data: R -- the value is free by default: Need to pin it.
126 
127  // Pin the data
128  Geom_data_pt[0]->pin(2);
129  // Give it a value:
130  Geom_data_pt[0]->set_value(2,r);
131 
132  // I've created the data, I need to clean up
133  Must_clean_up=true;
134  }
135 
136  /// Alternative constructor: Pass x and y-coords of centre and radius
137  /// (all as part of Data)
138  /// \code
139  /// Geom_data_pt[0]->value(0) = X_c;
140  /// Geom_data_pt[0]->value(1) = Y_c;
141  /// Geom_data_pt[0]->value(2) = R;
142  /// \endcode
143  GeneralCircle(Data* geom_data_pt) : GeomObject(1,2)
144  {
145 #ifdef PARANOID
146  if (geom_data_pt->nvalue()!=3)
147  {
148  std::ostringstream error_stream;
149  error_stream << "Geometric Data must have 3 values, not "
150  << geom_data_pt->nvalue() << std::endl;
151 
152  throw OomphLibError(error_stream.str(),
153  OOMPH_CURRENT_FUNCTION,
154  OOMPH_EXCEPTION_LOCATION);
155  }
156 #endif
157  Geom_data_pt.resize(1);
159 
160  // Data has been created externally: Must not clean up
161  Must_clean_up=false;
162 
163  } //end of alternative constructor
164 
165 
166  /// Destructor: Clean up if necessary
167  virtual ~GeneralCircle()
168  {
169  // Do I need to clean up?
170  if (Must_clean_up)
171  {
172  unsigned ngeom_data=Geom_data_pt.size();
173  for (unsigned i=0;i<ngeom_data;i++)
174  {
175  delete Geom_data_pt[i];
176  Geom_data_pt[i]=0;
177  }
178  }
179  } // end of destructor
180 
181 
182  /// Position Vector at Lagrangian coordinate zeta
183  void position(const Vector<double>& zeta, Vector<double>& r) const
184  {
185  // Extract data
186  double X_c= Geom_data_pt[0]->value(0);
187  double Y_c= Geom_data_pt[0]->value(1);
188  double R= Geom_data_pt[0]->value(2);
189 
190  // Position vector
191  r[0] = X_c+R*cos(zeta[0]);
192  r[1] = Y_c+R*sin(zeta[0]);
193 
194  } // end of position(...)
195 
196 
197  /// Position Vector at Lagrangian coordinate zeta at time level t
198  /// (t=0: present; t>0: previous level). Steady object, so we
199  /// simply forward the call to the steady version.
200  void position(const unsigned& t, const Vector<double>& zeta,
201  Vector<double>& r) const
202  {position(zeta,r);}
203 
204  /// Access function to x-coordinate of centre of circle
205  double& x_c(){return *Geom_data_pt[0]->value_pt(0);}
206 
207  /// Access function to y-coordinate of centre of circle
208  double& y_c(){return *Geom_data_pt[0]->value_pt(1);}
209 
210  /// Access function to radius of circle
211  double& R(){return *Geom_data_pt[0]->value_pt(2);}
212 
213  /// How many items of Data does the shape of the object depend on?
214  unsigned ngeom_data() const {return Geom_data_pt.size();}
215 
216  /// Return pointer to the j-th Data item that the object's
217  /// shape depends on
218  Data* geom_data_pt(const unsigned& j) {return Geom_data_pt[j];}
219 
220 
221 protected:
222 
223  /// Vector of pointers to Data items that affects the object's shape
224  Vector<Data*> Geom_data_pt;
225 
226  /// Do I need to clean up?
228 
229 };
230 
231 }
232 
233 #endif
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
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
virtual ~GeneralCircle()
Destructor: Clean up if necessary.
Definition: circle.h:167
bool Must_clean_up
Do I need to clean up?
Definition: circle.h:227
unsigned ngeom_data() const
How many items of Data does the shape of the object depend on?
Definition: circle.h:214
void position(const unsigned &t, const Vector< double > &zeta, Vector< double > &r) const
Position Vector at Lagrangian coordinate zeta at time level t (t=0: present; t>0: previous level)....
Definition: circle.h:200
double & x_c()
Access function to x-coordinate of centre of circle.
Definition: circle.h:205
GeneralCircle(const double &x_c, const double &y_c, const double &r)
Constructor: Pass x and y-coords of centre and radius (all pinned)
Definition: circle.h:101
void position(const Vector< double > &zeta, Vector< double > &r) const
Position Vector at Lagrangian coordinate zeta.
Definition: circle.h:183
Data * geom_data_pt(const unsigned &j)
Return pointer to the j-th Data item that the object's shape depends on.
Definition: circle.h:218
double & R()
Access function to radius of circle.
Definition: circle.h:211
double & y_c()
Access function to y-coordinate of centre of circle.
Definition: circle.h:208
GeneralCircle(Data *geom_data_pt)
Alternative constructor: Pass x and y-coords of centre and radius (all as part of Data)
Definition: circle.h:143
Simple circle in 2D space.
Definition: circle.h:42
void position(const unsigned &t, const Vector< double > &zeta, Vector< double > &r) const
Position Vector at Lagrangian coordinate zeta at time level t (t=0: present; t>0: previous level)....
Definition: circle.h:62
double Y_c
Y-coordinate of centre.
Definition: circle.h:72
SimpleCircle(const double &x_c, const double &y_c, const double &r)
Constructor: Pass x and y-coords of centre and radius.
Definition: circle.h:47
void position(const Vector< double > &zeta, Vector< double > &r) const
Position Vector at Lagrangian coordinate zeta.
Definition: circle.h:52
double X_c
X-coordinate of centre.
Definition: circle.h:69
double R
Radius.
Definition: circle.h:75
Definition: circle.h:34