Skip to content

Commit

Permalink
feat: Make interface to continua use velocity and pressure units
Browse files Browse the repository at this point in the history
  • Loading branch information
2b-t committed Jun 16, 2024
1 parent 252c9ac commit a976eb6
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 65 deletions.
47 changes: 38 additions & 9 deletions include/lbt/continuums/continuum_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <filesystem>
#include <type_traits>

#include "lbt/units/units.hpp"


namespace lbt {

Expand All @@ -21,7 +23,7 @@ namespace lbt {
* \tparam T Floating data type used for simulation
* \tparam Dummy argument used for SFINAE
*/
template <typename T, typename std::enable_if_t<std::is_floating_point_v<T>>* = nullptr>
template <typename T>
class ContinuumBase {
public:
/**\fn setP
Expand All @@ -32,7 +34,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \param[in] value The value the pressure should be set to
*/
virtual void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept = 0;
virtual void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Pressure const value) noexcept = 0;

/**\fn setU
* \brief Set the x-velocity to a given value \param value at the coordinates \param x, \param y and \param z
Expand All @@ -42,7 +44,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \param[in] value The value the pressure should be set to
*/
virtual void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept = 0;
virtual void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept = 0;

/**\fn setV
* \brief Set the y-velocity to a given value \param value at the coordinates \param x, \param y and \param z
Expand All @@ -52,7 +54,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \param[in] value The value the pressure should be set to
*/
virtual void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept = 0;
virtual void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept = 0;

/**\fn setW
* \brief Set the z-velocity to a given value \param value at the coordinates \param x, \param y and \param z
Expand All @@ -62,7 +64,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \param[in] value The value the pressure should be set to
*/
virtual void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept = 0;
virtual void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept = 0;

/**\fn getP
* \brief Get the pressure at the coordinates \param x, \param y and \param z
Expand All @@ -72,7 +74,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \return The pressure value at the coordinates \param x, \param y and \param z
*/
virtual T getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;
virtual lbt::unit::Pressure getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;

/**\fn getU
* \brief Get the x-velocity at the coordinates \param x, \param y and \param z
Expand All @@ -82,7 +84,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \return The x-velocity value at the coordinates \param x, \param y and \param z
*/
virtual T getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;
virtual lbt::unit::Velocity getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;

/**\fn getV
* \brief Get the y-velocity at the coordinates \param x, \param y and \param z
Expand All @@ -92,7 +94,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \return The y-velocity value at the coordinates \param x, \param y and \param z
*/
virtual T getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;
virtual lbt::unit::Velocity getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;

/**\fn getW
* \brief Get the z-velocity at the coordinates \param x, \param y and \param z
Expand All @@ -102,7 +104,7 @@ namespace lbt {
* \param[in] z The z-coordinate of cell
* \return The z-velocity value at the coordinates \param x, \param y and \param z
*/
virtual T getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;
virtual lbt::unit::Velocity getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept = 0;

/**\fn save
* \brief Function for exporting the domain to a file
Expand All @@ -111,6 +113,16 @@ namespace lbt {
*/
virtual void save(double const timestamp) const noexcept = 0;

/**\fn initializeUniform
* \brief Initialize the continuum with uniform values
*
* \param[in] p The pressure to be set for the entire flow field
* \param[in] u The x-velocity to be set to the entire flow field
* \param[in] v The y-velocity to be set to the entire flow field
* \param[in] w The z-velocity to be set to the entire flow field
*/
void initializeUniform(lbt::unit::Pressure const p, lbt::unit::Velocity const u, lbt::unit::Velocity const v, lbt::unit::Velocity const w = 0);

protected:
/**\fn ContinuumBase
* \brief Class constructor
Expand All @@ -122,6 +134,7 @@ namespace lbt {
*/
ContinuumBase(std::int32_t const NX, std::int32_t const NY, std::int32_t const NZ, std::filesystem::path const& output_path) noexcept
: NX{NX}, NY{NY}, NZ{NZ}, output_path{output_path} {
static_assert(std::is_floating_point_v<T>);
return;
}

Expand All @@ -137,6 +150,22 @@ namespace lbt {
std::filesystem::path output_path;
};

template <typename T>
void ContinuumBase<T>::initializeUniform(lbt::unit::Pressure const p, lbt::unit::Velocity const u,
lbt::unit::Velocity const v, lbt::unit::Velocity const w) {
for(std::int32_t z = 0; z < NZ; ++z) {
for(std::int32_t y = 0; y < NY; ++y) {
for(std::int32_t x = 0; x < NX; ++x) {
setP(x, y, z, p);
setU(x, y, z, u);
setV(x, y, z, v);
setW(x, y, z, w);
}
}
}
return;
}

}

#endif // LBT__CONTINUUMS__CONTINUUM_BASE
51 changes: 26 additions & 25 deletions include/lbt/continuums/simple_continuum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lbt/common/output_utilities.hpp"
#include "lbt/common/type_definitions.hpp"
#include "lbt/continuums/continuum_base.hpp"
#include "lbt/units/units.hpp"


namespace lbt {
Expand Down Expand Up @@ -54,14 +55,14 @@ namespace lbt {
SimpleContinuum(SimpleContinuum&&) = default;
SimpleContinuum& operator = (SimpleContinuum&&) = default;

void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
T getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Pressure const value) noexcept override;
void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
lbt::unit::Pressure getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
void save(double const timestamp) const noexcept override;

/**\fn operator()
Expand Down Expand Up @@ -152,47 +153,47 @@ namespace lbt {
};

template <typename T>
void SimpleContinuum<T>::setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
this->operator()(x,y,z,0) = value;
void SimpleContinuum<T>::setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Pressure const value) noexcept {
this->operator()(x,y,z,0) = value.get();
return;
}

template <typename T>
void SimpleContinuum<T>::setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
this->operator()(x,y,z,1) = value;
void SimpleContinuum<T>::setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
this->operator()(x,y,z,1) = value.get();
return;
}

template <typename T>
void SimpleContinuum<T>::setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
this->operator()(x,y,z,2) = value;
void SimpleContinuum<T>::setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
this->operator()(x,y,z,2) = value.get();
return;
}

template <typename T>
void SimpleContinuum<T>::setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
this->operator()(x,y,z,3) = value;
void SimpleContinuum<T>::setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
this->operator()(x,y,z,3) = value.get();
return;
}

template <typename T>
T SimpleContinuum<T>::getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return this->operator()(x,y,z,0);
lbt::unit::Pressure SimpleContinuum<T>::getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Pressure{this->operator()(x,y,z,0)};
}

template <typename T>
T SimpleContinuum<T>::getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return this->operator()(x,y,z,1);
lbt::unit::Velocity SimpleContinuum<T>::getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{this->operator()(x,y,z,1)};
}

template <typename T>
T SimpleContinuum<T>::getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return this->operator()(x,y,z,2);
lbt::unit::Velocity SimpleContinuum<T>::getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{this->operator()(x,y,z,2)};
}

template <typename T>
T SimpleContinuum<T>::getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return this->operator()(x,y,z,3);
lbt::unit::Velocity SimpleContinuum<T>::getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{this->operator()(x,y,z,3)};
}

template <typename T>
Expand Down Expand Up @@ -260,7 +261,7 @@ namespace lbt {

template <typename T>
inline std::int64_t SimpleContinuum<T>::spatialToLinear_(std::int32_t const x, std::int32_t const y, std::int32_t const z,
std::int32_t const m) const noexcept {
std::int32_t const m) const noexcept {
return ((static_cast<std::int64_t>(z)*ContinuumBase<T>::NY + y)*ContinuumBase<T>::NX + x)*number_of_values + m;
}

Expand Down
49 changes: 25 additions & 24 deletions include/lbt/continuums/vtk_continuum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "lbt/common/output_utilities.hpp"
#include "lbt/common/vtk_utilities.hpp"
#include "lbt/continuums/continuum_base.hpp"
#include "lbt/units/units.hpp"


namespace lbt {
Expand Down Expand Up @@ -112,14 +113,14 @@
return *this;
}

void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept override;
T getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
T getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
void setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Pressure const value) noexcept override;
void setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
void setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
void setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept override;
lbt::unit::Pressure getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
lbt::unit::Velocity getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept override;
void save(double const timestamp) const noexcept override;

/**\fn saveToVtk
Expand Down Expand Up @@ -180,47 +181,47 @@
};

template <typename T>
void VtkContinuum<T>::setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
setImageDataComponent_(p, x, y, z, value);
void VtkContinuum<T>::setP(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Pressure const value) noexcept {
setImageDataComponent_(p, x, y, z, value.get());
return;
}

template <typename T>
void VtkContinuum<T>::setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
setImageDataComponent_(u, x, y, z, value);
void VtkContinuum<T>::setU(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
setImageDataComponent_(u, x, y, z, value.get());
return;
}

template <typename T>
void VtkContinuum<T>::setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
setImageDataComponent_(v, x, y, z, value);
void VtkContinuum<T>::setV(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
setImageDataComponent_(v, x, y, z, value.get());
return;
}

template <typename T>
void VtkContinuum<T>::setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, T const value) noexcept {
setImageDataComponent_(w, x, y, z, value);
void VtkContinuum<T>::setW(std::int32_t const x, std::int32_t const y, std::int32_t const z, lbt::unit::Velocity const value) noexcept {
setImageDataComponent_(w, x, y, z, value.get());
return;
}

template <typename T>
T VtkContinuum<T>::getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return getImageDataComponent_(p, x, y, z);
lbt::unit::Pressure VtkContinuum<T>::getP(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Pressure{getImageDataComponent_(p, x, y, z)};
}

template <typename T>
T VtkContinuum<T>::getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return getImageDataComponent_(u, x, y, z);
lbt::unit::Velocity VtkContinuum<T>::getU(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{getImageDataComponent_(u, x, y, z)};
}

template <typename T>
T VtkContinuum<T>::getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return getImageDataComponent_(v, x, y, z);
lbt::unit::Velocity VtkContinuum<T>::getV(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{getImageDataComponent_(v, x, y, z)};
}

template <typename T>
T VtkContinuum<T>::getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return getImageDataComponent_(w, x, y, z);
lbt::unit::Velocity VtkContinuum<T>::getW(std::int32_t const x, std::int32_t const y, std::int32_t const z) const noexcept {
return lbt::unit::Velocity{getImageDataComponent_(w, x, y, z)};
}

template <typename T>
Expand Down
Loading

0 comments on commit a976eb6

Please sign in to comment.