Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try float32 #943

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion res/cmake/def.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if(devMode) # -DdevMode=ON
# Having quotes on strings here has lead to quotes being added to the compile string, so avoid.

set (_Werr ${PHARE_WERROR_FLAGS} -Wall -Wextra -pedantic -Werror -Wno-unused-variable -Wno-unused-parameter)
set (_Werr ${_Werr} -Wdouble-promotion -Wuninitialized )
set (_Werr ${_Werr} -Wuninitialized ) # -Wdouble-promotion
PhilipDeegan marked this conversation as resolved.
Show resolved Hide resolved

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (_Werr ${_Werr} -Wno-gnu-zero-variadic-macro-arguments)
Expand Down
4 changes: 2 additions & 2 deletions res/cmake/dep/highfive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set (PHARE_HAS_HIGHFIVE "0")
if(HighFive)

set (HIGHFIVE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/highfive)
set (HIGHFIVE_VERSION master)
set (HIGHFIVE_VERSION main)
PhilipDeegan marked this conversation as resolved.
Show resolved Hide resolved

phare_github_get_or_update(HighFive ${HIGHFIVE_SRC} BlueBrain/HighFive ${HIGHFIVE_VERSION})
phare_github_get_or_update(HighFive ${HIGHFIVE_SRC} highfive-devs/highfive ${HIGHFIVE_VERSION})

include_directories(
${HIGHFIVE_SRC}/include
Expand Down
6 changes: 3 additions & 3 deletions src/amr/data/field/coarsening/coarsen_weighter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ namespace amr
computeWeights_(nbrPoints);
}

std::vector<double> const& weights() const { return weights_; }
std::vector<core::floater_t<4>> const& weights() const { return weights_; }

private:
std::vector<double> weights_;
std::vector<core::floater_t<4>> weights_;

double findX_(std::size_t nbrPoints) const;
core::floater_t<4> findX_(std::size_t nbrPoints) const;
void computeWeights_(std::size_t nbrPoints);
};

Expand Down
9 changes: 5 additions & 4 deletions src/amr/data/field/coarsening/default_field_coarsener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "amr/data/field/coarsening/field_coarsen_index_weight.hpp"
#include "amr/resources_manager/amr_utils.hpp"
#include "core/utilities/types.hpp"

#include <SAMRAI/hier/Box.h>

Expand Down Expand Up @@ -67,7 +68,7 @@ namespace amr
coarseIndex = AMRToLocal(coarseIndex, destinationBox_);


double coarseValue = 0.;
core::floater_t<4> coarseValue = 0.;



Expand Down Expand Up @@ -99,7 +100,7 @@ namespace amr

for (std::size_t iShiftX = 0; iShiftX < xWeights.size(); ++iShiftX)
{
double Yinterp = 0.;
core::floater_t<4> Yinterp = 0.;
for (std::size_t iShiftY = 0; iShiftY < yWeights.size(); ++iShiftY)
{
Yinterp += fineField(xStartIndex + iShiftX, yStartIndex + iShiftY)
Expand All @@ -125,11 +126,11 @@ namespace amr

for (std::size_t iShiftX = 0; iShiftX < xWeights.size(); ++iShiftX)
{
double Yinterp = 0.;
core::floater_t<4> Yinterp = 0.;

for (std::size_t iShiftY = 0; iShiftY < yWeights.size(); ++iShiftY)
{
double Zinterp = 0.;
core::floater_t<4> Zinterp = 0.;
for (std::size_t iShiftZ = 0; iShiftZ < zWeights.size(); ++iShiftZ)
{
Zinterp += fineField(xStartIndex + iShiftX, yStartIndex + iShiftY,
Expand Down
30 changes: 15 additions & 15 deletions src/amr/data/field/coarsening/field_coarsen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace PHARE::amr
{
NO_DISCARD double CoarsenWeighter::findX_(std::size_t nbrPoints) const
NO_DISCARD core::floater_t<4> CoarsenWeighter::findX_(std::size_t nbrPoints) const
{
double x = 0.;
core::floater_t<4> x = 0.;

if (nbrPoints % 2 != 0)
{
x = 1.;
x = 1.f;
for (std::size_t i = 1; i <= (nbrPoints - 1) / 2; ++i)
{
x += 2 * 1. / (i + 1);
x += 2 * 1.f / (i + 1);
}
}
else
{
for (std::size_t i = 1; i <= nbrPoints / 2; ++i)
{
x += 2 * 1. / i;
x += 2 * 1.f / i;
}
}

Expand All @@ -32,7 +32,7 @@ void CoarsenWeighter::computeWeights_(std::size_t nbrPoints)
{
weights_.resize(nbrPoints);

auto x = findX_(nbrPoints);
auto const x = findX_(nbrPoints);


if (nbrPoints % 2 != 0)
Expand All @@ -42,13 +42,13 @@ void CoarsenWeighter::computeWeights_(std::size_t nbrPoints)
auto const halfNumberOfPointsLeft
= nbrPoints / 2; // half of the points needed besides the one on the middle

weights_[halfIndex] = 1. / x;
weights_[halfIndex] = 1.f / x;

for (std::size_t i = 1; i <= halfNumberOfPointsLeft; ++i)
{
double factor = static_cast<double>(i + 1);
weights_[halfIndex - i] = 1. / (factor * x);
weights_[halfIndex + i] = 1. / (factor * x);
core::floater_t<4> factor = static_cast<core::floater_t<4>>(i + 1);
weights_[halfIndex - i] = 1.f / (factor * x);
weights_[halfIndex + i] = 1.f / (factor * x);
}
}

Expand All @@ -60,17 +60,17 @@ void CoarsenWeighter::computeWeights_(std::size_t nbrPoints)
auto const halfIndexRight = nbrPoints / 2;
auto const halfIndexLeft = halfIndexRight - 1;

weights_[halfIndexRight] = 1. / x;
weights_[halfIndexLeft] = 1. / x;
weights_[halfIndexRight] = 1.f / x;
weights_[halfIndexLeft] = 1.f / x;

auto const halfNumberOfPointsLeft = (nbrPoints / 2) - 1;

for (std::size_t i = 1; i <= halfNumberOfPointsLeft; ++i)
{
double factor = static_cast<double>(i + 1);
core::floater_t<4> factor = static_cast<core::floater_t<4>>(i + 1);

weights_[halfIndexRight + i] = 1. / (factor * x);
weights_[halfIndexLeft - i] = 1. / (factor * x);
weights_[halfIndexRight + i] = 1.f / (factor * x);
weights_[halfIndexLeft - i] = 1.f / (factor * x);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace amr
}


NO_DISCARD std::vector<double> const& weights(core::Direction dir) const
NO_DISCARD std::vector<core::floater_t<4>> const& weights(core::Direction dir) const
{
return weighters_[static_cast<std::size_t>(dir)].weights();
}
Expand Down
9 changes: 5 additions & 4 deletions src/amr/data/field/coarsening/magnetic_field_coarsener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class MagneticFieldCoarsener
else if (centering_[dirX] == core::QtyCentering::dual) // by and bz
{
coarseField(coarseIndex[dirX])
= 0.5 * (fineField(fineStartIndex[dirX] + 1) + fineField(fineStartIndex[dirX]));
= 0.5f
* (fineField(fineStartIndex[dirX] + 1) + fineField(fineStartIndex[dirX]));
}
}

Expand All @@ -97,23 +98,23 @@ class MagneticFieldCoarsener
and centering_[dirY] == core::QtyCentering::dual)
{
coarseField(coarseIndex[dirX], coarseIndex[dirY])
= 0.5
= 0.5f
* (fineField(fineStartIndex[dirX], fineStartIndex[dirY])
+ fineField(fineStartIndex[dirX], fineStartIndex[dirY] + 1));
}
else if (centering_[dirX] == core::QtyCentering::dual
and centering_[dirY] == core::QtyCentering::primal)
{
coarseField(coarseIndex[dirX], coarseIndex[dirY])
= 0.5
= 0.5f
* (fineField(fineStartIndex[dirX], fineStartIndex[dirY])
+ fineField(fineStartIndex[dirX] + 1, fineStartIndex[dirY]));
}
else if (centering_[dirX] == core::QtyCentering::dual
and centering_[dirY] == core::QtyCentering::dual)
{
coarseField(coarseIndex[dirX], coarseIndex[dirY])
= 0.25
= 0.25f
* (fineField(fineStartIndex[dirX], fineStartIndex[dirY])
+ fineField(fineStartIndex[dirX] + 1, fineStartIndex[dirY])
+ fineField(fineStartIndex[dirX], fineStartIndex[dirY] + 1)
Expand Down
92 changes: 53 additions & 39 deletions src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define PHARE_SRC_AMR_FIELD_FIELD_DATA_HPP



#include "core/def.hpp"
#include "core/def/phare_mpi.hpp"


#include <SAMRAI/hier/PatchData.h>
#include <SAMRAI/tbox/MemoryUtilities.h>
#include <utility>
Expand Down Expand Up @@ -40,6 +41,7 @@ namespace amr
typename PhysicalQuantity = decltype(std::declval<Grid_t>().physicalQuantity())>
class FieldData : public SAMRAI::hier::PatchData
{
static_assert(std::is_same_v<typename Grid_t::value_type, core::floater_t<4>>);
using Super = SAMRAI::hier::PatchData;

public:
Expand All @@ -62,18 +64,19 @@ namespace amr
{
} //

[[deprecated]] FieldData(SAMRAI::hier::Box const& domain,
SAMRAI::hier::IntVector const& ghost, std::string name,
std::array<double, dimension> const& dl,
std::array<std::uint32_t, dimension> const& nbrCells,
core::Point<double, dimension> const& origin, PhysicalQuantity qty)
// [[deprecated]] FieldData(SAMRAI::hier::Box const& domain,
// SAMRAI::hier::IntVector const& ghost, std::string name,
// std::array<double, dimension> const& dl,
// std::array<std::uint32_t, dimension> const& nbrCells,
// core::Point<double, dimension> const& origin, PhysicalQuantity
// qty)

: SAMRAI::hier::PatchData(domain, ghost)
, gridLayout{dl, nbrCells, origin}
, field(name, qty, gridLayout.allocSize(qty))
, quantity_{qty}
{
}
// : SAMRAI::hier::PatchData(domain, ghost)
// , gridLayout{dl, nbrCells, origin}
// , field(name, qty, gridLayout.allocSize(qty))
// , quantity_{qty}
// {
// }

FieldData() = delete;
FieldData(FieldData const&) = delete;
Expand All @@ -87,8 +90,16 @@ namespace amr
Super::getFromRestart(restart_db);

assert(field.vector().size() > 0);
restart_db->getDoubleArray("field_" + field.name(), field.vector().data(),
field.vector().size()); // do not reallocate!
if constexpr (std::is_same_v<core::floater_t<4>, double>)
{
restart_db->getDoubleArray("field_" + field.name(), field.vector().data(),
field.vector().size()); // do not reallocate!
}
else
{
restart_db->getFloatArray("field_" + field.name(), field.vector().data(),
field.vector().size()); // do not reallocate!
}
}

void putToRestart(std::shared_ptr<SAMRAI::tbox::Database> const& restart_db) const override
Expand Down Expand Up @@ -471,12 +482,12 @@ namespace amr
void copyImpl(SAMRAI::hier::Box const& localSourceBox, Grid_t const& source,
SAMRAI::hier::Box const& localDestinationBox, Grid_t& destination) const
{
std::uint32_t xSourceStart = static_cast<std::uint32_t>(localSourceBox.lower(0));
std::uint32_t xDestinationStart
std::uint32_t const xSourceStart = static_cast<std::uint32_t>(localSourceBox.lower(0));
std::uint32_t const xDestinationStart
= static_cast<std::uint32_t>(localDestinationBox.lower(0));

std::uint32_t xSourceEnd = static_cast<std::uint32_t>(localSourceBox.upper(0));
std::uint32_t xDestinationEnd
std::uint32_t const xSourceEnd = static_cast<std::uint32_t>(localSourceBox.upper(0));
std::uint32_t const xDestinationEnd
= static_cast<std::uint32_t>(localDestinationBox.upper(0));

for (std::uint32_t xSource = xSourceStart, xDestination = xDestinationStart;
Expand All @@ -489,11 +500,12 @@ namespace amr



void packImpl(std::vector<double>& buffer, Grid_t const& source,
template<typename T>
void packImpl(std::vector<T>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& sourceBox) const
{
int xStart = overlap.lower(0) - sourceBox.lower(0);
int xEnd = overlap.upper(0) - sourceBox.lower(0);
int const xStart = overlap.lower(0) - sourceBox.lower(0);
int const xEnd = overlap.upper(0) - sourceBox.lower(0);

for (int xi = xStart; xi <= xEnd; ++xi)
{
Expand All @@ -502,13 +514,13 @@ namespace amr
}



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
template<typename T>
void unpackImpl(std::size_t& seek, std::vector<T> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
int xStart = overlap.lower(0) - destination.lower(0);
int xEnd = overlap.upper(0) - destination.lower(0);
int const xStart = overlap.lower(0) - destination.lower(0);
int const xEnd = overlap.upper(0) - destination.lower(0);

for (int xi = xStart; xi <= xEnd; ++xi)
{
Expand Down Expand Up @@ -559,16 +571,16 @@ namespace amr




void packImpl(std::vector<double>& buffer, Grid_t const& source,
template<typename T>
void packImpl(std::vector<T>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& destination) const

{
int xStart = overlap.lower(0) - destination.lower(0);
int xEnd = overlap.upper(0) - destination.lower(0);
int const xStart = overlap.lower(0) - destination.lower(0);
int const xEnd = overlap.upper(0) - destination.lower(0);

int yStart = overlap.lower(1) - destination.lower(1);
int yEnd = overlap.upper(1) - destination.lower(1);
int const yStart = overlap.lower(1) - destination.lower(1);
int const yEnd = overlap.upper(1) - destination.lower(1);

for (int xi = xStart; xi <= xEnd; ++xi)
{
Expand All @@ -582,15 +594,16 @@ namespace amr



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
template<typename T>
void unpackImpl(std::size_t& seek, std::vector<T> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
int xStart = overlap.lower(0) - destination.lower(0);
int xEnd = overlap.upper(0) - destination.lower(0);
int const xStart = overlap.lower(0) - destination.lower(0);
int const xEnd = overlap.upper(0) - destination.lower(0);

int yStart = overlap.lower(1) - destination.lower(1);
int yEnd = overlap.upper(1) - destination.lower(1);
int const yStart = overlap.lower(1) - destination.lower(1);
int const yEnd = overlap.upper(1) - destination.lower(1);

for (int xi = xStart; xi <= xEnd; ++xi)
{
Expand Down Expand Up @@ -658,8 +671,8 @@ namespace amr




void packImpl(std::vector<double>& buffer, Grid_t const& source,
template<typename T>
void packImpl(std::vector<T>& buffer, Grid_t const& source,
SAMRAI::hier::Box const& overlap, SAMRAI::hier::Box const& destination) const
{
int xStart = overlap.lower(0) - destination.lower(0);
Expand All @@ -686,7 +699,8 @@ namespace amr



void unpackImpl(std::size_t& seek, std::vector<double> const& buffer, Grid_t& source,
template<typename T>
void unpackImpl(std::size_t& seek, std::vector<T> const& buffer, Grid_t& source,
SAMRAI::hier::Box const& overlap,
SAMRAI::hier::Box const& destination) const
{
Expand Down
Loading
Loading