Skip to content

Commit

Permalink
Revert "try adding independent sparse field to advection example"
Browse files Browse the repository at this point in the history
This reverts commit cb03e10.
  • Loading branch information
jlippuner committed Sep 27, 2021
1 parent cb03e10 commit b2b1f74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
33 changes: 4 additions & 29 deletions example/advection/advection_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "advection_package.hpp"
#include "defs.hpp"
#include "interface/sparse_pool.hpp"
#include "kokkos_abstraction.hpp"
#include "reconstruct/dc_inline.hpp"
#include "utils/error_checking.hpp"
Expand Down Expand Up @@ -57,10 +56,6 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
Real derefine_tol = pin->GetOrAddReal("Advection", "derefine_tol", 0.03);
pkg->AddParam<>("derefine_tol", derefine_tol);

// add a sparse independent field
bool sparse_indep = pin->GetOrAddBoolean("Advection", "sparse_independent", true);
pkg->AddParam<>("sparse_indep", sparse_indep);

auto profile_str = pin->GetOrAddString("Advection", "profile", "wave");
if (!((profile_str == "wave") || (profile_str == "smooth_gaussian") ||
(profile_str == "hard_sphere") || (profile_str == "block"))) {
Expand Down Expand Up @@ -171,16 +166,6 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
std::vector<int>({vec_size}), advected_labels);
pkg->AddField(field_name, m);
}

if (sparse_indep) {
m = Metadata({Metadata::Cell, Metadata::Independent, Metadata::WithFluxes,
Metadata::FillGhost, Metadata::Sparse});
SparsePool pool("sparse_independent", m);
pool.Add(1);
pool.Add(-13, {2, 3}); // yes, negative sparse id and different shape
pkg->AddSparsePool(pool);
}

if (!v_const) {
m = Metadata({Metadata::Cell, Metadata::Independent, Metadata::WithFluxes,
Metadata::FillGhost, Metadata::Vector},
Expand Down Expand Up @@ -353,13 +338,8 @@ void PostFill(MeshBlockData<Real> *rc) {
IndexRange kb = pmb->cellbounds.GetBoundsK(IndexDomain::entire);

// check that we have the sparse indices we want
const auto x0 = pmb->coords.x1v(0);

if (x0 < -0.3) {
rc->AllocSparseID("one_minus_sqrt_one_minus_advected_sq", 12);
} else if (x0 > 0.3) {
rc->AllocSparseID("one_minus_sqrt_one_minus_advected_sq", 37);
}
rc->AllocSparseID("one_minus_sqrt_one_minus_advected_sq", 12);
rc->AllocSparseID("one_minus_sqrt_one_minus_advected_sq", 37);

// packing in principle unnecessary/convoluted here and just done for demonstration
std::vector<std::string> vars(
Expand All @@ -376,13 +356,8 @@ void PostFill(MeshBlockData<Real> *rc) {
pmb->par_for(
"advection_package::PostFill", 0, num_vars - 1, kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e, KOKKOS_LAMBDA(const int n, const int k, const int j, const int i) {
if (v.IsAllocated(out12 + n)) {
v(out12 + n, k, j, i) = 1.0 - sqrt(v(in + n, k, j, i));
}

if (v.IsAllocated(out37 + n)) {
v(out37 + n, k, j, i) = sqrt(v(in + n, k, j, i));
}
v(out12 + n, k, j, i) = 1.0 - sqrt(v(in + n, k, j, i));
v(out37 + n, k, j, i) = 1.0 - v(out12 + n, k, j, i);
});
}
}
Expand Down
36 changes: 0 additions & 36 deletions example/advection/parthenon_app_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
auto &data = pmb->meshblock_data.Get();

auto pkg = pmb->packages.Get("advection_package");
const auto &sparse_indep = pkg->Param<bool>("sparse_indep");
const auto &amp = pkg->Param<Real>("amp");
const auto &vel = pkg->Param<Real>("vel");
const auto &vx = pkg->Param<Real>("vx");
Expand Down Expand Up @@ -116,41 +115,6 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
q(idx_v + 2, 4, 10, 8) = -vz;
});
}

if (sparse_indep) {
// initialize sparse independent fields
auto coords = pmb->coords;
PackIndexMap index_map;
auto q =
data->PackVariables(std::vector<std::string>{"sparse_independent"}, index_map);
const auto sp1 = index_map.get("sparse_independent", 1).first;
const auto sp13_s = index_map.get("sparse_independent_-13").first;
const auto sp13_e = index_map.get("sparse_independent", -13).second;

pmb->par_for(
"Advection::ProblemGenerator", kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int k, const int j, const int i) {
Real rsq = coords.x1v(i) * coords.x1v(i) + coords.x2v(j) * coords.x2v(j) +
coords.x3v(k) * coords.x3v(k);

if (profile_type == 0) {
Real x = cos_a2 * (coords.x1v(i) * cos_a3 + coords.x2v(j) * sin_a3) +
coords.x3v(k) * sin_a2;
Real sn = std::sin(k_par * x);
q(n, k, j, i) = 1.0 + amp * sn * vel;
} else if (profile_type == 1) {
Real rsq = coords.x1v(i) * coords.x1v(i) + coords.x2v(j) * coords.x2v(j) +
coords.x3v(k) * coords.x3v(k);
q(n, k, j, i) = 1. + amp * exp(-100.0 * rsq);
} else if (profile_type == 2) {
Real rsq = coords.x1v(i) * coords.x1v(i) + coords.x2v(j) * coords.x2v(j) +
coords.x3v(k) * coords.x3v(k);
q(n, k, j, i) = (rsq < 0.15 * 0.15 ? 1.0 : 0.0);
} else {
q(n, k, j, i) = 0.0;
}
});
}
}

//========================================================================================
Expand Down

0 comments on commit b2b1f74

Please sign in to comment.