void Elastic::FAC::pack_strain(double* buffer, const SAMRAI::hier::Patch& patch, const SAMRAI::hier::Box& region, const int &depth) const { boost::shared_ptr<SAMRAI::pdat::SideData<double> > v_ptr= boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (patch.getPatchData(v_id)); SAMRAI::pdat::SideData<double>& v = *v_ptr; boost::shared_ptr<SAMRAI::pdat::CellData<double> > dv_diagonal; boost::shared_ptr<SAMRAI::pdat::SideData<double> > dv_mixed; if(!faults.empty()) { dv_diagonal=boost::dynamic_pointer_cast<SAMRAI::pdat::CellData<double> > (patch.getPatchData(dv_diagonal_id)); dv_mixed=boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (patch.getPatchData(dv_mixed_id)); } const Gamra::Dir dim=d_dim.getValue(); if(have_embedded_boundary()) { boost::shared_ptr<SAMRAI::pdat::SideData<double> > level_set_ptr; if(have_embedded_boundary()) level_set_ptr=boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (patch.getPatchData(level_set_id)); } Gamra::Dir ix(Gamra::Dir::from_int(depth/dim)), iy(Gamra::Dir::from_int(depth%dim)); const SAMRAI::hier::Index zero(SAMRAI::hier::Index::getZeroIndex(d_dim)); SAMRAI::hier::Index ip(zero), jp(zero); ip[ix]=1; jp[iy]=1; const double *dx(boost::dynamic_pointer_cast <SAMRAI::geom::CartesianPatchGeometry> (patch.getPatchGeometry())->getDx()); SAMRAI::pdat::CellIterator iend(SAMRAI::pdat::CellGeometry::end(region)); for(SAMRAI::pdat::CellIterator icell(SAMRAI::pdat::CellGeometry::begin(region)); icell!=iend; ++icell) { const SAMRAI::pdat::SideIndex s(*icell,ix,SAMRAI::pdat::SideIndex::Lower); if(ix==iy) { double diff(v(s+ip)-v(s)); if(!faults.empty()) diff-=(*dv_diagonal)(*icell,ix); *buffer=diff/dx[ix]; } else { const int ix_iy(index_map(ix,iy,dim)); double diff(- v(s-jp) - v(s+ip-jp) + v(s+jp) + v(s+ip+jp)); if(!faults.empty()) diff+=(*dv_mixed)(s,ix_iy+1) - (*dv_mixed)(s-jp,ix_iy) + (*dv_mixed)(s+ip,ix_iy+1) - (*dv_mixed)(s+ip-jp,ix_iy) + (*dv_mixed)(s+jp,ix_iy+1) - (*dv_mixed)(s,ix_iy) + (*dv_mixed)(s+ip+jp,ix_iy+1) - (*dv_mixed)(s+ip,ix_iy); *buffer=diff/(4*dx[iy]); } ++buffer; } }
void Elastic::FAC::pack_v_v_rhs(double* buffer, const SAMRAI::hier::Patch& patch, const SAMRAI::hier::Box& region, const std::string& variable_name, const int &depth) const { boost::shared_ptr<SAMRAI::pdat::SideData<double> > v_ptr; if (variable_name == "Displacement") { v_ptr = boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (patch.getPatchData(v_id)); } else if ("Fault Correction + RHS" == variable_name) { v_ptr = boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (patch.getPatchData(v_rhs_id)); } else { TBOX_ERROR("Unregistered variable name '" << variable_name << "' in\n" << "Elastic::FAC::packDerivedDataIntoDoubleBuffer"); } SAMRAI::pdat::SideData<double>& v = *v_ptr; if(d_dim.getValue()==2) { const SAMRAI::hier::Index ip(1,0), jp(0,1); SAMRAI::pdat::CellIterator iend(SAMRAI::pdat::CellGeometry::end(region)); for (SAMRAI::pdat::CellIterator icell(SAMRAI::pdat::CellGeometry::begin(region)); icell!=iend; ++icell) { const SAMRAI::pdat::CellIndex ¢er(*icell); const SAMRAI::pdat::SideIndex x(center,0,SAMRAI::pdat::SideIndex::Lower), y(center,1,SAMRAI::pdat::SideIndex::Lower); double vx=v(x); double vy=v(y); if(!offset_vector_on_output) { vx=(v(x+ip) + vx)/2; vy=(v(y+jp) + vy)/2; } if (0==depth) { *buffer = vx; } else { *buffer = vy; } buffer = buffer + 1; } } else { const SAMRAI::hier::Index ip(1,0,0), jp(0,1,0), kp(0,0,1); SAMRAI::pdat::CellIterator iend(SAMRAI::pdat::CellGeometry::end(region)); for (SAMRAI::pdat::CellIterator icell(SAMRAI::pdat::CellGeometry::begin(region)); icell!=iend; ++icell) { const SAMRAI::pdat::CellIndex ¢er(*icell); const SAMRAI::pdat::SideIndex x(center,0,SAMRAI::pdat::SideIndex::Lower), y(center,1,SAMRAI::pdat::SideIndex::Lower), z(center,2,SAMRAI::pdat::SideIndex::Lower); double vx=v(x); double vy=v(y); double vz=v(z); if(!offset_vector_on_output) { vx=(v(x+ip) + vx)/2; vy=(v(y+jp) + vy)/2; vz=(v(z+kp) + vz)/2; } if (0==depth) { *buffer = vx; } else if (1==depth) { *buffer = vy; } else { *buffer = vz; } ++buffer; } } }
/* ************************************************************************ */ void init_cell(void){ /* ================================================================== */ /* Allocate memory for the cell neighbor list. */ /* ================================================================== */ clistn = (struct clistn_struct*) calloc(sim.NB,sizeof(struct clistn_struct)); if(clistn == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clistn\n"); exit(11);} head = (int**) calloc(sim.NB,sizeof(int*)); if(head == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for head\n"); exit(11);} clist = (int**) calloc(sim.NB,sizeof(int*)); if(clist == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clist\n"); exit(11);} cell_no = (int**) calloc(sim.NB,sizeof(int*)); if(cell_no == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for cell_no\n"); exit(11);} for(int k=0; k<sim.NB; k++){ cell_no[k] = (int*) calloc(box[k].boxns,sizeof(int)); if(cell_no[k] == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for cell_no[k]\n"); exit(11);} } for(int k=0; k<sim.NB; k++){ /* ================================================================== */ /* Determine the number of cell per side(M) so that the length of */ /* the cell is about CELL_LENGTH anstrom. Then, determine the */ /* total number of boxes, the number of shells of neighboring cells, */ /* and allocate the necessary memory. */ /* ================================================================== */ int Mx, My, Mz; Mx = (int)(box[k].lx/CELL_LENGTH_X); My = (int)(box[k].ly/CELL_LENGTH_Y); Mz = (int)(box[k].lz/CELL_LENGTH_Z); clistn[k].Mx = Mx; clistn[k].My = My; clistn[k].Mz = Mz; int ncell = Mx * My * Mz; clistn[k].ncell = ncell; double cell_lengthx = box[k].lx/(double)(Mx); double cell_lengthy = box[k].ly/(double)(My); double cell_lengthz = box[k].lz/(double)(Mz); double least_cell_length = cell_lengthx; if(least_cell_length > cell_lengthy) least_cell_length=cell_lengthy; if(least_cell_length > cell_lengthz) least_cell_length=cell_lengthz; /* ------------------------------------------------------------------ */ /* Determine the number of shells of boxes to go out to check for */ /* neighbors. */ /* ------------------------------------------------------------------ */ int nshellx, nshelly, nshellz; #ifdef EWALD double rc = sim.rclist_ew; #else double rc = sim.rclist; #endif if(cell_lengthx < rc){ nshellx = (int)(rc/cell_lengthx); double test = rc/cell_lengthx-(double)nshellx; if(test > 0.001) nshellx++; } else nshellx = 1; if(cell_lengthy < rc){ nshelly = (int)(rc/cell_lengthy); double test = rc/cell_lengthy-(double)nshelly; if(test > 0.001) nshelly++; } else nshelly = 1; if(cell_lengthz < rc){ nshellz = (int)(rc/cell_lengthz); double test = rc/cell_lengthz-(double)nshellz; if(test > 0.001) nshellz++; } else nshellz = 1; /* ================================================================== */ /* Allocate memory */ /* ================================================================== */ head[k] = (int*) calloc(ncell+MEXTRA,sizeof(int*)); if(head[k] == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for head[k]\n"); exit(11);} clist[k] = (int*) calloc(ncell+box[k].boxns+MEXTRA,sizeof(int*)); if(clist[k] == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clist[k]\n"); exit(11);} clistn[k].count = (int*) calloc(ncell+MEXTRA,sizeof(int)); if(clistn[k].count == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clistn[k].count\n"); exit(11);} clistn[k].list = (int**) calloc(ncell+MEXTRA,sizeof(int*)); if(clistn[k].list == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clistn[k].list\n"); exit(11);} /* ------------------------------------------------ */ /* Check to make sure the shell length is at least */ /* as large as the cut off for the neighborlist, */ /* but not too large to overcount. */ /* ------------------------------------------------ */ double shell_lengthx = (double)(nshellx)*cell_lengthx; if(cell_lengthx < rc){ if(shell_lengthx<rc){ printf("Problem, shell length x=%f is less than rcut=%f!!\n", shell_lengthx, rc); exit(840); } } double shell_lengthy = (double)(nshelly)*cell_lengthy; if(cell_lengthy < rc){ if(shell_lengthy<rc){ printf("Problem, shell length y=%f is less than rcut=%f!!\n", shell_lengthy, rc); exit(840); } } double shell_lengthz = (double)(nshellz)*cell_lengthz; if(cell_lengthz < rc){ if(shell_lengthz<rc){ printf("Problem, shell length z=%f is less than rcut=%f!!\n", shell_lengthz, rc); exit(840); } } if(nshellx+1 > Mx/2){ printf("Problem, you must make CELL_LENGTH_X (defines.h) smaller or you will overcount atoms!!\n"); exit(840); } if(nshelly+1 > My/2){ printf("Problem, you must make CELL_LENGTH_Y (defines.h) smaller or you will overcount atoms!!\n"); exit(840); } if(nshellz+1 > Mz/2){ printf("Problem, you must make CELL_LENGTH_Z (defines.h) smaller or you will overcount atoms!!\n"); exit(840); } /* ================================================================== */ /* Allocate the memory needed for the cell neighbor list. */ /* ================================================================== */ int size = (int)((2*nshellx+1)*(2*nshelly+1)*(2*nshellz+1)); if(size ==-1) size = 1; for(int i=0; i<ncell; i++){ clistn[k].list[i] = (int*)calloc(size,sizeof(int)); if(clistn[k].list[i] == NULL){ fprintf(stdout, "ERROR: cannot allocate memory for clistn[k].list[i]\n"); exit(11);} } /* ================================================================== */ /* Loop to determine the neighbors of each box. */ /* ================================================================== */ for(int iz=0; iz<Mz; iz++){ for(int iy=0; iy<My; iy++){ for(int ix=0; ix<Mx; ix++){ int cell = icell(ix,iy,iz,Mx,My,Mz); for(int dz=-nshellz; dz<=nshellz; dz++){ for(int dy=-nshelly; dy<=nshelly; dy++){ for(int dx=-nshellx; dx<=nshellx; dx++){ //if(abs(dx)+abs(dy)+abs(dz)!=0){ int cell_nabor = icell(ix+dx,iy+dy,iz+dz,Mx,My,Mz); //if(cell_nabor > cell){ clistn[k].list[cell][clistn[k].count[cell]]=cell_nabor; clistn[k].count[cell]++; //}//if(cell_nabor > cell) //}//if(dx*dy*dz!=0) } } } } } } }//for k }//end subroutine init_cell