From 298d4af50f5abcd3c0d1655349d960f87f54f658 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 27 Apr 2010 10:18:25 -0500 Subject: CarpetLib: Calculate mask and refluxing entries in dh classes --- Carpet/CarpetLib/src/dh.cc | 253 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) diff --git a/Carpet/CarpetLib/src/dh.cc b/Carpet/CarpetLib/src/dh.cc index 9b849485e..9679b3fd7 100644 --- a/Carpet/CarpetLib/src/dh.cc +++ b/Carpet/CarpetLib/src/dh.cc @@ -971,6 +971,259 @@ regrid (bool const do_init) + // Mask: + static Carpet::Timer timer_mask ("CarpetLib::dh::regrid::mask"); + timer_mask.start(); + + if (rl > 0) { + int const orl = rl - 1; + full_cboxes const& full_olevel = full_boxes.AT(ml).AT(orl); + // Local boxes are not communicated or post-processed, and + // thus can be modified even for coarser levels + local_cboxes& local_olevel = local_boxes.AT(ml).AT(orl); + + ivect const reffact = h.reffacts.AT(rl) / h.reffacts.AT(orl); + + // This works only when the refinement factor is 2 + if (all (reffact == 2)) { + + ibbox const& base = domain_exterior; + ibbox const& obase = h.baseextent(ml,orl); + + // Calculate the union of all coarse regions + ibset const allointr (full_olevel, & full_dboxes::interior); + + // Project to current level + ivect const rf(reffact); + // TODO: Why expand by rf-1? This expansion shouldn't + // matter, since the coarse grid is larger than the fine + // grid anyway, except at the outer boundary + // ibset const parent (allointr.expand(rf-1,rf-1).contracted_for(base)); + ibset const parent (allointr.expanded_for(base)); + + // Subtract the active region + ibset const notrefined = parent - allactive; + + // Enlarge this set + vect enlarged; + for (int d=0; d all_boundaries; + for (int d=0; d 0) { + int const orl = rl - 1; + full_cboxes const& full_olevel = full_boxes.AT(ml).AT(orl); + local_cboxes & local_olevel = local_boxes.AT(ml).AT(orl); + + // This works only with cell centred grids + if (h.refcent == cell_centered) { + + // Fine grids + ibset const& fine_level = allactive; + + ivect const izero = ivect (0); + ivect const ione = ivect (1); + + vect,dim> all_fine_boundary; + + for (int dir=0; direxpand (idir, izero); + } + + // Fine grids without boundary + ibset fine_level_minus; + for (ibset::const_iterator fine_level_i = fine_level.begin(); + fine_level_i != fine_level.end(); + ++ fine_level_i) + { + // Shrink region at the left boundary (but not at the + // right boundary), since the fluxes are staggered by + // one half to the right + fine_level_minus |= fine_level_i->expand (izero, -idir); + } + + // Fine boundary only + all_fine_boundary[dir][0] = fine_level_plus - fine_level ; + all_fine_boundary[dir][1] = fine_level - fine_level_minus; + } // for dir + + + + // Coarse grids + ibbox const& coarse_domain_exterior = h.baseextent(ml, orl); + ibbox const& coarse_ext = coarse_domain_exterior; + + // Coarse equivalent of fine boundary + vect,dim> all_coarse_boundary; + for (int dir=0; dir<3; ++dir) { + // Unit vector + ivect const idir = ivect::dir(dir); + for (int face=0; face<2; ++face) { + for (ibset::const_iterator + all_fine_boundary_i = all_fine_boundary[dir][face].begin(); + all_fine_boundary_i != all_fine_boundary[dir][face].end(); + ++ all_fine_boundary_i) + { + ibbox const& fb = *all_fine_boundary_i; + + ivect const cstr = coarse_ext.stride(); + + ivect const flo = fb.lower(); + ivect const fup = fb.upper(); + ivect const fstr = fb.stride(); + + assert (all (h.reffacts.AT(rl) % h.reffacts.AT(orl) == 0)); + ivect const reffact = h.reffacts.AT(rl) / h.reffacts.AT(orl); + assert (all (reffact % 2 == 0)); + assert (all (fstr % 2 == 0)); + assert (all (cstr % 2 == 0)); + + ibbox const ftmp (flo + idir*(fstr/2-cstr/2), + fup + idir*(fstr/2-cstr/2), + fstr); + ibbox const ctmp = ftmp.contracted_for (coarse_ext); + + ivect const clo = ctmp.lower(); + ivect const cup = ctmp.upper(); + ibbox const cb (clo, cup, cstr); + + all_coarse_boundary[dir][face] += cb; + } + } // for face + } // for dir + + + + for (int lc = 0; lc < h.local_components(rl); ++ lc) { + int const c = h.get_component(rl, lc); + full_dboxes & box = full_level.AT(c); + local_dboxes & local_box = local_level.AT(lc); + + for (int dir = 0; dir < dim; ++ dir) { + for (int face = 0; face < 2; ++ face) { + + // This is not really used (only for debugging) + local_box.fine_boundary[dir][face] = + box.exterior & all_fine_boundary[dir][face]; + + } // for face + } // for dir + + } // for lc + + for (int lc = 0; lc < h.local_components(orl); ++ lc) { + int const c = h.get_component(orl, lc); + full_dboxes const & obox = full_olevel.AT(c); + local_dboxes & local_obox = local_olevel.AT(lc); + + for (int dir = 0; dir < dim; ++ dir) { + for (int face = 0; face < 2; ++ face) { + +#warning "TODO: Set up communication schedule for refluxing" + + local_obox.coarse_boundary[dir][face] = + obox.exterior & all_coarse_boundary[dir][face]; + + } // for face + } // for dir + + } // for lc + + } // if cell centered + + } // if rl > 0 + + timer_reflux.stop(); + + + // Regridding schedule: fast_level.do_init = do_init; -- cgit v1.2.3