Loading...
Searching...
No Matches
stencil_weight.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2024 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BTPIT_STENCIL_WEIGHT_HPP__
26#define __BTPIT_STENCIL_WEIGHT_HPP__
27
28#include "bitpit_common.hpp"
29
30#include <array>
31#include <vector>
32
33namespace bitpit {
34
35// Stencil weight pool
36template<typename weight_t>
38{
39
40public:
41 DiscreteStencilWeightPool(std::size_t capacity = 128);
42
43 std::size_t size() const;
44 std::size_t capacity() const;
45 void clear(bool release);
46
47 weight_t retrieve();
48 void store(weight_t &&weight);
49 void store(std::vector<weight_t> *weights);
50
51private:
52 std::size_t m_capacity;
53 std::vector<weight_t> m_storage;
54
55};
56
62template <typename weight_t, typename = void>
64{
65public:
66 using type = weight_t;
67};
68
69template <typename weight_t>
70class DiscreteStencilWeightValueInfo<weight_t, bitpit_void_t<typename weight_t::value_type>>
71{
72public:
73 using type = typename weight_t::value_type;
74};
75
81template <typename weight_t, typename value_t>
83{
84public:
85 using weight_type = weight_t;
86 using value_type = value_t;
87
88 template<typename W>
89 bool isNegligible(const W &weight, const weight_t &zero, double tolerance = 1e-12) const;
90 template<typename W = weight_t, typename V = value_t, std::size_t D = std::tuple_size<W>::value, typename std::enable_if<std::is_same<std::array<V, D>, W>::value>::type * = nullptr>
91 bool isNegligible(const std::array<V, D> &weight, const weight_t &zero, double tolerance = 1e-12) const;
92 template<typename W = weight_t, typename V = value_t, typename std::enable_if<std::is_same<std::vector<V>, W>::value>::type * = nullptr>
93 bool isNegligible(const std::vector<V> &weight, const weight_t &zero, double tolerance = 1e-12) const;
94
95 template<typename W>
96 void sum(const W &weight, double factor, W *target) const;
97 template<typename W = weight_t, typename V = value_t, std::size_t D = std::tuple_size<W>::value, typename std::enable_if<std::is_same<std::array<V, D>, W>::value>::type * = nullptr>
98 void sum(const std::array<V, D> &weight, double factor, std::array<V, D> *target) const;
99 template<typename W = weight_t, typename V = value_t, typename std::enable_if<std::is_same<std::vector<V>, W>::value>::type * = nullptr>
100 void sum(const std::vector<V> &weight, double factor, std::vector<V> *target) const;
101
102 template<typename W>
103 void copy(const W &weight, W *target) const;
104 template<typename W = weight_t, typename V = value_t, std::size_t D = std::tuple_size<W>::value, typename std::enable_if<std::is_same<std::array<V, D>, W>::value>::type * = nullptr>
105 void copy(const std::array<V, D> &weight, std::array<V, D> *target) const;
106 template<typename W = weight_t, typename V = value_t, typename std::enable_if<std::is_same<std::vector<V>, W>::value>::type * = nullptr>
107 void copy(const std::vector<V> &weight, std::vector<V> *target) const;
108
109 template<typename W>
110 void move(W &&weight, W *target) const;
111
112 template<typename W>
113 value_t & at(const W &weight, std::size_t index);
114 template<typename W>
115 const value_t & at(const W &weight, std::size_t index) const;
116 template<typename W = weight_t, typename V, std::size_t D = std::tuple_size<W>::value, typename std::enable_if<std::is_same<std::array<V, D>, W>::value>::type * = nullptr>
117 value_t & at(const std::array<V, D> &weight, std::size_t index);
118 template<typename W = weight_t, typename V, std::size_t D = std::tuple_size<W>::value, typename std::enable_if<std::is_same<std::array<V, D>, W>::value>::type * = nullptr>
119 const value_t & at(const std::array<V, D> &weight, std::size_t index) const;
120 template<typename W = weight_t, typename V, typename std::enable_if<std::is_same<std::vector<V>, W>::value>::type * = nullptr>
121 value_t & at(const std::vector<V> &weight, std::size_t index);
122 template<typename W = weight_t, typename V, typename std::enable_if<std::is_same<std::vector<V>, W>::value>::type * = nullptr>
123 const value_t & at(const std::vector<V> &weight, int index) const;
124
125};
126
127// Declaration of the typdefs
131
132}
133
134// Template implementation
135#include "stencil_weight.tpp"
136
137// Explicit instantization
138#ifndef __BITPIT_STENCIL_WEIGHT_SRC__
139namespace bitpit {
140
141extern template class DiscreteStencilWeightManager<double, double>;
142extern template class DiscreteStencilWeightManager<std::array<double, 3>, double>;
143extern template class DiscreteStencilWeightManager<std::vector<double>, double>;
144
145}
146#endif
147
148#endif
bool isNegligible(const W &weight, const weight_t &zero, double tolerance=1e-12) const
void copy(const W &weight, W *target) const
value_t & at(const W &weight, std::size_t index)
void move(W &&weight, W *target) const
void sum(const W &weight, double factor, W *target) const
DiscreteStencilWeightPool(std::size_t capacity=128)
--- layout: doxygen_footer ---