Exemple #1
0
    def error_norm(self, N, n_mg):
        "Return the infinity norm of errors for the u component."
        geometry, enthalpy, yield_stress = self.inputs(N)

        # set the number of multigrid levels
        self.opt.setValue("-bp_pc_mg_levels", n_mg)

        grid = enthalpy.grid()

        blatter_Mz = N
        coarsening_factor = 4

        model = PISM.BlatterTestXZ(grid, blatter_Mz, coarsening_factor)

        model.init()

        inputs = PISM.StressBalanceInputs()

        inputs.geometry = geometry
        inputs.basal_yield_stress = yield_stress
        inputs.enthalpy = enthalpy

        # run the solver
        model.update(inputs, True)

        u_model_z = model.velocity_u_sigma().levels()

        u_model = PISM.IceModelVec3(grid, "u_model", PISM.WITHOUT_GHOSTS,
                                    u_model_z)
        u_model.set_attrs("model", "modeled velocity", "m / s", "m / year", "",
                          0)
        u_model.copy_from(model.velocity_u_sigma())

        u_exact = self.exact_solution(grid, geometry.bed_elevation, u_model_z)

        # compute the error
        u_error = PISM.IceModelVec3(grid, "error", PISM.WITHOUT_GHOSTS,
                                    u_model_z)
        u_error.copy_from(u_exact)
        u_error.add(-1.0, model.velocity_u_sigma())

        return u_error.norm(PISM.PETSc.NormType.NORM_INFINITY)[0]