Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions include/Interpolation/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@ class Interpolation
ConstVector<double> fine_values) const;

/* Bilinear interpolation operator */
void applyProlongation0(const PolarGrid& coarse_grid, const PolarGrid& fine_grid, Vector<double> fine_result,
ConstVector<double> coarse_values) const;
void applyProlongation(const PolarGrid& coarse_grid, const PolarGrid& fine_grid, Vector<double> fine_result,
ConstVector<double> coarse_values) const;
void applyExtrapolatedProlongation0(const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
Vector<double> fine_result, ConstVector<double> coarse_values) const;

void applyExtrapolatedProlongation(const PolarGrid& coarse_grid, const PolarGrid& fine_grid,
Vector<double> fine_result, ConstVector<double> coarse_values) const;

/* Scaled full weighting (FW) restriction operator. */
void applyRestriction0(const PolarGrid& fine_grid, const PolarGrid& coarse_grid, Vector<double> coarse_result,
ConstVector<double> fine_values) const;
void applyRestriction(const PolarGrid& fine_grid, const PolarGrid& coarse_grid, Vector<double> coarse_result,
ConstVector<double> fine_values) const;
void applyExtrapolatedRestriction0(const PolarGrid& fine_grid, const PolarGrid& coarse_grid,
Vector<double> coarse_result, ConstVector<double> fine_values) const;

void applyExtrapolatedRestriction(const PolarGrid& fine_grid, const PolarGrid& coarse_grid,
Vector<double> coarse_result, ConstVector<double> fine_values) const;

Expand Down
20 changes: 6 additions & 14 deletions include/Level/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class LevelCache
explicit LevelCache(const PolarGrid& grid, const DensityProfileCoefficients& density_profile_coefficients,
const DomainGeometry& domain_geometry, const bool cache_density_profile_coefficients,
const bool cache_domain_geometry);
explicit LevelCache(const Level& previous_level, const PolarGrid& current_grid);

const DomainGeometry& domainGeometry() const;
const DensityProfileCoefficients& densityProfileCoefficients() const;
Expand All @@ -132,18 +131,8 @@ class LevelCache
inline void obtainValues(const int i_r, const int i_theta, const int global_index, double r, double theta,
double& coeff_beta, double& arr, double& att, double& art, double& detDF) const
{
if (cache_density_profile_coefficients_)
coeff_beta = coeff_beta_[global_index];
else
coeff_beta = density_profile_coefficients_.beta(r, theta);

double coeff_alpha;
if (!cache_domain_geometry_) {
if (cache_density_profile_coefficients_)
coeff_alpha = coeff_alpha_[global_index];
else
coeff_alpha = density_profile_coefficients_.alpha(r, theta);
}
coeff_beta = cache_density_profile_coefficients_ ? coeff_beta_[global_index]
: density_profile_coefficients_.beta(r, theta);

if (cache_domain_geometry_) {
arr = arr_[global_index];
Expand All @@ -152,6 +141,9 @@ class LevelCache
detDF = detDF_[global_index];
}
else {
double coeff_alpha = cache_density_profile_coefficients_ ? coeff_alpha_[global_index]
: density_profile_coefficients_.alpha(r, theta);

compute_jacobian_elements(domain_geometry_, r, theta, coeff_alpha, arr, att, art, detDF);
}
}
Expand All @@ -160,7 +152,7 @@ class LevelCache
const DomainGeometry& domain_geometry_;
const DensityProfileCoefficients& density_profile_coefficients_;

bool cache_density_profile_coefficients_; // cache alpha(r_i), beta(r_i)
bool cache_density_profile_coefficients_; // cache alpha(r, theta), beta(r, theta)
Vector<double> coeff_alpha_;
Vector<double> coeff_beta_;

Expand Down
46 changes: 0 additions & 46 deletions include/PolarGrid/multiindex.h

This file was deleted.

45 changes: 0 additions & 45 deletions include/PolarGrid/point.h

This file was deleted.

63 changes: 4 additions & 59 deletions include/PolarGrid/polargrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

#include "../common/equals.h"

#include "../PolarGrid/multiindex.h"
#include "../PolarGrid/point.h"

// The PolarGrid class implements a donut-shaped 2D grid.
// It is designed to handle polar coordinates, providing functionalities
// for storing data points and performing operations on them.

class PolarGrid
{
public:
Expand All @@ -44,12 +37,11 @@ class PolarGrid
// Optimized, inlined indexing.
int wrapThetaIndex(const int unwrapped_theta_index) const;
int index(const int r_index, const int unwrapped_theta_index) const;
int fastIndex(const int r_index, const int theta_index) const;
void multiIndex(const int node_index, int& r_index, int& theta_index) const;

// Grid Parameters
// Number of grid nodes
int numberOfNodes() const;
// Grid Parameters
// Get the number of grid points in radial direction
int nr() const;
// Get the number of angular divisions
Expand All @@ -58,9 +50,6 @@ class PolarGrid
double radius(const int r_index) const;
// Get the angle at a specific angular index
double theta(const int theta_index) const;
// Get all radii and angles available which define the grid
const std::vector<double>& radii() const;
const std::vector<double>& angles() const;

// Grid distances
// Get the radial distance to the next consecutive radial node at a specified radial index.
Expand All @@ -80,48 +69,8 @@ class PolarGrid
// Get the number of nodes in radial smoother.
int numberRadialSmootherNodes() const;

// ------------------------------------------- //
// Unoptimized Indexing and Neighbor Retrieval //
// ------------------------------------------- //
// Node Indexing (based on the combined circle-radial smoother)
// Get the index of a node based on its position.
int index(const MultiIndex& position) const;
// Get the position of a node based on its index.
MultiIndex multiIndex(const int node_index) const;
// Get the polar coordinates of a node based on its position.
Point polarCoordinates(const MultiIndex& position) const;
// Get adjacent neighbors of a node.
// If the neighbor index is -1, then there is no neighboring node in that direction.
// - The first entry (neighbors[0]) represents the radial direction (r):
// - First: inward neighbor (r - 1)
// - Second: outward neighbor (r + 1)
// - The second entry (neighbors[1]) represents the angular direction (theta):
// - First: counterclockwise neighbor (theta - 1)
// - Second: clockwise neighbor (theta + 1)
void adjacentNeighborsOf(const MultiIndex& position,
std::array<std::pair<int, int>, space_dimension>& neighbors) const;
// Get diagonal neighbors of a node.
// If the neighbor index is -1, then there is no neighboring node in that direction.
// - The first entry (neighbors[0]) represents:
// - First: bottom left neighbor (r - 1, theta - 1)
// - Second: bottom right neighbor (r + 1, theta - 1)
// - The second entry (neighbors[1]) represents:
// - First: top left neighbor (r - 1, theta + 1)
// - Second: top right neighbor (r + 1, theta + 1)
void diagonalNeighborsOf(const MultiIndex& position,
std::array<std::pair<int, int>, space_dimension>& neighbors) const;
// Neighbor distances
// Get distances to adjacent neighbors of a node.
// If there is no neighboring node in that direction, then the neighbor distance is 0.
void adjacentNeighborDistances(const MultiIndex& position,
std::array<std::pair<double, double>, space_dimension>& neighbor_distances) const;

private:
// --------------- //
// Private members //
// --------------- //

// We will use the convention:
// We use the convention:
// radii = [R0, ..., R], angles = [0, ..., 2*pi]
// Note that ntheta will be one less than the size of angles since 0 and 2pi are the same point.
int nr_; // number of nodes in radial direction
Expand Down Expand Up @@ -155,15 +104,11 @@ class PolarGrid
* - numberCircularSmootherNodes + numberRadialSmootherNodes = number_of_nodes()
*/

// ------------------------ //
// Private Helper Functions //
// ------------------------ //

// Check parameter validity
void checkParameters(const std::vector<double>& radii, const std::vector<double>& angles) const;

// Initialize radial_spacings_, angular_spacings_
void initializeDistances();

// Initializes line splitting parameters for Circle/radial indexing.
// splitting_radius: The radius value used for dividing the smoother into a circular and radial section.
// If std::nullopt, automatic line-splitting is enabled.
Expand Down Expand Up @@ -192,4 +137,4 @@ class PolarGrid
// ---------------------------------------------------- //
PolarGrid coarseningGrid(const PolarGrid& grid);

#include "polargrid.inl" // Include the inline function definitions
#include "polargrid.inl" // Include the inline function definitions
48 changes: 21 additions & 27 deletions include/PolarGrid/polargrid.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ inline double PolarGrid::theta(const int theta_index) const
return angles_[theta_index];
}

inline double PolarGrid::smootherSplittingRadius() const
{
return smoother_splitting_radius_;
}

// Get the number of circles in the circular smoother.
inline int PolarGrid::numberSmootherCircles() const
{
Expand Down Expand Up @@ -60,14 +65,9 @@ inline double PolarGrid::angularSpacing(const int unwrapped_theta_index) const
{
// unwrapped_theta_index may be negative or larger than ntheta() to allow for periodicity.
const int theta_index = wrapThetaIndex(unwrapped_theta_index);
assert(theta_index >= 0 && theta_index < ntheta());
return angular_spacings_[theta_index];
}

// ------------------ //
// Optimized indexing //
// ------------------ //

inline int PolarGrid::wrapThetaIndex(const int unwrapped_theta_index) const
{
// The unwrapped_theta_index may be negative or exceed the number of theta steps (ntheta()),
Expand All @@ -80,40 +80,34 @@ inline int PolarGrid::wrapThetaIndex(const int unwrapped_theta_index) const
// This effectively computes unwrapped_theta_index % ntheta(), because it discards all higher bits.
//
// If ntheta is not a power of two, we use the standard modulo approach to handle wrapping.
return is_ntheta_PowerOfTwo_ ? unwrapped_theta_index & (ntheta() - 1) : (unwrapped_theta_index % ntheta() + ntheta()) % ntheta();
int theta_index = is_ntheta_PowerOfTwo_ ? unwrapped_theta_index & (ntheta() - 1)
: (unwrapped_theta_index % ntheta() + ntheta()) % ntheta();
assert(0 <= theta_index && theta_index < ntheta());
return theta_index;
}

inline int PolarGrid::index(const int r_index, const int unwrapped_theta_index) const
{
// unwrapped_theta_index may be negative or larger than ntheta() to allow for periodicity.
assert(0 <= r_index && r_index < nr());
const int theta_index = wrapThetaIndex(unwrapped_theta_index);
assert(0 <= theta_index && theta_index < ntheta());
return r_index < numberSmootherCircles()
? theta_index + ntheta() * r_index
: numberCircularSmootherNodes() + r_index - numberSmootherCircles() + lengthSmootherRadial() * theta_index;
}

inline int PolarGrid::fastIndex(const int r_index, const int theta_index) const
{
assert(0 <= r_index && r_index < nr());
assert(0 <= theta_index && theta_index < ntheta());
return r_index < numberSmootherCircles()
? theta_index + ntheta() * r_index
: numberCircularSmootherNodes() + r_index - numberSmootherCircles() + lengthSmootherRadial() * theta_index;
int theta_index = wrapThetaIndex(unwrapped_theta_index);
int global_index =
r_index < numberSmootherCircles()
? theta_index + ntheta() * r_index
: numberCircularSmootherNodes() + r_index - numberSmootherCircles() + lengthSmootherRadial() * theta_index;
assert(0 <= global_index && global_index < numberOfNodes());
return global_index;
}

inline void PolarGrid::multiIndex(const int node_index, int& r_index, int& theta_index) const
{
assert(0 <= node_index && node_index < numberOfNodes());
if (node_index < numberCircularSmootherNodes())
{
r_index = node_index / ntheta();
theta_index = is_ntheta_PowerOfTwo_ ? node_index & (ntheta() - 1) : node_index % ntheta();
if (node_index < numberCircularSmootherNodes()) {
r_index = node_index / ntheta();
theta_index = wrapThetaIndex(node_index);
}
else
{
else {
theta_index = (node_index - numberCircularSmootherNodes()) / lengthSmootherRadial();
r_index = numberSmootherCircles() + (node_index - numberCircularSmootherNodes()) % lengthSmootherRadial();
r_index = numberSmootherCircles() + (node_index - numberCircularSmootherNodes()) % lengthSmootherRadial();
}
}
3 changes: 0 additions & 3 deletions include/common/space_dimension.h

This file was deleted.

4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ add_subdirectory(InputFunctions)
# Gather all source files
# file(GLOB_RECURSE POLAR_GRID_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/*.cpp)
set(POLAR_GRID_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/anisotropic_division.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/multiindex.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/point.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/polargrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/PolarGrid/anisotropic_division.cpp
)

# file(GLOB_RECURSE GMG_POLAR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/GMGPolar/*.cpp)
Expand Down
Loading