[cig-commits] commit: Make V_Coarsen_Patch_Strategy handle 3D
Mercurial
hg at geodynamics.org
Fri Apr 15 16:47:03 PDT 2011
changeset: 160:95b0f77ccfe6
user: Walter Landry <wlandry at caltech.edu>
date: Fri Apr 15 16:45:04 2011 -0700
files: V_Coarsen_Patch_Strategy.h V_Coarsen_Patch_Strategy/postprocessCoarsen_2D.C V_Coarsen_Patch_Strategy/postprocessCoarsen_3D.C wscript
description:
Make V_Coarsen_Patch_Strategy handle 3D
diff -r cf34865e7575 -r 95b0f77ccfe6 V_Coarsen_Patch_Strategy.h
--- a/V_Coarsen_Patch_Strategy.h Fri Apr 15 15:55:38 2011 -0700
+++ b/V_Coarsen_Patch_Strategy.h Fri Apr 15 16:45:04 2011 -0700
@@ -44,7 +44,7 @@ public:
V_Coarsen_Patch_Strategy(
const tbox::Dimension& dim,
std::string object_name = std::string()):
- xfer::CoarsenPatchStrategy(dim), d_dim(dim),
+ xfer::CoarsenPatchStrategy(dim),
d_object_name(object_name) {}
/*!
@@ -56,13 +56,8 @@ public:
virtual hier::IntVector
getCoarsenOpStencilWidth() const
- { return hier::IntVector::getOne(d_dim); }
- // virtual void
- // preprocessCoarsenBoxes(
- // hier::Patch& fine,
- // const hier::Patch& coarse,
- // const hier::BoxList& fine_boxes,
- // const hier::IntVector& ratio) {}
+ { return hier::IntVector::getOne(getDim()); }
+
virtual void
preprocessCoarsen(hier::Patch& ,
const hier::Patch& fine,
@@ -74,6 +69,26 @@ public:
virtual void
postprocessCoarsen(
+ hier::Patch& coarse,
+ const hier::Patch& fine,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio)
+ {
+ if(getDim().getValue()==2)
+ postprocessCoarsen_2D(coarse,fine,coarse_box,ratio);
+ else
+ postprocessCoarsen_3D(coarse,fine,coarse_box,ratio);
+ }
+
+ void
+ postprocessCoarsen_2D(
+ hier::Patch& coarse,
+ const hier::Patch& fine,
+ const hier::Box& coarse_box,
+ const hier::IntVector& ratio);
+
+ void
+ postprocessCoarsen_3D(
hier::Patch& coarse,
const hier::Patch& fine,
const hier::Box& coarse_box,
@@ -368,8 +383,6 @@ private:
// makeFaceBoundaryBox(
// const hier::BoundaryBox& boundary_box) const;
- const tbox::Dimension d_dim;
-
std::string d_object_name;
/*!
diff -r cf34865e7575 -r 95b0f77ccfe6 V_Coarsen_Patch_Strategy/postprocessCoarsen_2D.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/V_Coarsen_Patch_Strategy/postprocessCoarsen_2D.C Fri Apr 15 16:45:04 2011 -0700
@@ -0,0 +1,89 @@
+#include "V_Coarsen_Patch_Strategy.h"
+
+void
+SAMRAI::solv::V_Coarsen_Patch_Strategy::postprocessCoarsen_2D
+(hier::Patch& coarse,
+ const hier::Patch& fine,
+ const hier::Box& ,
+ const hier::IntVector& )
+{
+ /* Fix up the boundary elements by iterating through the boundary
+ boxes */
+
+ /* We only care about edges, not corners, so we only iterate over
+ edge boundary boxes. */
+ const tbox::Array<hier::BoundaryBox>
+ &boundaries=coarse_fine[fine.getPatchLevelNumber()]->getEdgeBoundaries(coarse.getGlobalId());
+
+ tbox::Pointer<pdat::SideData<double> >
+ v_fine = fine.getPatchData(v_id);
+ tbox::Pointer<pdat::SideData<double> >
+ v = coarse.getPatchData(v_id);
+
+ TBOX_ASSERT(!v.isNull());
+ TBOX_ASSERT(!v_fine.isNull());
+ TBOX_ASSERT(v_fine->getDepth() == v->getDepth());
+ TBOX_ASSERT(v->getDepth() == 1);
+
+ hier::Box gbox(v_fine->getGhostBox());
+ hier::Index ip(1,0), jp(0,1);
+ for(int mm=0; mm<boundaries.size(); ++mm)
+ {
+ hier::Box bbox=boundaries[mm].getBox();
+ int location_index=boundaries[mm].getLocationIndex();
+
+ hier::Index lower=hier::Index::coarsen(bbox.lower(),hier::Index(2,2)),
+ upper=hier::Index::coarsen(bbox.upper(),hier::Index(2,2));
+
+ for(int j=lower(1); j<=upper(1); ++j)
+ for(int i=lower(0); i<=upper(0); ++i)
+ {
+ /* Fix vx */
+ if(location_index==0)
+ {
+ pdat::SideIndex coarse(hier::Index(i,j),0,
+ pdat::SideIndex::Upper);
+ pdat::SideIndex center(coarse*2);
+ if(center[1]>=gbox.lower(1) && center[1]<gbox.upper(1))
+ {
+ (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+jp))/2;
+ }
+ }
+ else if(location_index==1)
+ {
+ pdat::SideIndex coarse(hier::Index(i,j),0,
+ pdat::SideIndex::Lower);
+ pdat::SideIndex center(coarse*2);
+ if(center[1]>=gbox.lower(1) && center[1]<gbox.upper(1))
+ {
+ (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+jp))/2;
+ }
+ }
+ /* Fix vy */
+ else if(location_index==2)
+ {
+ pdat::SideIndex coarse(hier::Index(i,j),1,
+ pdat::SideIndex::Upper);
+ pdat::SideIndex center(coarse*2);
+ if(center[0]>=gbox.lower(0) && center[0]<gbox.upper(0))
+ {
+ (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+ip))/2;
+ }
+ }
+ else if(location_index==3)
+ {
+ pdat::SideIndex coarse(hier::Index(i,j),1,
+ pdat::SideIndex::Lower);
+ pdat::SideIndex center(coarse*2);
+ if(center[0]>=gbox.lower(0) && center[0]<gbox.upper(0))
+ {
+ (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+ip))/2;
+ }
+ }
+ else
+ {
+ abort();
+ }
+ }
+ }
+}
diff -r cf34865e7575 -r 95b0f77ccfe6 V_Coarsen_Patch_Strategy/postprocessCoarsen_3D.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/V_Coarsen_Patch_Strategy/postprocessCoarsen_3D.C Fri Apr 15 16:45:04 2011 -0700
@@ -0,0 +1,87 @@
+#include "V_Coarsen_Patch_Strategy.h"
+
+void
+SAMRAI::solv::V_Coarsen_Patch_Strategy::postprocessCoarsen_3D
+(hier::Patch& coarse,
+ const hier::Patch& fine,
+ const hier::Box& ,
+ const hier::IntVector& )
+{
+ /* Fix up the boundary elements by iterating through the boundary
+ boxes */
+
+ /* We only care about faces, not edges or corners, so we only
+ iterate over face boundary boxes. */
+ const tbox::Array<hier::BoundaryBox> &boundaries
+ (coarse_fine[fine.getPatchLevelNumber()]
+ ->getFaceBoundaries(coarse.getGlobalId()));
+
+ tbox::Pointer<pdat::SideData<double> >
+ v_fine = fine.getPatchData(v_id);
+ tbox::Pointer<pdat::SideData<double> >
+ v = coarse.getPatchData(v_id);
+
+ TBOX_ASSERT(!v.isNull());
+ TBOX_ASSERT(!v_fine.isNull());
+ TBOX_ASSERT(v_fine->getDepth() == v->getDepth());
+ TBOX_ASSERT(v->getDepth() == 1);
+
+ hier::Box gbox(v_fine->getGhostBox());
+ hier::Index ip(1,0,0), jp(0,1,0), kp(0,0,1);
+ for(int mm=0; mm<boundaries.size(); ++mm)
+ {
+ hier::Box bbox=boundaries[mm].getBox();
+ /* location_index tells where, in relation to the box, the boundary is.
+ 0: x lower
+ 1: x upper
+ 2: y lower
+ 3: y upper
+ 4: z lower
+ 5: z upper
+
+ Therefore, if location_index==3, then we need to set vy on
+ the __lower__ side of that boundary box. */
+
+ int location_index=boundaries[mm].getLocationIndex();
+ int direction(location_index/2);
+ int side(location_index%2==0 ? pdat::SideIndex::Upper
+ : pdat::SideIndex::Lower);
+ int dir2((direction+1)%3), dir3((direction+2)%3);
+ hier::Index yp(ip), zp(ip);
+ switch(direction)
+ {
+ case 0:
+ yp=jp;
+ zp=kp;
+ break;
+ case 1:
+ yp=kp;
+ zp=ip;
+ break;
+ case 2:
+ yp=ip;
+ zp=jp;
+ break;
+ }
+
+ hier::Index lower=hier::Index::coarsen(bbox.lower(),hier::Index(2,2,2)),
+ upper=hier::Index::coarsen(bbox.upper(),hier::Index(2,2,2));
+
+ for(int k=lower(2); k<=upper(2); ++k)
+ for(int j=lower(1); j<=upper(1); ++j)
+ for(int i=lower(0); i<=upper(0); ++i)
+ {
+ pdat::SideIndex coarse(hier::Index(i,j,k),direction,side);
+ pdat::SideIndex center(coarse*2);
+ if(center[dir2]>=gbox.lower(dir2)
+ && center[dir2]<gbox.upper(dir2)
+ && center[dir3]>=gbox.lower(dir3)
+ && center[dir3]<gbox.upper(dir3))
+ {
+ (*v)(coarse)=
+ ((*v_fine)(center) + (*v_fine)(center+yp)
+ + (*v_fine)(center+zp) + (*v_fine)(center+yp+zp))/4;
+ }
+ }
+ }
+}
diff -r cf34865e7575 -r 95b0f77ccfe6 wscript
--- a/wscript Fri Apr 15 15:55:38 2011 -0700
+++ b/wscript Fri Apr 15 16:45:04 2011 -0700
@@ -29,7 +29,8 @@ def build(bld):
'V_Boundary_Refine/Update_V.C',
'P_Refine_Patch_Strategy.C',
'V_Refine_Patch_Strategy.C',
- 'V_Coarsen_Patch_Strategy.C',
+ 'V_Coarsen_Patch_Strategy/postprocessCoarsen_2D.C',
+ 'V_Coarsen_Patch_Strategy/postprocessCoarsen_3D.C',
'Cell_Viscosity_Coarsen.C',
'Edge_Viscosity_Coarsen.C',
'set_boundary.C',
More information about the CIG-COMMITS
mailing list