ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
polygon_ Class Reference

#include <ERF_EBPolygon.H>

Collaboration diagram for polygon_:

Public Member Functions

AMREX_GPU_HOST_DEVICE polygon_ (amrex::RealVect a_point, amrex::RealVect a_normal)
 
AMREX_GPU_HOST_DEVICE polygon_ ()
 
AMREX_GPU_HOST_DEVICE void add_vertex (amrex::RealVect const &a_v)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_area (amrex::Real const &a_area)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void define ()
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int ok () const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real area () const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real distance (amrex::RealVect const &a_point) const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect get_centroid () const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect normal () const noexcept
 
void report (int const a_id, amrex::RealVect a_v0)
 

Private Attributes

int const m_cell_face
 
amrex::RealVect const m_eb_point
 
amrex::RealVect const m_eb_normal
 
int m_defined
 
int m_vertices
 
amrex::Real m_area
 
int m_sorted
 
amrex::Array< amrex::RealVect, m_max_verticesm_vertex
 
amrex::GpuArray< amrex::Real, m_max_verticesm_theta
 
amrex::RealVect m_zdir
 

Static Private Attributes

static constexpr int m_max_vertices = 6
 

Constructor & Destructor Documentation

◆ polygon_() [1/2]

AMREX_GPU_HOST_DEVICE polygon_::polygon_ ( amrex::RealVect  a_point,
amrex::RealVect  a_normal 
)
inline
16  : m_cell_face(1)
17  , m_eb_point(a_point)
18  , m_eb_normal(a_normal)
19  , m_defined(0)
20  , m_vertices(0)
21  , m_area(0.)
22  , m_sorted(0)
23  , m_vertex({amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.),
24  amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.)})
25  , m_zdir(0.)
26  {}
int m_defined
Definition: ERF_EBPolygon.H:206
amrex::Real m_area
Definition: ERF_EBPolygon.H:210
int const m_cell_face
Definition: ERF_EBPolygon.H:201
int m_sorted
Definition: ERF_EBPolygon.H:212
int m_vertices
Definition: ERF_EBPolygon.H:208
amrex::Array< amrex::RealVect, m_max_vertices > m_vertex
Definition: ERF_EBPolygon.H:214
amrex::RealVect const m_eb_normal
Definition: ERF_EBPolygon.H:204
amrex::RealVect const m_eb_point
Definition: ERF_EBPolygon.H:203
amrex::RealVect m_zdir
Definition: ERF_EBPolygon.H:218

◆ polygon_() [2/2]

AMREX_GPU_HOST_DEVICE polygon_::polygon_ ( )
inline
30  : m_cell_face(0)
31  , m_eb_point(0.)
32  , m_eb_normal(0.)
33  , m_defined(0)
34  , m_vertices(0)
35  , m_area(0.)
36  , m_sorted(0)
37  , m_vertex({amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.),
38  amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.)})
39  , m_zdir(0.)
40  {}

Member Function Documentation

◆ add_vertex()

AMREX_GPU_HOST_DEVICE void polygon_::add_vertex ( amrex::RealVect const &  a_v)
inline
43  {
44  for ( int i(0); i<m_vertices; ++i) {
45  if (m_vertex[i] == a_v) {
46  return;
47  }
48  }
49  AMREX_ASSERT( m_vertices < m_max_vertices );
50  m_vertex[m_vertices] = a_v;
51  m_vertices++;
52  }
static constexpr int m_max_vertices
Definition: ERF_EBPolygon.H:199

Referenced by eb_cut_cell_::calc_edge_intersections(), and eb_cut_cell_::set_covered_regular_cell_vertices().

Here is the caller graph for this function:

◆ area()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real polygon_::area ( ) const
inlinenoexcept
128  {
129  AMREX_ALWAYS_ASSERT( ok() ); // <-------------------------------------- TODO remove ALWAYS
130  return m_area;
131  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int ok() const noexcept
Definition: ERF_EBPolygon.H:124

Referenced by eb_cut_cell_::areaBoun(), eb_cut_cell_::centVol(), get_centroid(), and eb_cut_cell_::volume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ define()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void polygon_::define ( )
inline
58  {
59 
60  AMREX_ALWAYS_ASSERT( m_defined == 0 ); // TODO ---------------------------- remove ALWAYS
61 
62  m_defined = 1;
63 
64  // We need at least 3 faces.
65  if (m_vertices < 3) { return; }
66 
67  // Check to see if the vertices of the face are inside or outside of the plane.
68  // If they are outside, this face doesn't belong to the volume.
69  if ( m_cell_face ) {
70  for ( int i(0); i<m_vertices; ++i) {
71  if ((m_eb_normal.dotProduct(m_vertex[i] - m_eb_point)) >= 0.) {
72  } else {
73  }
74  }
75  }
76 
77  // Calculate the centroid of the polygon.
78  amrex::RealVect centroid = get_centroid();
79 
80  // Shift the vertices relative to the centroid
81  amrex::Array<amrex::RealVect,m_max_vertices> vertex_cent;
82  for ( int i(0); i<m_vertices; ++i) { vertex_cent[i] = m_vertex[i] - centroid; }
83 
84  // Find a vertex that isn't inline with v[0] and the centroid so we can
85  // compute a vector normal to the face.
86  for ( int i(1); i<m_vertices; ++i ) {
87  m_zdir = vertex_cent[0].crossProduct(vertex_cent[i]);
88  if ( !amrex::almostEqual(m_zdir.vectorLength(),0.) ) { break; }
89  }
90  AMREX_ALWAYS_ASSERT(!amrex::almostEqual(m_zdir.vectorLength(), 0.));
91  m_zdir /= m_zdir.vectorLength();
92 
93  m_theta[0] = 0.0;
94  for ( int i(1); i<m_vertices; ++i) {
95 
96  m_theta[i] = std::atan2(m_zdir.dotProduct( vertex_cent[0].crossProduct(vertex_cent[i]) ),
97  vertex_cent[0].dotProduct(vertex_cent[i]));
98 
99  m_theta[i] += ((m_theta[i] >= 0.) ? 0.0 : 2.0*PI);
100  }
101 
102  // Sort counter clockwise based on theta.
103  for (int i(0); i<m_vertices; ++i) {
104  for (int j(0); j < m_vertices-i-1; ++j) {
105  if ( m_theta[j] > m_theta[j+1] ) {
106  amrex::Swap(m_theta[j], m_theta[j+1]);
107  amrex::Swap(m_vertex[j], m_vertex[j+1]);
108  amrex::Swap(vertex_cent[j], vertex_cent[j+1]);
109  }
110  } // j-loop
111  } // i-loop
112  m_sorted = 1;
113 
114  // Compute areas of triangles
115  for (int i(0); i<m_vertices; ++i) {
116  int const j( (i+1 == m_vertices) ? 0 : i+1 );
117  amrex::RealVect vi_cross_vj = vertex_cent[i].crossProduct(vertex_cent[j]);
118  m_area += 0.5*vi_cross_vj.vectorLength();
119  }
120  AMREX_ALWAYS_ASSERT( m_area > 0. ); // <------------------------------- TODO remove ALWAYS
121  }
constexpr amrex::Real PI
Definition: ERF_Constants.H:6
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect get_centroid() const noexcept
Definition: ERF_EBPolygon.H:143
amrex::GpuArray< amrex::Real, m_max_vertices > m_theta
Definition: ERF_EBPolygon.H:216
Here is the call graph for this function:

◆ distance()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real polygon_::distance ( amrex::RealVect const &  a_point) const
inlinenoexcept
135  {
136  AMREX_ALWAYS_ASSERT( m_defined == 1 ); // <--------------------------- TODO remove ALWAYS
137  amrex::RealVect x0 = a_point - m_vertex[0];
138  return amrex::Math::abs(x0.dotProduct(m_zdir));
139  }

Referenced by report(), and eb_cut_cell_::volume().

Here is the caller graph for this function:

◆ get_centroid()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect polygon_::get_centroid ( ) const
inlinenoexcept
143  {
144  amrex::RealVect cent(0.);
145  if (m_vertices==3) {
146  cent = (m_vertex[0] + m_vertex[1] + m_vertex[2]) / 3.0;
147  } else {
148  // Loop over sub-triangles
149  amrex::Real area(0.);
150  for ( int i(0); i<m_vertices-2; ++i) {
151  amrex::RealVect const v0 (m_vertex[i+1] - m_vertex[0]);
152  amrex::RealVect const v1 (m_vertex[i+2] - m_vertex[0]);
153  amrex::RealVect v0_cross_v1 = v0.crossProduct(v1);
154  amrex::Real area_tri = 0.5 * v0_cross_v1.vectorLength();
155  amrex::RealVect cent_tri = (m_vertex[0] + m_vertex[i+1] + m_vertex[i+2]) / 3.0;
156  area += area_tri;
157  cent += area_tri * cent_tri;
158  }
159  cent = cent / area;
160  }
161  return cent;
162  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real area() const noexcept
Definition: ERF_EBPolygon.H:128

Referenced by eb_cut_cell_::centBoun(), eb_cut_cell_::centVol(), define(), and report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normal()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect polygon_::normal ( ) const
inlinenoexcept
166  {
167  return m_zdir;
168  }

◆ ok()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int polygon_::ok ( ) const
inlinenoexcept
125  { return ((m_area > 0. || (m_area == 0. && m_defined == 1)) ? 1 : 0); }

Referenced by area(), report(), and eb_cut_cell_::volume().

Here is the caller graph for this function:

◆ report()

void polygon_::report ( int const  a_id,
amrex::RealVect  a_v0 
)
inline
175  {
176 
177 #ifndef AMREX_USE_GPU
178  amrex::RealVect centroid = get_centroid();
179  amrex::Print() << "Face " << a_id
180  << " -------------------------------------------\n"
181  << "\nok? " << (ok() ? "yes" : "no") << "\n\n";
182  for (int i(0); i<m_vertices; ++i) {
183  amrex::Print() << "v" << i << ": " << m_vertex[i] << '\n';
184  }
185  amrex::Print() << "\nvc: " << " " << centroid << "\n";
186 
187  amrex::Real const dist = distance( a_v0 );
188  // amrex::Real const vol = ok() ? m_area * dist : 0.;
189 
190  amrex::Print() << "\narea: " << m_area
191  << "\ndistance: " << dist
192  << "\nvolume: " << dist*m_area
193  << "\n==================================================\n\n";
194 #endif
195  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real distance(amrex::RealVect const &a_point) const noexcept
Definition: ERF_EBPolygon.H:135
Here is the call graph for this function:

◆ set_area()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void polygon_::set_area ( amrex::Real const &  a_area)
inline
55 { m_area = a_area; }

Referenced by eb_cut_cell_::set_regular().

Here is the caller graph for this function:

Member Data Documentation

◆ m_area

amrex::Real polygon_::m_area
private

Referenced by area(), define(), ok(), report(), and set_area().

◆ m_cell_face

int const polygon_::m_cell_face
private

Referenced by define().

◆ m_defined

int polygon_::m_defined
private

Referenced by define(), distance(), and ok().

◆ m_eb_normal

amrex::RealVect const polygon_::m_eb_normal
private

Referenced by define().

◆ m_eb_point

amrex::RealVect const polygon_::m_eb_point
private

Referenced by define().

◆ m_max_vertices

constexpr int polygon_::m_max_vertices = 6
staticconstexprprivate

Referenced by add_vertex().

◆ m_sorted

int polygon_::m_sorted
private

Referenced by define().

◆ m_theta

amrex::GpuArray<amrex::Real,m_max_vertices> polygon_::m_theta
private

Referenced by define().

◆ m_vertex

amrex::Array<amrex::RealVect,m_max_vertices> polygon_::m_vertex
private

◆ m_vertices

int polygon_::m_vertices
private

◆ m_zdir

amrex::RealVect polygon_::m_zdir
private

Referenced by define(), distance(), and normal().


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