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

Added function to compute convolution. #4

Merged
merged 1 commit into from
Jan 18, 2022
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FIND_PACKAGE(IBAMR REQUIRED)

SET(CXX_SRC
CohesionStressRHS.cpp
utility_functions.cpp
)
ADD_EXECUTABLE(main2d main.cpp)
TARGET_SOURCES(main2d PRIVATE ${CXX_SRC})
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include $(IBAMR_BUILD_DIR)/config/make.inc
## main driver is in main.cpp
##
## PDIM = 2 implies two spatial dimensions
OBJS = CohesionRHS.o
OBJS = CohesionRHS.o utility_functions.o
#main.o
PDIM = 2

Expand Down
42 changes: 42 additions & 0 deletions utility_functions.cpp
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);
Copy link
Collaborator

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?

Copy link
Owner Author

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.

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
32 changes: 32 additions & 0 deletions utility_functions.h
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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