Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discretization: fix evaluation of stencil grantient weights #76

Merged
merged 3 commits into from
Jul 29, 2020
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
6 changes: 2 additions & 4 deletions src/containers/piercedKernelIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,15 @@ friend class PiercedStorageIterator;
/**
* Two-way comparison.
*/
template<typename other_id_t>
bool operator==(const PiercedKernelIterator<other_id_t>& rhs) const
bool operator==(const PiercedKernelIterator &rhs) const
{
return (m_kernel == rhs.m_kernel) && (m_pos == rhs.m_pos);
}

/**
* Two-way comparison.
*/
template<typename other_id_t>
bool operator!=(const PiercedKernelIterator<other_id_t>& rhs) const
bool operator!=(const PiercedKernelIterator &rhs) const
{
return (m_kernel != rhs.m_kernel) || (m_pos != rhs.m_pos);
}
Expand Down
8 changes: 2 additions & 6 deletions src/containers/piercedStorageIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,15 @@ friend class PiercedStorage;
/**
* Two-way comparison.
*/
template<typename other_value_t, typename other_id_t = long,
typename other_value_no_cv_t = typename std::remove_cv<other_value_t>::type>
bool operator==(const PiercedStorageIterator<other_value_t, other_id_t, other_value_no_cv_t>& rhs) const
bool operator==(const PiercedStorageIterator &rhs) const
{
return (PiercedKernelIterator<id_t>::operator==(rhs) && m_storage == rhs.m_storage);
}

/**
* Two-way comparison.
*/
template<typename other_value_t, typename other_id_t = long,
typename other_value_no_cv_t = typename std::remove_cv<other_value_t>::type>
bool operator!=(const PiercedStorageIterator<other_value_t, other_id_t, other_value_no_cv_t>& rhs) const
bool operator!=(const PiercedStorageIterator &rhs) const
{
return (PiercedKernelIterator<id_t>::operator!=(rhs) || m_storage != rhs.m_storage);
}
Expand Down
49 changes: 16 additions & 33 deletions src/discretization/reconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2673,51 +2673,34 @@ void ReconstructionKernel::computeGradientLimitedWeights(uint8_t degree, const s
int nCoeffs = ReconstructionPolynomial::getCoefficientCount(degree, dimensions);

BITPIT_CREATE_WORKSPACE(dcsi, double, nCoeffs, MAX_STACK_WORKSPACE_SIZE);
BITPIT_CREATE_WORKSPACE(directionalStencilWeights, double, nEquations, MAX_STACK_WORKSPACE_SIZE);

const double *polynomialWeights = getPolynomialWeights();

// Evalaute weights in x-direction
ReconstructionPolynomial::evalPointBasisDerivatives(degree, dimensions, origin, point, {{1., 0., 0.}}, dcsi);
if (limiters) {
applyLimiter(degree, limiters, dcsi);
}

cblas_dgemv(CBLAS_ORDER::CblasColMajor, CBLAS_TRANSPOSE::CblasNoTrans,
nEquations, nCoeffs, 1., polynomialWeights, nEquations,
dcsi, 1, 0, directionalStencilWeights, 1);

for (int i = 0; i < nEquations; ++i) {
gradientWeights[i][0] = directionalStencilWeights[i];
}

// Evalaute weights in y-direction
ReconstructionPolynomial::evalPointBasisDerivatives(degree, getDimensions(), origin, point, {{0., 1., 0.}}, dcsi);
if (limiters) {
applyLimiter(degree, limiters, dcsi);
}
std::array<double, 3> direction = {{0., 0., 0.}};
for (int d = 0; d < dimensions; ++d) {
direction[d] = 1.;

cblas_dgemv(CBLAS_ORDER::CblasColMajor, CBLAS_TRANSPOSE::CblasNoTrans,
nEquations, nCoeffs, 1., polynomialWeights, nEquations,
dcsi, 1, 0, directionalStencilWeights, 1);

for (int i = 0; i < nEquations; ++i) {
gradientWeights[i][1] = directionalStencilWeights[i];
}

// Evalaute weights in z-direction
if (dimensions == 3) {
ReconstructionPolynomial::evalPointBasisDerivatives(degree, getDimensions(), origin, point, {{0., 0., 1.}}, dcsi);
ReconstructionPolynomial::evalPointBasisDerivatives(degree, dimensions, origin, point, direction, dcsi);
if (limiters) {
applyLimiter(degree, limiters, dcsi);
}

// Weights are stored in contiguous three-dimensional arrays, this
// means we can access the weights of the current dimensions using
// the dimension as offset and a stride of three elements
cblas_dgemv(CBLAS_ORDER::CblasColMajor, CBLAS_TRANSPOSE::CblasNoTrans,
nEquations, nCoeffs, 1., polynomialWeights, nEquations,
dcsi, 1, 0, directionalStencilWeights, 1);
dcsi, 1, 0, gradientWeights->data() + d, 3);

direction[d] = 0.;
}

// Explicitly zero unused components
if (dimensions != ReconstructionPolynomial::MAX_DIMENSIONS) {
for (int i = 0; i < nEquations; ++i) {
gradientWeights[i][2] = directionalStencilWeights[i];
for (int d = dimensions; d < ReconstructionPolynomial::MAX_DIMENSIONS; ++d) {
gradientWeights[i][d] = 0.;
}
}
}
}
Expand Down