-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added function to compute convolution. #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <ibamr/app_namespaces.h> | ||
|
||
#include <ibtk/ibtk_utilities.h> | ||
|
||
#include <Box.h> | ||
|
||
// Local includes | ||
#include "utility_functions.h" | ||
|
||
namespace IBAMR | ||
{ | ||
double | ||
convolution(double alpha, | ||
const CellData<NDIM, double>& a_data, | ||
double beta, | ||
const CellData<NDIM, double>& b_data, | ||
std::function<double(double)> phi, | ||
unsigned int phi_width, | ||
const CellIndex<NDIM>& idx, | ||
const double* const dx) | ||
{ | ||
// Box over which integration is performed | ||
Box<NDIM> int_box(idx, idx); | ||
int_box.grow(phi_width); | ||
#ifndef NDEBUG | ||
// Error checking. Need ghost data for patch data. | ||
TBOX_ASSERT(a_data.getGhostBox() * int_box == int_box); | ||
TBOX_ASSERT(b_data.getGhostBox() * int_box == int_box); | ||
#endif | ||
// Now compute convolution | ||
double convolve = 0.0; | ||
for (CellIterator<NDIM> ci(int_box); ci; ci++) | ||
{ | ||
const CellIndex<NDIM>& n_idx = ci(); | ||
double phi_weight = 1.0; | ||
; | ||
for (int d = 0; d < NDIM; ++d) phi_weight *= phi(static_cast<double>(n_idx(d) - idx(d))) * dx[d]; | ||
convolve += (alpha * a_data(n_idx) + beta * b_data(n_idx)) * phi_weight; | ||
} | ||
return convolve; | ||
} | ||
} // namespace IBAMR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/////////////////////////////// INCLUDE GUARD //////////////////////////////// | ||
|
||
#ifndef included_utility_functions | ||
#define included_utility_functions | ||
|
||
/////////////////////////////// INCLUDES ///////////////////////////////////// | ||
#include <ibamr/config.h> | ||
|
||
#include <CellData.h> | ||
#include <CellIndex.h> | ||
|
||
#include <functional> | ||
namespace IBAMR | ||
{ | ||
/*! | ||
* Computes the convolution of (alpha*a + beta*b) and the function phi at a given patch index, assuming phi has finite | ||
* support. | ||
* | ||
* Both patch data MUST have enough ghost cells for the width of the phi function. This assumes the phi function is | ||
* centered at idx and scaled by the grid spacing. | ||
*/ | ||
double convolution(double alpha, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain these parameters some more? I'm trying to include this in the two files I've been working on. In particular I'm curious as to where phi, phi_width, and dx come from and should be defined. I'm assuming a_data and b_data correspond loosely to phi_a and phi_b? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also a bit confused in my implementation since to compute alpha, you need to compute R2, which uses eta. But then eta is computed using alpha? This seems like a circular dependency. |
||
const SAMRAI::pdat::CellData<NDIM, double>& a_data, | ||
double beta, | ||
const SAMRAI::pdat::CellData<NDIM, double>& b_data, | ||
std::function<double(double)> phi, | ||
unsigned int phi_width, | ||
const SAMRAI::pdat::CellIndex<NDIM>& idx, | ||
const double* const dx); | ||
} // namespace IBAMR | ||
|
||
#endif // included_utility_functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on why we need ghost data here, and what exactly this line is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line computes the intersection between the two boxes, and makes sure that it's equal to the integration box. * is an overloaded operator for type
Box<NDIM>
. Essentially, we're checking that the integration box is contained within the ghost box.