macro_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// 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 OOMPH_MACROELEMENT_HEADER
31 #define OOMPH_MACROELEMENT_HEADER
32 
33 
34 // Config header generated by autoconfig
35 #ifdef HAVE_CONFIG_H
36  #include <oomph-lib-config.h>
37 #endif
38 
39 #ifdef OOMPH_HAS_MPI
40 #include "mpi.h"
41 #endif
42 
43 //oomph-lib headers
44 #include "Vector.h"
45 #include "oomph_utilities.h"
46 #include "quadtree.h"
47 #include "octree.h"
48 
49 namespace oomph
50 {
51 
52 class Domain;
53 
54 //================================================================
55 /// Base class for MacroElement s that are used during mesh refinement
56 /// in domains with curvlinear and/or time-dependent
57 /// boundaries; see the description of the Domain class for more
58 /// details.
59 ///
60 /// A macro element provides a parametrisation of a sub-domain
61 /// by providing a mapping between a set of local coordinates
62 /// \f$ {\bf S} \f$ and global coordinates \f$ {\bf r} ({\bf S}) \f$ . This
63 /// must be implemented in the function
64 ///
65 /// \code MacroElement::macro_map(...) \endcode
66 ///
67 /// The time-dependent version of the macro map returns the mapping
68 /// from local to global coordinates: \f$ {\bf r} (t,{\bf S}) \f$
69 /// where t is the discrete timelevel: t=0: current time; t>0:
70 /// previous timestep.
71 ///
72 /// The MacroElement s establish the current (and previous) domain
73 /// shape via member function pointers to the Domain 's
74 /// \code Domain::macro_element_boundary(...) \endcode
75 /// member function.
76 //=================================================================
78 {
79 
80  public:
81 
82  /// \short Constructor: Pass pointer to Domain and the number of the
83  /// MacroElement within that Domain.
85  : Domain_pt(domain_pt), Macro_element_number(macro_element_number)
86  {
87 #ifdef LEAK_CHECK
89 #endif
90  }
91 
92  /// Default constructor (empty and broken)
94  {
95  throw OomphLibError("Don't call empty constructor for MacroElement!",
96  OOMPH_CURRENT_FUNCTION,
97  OOMPH_EXCEPTION_LOCATION);
98  }
99 
100  /// Broken copy constructor
101  MacroElement(const MacroElement& dummy)
102  {
103  BrokenCopy::broken_copy("MacroElement");
104  }
105 
106  /// Broken assignment operator
107  void operator=(const MacroElement&)
108  {
109  BrokenCopy::broken_assign("MacroElement");
110  }
111 
112 
113  /// Empty destructor
114  virtual ~MacroElement()
115  {
116 #ifdef LEAK_CHECK
118 #endif
119  }
120 
121 
122  /// \short Plot: x,y (or x,y,z) at current time in tecplot
123  /// format
124  void output(std::ostream &outfile, const int& nplot)
125  {
126  unsigned t=0;
127  output(t,outfile,nplot);
128  }
129 
130 
131  /// \short Plot: x,y (or x,y,z) in tecplot format at time level t
132  /// (t=0: current; t>0: previous)
133  virtual void output(const unsigned & t, std::ostream &outfile,
134  const unsigned& nplot)=0;
135 
136 
137 
138  /// The mapping from local to global coordinates at the current time : r(s)
140  {
141  // Evaluate at current timestep
142  unsigned t=0;
143  macro_map(t,s,r);
144  }
145 
146 
147  ///\short The time-dependent mapping from local to global coordinates: r(t,s).
148  /// t is the discrete timelevel: t=0: current time; t>0: previous timestep.
149  virtual void macro_map(const unsigned& t, const Vector<double>& s,
150  Vector<double>& r)=0;
151 
152  /// \short Output all macro element boundaries as tecplot zones
153  virtual void output_macro_element_boundaries(std::ostream &outfile,
154  const unsigned& nplot)=0;
155 
156 
157  ///\short the jacobian of the mapping from the macro coordinates to the global
158  /// coordinates
159  virtual void assemble_macro_to_eulerian_jacobian(const unsigned& t,
160  const Vector<double>& s,
162  jacobian)
163  {
164  // error message stream
165  std::ostringstream error_message;
166  error_message << "assemble_macro_to_eulerian_jacobian(...) not \n"
167  << "implemented for this element\n" << std::endl;
168  // throw error
169  throw OomphLibError(error_message.str(),
170  OOMPH_CURRENT_FUNCTION,
171  OOMPH_EXCEPTION_LOCATION);
172  }
173 
174 
175  ///\short Assembles the second derivative jacobian of the mapping from the
176  /// macro coordinates to the global coordinates
177  virtual void assemble_macro_to_eulerian_jacobian2(const unsigned& t,
178  const Vector<double>& s,
180  jacobian2)
181  {
182  // error message stream
183  std::ostringstream error_message;
184  error_message << "assemble_macro_to_eulerian_jacobian2(...) not \n"
185  << "implemented for this element\n" << std::endl;
186  // throw error
187  throw OomphLibError(error_message.str(),
188  OOMPH_CURRENT_FUNCTION,
189  OOMPH_EXCEPTION_LOCATION);
190  }
191 
192 
193 
194  ///\short Assembles the jacobian of the mapping from the macro coordinates to
195  /// the global coordinates
197  DenseMatrix<double>& jacobian)
198  {
199  unsigned t = 0;
201  }
202 
203 
204  ///\short Assembles the second derivative jacobian of the mapping from the
205  /// macro coordinates to the global coordinates
207  DenseMatrix<double>& jacobian2)
208  {
209  unsigned t = 0;
211  }
212 
213  ///\short Access function to the Macro_element_number
215  {
216  return Macro_element_number;
217  }
218 
219  ///\short Access function to the Domain_pt
221  {
222  return Domain_pt;
223  }
224 
225  protected:
226 
227  /// Pointer to domain
229 
230  /// What is the number of the current macro element within its domain
232 
233 };
234 
235 
236 
237 ///////////////////////////////////////////////////////////////////////////
238 ///////////////////////////////////////////////////////////////////////////
239 ///////////////////////////////////////////////////////////////////////////
240 
241 
242 //================================================================
243 /// QMacroElement
244 ///
245 /// QMacroElements are MacroElement s with linear/quadrilateral/hexahedral
246 /// shape. This class is empty and simply establishes the dimension
247 /// as the template parameter.
248 //=================================================================
249 template<int DIM>
251 {
252 };
253 
254 
255 
256 
257 
258 //================================================================
259 /// QMacroElement specialised to 2 spatial dimensions.
260 ///
261 /// The macro element mapping is based on the member function pointer
262 /// to the associated Domain 's
263 /// \code Domain::macro_element_boundary(...) \endcode
264 /// function which provides a parametrisation of the macro element's
265 /// boundaries in the form:
266 /// \f[ {\bf f}_{i} (t,{\bf S}) \f]
267 /// where
268 /// - \f$ i \f$ labels the boundary (N/S/W/E)
269 /// - \f$ {\bf S} \in [-1,1]^1 \f$ is the (1D) Vector of local coordinate(s)
270 /// along the boundary.
271 /// - \f$ {\bf f} \f$ is the position Vector to the boundary.
272 /// - \f$ t \f$ is the time level (t=0: current; t>0 previous timestep)
273 //=================================================================
274 template<>
275 class QMacroElement<2> : public MacroElement
276 {
277 
278 public:
279 
280  /// \short Constructor: Pass the pointer to the domain and the macro element's
281  /// number within this domain
283  MacroElement(domain_pt,macro_element_number) {};
284 
285 
286  /// Default constructor (empty and broken)
288  {
289  throw OomphLibError("Don't call empty constructor for QMacroElement!",
290  OOMPH_CURRENT_FUNCTION,
291  OOMPH_EXCEPTION_LOCATION);
292  }
293 
294  /// Broken copy constructor
296  {
297  BrokenCopy::broken_copy("QMacroElement");
298  }
299 
300  /// Broken assignment operator
301  void operator=(const QMacroElement&)
302  {
303  BrokenCopy::broken_assign("QMacroElement");
304  }
305 
306  /// Empty destructor
307  virtual ~QMacroElement(){};
308 
309 
310  /// \short Plot: x,y in tecplot format at time level t (t=0: current;
311  /// t>0: previous)
312  void output(const unsigned& t, std::ostream &outfile, const unsigned& nplot)
313  {
314  Vector<double> x(2),f(2);
315  outfile << "ZONE I=" << nplot << ", J=" << nplot << std::endl;
316  for (unsigned i=0;i<nplot;i++)
317  {
318  x[1]=-1.0+2.0*double(i)/double(nplot-1);
319  for (unsigned j=0;j<nplot;j++)
320  {
321  x[0]=-1.0+2.0*double(j)/double(nplot-1);
322  macro_map(t,x,f);
323  outfile << f[0] << " " << f[1] << std::endl;
324  }
325  }
326  }
327 
328 
329  /// \short Output all macro element boundaries as tecplot zones
330  void output_macro_element_boundaries(std::ostream &outfile,
331  const unsigned& nplot);
332 
333  /// \short Get global position r(S) at discrete time level t.
334  /// t=0: Present time; t>0: previous timestep.
335  void macro_map(const unsigned& t,
336  const Vector<double>& S,
337  Vector<double>& r);
338 
339 
340  ///\short assemble the jacobian of the mapping from the macro coordinates to
341  /// the global coordinates
342  virtual void assemble_macro_to_eulerian_jacobian(const unsigned& t,
343  const Vector<double>& s,
344  DenseMatrix<double>& jacobian);
345 
346 
347  /// \short Assembles the second derivative jacobian of the mapping from the
348  /// macro coordinates to global coordinates x
349  virtual void assemble_macro_to_eulerian_jacobian2(const unsigned& t,
350  const Vector<double>& s,
351  DenseMatrix<double>& jacobian2);
352 
353 };
354 
355 
356 
357 
358 //================================================================
359 /// QMacroElement specialised to 3 spatial dimensions.
360 ///
361 /// The macro element mapping is based on the member function pointer
362 /// to the associated Domain 's
363 /// \code Domain::macro_element_boundary(...) \endcode
364 /// function which provides a parametrisation of the macro element's
365 /// boundaries in the form:
366 /// \f[ {\bf f}_{i} (t,{\bf S}) \f]
367 /// where
368 /// - \f$ i \f$ labels the boundary (L/R/D/U/B/F)
369 /// - \f$ {\bf S} \in [-1,1]^2 \f$ is the (2D) Vector of local coordinate(s)
370 /// along the boundary.
371 /// - \f$ {\bf f} \f$ is the position Vector to the boundary.
372 /// - \f$ t \f$ is the time level (t=0: current; t>0 previous timestep)
373 //=================================================================
374 template<>
375 class QMacroElement<3> : public MacroElement
376 {
377 
378 
379 public:
380 
381  /// \short Constructor: Pass the pointer to the domain and the macro element's
382  /// number within this domain
384  MacroElement(domain_pt,macro_element_number) {};
385 
386  /// Default constructor (empty and broken)
388  {
389  throw OomphLibError("Don't call empty constructor for QMacroElement!",
390  OOMPH_CURRENT_FUNCTION,
391  OOMPH_EXCEPTION_LOCATION);
392  }
393 
394  /// Broken copy constructor
396  {
397  BrokenCopy::broken_copy("QMacroElement");
398  }
399 
400  /// Broken assignment operator
401  void operator=(const QMacroElement&)
402  {
403  BrokenCopy::broken_assign("QMacroElement");
404  }
405 
406 
407  /// Empty destructor
408  virtual ~QMacroElement(){};
409 
410 
411  /// \short Plot: x,y in tecplot format at time level t (t=0: current;
412  /// t>0: previous)
413  void output(const unsigned& t, std::ostream &outfile, const unsigned& nplot)
414  {
415 
416  Vector<double> x(3),f(3);
417 
418  outfile << "ZONE I=" << nplot << ", J="
419  << nplot <<", k=" << nplot << std::endl;
420  for (unsigned i=0;i<nplot;i++)
421  {
422  x[2]=-1.0+2.0*double(i)/double(nplot-1);
423 
424  for (unsigned j=0;j<nplot;j++)
425  {
426  x[1]=-1.0+2.0*double(j)/double(nplot-1);
427 
428  for (unsigned k=0;k<nplot;k++)
429  {
430  x[0]=-1.0+2.0*double(k)/double(nplot-1);
431 
432  macro_map(t,x,f);
433 
434  outfile << f[0] << " " << f[1]<< " " << f[2] << std::endl;
435 
436  }
437  }
438  }
439  }
440 
441 
442  /// \short Output all macro element boundaries as tecplot zones
443  void output_macro_element_boundaries(std::ostream &outfile,
444  const unsigned& nplot);
445 
446  /// \short Get global position r(S) at discrete time level t.
447  /// t=0: Present time; t>0: previous timestep.
448  void macro_map(const unsigned& t,
449  const Vector<double>& S,
450  Vector<double>& r);
451 
452 };
453 
454 }
455 
456 #endif
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
unsigned & macro_element_number()
Access function to the Macro_element_number.
void output(const unsigned &t, std::ostream &outfile, const unsigned &nplot)
Plot: x,y in tecplot format at time level t (t=0: current; t>0: previous)
QMacroElement()
Default constructor (empty and broken)
virtual void assemble_macro_to_eulerian_jacobian(const unsigned &t, const Vector< double > &s, DenseMatrix< double > &jacobian)
the jacobian of the mapping from the macro coordinates to the global coordinates
virtual void output_macro_element_boundaries(std::ostream &outfile, const unsigned &nplot)=0
Output all macro element boundaries as tecplot zones.
cstr elem_len * i
Definition: cfortran.h:607
QMacroElement(Domain *domain_pt, const unsigned &macro_element_number)
Constructor: Pass the pointer to the domain and the macro element&#39;s number within this domain...
virtual ~MacroElement()
Empty destructor.
QMacroElement(const QMacroElement &dummy)
Broken copy constructor.
void operator=(const QMacroElement &)
Broken assignment operator.
char t
Definition: cfortran.h:572
virtual ~QMacroElement()
Empty destructor.
Domain *& domain_pt()
Access function to the Domain_pt.
Domain * Domain_pt
Pointer to domain.
void assemble_macro_to_eulerian_jacobian(const Vector< double > &s, DenseMatrix< double > &jacobian)
Assembles the jacobian of the mapping from the macro coordinates to the global coordinates.
virtual ~QMacroElement()
Empty destructor.
static char t char * s
Definition: cfortran.h:572
void macro_map(const Vector< double > &s, Vector< double > &r)
The mapping from local to global coordinates at the current time : r(s)
QMacroElement(Domain *domain_pt, const unsigned &macro_element_number)
Constructor: Pass the pointer to the domain and the macro element&#39;s number within this domain...
virtual void assemble_macro_to_eulerian_jacobian2(const unsigned &t, const Vector< double > &s, DenseMatrix< double > &jacobian2)
Assembles the second derivative jacobian of the mapping from the macro coordinates to the global coor...
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
void output(std::ostream &outfile, const int &nplot)
Plot: x,y (or x,y,z) at current time in tecplot format.
unsigned Macro_element_number
What is the number of the current macro element within its domain.
QMacroElement(const QMacroElement &dummy)
Broken copy constructor.
MacroElement()
Default constructor (empty and broken)
Definition: macro_element.h:93
MacroElement(const MacroElement &dummy)
Broken copy constructor.
void operator=(const MacroElement &)
Broken assignment operator.
void assemble_macro_to_eulerian_jacobian2(const Vector< double > &s, DenseMatrix< double > &jacobian2)
Assembles the second derivative jacobian of the mapping from the macro coordinates to the global coor...
void operator=(const QMacroElement &)
Broken assignment operator.
MacroElement(Domain *domain_pt, const unsigned &macro_element_number)
Constructor: Pass pointer to Domain and the number of the MacroElement within that Domain...
Definition: macro_element.h:84
Base class for Domains with curvilinear and/or time-dependent boundaries. Domain boundaries are typic...
Definition: domain.h:71
void output(const unsigned &t, std::ostream &outfile, const unsigned &nplot)
Plot: x,y in tecplot format at time level t (t=0: current; t>0: previous)
QMacroElement()
Default constructor (empty and broken)