Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

# Set compiler flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -Wno-unused -Wno-psabi")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -Wno-unused -Wno-psabi -Wfloat-conversion")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -mtune=generic -Wno-psabi")

# Set coverage compiler flags - must come before any targets are defined
Expand Down
4 changes: 2 additions & 2 deletions src/GMGPolar/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ int GMGPolar::chooseNumberOfLevels(const PolarGrid& finestGrid)
}

/* Currently unused: Number of levels which guarantee linear scalability */
const int linear_complexity_levels = std::ceil(
(2.0 * std::log(static_cast<double>(finestGrid.numberOfNodes())) - std::log(3.0)) / (3.0 * std::log(4.0)));
const int linear_complexity_levels = static_cast<int>(std::ceil(
(2.0 * std::log(static_cast<double>(finestGrid.numberOfNodes())) - std::log(3.0)) / (3.0 * std::log(4.0))));

// Determine the number of levels as the minimum of radial maximum level, angular maximum level,
// and the maximum levels specified.
Expand Down
21 changes: 12 additions & 9 deletions src/PolarGrid/anisotropic_division.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ void PolarGrid::RadialAnisotropicDivision(std::vector<double>& r_temp, double R0
// very ugly anisotropy hack.... dividing recursively smaller and smaller number of cells

/* uniform division of r in 2^nr_exp - 2^aniso */
int dummy_lognr = nr_exp;
int n_elems_equi = pow(2, dummy_lognr) - pow(2, anisotropic_factor);
int dummy_lognr = nr_exp;
// n_elems_equi = 2**dummy_lognr - 2**anisotropic_factor
int n_elems_equi = (1 << dummy_lognr) - (1 << anisotropic_factor);
if (anisotropic_factor < 0 || n_elems_equi <= 0) {
throw std::runtime_error("Please choose anisotropy factor a such that 2^fac_ani < 2^nr_exp.\n");
}
Expand All @@ -30,22 +31,24 @@ void PolarGrid::RadialAnisotropicDivision(std::vector<double>& r_temp, double R0
r_temp2[nr - 1] = R;

/* refine around 2/3 of r */
int n_elems_refined = pow(2, anisotropic_factor);
// n_elems_refined = 2**anisotropic_factor
int n_elems_refined = (1 << anisotropic_factor);

// edge
int se;

// Added by Allan Kuhn to fix a memory error
if (floor(nr * percentage) > nr - (n_elems_refined / 2)) {
int new_aniso = log2(nr - floor(nr * percentage)) + 1;
n_elems_refined = pow(2, new_aniso);
int new_aniso = static_cast<int>(log2(nr - floor(nr * percentage)) + 1);
// n_elems_refined = 2**new_aniso
n_elems_refined = (1 << new_aniso);
}

se = floor(nr * percentage) - n_elems_refined / 2;
se = static_cast<int>(floor(nr * percentage)) - n_elems_refined / 2;
int ee = se + n_elems_refined;
// takeout
int st = ceil((double)n_elems_refined / 4.0 + 1) - 1;
int et = floor(3 * ((double)n_elems_refined / 4.0));
int st = static_cast<int>(ceil((double)n_elems_refined / 4.0 + 1) - 1);
int et = static_cast<int>(floor(3 * ((double)n_elems_refined / 4.0)));

std::set<double> r_set;
std::set<double> r_set_p1;
Expand Down Expand Up @@ -97,4 +100,4 @@ void PolarGrid::RadialAnisotropicDivision(std::vector<double>& r_temp, double R0
}
for (int i = 0; i < n_elems_equi - ee + 1; i++)
r_temp[se + r_set.size() + i] = r_temp2[ee + i];
}
}
19 changes: 11 additions & 8 deletions src/PolarGrid/polargrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void PolarGrid::constructRadialDivisions(double R0, double R, const int nr_exp,
// Therefore we first consider 2^(nr_exp-1) points.
std::vector<double> r_temp;
if (anisotropic_factor == 0) {
int nr = pow(2, nr_exp - 1) + 1;
// nr = 2**(nr_exp-1) + 1
int nr = (1 << (nr_exp - 1)) + 1;
double uniform_distance = (R - R0) / (nr - 1);
assert(uniform_distance > 0.0);
r_temp.resize(nr);
Expand Down Expand Up @@ -82,11 +83,13 @@ void PolarGrid::constructAngularDivisions(const int ntheta_exp, const int nr)
{
if (ntheta_exp < 0) {
// Choose number of theta divisions similar to radial divisions.
ntheta_ = pow(2, ceil(log2(nr)));
// ntheta_ = pow(2, ceil(log2(nr-1)));
// ntheta_ = 2**ceil(log2(nr))
ntheta_ = 1 << static_cast<int>(ceil(log2(nr)));
// ntheta_ = 1 << static_cast<int>(ceil(log2(nr-1)));
}
else {
ntheta_ = pow(2, ntheta_exp);
// ntheta_ = 2**ntheta_exp
ntheta_ = 1 << ntheta_exp;
}
is_ntheta_PowerOfTwo_ = (ntheta_ & (ntheta_ - 1)) == 0;
// Note that currently ntheta_ = 2^k which allows us to do some optimizations when indexing.
Expand All @@ -110,16 +113,16 @@ void PolarGrid::refineGrid(const int divideBy2)

std::vector<double> PolarGrid::divideVector(const std::vector<double>& vec, const int divideBy2) const
{
const double powerOfTwo = 1 << divideBy2;
size_t vecSize = vec.size();
size_t resultSize = vecSize + (vecSize - 1) * (powerOfTwo - 1);
const int powerOfTwo = 1 << divideBy2;
size_t vecSize = vec.size();
size_t resultSize = vecSize + (vecSize - 1) * (powerOfTwo - 1);
std::vector<double> result(resultSize);

for (size_t i = 0; i < vecSize - 1; ++i) {
size_t baseIndex = i * powerOfTwo;
result[baseIndex] = vec[i]; // Add the original value
for (int j = 1; j < powerOfTwo; ++j) {
double interpolated_value = vec[i] + j * (vec[i + 1] - vec[i]) / powerOfTwo;
double interpolated_value = vec[i] + j * (vec[i + 1] - vec[i]) / static_cast<double>(powerOfTwo);
result[baseIndex + j] = interpolated_value;
}
}
Expand Down