-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create simple exe to read in SF plt file and print data as ASCII file.
- Loading branch information
Matthew Blomquist
committed
Nov 16, 2024
1 parent
66ae99d
commit 1639ca5
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
AMREX_HOME ?= ../../../../amrex/ | ||
|
||
DEBUG = TRUE | ||
#DEBUG = FALSE | ||
|
||
DIM = 3 | ||
DIM = 2 | ||
|
||
COMP = gcc | ||
|
||
PRECISION = DOUBLE | ||
|
||
USE_MPI = FALSE | ||
USE_OMP = FALSE | ||
|
||
################################################### | ||
|
||
EBASE = WriteSFToASCII | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.defs | ||
|
||
include ./Make.package | ||
include $(AMREX_HOME)/Src/Base/Make.package | ||
|
||
vpath %.c : . $(vpathdir) | ||
vpath %.h : . $(vpathdir) | ||
vpath %.cpp : . $(vpathdir) | ||
vpath %.H : . $(vpathdir) | ||
vpath %.F : . $(vpathdir) | ||
vpath %.f : . $(vpathdir) | ||
vpath %.f90 : . $(vpathdir) | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.rules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CEXE_sources += ${EBASE}.cpp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
#include <AMReX_ParmParse.H> | ||
#include <AMReX_PlotFileUtil.H> | ||
|
||
using namespace std; | ||
using namespace amrex; | ||
|
||
int main (int argc, char* argv[]) { | ||
|
||
amrex::Initialize(argc,argv); | ||
|
||
MultiFab mf; | ||
|
||
// Parse command-line arguments | ||
std::string plt_file; | ||
int n_bins; | ||
|
||
for (int i = 1; i < argc; ++i) { | ||
std::string arg = argv[i]; | ||
if (arg == "-i" && i + 1 < argc) { | ||
plt_file= argv[++i]; | ||
} | ||
|
||
if (arg == "-b" && i + 1 < argc) { | ||
n_bins = std::stoi(argv[++i]); | ||
} | ||
} | ||
|
||
// Append Level_0/Cell for mf read | ||
plt_file += "/Level_0/Cell"; | ||
std::cout << plt_file << std::endl; | ||
|
||
// read in plotfile to MultiFab | ||
VisMF::Read(mf, plt_file); | ||
//VisMF::Read(mf, "plt_SF_mag000200000/Level_0/Cell"); | ||
|
||
std::vector<std::pair<double, double>> sf_flat; | ||
|
||
const int center_x = 32; | ||
const int center_y = 32; | ||
|
||
for ( MFIter mfi(mf,false); mfi.isValid(); ++mfi ) { | ||
|
||
const Box& bx = mfi.validbox(); | ||
const auto lo = amrex::lbound(bx); | ||
const auto hi = amrex::ubound(bx); | ||
const Array4<Real>& mfdata = mf.array(mfi); | ||
|
||
// assume everything is 2d for now | ||
for (auto n=0; n<1; ++n) { | ||
for (auto k = lo.z; k <= hi.z; ++k) { | ||
for (auto j = lo.y; j <= hi.y; ++j) { | ||
for (auto i = lo.x; i <= hi.x; ++i) { | ||
auto dk_x = i - center_x; | ||
auto dk_y = j - center_y; | ||
auto dk = sqrt(dk_x*dk_x + dk_y*dk_y); | ||
|
||
sf_flat.push_back(std::make_pair(dk, mfdata(i,j,k,n))); | ||
//std::cout << dk << ", " << mfdata(i,j,0,n) << "\n"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // end MFIter | ||
|
||
// sort and bin data | ||
std::sort(sf_flat.begin(), sf_flat.end(), [](const auto& a, const auto& b) { | ||
return a.first < b.first; | ||
}); | ||
|
||
std::cout << "... and we are done!\n\n"; | ||
|
||
} | ||
|
||
|