Beispiel #1
0
double
NormOps::L2Norm_local(
    const SAMRAIVectorReal<NDIM,double>* const samrai_vector)
{
    std::vector<double> L2_norm_local_patch;
    Pointer<PatchHierarchy<NDIM> > hierarchy = samrai_vector->getPatchHierarchy();
    const int coarsest_ln = samrai_vector->getCoarsestLevelNumber();
    const int finest_ln = samrai_vector->getFinestLevelNumber();
    const int ncomp = samrai_vector->getNumberOfComponents();
    for (int comp = 0; comp < ncomp; ++comp)
    {
        const Pointer<Variable<NDIM> >& comp_var = samrai_vector->getComponentVariable(comp);
        const int comp_idx = samrai_vector->getComponentDescriptorIndex(comp);
        const int cvol_idx = samrai_vector->getControlVolumeIndex(comp);
        const bool has_cvol = cvol_idx >= 0;

        Pointer<CellVariable<NDIM,double> > comp_cc_var = comp_var;
        const bool cell_centered = !comp_cc_var.isNull();
        if (cell_centered)
        {
            PatchCellDataNormOpsReal<NDIM,double> patch_ops;
            for (int ln = coarsest_ln; ln <= finest_ln; ++ln)
            {
                Pointer<PatchLevel<NDIM> > level = hierarchy->getPatchLevel(ln);
                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> > comp_data = patch->getPatchData(comp_idx);
                    Pointer<CellData<NDIM,double> > cvol_data = (has_cvol ? patch->getPatchData(cvol_idx) : Pointer<PatchData<NDIM> >(NULL));
                    L2_norm_local_patch.push_back(patch_ops.L2Norm(comp_data, patch_box, cvol_data));
                }
            }
        }

        Pointer<SideVariable<NDIM,double> > comp_sc_var = comp_var;
        const bool side_centered = !comp_sc_var.isNull();
        if (side_centered)
        {
            PatchSideDataNormOpsReal<NDIM,double> patch_ops;
            for (int ln = coarsest_ln; ln <= finest_ln; ++ln)
            {
                Pointer<PatchLevel<NDIM> > level = hierarchy->getPatchLevel(ln);
                for (PatchLevel<NDIM>::Iterator p(level); p; p++)
                {
                    Pointer<Patch<NDIM> > patch = level->getPatch(p());
                    const Box<NDIM>& patch_box = patch->getBox();
                    Pointer<SideData<NDIM,double> > comp_data = patch->getPatchData(comp_idx);
                    Pointer<SideData<NDIM,double> > cvol_data = (has_cvol ? patch->getPatchData(cvol_idx) : Pointer<PatchData<NDIM> >(NULL));
                    L2_norm_local_patch.push_back(patch_ops.L2Norm(comp_data, patch_box, cvol_data));
                }
            }
        }
    }
    return std::sqrt(accurate_sum_of_squares(L2_norm_local_patch));
}// L2Norm_local
Beispiel #2
0
double NormOps::L2Norm(const SAMRAIVectorReal<NDIM, double>* const samrai_vector, const bool local_only)
{
    const double L2_norm_local = L2Norm_local(samrai_vector);
    if (local_only) return L2_norm_local;

    const int nprocs = SAMRAI_MPI::getNodes();
    std::vector<double> L2_norm_proc(nprocs, 0.0);
    SAMRAI_MPI::allGather(L2_norm_local, &L2_norm_proc[0]);
    const double ret_val = std::sqrt(accurate_sum_of_squares(L2_norm_proc));
    return ret_val;
} // L2Norm