本文整理汇总了C++中MultiFab::DistributionMap方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiFab::DistributionMap方法的具体用法?C++ MultiFab::DistributionMap怎么用?C++ MultiFab::DistributionMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiFab
的用法示例。
在下文中一共展示了MultiFab::DistributionMap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset_e_src
void
Nyx::strang_second_step (Real time, Real dt, MultiFab& S_new, MultiFab& D_new)
{
BL_PROFILE("Nyx::strang_second_step()");
Real half_dt = 0.5*dt;
int min_iter = 100000;
int max_iter = 0;
int min_iter_grid;
int max_iter_grid;
// Set a at the half of the time step in the second strang
const Real a = get_comoving_a(time-half_dt);
MultiFab reset_e_src(S_new.boxArray(), S_new.DistributionMap(), 1, NUM_GROW);
reset_e_src.setVal(0.0);
reset_internal_energy(S_new,D_new,reset_e_src);
compute_new_temp (S_new,D_new);
#ifndef FORCING
{
const Real z = 1.0/a - 1.0;
fort_interp_to_this_z(&z);
}
#endif
#ifdef _OPENMP
#pragma omp parallel private(min_iter_grid,max_iter_grid) reduction(min:min_iter) reduction(max:max_iter)
#endif
for (MFIter mfi(S_new,true); mfi.isValid(); ++mfi)
{
// Here bx is just the valid region
const Box& bx = mfi.tilebox();
min_iter_grid = 100000;
max_iter_grid = 0;
integrate_state
(bx.loVect(), bx.hiVect(),
BL_TO_FORTRAN(S_new[mfi]),
BL_TO_FORTRAN(D_new[mfi]),
&a, &half_dt, &min_iter_grid, &max_iter_grid);
if (S_new[mfi].contains_nan(bx,0,S_new.nComp()))
{
std::cout << "NANS IN THIS GRID " << bx << std::endl;
}
min_iter = std::min(min_iter,min_iter_grid);
max_iter = std::max(max_iter,max_iter_grid);
}
ParallelDescriptor::ReduceIntMax(max_iter);
ParallelDescriptor::ReduceIntMin(min_iter);
if (heat_cool_type == 1)
if (ParallelDescriptor::IOProcessor())
std::cout << "Min/Max Number of Iterations in Second Strang: " << min_iter << " " << max_iter << std::endl;
}
示例2: cdr
//.........这里部分代码省略.........
// This "probably" works, but is not strictly needed just because of the way Bill
// coded up the tangential derivative stuff. It's handy code though, so I want to
// keep it around/
// Clean up corners:
// The problem here is that APPLYBC fills only grow cells normal to the boundary.
// As a result, any corner cell on the boundary (either coarse-fine or fine-fine)
// is not filled. For coarse-fine, the operator adjusts itself, sliding away from
// the box edge to avoid referencing that corner point. On the physical boundary
// though, the corner point is needed. Particularly if a fine-fine boundary intersects
// the physical boundary, since we want the stencil to be independent of the box
// blocking. FillBoundary operations wont fix the problem because the "good"
// data we need is living in the grow region of adjacent fabs. So, here we play
// the usual games to treat the newly filled grow cells as "valid" data.
// Note that we only need to do something where the grids touch the physical boundary.
const Geometry& geomlev = geomarray[level];
const BoxArray& grids = inout.boxArray();
const Box& domain = geomlev.Domain();
int nGrow = 1;
int src_comp = 0;
int num_comp = BL_SPACEDIM;
// Lets do a quick check to see if we need to do anything at all here
BoxArray BIGba = BoxArray(grids).grow(nGrow);
if (! (domain.contains(BIGba.minimalBox())) ) {
BoxArray boundary_pieces;
Array<int> proc_idxs;
Array<Array<int> > old_to_new(grids.size());
const DistributionMapping& dmap=inout.DistributionMap();
for (int d=0; d<BL_SPACEDIM; ++d) {
if (! (geomlev.isPeriodic(d)) ) {
BoxArray gba = BoxArray(grids).grow(d,nGrow);
for (int i=0; i<gba.size(); ++i) {
BoxArray new_pieces = BoxLib::boxComplement(gba[i],domain);
int size_new = new_pieces.size();
if (size_new>0) {
int size_old = boundary_pieces.size();
boundary_pieces.resize(size_old+size_new);
proc_idxs.resize(boundary_pieces.size());
for (int j=0; j<size_new; ++j) {
boundary_pieces.set(size_old+j,new_pieces[j]);
proc_idxs[size_old+j] = dmap[i];
old_to_new[i].push_back(size_old+j);
}
}
}
}
}
proc_idxs.push_back(ParallelDescriptor::MyProc());
MultiFab boundary_data(boundary_pieces,num_comp,nGrow,
DistributionMapping(proc_idxs));
for (MFIter mfi(inout); mfi.isValid(); ++mfi) {
const FArrayBox& src_fab = inout[mfi];
for (int j=0; j<old_to_new[mfi.index()].size(); ++j) {
int new_box_idx = old_to_new[mfi.index()][j];
boundary_data[new_box_idx].copy(src_fab,src_comp,0,num_comp);
示例3: reset_e_src
void
Nyx::sdc_reactions (MultiFab& S_old, MultiFab& S_new, MultiFab& D_new,
MultiFab& hydro_src, MultiFab& IR,
Real delta_time, Real a_old, Real a_new, int sdc_iter)
{
BL_PROFILE("Nyx::sdc_reactions()");
const Real* dx = geom.CellSize();
// First reset internal energy before call to compute_temp
MultiFab reset_e_src(S_new.boxArray(), S_new.DistributionMap(), 1, NUM_GROW);
reset_e_src.setVal(0.0);
reset_internal_energy(S_new,D_new,reset_e_src);
compute_new_temp (S_new,D_new);
#ifndef FORCING
{
const Real z = 1.0/a_old - 1.0;
fort_interp_to_this_z(&z);
}
#endif
int min_iter = 100000;
int max_iter = 0;
int min_iter_grid, max_iter_grid;
/////////////////////Consider adding ifdefs for whether CVODE is compiled in for these statements
if(heat_cool_type == 3)
{
#ifdef _OPENMP
#pragma omp parallel
#endif
for (MFIter mfi(S_old,true); mfi.isValid(); ++mfi)
{
// Note that this "bx" is only the valid region (unlike for Strang)
const Box& bx = mfi.tilebox();
min_iter_grid = 100000;
max_iter_grid = 0;
integrate_state_with_source
(bx.loVect(), bx.hiVect(),
BL_TO_FORTRAN(S_old[mfi]),
BL_TO_FORTRAN(S_new[mfi]),
BL_TO_FORTRAN(D_new[mfi]),
BL_TO_FORTRAN(hydro_src[mfi]),
BL_TO_FORTRAN(reset_e_src[mfi]),
BL_TO_FORTRAN(IR[mfi]),
&a_old, &delta_time, &min_iter_grid, &max_iter_grid);
min_iter = std::min(min_iter,min_iter_grid);
max_iter = std::max(max_iter,max_iter_grid);
}
}
else if(heat_cool_type == 5)
{
#ifdef _OPENMP
#pragma omp parallel
#endif
for (MFIter mfi(S_old,true); mfi.isValid(); ++mfi)
{
// Note that this "bx" is only the valid region (unlike for Strang)
const Box& bx = mfi.tilebox();
min_iter_grid = 100000;
max_iter_grid = 0;
integrate_state_fcvode_with_source
(bx.loVect(), bx.hiVect(),
BL_TO_FORTRAN(S_old[mfi]),
BL_TO_FORTRAN(S_new[mfi]),
BL_TO_FORTRAN(D_new[mfi]),
BL_TO_FORTRAN(hydro_src[mfi]),
BL_TO_FORTRAN(reset_e_src[mfi]),
BL_TO_FORTRAN(IR[mfi]),
&a_old, &delta_time, &min_iter_grid, &max_iter_grid);
min_iter = std::min(min_iter,min_iter_grid);
max_iter = std::max(max_iter,max_iter_grid);
}
}
ParallelDescriptor::ReduceIntMax(max_iter);
ParallelDescriptor::ReduceIntMin(min_iter);
amrex::Print() << "Min/Max Number of Iterations in SDC: " << min_iter << " " << max_iter << std::endl;
}
示例4: ph
int
CGSolver::solve_bicgstab (MultiFab& sol,
const MultiFab& rhs,
Real eps_rel,
Real eps_abs,
LinOp::BC_Mode bc_mode)
{
BL_PROFILE("CGSolver::solve_bicgstab()");
const int nghost = sol.nGrow(), ncomp = 1;
const BoxArray& ba = sol.boxArray();
const DistributionMapping& dm = sol.DistributionMap();
BL_ASSERT(sol.nComp() == ncomp);
BL_ASSERT(sol.boxArray() == Lp.boxArray(lev));
BL_ASSERT(rhs.boxArray() == Lp.boxArray(lev));
MultiFab ph(ba, ncomp, nghost, dm);
MultiFab sh(ba, ncomp, nghost, dm);
MultiFab sorig(ba, ncomp, 0, dm);
MultiFab p (ba, ncomp, 0, dm);
MultiFab r (ba, ncomp, 0, dm);
MultiFab s (ba, ncomp, 0, dm);
MultiFab rh (ba, ncomp, 0, dm);
MultiFab v (ba, ncomp, 0, dm);
MultiFab t (ba, ncomp, 0, dm);
Lp.residual(r, rhs, sol, lev, bc_mode);
MultiFab::Copy(sorig,sol,0,0,1,0);
MultiFab::Copy(rh, r, 0,0,1,0);
sol.setVal(0);
const LinOp::BC_Mode temp_bc_mode = LinOp::Homogeneous_BC;
#ifdef CG_USE_OLD_CONVERGENCE_CRITERIA
Real rnorm = norm_inf(r);
#else
//
// Calculate the local values of these norms & reduce their values together.
//
Real vals[2] = { norm_inf(r, true), Lp.norm(0, lev, true) };
ParallelDescriptor::ReduceRealMax(vals,2,color());
Real rnorm = vals[0];
const Real Lp_norm = vals[1];
Real sol_norm = 0;
#endif
const Real rnorm0 = rnorm;
if ( verbose > 0 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev);
std::cout << "CGSolver_BiCGStab: Initial error (error0) = " << rnorm0 << '\n';
}
int ret = 0, nit = 1;
Real rho_1 = 0, alpha = 0, omega = 0;
if ( rnorm0 == 0 || rnorm0 < eps_abs )
{
if ( verbose > 0 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev);
std::cout << "CGSolver_BiCGStab: niter = 0,"
<< ", rnorm = " << rnorm
<< ", eps_abs = " << eps_abs << std::endl;
}
return ret;
}
for (; nit <= maxiter; ++nit)
{
const Real rho = dotxy(rh,r);
if ( rho == 0 )
{
ret = 1; break;
}
if ( nit == 1 )
{
MultiFab::Copy(p,r,0,0,1,0);
}
else
{
const Real beta = (rho/rho_1)*(alpha/omega);
sxay(p, p, -omega, v);
sxay(p, r, beta, p);
}
if ( use_mg_precond )
{
ph.setVal(0);
mg_precond->solve(ph, p, eps_rel, eps_abs, temp_bc_mode);
}
else if ( use_jacobi_precond )
{
ph.setVal(0);
Lp.jacobi_smooth(ph, p, lev, temp_bc_mode);
//.........这里部分代码省略.........
示例5: PR
int
CGSolver::solve_cabicgstab (MultiFab& sol,
const MultiFab& rhs,
Real eps_rel,
Real eps_abs,
LinOp::BC_Mode bc_mode)
{
BL_PROFILE("CGSolver::solve_cabicgstab()");
BL_ASSERT(sol.nComp() == 1);
BL_ASSERT(sol.boxArray() == Lp.boxArray(lev));
BL_ASSERT(rhs.boxArray() == Lp.boxArray(lev));
Real temp1[4*SSS_MAX+1];
Real temp2[4*SSS_MAX+1];
Real temp3[4*SSS_MAX+1];
Real Tp[4*SSS_MAX+1][4*SSS_MAX+1];
Real Tpp[4*SSS_MAX+1][4*SSS_MAX+1];
Real aj[4*SSS_MAX+1];
Real cj[4*SSS_MAX+1];
Real ej[4*SSS_MAX+1];
Real Tpaj[4*SSS_MAX+1];
Real Tpcj[4*SSS_MAX+1];
Real Tppaj[4*SSS_MAX+1];
Real G[4*SSS_MAX+1][4*SSS_MAX+1]; // Extracted from first 4*SSS+1 columns of Gg[][]. indexed as [row][col]
Real g[4*SSS_MAX+1]; // Extracted from last [4*SSS+1] column of Gg[][].
Real Gg[(4*SSS_MAX+1)*(4*SSS_MAX+2)]; // Buffer to hold the Gram-like matrix produced by matmul(). indexed as [row*(4*SSS+2) + col]
//
// If variable_SSS we "telescope" SSS.
// We start with 1 and increase it up to SSS_MAX on the outer iterations.
//
if (variable_SSS) SSS = 1;
zero( aj, 4*SSS_MAX+1);
zero( cj, 4*SSS_MAX+1);
zero( ej, 4*SSS_MAX+1);
zero( Tpaj, 4*SSS_MAX+1);
zero( Tpcj, 4*SSS_MAX+1);
zero(Tppaj, 4*SSS_MAX+1);
zero(temp1, 4*SSS_MAX+1);
zero(temp2, 4*SSS_MAX+1);
zero(temp3, 4*SSS_MAX+1);
SetMonomialBasis(Tp,Tpp,SSS);
const int ncomp = 1, nghost = sol.nGrow();
//
// Contains the matrix powers of p[] and r[].
//
// First 2*SSS+1 components are powers of p[].
// Next 2*SSS components are powers of r[].
//
const BoxArray& ba = sol.boxArray();
const DistributionMapping& dm = sol.DistributionMap();
MultiFab PR(ba, 4*SSS_MAX+1, 0, dm);
MultiFab p(ba, ncomp, 0, dm);
MultiFab r(ba, ncomp, 0, dm);
MultiFab rt(ba, ncomp, 0, dm);
MultiFab tmp(ba, 4, nghost, dm);
Lp.residual(r, rhs, sol, lev, bc_mode);
BL_ASSERT(!r.contains_nan());
MultiFab::Copy(rt,r,0,0,1,0);
MultiFab::Copy( p,r,0,0,1,0);
const Real rnorm0 = norm_inf(r);
Real delta = dotxy(r,rt);
const Real L2_norm_of_rt = sqrt(delta);
const LinOp::BC_Mode temp_bc_mode = LinOp::Homogeneous_BC;
if ( verbose > 0 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev);
std::cout << "CGSolver_CABiCGStab: Initial error (error0) = " << rnorm0 << '\n';
}
if ( rnorm0 == 0 || delta == 0 || rnorm0 < eps_abs )
{
if ( verbose > 0 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev);
std::cout << "CGSolver_CABiCGStab: niter = 0,"
<< ", rnorm = " << rnorm0
<< ", delta = " << delta
<< ", eps_abs = " << eps_abs << '\n';
}
return 0;
}
int niters = 0, ret = 0;
Real L2_norm_of_resid = 0, atime = 0, gtime = 0;
bool BiCGStabFailed = false, BiCGStabConverged = false;
//.........这里部分代码省略.........
示例6: sorig
int
CGSolver::jbb_precond (MultiFab& sol,
const MultiFab& rhs,
int lev,
LinOp& Lp)
{
//
// This is a local routine. No parallel is allowed to happen here.
//
int lev_loc = lev;
const Real eps_rel = 1.e-2;
const Real eps_abs = 1.e-16;
const int nghost = sol.nGrow();
const int ncomp = sol.nComp();
const bool local = true;
const LinOp::BC_Mode bc_mode = LinOp::Homogeneous_BC;
BL_ASSERT(ncomp == 1 );
BL_ASSERT(sol.boxArray() == Lp.boxArray(lev_loc));
BL_ASSERT(rhs.boxArray() == Lp.boxArray(lev_loc));
const BoxArray& ba = sol.boxArray();
const DistributionMapping& dm = sol.DistributionMap();
MultiFab sorig(ba, ncomp, nghost, dm);
MultiFab r(ba, ncomp, nghost, dm);
MultiFab z(ba, ncomp, nghost, dm);
MultiFab q(ba, ncomp, nghost, dm);
MultiFab p(ba, ncomp, nghost, dm);
sorig.copy(sol);
Lp.residual(r, rhs, sorig, lev_loc, LinOp::Homogeneous_BC, local);
sol.setVal(0);
Real rnorm = norm_inf(r,local);
const Real rnorm0 = rnorm;
Real minrnorm = rnorm;
if ( verbose > 2 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev_loc);
std::cout << " jbb_precond: Initial error : " << rnorm0 << '\n';
}
const Real Lp_norm = Lp.norm(0, lev_loc, local);
Real sol_norm = 0;
int ret = 0; // will return this value if all goes well
Real rho_1 = 0;
int nit = 1;
if ( rnorm0 == 0 || rnorm0 < eps_abs )
{
if ( verbose > 2 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev_loc);
std::cout << "jbb_precond: niter = 0,"
<< ", rnorm = " << rnorm
<< ", eps_abs = " << eps_abs << std::endl;
}
return 0;
}
for (; nit <= maxiter; ++nit)
{
z.copy(r);
Real rho = dotxy(z,r,local);
if (nit == 1)
{
p.copy(z);
}
else
{
Real beta = rho/rho_1;
sxay(p, z, beta, p);
}
Lp.apply(q, p, lev_loc, bc_mode, local);
Real alpha;
if ( Real pw = dotxy(p,q,local) )
{
alpha = rho/pw;
}
else
{
ret = 1; break;
}
if ( verbose > 3 && ParallelDescriptor::IOProcessor(color()) )
{
Spacer(std::cout, lev_loc);
std::cout << "jbb_precond:" << " nit " << nit
<< " rho " << rho << " alpha " << alpha << '\n';
}
sxay(sol, sol, alpha, p);
sxay( r, r,-alpha, q);
//.........这里部分代码省略.........