23 Grid(std::vector<size_t> shape, std::vector<double> spacing)
24 : shape_(shape), spacing_(spacing), dim_(shape.size()) {
25 if (shape.size() != spacing.size()) {
26 throw std::invalid_argument(
"Shape y spacing deben tener el mismo número de dimensiones.");
28 if (dim_ < 1 || dim_ > 3) {
29 throw std::invalid_argument(
"La malla debe ser 1D, 2D o 3D.");
33 for (
size_t i = 0; i < dim_; ++i) {
34 origin_[i] = -0.5 * (
static_cast<double>(shape_[i] - 1)) * spacing_[i];
40 const std::vector<size_t>&
get_shape()
const {
return shape_; }
41 const std::vector<double>&
get_spacing()
const {
return spacing_; }
49 for (
size_t n : shape_) {
62 throw std::out_of_range(
"El índice de la malla está fuera de rango.");
65 std::vector<double> coords(dim_);
66 size_t temp_index = index;
69 coords[0] = origin_[0] +
static_cast<double>(index) * spacing_[0];
70 }
else if (dim_ == 2) {
71 size_t nx = shape_[0];
72 size_t ix = temp_index % nx;
73 size_t iy = temp_index / nx;
74 coords[0] = origin_[0] +
static_cast<double>(ix) * spacing_[0];
75 coords[1] = origin_[1] +
static_cast<double>(iy) * spacing_[1];
76 }
else if (dim_ == 3) {
77 size_t nx = shape_[0];
78 size_t ny = shape_[1];
79 size_t ix = temp_index % nx;
80 size_t iy = (temp_index / nx) % ny;
81 size_t iz = temp_index / (nx * ny);
82 coords[0] = origin_[0] +
static_cast<double>(ix) * spacing_[0];
83 coords[1] = origin_[1] +
static_cast<double>(iy) * spacing_[1];
84 coords[2] = origin_[2] +
static_cast<double>(iz) * spacing_[2];
90 std::vector<size_t> shape_;
91 std::vector<double> spacing_;
92 std::vector<double> origin_;
Representa una malla espacial (1D, 2D o 3D) para la simulación.
Definition Grid.h:16
size_t get_dim() const
Definition Grid.h:39
std::vector< double > get_coords(size_t index) const
Obtiene las coordenadas espaciales para un índice de malla plano dado.
Definition Grid.h:60
size_t get_total_points() const
Calcula el número total de puntos en la malla.
Definition Grid.h:47
Grid(std::vector< size_t > shape, std::vector< double > spacing)
Construye un objeto Grid.
Definition Grid.h:23
const std::vector< double > & get_spacing() const
Definition Grid.h:41
const std::vector< size_t > & get_shape() const
Definition Grid.h:40