// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetSlab/src/Attic/carpetslab.cc,v 1.9 2001/07/02 13:22:15 schnetter Exp $ #include #include #include #include "cctk.h" #include "Carpet/CarpetLib/src/bbox.hh" #include "Carpet/CarpetLib/src/bboxset.hh" #include "Carpet/CarpetLib/src/dh.hh" #include "Carpet/CarpetLib/src/gdata.hh" #include "Carpet/CarpetLib/src/gh.hh" #include "Carpet/CarpetLib/src/ggf.hh" #include "Carpet/CarpetLib/src/vect.hh" #include "Carpet/Carpet/src/carpet.hh" #include "carpetslab.hh" static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetSlab/src/Attic/carpetslab.cc,v 1.9 2001/07/02 13:22:15 schnetter Exp $"; namespace CarpetSlab { using namespace Carpet; void* GetSlab (cGH* const cgh, const int dest_proc, const int n, const int ti, const int hdim, const int origin[/*vdim*/], const int dirs[/*hdim*/], const int stride[/*hdim*/], const int length[/*hdim*/]) { // Check global state assert (reflevel>=0); assert (mglevel>=0); // Save global state int saved_component = component; component = -1; // Check Cactus grid hierarchy assert (cgh); // Check destination processor assert (dest_proc>=-1 && dest_proc=0 && n=0); const int n0 = CCTK_FirstVarIndexI(group); assert (n0>=0); const int var = n - n0; assert (var>=0); // Get info about group cGroup gp; CCTK_GroupData (group, &gp); assert (gp.dim<=maxdim); assert (CCTK_QueryGroupStorageI(cgh, group)); const int typesize = CCTK_VarTypeSize(gp.vartype); assert (typesize>0); const int dim = gp.dim; // Check dimension assert (hdim>=0 && hdim<=gp.dim); // Check timelevel const int num_tl = gp.numtimelevels; assert (ti>=0 && ti=0 && origin[d]<=sizes[d]); // } // Check directions for (int dd=0; dd=1 && dirs[dd]<=dim); } // Check stride for (int dd=0; dd0); } // Check length for (int dd=0; dd=0); } // Check extent // for (int dd=0; ddcomponents(reflevel) > 0) { switch (CCTK_GroupDimI(group)) { #define CODE \ do { \ \ /* convert types */ \ const gh* myhh1 = dynamic_cast*>(myhh); \ const dh* mydd1 = dynamic_cast*>(mydd); \ const generic_gf* myff1 \ = dynamic_cast*>(myff); \ \ /* Only temporarily */ \ component = 0; \ \ /* Get sample data */ \ const generic_data* mydata; \ mydata = (*myff1)(tl, reflevel, component, mglevel); \ \ /* Stride of data in memory */ \ const vect str = mydata->extent().stride(); \ \ /* Stride of collected data */ \ vect hstr = str; \ for (int dd=0; dd hlb; \ for (int d=0; d hub = hlb; \ for (int dd=0; dd hextent (hlb, hub, hstr); \ assert (hextent.num_points() == totalsize); \ \ /* Create collector data object */ \ void* myhdata = rank==collect_proc ? hdata : 0; \ generic_data* const alldata = mydata->make_typed(); \ alldata->allocate (hextent, collect_proc, myhdata); \ \ /* Done with the temporary stuff */ \ mydata = 0; \ component = -1; \ \ /* Loop over all components, copying data from them */ \ assert (component == -1); \ for (component=0; \ componentcomponents(reflevel); \ ++component) { \ \ /* Get data object */ \ mydata = (*myff1)(tl, reflevel, component, mglevel); \ \ /* Calculate overlapping extents */ \ const bboxset myextents \ = ((mydd1->boxes[reflevel][component][mglevel].sync_not \ | mydd1->boxes[reflevel][component][mglevel].interior) \ & hextent); \ \ /* Loop over overlapping extents */ \ for (bboxset::const_iterator \ ext_iter = myextents.begin(); \ ext_iter != myextents.end(); \ ++ext_iter) { \ \ /* Copy data */ \ alldata->copy_from (mydata, *ext_iter); \ \ } \ \ } /* Loop over components */ \ component = -1; \ \ /* Copy result to all processors */ \ if (dest_proc == -1) { \ for (int proc=0; proc* const tmpdata = mydata->make_typed(); \ tmpdata->allocate (alldata->extent(), proc, myhdata); \ tmpdata->copy_from (alldata, alldata->extent()); \ delete tmpdata; \ \ } \ } \ } /* Copy result */ \ \ delete alldata; \ \ } while(0) case 1: { const int dim=1; CODE; break; } case 2: { const int dim=2; CODE; break; } case 3: { const int dim=3; CODE; break; } default: abort(); #undef CODE } // switch } // if components>0 // Restore global state component = saved_component; // Success return hdata; } int Hyperslab_GetHyperslab (cGH* const GH, const int target_proc, const int vindex, const int vtimelvl, const int hdim, const int global_startpoint [/*vdim*/], const int directions [/*vdim*/], const int lengths [/*hdim*/], const int downsample [/*hdim*/], void** const hdata, int hsize [/*hdim*/]) { const int dim = CCTK_GroupDimFromVarI(vindex); assert (dim>=1 && dim<=maxdim); // Check some arguments assert (hdim>=0 && hdim<=dim); // Check output arguments assert (hdata); assert (hsize); // Calculate more convenient representation of the direction int* const dirs = (int*)alloca(hdim * sizeof(int)); // The following if statement is written according to the // definition of "dir". if (hdim==1) { // 1-dimensional hyperslab int mydir = 0; for (int d=0; d0); for (int d=0; d0); for (int d=0; d=0); // Partial argument check assert (global_startpoint[dirs[dd]-1]>=0); assert (global_startpoint[dirs[dd]-1]<=totlen); assert (downsample[dd]>0); hsize[dd] = (totlen - global_startpoint[dirs[dd]-1]) / downsample[dd]; } else { hsize[dd] = lengths[dd]; } assert (hsize[dd]>=0); } // Get the slab *hdata = GetSlab (GH, target_proc, vindex, vtimelvl, hdim, global_startpoint, dirs, downsample, hsize); // Return with success return 1; } } // namespace CarpetSlab