size_t PatchSideDataNormOpsReal<TYPE>::numberOfEntries( const boost::shared_ptr<pdat::SideData<TYPE> >& data, const hier::Box& box) const { TBOX_ASSERT(data); TBOX_ASSERT_OBJDIM_EQUALITY2(*data, box); tbox::Dimension::dir_t dimVal = box.getDim().getValue(); size_t retval = 0; const hier::Box ibox = box * data->getGhostBox(); const hier::IntVector& directions = data->getDirectionVector(); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { if (directions(d)) { const hier::Box dbox = pdat::SideGeometry::toSideBox(ibox, d); retval += (dbox.size() * data->getDepth()); } } return retval; }
void EdgeDataSynchronization::synchronizeData(const double fill_time) { #if !defined(NDEBUG) TBOX_ASSERT(d_is_initialized); #endif for (int ln = d_finest_ln; ln >= d_coarsest_ln; --ln) { Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(ln); // Synchronize data on the current level. for (unsigned int axis = 0; axis < NDIM; ++axis) { d_refine_scheds[axis][ln]->fillData(fill_time); } // When appropriate, coarsen data from the current level to the next // coarser level. if (ln > d_coarsest_ln && d_coarsen_scheds[ln]) d_coarsen_scheds[ln]->coarsenData(); } return; } // synchronizeData
void CVODEModel::setupSolutionVector( std::shared_ptr<PatchHierarchy> hierarchy) { /* create SAMRAIVector */ std::shared_ptr<SAMRAIVectorReal<double> > soln_samvect( new SAMRAIVectorReal<double>( "solution", hierarchy, 0, hierarchy->getFinestLevelNumber())); soln_samvect->addComponent(d_soln_var, d_soln_cur_id); /* allocate memory for vectors. */ soln_samvect->allocateVectorData(); /* create SundialsAbstractVector */ d_solution_vector = Sundials_SAMRAIVector::createSundialsVector(soln_samvect); #ifdef USE_FAC_PRECONDITIONER /* * Allocate memory for preconditioner variables. */ const int nlevels = hierarchy->getNumberOfLevels(); for (int ln = 0; ln < nlevels; ++ln) { std::shared_ptr<PatchLevel> level(hierarchy->getPatchLevel(ln)); TBOX_ASSERT(level); level->allocatePatchData(d_diff_id); if (d_use_neumann_bcs) { level->allocatePatchData(d_flag_id); level->allocatePatchData(d_neuf_id); } } #endif }
boost::shared_ptr<TimeInterpolateOperator> TransferOperatorRegistry::lookupTimeInterpolateOperator( const boost::shared_ptr<Variable>& var, const std::string& op_name) { TBOX_ASSERT(var); TBOX_ASSERT_OBJDIM_EQUALITY2(d_min_stencil_width, *var); boost::shared_ptr<TimeInterpolateOperator> time_op; if ((op_name == "NO_TIME_INTERPOLATE") || (op_name.empty())) { } else { boost::unordered_map<std::string, boost::unordered_map<std::string, boost::shared_ptr< TimeInterpolateOperator> > >:: iterator time_ops = d_time_operators.find(op_name); if (time_ops == d_time_operators.end()) { TBOX_ERROR( "TransferOperatorRegistry::lookupTimeInterpolateOperator" << " could not find any operators with name " << op_name << std::endl); } boost::unordered_map<std::string, boost::shared_ptr<TimeInterpolateOperator> >::iterator the_op = time_ops->second.find(typeid(*var).name()); if (the_op == time_ops->second.end()) { TBOX_ERROR( "TransferOperatorRegistry::lookupTimeInterpolateOperator" << " could not find operator with name " << op_name << " for variable named " << typeid(*var).name() << std::endl); } time_op = the_op->second; } return time_op; }
void IBHierarchyIntegrator::IBEulerianSourceFunction::setDataOnPatch( const int data_idx, Pointer<Variable<NDIM> > /*var*/, Pointer<Patch<NDIM> > patch, const double /*data_time*/, const bool initial_time, Pointer<PatchLevel<NDIM> > /*level*/) { Pointer<CellData<NDIM,double> > q_cc_data = patch->getPatchData(data_idx); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(!q_cc_data.isNull()); #endif q_cc_data->fillAll(0.0); if (initial_time) return; Pointer<CellData<NDIM,double> > q_ib_cc_data = patch->getPatchData(d_ib_solver->d_q_idx); PatchCellDataBasicOps<NDIM,double> patch_ops; patch_ops.add(q_cc_data, q_cc_data, q_ib_cc_data, patch->getBox()); return; }// setDataOnPatch
boost::shared_ptr<RefineOperator> TransferOperatorRegistry::lookupRefineOperator( const boost::shared_ptr<Variable>& var, const std::string& op_name) { TBOX_ASSERT(var); TBOX_ASSERT_OBJDIM_EQUALITY2(d_min_stencil_width, *var); boost::shared_ptr<RefineOperator> refine_op; if ((op_name == "NO_REFINE") || (op_name == "USER_DEFINED_REFINE") || (op_name.empty())) { } else { boost::unordered_map<std::string, boost::unordered_map<std::string, boost::shared_ptr<RefineOperator> > > ::iterator refine_ops = d_refine_operators.find(op_name); if (refine_ops == d_refine_operators.end()) { TBOX_ERROR( "TransferOperatorRegistry::lookupRefineOperator" << " could not find any operators with name " << op_name << std::endl); } boost::unordered_map<std::string, boost::shared_ptr<RefineOperator> >::iterator the_op = refine_ops->second.find(typeid(*var).name()); if (the_op == refine_ops->second.end()) { TBOX_ERROR( "TransferOperatorRegistry::lookupRefineOperator" << " could not find operator with name " << op_name << " for variable named " << typeid(*var).name() << std::endl); } refine_op = the_op->second; } return refine_op; }
void StaggeredStokesPhysicalBoundaryHelper::setupBcCoefObjects(const std::vector<RobinBcCoefStrategy<NDIM>*>& u_bc_coefs, RobinBcCoefStrategy<NDIM>* p_bc_coef, int u_target_data_idx, int p_target_data_idx, bool homogeneous_bc) { #if !defined(NDEBUG) TBOX_ASSERT(u_bc_coefs.size() == NDIM); #endif for (unsigned int d = 0; d < NDIM; ++d) { ExtendedRobinBcCoefStrategy* extended_u_bc_coef = dynamic_cast<ExtendedRobinBcCoefStrategy*>(u_bc_coefs[d]); if (extended_u_bc_coef) { extended_u_bc_coef->clearTargetPatchDataIndex(); extended_u_bc_coef->setHomogeneousBc(homogeneous_bc); } StokesBcCoefStrategy* stokes_u_bc_coef = dynamic_cast<StokesBcCoefStrategy*>(u_bc_coefs[d]); if (stokes_u_bc_coef) { stokes_u_bc_coef->setTargetVelocityPatchDataIndex(u_target_data_idx); stokes_u_bc_coef->setTargetPressurePatchDataIndex(p_target_data_idx); } } ExtendedRobinBcCoefStrategy* extended_p_bc_coef = dynamic_cast<ExtendedRobinBcCoefStrategy*>(p_bc_coef); if (extended_p_bc_coef) { extended_p_bc_coef->clearTargetPatchDataIndex(); extended_p_bc_coef->setHomogeneousBc(homogeneous_bc); } StokesBcCoefStrategy* stokes_p_bc_coef = dynamic_cast<StokesBcCoefStrategy*>(p_bc_coef); if (stokes_p_bc_coef) { stokes_p_bc_coef->setTargetVelocityPatchDataIndex(u_target_data_idx); stokes_p_bc_coef->setTargetPressurePatchDataIndex(p_target_data_idx); } return; } // setupBcCoefObjects
void IBStrategy::registerVariable(int& current_idx, int& new_idx, int& scratch_idx, Pointer<Variable<NDIM> > variable, const IntVector<NDIM>& scratch_ghosts, const std::string& coarsen_name, const std::string& refine_name, Pointer<CartGridFunction> init_fcn) { #if !defined(NDEBUG) TBOX_ASSERT(d_ib_solver); #endif d_ib_solver->registerVariable(current_idx, new_idx, scratch_idx, variable, scratch_ghosts, coarsen_name, refine_name, init_fcn); return; } // registerVariable
PetscErrorCode VecNorm_SAMRAI( Vec x, NormType type, PetscScalar* val) { IBTK_TIMER_START(t_vec_norm); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); #endif if (type == NORM_1) { *val = NormOps::L1Norm(PSVR_CAST2(x)); } else if (type == NORM_2) { *val = NormOps::L2Norm(PSVR_CAST2(x)); } else if (type == NORM_INFINITY) { *val = NormOps::maxNorm(PSVR_CAST2(x)); } else if (type == NORM_1_AND_2) { static const bool local_only = true; val[0] = NormOps::L1Norm(PSVR_CAST2(x), local_only); val[1] = NormOps::L2Norm(PSVR_CAST2(x), local_only); val[1] = val[1]*val[1]; SAMRAI_MPI::sumReduction(val, 2); val[1] = std::sqrt(val[1]); } else { TBOX_ERROR("PETScSAMRAIVectorReal::norm()\n" << " vector norm type " << static_cast<int>(type) << " unsupported" << std::endl); } IBTK_TIMER_STOP(t_vec_norm); PetscFunctionReturn(0); }// VecNorm
void MainRestartData::getFromInput( std::shared_ptr<tbox::Database> input_db, bool is_from_restart) { TBOX_ASSERT(input_db); if (input_db->keyExists("max_timesteps")) { d_max_timesteps = input_db->getInteger("max_timesteps"); } else { if (!is_from_restart) { TBOX_ERROR("max_timesteps not entered in input file" << endl); } } if (input_db->keyExists("start_time")) { d_start_time = input_db->getDouble("start_time"); } else { d_start_time = 0.0; } if (input_db->keyExists("end_time")) { d_end_time = input_db->getDouble("end_time"); } else { d_end_time = 100000.; } if (input_db->keyExists("regrid_step")) { d_regrid_step = input_db->getInteger("regrid_step"); } else { d_regrid_step = 2; } if (input_db->keyExists("tag_buffer")) { d_tag_buffer = input_db->getInteger("tag_buffer"); } else { d_tag_buffer = d_regrid_step; } }
void LData::putToDatabase(Pointer<Database> db) { #if !defined(NDEBUG) TBOX_ASSERT(db); #endif const int num_local_nodes = getLocalNodeCount(); const int num_ghost_nodes = static_cast<int>(d_nonlocal_petsc_indices.size()); db->putString("d_name", d_name); db->putInteger("d_depth", d_depth); db->putInteger("num_local_nodes", num_local_nodes); db->putInteger("num_ghost_nodes", num_ghost_nodes); if (num_ghost_nodes > 0) { db->putIntegerArray("d_nonlocal_petsc_indices", &d_nonlocal_petsc_indices[0], num_ghost_nodes); } const double* const ghosted_local_vec_array = getGhostedLocalFormVecArray()->data(); if (num_local_nodes + num_ghost_nodes > 0) { db->putDoubleArray("vals", ghosted_local_vec_array, d_depth * (num_local_nodes + num_ghost_nodes)); } restoreArrays(); return; } // putToDatabase
/* ************************************************************************* * * Write data to restart database. * ************************************************************************* */ void CVODEModel::putToRestart( const std::shared_ptr<Database>& restart_db) const { TBOX_ASSERT(restart_db); restart_db->putInteger("CVODE_MODEL_VERSION", CVODE_MODEL_VERSION); restart_db->putDouble("d_initial_value", d_initial_value); restart_db->putIntegerVector("d_scalar_bdry_edge_conds", d_scalar_bdry_edge_conds); restart_db->putIntegerVector("d_scalar_bdry_node_conds", d_scalar_bdry_node_conds); if (d_dim == Dimension(2)) { restart_db->putDoubleVector("d_bdry_edge_val", d_bdry_edge_val); } else if (d_dim == Dimension(3)) { restart_db->putIntegerVector("d_scalar_bdry_face_conds", d_scalar_bdry_face_conds); restart_db->putDoubleVector("d_bdry_face_val", d_bdry_face_val); } }
MainRestartData::MainRestartData( const string& object_name, std::shared_ptr<tbox::Database> input_db): d_object_name(object_name) { TBOX_ASSERT(input_db); tbox::RestartManager::getManager()->registerRestartItem(d_object_name, this); /* * Initialize object with data read from given input/restart databases. */ bool is_from_restart = tbox::RestartManager::getManager()->isFromRestart(); if (is_from_restart) { getFromRestart(); } getFromInput(input_db, is_from_restart); /* if not starting from restart file, set loop_time and iteration_number */ if (!is_from_restart) { d_loop_time = d_start_time; d_iteration_number = 0; } }
double QuarticFcn::operator () ( double x, double y, double z) const { TBOX_ASSERT(d_dim == tbox::Dimension(3)); double rval; rval = d_coefs[co_c] + d_coefs[co_x] * x + d_coefs[co_y] * y + d_coefs[co_z] * z + d_coefs[co_xx] * x * x + d_coefs[co_yy] * y * y + d_coefs[co_zz] * z * z + d_coefs[co_xy] * x * y + d_coefs[co_xz] * x * z + d_coefs[co_yz] * y * z + d_coefs[co_zzz] * z * z * z + d_coefs[co_xxz] * x * x * z + d_coefs[co_xzz] * x * z * z + d_coefs[co_yyz] * y * y * z + d_coefs[co_yzz] * x * z * z + d_coefs[co_xyz] * x * y * z + d_coefs[co_xxxz] * x * x * x * z + d_coefs[co_xxyz] * x * x * y * z + d_coefs[co_xxzz] * x * x * z * x + d_coefs[co_xyyz] * x * y * y * z + d_coefs[co_xyzz] * x * y * z * z + d_coefs[co_xzzz] * x * z * z * z + d_coefs[co_yyyz] * y * y * y * z + d_coefs[co_yyzz] * y * y * z * z + d_coefs[co_yzzz] * y * z * z * z + d_coefs[co_zzzz] * z * z * z * z ; return rval; }
int PatchEdgeDataMiscellaneousOpsReal<TYPE>::computeConstrProdPos( const std::shared_ptr<pdat::EdgeData<TYPE> >& data1, const std::shared_ptr<pdat::EdgeData<TYPE> >& data2, const hier::Box& box, const std::shared_ptr<pdat::EdgeData<double> >& cvol) const { TBOX_ASSERT(data1 && data2); int dimVal = data1->getDim().getValue(); int retval = 1; if (!cvol) { for (int d = 0; d < dimVal; ++d) { const hier::Box edge_box = pdat::EdgeGeometry::toEdgeBox(box, d); retval = tbox::MathUtilities<int>::Min(retval, d_array_ops.computeConstrProdPos( data1->getArrayData(d), data2->getArrayData(d), edge_box)); } } else { for (int d = 0; d < dimVal; ++d) { const hier::Box edge_box = pdat::EdgeGeometry::toEdgeBox(box, d); retval = tbox::MathUtilities<int>::Min(retval, d_array_ops.computeConstrProdPosWithControlVolume( data1->getArrayData(d), data2->getArrayData(d), cvol->getArrayData(d), edge_box)); } } return retval; }
int PatchEdgeDataMiscellaneousOpsReal<TYPE>::testReciprocal( const std::shared_ptr<pdat::EdgeData<TYPE> >& dst, const std::shared_ptr<pdat::EdgeData<TYPE> >& src, const hier::Box& box, const std::shared_ptr<pdat::EdgeData<double> >& cvol) const { TBOX_ASSERT(dst && src); int dimVal = dst->getDim().getValue(); int retval = 1; if (!cvol) { for (int d = 0; d < dimVal; ++d) { const hier::Box edge_box = pdat::EdgeGeometry::toEdgeBox(box, d); retval = tbox::MathUtilities<int>::Min(retval, d_array_ops.testReciprocal( dst->getArrayData(d), src->getArrayData(d), edge_box)); } } else { for (int d = 0; d < dimVal; ++d) { const hier::Box edge_box = pdat::EdgeGeometry::toEdgeBox(box, d); retval = tbox::MathUtilities<int>::Min(retval, d_array_ops.testReciprocalWithControlVolume( dst->getArrayData(d), src->getArrayData(d), cvol->getArrayData(d), edge_box)); } } return retval; }
void StaggeredStokesPhysicalBoundaryHelper::resetBcCoefObjects(const std::vector<RobinBcCoefStrategy<NDIM>*>& u_bc_coefs, RobinBcCoefStrategy<NDIM>* p_bc_coef) { #if !defined(NDEBUG) TBOX_ASSERT(u_bc_coefs.size() == NDIM); #endif for (unsigned int d = 0; d < NDIM; ++d) { StokesBcCoefStrategy* stokes_u_bc_coef = dynamic_cast<StokesBcCoefStrategy*>(u_bc_coefs[d]); if (stokes_u_bc_coef) { stokes_u_bc_coef->clearTargetVelocityPatchDataIndex(); stokes_u_bc_coef->clearTargetPressurePatchDataIndex(); } } StokesBcCoefStrategy* stokes_p_bc_coef = dynamic_cast<StokesBcCoefStrategy*>(p_bc_coef); if (stokes_p_bc_coef) { stokes_p_bc_coef->clearTargetVelocityPatchDataIndex(); stokes_p_bc_coef->clearTargetPressurePatchDataIndex(); } return; } // resetBcCoefObjects
double PatchFaceDataNormOpsComplex::weightedL2Norm( const std::shared_ptr<pdat::FaceData<dcomplex> >& data, const std::shared_ptr<pdat::FaceData<dcomplex> >& weight, const hier::Box& box, const std::shared_ptr<pdat::FaceData<double> >& cvol) const { TBOX_ASSERT(data && weight); TBOX_ASSERT_OBJDIM_EQUALITY3(*data, *weight, box); tbox::Dimension::dir_t dimVal = box.getDim().getValue(); double retval = 0.0; if (!cvol) { for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { const hier::Box face_box = pdat::FaceGeometry::toFaceBox(box, d); double aval = d_array_ops.weightedL2Norm(data->getArrayData(d), weight->getArrayData(d), face_box); retval += aval * aval; } } else { TBOX_ASSERT_OBJDIM_EQUALITY2(*data, *cvol); for (tbox::Dimension::dir_t d = 0; d < dimVal; ++d) { const hier::Box face_box = pdat::FaceGeometry::toFaceBox(box, d); double aval = d_array_ops.weightedL2NormWithControlVolume( data->getArrayData(d), weight->getArrayData(d), cvol->getArrayData(d), face_box); retval += aval * aval; } } return sqrt(retval); }
RefineCopyTransaction::RefineCopyTransaction( const std::shared_ptr<hier::PatchLevel>& dst_level, const std::shared_ptr<hier::PatchLevel>& src_level, const std::shared_ptr<hier::BoxOverlap>& overlap, const hier::Box& dst_box, const hier::Box& src_box, const RefineClasses::Data** refine_data, int item_id): d_dst_patch_rank(dst_box.getOwnerRank()), d_src_patch_rank(src_box.getOwnerRank()), d_overlap(overlap), d_refine_data(refine_data), d_item_id(item_id), d_incoming_bytes(0), d_outgoing_bytes(0) { TBOX_ASSERT(dst_level); TBOX_ASSERT(src_level); TBOX_ASSERT(overlap); TBOX_ASSERT(dst_box.getLocalId() >= 0); TBOX_ASSERT(src_box.getLocalId() >= 0); TBOX_ASSERT(item_id >= 0); TBOX_ASSERT(refine_data[item_id] != 0); TBOX_ASSERT_OBJDIM_EQUALITY4(*dst_level, *src_level, dst_box, src_box); // Note: s_num_coarsen_items cannot be used at this point! if (d_dst_patch_rank == dst_level->getBoxLevel()->getMPI().getRank()) { d_dst_patch = dst_level->getPatch(dst_box.getGlobalId()); } if (d_src_patch_rank == dst_level->getBoxLevel()->getMPI().getRank()) { d_src_patch = src_level->getPatch(src_box.getGlobalId()); } }
void PatchSideDataOpsReal<TYPE>::swapData( const std::shared_ptr<hier::Patch>& patch, const int data1_id, const int data2_id) const { TBOX_ASSERT(patch); std::shared_ptr<pdat::SideData<TYPE> > d1( SAMRAI_SHARED_PTR_CAST<pdat::SideData<TYPE>, hier::PatchData>( patch->getPatchData(data1_id))); std::shared_ptr<pdat::SideData<TYPE> > d2( SAMRAI_SHARED_PTR_CAST<pdat::SideData<TYPE>, hier::PatchData>( patch->getPatchData(data2_id))); TBOX_ASSERT(d1 && d2); TBOX_ASSERT(d1->getDepth() && d2->getDepth()); TBOX_ASSERT(d1->getBox().isSpatiallyEqual(d2->getBox())); TBOX_ASSERT(d1->getDirectionVector() == d2->getDirectionVector()); TBOX_ASSERT(d1->getGhostBox().isSpatiallyEqual(d2->getGhostBox())); patch->setPatchData(data1_id, d2); patch->setPatchData(data2_id, d1); }
/******************************************************************************* * For each run, the input filename must be given on the command line. In all * * cases, the command line is: * * * * executable <input file name> * * * *******************************************************************************/ int main(int argc, char* argv[]) { // Initialize PETSc, MPI, and SAMRAI. PetscInitialize(&argc, &argv, NULL, NULL); SAMRAI_MPI::setCommunicator(PETSC_COMM_WORLD); SAMRAI_MPI::setCallAbortInSerialInsteadOfExit(); SAMRAIManager::startup(); { // cleanup dynamically allocated objects prior to shutdown // Parse command line options, set some standard options from the input // file, and enable file logging. Pointer<AppInitializer> app_initializer = new AppInitializer(argc, argv, "vc_laplace.log"); Pointer<Database> input_db = app_initializer->getInputDatabase(); // Create major algorithm and data objects that comprise the // application. These objects are configured from the input database. Pointer<CartesianGridGeometry<NDIM> > grid_geometry = new CartesianGridGeometry<NDIM>( "CartesianGeometry", app_initializer->getComponentDatabase("CartesianGeometry")); Pointer<PatchHierarchy<NDIM> > patch_hierarchy = new PatchHierarchy<NDIM>("PatchHierarchy", grid_geometry); Pointer<StandardTagAndInitialize<NDIM> > error_detector = new StandardTagAndInitialize<NDIM>( "StandardTagAndInitialize", NULL, app_initializer->getComponentDatabase("StandardTagAndInitialize")); Pointer<BergerRigoutsos<NDIM> > box_generator = new BergerRigoutsos<NDIM>(); Pointer<LoadBalancer<NDIM> > load_balancer = new LoadBalancer<NDIM>("LoadBalancer", app_initializer->getComponentDatabase("LoadBalancer")); Pointer<GriddingAlgorithm<NDIM> > gridding_algorithm = new GriddingAlgorithm<NDIM>("GriddingAlgorithm", app_initializer->getComponentDatabase("GriddingAlgorithm"), error_detector, box_generator, load_balancer); // Create variables and register them with the variable database. VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); Pointer<VariableContext> ctx = var_db->getContext("context"); Pointer<SideVariable<NDIM, double> > u_side_var = new SideVariable<NDIM, double>("u_side"); Pointer<SideVariable<NDIM, double> > f_side_var = new SideVariable<NDIM, double>("f_side"); Pointer<SideVariable<NDIM, double> > e_side_var = new SideVariable<NDIM, double>("e_side"); const int u_side_idx = var_db->registerVariableAndContext(u_side_var, ctx, IntVector<NDIM>(1)); const int f_side_idx = var_db->registerVariableAndContext(f_side_var, ctx, IntVector<NDIM>(1)); const int e_side_idx = var_db->registerVariableAndContext(e_side_var, ctx, IntVector<NDIM>(1)); Pointer<CellVariable<NDIM, double> > u_cell_var = new CellVariable<NDIM, double>("u_cell", NDIM); Pointer<CellVariable<NDIM, double> > f_cell_var = new CellVariable<NDIM, double>("f_cell", NDIM); Pointer<CellVariable<NDIM, double> > e_cell_var = new CellVariable<NDIM, double>("e_cell", NDIM); const int u_cell_idx = var_db->registerVariableAndContext(u_cell_var, ctx, IntVector<NDIM>(0)); const int f_cell_idx = var_db->registerVariableAndContext(f_cell_var, ctx, IntVector<NDIM>(0)); const int e_cell_idx = var_db->registerVariableAndContext(e_cell_var, ctx, IntVector<NDIM>(0)); Pointer<NodeVariable<NDIM, double> > mu_node_var = new NodeVariable<NDIM, double>("mu_node"); const int mu_node_idx = var_db->registerVariableAndContext(mu_node_var, ctx, IntVector<NDIM>(1)); // Register variables for plotting. Pointer<VisItDataWriter<NDIM> > visit_data_writer = app_initializer->getVisItDataWriter(); TBOX_ASSERT(visit_data_writer); visit_data_writer->registerPlotQuantity(u_cell_var->getName(), "VECTOR", u_cell_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(u_cell_var->getName() + stream.str(), "SCALAR", u_cell_idx, d); } visit_data_writer->registerPlotQuantity(f_cell_var->getName(), "VECTOR", f_cell_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(f_cell_var->getName() + stream.str(), "SCALAR", f_cell_idx, d); } visit_data_writer->registerPlotQuantity(e_cell_var->getName(), "VECTOR", e_cell_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(e_cell_var->getName() + stream.str(), "SCALAR", e_cell_idx, d); } visit_data_writer->registerPlotQuantity(mu_node_var->getName(), "SCALAR", mu_node_idx); // Initialize the AMR patch hierarchy. gridding_algorithm->makeCoarsestLevel(patch_hierarchy, 0.0); int tag_buffer = 1; int level_number = 0; bool done = false; while (!done && (gridding_algorithm->levelCanBeRefined(level_number))) { gridding_algorithm->makeFinerLevel(patch_hierarchy, 0.0, 0.0, tag_buffer); done = !patch_hierarchy->finerLevelExists(level_number); ++level_number; } // Set the simulation time to be zero. const double data_time = 0.0; // Allocate data on each level of the patch hierarchy. for (int ln = 0; ln <= patch_hierarchy->getFinestLevelNumber(); ++ln) { Pointer<PatchLevel<NDIM> > level = patch_hierarchy->getPatchLevel(ln); level->allocatePatchData(u_side_idx, data_time); level->allocatePatchData(f_side_idx, data_time); level->allocatePatchData(e_side_idx, data_time); level->allocatePatchData(u_cell_idx, data_time); level->allocatePatchData(f_cell_idx, data_time); level->allocatePatchData(e_cell_idx, data_time); level->allocatePatchData(mu_node_idx, data_time); } // Setup exact solution data. muParserCartGridFunction u_fcn("u", app_initializer->getComponentDatabase("u"), grid_geometry); muParserCartGridFunction f_fcn("f", app_initializer->getComponentDatabase("f"), grid_geometry); muParserCartGridFunction mu_fcn("mu", app_initializer->getComponentDatabase("mu"), grid_geometry); u_fcn.setDataOnPatchHierarchy(u_side_idx, u_side_var, patch_hierarchy, data_time); f_fcn.setDataOnPatchHierarchy(e_side_idx, e_side_var, patch_hierarchy, data_time); mu_fcn.setDataOnPatchHierarchy(mu_node_idx, mu_node_var, patch_hierarchy, data_time); // Create an object to communicate ghost cell data. typedef HierarchyGhostCellInterpolation::InterpolationTransactionComponent InterpolationTransactionComponent; InterpolationTransactionComponent u_transaction(u_side_idx, "CUBIC_COARSEN", "LINEAR"); InterpolationTransactionComponent mu_transaction(mu_node_idx, "CONSTANT_COARSEN", "LINEAR"); vector<InterpolationTransactionComponent> transactions(2); transactions[0] = u_transaction; transactions[1] = mu_transaction; Pointer<HierarchyGhostCellInterpolation> bdry_fill_op = new HierarchyGhostCellInterpolation(); bdry_fill_op->initializeOperatorState(transactions, patch_hierarchy); // Create the math operations object and get the patch data index for // the side-centered weighting factor. HierarchyMathOps hier_math_ops("hier_math_ops", patch_hierarchy); const int dx_side_idx = hier_math_ops.getSideWeightPatchDescriptorIndex(); // Compute (f0,f1) := div mu (grad(u0,u1) + grad(u0,u1)^T). hier_math_ops.vc_laplace(f_side_idx, f_side_var, 1.0, 0.0, mu_node_idx, mu_node_var, u_side_idx, u_side_var, bdry_fill_op, data_time); // Compute error and print error norms. Pointer<HierarchyDataOpsReal<NDIM, double> > hier_side_data_ops = HierarchyDataOpsManager<NDIM>::getManager()->getOperationsDouble(u_side_var, patch_hierarchy, true); hier_side_data_ops->subtract(e_side_idx, e_side_idx, f_side_idx); // computes e := e - f pout << "|e|_oo = " << hier_side_data_ops->maxNorm(e_side_idx, dx_side_idx) << "\n"; pout << "|e|_2 = " << hier_side_data_ops->L2Norm(e_side_idx, dx_side_idx) << "\n"; pout << "|e|_1 = " << hier_side_data_ops->L1Norm(e_side_idx, dx_side_idx) << "\n"; // Interpolate the side-centered data to cell centers for output. static const bool synch_cf_interface = true; hier_math_ops.interp(u_cell_idx, u_cell_var, u_side_idx, u_side_var, NULL, data_time, synch_cf_interface); hier_math_ops.interp(f_cell_idx, f_cell_var, f_side_idx, f_side_var, NULL, data_time, synch_cf_interface); hier_math_ops.interp(e_cell_idx, e_cell_var, e_side_idx, e_side_var, NULL, data_time, synch_cf_interface); // Output data for plotting. visit_data_writer->writePlotData(patch_hierarchy, 0, data_time); } // cleanup dynamically allocated objects prior to shutdown SAMRAIManager::shutdown(); PetscFinalize(); return 0; } // main
void FaceDataSynchronization::initializeOperatorState( const std::vector<SynchronizationTransactionComponent>& transaction_comps, Pointer<PatchHierarchy<NDIM> > hierarchy) { // Deallocate the operator state if the operator is already initialized. if (d_is_initialized) deallocateOperatorState(); // Reset the transaction components. d_transaction_comps = transaction_comps; // Cache hierarchy data. d_hierarchy = hierarchy; d_grid_geom = d_hierarchy->getGridGeometry(); d_coarsest_ln = 0; d_finest_ln = d_hierarchy->getFinestLevelNumber(); // Setup cached coarsen algorithms and schedules. VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); bool registered_coarsen_op = false; d_coarsen_alg = new CoarsenAlgorithm<NDIM>(); for (unsigned int comp_idx = 0; comp_idx < d_transaction_comps.size(); ++comp_idx) { const std::string& coarsen_op_name = d_transaction_comps[comp_idx].d_coarsen_op_name; if (coarsen_op_name != "NONE") { const int data_idx = d_transaction_comps[comp_idx].d_data_idx; Pointer<Variable<NDIM> > var; var_db->mapIndexToVariable(data_idx, var); #if !defined(NDEBUG) TBOX_ASSERT(var); #endif Pointer<CoarsenOperator<NDIM> > coarsen_op = d_grid_geom->lookupCoarsenOperator(var, coarsen_op_name); #if !defined(NDEBUG) TBOX_ASSERT(coarsen_op); #endif d_coarsen_alg->registerCoarsen(data_idx, // destination data_idx, // source coarsen_op); registered_coarsen_op = true; } } CoarsenPatchStrategy<NDIM>* coarsen_strategy = NULL; d_coarsen_scheds.resize(d_finest_ln + 1); if (registered_coarsen_op) { for (int ln = d_coarsest_ln + 1; ln <= d_finest_ln; ++ln) { Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(ln); Pointer<PatchLevel<NDIM> > coarser_level = d_hierarchy->getPatchLevel(ln - 1); d_coarsen_scheds[ln] = d_coarsen_alg->createSchedule(coarser_level, level, coarsen_strategy); } } // Setup cached refine algorithms and schedules. d_refine_alg = new RefineAlgorithm<NDIM>(); for (unsigned int comp_idx = 0; comp_idx < d_transaction_comps.size(); ++comp_idx) { const int data_idx = d_transaction_comps[comp_idx].d_data_idx; Pointer<Variable<NDIM> > var; var_db->mapIndexToVariable(data_idx, var); Pointer<FaceVariable<NDIM, double> > fc_var = var; if (!fc_var) { TBOX_ERROR("FaceDataSynchronization::initializeOperatorState():\n" << " only double-precision face-centered data is supported." << std::endl); } Pointer<RefineOperator<NDIM> > refine_op = NULL; Pointer<VariableFillPattern<NDIM> > fill_pattern = new FaceSynchCopyFillPattern(); d_refine_alg->registerRefine(data_idx, // destination data_idx, // source data_idx, // temporary work space refine_op, fill_pattern); } d_refine_scheds.resize(d_finest_ln + 1); for (int ln = d_coarsest_ln; ln <= d_finest_ln; ++ln) { Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(ln); d_refine_scheds[ln] = d_refine_alg->createSchedule(level); } // Indicate the operator is initialized. d_is_initialized = true; return; } // initializeOperatorState
void FaceDataSynchronization::resetTransactionComponents( const std::vector<SynchronizationTransactionComponent>& transaction_comps) { #if !defined(NDEBUG) TBOX_ASSERT(d_is_initialized); #endif if (d_transaction_comps.size() != transaction_comps.size()) { TBOX_ERROR( "FaceDataSynchronization::resetTransactionComponents():" << " invalid reset operation. attempting to change the number of registered " "synchronization transaction components.\n"); } // Reset the transaction components. d_transaction_comps = transaction_comps; // Reset cached coarsen algorithms and schedules. VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); bool registered_coarsen_op = false; d_coarsen_alg = new CoarsenAlgorithm<NDIM>(); for (unsigned int comp_idx = 0; comp_idx < d_transaction_comps.size(); ++comp_idx) { const std::string& coarsen_op_name = d_transaction_comps[comp_idx].d_coarsen_op_name; if (coarsen_op_name != "NONE") { const int data_idx = d_transaction_comps[comp_idx].d_data_idx; Pointer<Variable<NDIM> > var; var_db->mapIndexToVariable(data_idx, var); #if !defined(NDEBUG) TBOX_ASSERT(var); #endif Pointer<CoarsenOperator<NDIM> > coarsen_op = d_grid_geom->lookupCoarsenOperator(var, coarsen_op_name); #if !defined(NDEBUG) TBOX_ASSERT(coarsen_op); #endif d_coarsen_alg->registerCoarsen(data_idx, // destination data_idx, // source coarsen_op); registered_coarsen_op = true; } } if (registered_coarsen_op) { for (int ln = d_coarsest_ln + 1; ln <= d_finest_ln; ++ln) { d_coarsen_alg->resetSchedule(d_coarsen_scheds[ln]); } } // Reset cached refine algorithms and schedules. d_refine_alg = new RefineAlgorithm<NDIM>(); for (unsigned int comp_idx = 0; comp_idx < d_transaction_comps.size(); ++comp_idx) { const int data_idx = d_transaction_comps[comp_idx].d_data_idx; Pointer<Variable<NDIM> > var; var_db->mapIndexToVariable(data_idx, var); Pointer<FaceVariable<NDIM, double> > fc_var = var; if (!fc_var) { TBOX_ERROR("FaceDataSynchronization::resetTransactionComponents():\n" << " only double-precision face-centered data is supported." << std::endl); } Pointer<RefineOperator<NDIM> > refine_op = NULL; Pointer<VariableFillPattern<NDIM> > fill_pattern = new FaceSynchCopyFillPattern(); d_refine_alg->registerRefine(data_idx, // destination data_idx, // source data_idx, // temporary work space refine_op, fill_pattern); } for (int ln = d_coarsest_ln; ln <= d_finest_ln; ++ln) { d_refine_alg->resetSchedule(d_refine_scheds[ln]); } return; } // resetTransactionComponents
void CartSideDoubleRT0Refine::refine(Patch<NDIM>& fine, const Patch<NDIM>& coarse, const int dst_component, const int src_component, const Box<NDIM>& fine_box, const IntVector<NDIM>& ratio) const { // Get the patch data. Pointer<SideData<NDIM, double> > fdata = fine.getPatchData(dst_component); Pointer<SideData<NDIM, double> > cdata = coarse.getPatchData(src_component); #if !defined(NDEBUG) TBOX_ASSERT(fdata); TBOX_ASSERT(cdata); TBOX_ASSERT(fdata->getDepth() == cdata->getDepth()); #endif const int data_depth = fdata->getDepth(); const Box<NDIM>& fdata_box = fdata->getBox(); const int fdata_gcw = fdata->getGhostCellWidth().max(); #if !defined(NDEBUG) TBOX_ASSERT(fdata_gcw == fdata->getGhostCellWidth().min()); #endif const Box<NDIM>& cdata_box = cdata->getBox(); const int cdata_gcw = cdata->getGhostCellWidth().max(); #if !defined(NDEBUG) TBOX_ASSERT(cdata_gcw == cdata->getGhostCellWidth().min()); #endif // Refine the data. for (int depth = 0; depth < data_depth; ++depth) { CART_SIDE_RT0_REFINE_FC( #if (NDIM == 2) fdata->getPointer(0, depth), fdata->getPointer(1, depth), fdata_gcw, fdata_box.lower()(0), fdata_box.upper()(0), fdata_box.lower()(1), fdata_box.upper()(1), cdata->getPointer(0, depth), cdata->getPointer(1, depth), cdata_gcw, cdata_box.lower()(0), cdata_box.upper()(0), cdata_box.lower()(1), cdata_box.upper()(1), fine_box.lower()(0), fine_box.upper()(0), fine_box.lower()(1), fine_box.upper()(1), #endif #if (NDIM == 3) fdata->getPointer(0, depth), fdata->getPointer(1, depth), fdata->getPointer(2, depth), fdata_gcw, fdata_box.lower()(0), fdata_box.upper()(0), fdata_box.lower()(1), fdata_box.upper()(1), fdata_box.lower()(2), fdata_box.upper()(2), cdata->getPointer(0, depth), cdata->getPointer(1, depth), cdata->getPointer(2, depth), cdata_gcw, cdata_box.lower()(0), cdata_box.upper()(0), cdata_box.lower()(1), cdata_box.upper()(1), cdata_box.lower()(2), cdata_box.upper()(2), fine_box.lower()(0), fine_box.upper()(0), fine_box.lower()(1), fine_box.upper()(1), fine_box.lower()(2), fine_box.upper()(2), #endif ratio); } return; } // refine
/******************************************************************************* * For each run, the input filename must be given on the command line. In all * * cases, the command line is: * * * * executable <input file name> * * * *******************************************************************************/ int main(int argc, char* argv[]) { // Initialize PETSc, MPI, and SAMRAI. PetscInitialize(&argc, &argv, NULL, NULL); SAMRAI_MPI::setCommunicator(PETSC_COMM_WORLD); SAMRAI_MPI::setCallAbortInSerialInsteadOfExit(); SAMRAIManager::startup(); { // cleanup dynamically allocated objects prior to shutdown // Parse command line options, set some standard options from the input // file, and enable file logging. Pointer<AppInitializer> app_initializer = new AppInitializer(argc, argv, "sc_poisson.log"); Pointer<Database> input_db = app_initializer->getInputDatabase(); // Create major algorithm and data objects that comprise the // application. These objects are configured from the input database. Pointer<CartesianGridGeometry<NDIM> > grid_geometry = new CartesianGridGeometry<NDIM>( "CartesianGeometry", app_initializer->getComponentDatabase("CartesianGeometry")); Pointer<PatchHierarchy<NDIM> > patch_hierarchy = new PatchHierarchy<NDIM>("PatchHierarchy", grid_geometry); Pointer<StandardTagAndInitialize<NDIM> > error_detector = new StandardTagAndInitialize<NDIM>( "StandardTagAndInitialize", NULL, app_initializer->getComponentDatabase("StandardTagAndInitialize")); Pointer<BergerRigoutsos<NDIM> > box_generator = new BergerRigoutsos<NDIM>(); Pointer<LoadBalancer<NDIM> > load_balancer = new LoadBalancer<NDIM>("LoadBalancer", app_initializer->getComponentDatabase("LoadBalancer")); Pointer<GriddingAlgorithm<NDIM> > gridding_algorithm = new GriddingAlgorithm<NDIM>("GriddingAlgorithm", app_initializer->getComponentDatabase("GriddingAlgorithm"), error_detector, box_generator, load_balancer); // Create variables and register them with the variable database. VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); Pointer<VariableContext> ctx = var_db->getContext("context"); Pointer<SideVariable<NDIM, double> > u_sc_var = new SideVariable<NDIM, double>("u_sc"); Pointer<SideVariable<NDIM, double> > f_sc_var = new SideVariable<NDIM, double>("f_sc"); Pointer<SideVariable<NDIM, double> > e_sc_var = new SideVariable<NDIM, double>("e_sc"); Pointer<SideVariable<NDIM, double> > r_sc_var = new SideVariable<NDIM, double>("r_sc"); const int u_sc_idx = var_db->registerVariableAndContext(u_sc_var, ctx, IntVector<NDIM>(1)); const int f_sc_idx = var_db->registerVariableAndContext(f_sc_var, ctx, IntVector<NDIM>(1)); const int e_sc_idx = var_db->registerVariableAndContext(e_sc_var, ctx, IntVector<NDIM>(1)); const int r_sc_idx = var_db->registerVariableAndContext(r_sc_var, ctx, IntVector<NDIM>(1)); Pointer<CellVariable<NDIM, double> > u_cc_var = new CellVariable<NDIM, double>("u_cc", NDIM); Pointer<CellVariable<NDIM, double> > f_cc_var = new CellVariable<NDIM, double>("f_cc", NDIM); Pointer<CellVariable<NDIM, double> > e_cc_var = new CellVariable<NDIM, double>("e_cc", NDIM); Pointer<CellVariable<NDIM, double> > r_cc_var = new CellVariable<NDIM, double>("r_cc", NDIM); const int u_cc_idx = var_db->registerVariableAndContext(u_cc_var, ctx, IntVector<NDIM>(0)); const int f_cc_idx = var_db->registerVariableAndContext(f_cc_var, ctx, IntVector<NDIM>(0)); const int e_cc_idx = var_db->registerVariableAndContext(e_cc_var, ctx, IntVector<NDIM>(0)); const int r_cc_idx = var_db->registerVariableAndContext(r_cc_var, ctx, IntVector<NDIM>(0)); // Register variables for plotting. Pointer<VisItDataWriter<NDIM> > visit_data_writer = app_initializer->getVisItDataWriter(); TBOX_ASSERT(visit_data_writer); visit_data_writer->registerPlotQuantity(u_cc_var->getName(), "VECTOR", u_cc_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(u_cc_var->getName() + stream.str(), "SCALAR", u_cc_idx, d); } visit_data_writer->registerPlotQuantity(f_cc_var->getName(), "VECTOR", f_cc_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(f_cc_var->getName() + stream.str(), "SCALAR", f_cc_idx, d); } visit_data_writer->registerPlotQuantity(e_cc_var->getName(), "VECTOR", e_cc_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(e_cc_var->getName() + stream.str(), "SCALAR", e_cc_idx, d); } visit_data_writer->registerPlotQuantity(r_cc_var->getName(), "VECTOR", r_cc_idx); for (unsigned int d = 0; d < NDIM; ++d) { ostringstream stream; stream << d; visit_data_writer->registerPlotQuantity(r_cc_var->getName() + stream.str(), "SCALAR", r_cc_idx, d); } // Initialize the AMR patch hierarchy. gridding_algorithm->makeCoarsestLevel(patch_hierarchy, 0.0); int tag_buffer = 1; int level_number = 0; bool done = false; while (!done && (gridding_algorithm->levelCanBeRefined(level_number))) { gridding_algorithm->makeFinerLevel(patch_hierarchy, 0.0, 0.0, tag_buffer); done = !patch_hierarchy->finerLevelExists(level_number); ++level_number; } // Allocate data on each level of the patch hierarchy. for (int ln = 0; ln <= patch_hierarchy->getFinestLevelNumber(); ++ln) { Pointer<PatchLevel<NDIM> > level = patch_hierarchy->getPatchLevel(ln); level->allocatePatchData(u_sc_idx, 0.0); level->allocatePatchData(f_sc_idx, 0.0); level->allocatePatchData(e_sc_idx, 0.0); level->allocatePatchData(r_sc_idx, 0.0); level->allocatePatchData(u_cc_idx, 0.0); level->allocatePatchData(f_cc_idx, 0.0); level->allocatePatchData(e_cc_idx, 0.0); level->allocatePatchData(r_cc_idx, 0.0); } // Setup vector objects. HierarchyMathOps hier_math_ops("hier_math_ops", patch_hierarchy); const int h_sc_idx = hier_math_ops.getSideWeightPatchDescriptorIndex(); SAMRAIVectorReal<NDIM, double> u_vec("u", patch_hierarchy, 0, patch_hierarchy->getFinestLevelNumber()); SAMRAIVectorReal<NDIM, double> f_vec("f", patch_hierarchy, 0, patch_hierarchy->getFinestLevelNumber()); SAMRAIVectorReal<NDIM, double> e_vec("e", patch_hierarchy, 0, patch_hierarchy->getFinestLevelNumber()); SAMRAIVectorReal<NDIM, double> r_vec("r", patch_hierarchy, 0, patch_hierarchy->getFinestLevelNumber()); u_vec.addComponent(u_sc_var, u_sc_idx, h_sc_idx); f_vec.addComponent(f_sc_var, f_sc_idx, h_sc_idx); e_vec.addComponent(e_sc_var, e_sc_idx, h_sc_idx); r_vec.addComponent(r_sc_var, r_sc_idx, h_sc_idx); u_vec.setToScalar(0.0); f_vec.setToScalar(0.0); e_vec.setToScalar(0.0); r_vec.setToScalar(0.0); // Setup exact solutions. muParserCartGridFunction u_fcn("u", app_initializer->getComponentDatabase("u"), grid_geometry); muParserCartGridFunction f_fcn("f", app_initializer->getComponentDatabase("f"), grid_geometry); u_fcn.setDataOnPatchHierarchy(e_sc_idx, e_sc_var, patch_hierarchy, 0.0); f_fcn.setDataOnPatchHierarchy(f_sc_idx, f_sc_var, patch_hierarchy, 0.0); // Setup the Poisson solver. PoissonSpecifications poisson_spec("poisson_spec"); poisson_spec.setCConstant(0.0); poisson_spec.setDConstant(-1.0); vector<RobinBcCoefStrategy<NDIM>*> bc_coefs(NDIM, static_cast<RobinBcCoefStrategy<NDIM>*>(NULL)); SCLaplaceOperator laplace_op("laplace_op"); laplace_op.setPoissonSpecifications(poisson_spec); laplace_op.setPhysicalBcCoefs(bc_coefs); laplace_op.initializeOperatorState(u_vec, f_vec); string solver_type = input_db->getString("solver_type"); Pointer<Database> solver_db = input_db->getDatabase("solver_db"); string precond_type = input_db->getString("precond_type"); Pointer<Database> precond_db = input_db->getDatabase("precond_db"); Pointer<PoissonSolver> poisson_solver = SCPoissonSolverManager::getManager()->allocateSolver( solver_type, "poisson_solver", solver_db, "", precond_type, "poisson_precond", precond_db, ""); poisson_solver->setPoissonSpecifications(poisson_spec); poisson_solver->setPhysicalBcCoefs(bc_coefs); poisson_solver->initializeSolverState(u_vec, f_vec); // Solve -L*u = f. u_vec.setToScalar(0.0); poisson_solver->solveSystem(u_vec, f_vec); // Compute error and print error norms. e_vec.subtract(Pointer<SAMRAIVectorReal<NDIM, double> >(&e_vec, false), Pointer<SAMRAIVectorReal<NDIM, double> >(&u_vec, false)); pout << "|e|_oo = " << e_vec.maxNorm() << "\n"; pout << "|e|_2 = " << e_vec.L2Norm() << "\n"; pout << "|e|_1 = " << e_vec.L1Norm() << "\n"; // Compute the residual and print residual norms. laplace_op.apply(u_vec, r_vec); r_vec.subtract(Pointer<SAMRAIVectorReal<NDIM, double> >(&f_vec, false), Pointer<SAMRAIVectorReal<NDIM, double> >(&r_vec, false)); pout << "|r|_oo = " << r_vec.maxNorm() << "\n"; pout << "|r|_2 = " << r_vec.L2Norm() << "\n"; pout << "|r|_1 = " << r_vec.L1Norm() << "\n"; // Interpolate the side-centered data to cell centers for output. static const bool synch_cf_interface = true; hier_math_ops.interp(u_cc_idx, u_cc_var, u_sc_idx, u_sc_var, NULL, 0.0, synch_cf_interface); hier_math_ops.interp(f_cc_idx, f_cc_var, f_sc_idx, f_sc_var, NULL, 0.0, synch_cf_interface); hier_math_ops.interp(e_cc_idx, e_cc_var, e_sc_idx, e_sc_var, NULL, 0.0, synch_cf_interface); hier_math_ops.interp(r_cc_idx, r_cc_var, r_sc_idx, r_sc_var, NULL, 0.0, synch_cf_interface); // Set invalid values on coarse levels (i.e., coarse-grid values that // are covered by finer grid patches) to equal zero. for (int ln = 0; ln <= patch_hierarchy->getFinestLevelNumber() - 1; ++ln) { Pointer<PatchLevel<NDIM> > level = patch_hierarchy->getPatchLevel(ln); BoxArray<NDIM> refined_region_boxes; Pointer<PatchLevel<NDIM> > next_finer_level = patch_hierarchy->getPatchLevel(ln + 1); refined_region_boxes = next_finer_level->getBoxes(); refined_region_boxes.coarsen(next_finer_level->getRatioToCoarserLevel()); for (PatchLevel<NDIM>::Iterator p(level); p; p++) { Pointer<Patch<NDIM> > patch = level->getPatch(p()); const Box<NDIM>& patch_box = patch->getBox(); Pointer<CellData<NDIM, double> > e_cc_data = patch->getPatchData(e_cc_idx); Pointer<CellData<NDIM, double> > r_cc_data = patch->getPatchData(r_cc_idx); for (int i = 0; i < refined_region_boxes.getNumberOfBoxes(); ++i) { const Box<NDIM> refined_box = refined_region_boxes[i]; const Box<NDIM> intersection = Box<NDIM>::grow(patch_box, 1) * refined_box; if (!intersection.empty()) { e_cc_data->fillAll(0.0, intersection); r_cc_data->fillAll(0.0, intersection); } } } } // Output data for plotting. visit_data_writer->writePlotData(patch_hierarchy, 0, 0.0); } // cleanup dynamically allocated objects prior to shutdown SAMRAIManager::shutdown(); PetscFinalize(); return 0; } // main
void CellComplexLinearTimeInterpolateOp::timeInterpolate( hier::PatchData& dst_data, const hier::Box& where, const hier::PatchData& src_data_old, const hier::PatchData& src_data_new) const { const tbox::Dimension& dim(where.getDim()); const CellData<dcomplex>* old_dat = CPP_CAST<const CellData<dcomplex> *>(&src_data_old); const CellData<dcomplex>* new_dat = CPP_CAST<const CellData<dcomplex> *>(&src_data_new); CellData<dcomplex>* dst_dat = CPP_CAST<CellData<dcomplex> *>(&dst_data); TBOX_ASSERT(old_dat != 0); TBOX_ASSERT(new_dat != 0); TBOX_ASSERT(dst_dat != 0); TBOX_ASSERT((where * old_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT((where * new_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT((where * dst_dat->getGhostBox()).isSpatiallyEqual(where)); TBOX_ASSERT_OBJDIM_EQUALITY4(dst_data, where, src_data_old, src_data_new); const hier::Index& old_ilo = old_dat->getGhostBox().lower(); const hier::Index& old_ihi = old_dat->getGhostBox().upper(); const hier::Index& new_ilo = new_dat->getGhostBox().lower(); const hier::Index& new_ihi = new_dat->getGhostBox().upper(); const hier::Index& dst_ilo = dst_dat->getGhostBox().lower(); const hier::Index& dst_ihi = dst_dat->getGhostBox().upper(); const hier::Index& ifirst = where.lower(); const hier::Index& ilast = where.upper(); const double old_time = old_dat->getTime(); const double new_time = new_dat->getTime(); const double dst_time = dst_dat->getTime(); TBOX_ASSERT((old_time < dst_time || tbox::MathUtilities<double>::equalEps(old_time, dst_time)) && (dst_time < new_time || tbox::MathUtilities<double>::equalEps(dst_time, new_time))); double tfrac = dst_time - old_time; double denom = new_time - old_time; if (denom > tbox::MathUtilities<double>::getMin()) { tfrac /= denom; } else { tfrac = 0.0; } for (int d = 0; d < dst_dat->getDepth(); ++d) { if (dim == tbox::Dimension(1)) { SAMRAI_F77_FUNC(lintimeintcellcmplx1d, LINTIMEINTCELLCMPLX1D) (ifirst(0), ilast(0), old_ilo(0), old_ihi(0), new_ilo(0), new_ihi(0), dst_ilo(0), dst_ihi(0), tfrac, old_dat->getPointer(d), new_dat->getPointer(d), dst_dat->getPointer(d)); } else if (dim == tbox::Dimension(2)) { SAMRAI_F77_FUNC(lintimeintcellcmplx2d, LINTIMEINTCELLCMPLX2D) (ifirst(0), ifirst(1), ilast(0), ilast(1), old_ilo(0), old_ilo(1), old_ihi(0), old_ihi(1), new_ilo(0), new_ilo(1), new_ihi(0), new_ihi(1), dst_ilo(0), dst_ilo(1), dst_ihi(0), dst_ihi(1), tfrac, old_dat->getPointer(d), new_dat->getPointer(d), dst_dat->getPointer(d)); } else if (dim == tbox::Dimension(3)) { SAMRAI_F77_FUNC(lintimeintcellcmplx3d, LINTIMEINTCELLCMPLX3D) (ifirst(0), ifirst(1), ifirst(2), ilast(0), ilast(1), ilast(2), old_ilo(0), old_ilo(1), old_ilo(2), old_ihi(0), old_ihi(1), old_ihi(2), new_ilo(0), new_ilo(1), new_ilo(2), new_ihi(0), new_ihi(1), new_ihi(2), dst_ilo(0), dst_ilo(1), dst_ilo(2), dst_ihi(0), dst_ihi(1), dst_ihi(2), tfrac, old_dat->getPointer(d), new_dat->getPointer(d), dst_dat->getPointer(d)); } else { TBOX_ERROR( "CellComplexLinearTimeInterpolateOp::TimeInterpolate dim > 3 not supported" << std::endl); } } }
FlattenedHierarchy::FlattenedHierarchy( const PatchHierarchy& hierarchy, int coarsest_level, int finest_level) : d_coarsest_level(coarsest_level), d_finest_level(finest_level), d_patch_hierarchy(&hierarchy) { int num_levels = hierarchy.getNumberOfLevels(); TBOX_ASSERT(coarsest_level >= 0); TBOX_ASSERT(coarsest_level <= finest_level); TBOX_ASSERT(finest_level < num_levels); d_visible_boxes.resize(num_levels); LocalId local_id(0); for (int ln = finest_level; ln >= coarsest_level; --ln) { const std::shared_ptr<PatchLevel>& current_level = hierarchy.getPatchLevel(ln); if (ln != finest_level) { const Connector& coarse_to_fine = current_level->findConnector( *(hierarchy.getPatchLevel(ln+1)), IntVector::getOne(hierarchy.getDim()), CONNECTOR_IMPLICIT_CREATION_RULE, true); const IntVector& connector_ratio = coarse_to_fine.getRatio(); for (PatchLevel::iterator ip(current_level->begin()); ip != current_level->end(); ++ip) { const std::shared_ptr<Patch>& patch = *ip; const Box& box = patch->getBox(); const BlockId& block_id = box.getBlockId(); const BoxId& box_id = box.getBoxId(); BoxContainer& visible_boxes = d_visible_boxes[ln][box_id]; BoxContainer coarse_boxes(box); BoxContainer fine_nbr_boxes; if (coarse_to_fine.hasNeighborSet(box_id)) { coarse_to_fine.getNeighborBoxes(box_id, fine_nbr_boxes); } if (!fine_nbr_boxes.empty()) { BoxContainer fine_boxes; for (SAMRAI::hier::RealBoxConstIterator nbr_itr = fine_nbr_boxes.realBegin(); nbr_itr != fine_nbr_boxes.realEnd(); ++nbr_itr) { if (nbr_itr->getBlockId() == block_id) { fine_boxes.pushBack(*nbr_itr); } } fine_boxes.coarsen(connector_ratio); coarse_boxes.removeIntersections(fine_boxes); coarse_boxes.coalesce(); } for (BoxContainer::iterator itr = coarse_boxes.begin(); itr != coarse_boxes.end(); ++itr) { Box new_box(*itr, local_id, box_id.getOwnerRank()); ++local_id; visible_boxes.insert(visible_boxes.end(), new_box); } } } else { for (PatchLevel::iterator ip(current_level->begin()); ip != current_level->end(); ++ip) { const std::shared_ptr<Patch>& patch = *ip; const Box& box = patch->getBox(); const BoxId& box_id = box.getBoxId(); BoxContainer& visible_boxes = d_visible_boxes[ln][box_id]; Box new_box(box, local_id, box.getOwnerRank()); ++local_id; visible_boxes.insert(visible_boxes.end(), new_box); } } } }
void Stokes::V_Coarsen_Patch_Strategy::postprocessCoarsen_2D (SAMRAI::hier::Patch& coarse, const SAMRAI::hier::Patch& fine, const SAMRAI::hier::Box& , const SAMRAI::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 std::vector<SAMRAI::hier::BoundaryBox> &boundaries=coarse_fine[fine.getPatchLevelNumber()]->getEdgeBoundaries(coarse.getGlobalId()); boost::shared_ptr<SAMRAI::pdat::SideData<double> > v_fine = boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (fine.getPatchData(v_id)); boost::shared_ptr<SAMRAI::pdat::SideData<double> > v = boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> > (coarse.getPatchData(v_id)); TBOX_ASSERT(v); TBOX_ASSERT(v_fine); TBOX_ASSERT(v_fine->getDepth() == v->getDepth()); TBOX_ASSERT(v->getDepth() == 1); SAMRAI::hier::Box gbox(v_fine->getGhostBox()); SAMRAI::hier::Index ip(1,0), jp(0,1); for(size_t mm=0; mm<boundaries.size(); ++mm) { SAMRAI::hier::Box bbox=boundaries[mm].getBox(); int location_index=boundaries[mm].getLocationIndex(); SAMRAI::hier::Index lower=SAMRAI::hier::Index::coarsen(bbox.lower(), SAMRAI::hier::Index(2,2)), upper=SAMRAI::hier::Index::coarsen(bbox.upper(), SAMRAI::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) { SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0, SAMRAI::pdat::SideIndex::Upper); SAMRAI::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) { SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0, SAMRAI::pdat::SideIndex::Lower); SAMRAI::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) { SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1, SAMRAI::pdat::SideIndex::Upper); SAMRAI::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) { SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1, SAMRAI::pdat::SideIndex::Lower); SAMRAI::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(); } } } }
void INSCollocatedVelocityBcCoef::setBcCoefs(Pointer<ArrayData<NDIM, double> >& acoef_data, Pointer<ArrayData<NDIM, double> >& bcoef_data, Pointer<ArrayData<NDIM, double> >& gcoef_data, const Pointer<Variable<NDIM> >& variable, const Patch<NDIM>& patch, const BoundaryBox<NDIM>& bdry_box, double fill_time) const { #if !defined(NDEBUG) for (unsigned int d = 0; d < NDIM; ++d) { TBOX_ASSERT(d_bc_coefs[d]); } #endif // Set the unmodified velocity bc coefs. d_bc_coefs[d_comp_idx]->setBcCoefs( acoef_data, bcoef_data, gcoef_data, variable, patch, bdry_box, fill_time); // We do not make any further modifications to the values of acoef_data and // bcoef_data beyond this point. if (!gcoef_data) return; #if !defined(NDEBUG) TBOX_ASSERT(acoef_data); TBOX_ASSERT(bcoef_data); #endif // Ensure homogeneous boundary conditions are enforced. if (d_homogeneous_bc) gcoef_data->fillAll(0.0); // Where appropriate, update boundary condition coefficients. // // Dirichlet boundary conditions are not modified. // // Neumann boundary conditions on the normal component of the velocity are // interpreted as "open" boundary conditions, and we set du/dn = 0. // // Neumann boundary conditions on the tangential component of the velocity // are interpreted as traction (stress) boundary conditions, and we update // the boundary condition coefficients accordingly. const unsigned int location_index = bdry_box.getLocationIndex(); const unsigned int bdry_normal_axis = location_index / 2; const bool is_lower = location_index % 2 == 0; const Box<NDIM>& bc_coef_box = acoef_data->getBox(); #if !defined(NDEBUG) TBOX_ASSERT(bc_coef_box == acoef_data->getBox()); TBOX_ASSERT(bc_coef_box == bcoef_data->getBox()); TBOX_ASSERT(bc_coef_box == gcoef_data->getBox()); #endif const double mu = d_problem_coefs->getMu(); for (Box<NDIM>::Iterator it(bc_coef_box); it; it++) { const Index<NDIM>& i = it(); double& alpha = (*acoef_data)(i, 0); double& beta = (*bcoef_data)(i, 0); double& gamma = (*gcoef_data)(i, 0); const bool velocity_bc = MathUtilities<double>::equalEps(alpha, 1.0); const bool traction_bc = MathUtilities<double>::equalEps(beta, 1.0); #if !defined(NDEBUG) TBOX_ASSERT((velocity_bc || traction_bc) && !(velocity_bc && traction_bc)); #endif if (velocity_bc) { alpha = 1.0; beta = 0.0; } else if (traction_bc) { if (d_comp_idx == bdry_normal_axis) { // Set du/dn = 0. // // NOTE: We would prefer to determine the ghost cell value of // the normal velocity so that div u = 0 in the ghost cell. // This could be done here, but it is more convenient to do so // as a post-processing step after the tangential velocity ghost // cell values have all been set. alpha = 0.0; beta = 1.0; gamma = 0.0; } else { switch (d_traction_bc_type) { case PSEUDO_TRACTION: // mu*du_tan/dx_norm = g. { alpha = 0.0; beta = 1.0; gamma = (is_lower ? -1.0 : +1.0) * (gamma / mu); break; } default: { TBOX_ERROR( "INSCollocatedVelocityBcCoef::setBcCoefs(): unrecognized or " "unsupported " "traction boundary condition type: " << enum_to_string<TractionBcType>(d_traction_bc_type) << "\n"); } } } } else { TBOX_ERROR("this statement should not be reached!\n"); } } return; } // setBcCoefs
void StaggeredStokesOperator::initializeOperatorState(const SAMRAIVectorReal<NDIM, double>& in, const SAMRAIVectorReal<NDIM, double>& out) { IBAMR_TIMER_START(t_initialize_operator_state); // Deallocate the operator state if the operator is already initialized. if (d_is_initialized) deallocateOperatorState(); // Setup solution and rhs vectors. d_x = in.cloneVector(in.getName()); d_b = out.cloneVector(out.getName()); d_x->allocateVectorData(); // Setup the interpolation transaction information. d_U_fill_pattern = new SideNoCornersFillPattern(SIDEG, false, false, true); d_P_fill_pattern = new CellNoCornersFillPattern(CELLG, false, false, true); typedef HierarchyGhostCellInterpolation::InterpolationTransactionComponent InterpolationTransactionComponent; d_transaction_comps.resize(2); d_transaction_comps[0] = InterpolationTransactionComponent(d_x->getComponentDescriptorIndex(0), in.getComponentDescriptorIndex(0), DATA_REFINE_TYPE, USE_CF_INTERPOLATION, DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY, d_U_bc_coefs, d_U_fill_pattern); d_transaction_comps[1] = InterpolationTransactionComponent(in.getComponentDescriptorIndex(1), DATA_REFINE_TYPE, USE_CF_INTERPOLATION, DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY, d_P_bc_coef, d_P_fill_pattern); // Initialize the interpolation operators. d_hier_bdry_fill = new HierarchyGhostCellInterpolation(); d_hier_bdry_fill->initializeOperatorState(d_transaction_comps, d_x->getPatchHierarchy()); // Initialize hierarchy math ops object. if (!d_hier_math_ops_external) { d_hier_math_ops = new HierarchyMathOps(d_object_name + "::HierarchyMathOps", in.getPatchHierarchy(), in.getCoarsestLevelNumber(), in.getFinestLevelNumber()); } #if !defined(NDEBUG) else { TBOX_ASSERT(d_hier_math_ops); } #endif // Indicate the operator is initialized. d_is_initialized = true; IBAMR_TIMER_STOP(t_initialize_operator_state); return; } // initializeOperatorState