Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*! \file computational_cell.hpp
- \author Almog Yalinewich
- \brief Computational cell
- */
- #ifndef COMPUTATIONAL_CELL_HPP
- #define COMPUTATIONAL_CELL_HPP 1
- /*#include <boost/container/small_vector.hpp>
- typedef boost::container::small_vector<double,0> tvector;
- typedef boost::container::small_vector<bool,0> svector;*/
- #include <vector>
- #include <array>
- typedef std::vector<double> tvector;
- typedef std::vector<bool> svector;
- #include <string>
- #include "../../tessellation/geometry.hpp"
- #include "../../misc/int2str.hpp"
- #ifdef RICH_MPI
- #include "../../misc/serializable.hpp"
- #endif // RICH_MPI
- using std::array;
- using std::string;
- //! \brief Computational cell
- template<int N, class T> class ComputationalCell
- #ifdef RICH_MPI
- : public Serializable
- #endif // RICH_MPI
- {
- public:
- //! \brief Density
- double density;
- //! \brief Pressure
- double pressure;
- //! \brief Velocity
- Vector2D velocity;
- //! \brief Tracers (can transfer from one cell to another)
- #ifdef __clang__
- [[clang::no_destroy]]
- #endif // __clang__
- static array<string, N> tracer_names;
- array<double, N> tracers;
- //! \brief Stickers (stick to the same cell)
- T meta;
- /*!
- \brief Copy constructor
- \param other The cell to copy
- */
- ComputationalCell(ComputationalCell<N, T> const& other):
- density(other.density),
- pressure(other.pressure),
- velocity(other.velocity),
- tracers(other.tracers) {}
- /*!
- \brief Default constructor
- */
- ComputationalCell(void):
- density(0),
- pressure(0),
- velocity(Vector2D()),
- tracers() {}
- /*! \brief Self increment operator
- \param other Addition
- \return Reference to self
- */
- ComputationalCell& operator+=(ComputationalCell const& other)
- {
- this->density += other.density;
- this->pressure += other.pressure;
- this->velocity += other.velocity;
- assert(this->tracers.size() == other.tracers.size());
- // size_t N = this->tracers.size();
- for (size_t j = 0; j < N; ++j)
- this->tracers[j] += other.tracers[j];
- return *this;
- }
- /*! \brief Self reduction operator
- \param other Reduction
- \return Reference to self
- */
- ComputationalCell& operator-=(ComputationalCell const& other)
- {
- this->density -= other.density;
- this->pressure -= other.pressure;
- this->velocity -= other.velocity;
- transform(this->tracers.begin(),
- this->tracers.end(),
- other.tracers.begin(),
- this->tracers.begin(),
- [](double x, double y)
- {return x-y;});
- return *this;
- }
- /*! \brief Self multiplication operator
- \param s The scalar to multiply
- \return Reference to self
- */
- ComputationalCell& operator*=(double s)
- {
- this->density *= s;
- this->pressure *= s;
- this->velocity *= s;
- // size_t N = this->tracers.size();
- for (size_t j = 0; j < N; ++j)
- this->tracers[j] *= s;
- return *this;
- }
- /*! \brief Self decrement operator
- \param other difference
- \return Reference to self
- */
- ComputationalCell<N, T>& operator=(ComputationalCell<N, T> const& other)
- {
- density = other.density;
- pressure = other.pressure;
- velocity = other.velocity;
- tracers = other.tracers;
- return *this;
- }
- #ifdef RICH_MPI
- size_t getChunkSize(void) const;
- vector<double> serialize(void) const;
- void unserialize
- (const vector<double>& data);
- #endif // RICH_MPI
- ~ComputationalCell(void) {}
- };
- /*
- template<int N> array<string, N> uninitialised_tracer_names(void)
- {
- array<string, N> res;
- generate(res.begin(),
- res.end(),
- [n=0]() mutable{
- ++n;
- return "untitled"+int2str(n);
- });
- return res;
- }
- */
- //template<int N, class T> array<string, N> ComputationalCell<N, T>::tracer_names = uninitialised_tracer_names<N>();
- template<int N, class T> array<string, N> ComputationalCell<N, T>::tracer_names = array<string, N>();
- /*! \brief Term by term addition
- \param p1 Computational Cell
- \param p2 Computational Cell
- \return Computational Cell
- */
- /*
- ComputationalCell operator+
- (ComputationalCell const& p1,
- ComputationalCell const& p2);
- */
- /*! \brief Term by term subtraction
- \param p1 Computational Cell
- \param p2 Computational Cell
- \return Computational Cell
- */
- template<int N, class T> ComputationalCell<N, T> operator-
- (ComputationalCell<N, T> const& p1,
- ComputationalCell<N, T> const& p2)
- {
- ComputationalCell<N, T> res(p1);
- res -= p2;
- return res;
- }
- /*! \brief Scalar division
- \param p Computational Cell
- \param s Scalar
- \return Computational Cell
- */
- template<int N, class T> ComputationalCell<N, T> operator/
- (const ComputationalCell<N, T>& p,
- double s)
- {
- ComputationalCell<N, T> res(p);
- res.density /= s;
- res.pressure /= s;
- res.velocity.x /= s;
- res.velocity.y /= s;
- transform(res.tracers.begin(),
- res.tracers.end(),
- res.tracers.begin(),
- [&s](double x)
- {return x/s;});
- return res;
- }
- /*! \brief Scalar multiplication on the right
- \param p Computational Cell
- \param s Scalar
- \return Computational Cell
- */
- template<int N, class T> ComputationalCell<N, T> operator*
- (const ComputationalCell<N, T>& p, double s)
- {
- ComputationalCell<N, T> res(p);
- res.density *= s;
- res.pressure *= s;
- res.velocity *= s;
- transform(res.tracers.begin(),
- res.tracers.end(),
- res.tracers.begin(),
- [&s](double x)
- {return x*s;});
- return res;
- }
- /*! \brief Scalar multiplication on the left
- \param s Scalar
- \param p Computational Cell
- \return Computational Cell
- */
- //ComputationalCell operator*(double s, ComputationalCell const& p);
- template<int N, class T> void ComputationalCellAddMult
- (ComputationalCell<N, T> &res,
- const ComputationalCell<N, T>& other,
- double scalar)
- {
- res.density += other.density*scalar;
- res.pressure += other.pressure*scalar;
- res.velocity += other.velocity*scalar;
- assert(res.tracers.size() == other.tracers.size());
- size_t N0 = res.tracers.size();
- for (size_t j = 0; j < N0; ++j)
- res.tracers[j] += other.tracers[j]*scalar;
- }
- //void ReplaceComputationalCell(ComputationalCell &res, ComputationalCell const& other);
- //void ReplaceComputationalCellDiff(ComputationalCell &res, ComputationalCell const& first, ComputationalCell const& second);
- //! \brief Class for spatial interpolations
- template<int N, class T> class Slope
- #ifdef RICH_MPI
- : public Serializable
- #endif // RICH_MPI
- {
- public:
- //! \brief Slope in the x direction
- ComputationalCell<N, T> xderivative;
- //! \brief Slope in the y direction
- ComputationalCell<N, T> yderivative;
- /*!
- \brief Class constructor
- \param x The x derivative
- \param y The y derivative
- */
- Slope
- (const ComputationalCell<N, T>& x,
- const ComputationalCell<N, T>& y):
- xderivative(x), yderivative(y) {}
- //! \brief Default constructor
- Slope(void):
- xderivative(), yderivative() {}
- #ifdef RICH_MPI
- size_t getChunkSize(void) const;
- vector<double> serialize(void) const;
- void unserialize(const vector<double>& data);
- #endif//RICH_MPI
- };
- #endif // COMPUTATIONAL_CELL_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement