25#ifndef __BTPIT_STENCIL_HPP__
26#define __BTPIT_STENCIL_HPP__
28#include "stencil_weight.hpp"
30#include "bitpit_common.hpp"
31#include "bitpit_containers.hpp"
32#include "bitpit_operators.hpp"
36#include <unordered_map>
42template<
typename weight_t,
typename value_t>
45template<
typename weight_t,
typename value_t>
46OBinaryStream &
operator<<(OBinaryStream &buffer,
const DiscreteStencil<weight_t, value_t> &stencil);
48template<
typename weight_t,
typename value_t>
49IBinaryStream & operator>>(IBinaryStream &buffer, DiscreteStencil<weight_t, value_t> &stencil);
58template<typename weight_t, typename value_t = typename DiscreteStencilWeightValueInfo<weight_t>::type>
61template<
typename W,
typename V>
63template<
typename W,
typename V>
67 long NULL_ID = - std::numeric_limits<long>::max();
69 using weight_type = weight_t;
72 using value_type = value_t;
87 DiscreteStencil(std::size_t
size,
const long *pattern,
const weight_t *weights,
const weight_t &
zero = weight_t());
91 void initialize(std::size_t nItems,
const weight_t &
zero = weight_t());
92 void initialize(std::size_t
size,
const long *pattern,
const weight_t &
zero = weight_t());
93 void initialize(std::size_t
size,
const long *pattern,
const weight_t *weights,
const weight_t &
zero = weight_t());
96 void clear(
bool release =
false);
98 std::size_t
size()
const;
100 void resize(std::size_t nItems);
101 void reserve(std::size_t nItems);
104 const long &
getPattern(std::size_t pos)
const;
110 const weight_t &
getWeight(std::size_t pos)
const;
113 void setWeight(std::size_t pos,
const weight_t &weight);
114 void setWeight(std::size_t pos, weight_t &&weight);
115 void sumWeight(std::size_t pos,
const weight_t &weight,
double factor = 1.);
118 void setItem(std::size_t pos,
long id,
const weight_t &weight);
119 void setItem(std::size_t pos,
long id, weight_t &&weight);
120 void sumItem(
long id,
const weight_t &weight,
double factor = 1.);
121 void appendItem(
long id,
const weight_t &weight);
128 void sumConstant(
const weight_t &constant,
double factor = 1.);
133 void optimize(
double tolerance = 1.e-12);
134 void renumber(
const std::unordered_map<long, long> &map);
135 template<
typename Mapper>
136 void renumber(
const Mapper &mapper);
140 void display(std::ostream &out,
double factor = 1.)
const;
144 weight_t &
at(
long id);
145 const weight_t &
at(
long id)
const;
158 std::vector<long> m_pattern;
159 std::vector<weight_t> m_weights;
168 weight_t * findWeight(
long id);
169 const weight_t * findWeight(
long id)
const;
181template<typename weight_t, typename value_t = typename DiscreteStencilWeightValueInfo<weight_t>::type>
216template <
typename weight_t,
typename value_t>
219template <
typename weight_t,
typename value_t>
222template <
typename weight_t,
typename value_t>
225template <
typename weight_t,
typename value_t>
228template <
typename weight_t,
typename value_t>
249#include "stencil.tpp"
252#ifndef __BTPIT_STENCIL_SRC__
255extern template class DiscreteStencilWeightPool<double>;
256extern template class DiscreteStencilWeightPool<std::array<double, 3>>;
257extern template class DiscreteStencilWeightPool<std::vector<double>>;
259extern template class DiscreteStencil<double>;
260extern template class DiscreteStencil<std::array<double, 3>>;
261extern template class DiscreteStencil<std::vector<double>>;
263extern template class MPDiscreteStencil<double>;
264extern template class MPDiscreteStencil<std::array<double, 3>>;
265extern template class MPDiscreteStencil<std::vector<double>>;
Metafunction for generating a discretization stencil.
void sumWeight(std::size_t pos, const weight_t &weight, double factor=1.)
void sumConstant(const weight_t &constant, double factor=1.)
static const weight_manager_type m_weightManager
long & getPattern(std::size_t pos)
void addComplementToZero(long id)
void setWeight(std::size_t pos, const weight_t &weight)
void reserve(std::size_t nItems)
virtual void clearWeights(bool release)
void resize(std::size_t nItems)
void optimize(double tolerance=1.e-12)
void clear(bool release=false)
DiscreteStencil< weight_t, value_t > & operator-=(const DiscreteStencil< weight_t, value_t > &other)
weight_t & getWeight(std::size_t pos)
DiscreteStencil(const weight_t &zero=weight_t())
void setItem(std::size_t pos, long id, const weight_t &weight)
void zeroWeight(std::size_t pos)
DiscreteStencil< weight_t, value_t > & operator+=(const DiscreteStencil< weight_t, value_t > &other)
void renumber(const std::unordered_map< long, long > &map)
void display(std::ostream &out, double factor=1.) const
size_t getBinarySize() const
void appendItem(long id, const weight_t &weight)
DiscreteStencil< weight_t, value_t > & operator/=(double factor)
virtual void appendWeight(weight_t &&weight)
void setConstant(const weight_t &constant)
DiscreteStencil< weight_t, value_t > & operator*=(double factor)
void sum(const DiscreteStencil< weight_t, value_t > &other, double factor)
void setPattern(std::size_t pos, long id)
static const weight_manager_type & getWeightManager()
void sumItem(long id, const weight_t &weight, double factor=1.)
void initialize(std::size_t nItems, const weight_t &zero=weight_t())
weight_t & operator[](long id)
Metafunction for generating a discretization stencil with a memory pool (MP).
void appendWeight(const weight_t &weight) override
void clearWeights(bool release) override
void setWeightPool(weight_pool_type *pool)
MPDiscreteStencil(const weight_t &zero=weight_t())
T dotProduct(const std::array< T, d > &x, const std::array< T, d > &y)
std::vector< T > operator+(const std::vector< T > &, const std::vector< T > &)
std::ostream & operator<<(std::ostream &, const std::vector< T > &)