CompareElementCoordinate< ELEMENT > Class Template Reference

Public Member Functions

int operator() (GeneralisedElement *const &element1_pt, GeneralisedElement *const &element2_pt)
 The actual comparison operator. More...
 
int operator() (GeneralisedElement *const &element1_pt, GeneralisedElement *const &element2_pt)
 The actual comparison operator. More...
 

Detailed Description

template<class ELEMENT>
class CompareElementCoordinate< ELEMENT >

Class for sorting the elements into lexicographic order based on the coordinate at the centre of the element. This is the only "rational" way to preserve the ordering given rotations of the elements.

Member Function Documentation

◆ operator()() [1/2]

template<class ELEMENT >
int CompareElementCoordinate< ELEMENT >::operator() ( GeneralisedElement *const &  element1_pt,
GeneralisedElement *const &  element2_pt 
)
inline

The actual comparison operator.

55  {
56 
57  //Dynamic cast the elements
58  ELEMENT* cast_element1_pt = dynamic_cast<ELEMENT*>(element1_pt);
59  ELEMENT* cast_element2_pt = dynamic_cast<ELEMENT*>(element2_pt);
60 
61  //Check that we managed to successfully cast the elements
62 #ifdef PARANOID
63  if (cast_element1_pt==0)
64  {
65  std::ostringstream error_message;
66  error_message
67  << "Failed to cast element1_pt to an ELEMENT"
68  << std::endl;
69  throw OomphLibError(error_message.str(),
72  }
73 
74  if (cast_element2_pt==0)
75  {
76  std::ostringstream error_message;
77  error_message
78  << "Failed to cast element2_pt to an ELEMENT"
79  << std::endl;
80  throw OomphLibError(error_message.str(),
83  }
84 #endif
85 
86  //Find the dimension of the element
87  unsigned dim = cast_element1_pt->dim();
88  //Check that the dimensions of bothelements are the same
89  {
90  unsigned dim2 = cast_element2_pt->dim();
91 
92  if(dim != dim2)
93  {
94  std::ostringstream warn_message;
95  warn_message
96  << "Warning: Two elements do not have the same dimension"
97  << dim << " and " << dim2 << ". They cannot be compared\n";
98  OomphLibWarning(warn_message.str(),
99  "CompareElementCoordinate::()",
101  }
102  }
103 
104  //Find the positions of the centres of the elements
105  Vector<double> x1(dim), x2(dim);
106  //Not general, only works for quads or octs (centre 0,0,0)
107  Vector<double> s(dim,0.0);
108  cast_element1_pt->interpolated_x(s,x1);
109  cast_element2_pt->interpolated_x(s,x2);
110 
111  //This is the Stroustrup-approved way to do lexicographical ordering
112  //Loop over the components until they are not equal
113  //to within a given tolerance
114  {
115  unsigned i=0; double tol = 1.0e-14;
116  while(i!=dim && (std::abs(x1[i]-x2[i]) < tol)){ ++i;}
117  //If we've reached the end, the coordinates are equal, return false
118  if(i==dim) {return 0;}
119  //Otherwise, return the ordering on the final component
120  return x1[i] < x2[i];
121  }
122  }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: oomph_definitions.h:222
Definition: oomph_definitions.h:267
RealScalar s
Definition: level1_cplx_impl.h:130
Vector< double > x1(const Vector< double > &coord)
Cartesian coordinates centered at the point (0.5,1)
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:86
Vector< double > x2(const Vector< double > &coord)
Cartesian coordinates centered at the point (1.5,1)
Definition: poisson/poisson_with_singularity/two_d_poisson.cc:102
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References abs(), i, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, s, Global_parameters::x1(), and Global_parameters::x2().

◆ operator()() [2/2]

template<class ELEMENT >
int CompareElementCoordinate< ELEMENT >::operator() ( GeneralisedElement *const &  element1_pt,
GeneralisedElement *const &  element2_pt 
)
inline

The actual comparison operator.

55  {
56 
57  //Dynamic cast the elements
58  ELEMENT* cast_element1_pt = dynamic_cast<ELEMENT*>(element1_pt);
59  ELEMENT* cast_element2_pt = dynamic_cast<ELEMENT*>(element2_pt);
60 
61  //Check that we managed to successfully cast the elements
62 #ifdef PARANOID
63  if (cast_element1_pt==0)
64  {
65  std::ostringstream error_message;
66  error_message
67  << "Failed to cast element1_pt to an ELEMENT"
68  << std::endl;
69  throw OomphLibError(error_message.str(),
72  }
73 
74  if (cast_element2_pt==0)
75  {
76  std::ostringstream error_message;
77  error_message
78  << "Failed to cast element2_pt to an ELEMENT"
79  << std::endl;
80  throw OomphLibError(error_message.str(),
83  }
84 #endif
85 
86  //Find the dimension of the element
87  unsigned dim = cast_element1_pt->dim();
88  //Check that the dimensions of bothelements are the same
89  {
90  unsigned dim2 = cast_element2_pt->dim();
91 
92  if(dim != dim2)
93  {
94  std::ostringstream warn_message;
95  warn_message
96  << "Warning: Two elements do not have the same dimension"
97  << dim << " and " << dim2 << ". They cannot be compared\n";
98  OomphLibWarning(warn_message.str(),
99  "CompareElementCoordinate::()",
101  }
102  }
103 
104  //Find the positions of the centres of the elements
105  Vector<double> x1(dim), x2(dim);
106  //Not general, only works for quads or octs (centre 0,0,0)
107  Vector<double> s(dim,0.0);
108  cast_element1_pt->interpolated_x(s,x1);
109  cast_element2_pt->interpolated_x(s,x2);
110 
111  //This is the Stroustrup-approved way to do lexicographical ordering
112  //Loop over the components until they are not equal
113  //to within a given tolerance
114  {
115  unsigned i=0; double tol = 1.0e-14;
116  while(i!=dim && (std::abs(x1[i]-x2[i]) < tol)){ ++i;}
117  //If we've reached the end, the coordinates are equal, return false
118  if(i==dim) {return 0;}
119  //Otherwise, return the ordering on the final component
120  return x1[i] < x2[i];
121  }
122  }

References abs(), i, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, s, Global_parameters::x1(), and Global_parameters::x2().


The documentation for this class was generated from the following files: