KG47IF4CPCUT3BHS34WDRHTH5HYMBTY4OSTB3X7APR2E5ZJ32IYQC
KQNKYNRSWOY2K7M5PY362RJT4CRUJVECVSCNGKSJJBPYI3NU4GDQC
VAF66DTVLDWNG7N2PEQYEH4OH5SPSMFBXKPR2PU67IIM6CVPCJ7AC
QN2UTSQP4IMCMVXZNR24J22N24ASGXF6EWXQ2P3VWVQERUPFAFDQC
IEFVL4X5BPCLUX5D24ESP7FTFSX2HMCD2GOIFCMSWNUYEHQEJOIAC
U77PE56ICORZNQW33NXGSEMW7GDHCSSZ4EXB6OHBJSHEG6WHYSSQC
722HZ7UFINNE3YKSYKP2NHZ5XEG5QQLQHSKC7PREJZR3EX6RDYUAC
2DD222JSYRPHTXKSRXLSOMSCQPZUORNFLLO2P3GMIDELAAMD5MEQC
BVR7DVINVPQG7PA6Z7QYVYNQ43YZL7XCC6AOMSMWMGAAB2Q43STAC
RTNZAS3UPI6GG3KY4Z5WVXJ4R2YF5427BB6WAV3GHRS5W7XPOSUQC
IVHURSHY4636OGIF3PNDO5CWOVRLJ75M4LP65J6I2E6KAM4QKF4AC
WASO7G5FJXRXWNH2U2FLUNEKU6VE63OI3HUYP64BVD4LMD6KE7OQC
PQB3EKQ6MBCXPTW4HB7SGMSTOTYMB3EFZX2573OFCQI6PSOEKCSQC
AEVGZIZEUIC52MCK3J4V547YEV2R4YQL3JUJW7FSP4R34PSZ43DAC
ORAAQXS3UNKXYDJBCTHNEIDJIZDHWMM5EVCZKVMFRKQK2NIQNJGAC
// AmrCore functions
CactusAmrMesh::CactusAmrMesh() {}
CactusAmrMesh::CactusAmrMesh(const RealBox *rb, int max_level_in,
const Vector<int> &n_cell_in, int coord,
Vector<IntVect> ref_ratios, const int *is_per)
: AmrMesh(rb, max_level_in, n_cell_in, coord, ref_ratios, is_per) {}
CactusAmrMesh::CactusAmrMesh(const RealBox &rb, int max_level_in,
const Vector<int> &n_cell_in, int coord,
Vector<IntVect> const &ref_ratios,
Array<int, AMREX_SPACEDIM> const &is_per)
: AmrMesh(rb, max_level_in, n_cell_in, coord, ref_ratios, is_per) {}
CactusAmrMesh::~CactusAmrMesh() {}
void CactusAmrMesh::ErrorEst(int lev, TagBoxArray &tags, Real time, int ngrow) {
// // refine everywhere
// tags.setVal(boxArray(lev), TagBox::SET);
// refine centre
const BoxArray &ba = boxArray(lev);
const Box &bx = ba.minimalBox();
Box nbx;
for (int d = 0; d < dim; ++d) {
int sz = bx.bigEnd(d) - bx.smallEnd(d) + 1;
nbx.setSmall(d, bx.smallEnd(d) + sz / 4 + 1);
nbx.setBig(d, bx.bigEnd(d) - sz / 4 - 1);
}
cout << "nbx: " << nbx << "\n";
tags.setVal(intersect(ba, nbx), TagBox::SET);
}
////////////////////////////////////////////////////////////////////////////////
ghext->amrmesh = make_unique<AmrMesh>(domain, maxlevels, ncells, coord,
reffacts, periodic);
ghext->amrmesh = make_unique<CactusAmrMesh>(domain, maxnumlevels - 1, ncells,
coord, reffacts, periodic);
#warning "TODO: increase blocking factor"
// const int blocking_factor = 8;
const int blocking_factor = 1;
ghext->amrmesh->SetBlockingFactor(blocking_factor);
CCTK_VINFO("Geometry:");
cout << ghext->amrmesh->Geom(0) << "\n";
CCTK_VINFO("BoxArray:");
cout << ghext->amrmesh->boxArray(0) << "\n";
CCTK_VINFO("DistributionMap:");
cout << ghext->amrmesh->DistributionMap(0) << "\n";
for (int level = 0; level < maxnumlevels; ++level) {
CCTK_VINFO("Geometry level %d:", level);
cout << ghext->amrmesh->Geom(level) << "\n";
}
// Create grid structure
if (level == 0) {
// Create coarse grid
ghext->amrmesh->MakeNewGrids(time);
} else {
// Create refined grid
int new_finest = -999;
Vector<BoxArray> new_grids;
ghext->amrmesh->MakeNewGrids(0, time, new_finest, new_grids);
assert(new_finest == level);
}
// CCTK_VINFO("BoxArray level %d:", level);
// cout << ghext->amrmesh->boxArray(level) << "\n";
// CCTK_VINFO("DistributionMap level %d:", level);
// cout << ghext->amrmesh->DistributionMap(level) << "\n";
class CactusAmrMesh : public AmrMesh {
public:
CactusAmrMesh();
CactusAmrMesh(const RealBox *rb, int max_level_in,
const Vector<int> &n_cell_in, int coord = -1,
Vector<IntVect> ref_ratios = Vector<IntVect>(),
const int *is_per = nullptr);
CactusAmrMesh(const RealBox &rb, int max_level_in,
const Vector<int> &n_cell_in, int coord,
Vector<IntVect> const &ref_ratios,
Array<int, AMREX_SPACEDIM> const &is_per);
CactusAmrMesh(const AmrMesh &rhs) = delete;
CactusAmrMesh &operator=(const AmrMesh &rhs) = delete;
virtual ~CactusAmrMesh();
// virtual void MakeNewLevelFromScratch(int lev, Real time, const BoxArray
// &ba,
// const DistributionMapping &dm)
// override;
virtual void ErrorEst(int lev, TagBoxArray &tags, Real time,
int ngrow) override;
// virtual void ManualTagsPlacement(int lev, TagBoxArray &tags,
// const Vector<IntVect> &bf_lev) override;
// virtual BoxArray GetAreaNotToTag(int lev) override;
};
reduction<T> reduce_array(const T *restrict var, const int *restrict ash,
const int *restrict lsh) {
reduction<T> reduce_array(const Geometry &geom, const T *restrict var,
const int *restrict ash, const int *restrict lsh) {
const CCTK_REAL *restrict dx = geom.CellSize();
CCTK_REAL dV = 1.0;
for (int d = 0; d < dim; ++d)
dV *= dx[d];
reduction<T>::reduction(const T &x)
: min(x), max(x), sum(x), sum2(x * x), count(1.0), maxabs(fabs(x)),
sumabs(fabs(x)), sum2abs(fabs(x) * fabs(x)) {}
reduction<T>::reduction(const T &V, const T &x)
: min(x), max(x), sum(V * x), sum2((V * x) * (V * x)), vol(V),
maxabs(fabs(x)), sumabs(fabs(V * x)), sum2abs(fabs(V * x) * fabs(V * x)) {
}
int ncells[dim] = {ncells_x, ncells_y, ncells_z};
CCTK_REAL x0[dim] = {xmin, ymin, zmin};
CCTK_REAL x1[dim] = {xmax, ymax, zmax};
CCTK_REAL dx[dim];
for (int d = 0; d < dim; ++d)
dx[d] = (x1[d] - x0[d]) / ncells[d];
CCTK_REAL mindx = 1.0 / 0.0;
for (int d = 0; d < dim; ++d)
mindx = fmin(mindx, dx[d]);
const Geometry &geom = ghext->amrmesh->Geom(0);
const CCTK_REAL *restrict x0 = geom.ProbLo();
const CCTK_REAL *restrict dx = geom.CellSize();
CCTK_REAL mindx = 1.0 / 0.0;
const int numlevels = ghext->amrmesh->finestLevel() + 1;
for (int level = 0; level <numlevels; ++level) {
const Geometry &geom = ghext->amrmesh->Geom(level);
const CCTK_REAL *restrict dx = geom.CellSize();
for (int d = 0; d < dim; ++d)
mindx = fmin(mindx, dx[d]);
}
// Offset between this level's and the coarsest level's origin
#warning "TODO"
for (int d = 0; d < dim; ++d)
cctkGH->cctk_levoff[d] = 0; // TODO
#warning "TODO"
for (int d = 0; d < dim; ++d)
cctkGH->cctk_levoffdenom[d] = 0; // TODO
// Offset between this level's and the coarsest level's origin
for (int d = 0; d < dim; ++d) {
cctkGH->cctk_levoff[d] = 1;
cctkGH->cctk_levoffdenom[d] = 2;
}
const CCTK_REAL dt = cctk_delta_time;
const CCTK_REAL *restrict const x0 = cctk_origin_space;
const CCTK_REAL *restrict const dx = cctk_delta_space;
const CCTK_REAL dt = CCTK_DELTA_TIME;
CCTK_REAL x0[dim], dx[dim];
for (int d = 0; d < dim; ++d) {
x0[d] = CCTK_ORIGIN_SPACE(d);
dx[d] = CCTK_DELTA_SPACE(d);
}