Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/AMReX-Codes/amrex in…
Browse files Browse the repository at this point in the history
…to development
  • Loading branch information
JBlaschke committed Jan 26, 2019
2 parents 4ba6a33 + db3e728 commit 38d95b0
Show file tree
Hide file tree
Showing 498 changed files with 90,687 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Src/AmrTask/tutorials/Apps/Nyx_hydro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# latex intermediates
*.aux
*.log
*.dvi
*.toc
*.bbl
*.blg
*.lof
*.lot
*.idx
*.ilg
*.ind
*.backup
Docs/*.out
Docs/*.ps
Docs/*.pdf
Docs/*/*.pdf
UsersGuide/*.out
UsersGuide/*.pdf

# emacs temporaries
*~
\#*


# executables
*.ex
*.exe

# Nyx executables
Nyx*.ex

# plt and chk files
plt*
chk*
*plt?????
*chk?????
*plt?????.old*
*chk?????.old*
*.xmgr
ic_sb_32.ascii
fixed_grids

# build directories
o/
d/
f/
t/
tmp_build_dir/
AMReX_buildInfo.cpp
buildInfo.cpp

*.hack
*.bak
*.hlrn

Backtrace.*
junk

ChangeLog.Nyx
git.*
20 changes: 20 additions & 0 deletions Src/AmrTask/tutorials/Apps/Nyx_hydro/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
If you use Nyx, we appreciate you citing the main code paper:

@ARTICLE{Nyx,
author = {{Almgren}, A.~S. and {Bell}, J.~B. and {Lijewski}, M.~J. and
{Luki{\'c}}, Z. and {Van Andel}, E.},
title = "{Nyx: A Massively Parallel AMR Code for Computational Cosmology}",
journal = {The Astrophysical Journal},
archivePrefix = "arXiv",
eprint = {1301.4498},
primaryClass = "astro-ph.IM",
keywords = {gravitation, hydrodynamics, methods: numerical },
year = 2013,
month = mar,
volume = 765,
eid = {39},
pages = {39},
doi = {10.1088/0004-637X/765/1/39},
adsurl = {http://adsabs.harvard.edu/abs/2013ApJ...765...39A},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
215 changes: 215 additions & 0 deletions Src/AmrTask/tutorials/Apps/Nyx_hydro/Diagnostics/AmrDerive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
//BL_COPYRIGHT_NOTICE

#include <new>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <list>
#include <map>
#include <algorithm>

using std::cout;
using std::cerr;
using std::endl;

#ifndef WIN32
#include <unistd.h>
#endif

#include "AMReX_ParmParse.H"
#include "AMReX_ParallelDescriptor.H"
#include "AMReX_DataServices.H"
#include "AMReX_Utility.H"
#include "AMReX_FArrayBox.H"

using namespace amrex;

static
void
print_usage (int,
char* argv[])
{
cout << '\n';
cout << "Usage:" << '\n';
cout << " infile = plotfilename" << '\n';
cout << " [-verbose]" << '\n';
cout << '\n';
exit(1);

}

int
main (int argc,
char* argv[])
{
amrex::Initialize(argc,argv);

if (argc < 2)
print_usage(argc,argv);

ParmParse pp;

if (pp.contains("help"))
print_usage(argc,argv);

bool verbose = false;
if (pp.contains("verbose"))
{
verbose = true;
AmrData::SetVerbose(true);
}

std::string infile;
pp.get("infile",infile);

if (ParallelDescriptor::IOProcessor())
std::cout << "Reading " << infile << "...";

DataServices::SetBatchMode();
Amrvis::FileType fileType(Amrvis::NEWPLT);
DataServices dataServices(infile, fileType);
if( ! dataServices.AmrDataOk())
DataServices::Dispatch(DataServices::ExitRequest, NULL);

if (ParallelDescriptor::IOProcessor())
std::cout << "Done reading plot file" << std::endl;

AmrData& amrData = dataServices.AmrDataRef();

int finestLevel = amrData.FinestLevel();
pp.query("finestLevel",finestLevel); finestLevel=std::min(finestLevel,amrData.FinestLevel());
int Nlev = finestLevel + 1;

if (ParallelDescriptor::IOProcessor())
std::cout << "... finest level " << finestLevel << std::endl;

Vector<int> comps;
if (int nc = pp.countval("comps"))
{
comps.resize(nc);
pp.getarr("comps",comps,0,nc);
}
else
{
int sComp = 0;
pp.query("sComp",sComp);
int nComp = 1;
pp.query("nComp",nComp);
BL_ASSERT(sComp+nComp <= amrData.NComp());
comps.resize(nComp);
std::cout << "NCOMP NOW " << nComp << std::endl;
for (int i=0; i<nComp; ++i)
comps[i] = sComp + i;
}

int nComp = comps.size();
const Vector<string>& plotVarNames=amrData.PlotVarNames();
Vector<string> inVarNames(nComp);
Vector<int> destFillComps(nComp);
for (int i=0; i<nComp; ++i)
{
inVarNames[i] = plotVarNames[comps[i]];
std::cout << "plotVarNames " << plotVarNames[comps[i]] << std::endl;;
destFillComps[i] = i;
}

const int nGrow = 0;

if (ParallelDescriptor::IOProcessor() && verbose>0)
{
cerr << "Will read the following states: ";
for (int i=0; i<nComp; ++i)
cerr << " " << amrData.StateNumber(inVarNames[i]) << " (" << inVarNames[i] << ")" ;
cerr << '\n';
}

const Box& probDomain = amrData.ProbDomain()[finestLevel];
int dir=BL_SPACEDIM-1; pp.query("dir",dir);
const IntVect lo=probDomain.smallEnd();
IntVect hi=lo; hi[dir] = probDomain.bigEnd()[dir];
const Box resBox(lo,hi);
FArrayBox resFab(resBox,nComp); resFab.setVal(0.);

int accumFac = 1;
for (int lev=finestLevel; lev>=0; --lev)
{
const BoxArray& ba = amrData.boxArray(lev);
const DistributionMapping& dm = amrData.DistributionMap(lev);
MultiFab mf(ba,dm,nComp,nGrow);
if (ParallelDescriptor::IOProcessor() && verbose>0)
cerr << "...filling data at level " << lev << endl;
amrData.FillVar(mf,lev,inVarNames,destFillComps);

// Zero covered regions
if (lev < finestLevel)
{
const BoxArray baf = BoxArray(amrData.boxArray(lev+1)).coarsen(amrData.RefRatio()[lev]);

for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
FArrayBox& myFab = mf[mfi];
std::vector< std::pair<int,Box> > isects = baf.intersections(ba[mfi.index()]);

for (int ii = 0; ii < isects.size(); ii++)
myFab.setVal(0,isects[ii].second,0,nComp);
}
}

// Scale by "volume" (plane, 1 cell thick) of cells, normalized to volume of finest cells
mf.mult(accumFac*accumFac,0,nComp);

for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
const FArrayBox& fab = mf[mfi];
const Box& box = mfi.validbox();
IntVect ivlo = box.smallEnd();
IntVect ivhi = box.bigEnd(); ivhi[dir] = ivlo[dir];

for (int plane=box.smallEnd(dir); plane<=box.bigEnd(dir); ++plane)
{
ivlo[dir] = plane;
ivhi[dir] = plane;

Box subbox(ivlo,ivhi);
Vector<Real> thisSum(nComp);
for (int n=0; n<nComp; ++n)
thisSum[n] = fab.sum(subbox,n,1);

// Now, increment each sum affected by this coarse plane
for (int r=0; r<accumFac; ++r)
{
const int finePlane = plane*accumFac + r;
IntVect ivF=resBox.smallEnd(); ivF[dir] = finePlane;
for (int n=0; n<nComp; ++n)
resFab(ivF,n) += thisSum[n];
}
}
}

if (lev>0)
accumFac *= amrData.RefRatio()[lev-1];
}

// Accumulate sums from all processors to IOProc
ParallelDescriptor::ReduceRealSum(resFab.dataPtr(),nComp*resBox.numPts(),ParallelDescriptor::IOProcessorNumber());

if (ParallelDescriptor::IOProcessor())
{
// Scale result by total "volume" (plane, 1 cell thick) of slab at each plane
Real volume=1;
for (int d=0; d<BL_SPACEDIM; ++d)
if (d!=dir)
volume*=probDomain.length(d);

resFab.mult(1/volume);
std::cout << "RESFAB " << resFab << std::endl;
}


amrex::Finalize();
return 0;
}

52 changes: 52 additions & 0 deletions Src/AmrTask/tutorials/Apps/Nyx_hydro/Diagnostics/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# AMREX_HOME defines the directory in which we will find all the BoxLib code
AMREX_HOME ?= /project/projectdirs/nyx/src/amrex

# TOP defines the directory in which we will find Source, Exec, etc
TOP = ..

EBASE = AmrDerive

# compilation options
COMP = gcc

USE_MPI = TRUE
USE_OMP = FALSE

PRECISION = DOUBLE
DEBUG = TRUE
DEBUG = FALSE

DIM = 3

DEFINES += -DBL_NOLINEVALUES

include $(AMREX_HOME)/Tools/GNUMake/Make.defs

Bpack := ./Make.package
Blocs := .

include $(Bpack)
INCLUDE_LOCATIONS += $(Blocs)
VPATH_LOCATIONS += $(Blocs)

Pdirs := Base Extern/amrdata
Ppack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package)
Plocs += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir))

include $(Ppack)
INCLUDE_LOCATIONS += $(Plocs)
VPATH_LOCATIONS += $(Plocs)

vpath %.c . $(VPATH_LOCATIONS)
vpath %.cpp . $(VPATH_LOCATIONS)
vpath %.h . $(VPATH_LOCATIONS)
vpath %.H . $(VPATH_LOCATIONS)
vpath %.F . $(VPATH_LOCATIONS)
vpath %.f90 . $(VPATH_LOCATIONS)
vpath %.f . $(VPATH_LOCATIONS)
vpath %.fi . $(VPATH_LOCATIONS)

all: $(executable)
@echo SUCCESS

include $(AMREX_HOME)/Tools/GNUMake/Make.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CEXE_sources += AmrDerive.cpp
45 changes: 45 additions & 0 deletions Src/AmrTask/tutorials/Apps/Nyx_hydro/Diagnostics/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

********************************************** **********************************************

Program:

Given a N-dimensional data set, this program computes a one-dimensional
profile in direction "dir" where each value in the profile is the average of the data
in the non-"dir" directions. This can do multiple components at one time.

********************************************** **********************************************

Usage:

The following are equivalent and all work:

**********************************************

AmrDerive3d.Linux.gcc.gfortran.MPI.ex inputs

where the file inputs contains:

infile = plt00000
nComp = 1
sComp = 0

**********************************************

OR

**********************************************

AmrDerive3d.Linux.gcc.gfortran.MPI.ex infile=plt00000 nComp=2 sComp=0

**********************************************

OR

**********************************************

AmrDerive3d.Linux.gcc.gfortran.MPI.ex infile=plt00000 comps= 0 1


**********************************************

If you set verbose = 1 (command line or inputs file) then you will get all sort of output.
Loading

0 comments on commit 38d95b0

Please sign in to comment.