|
| 1 | +// |
| 2 | +// Process a sedov problem to produce rho, u, and p as a |
| 3 | +// function of r, for comparison to the analytic solution. |
| 4 | +// |
| 5 | +#include <iostream> |
| 6 | +// #include <stringstream> |
| 7 | +#include <regex> |
| 8 | +#include <string> |
| 9 | +#include <AMReX_PlotFileUtil.H> |
| 10 | +#include <AMReX_MultiFabUtil.H> |
| 11 | +#include <AMReX_ParallelDescriptor.H> |
| 12 | + |
| 13 | +#include <amrex_astro_util.H> |
| 14 | + |
| 15 | +#include <extern_parameters.H> |
| 16 | + |
| 17 | +#include <network.H> |
| 18 | +#include <eos.H> |
| 19 | + |
| 20 | +using namespace amrex; |
| 21 | + |
| 22 | + |
| 23 | +int main(int argc, char* argv[]) |
| 24 | +{ |
| 25 | + |
| 26 | + amrex::Initialize(argc, argv); |
| 27 | + |
| 28 | + // initialize the runtime parameters |
| 29 | + |
| 30 | + init_extern_parameters(); |
| 31 | + |
| 32 | + // initialize C++ Microphysics |
| 33 | + |
| 34 | + eos_init(diag_rp::small_temp, diag_rp::small_dens); |
| 35 | + network_init(); |
| 36 | + |
| 37 | + // timer for profiling |
| 38 | + |
| 39 | + BL_PROFILE_VAR("main()", pmain); |
| 40 | + |
| 41 | + // read the plotfile metadata |
| 42 | + |
| 43 | + PlotFileData pf(diag_rp::plotfile); |
| 44 | + |
| 45 | + int fine_level = pf.finestLevel(); |
| 46 | + const int dim = pf.spaceDim(); |
| 47 | + |
| 48 | + // find variable indices -- we want density, temperature, and species. |
| 49 | + // we will assume here that the species are contiguous, so we will find |
| 50 | + // the index of the first species |
| 51 | + |
| 52 | + // the plotfile can store either (rho X) or just X alone. Here we'll assume |
| 53 | + // that we have just X alone |
| 54 | + |
| 55 | + const Vector<std::string>& var_names_pf = pf.varNames(); |
| 56 | + |
| 57 | + int dens_comp = get_dens_index(var_names_pf); |
| 58 | + int temp_comp = get_temp_index(var_names_pf); |
| 59 | + int spec_comp = get_spec_index(var_names_pf); |
| 60 | + |
| 61 | + // we will use a mask that tells us if a zone on the current level |
| 62 | + // is covered by data on a finer level. |
| 63 | + |
| 64 | + for (int ilev = 0; ilev <= fine_level; ++ilev) { |
| 65 | + |
| 66 | + if (ilev < fine_level) { |
| 67 | + IntVect ratio{pf.refRatio(ilev)}; |
| 68 | + for (int idim = dim; idim < AMREX_SPACEDIM; ++idim) { |
| 69 | + ratio[idim] = 1; |
| 70 | + } |
| 71 | + const iMultiFab mask = makeFineMask(pf.boxArray(ilev), pf.DistributionMap(ilev), |
| 72 | + pf.boxArray(ilev+1), ratio); |
| 73 | + |
| 74 | + const MultiFab& lev_data_mf = pf.get(ilev); |
| 75 | + |
| 76 | + for (MFIter mfi(lev_data_mf); mfi.isValid(); ++mfi) { |
| 77 | + const Box& bx = mfi.validbox(); |
| 78 | + if (bx.ok()) { |
| 79 | + const auto& m = mask.array(mfi); |
| 80 | + const auto& fab = lev_data_mf.array(mfi); |
| 81 | + const auto lo = amrex::lbound(bx); |
| 82 | + const auto hi = amrex::ubound(bx); |
| 83 | + |
| 84 | + for (int k = lo.z; k <= hi.z; ++k) { |
| 85 | + for (int j = lo.y; j <= hi.y; ++j) { |
| 86 | + for (int i = lo.x; i <= hi.x; ++i) { |
| 87 | + |
| 88 | + // if we only wanted to work on the zones not covered |
| 89 | + // by finer grids (e.g., for computing a global sum) |
| 90 | + // we'd uncomment this mask check |
| 91 | + |
| 92 | + //if (m(i,j,k) == 0) { // not covered by fine |
| 93 | + |
| 94 | + // compute the coordinate of the current zone |
| 95 | + |
| 96 | + eos_t eos_state; |
| 97 | + |
| 98 | + eos_state.rho = fab(i,j,k,dens_comp); |
| 99 | + eos_state.T = fab(i,j,k,temp_comp); |
| 100 | + for (int n = 0; n < NumSpec; ++n) { |
| 101 | + eos_state.xn[n] = fab(i,j,k,spec_comp+n); |
| 102 | + } |
| 103 | + |
| 104 | + eos(eos_input_rt, eos_state); |
| 105 | + |
| 106 | + // } // mask |
| 107 | + |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + } // bx.ok() |
| 113 | + |
| 114 | + } // MFIter |
| 115 | + |
| 116 | + } else { |
| 117 | + // this is the finest level |
| 118 | + |
| 119 | + const MultiFab& lev_data_mf = pf.get(ilev); |
| 120 | + |
| 121 | + for (MFIter mfi(lev_data_mf); mfi.isValid(); ++mfi) { |
| 122 | + const Box& bx = mfi.validbox(); |
| 123 | + if (bx.ok()) { |
| 124 | + const auto& fab = lev_data_mf.array(mfi); |
| 125 | + const auto lo = amrex::lbound(bx); |
| 126 | + const auto hi = amrex::ubound(bx); |
| 127 | + |
| 128 | + for (int k = lo.z; k <= hi.z; ++k) { |
| 129 | + for (int j = lo.y; j <= hi.y; ++j) { |
| 130 | + for (int i = lo.x; i <= hi.x; ++i) { |
| 131 | + |
| 132 | + eos_t eos_state; |
| 133 | + |
| 134 | + eos_state.rho = fab(i,j,k,dens_comp); |
| 135 | + eos_state.T = fab(i,j,k,temp_comp); |
| 136 | + for (int n = 0; n < NumSpec; ++n) { |
| 137 | + eos_state.xn[n] = fab(i,j,k,spec_comp+n); |
| 138 | + } |
| 139 | + |
| 140 | + eos(eos_input_rt, eos_state); |
| 141 | + |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + } // bx.ok() |
| 147 | + |
| 148 | + } // MFIter |
| 149 | + |
| 150 | + |
| 151 | + } |
| 152 | + |
| 153 | + } // level loop |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + // destroy timer for profiling |
| 158 | + BL_PROFILE_VAR_STOP(pmain); |
| 159 | + |
| 160 | + amrex::Finalize(); |
| 161 | +} |
| 162 | + |
0 commit comments