Ejemplo n.º 1
0
void LIndexSetData<T>::cacheLocalIndices(Pointer<Patch<NDIM> > patch, const IntVector<NDIM>& periodic_shift)
{
    d_lag_indices.clear();
    d_interior_lag_indices.clear();
    d_ghost_lag_indices.clear();
    d_global_petsc_indices.clear();
    d_interior_global_petsc_indices.clear();
    d_ghost_global_petsc_indices.clear();
    d_local_petsc_indices.clear();
    d_interior_local_petsc_indices.clear();
    d_ghost_local_petsc_indices.clear();
    d_periodic_shifts.clear();
    d_interior_periodic_shifts.clear();
    d_ghost_periodic_shifts.clear();

    const Box<NDIM>& patch_box = patch->getBox();
    const Index<NDIM>& ilower = patch_box.lower();
    const Index<NDIM>& iupper = patch_box.upper();

    const Pointer<CartesianPatchGeometry<NDIM> > pgeom = patch->getPatchGeometry();
    const double* const dx = pgeom->getDx();
    boost::array<bool, NDIM> patch_touches_lower_periodic_bdry, patch_touches_upper_periodic_bdry;
    for (unsigned int axis = 0; axis < NDIM; ++axis)
    {
        patch_touches_lower_periodic_bdry[axis] = pgeom->getTouchesPeriodicBoundary(axis, 0);
        patch_touches_upper_periodic_bdry[axis] = pgeom->getTouchesPeriodicBoundary(axis, 1);
    }

    for (typename LSetData<T>::SetIterator it(*this); it; it++)
    {
        const CellIndex<NDIM>& i = it.getIndex();
        boost::array<int, NDIM> offset;
        for (unsigned int d = 0; d < NDIM; ++d)
        {
            if (patch_touches_lower_periodic_bdry[d] && i(d) < ilower(d))
            {
                offset[d] = -periodic_shift(d); // X is ABOVE the top    of the patch --- need
                                                // to shift DOWN
            }
            else if (patch_touches_upper_periodic_bdry[d] && i(d) > iupper(d))
            {
                offset[d] = +periodic_shift(d); // X is BELOW the bottom of the patch --- need to shift UP
            }
            else
            {
                offset[d] = 0;
            }
        }
        const LSet<T>& idx_set = *it;
        const bool patch_owns_idx_set = patch_box.contains(i);
        for (typename LSet<T>::const_iterator n = idx_set.begin(); n != idx_set.end(); ++n)
        {
            const typename LSet<T>::value_type& idx = *n;
            const int lag_idx = idx->getLagrangianIndex();
            const int global_petsc_idx = idx->getGlobalPETScIndex();
            const int local_petsc_idx = idx->getLocalPETScIndex();
            d_lag_indices.push_back(lag_idx);
            d_global_petsc_indices.push_back(global_petsc_idx);
            d_local_petsc_indices.push_back(local_petsc_idx);
            for (unsigned int d = 0; d < NDIM; ++d)
            {
                d_periodic_shifts.push_back(static_cast<double>(offset[d]) * dx[d]);
            }
            if (patch_owns_idx_set)
            {
                d_interior_lag_indices.push_back(lag_idx);
                d_interior_global_petsc_indices.push_back(global_petsc_idx);
                d_interior_local_petsc_indices.push_back(local_petsc_idx);
                for (unsigned int d = 0; d < NDIM; ++d)
                {
                    d_interior_periodic_shifts.push_back(static_cast<double>(offset[d]) * dx[d]);
                }
            }
            else
            {
                d_ghost_lag_indices.push_back(lag_idx);
                d_ghost_global_petsc_indices.push_back(global_petsc_idx);
                d_ghost_local_petsc_indices.push_back(local_petsc_idx);
                for (unsigned int d = 0; d < NDIM; ++d)
                {
                    d_ghost_periodic_shifts.push_back(static_cast<double>(offset[d]) * dx[d]);
                }
            }
        }
    }
    return;
} // cacheLocalIndices
Ejemplo n.º 2
0
void
AdvDiffHypPatchOps::conservativeDifferenceOnPatch(
    Patch<NDIM>& patch,
    const double /*time*/,
    const double dt,
    bool /*at_synchronization*/)
{
    const Box<NDIM>& patch_box = patch.getBox();
    const Index<NDIM>& ilower = patch_box.lower();
    const Index<NDIM>& iupper = patch_box.upper();

    const Pointer<CartesianPatchGeometry<NDIM> > patch_geom = patch.getPatchGeometry();
    const double* const dx = patch_geom->getDx();

    for (std::set<Pointer<CellVariable<NDIM,double> > >::const_iterator cit = d_Q_var.begin();
         cit != d_Q_var.end(); ++cit)
    {
        Pointer<CellVariable<NDIM,double> > Q_var = *cit;
        Pointer<FaceVariable<NDIM,double> > u_var = d_Q_u_map[Q_var];

        if (u_var.isNull())
        {
            Pointer<CellData<NDIM,double> > Q_data = patch.getPatchData(Q_var, getDataContext());
            Q_data->fillAll(0.0);
            continue;
        }

        const bool conservation_form = d_Q_difference_form[Q_var] == CONSERVATIVE;
        const bool u_is_div_free = d_u_is_div_free[u_var];

        Pointer<FaceVariable<NDIM,double> > flux_integral_var = d_flux_integral_var[Q_var];
        Pointer<FaceVariable<NDIM,double> > q_integral_var = d_q_integral_var[Q_var];
        Pointer<FaceVariable<NDIM,double> > u_integral_var = d_u_integral_var[u_var];

        Pointer<CellData<NDIM,double> > Q_data = patch.getPatchData(Q_var, getDataContext());
        Pointer<FaceData<NDIM,double> > flux_integral_data =
            (conservation_form
             ? patch.getPatchData(flux_integral_var, getDataContext())
             : Pointer<PatchData<NDIM> >(NULL));
        Pointer<FaceData<NDIM,double> > q_integral_data =
            (!conservation_form || !u_is_div_free
             ? patch.getPatchData(q_integral_var, getDataContext())
             : Pointer<PatchData<NDIM> >(NULL));
        Pointer<FaceData<NDIM,double> > u_integral_data =
            (!conservation_form || !u_is_div_free
             ? patch.getPatchData(u_integral_var, getDataContext())
             : Pointer<PatchData<NDIM> >(NULL));

        const IntVector<NDIM>& Q_data_ghost_cells = Q_data->getGhostCellWidth();
        const IntVector<NDIM>& flux_integral_data_ghost_cells =
            (!flux_integral_data.isNull()
             ? flux_integral_data->getGhostCellWidth()
             : 0);
        const IntVector<NDIM>& q_integral_data_ghost_cells =
            (!q_integral_data.isNull()
             ? q_integral_data->getGhostCellWidth()
             : 0);
        const IntVector<NDIM>& u_integral_data_ghost_cells =
            (!u_integral_data.isNull()
             ? u_integral_data->getGhostCellWidth()
             : 0);

        switch (d_Q_difference_form[Q_var])
        {
            case CONSERVATIVE:
            {
                for (int depth = 0; depth < Q_data->getDepth(); ++depth)
                {
                    if (u_is_div_free)
                    {
#if (NDIM == 2)
                        ADV_DIFF_CONSDIFF_FC(
                            dx,dt,
                            ilower(0),iupper(0),ilower(1),iupper(1),
                            flux_integral_data_ghost_cells(0),flux_integral_data_ghost_cells(1),
                            Q_data_ghost_cells(0),Q_data_ghost_cells(1),
                            flux_integral_data->getPointer(0,depth),
                            flux_integral_data->getPointer(1,depth),
                            Q_data->getPointer(depth));
#endif
#if (NDIM == 3)
                        ADV_DIFF_CONSDIFF_FC(
                            dx,dt,
                            ilower(0),iupper(0),ilower(1),iupper(1),ilower(2),iupper(2),
                            flux_integral_data_ghost_cells(0),flux_integral_data_ghost_cells(1),flux_integral_data_ghost_cells(2),
                            Q_data_ghost_cells(0),Q_data_ghost_cells(1),Q_data_ghost_cells(2),
                            flux_integral_data->getPointer(0,depth),
                            flux_integral_data->getPointer(1,depth),
                            flux_integral_data->getPointer(2,depth),
                            Q_data->getPointer(depth));
#endif
                    }
                    else
                    {
#if (NDIM == 2)
                        ADV_DIFF_CONSDIFFWITHDIVSOURCE_FC(
                            dx,dt,
                            ilower(0),iupper(0),ilower(1),iupper(1),
                            flux_integral_data_ghost_cells(0),flux_integral_data_ghost_cells(1),
                            q_integral_data_ghost_cells(0),q_integral_data_ghost_cells(1),
                            u_integral_data_ghost_cells(0),u_integral_data_ghost_cells(1),
                            Q_data_ghost_cells(0),Q_data_ghost_cells(1),
                            flux_integral_data->getPointer(0,depth),
                            flux_integral_data->getPointer(1,depth),
                            q_integral_data->getPointer(0,depth),
                            q_integral_data->getPointer(1,depth),
                            u_integral_data->getPointer(0),
                            u_integral_data->getPointer(1),
                            Q_data->getPointer(depth));
#endif
#if (NDIM == 3)
                        ADV_DIFF_CONSDIFFWITHDIVSOURCE_FC(
                            dx,dt,
                            ilower(0),iupper(0),ilower(1),iupper(1),ilower(2),iupper(2),
                            flux_integral_data_ghost_cells(0),flux_integral_data_ghost_cells(1),flux_integral_data_ghost_cells(2),
                            q_integral_data_ghost_cells(0),q_integral_data_ghost_cells(1),q_integral_data_ghost_cells(2),
                            u_integral_data_ghost_cells(0),u_integral_data_ghost_cells(1),u_integral_data_ghost_cells(2),
                            Q_data_ghost_cells(0),Q_data_ghost_cells(1),Q_data_ghost_cells(2),
                            flux_integral_data->getPointer(0,depth),
                            flux_integral_data->getPointer(1,depth),
                            flux_integral_data->getPointer(2,depth),
                            q_integral_data->getPointer(0,depth),
                            q_integral_data->getPointer(1,depth),
                            q_integral_data->getPointer(2,depth),
                            u_integral_data->getPointer(0),
                            u_integral_data->getPointer(1),
                            u_integral_data->getPointer(2),
                            Q_data->getPointer(depth));
#endif
                    }
                }
                break;
            }
            case ADVECTIVE:
            {
                CellData<NDIM,double> N_data(patch_box,Q_data->getDepth(),0);
                d_godunov_advector->computeAdvectiveDerivative(N_data, *u_integral_data, *q_integral_data, patch);
                PatchCellDataOpsReal<NDIM,double> patch_cc_data_ops;
                patch_cc_data_ops.scale(Q_data, -1.0/(dt*dt), Pointer<CellData<NDIM,double> >(&N_data,false), patch_box);
                break;
            }
            default:
            {
                TBOX_ERROR("AdvDiffHypPatchOps::conservativeDifferenceOnPatch():\n"
                           << "  unsupported differencing form: " << enum_to_string<ConvectiveDifferencingType>(d_Q_difference_form[Q_var]) << " \n"
                           << "  valid choices are: ADVECTIVE, CONSERVATIVE\n");
            }
        }
    }
    return;
}// conservativeDifferenceOnPatch