Skip to content

Commit 227e378

Browse files
authored
Slopes test (AMReX-Codes#1859)
Slope computation on cell centroids using the Least Square method. These tests are based from the LeastSquares Test (AMReX-Codes#1707) but instead of calculating scalar values on face centroids they are calculated on cell centroids using a linear function rather than a second order polynomial (AMReX-Codes#1707).
1 parent 0ab63f3 commit 227e378

26 files changed

+1420
-0
lines changed

Tests/Slopes/GNUmakefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
TEST = TRUE
2+
USE_ASSERTION = TRUE
3+
4+
USE_EB = TRUE
5+
DEBUG = FALSE
6+
USE_MPI = TRUE
7+
USE_OMP = FALSE
8+
9+
COMP = gnu
10+
11+
DIM = 3
12+
13+
AMREX_HOME ?= ../..
14+
15+
include $(AMREX_HOME)/Tools/GNUMake/Make.defs
16+
include ./Make.package
17+
18+
Pdirs := Base Boundary AmrCore
19+
Pdirs += EB
20+
21+
Ppack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package)
22+
23+
include $(Ppack)
24+
25+
include $(AMREX_HOME)/Tools/GNUMake/Make.rules
26+

Tests/Slopes/Make.package

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
CEXE_sources += main.cpp
3+
CEXE_sources += MyTest.cpp initEB.cpp initData.cpp initLinearData.cpp initLinearDataFor2D.cpp initLinearDataFor3D.cpp
4+
CEXE_headers += MyTest.H MyEB.H

Tests/Slopes/MyEB.H

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef MY_EB_H_
2+
#define MY_EB_H_
3+
4+
#include <AMReX_Array.H>
5+
#include <AMReX_Config.H>
6+
#include <AMReX_EB2_IF_Base.H>
7+
8+
#include <cmath>
9+
#include <algorithm>
10+
11+
// For all implicit functions, >0: body; =0: boundary; <0: fluid
12+
13+
class FlowerIF
14+
: amrex::GPUable
15+
{
16+
public:
17+
18+
FlowerIF (amrex::Real a_radius, amrex::Real a_delta, int a_npetals,
19+
const amrex::RealArray& a_center, bool a_inside)
20+
: m_r(a_radius),
21+
m_dr(a_delta),
22+
m_npetals(a_npetals),
23+
m_center(amrex::makeXDim3(a_center)),
24+
m_inside(a_inside),
25+
m_sign(a_inside ? 1.0 : -1.0)
26+
{}
27+
28+
FlowerIF (const FlowerIF& rhs) noexcept = default;
29+
FlowerIF (FlowerIF&& rhs) noexcept = default;
30+
FlowerIF& operator= (const FlowerIF& rhs) = delete;
31+
FlowerIF& operator= (FlowerIF&& rhs) = delete;
32+
33+
AMREX_GPU_HOST_DEVICE inline
34+
amrex::Real operator() (AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z))
35+
const noexcept
36+
{
37+
amrex::Real posx = x - m_center.x;
38+
amrex::Real posy = y - m_center.y;
39+
amrex::Real r = std::hypot(posx, posy);
40+
amrex::Real theta = std::atan2(posy, posx);
41+
return m_sign*(r - m_r - m_dr * std::cos(m_npetals*theta));
42+
}
43+
44+
inline amrex::Real operator() (const amrex::RealArray& p) const noexcept
45+
{
46+
return this->operator() (AMREX_D_DECL(p[0], p[1], p[2]));
47+
}
48+
49+
protected:
50+
amrex::Real m_r;
51+
amrex::Real m_dr;
52+
amrex::Real m_npetals;
53+
amrex::XDim3 m_center;
54+
bool m_inside;
55+
//
56+
amrex::Real m_sign;
57+
};
58+
59+
#endif

Tests/Slopes/MyTest.H

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef MY_TEST_H_
2+
#define MY_TEST_H_
3+
4+
#include <AMReX_Config.H>
5+
#include <AMReX_EBFabFactory.H>
6+
#include <AMReX_Array.H>
7+
8+
class MyTest
9+
{
10+
public:
11+
12+
MyTest ();
13+
~MyTest ();
14+
15+
void compute_gradient ();
16+
void writePlotfile ();
17+
void initData ();
18+
19+
private:
20+
21+
void initializeEB ();
22+
void readParameters ();
23+
void initGrids ();
24+
25+
void initializeLinearData (int ilev);
26+
void initializeLinearDataFor2D (int ilev);
27+
void initializeLinearDataFor3D (int ilev);
28+
29+
int max_level = 0;
30+
int ref_ratio = 2;
31+
int n_cell = 128;
32+
int max_grid_size = 64;
33+
amrex::Vector<int> is_periodic = amrex::Vector<int>(3,0);
34+
int eb_is_dirichlet = 0;
35+
int eb_is_homog_dirichlet = 0;
36+
amrex::Vector<amrex::Real> prob_lo = amrex::Vector<amrex::Real>(3,0.0);
37+
amrex::Vector<amrex::Real> prob_hi = amrex::Vector<amrex::Real>(3,1.0);
38+
39+
std::string plot_file_name{"plot"};
40+
41+
amrex::Vector<amrex::Real> scalars;
42+
43+
int max_coarsening_level = 0;
44+
45+
bool use_linear_1d = false;
46+
bool linear_1d_askew = false;
47+
amrex::Vector<amrex::Real> linear_1d_pt_on_top_wall = amrex::Vector<amrex::Real>(3,0.0);
48+
amrex::Real linear_1d_height = 1.0;
49+
amrex::Real linear_1d_rotation = 0.;
50+
int linear_1d_flow_dir = 0;
51+
int linear_1d_height_dir = 1;
52+
amrex::Real linear_1d_bottom = 0.0;
53+
amrex::Vector<amrex::Real> linear_1d_askew_rotation = amrex::Vector<amrex::Real>(2,0.0);
54+
int linear_1d_no_flow_dir = 0;
55+
56+
amrex::Vector<amrex::Geometry> geom;
57+
amrex::Vector<amrex::BoxArray> grids;
58+
amrex::Vector<amrex::DistributionMapping> dmap;
59+
amrex::Vector<std::unique_ptr<amrex::EBFArrayBoxFactory> > factory;
60+
61+
amrex::Vector<amrex::MultiFab> phi;
62+
amrex::Vector<amrex::MultiFab> grad_x;
63+
amrex::Vector<amrex::MultiFab> grad_x_analytic;
64+
amrex::Vector<amrex::MultiFab> grad_y;
65+
amrex::Vector<amrex::MultiFab> grad_y_analytic;
66+
amrex::Vector<amrex::MultiFab> grad_z;
67+
amrex::Vector<amrex::MultiFab> grad_z_analytic;
68+
amrex::Vector<amrex::MultiFab> ccentr;
69+
70+
};
71+
72+
#endif

0 commit comments

Comments
 (0)