// 输出网格到 VTK 文件 void MeshOpt::writeToVTK(hier::Patch<NDIM>& patch, const double time, const double dt, const bool initial_time) { NULL_USE(dt); NULL_USE(time); NULL_USE(initial_time); const tbox::Pointer< hier::BlockPatchGeometry<NDIM> > pgeom = patch.getPatchGeometry(); int block_index = pgeom->getBlockNumber(); int patch_index = patch.getPatchNumber(); std::stringstream bi, pi, df; bi << block_index; pi << patch_index; df << d_flag; std::string file_name = df.str() + "_block_ " + bi.str()+ "_patch_" + pi.str() + ".vtk"; MsqError err; MeshImpl * mesh = createLocalMesh(patch); mesh->write_vtk(file_name.c_str(), err); return; }
void PoissonGaussianSolution::setGridData( hier::Patch& patch, pdat::CellData<double>& exact_data, pdat::CellData<double>& source_data) { boost::shared_ptr<geom::CartesianPatchGeometry> patch_geom( BOOST_CAST<geom::CartesianPatchGeometry, hier::PatchGeometry>( patch.getPatchGeometry())); TBOX_ASSERT(patch_geom); const double* h = patch_geom->getDx(); const double* xl = patch_geom->getXLower(); const int* il = &patch.getBox().lower()[0]; { /* Set cell-centered data. */ double sl[SAMRAI::MAX_DIM_VAL]; // Like XLower, except for cell. int j; for (j = 0; j < d_dim.getValue(); ++j) { sl[j] = xl[j] + 0.5 * h[j]; } pdat::CellData<double>::iterator iter(pdat::CellGeometry::begin(patch.getBox())); pdat::CellData<double>::iterator iterend(pdat::CellGeometry::end(patch.getBox())); if (d_dim == tbox::Dimension(2)) { double x, y; for ( ; iter != iterend; ++iter) { const pdat::CellIndex& index = *iter; x = sl[0] + (index[0] - il[0]) * h[0]; y = sl[1] + (index[1] - il[1]) * h[1]; exact_data(index) = exactFcn(x, y); source_data(index) = sourceFcn(x, y); } } else if (d_dim == tbox::Dimension(3)) { double x, y, z; for ( ; iter != iterend; ++iter) { const pdat::CellIndex& index = *iter; x = sl[0] + (index[0] - il[0]) * h[0]; y = sl[1] + (index[1] - il[1]) * h[1]; z = sl[2] + (index[2] - il[2]) * h[2]; exact_data(index) = exactFcn(x, y, z); source_data(index) = sourceFcn(x, y, z); } } } } // End patch loop.
void CommTester::putCoordinatesToDatabase( std::shared_ptr<tbox::Database>& coords_db, const hier::Patch& patch) { std::shared_ptr<geom::CartesianPatchGeometry> pgeom( SAMRAI_SHARED_PTR_CAST<geom::CartesianPatchGeometry, hier::PatchGeometry>( patch.getPatchGeometry())); /* if (pgeom) { pgeom->putBlueprintCoords(coords_db, patch.getBox()); } */ const tbox::Dimension& dim(patch.getDim()); pdat::NodeData<double> coords(patch.getBox(), dim.getValue(), hier::IntVector::getZero(dim)); const hier::Index& box_lo = patch.getBox().lower(); const double* x_lo = pgeom->getXLower(); const double* dx = pgeom->getDx(); pdat::NodeIterator nend = pdat::NodeGeometry::end(patch.getBox()); for (pdat::NodeIterator itr(pdat::NodeGeometry::begin(patch.getBox())); itr != nend; ++itr) { const pdat::NodeIndex& ni = *itr; for (int d = 0; d < dim.getValue(); ++d) { coords(ni, d) = x_lo[d] + (ni(d)-box_lo(d))*dx[d]; } } coords_db->putString("type", "explicit"); std::shared_ptr<tbox::Database> values_db = coords_db->putDatabase("values"); int data_size = coords.getArrayData().getBox().size(); values_db->putDoubleArray("x", coords.getPointer(0), data_size); if (dim.getValue() > 1) { values_db->putDoubleArray("y", coords.getPointer(1), data_size); } if (dim.getValue() > 2) { values_db->putDoubleArray("z", coords.getPointer(2), data_size); } }
void PoissonGaussianSolution::setBcCoefs( const boost::shared_ptr<pdat::ArrayData<double> >& acoef_data, const boost::shared_ptr<pdat::ArrayData<double> >& bcoef_data, const boost::shared_ptr<pdat::ArrayData<double> >& gcoef_data, const boost::shared_ptr<hier::Variable>& variable, const hier::Patch& patch, const hier::BoundaryBox& bdry_box, const double fill_time) const { NULL_USE(variable); NULL_USE(fill_time); boost::shared_ptr<geom::CartesianPatchGeometry> patch_geom( BOOST_CAST<geom::CartesianPatchGeometry, hier::PatchGeometry>( patch.getPatchGeometry())); TBOX_ASSERT(patch_geom); /* * Set to an inhomogeneous Dirichlet boundary condition. */ hier::Box patch_box(patch.getBox()); const double* xlo = patch_geom->getXLower(); const double* xup = patch_geom->getXUpper(); const double* dx = patch_geom->getDx(); if (bdry_box.getBoundaryType() != 1) { // Must be a face boundary. TBOX_ERROR("Bad boundary type in\n" << "PoissonGaussianSolution::setBcCoefs \n"); } const hier::Box& box = bdry_box.getBox(); hier::Index lower = box.lower(); hier::Index upper = box.upper(); if (d_dim == tbox::Dimension(2)) { double* a_array = acoef_data ? acoef_data->getPointer() : 0; double* b_array = bcoef_data ? bcoef_data->getPointer() : 0; double* g_array = gcoef_data ? gcoef_data->getPointer() : 0; int i, j, ibeg, iend, jbeg, jend; double x, y; switch (bdry_box.getLocationIndex()) { case 0: // min i edge jbeg = box.lower()[1]; jend = box.upper()[1]; x = xlo[0]; for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); if (a_array) a_array[j - jbeg] = 1.0; if (b_array) b_array[j - jbeg] = 0.0; if (g_array) g_array[j - jbeg] = exactFcn(x, y); } break; case 1: // max i edge jbeg = box.lower()[1]; jend = box.upper()[1]; x = xup[0]; for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); if (a_array) a_array[j - jbeg] = 1.0; if (b_array) b_array[j - jbeg] = 0.0; if (g_array) g_array[j - jbeg] = exactFcn(x, y); } break; case 2: // min j edge ibeg = box.lower()[0]; iend = box.upper()[0]; y = xlo[1]; for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array[i - ibeg] = 1.0; if (b_array) b_array[i - ibeg] = 0.0; if (g_array) g_array[i - ibeg] = exactFcn(x, y); } break; case 3: // max j edge ibeg = box.lower()[0]; iend = box.upper()[0]; y = xup[1]; for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array[i - ibeg] = 1.0; if (b_array) b_array[i - ibeg] = 0.0; if (g_array) g_array[i - ibeg] = exactFcn(x, y); } break; default: TBOX_ERROR("Invalid location index in\n" << "PoissonGaussianSolution::setBcCoefs"); } } if (d_dim == tbox::Dimension(3)) { MDA_Access<double, 3, MDA_OrderColMajor<3> > a_array, b_array, g_array; if (acoef_data) a_array = pdat::ArrayDataAccess::access<3, double>( *acoef_data); if (bcoef_data) b_array = pdat::ArrayDataAccess::access<3, double>( *bcoef_data); if (gcoef_data) g_array = pdat::ArrayDataAccess::access<3, double>( *gcoef_data); int i, j, k, ibeg, iend, jbeg, jend, kbeg, kend; double x, y, z; switch (bdry_box.getLocationIndex()) { case 0: // min i side jbeg = box.lower()[1]; jend = box.upper()[1]; kbeg = box.lower()[2]; kend = box.upper()[2]; i = box.lower()[0] + 1; x = xlo[0]; for (k = kbeg; k <= kend; ++k) { z = xlo[2] + dx[2] * (k - patch_box.lower()[2] + 0.5); for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; case 1: // max i side jbeg = box.lower()[1]; jend = box.upper()[1]; kbeg = box.lower()[2]; kend = box.upper()[2]; i = box.upper()[0]; x = xup[0]; for (k = kbeg; k <= kend; ++k) { z = xlo[2] + dx[2] * (k - patch_box.lower()[2] + 0.5); for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; case 2: // min j side ibeg = box.lower()[0]; iend = box.upper()[0]; kbeg = box.lower()[2]; kend = box.upper()[2]; j = box.lower()[1] + 1; y = xlo[1]; for (k = kbeg; k <= kend; ++k) { z = xlo[2] + dx[2] * (k - patch_box.lower()[2] + 0.5); for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; case 3: // max j side ibeg = box.lower()[0]; iend = box.upper()[0]; kbeg = box.lower()[2]; kend = box.upper()[2]; j = box.upper()[1]; y = xup[1]; for (k = kbeg; k <= kend; ++k) { z = xlo[2] + dx[2] * (k - patch_box.lower()[2] + 0.5); for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; case 4: // min k side ibeg = box.lower()[0]; iend = box.upper()[0]; jbeg = box.lower()[1]; jend = box.upper()[1]; k = box.lower()[2] + 1; z = xlo[2]; for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; case 5: // max k side ibeg = box.lower()[0]; iend = box.upper()[0]; jbeg = box.lower()[1]; jend = box.upper()[1]; k = box.upper()[2]; z = xup[2]; for (j = jbeg; j <= jend; ++j) { y = xlo[1] + dx[1] * (j - patch_box.lower()[1] + 0.5); for (i = ibeg; i <= iend; ++i) { x = xlo[0] + dx[0] * (i - patch_box.lower()[0] + 0.5); if (a_array) a_array(i, j, k) = 1.0; if (b_array) b_array(i, j, k) = 0.0; if (g_array) g_array(i, j, k) = exactFcn(x, y, z); } } break; default: TBOX_ERROR("Invalid location index in\n" << "PoissonGaussianSolution::setBcCoefs"); } } }
/* ************************************************************************* * * Verify results of communication operations. This test must be * consistent with data initialization and boundary operations above. * ************************************************************************* */ bool EdgeMultiblockTest::verifyResults( const hier::Patch& patch, const std::shared_ptr<hier::PatchHierarchy> hierarchy, const int level_number, const hier::BlockId& block_id) { tbox::plog << "\nEntering EdgeMultiblockTest::verifyResults..." << endl; tbox::plog << "level_number = " << level_number << endl; tbox::plog << "Patch box = " << patch.getBox() << endl; hier::IntVector tgcw(d_dim, 0); for (int i = 0; i < static_cast<int>(d_variables.size()); ++i) { tgcw.max(patch.getPatchData(d_variables[i], getDataContext())-> getGhostCellWidth()); } hier::Box pbox = patch.getBox(); std::shared_ptr<pdat::EdgeData<double> > solution( new pdat::EdgeData<double>(pbox, 1, tgcw)); hier::Box tbox(pbox); tbox.grow(tgcw); std::shared_ptr<hier::BaseGridGeometry> grid_geom( hierarchy->getGridGeometry()); hier::BoxContainer singularity( grid_geom->getSingularityBoxContainer(block_id)); hier::IntVector ratio = hierarchy->getPatchLevel(level_number)->getRatioToLevelZero(); singularity.refine(ratio); bool test_failed = false; for (int i = 0; i < static_cast<int>(d_variables.size()); ++i) { double correct = (double)block_id.getBlockValue(); std::shared_ptr<pdat::EdgeData<double> > edge_data( SAMRAI_SHARED_PTR_CAST<pdat::EdgeData<double>, hier::PatchData>( patch.getPatchData(d_variables[i], getDataContext()))); TBOX_ASSERT(edge_data); int depth = edge_data->getDepth(); hier::Box interior_box(pbox); interior_box.grow(hier::IntVector(d_dim, -1)); for (int axis = 0; axis < d_dim.getValue(); ++axis) { pdat::EdgeIterator ciend(pdat::EdgeGeometry::end(interior_box, axis)); for (pdat::EdgeIterator ci(pdat::EdgeGeometry::begin(interior_box, axis)); ci != ciend; ++ci) { for (int d = 0; d < depth; ++d) { double result = (*edge_data)(*ci, d); if (!tbox::MathUtilities<double>::equalEps(correct, result)) { tbox::perr << "Test FAILED: ...." << " : edge index = " << *ci << endl; tbox::perr << " Variable = " << d_variable_src_name[i] << " : depth index = " << d << endl; tbox::perr << " result = " << result << " : correct = " << correct << endl; test_failed = true; } } } } hier::Box gbox = edge_data->getGhostBox(); for (int axis = 0; axis < d_dim.getValue(); ++axis) { hier::Box patch_edge_box = pdat::EdgeGeometry::toEdgeBox(pbox, axis); hier::BoxContainer tested_neighbors; hier::BoxContainer sing_edge_boxlist; for (hier::BoxContainer::iterator si = singularity.begin(); si != singularity.end(); ++si) { sing_edge_boxlist.pushFront( pdat::EdgeGeometry::toEdgeBox(*si, axis)); } for (hier::BaseGridGeometry::ConstNeighborIterator ne( grid_geom->begin(block_id)); ne != grid_geom->end(block_id); ++ne) { const hier::BaseGridGeometry::Neighbor& nbr = *ne; if (nbr.isSingularity()) { continue; } correct = nbr.getBlockId().getBlockValue(); hier::BoxContainer neighbor_ghost(nbr.getTransformedDomain()); hier::BoxContainer neighbor_edge_ghost; for (hier::BoxContainer::iterator nn = neighbor_ghost.begin(); nn != neighbor_ghost.end(); ++nn) { hier::Box neighbor_ghost_interior( pdat::EdgeGeometry::toEdgeBox(*nn, axis)); neighbor_ghost_interior.grow(-hier::IntVector::getOne(d_dim)); neighbor_edge_ghost.pushFront(neighbor_ghost_interior); } neighbor_edge_ghost.refine(ratio); neighbor_edge_ghost.intersectBoxes( pdat::EdgeGeometry::toEdgeBox(gbox, axis)); neighbor_edge_ghost.removeIntersections(sing_edge_boxlist); neighbor_edge_ghost.removeIntersections(tested_neighbors); for (hier::BoxContainer::iterator ng = neighbor_edge_ghost.begin(); ng != neighbor_edge_ghost.end(); ++ng) { hier::Box::iterator ciend(ng->end()); for (hier::Box::iterator ci(ng->begin()); ci != ciend; ++ci) { pdat::EdgeIndex ei(*ci, 0, 0); ei.setAxis(axis); if (!patch_edge_box.contains(ei)) { for (int d = 0; d < depth; ++d) { double result = (*edge_data)(ei, d); if (!tbox::MathUtilities<double>::equalEps(correct, result)) { tbox::perr << "Test FAILED: ...." << " : edge index = " << ei << endl; tbox::perr << " Variable = " << d_variable_src_name[i] << " : depth index = " << d << endl; tbox::perr << " result = " << result << " : correct = " << correct << endl; test_failed = true; } } } } } tested_neighbors.spliceBack(neighbor_edge_ghost); } } std::shared_ptr<hier::PatchGeometry> pgeom(patch.getPatchGeometry()); for (int b = 0; b < d_dim.getValue(); ++b) { const std::vector<hier::BoundaryBox>& bdry = pgeom->getCodimensionBoundaries(b + 1); for (int k = 0; k < static_cast<int>(bdry.size()); ++k) { hier::Box fill_box = pgeom->getBoundaryFillBox(bdry[k], patch.getBox(), tgcw); fill_box = fill_box * gbox; if (bdry[k].getIsMultiblockSingularity()) { correct = 0.0; int num_sing_neighbors = 0; for (hier::BaseGridGeometry::ConstNeighborIterator ns( grid_geom->begin(block_id)); ns != grid_geom->end(block_id); ++ns) { const hier::BaseGridGeometry::Neighbor& nbr = *ns; if (nbr.isSingularity()) { hier::BoxContainer neighbor_ghost( nbr.getTransformedDomain()); neighbor_ghost.refine(ratio); neighbor_ghost.intersectBoxes(fill_box); if (neighbor_ghost.size()) { ++num_sing_neighbors; correct += nbr.getBlockId().getBlockValue(); } } } if (num_sing_neighbors == 0) { correct = (double)bdry[k].getLocationIndex() + 200.0; } else { correct /= (double)num_sing_neighbors; } } else { correct = (double)(bdry[k].getLocationIndex() + 100); } for (int axis = 0; axis < d_dim.getValue(); ++axis) { hier::Box patch_edge_box = pdat::EdgeGeometry::toEdgeBox(pbox, axis); pdat::EdgeIterator ciend(pdat::EdgeGeometry::end(fill_box, axis)); for (pdat::EdgeIterator ci(pdat::EdgeGeometry::begin(fill_box, axis)); ci != ciend; ++ci) { if (!patch_edge_box.contains(*ci)) { bool use_index = true; for (tbox::Dimension::dir_t n = 0; n < d_dim.getValue(); ++n) { if (axis != n && bdry[k].getBox().numberCells(n) == 1) { if ((*ci)(n) == patch_edge_box.lower() (n) || (*ci)(n) == patch_edge_box.upper() (n)) { use_index = false; break; } } } if (use_index) { for (int d = 0; d < depth; ++d) { double result = (*edge_data)(*ci, d); if (!tbox::MathUtilities<double>::equalEps(correct, result)) { tbox::perr << "Test FAILED: ...." << " : edge index = " << *ci << endl; tbox::perr << " Variable = " << d_variable_src_name[i] << " : depth index = " << d << endl; tbox::perr << " result = " << result << " : correct = " << correct << endl; test_failed = true; } } } } } } } } } if (!test_failed) { tbox::plog << "EdgeMultiblockTest Successful!" << endl; } else { tbox::perr << "Multiblock EdgeMultiblockTest FAILED: \n" << endl; } solution.reset(); // just to be anal... tbox::plog << "\nExiting EdgeMultiblockTest::verifyResults..." << endl; tbox::plog << "level_number = " << level_number << endl; tbox::plog << "Patch box = " << patch.getBox() << endl << endl; return !test_failed; }
void EdgeMultiblockTest::setPhysicalBoundaryConditions( hier::Patch& patch, const double time, const hier::IntVector& gcw_to_fill) const { NULL_USE(time); std::shared_ptr<hier::PatchGeometry> pgeom(patch.getPatchGeometry()); const std::vector<hier::BoundaryBox>& node_bdry = pgeom->getCodimensionBoundaries(d_dim.getValue()); const int num_node_bdry_boxes = static_cast<int>(node_bdry.size()); std::vector<hier::BoundaryBox> empty_vector(0, hier::BoundaryBox(d_dim)); const std::vector<hier::BoundaryBox>& edge_bdry = d_dim > tbox::Dimension(1) ? pgeom->getCodimensionBoundaries(d_dim.getValue() - 1) : empty_vector; const int num_edge_bdry_boxes = static_cast<int>(edge_bdry.size()); const std::vector<hier::BoundaryBox>& face_bdry = d_dim == tbox::Dimension(3) ? pgeom->getCodimensionBoundaries(d_dim.getValue() - 2) : empty_vector; const int num_face_bdry_boxes = static_cast<int>(face_bdry.size()); for (int i = 0; i < static_cast<int>(d_variables.size()); ++i) { std::shared_ptr<pdat::EdgeData<double> > edge_data( SAMRAI_SHARED_PTR_CAST<pdat::EdgeData<double>, hier::PatchData>( patch.getPatchData(d_variables[i], getDataContext()))); TBOX_ASSERT(edge_data); /* * Set node boundary data. */ for (int nb = 0; nb < num_node_bdry_boxes; ++nb) { hier::Box fill_box = pgeom->getBoundaryFillBox(node_bdry[nb], patch.getBox(), gcw_to_fill); for (int axis = 0; axis < d_dim.getValue(); ++axis) { hier::Box patch_edge_box = pdat::EdgeGeometry::toEdgeBox(patch.getBox(), axis); if (!node_bdry[nb].getIsMultiblockSingularity()) { pdat::EdgeIterator niend(pdat::EdgeGeometry::end(fill_box, axis)); for (pdat::EdgeIterator ni(pdat::EdgeGeometry::begin(fill_box, axis)); ni != niend; ++ni) { if (!patch_edge_box.contains(*ni)) { for (int d = 0; d < edge_data->getDepth(); ++d) { (*edge_data)(*ni, d) = (double)(node_bdry[nb].getLocationIndex() + 100); } } } } } } if (d_dim > tbox::Dimension(1)) { /* * Set edge boundary data. */ for (int eb = 0; eb < num_edge_bdry_boxes; ++eb) { hier::Box fill_box = pgeom->getBoundaryFillBox(edge_bdry[eb], patch.getBox(), gcw_to_fill); for (int axis = 0; axis < d_dim.getValue(); ++axis) { hier::Box patch_edge_box = pdat::EdgeGeometry::toEdgeBox(patch.getBox(), axis); hier::Index plower(patch_edge_box.lower()); hier::Index pupper(patch_edge_box.upper()); if (!edge_bdry[eb].getIsMultiblockSingularity()) { pdat::EdgeIterator niend(pdat::EdgeGeometry::end(fill_box, axis)); for (pdat::EdgeIterator ni(pdat::EdgeGeometry::begin(fill_box, axis)); ni != niend; ++ni) { if (!patch_edge_box.contains(*ni)) { bool use_index = true; for (tbox::Dimension::dir_t n = 0; n < d_dim.getValue(); ++n) { if (axis != n && edge_bdry[eb].getBox().numberCells(n) == 1) { if ((*ni)(n) == plower(n) || (*ni)(n) == pupper(n)) { use_index = false; break; } } } if (use_index) { for (int d = 0; d < edge_data->getDepth(); ++d) { (*edge_data)(*ni, d) = (double)(edge_bdry[eb].getLocationIndex() + 100); } } } } } } } } if (d_dim == tbox::Dimension(3)) { /* * Set face boundary data. */ for (int fb = 0; fb < num_face_bdry_boxes; ++fb) { hier::Box fill_box = pgeom->getBoundaryFillBox(face_bdry[fb], patch.getBox(), gcw_to_fill); for (int axis = 0; axis < d_dim.getValue(); ++axis) { hier::Box patch_edge_box = pdat::EdgeGeometry::toEdgeBox(patch.getBox(), axis); hier::Index plower(patch_edge_box.lower()); hier::Index pupper(patch_edge_box.upper()); if (!face_bdry[fb].getIsMultiblockSingularity()) { pdat::EdgeIterator niend(pdat::EdgeGeometry::end(fill_box, axis)); for (pdat::EdgeIterator ni(pdat::EdgeGeometry::begin(fill_box, axis)); ni != niend; ++ni) { if (!patch_edge_box.contains(*ni)) { bool use_index = true; for (tbox::Dimension::dir_t n = 0; n < d_dim.getValue(); ++n) { if (axis != n && face_bdry[fb].getBox().numberCells(n) == 1) { if ((*ni)(n) == plower(n) || (*ni)(n) == pupper(n)) { use_index = false; break; } } } if (use_index) { (*edge_data)(*ni) = (double)(face_bdry[fb].getLocationIndex() + 100); } } } } } } } } }
void BoundaryDataTester::checkBoundaryData( int btype, const hier::Patch& patch, const hier::IntVector& ghost_width_to_check) { #ifdef DEBUG_CHECK_ASSERTIONS if (d_dim == tbox::Dimension(2)) { TBOX_ASSERT(btype == Bdry::EDGE2D || btype == Bdry::NODE2D); } if (d_dim == tbox::Dimension(3)) { TBOX_ASSERT(btype == Bdry::FACE3D || btype == Bdry::EDGE3D || btype == Bdry::NODE3D); } #endif const std::shared_ptr<geom::CartesianPatchGeometry> pgeom( SAMRAI_SHARED_PTR_CAST<geom::CartesianPatchGeometry, hier::PatchGeometry>( patch.getPatchGeometry())); TBOX_ASSERT(pgeom); const std::vector<hier::BoundaryBox>& bdry_boxes = pgeom->getCodimensionBoundaries(btype); for (int i = 0; i < static_cast<int>(bdry_boxes.size()); ++i) { hier::BoundaryBox bbox = bdry_boxes[i]; TBOX_ASSERT(bbox.getBoundaryType() == btype); int bloc = bbox.getLocationIndex(); for (int iv = 0; iv < static_cast<int>(d_variables.size()); ++iv) { std::shared_ptr<pdat::CellData<double> > cvdata( SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>( patch.getPatchData(d_variables[iv], d_variable_context))); TBOX_ASSERT(cvdata); int depth = d_variable_depth[iv]; int bscalarcase = 0; int bvectorcase = 0; int refbdryloc = 0; if (d_dim == tbox::Dimension(2)) { if (btype == Bdry::EDGE2D) { bscalarcase = d_scalar_bdry_edge_conds[bloc]; bvectorcase = d_vector_bdry_edge_conds[bloc]; refbdryloc = bloc; } else { // btype == Bdry::NODE2D bscalarcase = d_scalar_bdry_node_conds[bloc]; bvectorcase = d_vector_bdry_node_conds[bloc]; refbdryloc = d_node_bdry_edge[bloc]; } } if (d_dim == tbox::Dimension(3)) { if (btype == Bdry::FACE3D) { bscalarcase = d_scalar_bdry_face_conds[bloc]; bvectorcase = d_vector_bdry_face_conds[bloc]; refbdryloc = bloc; } else if (btype == Bdry::EDGE3D) { bscalarcase = d_scalar_bdry_edge_conds[bloc]; bvectorcase = d_vector_bdry_edge_conds[bloc]; refbdryloc = d_edge_bdry_face[bloc]; } else { // btype == Bdry::NODE3D bscalarcase = d_scalar_bdry_node_conds[bloc]; bvectorcase = d_vector_bdry_node_conds[bloc]; refbdryloc = d_node_bdry_face[bloc]; } } int data_id = hier::VariableDatabase::getDatabase()-> mapVariableAndContextToIndex(d_variables[iv], d_variable_context); int num_bad_values = 0; if (depth == 1) { if (d_dim == tbox::Dimension(2)) { num_bad_values = appu::CartesianBoundaryUtilities2:: checkBdryData(d_variable_name[iv], patch, data_id, 0, ghost_width_to_check, bbox, bscalarcase, d_variable_bc_values[iv][refbdryloc]); } if (d_dim == tbox::Dimension(3)) { num_bad_values = appu::CartesianBoundaryUtilities3:: checkBdryData(d_variable_name[iv], patch, data_id, 0, ghost_width_to_check, bbox, bscalarcase, d_variable_bc_values[iv][refbdryloc]); } #if (TESTING == 1) if (num_bad_values > 0) { ++d_fail_count; tbox::perr << "\nBoundary Test FAILED: \n" << " " << num_bad_values << " bad " << d_variable_name[iv] << " values found for" << " boundary type " << btype << " at location " << bloc << endl; } #endif } else { for (int id = 0; id < depth; ++id) { int vbcase = bscalarcase; if (d_dim == tbox::Dimension(2)) { if (btype == Bdry::EDGE2D) { if ((id == 0 && (bloc == BdryLoc::XLO || bloc == BdryLoc::XHI)) || (id == 1 && (bloc == BdryLoc::YLO || bloc == BdryLoc::YHI))) { vbcase = bvectorcase; } } else { if ((id == 0 && bvectorcase == BdryCond::XREFLECT) || (id == 1 && bvectorcase == BdryCond::YREFLECT)) { vbcase = bvectorcase; } } } if (d_dim == tbox::Dimension(3)) { if (btype == Bdry::FACE3D) { if ((id == 0 && (bloc == BdryLoc::XLO || bloc == BdryLoc::XHI)) || (id == 1 && (bloc == BdryLoc::YLO || bloc == BdryLoc::YHI)) || (id == 2 && (bloc == BdryLoc::ZLO || bloc == BdryLoc::ZHI))) { vbcase = bvectorcase; } } else { if ((id == 0 && bvectorcase == BdryCond::XREFLECT) || (id == 1 && bvectorcase == BdryCond::YREFLECT) || (id == 2 && bvectorcase == BdryCond::ZREFLECT)) { vbcase = bvectorcase; } } } if (d_dim == tbox::Dimension(2)) { num_bad_values = appu::CartesianBoundaryUtilities2:: checkBdryData(d_variable_name[iv], patch, data_id, id, ghost_width_to_check, bbox, vbcase, d_variable_bc_values[iv][refbdryloc * depth + id]); } if (d_dim == tbox::Dimension(3)) { num_bad_values = appu::CartesianBoundaryUtilities3:: checkBdryData(d_variable_name[iv], patch, data_id, id, ghost_width_to_check, bbox, vbcase, d_variable_bc_values[iv][refbdryloc * depth + id]); } #if (TESTING == 1) if (num_bad_values > 0) { ++d_fail_count; tbox::perr << "\nBoundary Test FAILED: \n" << " " << num_bad_values << " bad " << d_variable_name[iv] << " values found for" << " boundary type " << btype << " at location " << bloc << endl; } #endif } // for (int id = 0; id < depth; ++id) } // else } // for (int iv = 0; iv < static_cast<int>(d_variables.size()); ++iv) } // for (int i = 0; i < static_cast<int>(bdry_boxes.size()); ++i ) }
void CartesianCellDoubleConservativeLinearRefine::refine( hier::Patch& fine, const hier::Patch& coarse, const int dst_component, const int src_component, const hier::Box& fine_box, const hier::IntVector& ratio) const { const tbox::Dimension& dim(fine.getDim()); TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, fine_box, ratio); std::shared_ptr<pdat::CellData<double> > cdata( SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>( coarse.getPatchData(src_component))); std::shared_ptr<pdat::CellData<double> > fdata( SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>( fine.getPatchData(dst_component))); TBOX_ASSERT(cdata); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::Box cgbox(cdata->getGhostBox()); const hier::Index& cilo = cgbox.lower(); const hier::Index& cihi = cgbox.upper(); const hier::Index& filo = fdata->getGhostBox().lower(); const hier::Index& fihi = fdata->getGhostBox().upper(); const std::shared_ptr<CartesianPatchGeometry> cgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( coarse.getPatchGeometry())); const std::shared_ptr<CartesianPatchGeometry> fgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( fine.getPatchGeometry())); TBOX_ASSERT(cgeom); TBOX_ASSERT(fgeom); const hier::Box coarse_box = hier::Box::coarsen(fine_box, ratio); const hier::Index& ifirstc = coarse_box.lower(); const hier::Index& ilastc = coarse_box.upper(); const hier::Index& ifirstf = fine_box.lower(); const hier::Index& ilastf = fine_box.upper(); const hier::IntVector tmp_ghosts(dim, 0); std::vector<double> diff0(cgbox.numberCells(0) + 1); pdat::CellData<double> slope0(cgbox, 1, tmp_ghosts); for (int d = 0; d < fdata->getDepth(); ++d) { if ((dim == tbox::Dimension(1))) { SAMRAI_F77_FUNC(cartclinrefcelldoub1d, CARTCLINREFCELLDOUB1D) (ifirstc(0), ilastc(0), ifirstf(0), ilastf(0), cilo(0), cihi(0), filo(0), fihi(0), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d), &diff0[0], slope0.getPointer()); } else if ((dim == tbox::Dimension(2))) { std::vector<double> diff1(cgbox.numberCells(1) + 1); pdat::CellData<double> slope1(cgbox, 1, tmp_ghosts); SAMRAI_F77_FUNC(cartclinrefcelldoub2d, CARTCLINREFCELLDOUB2D) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), ifirstf(0), ifirstf(1), ilastf(0), ilastf(1), cilo(0), cilo(1), cihi(0), cihi(1), filo(0), filo(1), fihi(0), fihi(1), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d), &diff0[0], slope0.getPointer(), &diff1[0], slope1.getPointer()); } else if ((dim == tbox::Dimension(3))) { std::vector<double> diff1(cgbox.numberCells(1) + 1); pdat::CellData<double> slope1(cgbox, 1, tmp_ghosts); std::vector<double> diff2(cgbox.numberCells(2) + 1); pdat::CellData<double> slope2(cgbox, 1, tmp_ghosts); SAMRAI_F77_FUNC(cartclinrefcelldoub3d, CARTCLINREFCELLDOUB3D) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), ifirstf(0), ifirstf(1), ifirstf(2), ilastf(0), ilastf(1), ilastf(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d), &diff0[0], slope0.getPointer(), &diff1[0], slope1.getPointer(), &diff2[0], slope2.getPointer()); } else { TBOX_ERROR("CartesianCellDoubleConservativeLinearRefine error...\n" << "dim > 3 not supported." << std::endl); } } }
void SkeletonOutersideDoubleWeightedAverage::coarsen( hier::Patch& coarse, const hier::Patch& fine, const int dst_component, const int src_component, const hier::Box& coarse_box, const hier::IntVector& ratio) const { boost::shared_ptr<pdat::OuterfaceData<double> > fdata( BOOST_CAST<pdat::OuterfaceData<double>, hier::PatchData>( fine.getPatchData(src_component))); boost::shared_ptr<pdat::OuterfaceData<double> > cdata( BOOST_CAST<pdat::OuterfaceData<double>, hier::PatchData>( coarse.getPatchData(dst_component))); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::Index filo = fdata->getGhostBox().lower(); const hier::Index fihi = fdata->getGhostBox().upper(); const hier::Index cilo = cdata->getGhostBox().lower(); const hier::Index cihi = cdata->getGhostBox().upper(); const boost::shared_ptr<hier::PatchGeometry> fgeom( fine.getPatchGeometry()); const boost::shared_ptr<hier::PatchGeometry> cgeom( coarse.getPatchGeometry()); const hier::Index ifirstc = coarse_box.lower(); const hier::Index ilastc = coarse_box.upper(); int flev_num = fine.getPatchLevelNumber(); int clev_num = coarse.getPatchLevelNumber(); // deal with levels not in hierarchy if (flev_num < 0) flev_num = clev_num + 1; if (clev_num < 0) clev_num = flev_num - 1; double cdx[SAMRAI::MAX_DIM_VAL]; double fdx[SAMRAI::MAX_DIM_VAL]; getDx(clev_num, cdx); getDx(flev_num, fdx); for (int d = 0; d < cdata->getDepth(); ++d) { // loop over lower and upper outerside arrays for (int i = 0; i < 2; ++i) { if (d_dim == tbox::Dimension(1)) { SAMRAI_F77_FUNC(cartwgtavgoutfacedoub1d, CARTWGTAVGOUTFACEDOUB1D) ( ifirstc(0), ilastc(0), filo(0), fihi(0), cilo(0), cihi(0), &ratio[0], fdx, cdx, fdata->getPointer(0, i, d), cdata->getPointer(0, i, d)); } else if (d_dim == tbox::Dimension(2)) { SAMRAI_F77_FUNC(cartwgtavgoutfacedoub2d0, CARTWGTAVGOUTFACEDOUB2D0) ( ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fdx, cdx, fdata->getPointer(0, i, d), cdata->getPointer(0, i, d)); SAMRAI_F77_FUNC(cartwgtavgoutfacedoub2d1, CARTWGTAVGOUTFACEDOUB2D1) ( ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fdx, cdx, fdata->getPointer(1, i, d), cdata->getPointer(1, i, d)); } else if (d_dim == tbox::Dimension(3)) { SAMRAI_F77_FUNC(cartwgtavgoutfacedoub3d0, CARTWGTAVGOUTFACEDOUB3D0) ( ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fdx, cdx, fdata->getPointer(0, i, d), cdata->getPointer(0, i, d)); SAMRAI_F77_FUNC(cartwgtavgoutfacedoub3d1, CARTWGTAVGOUTFACEDOUB3D1) ( ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fdx, cdx, fdata->getPointer(1, i, d), cdata->getPointer(1, i, d)); SAMRAI_F77_FUNC(cartwgtavgoutfacedoub3d2, CARTWGTAVGOUTFACEDOUB3D2) ( ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fdx, cdx, fdata->getPointer(2, i, d), cdata->getPointer(2, i, d)); } else { TBOX_ERROR("SkeletonOutersideDoubleWeightedAverage error...\n" << "d_dim > 3 not supported." << endl); } } } }
void CartesianFaceDoubleWeightedAverage::coarsen( hier::Patch& coarse, const hier::Patch& fine, const int dst_component, const int src_component, const hier::Box& coarse_box, const hier::IntVector& ratio) const { const tbox::Dimension& dim(fine.getDim()); TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, coarse_box, ratio); std::shared_ptr<pdat::FaceData<double> > fdata( SAMRAI_SHARED_PTR_CAST<pdat::FaceData<double>, hier::PatchData>( fine.getPatchData(src_component))); std::shared_ptr<pdat::FaceData<double> > cdata( SAMRAI_SHARED_PTR_CAST<pdat::FaceData<double>, hier::PatchData>( coarse.getPatchData(dst_component))); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::Index& filo = fdata->getGhostBox().lower(); const hier::Index& fihi = fdata->getGhostBox().upper(); const hier::Index& cilo = cdata->getGhostBox().lower(); const hier::Index& cihi = cdata->getGhostBox().upper(); const std::shared_ptr<CartesianPatchGeometry> fgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( fine.getPatchGeometry())); const std::shared_ptr<CartesianPatchGeometry> cgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( coarse.getPatchGeometry())); TBOX_ASSERT(fgeom); TBOX_ASSERT(cgeom); const hier::Index& ifirstc = coarse_box.lower(); const hier::Index& ilastc = coarse_box.upper(); for (int d = 0; d < cdata->getDepth(); ++d) { if ((dim == tbox::Dimension(1))) { SAMRAI_F77_FUNC(cartwgtavgfacedoub1d, CARTWGTAVGFACEDOUB1D) (ifirstc(0), ilastc(0), filo(0), fihi(0), cilo(0), cihi(0), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } else if ((dim == tbox::Dimension(2))) { SAMRAI_F77_FUNC(cartwgtavgfacedoub2d0, CARTWGTAVGFACEDOUB2D0) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub2d1, CARTWGTAVGFACEDOUB2D1) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); } else if ((dim == tbox::Dimension(3))) { SAMRAI_F77_FUNC(cartwgtavgfacedoub3d0, CARTWGTAVGFACEDOUB3D0) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub3d1, CARTWGTAVGFACEDOUB3D1) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub3d2, CARTWGTAVGFACEDOUB3D2) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(2, d), cdata->getPointer(2, d)); } else if ((dim == tbox::Dimension(4))) { SAMRAI_F77_FUNC(cartwgtavgfacedoub4d0, CARTWGTAVGFACEDOUB4D0) (ifirstc(0), ifirstc(1), ifirstc(2), ifirstc(3), ilastc(0), ilastc(1), ilastc(2), ilastc(3), filo(0), filo(1), filo(2), filo(3), fihi(0), fihi(1), fihi(2), fihi(3), cilo(0), cilo(1), cilo(2), cilo(3), cihi(0), cihi(1), cihi(2), cihi(3), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub4d1, CARTWGTAVGFACEDOUB4D1) (ifirstc(0), ifirstc(1), ifirstc(2), ifirstc(3), ilastc(0), ilastc(1), ilastc(2), ilastc(3), filo(0), filo(1), filo(2), filo(3), fihi(0), fihi(1), fihi(2), fihi(3), cilo(0), cilo(1), cilo(2), cilo(3), cihi(0), cihi(1), cihi(2), cihi(3), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub4d2, CARTWGTAVGFACEDOUB4D2) (ifirstc(0), ifirstc(1), ifirstc(2), ifirstc(3), ilastc(0), ilastc(1), ilastc(2), ilastc(3), filo(0), filo(1), filo(2), filo(3), fihi(0), fihi(1), fihi(2), fihi(3), cilo(0), cilo(1), cilo(2), cilo(3), cihi(0), cihi(1), cihi(2), cihi(3), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(2, d), cdata->getPointer(2, d)); SAMRAI_F77_FUNC(cartwgtavgfacedoub4d3, CARTWGTAVGFACEDOUB4D3) (ifirstc(0), ifirstc(1), ifirstc(2), ifirstc(3), ilastc(0), ilastc(1), ilastc(2), ilastc(3), filo(0), filo(1), filo(2), filo(3), fihi(0), fihi(1), fihi(2), fihi(3), cilo(0), cilo(1), cilo(2), cilo(3), cihi(0), cihi(1), cihi(2), cihi(3), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(3, d), cdata->getPointer(3, d)); } else { TBOX_ERROR("CartesianFaceDoubleWeightedAverage error...\n" << "dim > 4 not supported." << std::endl); } } }
void CartesianSideFloatWeightedAverage::coarsen( hier::Patch& coarse, const hier::Patch& fine, const int dst_component, const int src_component, const hier::Box& coarse_box, const hier::IntVector& ratio) const { const tbox::Dimension& dim(fine.getDim()); TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, coarse_box, ratio); std::shared_ptr<pdat::SideData<float> > fdata( SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>( fine.getPatchData(src_component))); std::shared_ptr<pdat::SideData<float> > cdata( SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>( coarse.getPatchData(dst_component))); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::IntVector& directions = cdata->getDirectionVector(); TBOX_ASSERT(directions == hier::IntVector::min(directions, fdata->getDirectionVector())); const hier::Index& filo = fdata->getGhostBox().lower(); const hier::Index& fihi = fdata->getGhostBox().upper(); const hier::Index& cilo = cdata->getGhostBox().lower(); const hier::Index& cihi = cdata->getGhostBox().upper(); const std::shared_ptr<CartesianPatchGeometry> fgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( fine.getPatchGeometry())); const std::shared_ptr<CartesianPatchGeometry> cgeom( SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>( coarse.getPatchGeometry())); TBOX_ASSERT(fgeom); TBOX_ASSERT(cgeom); const hier::Index& ifirstc = coarse_box.lower(); const hier::Index& ilastc = coarse_box.upper(); for (int d = 0; d < cdata->getDepth(); ++d) { if ((dim == tbox::Dimension(1))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot1d, CARTWGTAVGSIDEFLOT1D) (ifirstc(0), ilastc(0), filo(0), fihi(0), cilo(0), cihi(0), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } } else if ((dim == tbox::Dimension(2))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot2d0, CARTWGTAVGSIDEFLOT2D0) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(cartwgtavgsideflot2d1, CARTWGTAVGSIDEFLOT2D1) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), filo(0), filo(1), fihi(0), fihi(1), cilo(0), cilo(1), cihi(0), cihi(1), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); } } else if ((dim == tbox::Dimension(3))) { if (directions(0)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d0, CARTWGTAVGSIDEFLOT3D0) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(0, d), cdata->getPointer(0, d)); } if (directions(1)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d1, CARTWGTAVGSIDEFLOT3D1) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(1, d), cdata->getPointer(1, d)); } if (directions(2)) { SAMRAI_F77_FUNC(cartwgtavgsideflot3d2, CARTWGTAVGSIDEFLOT3D2) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), &ratio[0], fgeom->getDx(), cgeom->getDx(), fdata->getPointer(2, d), cdata->getPointer(2, d)); } } else { TBOX_ERROR("CartesianSideFloatWeightedAverage error...\n" << "dim > 3 not supported." << std::endl); } } }
int SkeletonBoundaryUtilities2::checkBdryData( const string& varname, const hier::Patch& patch, int data_id, int depth, const hier::IntVector& gcw_to_check, const hier::BoundaryBox& bbox, int bcase, double bstate) { TBOX_ASSERT(!varname.empty()); TBOX_ASSERT(data_id >= 0); TBOX_ASSERT(depth >= 0); int num_bad_values = 0; int btype = bbox.getBoundaryType(); int bloc = bbox.getLocationIndex(); std::shared_ptr<hier::PatchGeometry> pgeom(patch.getPatchGeometry()); std::shared_ptr<pdat::CellData<double> > vardata( SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>( patch.getPatchData(data_id))); TBOX_ASSERT(vardata); string bdry_type_str; if (btype == Bdry::EDGE2D) { bdry_type_str = "EDGE"; } else if (btype == Bdry::NODE2D) { bdry_type_str = "NODE"; } else { TBOX_ERROR( "Unknown btype " << btype << " passed to SkeletonBoundaryUtilities2::checkBdryData()! " << endl); } tbox::plog << "\n\nCHECKING 2D " << bdry_type_str << " BDRY DATA..." << endl; tbox::plog << "varname = " << varname << " : depth = " << depth << endl; tbox::plog << "bbox = " << bbox.getBox() << endl; tbox::plog << "btype, bloc, bcase = " << btype << ", = " << bloc << ", = " << bcase << endl; tbox::Dimension::dir_t idir; double valfact = 0.0, constval = 0.0, dxfact = 0.0; int offsign; get2dBdryDirectionCheckValues(idir, offsign, btype, bloc, bcase); if (btype == Bdry::EDGE2D) { if (bcase == BdryCond::FLOW) { valfact = 1.0; constval = 0.0; dxfact = 0.0; } else if (bcase == BdryCond::REFLECT) { valfact = -1.0; constval = 0.0; dxfact = 0.0; } else if (bcase == BdryCond::DIRICHLET) { valfact = 0.0; constval = bstate; dxfact = 0.0; } else { TBOX_ERROR( "Unknown bcase " << bcase << " passed to SkeletonBoundaryUtilities2::checkBdryData()" << "\n for " << bdry_type_str << " at location " << bloc << endl); } } else if (btype == Bdry::NODE2D) { if (bcase == BdryCond::XFLOW || bcase == BdryCond::YFLOW) { valfact = 1.0; constval = 0.0; dxfact = 0.0; } else if (bcase == BdryCond::XREFLECT || bcase == BdryCond::YREFLECT) { valfact = -1.0; constval = 0.0; dxfact = 0.0; } else if (bcase == BdryCond::XDIRICHLET || bcase == BdryCond::YDIRICHLET) { valfact = 0.0; constval = bstate; dxfact = 0.0; } else { TBOX_ERROR( "Unknown bcase " << bcase << " passed to SkeletonBoundaryUtilities2::checkBdryData()" << "\n for " << bdry_type_str << " at location " << bloc << endl); } } hier::Box gbox_to_check( vardata->getGhostBox() * pgeom->getBoundaryFillBox(bbox, patch.getBox(), gcw_to_check)); hier::Box cbox(gbox_to_check); hier::Box dbox(gbox_to_check); hier::Index ifirst(vardata->getBox().lower()); hier::Index ilast(vardata->getBox().upper()); if (offsign == -1) { cbox.setLower(idir, ifirst(idir) - 1); cbox.setUpper(idir, ifirst(idir) - 1); dbox.setLower(idir, ifirst(idir)); dbox.setUpper(idir, ifirst(idir)); } else { cbox.setLower(idir, ilast(idir) + 1); cbox.setUpper(idir, ilast(idir) + 1); dbox.setLower(idir, ilast(idir)); dbox.setUpper(idir, ilast(idir)); } pdat::CellIterator id(pdat::CellGeometry::begin(dbox)); pdat::CellIterator icend(pdat::CellGeometry::end(cbox)); for (pdat::CellIterator ic(pdat::CellGeometry::begin(cbox)); ic != icend; ++ic) { double checkval = valfact * (*vardata)(*id, depth) + constval; pdat::CellIndex check = *ic; for (int p = 0; p < gbox_to_check.numberCells(idir); ++p) { double offcheckval = checkval + dxfact * (p + 1); if ((*vardata)(check, depth) != offcheckval) { ++num_bad_values; TBOX_WARNING("Bad " << bdry_type_str << " boundary value for " << varname << " found in cell " << check << "\n found = " << (*vardata)(check, depth) << " : correct = " << offcheckval << endl); } check(idir) += offsign; } ++id; } return num_bad_values; }
void SkeletonBoundaryUtilities2::fillNodeBoundaryData( const string& varname, std::shared_ptr<pdat::CellData<double> >& vardata, const hier::Patch& patch, const hier::IntVector& ghost_fill_width, const std::vector<int>& bdry_node_conds, const std::vector<double>& bdry_edge_values) { NULL_USE(varname); TBOX_ASSERT(vardata); TBOX_ASSERT(static_cast<int>(bdry_node_conds.size()) == NUM_2D_NODES); TBOX_ASSERT(static_cast<int>(bdry_edge_values.size()) == NUM_2D_EDGES * (vardata->getDepth())); if (!s_fortran_constants_stuffed) { stuff2dBdryFortConst(); } const std::shared_ptr<hier::PatchGeometry> pgeom( patch.getPatchGeometry()); const hier::Box& interior(patch.getBox()); const hier::Index& ifirst(interior.lower()); const hier::Index& ilast(interior.upper()); const hier::IntVector& ghost_cells = vardata->getGhostCellWidth(); hier::IntVector gcw_to_fill = hier::IntVector::min(ghost_cells, ghost_fill_width); const std::vector<hier::BoundaryBox>& node_bdry = pgeom->getCodimensionBoundaries(Bdry::NODE2D); for (int i = 0; i < static_cast<int>(node_bdry.size()); ++i) { TBOX_ASSERT(node_bdry[i].getBoundaryType() == Bdry::NODE2D); int bnode_loc = node_bdry[i].getLocationIndex(); hier::Box fill_box(pgeom->getBoundaryFillBox(node_bdry[i], interior, gcw_to_fill)); if (!fill_box.empty()) { const hier::Index& ibeg(fill_box.lower()); const hier::Index& iend(fill_box.upper()); SAMRAI_F77_FUNC(getskelnodebdry2d, GETSKELNODEBDRY2D) ( ifirst(0), ilast(0), ifirst(1), ilast(1), ibeg(0), iend(0), ibeg(1), iend(1), ghost_cells(0), ghost_cells(1), bnode_loc, bdry_node_conds[bnode_loc], &bdry_edge_values[0], vardata->getPointer(), vardata->getDepth()); } } }
void CartesianNodeComplexLinearRefine::refine( hier::Patch& fine, const hier::Patch& coarse, const int dst_component, const int src_component, const hier::Box& fine_box, const hier::IntVector& ratio) const { const tbox::Dimension& dim(fine.getDim()); TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, fine_box, ratio); boost::shared_ptr<pdat::NodeData<dcomplex> > cdata( BOOST_CAST<pdat::NodeData<dcomplex>, hier::PatchData>( coarse.getPatchData(src_component))); boost::shared_ptr<pdat::NodeData<dcomplex> > fdata( BOOST_CAST<pdat::NodeData<dcomplex>, hier::PatchData>( fine.getPatchData(dst_component))); TBOX_ASSERT(cdata); TBOX_ASSERT(fdata); TBOX_ASSERT(cdata->getDepth() == fdata->getDepth()); const hier::Box cgbox(cdata->getGhostBox()); const hier::Index cilo = cgbox.lower(); const hier::Index cihi = cgbox.upper(); const hier::Index filo = fdata->getGhostBox().lower(); const hier::Index fihi = fdata->getGhostBox().upper(); const boost::shared_ptr<CartesianPatchGeometry> cgeom( BOOST_CAST<CartesianPatchGeometry, hier::PatchGeometry>( coarse.getPatchGeometry())); const boost::shared_ptr<CartesianPatchGeometry> fgeom( BOOST_CAST<CartesianPatchGeometry, hier::PatchGeometry>( fine.getPatchGeometry())); TBOX_ASSERT(cgeom); TBOX_ASSERT(fgeom); const hier::Box coarse_box = hier::Box::coarsen(fine_box, ratio); const hier::Index ifirstc = coarse_box.lower(); const hier::Index ilastc = coarse_box.upper(); const hier::Index ifirstf = fine_box.lower(); const hier::Index ilastf = fine_box.upper(); for (int d = 0; d < fdata->getDepth(); ++d) { if ((dim == tbox::Dimension(1))) { SAMRAI_F77_FUNC(cartlinrefnodecplx1d, CARTLINREFNODECPLX1D) (ifirstc(0), ilastc(0), ifirstf(0), ilastf(0), cilo(0), cihi(0), filo(0), fihi(0), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d)); } else if ((dim == tbox::Dimension(2))) { SAMRAI_F77_FUNC(cartlinrefnodecplx2d, CARTLINREFNODECPLX2D) (ifirstc(0), ifirstc(1), ilastc(0), ilastc(1), ifirstf(0), ifirstf(1), ilastf(0), ilastf(1), cilo(0), cilo(1), cihi(0), cihi(1), filo(0), filo(1), fihi(0), fihi(1), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d)); } else if ((dim == tbox::Dimension(3))) { SAMRAI_F77_FUNC(cartlinrefnodecplx3d, CARTLINREFNODECPLX3D) (ifirstc(0), ifirstc(1), ifirstc(2), ilastc(0), ilastc(1), ilastc(2), ifirstf(0), ifirstf(1), ifirstf(2), ilastf(0), ilastf(1), ilastf(2), cilo(0), cilo(1), cilo(2), cihi(0), cihi(1), cihi(2), filo(0), filo(1), filo(2), fihi(0), fihi(1), fihi(2), &ratio[0], cgeom->getDx(), fgeom->getDx(), cdata->getPointer(d), fdata->getPointer(d)); } else { TBOX_ERROR("CartesianNodeComplexLinearRefine error...\n" << "dim > 3 not supported." << std::endl); } } }