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