Skip to content

Commit

Permalink
wip updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Dec 19, 2023
1 parent ccfbabd commit 875638d
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 153 deletions.
36 changes: 20 additions & 16 deletions src/core/data/ions/ion_population/ion_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace core
: name_{initializer["name"].template to<std::string>()}
, mass_{initializer["mass"].template to<double>()}
, flux_{name_ + "_flux", HybridQuantity::Vector::V}
, rho_{name_ + "_rho", HybridQuantity::Scalar::rho}
, particleInitializerInfo_{initializer["particle_initializer"]}
{
}
Expand All @@ -52,13 +53,13 @@ namespace core

NO_DISCARD bool isUsable() const
{
return particles_ != nullptr && rho_ != nullptr && flux_.isUsable();
return particles_ != nullptr && rho_.isUsable() && flux_.isUsable();
}


NO_DISCARD bool isSettable() const
{
return particles_ == nullptr && rho_ == nullptr && flux_.isSettable();
return particles_ == nullptr && rho_.isSettable() && flux_.isSettable();
}


Expand Down Expand Up @@ -181,7 +182,7 @@ namespace core
{
if (isUsable())
{
return *rho_;
return rho_;
}
else
{
Expand Down Expand Up @@ -252,21 +253,24 @@ namespace core



void setBuffer(std::string const& bufferName, field_type* field)
{
if (bufferName == name_ + "_rho")
{
rho_ = field;
}
else
{
throw std::runtime_error("Error - invalid density buffer name");
}
}
// void setBuffer(std::string const& bufferName, field_type* field)
// {
// if (bufferName == name_ + "_rho")
// {
// rho_ = field;
// }
// else
// {
// throw std::runtime_error("Error - invalid density buffer name");
// }
// }



NO_DISCARD auto getCompileTimeResourcesUserList() { return std::forward_as_tuple(flux_); }
NO_DISCARD auto getCompileTimeResourcesUserList()
{
return std::forward_as_tuple(flux_, rho_);
}


//-------------------------------------------------------------------------
Expand All @@ -288,7 +292,7 @@ namespace core
std::string name_;
double mass_;
VecField flux_;
field_type* rho_{nullptr};
field_type rho_; //{nullptr};
ParticlesPack<ParticleArray>* particles_{nullptr};
initializer::PHAREDict const& particleInitializerInfo_;
};
Expand Down
64 changes: 22 additions & 42 deletions src/core/data/ions/ions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace core


explicit Ions(PHARE::initializer::PHAREDict const& dict)
: bulkVelocity_{"bulkVel", HybridQuantity::Vector::V}
: rho_{densityName(), HybridQuantity::Scalar::rho}
, massDensity_{massDensityName(), HybridQuantity::Scalar::rho}
, bulkVelocity_{"bulkVel", HybridQuantity::Vector::V}
, populations_{generate(
[&dict](auto ipop) { //
return IonPopulation{dict["pop" + std::to_string(ipop)]};
Expand All @@ -58,20 +60,16 @@ namespace core

NO_DISCARD field_type const& density() const
{
if (isUsable())
return *rho_;
else
if (!isUsable())
throw std::runtime_error("Error - cannot access density data");
return rho_;
}



NO_DISCARD field_type& density()
{
if (isUsable())
return *rho_;
else
if (!isUsable())
throw std::runtime_error("Error - cannot access density data");
return rho_;
}


Expand All @@ -80,13 +78,13 @@ namespace core

NO_DISCARD vecfield_type& velocity() { return bulkVelocity_; }

NO_DISCARD std::string densityName() const { return "rho"; }
NO_DISCARD std::string massDensityName() const { return "massDensity"; }
NO_DISCARD std::string static densityName() { return "rho"; }
NO_DISCARD std::string static massDensityName() { return "massDensity"; }


void computeDensity()
{
rho_->zero();
rho_.zero();

for (auto const& pop : populations_)
{
Expand All @@ -95,8 +93,8 @@ namespace core
// have to account for the field dimensionality.

auto& popDensity = pop.density();
std::transform(std::begin(*rho_), std::end(*rho_), std::begin(popDensity),
std::begin(*rho_), std::plus<Float>{});
std::transform(std::begin(rho_), std::end(rho_), std::begin(popDensity),
std::begin(rho_), std::plus<Float>{});
}
}
void computeMassDensity()
Expand All @@ -111,8 +109,8 @@ namespace core

auto& popDensity = pop.density();
std::transform(
std::begin(*massDensity_), std::end(*massDensity_), std::begin(popDensity),
std::begin(*massDensity_),
std::begin(massDensity_), std::end(massDensity_), std::begin(popDensity),
std::begin(massDensity_),
[&pop](auto const& n, auto const& pop_n) { return n + pop_n * pop.mass(); });
}
}
Expand Down Expand Up @@ -154,11 +152,11 @@ namespace core
}


std::transform(std::begin(vx), std::end(vx), std::begin(*density), std::begin(vx),
std::transform(std::begin(vx), std::end(vx), std::begin(density), std::begin(vx),
std::divides<Float>{});
std::transform(std::begin(vy), std::end(vy), std::begin(*density), std::begin(vy),
std::transform(std::begin(vy), std::end(vy), std::begin(density), std::begin(vy),
std::divides<Float>{});
std::transform(std::begin(vz), std::end(vz), std::begin(*density), std::begin(vz),
std::transform(std::begin(vz), std::end(vz), std::begin(density), std::begin(vz),
std::divides<Float>{});
}

Expand All @@ -175,7 +173,7 @@ namespace core
// because it is for internal use only so no object will ever need to access it.
NO_DISCARD bool isUsable() const
{
bool usable = rho_ != nullptr && bulkVelocity_.isUsable();
bool usable = rho_.isUsable() && bulkVelocity_.isUsable();
for (auto const& pop : populations_)
{
usable = usable && pop.isUsable();
Expand All @@ -187,7 +185,7 @@ namespace core

NO_DISCARD bool isSettable() const
{
bool settable = rho_ == nullptr && bulkVelocity_.isSettable();
bool settable = rho_.isSettable() && bulkVelocity_.isSettable();
for (auto const& pop : populations_)
{
settable = settable && pop.isSettable();
Expand Down Expand Up @@ -218,32 +216,14 @@ namespace core



void setBuffer(std::string const& bufferName, field_type* field)
{
if (bufferName == densityName())
{
rho_ = field;
}
else if (bufferName == massDensityName())
{
massDensity_ = field;
}
else
{
throw std::runtime_error("Error - invalid density buffer name : " + bufferName);
}
}



NO_DISCARD std::vector<IonPopulation>& getRunTimeResourcesUserList()
{
return populations_;
}

NO_DISCARD auto getCompileTimeResourcesUserList()
{
return std::forward_as_tuple(bulkVelocity_);
return std::forward_as_tuple(bulkVelocity_, rho_, massDensity_);
}


Expand Down Expand Up @@ -276,8 +256,8 @@ namespace core



field_type* rho_{nullptr};
field_type* massDensity_{nullptr};
field_type rho_; //{nullptr};
field_type massDensity_; //{nullptr};
vecfield_type bulkVelocity_;
std::vector<IonPopulation> populations_;

Expand Down
Loading

0 comments on commit 875638d

Please sign in to comment.