Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
mdarray.hpp
Go to the documentation of this file.
1 // Copyright (c) 2018 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #include "fub/core/mdspan.hpp"
22 
23 namespace fub {
24 
25 template <typename ValueType, typename Extents, typename LayoutPolicy,
26  typename ContainerPolicy>
28 public:
29  using value_type = ValueType;
31  using layout_policy = LayoutPolicy;
32  using mapping_type = typename layout_policy::template mapping<Extents>;
33  using container_policy = ContainerPolicy;
35  typename container_policy::template container<value_type>;
36 
37  basic_mdarray(const value_type& default_value, const extents_type& extents,
38  const allocator_type& allocator = allocator_type());
39 
41  const allocator_type& allocator = allocator_type());
42 
43  view_type view() noexcept;
44  const_view_type view() const noexcept;
45 
46  static constexpr std::ptrdiff_t rank() noexcept;
47 
48  reference operator()(std::array<std::ptrdiff_t, rank()> i);
49  const_reference operator()(std::array<std::ptrdiff_t, rank()> i) const;
50 
51  template <typename... Is>
52  std::enable_if_t<sizeof...(Is) == rank() &&
53  (true && ... && std::is_integral_v<Is>),
54  reference>
55  operator()(Is... is);
56 
57  template <typename... Is>
58  std::enable_if_t<sizeof...(Is) == rank() &&
59  (true && ... && std::is_integral_v<Is>),
60  const_reference>
61  operator()(Is... is) const;
62 
63  std::ptrdiff_t extent(std::ptrdiff_t rank);
64 
65  const container_type& container() const noexcept;
66  container_type& container() noexcept;
67 
68  std::size_t size() const noexcept;
69 
70 private:
71  container_type container_;
72  [[no_unique_address]] mapping_type mapping_;
73 };
74 
75 template <typename ValueType, typename... Is>
76 using mdarray =
77  basic_mdarray<ValueType, extents<Is...>, layout_left, std_vector_policy>;
78 
79 template <typename ValueType, std::ptrdiff_t Rank>
81  layout_left, std_vector_policy>;
82 
83 } // namespace fub
Definition: mdarray.hpp:27
typename container_policy::template container< value_type > conatiner_type
Definition: mdarray.hpp:35
std::ptrdiff_t extent(std::ptrdiff_t rank)
typename layout_policy::template mapping< Extents > mapping_type
Definition: mdarray.hpp:32
static constexpr std::ptrdiff_t rank() noexcept
LayoutPolicy layout_policy
Definition: mdarray.hpp:31
const container_type & container() const noexcept
basic_mdarray(const extents_type &extents, const allocator_type &allocator=allocator_type())
view_type view() noexcept
ContainerPolicy container_policy
Definition: mdarray.hpp:33
std::size_t size() const noexcept
mapping_type mapping_
Definition: mdarray.hpp:72
basic_mdarray(const value_type &default_value, const extents_type &extents, const allocator_type &allocator=allocator_type())
Extents extents_type
Definition: mdarray.hpp:30
container_type container_
Definition: mdarray.hpp:71
ValueType value_type
Definition: mdarray.hpp:29
An extents object defines a multidimensional index space which is the Cartesian product of integers e...
Definition: mdspan.hpp:208
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
typename dynamic_extents_< make_index_sequence< Rank > >::type dynamic_extents
Definition: mdspan.hpp:725
dynamic_extents< static_cast< std::size_t >Rank)> Extents(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:480
This layout creates mappings which do row first indexing (as in Fortran).
Definition: mdspan.hpp:296