Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions Source/Projection.H
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ class Projection
protected:
static const int maxlev = 10;
static const int LEVEL_PROJ = 1001;
static const int INITIAL_VEL = 1002;
static const int INITIAL_PRESS = 1003;
static const int INITIAL_SYNC = 1004;
static const int SYNC_PROJ = 1005;
static const int FILTER_P = 1006;

public:

Expand Down Expand Up @@ -66,18 +62,6 @@ public:
int iteration,
int have_divu);

// solve DG(correction to P_new) = -D G^perp p^(n-half)
// or DG(correction to P_new) = -D G^perp p^(n-half) - D(U^n /dt)
void filterP(int level,
const amrex::Geometry& geom,
amrex::MultiFab &P_old,
amrex::MultiFab &P_new,
amrex::MultiFab &U_old,
amrex::MultiFab &rho_half,
int ** bc,
amrex::Real time,
amrex::Real dt,
int have_divu);
//
// A sync project involving the coarse and fine level of a 2 level system.
//
Expand Down Expand Up @@ -176,26 +160,22 @@ public:
amrex::MultiFab* vel,
int level) const;

//
// Impose the hydrostatic pressure rho*g on outflow faces.
//
void set_outflow_bcs (int which_call,
const amrex::Vector<amrex::MultiFab*>& phi,
const amrex::Vector<amrex::MultiFab*>& Vel_in,
const amrex::Vector<amrex::MultiFab*>& Divu_in,
const amrex::Vector<amrex::MultiFab*>& Sig_in,
int c_lev,
int f_lev,
int have_divu);
int f_lev);

void set_outflow_bcs_at_level (int which_call,
int lev,
void set_outflow_bcs_at_level (int lev,
int c_lev,
amrex::Box* state_strip,
amrex::Orientation* outFacesAtThisLevel,
int numOutFlowFaces,
const amrex::Vector<amrex::MultiFab*>& phi,
amrex::MultiFab* Vel_in,
amrex::MultiFab* Divu_in,
amrex::MultiFab* Sig_in,
int have_divu,
amrex::Real gravity);

void computeRhoG (amrex::FArrayBox* rhoFab,
Expand Down Expand Up @@ -239,7 +219,6 @@ public:
static int proj_2;
static int rho_wgt_vel_proj;
static int do_outflow_bcs;
static int add_vort_proj;

void doMLMGNodalProjection (int c_lev, int nlevel,
const amrex::Vector<amrex::MultiFab*>& vel,
Expand Down
136 changes: 28 additions & 108 deletions Source/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ int Projection::verbose = 0;
Real Projection::proj_tol = 1.0e-12;
Real Projection::sync_tol = 1.e-10;
Real Projection::proj_abs_tol = 1.e-16;
int Projection::add_vort_proj = 0;
int Projection::do_outflow_bcs = 1;
int Projection::rho_wgt_vel_proj = 0;

Expand Down Expand Up @@ -55,7 +54,6 @@ Projection::Initialize ()
pp.query("sync_tol", sync_tol);
pp.query("proj_abs_tol", proj_abs_tol);
pp.query("benchmarking", benchmarking);
pp.query("add_vort_proj", add_vort_proj);
pp.query("do_outflow_bcs", do_outflow_bcs);
pp.query("rho_wgt_vel_proj", rho_wgt_vel_proj);

Expand Down Expand Up @@ -226,9 +224,8 @@ Projection::level_project (int level,
AMREX_ASSERT(ns != nullptr);

//
// NOTE: IT IS IMPORTANT TO DO THE BOUNDARY CONDITIONS BEFORE
// MAKING UNEW HOLD U_t OR U/dt, BECAUSE UNEW IS USED IN
// CONSTRUCTING THE OUTFLOW BC'S.
// Set the physical boundary values of U_old and U_new before
// U_new is made to hold U_t or U/dt below.
//
// Set boundary values for P_new, to increment, if applicable
// // Note: we don't need to worry here about using FillCoarsePatch because
Expand Down Expand Up @@ -303,27 +300,19 @@ Projection::level_project (int level,
}

//
// Outflow uses appropriately constructed "U_new" and "divusource" to
// compute BC for phi, so make sure this call comes after those are set,
// but before fields are scaled by r or rho is set to 1/rho.
// Outflow sets phi to the hydrostatic rho*g, so make sure this call comes
// before rho_half is scaled by r or set to 1/rho.
//
Real gravity = NavierStokesBase::getGravity();
if (OutFlowBC::HasOutFlowBC(phys_bc) && (have_divu || std::fabs(gravity) > 0.0)
&& do_outflow_bcs)
if (OutFlowBC::HasOutFlowBC(phys_bc) && std::fabs(gravity) > 0.0 && do_outflow_bcs)
{
Vector<MultiFab*> phi(maxlev, nullptr);
phi[level] = &(LevelData[level]->get_new_data(Press_Type));

Vector<MultiFab*> Vel_ML(maxlev, nullptr);
Vel_ML[level] = &U_new;

Vector<MultiFab*> Divu_ML(maxlev, nullptr);
Divu_ML[level] = divusource.get();

Vector<MultiFab*> Rho_ML(maxlev, nullptr);
Rho_ML[level] = &rho_half;

set_outflow_bcs(LEVEL_PROJ,phi,Vel_ML,Divu_ML,Rho_ML,level,level,have_divu);
set_outflow_bcs(LEVEL_PROJ,phi,Rho_ML,level,level);
}

//
Expand Down Expand Up @@ -667,13 +656,10 @@ Projection::initialVelocityProject (int c_lev,
LevelData[lev]->get_old_data(Press_Type).setVal(0.0);
}

// MLNodeLaplacian does not take any ghost cells from rhcc or sig.
// copies only valid cells and fills ghosts internally.
// MLNodeLaplacian does not take any ghost cells from rhcc or sig;
// it copies only valid cells and fills ghosts internally.
// However, vel and phi are assumed to have 1 ghost cell in MLMG.
// set outflow bcs fills vel and phi using 1 ghost cell from sig (holding rho)
// and rhcc (holding divu)
const int nghost =
(OutFlowBC::HasOutFlowBC(phys_bc) && do_outflow_bcs && have_divu) ? 1 : 0;
const int nghost = 0;

for (lev = c_lev; lev <= f_lev; lev++)
{
Expand All @@ -686,22 +672,6 @@ Projection::initialVelocityProject (int c_lev,

if (rho_wgt_vel_proj)
{
if ( nghost > 0 ){
LevelData[lev]->get_new_data(State_Type).setBndry(BogusValue,Density,1);

AmrLevel& amr_level = parent->getLevel(lev);

MultiFab& S_new = amr_level.get_new_data(State_Type);

Real curr_time = amr_level.get_state_data(State_Type).curTime();

for (MFIter mfi(S_new); mfi.isValid(); ++mfi)
{
amr_level.setPhysBoundaryValues(S_new[mfi],State_Type,curr_time,
Density,Density,1);
}
}

MultiFab::Copy(*sig[lev],
LevelData[lev]->get_new_data(State_Type),
Density, 0, 1, nghost);
Expand Down Expand Up @@ -745,14 +715,6 @@ Projection::initialVelocityProject (int c_lev,
}
}

if (OutFlowBC::HasOutFlowBC(phys_bc) && do_outflow_bcs && have_divu)
{
set_outflow_bcs(INITIAL_VEL,phi,vel,
amrex::GetVecOfPtrs(rhcc),
amrex::GetVecOfPtrs(sig),
c_lev,f_lev,have_divu);
}

//
// Scale the projection variables.
//
Expand Down Expand Up @@ -895,13 +857,11 @@ Projection::initialPressureProject (int c_lev)
//
Real gravity = NavierStokesBase::getGravity();

if (OutFlowBC::HasOutFlowBC(phys_bc) && do_outflow_bcs)
if (OutFlowBC::HasOutFlowBC(phys_bc) && std::fabs(gravity) > 0. && do_outflow_bcs)
{
int have_divu_dummy = 0;
set_outflow_bcs(INITIAL_PRESS,phi,vel,
Vector<MultiFab*>(maxlev, nullptr),
set_outflow_bcs(INITIAL_PRESS,phi,
amrex::GetVecOfPtrs(sig),
c_lev,f_lev,have_divu_dummy);
c_lev,f_lev);
}

Vector<std::unique_ptr<MultiFab> > raii;
Expand Down Expand Up @@ -1038,8 +998,8 @@ Projection::initialSyncProject (int c_lev,
amr_level.setPhysBoundaryValues(divu_new[mfi],Divu_Type,curr_time,0,0,1);
}

// Needed for set_outflow_bcs(). MLMG ignores rh ghost cells.
const int nghost = 1;
// MLMG ignores rhcc ghost cells.
const int nghost = 0;
rhcc[lev] = std::make_unique<MultiFab>
(amr_level.boxArray(), amr_level.DistributionMap(),
1,nghost,MFInfo(),amr_level.Factory());
Expand Down Expand Up @@ -1103,12 +1063,6 @@ Projection::initialSyncProject (int c_lev,
ConvertUnew(*vel[lev], u_o, dt, LevelData[lev]->boxArray());
}

if (OutFlowBC::HasOutFlowBC(phys_bc) && have_divu && do_outflow_bcs) {
set_outflow_bcs(INITIAL_SYNC,phi,vel,
amrex::GetVecOfPtrs(rhcc),
sig,c_lev,f_lev,have_divu);
}

//
// Scale initial sync projection variables.
//
Expand Down Expand Up @@ -1606,7 +1560,7 @@ Projection::initialVorticityProject (int c_lev)
//
// Project.
//
bool proj2 = !add_vort_proj;
bool proj2 = true;
doMLMGNodalProjection(c_lev, f_lev-c_lev+1,
amrex::GetVecOfPtrs(u_real),
amrex::GetVecOfPtrs(p_real),
Expand Down Expand Up @@ -1639,14 +1593,7 @@ Projection::initialVorticityProject (int c_lev)
for (MFIter mfi(*vel[lev],true); mfi.isValid(); ++mfi)
{
const Box& box = mfi.tilebox();
if (add_vort_proj)
{
(*vel[lev])[mfi].plus<RunOn::Gpu>((*u_real[lev])[mfi],box,Xvel+n,Xvel+idx[n], 1);
}
else
{
(*vel[lev])[mfi].copy<RunOn::Gpu>((*u_real[lev])[mfi],box,Xvel+n,box,Xvel+idx[n], 1);
}
(*vel[lev])[mfi].copy<RunOn::Gpu>((*u_real[lev])[mfi],box,Xvel+n,box,Xvel+idx[n], 1);
}
}
}
Expand Down Expand Up @@ -1742,16 +1689,11 @@ Projection::getStreamFunction (Vector<std::unique_ptr<MultiFab> >& /*phi*/) // N
void
Projection::set_outflow_bcs (int which_call,
const Vector<MultiFab*>& phi,
const Vector<MultiFab*>& Vel_in,
const Vector<MultiFab*>& Divu_in,
const Vector<MultiFab*>& Sig_in,
int c_lev,
int f_lev,
int have_divu)
int f_lev)
{
AMREX_ASSERT((which_call == INITIAL_VEL ) ||
(which_call == INITIAL_PRESS) ||
(which_call == INITIAL_SYNC ) ||
AMREX_ASSERT((which_call == INITIAL_PRESS) ||
(which_call == LEVEL_PROJ ) );

if (which_call != LEVEL_PROJ)
Expand All @@ -1760,7 +1702,7 @@ Projection::set_outflow_bcs (int which_call,
if (verbose)
amrex::Print() << "...setting outflow bcs for the nodal projection ... " << '\n';

bool hasOutFlow;
bool hasOutFlow; // out-param of GetOutFlowFaces; the callers already checked it
Orientation outFaces[2*AMREX_SPACEDIM];
Orientation outFacesAtThisLevel[maxlev][2*AMREX_SPACEDIM];

Expand All @@ -1769,19 +1711,14 @@ Projection::set_outflow_bcs (int which_call,
int numOutFlowFacesAtAllLevels;
int numOutFlowFaces[maxlev];
OutFlowBC::GetOutFlowFaces(hasOutFlow,outFaces,phys_bc,numOutFlowFacesAtAllLevels);
amrex::ignore_unused(hasOutFlow);

//
// Get 2-wide cc box, state_strip, along interior of top.
// Get 1-wide nc box, phi_strip , along top.
//
const int ccStripWidth = 2;

// const int nCompPhi = 1;
// const int srcCompVel = Xvel;
// const int srcCompDivu = 0;
// const int nCompVel = AMREX_SPACEDIM;
// const int nCompDivu = 1;

//
// Determine the finest level such that the entire outflow face is covered
// by boxes at this level (skip if doesn't touch, and bomb if only partially
Expand Down Expand Up @@ -1850,53 +1787,36 @@ Projection::set_outflow_bcs (int which_call,
numOutFlowFaces[lev] = icount[lev];
}

int Divu_Type, Divu;
Real gravity = 0;

if (which_call == INITIAL_SYNC || which_call == INITIAL_VEL)
{
if (!AmrLevel::isStateVariable("divu", Divu_Type, Divu))
amrex::Error("Projection::set_outflow_bcs: No divu.");
}

if (which_call == INITIAL_PRESS || which_call == LEVEL_PROJ)
{
gravity = NavierStokesBase::getGravity();
if (!AmrLevel::isStateVariable("divu", Divu_Type, Divu) && (gravity == 0) ) {
amrex::Error("Projection::set_outflow_bcs: No divu or gravity.");
}
}
//
// The only outflow condition left is the hydrostatic rho*g computed in
// computeRhoG, so both callers gate on gravity being non-zero.
//
const Real gravity = NavierStokesBase::getGravity();
AMREX_ALWAYS_ASSERT(std::fabs(gravity) > 0.);

for (int lev = c_lev; lev <= f_lev; lev++)
{
if (numOutFlowFaces[lev] > 0)
set_outflow_bcs_at_level (which_call,lev,c_lev,
set_outflow_bcs_at_level (lev,c_lev,
state_strip[lev],
outFacesAtThisLevel[lev],
numOutFlowFaces[lev],
phi,
Vel_in[lev],
Divu_in[lev],
Sig_in[lev],
have_divu,
gravity);

}

}

void
Projection::set_outflow_bcs_at_level (int /*which_call*/,
int lev,
Projection::set_outflow_bcs_at_level (int lev,
int c_lev,
Box* state_strip,
Orientation* outFacesAtThisLevel,
int numOutFlowFaces,
const Vector<MultiFab*>& phi,
MultiFab* /*Vel_in*/,
MultiFab* /*Divu_in*/,
MultiFab* Sig_in,
int /*have_divu*/,
Real gravity)
{
AMREX_ASSERT(dynamic_cast<NavierStokesBase*>(LevelData[lev]) != nullptr);
Expand Down
Loading