ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_EBUtils.H
Go to the documentation of this file.
1 #ifndef ERF_EB_UTIL_H_
2 #define ERF_EB_UTIL_H_
3 
4 #include <AMReX_RealVect.H>
5 
6 namespace utils {
7 
8 // Harmonic average
9 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
10 amrex::Real avg_h ( amrex::Real XXXm, amrex::Real XXXp) {
11  if ( XXXm + XXXp < std::numeric_limits<amrex::Real>::min()) { return 0.; }
12  else { return ((XXXm * XXXp) / (0.5*(XXXm + XXXp))); }
13 }
14 
15 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
16 amrex::Real trD (int i, int j, int k,
17  amrex::GpuArray<amrex::Real,AMREX_SPACEDIM> const& dx,
18  amrex::Array4<amrex::Real const> const& vel_x,
19  amrex::Array4<amrex::Real const> const& vel_y,
20  amrex::Array4<amrex::Real const> const& vel_z)
21 {
22  return (vel_x(i+1,j,k)-vel_x(i,j,k))/dx[0] +
23  (vel_y(i,j+1,k)-vel_y(i,j,k))/dx[1] +
24  (vel_z(i,j,k+1)-vel_z(i,j,k))/dx[2];
25 }
26 
27 
28 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
29 int
30 intersect_plane_edge ( amrex::RealVect const& a_plane_point,
31  amrex::RealVect const& a_plane_normal,
32  amrex::RealVect const& a_edge_point0,
33  amrex::RealVect const& a_edge_point1,
34  amrex::RealVect& a_intersection_point,
35  amrex::Real& a_intersection_dist )
36 {
37  amrex::RealVect const edge(a_edge_point1 - a_edge_point0);
38  amrex::Real const edge_length = edge.vectorLength();
39 
40  AMREX_ALWAYS_ASSERT(edge_length > 0.);
41 
42  amrex::RealVect edge_normal = edge / edge_length;
43 
44  amrex::Real np_dot_ne = a_plane_normal.dotProduct(edge_normal);
45 
46  if ( amrex::Math::abs(np_dot_ne) < std::numeric_limits<amrex::Real>::min() )
47  { return 0; }
48 
49  a_intersection_dist = a_plane_normal.dotProduct(a_plane_point - a_edge_point0);
50  a_intersection_dist /= np_dot_ne;
51 
52  a_intersection_point = a_edge_point0 + a_intersection_dist*edge_normal;
53 
54  if (0. <= a_intersection_dist && a_intersection_dist <= edge_length) { return 1;}
55 
56  return 0;
57 }
58 
59 }
60 #endif
Definition: ERF_EBUtils.H:6
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int intersect_plane_edge(amrex::RealVect const &a_plane_point, amrex::RealVect const &a_plane_normal, amrex::RealVect const &a_edge_point0, amrex::RealVect const &a_edge_point1, amrex::RealVect &a_intersection_point, amrex::Real &a_intersection_dist)
Definition: ERF_EBUtils.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real trD(int i, int j, int k, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dx, amrex::Array4< amrex::Real const > const &vel_x, amrex::Array4< amrex::Real const > const &vel_y, amrex::Array4< amrex::Real const > const &vel_z)
Definition: ERF_EBUtils.H:16
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real avg_h(amrex::Real XXXm, amrex::Real XXXp)
Definition: ERF_EBUtils.H:10