Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Adaptive Mesh Refinement

Kengo TOMIDA edited this page Feb 29, 2016 · 29 revisions

Enabling Adaptive Mesh Refinement

Like Static Mesh Refinement, no configuration option is needed to enable AMR. You need to set the refinement parameters in the input file. For example,

<mesh>
...
refinement     = adaptive
numlevels      = 4
deref_count    = 5

This means the finer levels are created up to 4 levels (= the root level + 3 finer levels). The deref_count parameter means that at least 5 timesteps are required to be flagged for derefinement before a MeshBlock is actually derefined. This suppresses destruction of newly-refined MeshBlocks immediately after refinement.

The AMR Condition Function

Then a function to check whether a MeshBlock should be refined or derefined must be defined and enrolled in the Problem Generator. For example, in src/pgen/dmr.cpp,

int RefinementCondition(MeshBlock *pmb)
{
  AthenaArray<Real> &w = pmb->phydro->w;
  Real maxeps=0.0;
  int k=pmb->ks;
  for(int j=pmb->js; j<=pmb->je; j++) {
    for(int i=pmb->is; i<=pmb->ie; i++) {
      Real epsr= (std::abs(w(IDN,k,j,i+1)-2.0*w(IDN,k,j,i)+w(IDN,k,j,i-1))
                 +std::abs(w(IDN,k,j+1,i)-2.0*w(IDN,k,j,i)+w(IDN,k,j-1,i)))/w(IDN,k,j,i);
      Real epsp= (std::abs(w(IEN,k,j,i+1)-2.0*w(IEN,k,j,i)+w(IEN,k,j,i-1))
                 +std::abs(w(IEN,k,j+1,i)-2.0*w(IEN,k,j,i)+w(IEN,k,j-1,i)))/w(IEN,k,j,i);
      Real eps = std::max(epsr, epsp);
      maxeps = std::max(maxeps, eps);
    }
  }
  if(maxeps > 0.01) return 1;
  if(maxeps < 0.005) return -1;
  return 0;
}

Clone this wiki locally