Skip to content

Commit

Permalink
IndexMap is a singleton class (#43)
Browse files Browse the repository at this point in the history
Good to go
  • Loading branch information
chengcli authored Jul 6, 2023
1 parent 1fba91c commit 9ab0d7d
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .gitcustom/git-done
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ currentBranch=$(git symbolic-ref --short -q HEAD) # Getting the current branch
git checkout main
git fetch
git rebase origin/main
git branch -D currentBranch
git branch -D $currentBranch
13 changes: 4 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ jobs:
runs-on: [self-hosted, linux, 4core]
needs: build-non-hydrostatic
steps:
- name: source
run: source ~/.bashrc

- uses: actions/checkout@v3

- name: create build directory
Expand Down Expand Up @@ -175,9 +172,6 @@ jobs:
runs-on: [self-hosted, Linux, 8core]
needs: build-non-hydrostatic
steps:
- name: source
run: source ~/.bashrc

- uses: actions/checkout@v3

- name: create build directory
Expand All @@ -190,6 +184,8 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j8

- name: run simulation
env:
PATH: $PATH:/usr/lib64/mpich/bin
run: cd ${{github.workspace}}/build/bin && mpiexec -n 8 ./robert.release -i robert2d.inp

- name: combile outputs
Expand All @@ -206,9 +202,6 @@ jobs:
runs-on: [self-hosted, Linux, 8core]
needs: build-non-hydrostatic
steps:
- name: source
run: source ~/.bashrc

- uses: actions/checkout@v3

- name: create build directory
Expand All @@ -221,6 +214,8 @@ jobs:
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j8

- name: run simulation
env:
PATH: $PATH:/usr/lib64/mpich/bin
run: cd ${{github.workspace}}/build/bin && mpiexec -n 8 ./robert.release -i robert3d.inp

- name: combile outputs
Expand Down
37 changes: 19 additions & 18 deletions examples/2023-jupiter-mwr-eq/juno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void MeshBlock::ProblemGenerator(ParameterInput *pin)
Real cp = gamma/(gamma - 1.)*Rd;

// index
auto pindex = IndexMap::GetInstance();
int iH2O = pindex->GetVaporId("H2O");
int iNH3 = pindex->GetVaporId("NH3");

Expand Down Expand Up @@ -218,24 +219,6 @@ void MeshBlock::ProblemGenerator(ParameterInput *pin)
}
}

// set tracers, electron and Na
int ielec = pindex->GetTracerId("e-");
int iNa = pindex->GetTracerId("Na");
auto ptracer = pimpl->ptracer;

for (int k = ks; k <= ke; ++k)
for (int j = js; j <= je; ++j)
for (int i = is; i <= ie; ++i) {
Real temp = pthermo->GetTemp(this,k,j,i);
Real pH2S = xH2S*phydro->w(IPR,k,j,i);
Real pNa = xNa*phydro->w(IPR,k,j,i);
Real svp = sat_vapor_p_Na_H2S_Visscher(temp, pH2S);
pNa = std::min(svp, pNa);

ptracer->u(iNa,k,j,i) = pNa/(Constants::kBoltz*temp);
ptracer->u(ielec,k,j,i) = saha_ionization_electron_density(temp, ptracer->u(iNa,k,j,i), 5.14);
}

// if requested
// modify atmospheric stability
Real adlnTdlnP = pin->GetOrAddReal("problem", "adlnTdlnP", 0.);
Expand Down Expand Up @@ -275,6 +258,24 @@ void MeshBlock::ProblemGenerator(ParameterInput *pin)
}
}

// set tracers, electron and Na
int ielec = pindex->GetTracerId("e-");
int iNa = pindex->GetTracerId("Na");
auto ptracer = pimpl->ptracer;

for (int k = ks; k <= ke; ++k)
for (int j = js; j <= je; ++j)
for (int i = is; i <= ie; ++i) {
Real temp = pthermo->GetTemp(this,k,j,i);
Real pH2S = xH2S*phydro->w(IPR,k,j,i);
Real pNa = xNa*phydro->w(IPR,k,j,i);
Real svp = sat_vapor_p_Na_H2S_Visscher(temp, pH2S);
pNa = std::min(svp, pNa);

ptracer->u(iNa,k,j,i) = pNa/(Constants::kBoltz*temp);
ptracer->u(ielec,k,j,i) = saha_ionization_electron_density(temp, ptracer->u(iNa,k,j,i), 5.14);
}

// primitive to conserved conversion
peos->PrimitiveToConserved(phydro->w, pfield->bcc,
phydro->u, pcoord, is, ie, js, je, ks, ke);
Expand Down
7 changes: 3 additions & 4 deletions examples/2023-jupiter-mwr-eq/juno.inp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ xNa = 3.97E-6
xKCl = 0.
metallicity = -2

#rdlnTdlnP = 1.015
rdlnTdlnP = 0.985
rdlnTdlnP.pmin = 1.E5
rdlnTdlnP.pmax = 20.E5
adlnTdlnP = 0.015
adlnTdlnP.pmin = 1.E5
adlnTdlnP.pmax = 20.E5
8 changes: 4 additions & 4 deletions src/harp/absorber.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// athena
#include <athena/athena.hpp>
#include <athena/mesh/mesh.hpp>

// canoe
#include <index_map.hpp>
Expand All @@ -17,15 +16,16 @@ Absorber::Absorber(std::string name) : name_(name) {
app->Log("Create Absorber " + name_);
}

Absorber::Absorber(MeshBlock* pmb, std::string name,
std::vector<std::string> species,
Absorber::Absorber(std::string name, std::vector<std::string> species,
std::map<std::string, Real> params)
: name_(name), params_(params) {
Application::Logger app("harp");
app->Log("Create Absorber " + name_);

auto pindex = IndexMap::GetInstance();

for (auto s : species) {
imols_.push_back(pmb->pindex->GetSpeciesId(s));
imols_.push_back(pindex->GetSpeciesId(s));
}

app->Log("Dependent species ids", imols_);
Expand Down
3 changes: 1 addition & 2 deletions src/harp/absorber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
#include <athena/athena.hpp>

class Variable;
class MeshBlock;

using ParameterMap = std::map<std::string, Real>;

class Absorber {
public:
explicit Absorber(std::string name);

Absorber(MeshBlock* pmb, std::string name, std::vector<std::string> species,
Absorber(std::string name, std::vector<std::string> species,
ParameterMap params);

std::string GetName() const { return name_; }
Expand Down
12 changes: 6 additions & 6 deletions src/harp/add_absorber_giants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ void RadiationBand::addAbsorberGiants(ParameterInput *pin, YAML::Node &node) {
if (type_ == "radio") {
if (aname == "NH3") {
auto ab = std::make_unique<gp::MwrAbsorberNH3>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else if (aname == "H2O") {
auto ab = std::make_unique<gp::MwrAbsorberH2O>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else if (aname == "H2S") {
auto ab = std::make_unique<gp::MwrAbsorberH2S>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else if (aname == "PH3") {
auto ab = std::make_unique<gp::MwrAbsorberPH3>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else if (aname == "CIA") {
auto ab = std::make_unique<gp::MwrAbsorberCIA>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else if (aname == "Electron") {
auto ab = std::make_unique<gp::MwrAbsorberElectron>(
pmy_block_, species, ToParameterMap(node["parameters"]));
species, ToParameterMap(node["parameters"]));

absorbers_.push_back(std::move(ab));
} else {
Expand Down
75 changes: 36 additions & 39 deletions src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@

// canoe
#include "impl.hpp"
#include "index_map.hpp"

MeshBlock::Impl::Impl(MeshBlock *pmb, ParameterInput *pin) : pmy_block_(pmb) {
du.NewAthenaArray(NHYDRO, pmb->ncells3, pmb->ncells2, pmb->ncells1);

// index map
IndexMap::InitFromAthenaInput(pin);

// thermodynamics
Thermodynamics::InitFromAthenaInput(pin);

Expand Down Expand Up @@ -64,96 +68,89 @@ MeshBlock::Impl::Impl(MeshBlock *pmb, ParameterInput *pin) : pmy_block_(pmb) {
#endif // HYDROSTATIC
}

MeshBlock::Impl::~Impl() { Thermodynamics::Destroy(); }
MeshBlock::Impl::~Impl() {
Thermodynamics::Destroy();
IndexMap::Destroy();
}

void MeshBlock::Impl::GatherFromPrimitive(Variable *var, int k, int j, int i) const {
auto& pmb = pmy_block_;
void MeshBlock::Impl::GatherFromPrimitive(Variable *var, int k, int j,
int i) const {
auto &pmb = pmy_block_;
auto mytype = var->GetType();
var->SetType(Variable::Type::MassFrac);

for (int n = 0; n < NHYDRO; ++n)
var->w[n] = pmb->phydro->w(n, k, j, i);
for (int n = 0; n < NHYDRO; ++n) var->w[n] = pmb->phydro->w(n, k, j, i);

for (int n = 0; n < NCLOUD; ++n)
var->c[n] = pcloud->w(n, k, j, i);
for (int n = 0; n < NCLOUD; ++n) var->c[n] = pcloud->w(n, k, j, i);

for (int n = 0; n < NTRACER; ++n)
var->x[n] = ptracer->w(n, k, j, i);
for (int n = 0; n < NTRACER; ++n) var->x[n] = ptracer->w(n, k, j, i);

for (int n = 0; n < NCHEMISTRY; ++n)
var->q[n] = pchem->w(n, k, j, i);
for (int n = 0; n < NCHEMISTRY; ++n) var->q[n] = pchem->w(n, k, j, i);

var->ConvertTo(mytype);
}

void MeshBlock::Impl::GatherFromConserved(Variable *var, int k, int j, int i) const {
auto& pmb = pmy_block_;
void MeshBlock::Impl::GatherFromConserved(Variable *var, int k, int j,
int i) const {
auto &pmb = pmy_block_;
auto mytype = var->GetType();
var->SetType(Variable::Type::MassConc);

for (int n = 0; n < NHYDRO; ++n)
var->w[n] = pmb->phydro->u(n, k, j, i);
for (int n = 0; n < NHYDRO; ++n) var->w[n] = pmb->phydro->u(n, k, j, i);

for (int n = 0; n < NCLOUD; ++n)
var->c[n] = pcloud->u(n, k, j, i);
for (int n = 0; n < NCLOUD; ++n) var->c[n] = pcloud->u(n, k, j, i);

for (int n = 0; n < NTRACER; ++n)
var->x[n] = ptracer->u(n, k, j, i);
for (int n = 0; n < NTRACER; ++n) var->x[n] = ptracer->u(n, k, j, i);

for (int n = 0; n < NCHEMISTRY; ++n)
var->q[n] = pchem->u(n, k, j, i);
for (int n = 0; n < NCHEMISTRY; ++n) var->q[n] = pchem->u(n, k, j, i);

var->ConvertTo(mytype);
}

void MeshBlock::Impl::DistributeToPrimitive(Variable const& var_in, int k, int j, int i) {
void MeshBlock::Impl::DistributeToPrimitive(Variable const &var_in, int k,
int j, int i) {
Variable *var;
auto& pmb = pmy_block_;
auto &pmb = pmy_block_;

if (var_in.GetType() != Variable::Type::MassFrac) {
var = new Variable(var_in);
var->ConvertToMassFraction();
} else {
var = const_cast<Variable*>(&var_in);
var = const_cast<Variable *>(&var_in);
}

for (int n = 0; n < NHYDRO; ++n) pmb->phydro->w(n, k, j, i) = var->w[n];

for (int n = 0; n < NCLOUD; ++n)
pcloud->w(n, k, j, i) = var->c[n];
for (int n = 0; n < NCLOUD; ++n) pcloud->w(n, k, j, i) = var->c[n];

for (int n = 0; n < NCHEMISTRY; ++n)
pchem->w(n, k, j, i) = var->q[n];
for (int n = 0; n < NCHEMISTRY; ++n) pchem->w(n, k, j, i) = var->q[n];

for (int n = 0; n < NTRACER; ++n)
ptracer->w(n, k, j, i) = var->x[n];
for (int n = 0; n < NTRACER; ++n) ptracer->w(n, k, j, i) = var->x[n];

if (var_in.GetType() != Variable::Type::MassFrac) {
delete var;
}
}

void MeshBlock::Impl::DistributeToConserved(Variable const& var_in, int k, int j, int i) {
void MeshBlock::Impl::DistributeToConserved(Variable const &var_in, int k,
int j, int i) {
Variable *var;
auto& pmb = pmy_block_;
auto &pmb = pmy_block_;

if (var_in.GetType() != Variable::Type::MassConc) {
var = new Variable(var_in);
var->ConvertToMassConcentration();
} else {
var = const_cast<Variable*>(&var_in);
var = const_cast<Variable *>(&var_in);
}

for (int n = 0; n < NHYDRO; ++n) pmb->phydro->u(n, k, j, i) = var->w[n];

for (int n = 0; n < NCLOUD; ++n)
pcloud->u(n, k, j, i) = var->c[n];
for (int n = 0; n < NCLOUD; ++n) pcloud->u(n, k, j, i) = var->c[n];

for (int n = 0; n < NCHEMISTRY; ++n)
pchem->u(n, k, j, i) = var->q[n];
for (int n = 0; n < NCHEMISTRY; ++n) pchem->u(n, k, j, i) = var->q[n];

for (int n = 0; n < NTRACER; ++n)
ptracer->u(n, k, j, i) = var->x[n];
for (int n = 0; n < NTRACER; ++n) ptracer->u(n, k, j, i) = var->x[n];

if (var_in.GetType() != Variable::Type::MassConc) {
delete var;
Expand Down
Loading

0 comments on commit 9ab0d7d

Please sign in to comment.