QUGaR 0.0.9
Loading...
Searching...
No Matches
cart_grid_tp.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------
2//
3// Copyright (C) 2025-present by Pablo Antolin
4//
5// This file is part of the QUGaR library.
6//
7// SPDX-License-Identifier: MIT
8//
9// --------------------------------------------------------------------------
10
11#ifndef QUGAR_LIBRARY_CART_GRID_TP_HPP
12#define QUGAR_LIBRARY_CART_GRID_TP_HPP
13
20
21#include <qugar/bbox.hpp>
22#include <qugar/point.hpp>
24#include <qugar/tolerance.hpp>
25#include <qugar/types.hpp>
26
27#include <array>
28#include <cstddef>
29#include <cstdint>
30#include <memory>
31#include <optional>
32#include <vector>
33
34namespace qugar {
35
36
40template<int dim> class CartGridTP
41{
44
45public:
47
48
50 explicit CartGridTP(const std::array<std::vector<real>, dim> &breaks);
51
56 CartGridTP(const BoundBox<dim> &domain, const std::array<std::size_t, dim> &n_intrvs_dir);
57
61 explicit CartGridTP(const std::array<std::size_t, dim> &n_intrvs_dir);
63
65
66
70 [[nodiscard]] const std::vector<real> &get_breaks(int dir) const;
71
74 [[nodiscard]] const BoundBox<dim> &get_domain() const;
75
82 [[nodiscard]] std::int64_t get_cell_id(const PointType &point, const Tolerance &tolerance = Tolerance()) const;
83
92 [[nodiscard]] std::optional<int> at_cells_boundary(const PointType &point,
93 const Tolerance &tolerance = Tolerance()) const;
94
100 [[nodiscard]] bool on_boundary(std::int64_t cell_id, int local_facet_id) const;
101
106 [[nodiscard]] std::vector<std::int64_t> get_boundary_cells(int facet_id) const;
107
112 [[nodiscard]] std::int64_t to_flat(const TensorIndexTP<dim> &tid) const;
113
118 [[nodiscard]] TensorIndexTP<dim> to_tensor(std::int64_t fid) const;
119
124
125
129 [[nodiscard]] std::size_t get_num_cells() const;
130
135 [[nodiscard]] BoundBox<dim> get_cell_domain(std::int64_t cell_fid) const;
136
138
139
140private:
142
143
144 std::array<std::vector<real>, dim> breaks_;
150};
151
156template<int dim> class SubCartGridTP
157{
158public:
160 using GridPtr = std::shared_ptr<const CartGridTP<dim>>;
161
167 SubCartGridTP(const GridPtr grid, const TensorIndexTP<dim> &indices_start, const TensorIndexTP<dim> &indices_end);
168
173 SubCartGridTP(const GridPtr grid, const TensorIndexRangeTP<dim> &indices_range);
174
179 explicit SubCartGridTP(const GridPtr grid);
180
181private:
186
187public:
196
201 [[nodiscard]] std::int64_t to_flat(const TensorIndexTP<dim> &tid) const;
202
206 [[nodiscard]] std::size_t get_num_cells() const;
207
211 [[nodiscard]] bool is_full() const;
212
216 [[nodiscard]] bool is_unique_cell() const;
217
220 [[nodiscard]] const TensorIndexRangeTP<dim> &get_range() const;
221
226 [[nodiscard]] std::array<std::shared_ptr<const SubCartGridTP<dim>>, 2> split() const;
227
231 [[nodiscard]] BoundBox<dim> get_domain() const;
232
236 [[nodiscard]] GridPtr get_grid() const;
237
241 [[nodiscard]] std::int64_t get_single_cell() const;
242};
243
244}// namespace qugar
245
246#endif// QUGAR_LIBRARY_CART_GRID_TP_HPP
Definition of Cartesian bounding box class.
Class representing a dim-dimensional Cartesian product bounding box.
Definition bbox.hpp:38
Class representing a dim-dimensional Cartesian tensor-product grid.
Definition cart_grid_tp.hpp:41
std::size_t get_num_cells() const
Gets the total number of cell.
TensorIndexRangeTP< dim > range_
Indices range.
Definition cart_grid_tp.hpp:148
std::array< std::vector< real >, dim > breaks_
Breaks definining the cell intervals along the dim parametric directions.
Definition cart_grid_tp.hpp:144
CartGridTP(const BoundBox< dim > &domain, const std::array< std::size_t, dim > &n_intrvs_dir)
Construct a new CartGridTP object from a domain and the number of intervals per direction.
TensorIndexTP< dim > to_tensor(std::int64_t fid) const
Gets the tensor index of a grid cell from the flat index.
CartGridTP(const std::array< std::size_t, dim > &n_intrvs_dir)
Construct a new CartGridTP object from a [0,1] domain and the number of intervals per direction.
qugar::BoundBox< dim > domain_
Domain of the grid.
Definition cart_grid_tp.hpp:146
std::vector< std::int64_t > get_boundary_cells(int facet_id) const
Gets the list of cells belonging to given facet of the grid.
BoundBox< dim > get_cell_domain(std::int64_t cell_fid) const
Gets an cell's domain.
bool on_boundary(std::int64_t cell_id, int local_facet_id) const
Checks if a cell's facet is on the grids boundary.
std::optional< int > at_cells_boundary(const PointType &point, const Tolerance &tolerance=Tolerance()) const
Checks if the given point is on the boundary of two cells (up to tolerance).
std::int64_t get_cell_id(const PointType &point, const Tolerance &tolerance=Tolerance()) const
Get the id of the cell the given point belongs to.
const std::vector< real > & get_breaks(int dir) const
Gets the breaks along the given direction dir.
TensorSizeTP< dim > get_num_cells_dir() const
Gets the number of cells per direction.
const BoundBox< dim > & get_domain() const
Gets the grid's domain.
std::int64_t to_flat(const TensorIndexTP< dim > &tid) const
Gets the flat index of a grid cell from the tensor index.
Point< dim > PointType
Point type.
Definition cart_grid_tp.hpp:43
CartGridTP(const std::array< std::vector< real >, dim > &breaks)
Construct a new CartGridTP object from its breaks.
Subgrid of a Cartesian grid TP. It is a subset of the cells of a given grid.
Definition cart_grid_tp.hpp:157
TensorIndexRangeTP< dim > range_
Indices range.
Definition cart_grid_tp.hpp:185
BoundBox< dim > get_domain() const
Creates the bounding box of the subgrid's domain.
TensorSizeTP< dim > get_num_cells_dir() const
Gets the number of cells (spans) per direction of the subgrid.
GridPtr grid_
Parent grid.
Definition cart_grid_tp.hpp:183
SubCartGridTP(const GridPtr grid, const TensorIndexRangeTP< dim > &indices_range)
Constructor.
bool is_full() const
Checks if the subgrid corresponds to the total grid.
bool is_unique_cell() const
Checks if the subgrid has only one cell.
std::array< std::shared_ptr< const SubCartGridTP< dim > >, 2 > split() const
Splits the current subgrid along the direction with a largest number of cells.
SubCartGridTP(const GridPtr grid, const TensorIndexTP< dim > &indices_start, const TensorIndexTP< dim > &indices_end)
Constructor.
std::int64_t get_single_cell() const
Gets the single cell in the subgrid.
std::int64_t to_flat(const TensorIndexTP< dim > &tid) const
Gets the flat index of a grid cells from the tensor index.
SubCartGridTP(const GridPtr grid)
Constructor. Creates a subgrid containing the full grid.
std::shared_ptr< const CartGridTP< dim > > GridPtr
Shared-pointer to Cartesian grid type.
Definition cart_grid_tp.hpp:160
const TensorIndexRangeTP< dim > & get_range() const
Gets a range describing the range of the subrid.
GridPtr get_grid() const
Gets the parent grid.
std::size_t get_num_cells() const
Gets the total number of cells of the subgrid.
Class representing a dim-dimensional range defined by lower and upper tensor bounds.
Definition tensor_index_tp.hpp:246
Class representing a dim-dimensional tensor-product indices.
Definition tensor_index_tp.hpp:97
Class representing a dim-dimensional tensor-product sizes container.
Definition tensor_index_tp.hpp:40
Class for tolerance related computations.
Definition tolerance.hpp:33
QUGaR's main namespace.
Definition affine_transf.hpp:28
Vector< T, dim > Point
Class representing a dim-dimensional Point.
Definition point.hpp:34
Definition and implementation of Point class.
Declaration of tensor-product index and size related classes.
Definition of tolerance related functionalities.
Declaration of types.