Exemplo n.º 1
0
    def residualVectorAndNorm(self,
                              var=None,
                              solver=None,
                              boundaryConditions=(),
                              dt=None,
                              underRelaxation=None,
                              residualFn=None):
        r"""
        Builds the `Term`'s linear system once. This method
        also recalculates and returns the residual as well as applying
        under-relaxation.

        :Parameters:

           - `var`: The variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
           - `solver`: The iterative solver to be used to solve the linear system of equations. Defaults to `LinearPCGSolver` for Pysparse and `LinearLUSolver` for Trilinos.
           - `boundaryConditions`: A tuple of boundaryConditions.
           - `dt`: The time step size.
           - `underRelaxation`: Usually a value between `0` and `1` or `None` in the case of no under-relaxation
           - `residualFn`: A function that takes var, matrix, and RHSvector arguments used to customize the residual calculation.

        """
        vector = self.justResidualVector(var=var,
                                         solver=solver,
                                         boundaryConditions=boundaryConditions,
                                         dt=dt,
                                         underRelaxation=underRelaxation,
                                         residualFn=residualFn)

        L2norm = numerix.L2norm(vector)

        return vector, L2norm
Exemplo n.º 2
0
    def residualVectorAndNorm(self,
                              var=None,
                              solver=None,
                              boundaryConditions=(),
                              dt=None,
                              underRelaxation=None,
                              residualFn=None):
        r"""Builds the `Term`'s linear system once.

        This method also recalculates and returns the residual as well as
        applying under-relaxation.

        Parameters
        ----------
        var : ~fipy.variables.cellVariable.CellVariable
            `Variable` to be solved for.  Provides the initial condition,
            the old value and holds the solution on completion.
        solver : ~fipy.solvers.solver.Solver
            Iterative solver to be used to solve the linear system of
            equations.  The default sovler depends on the solver package
            selected.
        boundaryConditions : :obj:`tuple` of :obj:`~fipy.boundaryConditions.boundaryCondition.BoundaryCondition`
        dt : float
            Timestep size.
        underRelaxation : float
            Usually a value between `0` and `1` or `None` in the case of no
            under-relaxation
        residualFn : function
            Takes `var`, `matrix`, and `RHSvector` arguments, used to
            customize the residual calculation.
        """
        vector = self.justResidualVector(var=var,
                                         solver=solver,
                                         boundaryConditions=boundaryConditions,
                                         dt=dt,
                                         underRelaxation=underRelaxation,
                                         residualFn=residualFn)

        L2norm = numerix.L2norm(vector)

        return vector, L2norm
Exemplo n.º 3
0
    mesh = Gmsh2D(geo, background=monitor)

    charge = CellVariable(mesh=mesh, name=r"$\rho$", value=0.)
    charge.setValue(+1, where=mesh.physicalCells["Anode"])
    charge.setValue(-1, where=mesh.physicalCells["Cathode"])

    potential = CellVariable(mesh=mesh, name=r"$\psi$")
    potential.constrain(0., where=mesh.physicalFaces["Ground"])

    eq = DiffusionTerm(coeff=1.) == -charge

    res0 = eq.sweep(var=potential)

    res = eq.justResidualVector(var=potential)

    res1 = numerix.L2norm(res)
    res1a = CellVariable(mesh=mesh, value=abs(res))

    res = CellVariable(mesh=mesh, name="residual", value=abs(res) / mesh.cellVolumes**(1./mesh.dim) / 1e-3)

    # want cells no bigger than 1 and no smaller than 0.001
    maxSize = 1.
    minSize = 0.001
    monitor = CellVariable(mesh=mesh, name="monitor", value= 1. / (res + maxSize) +  minSize)

    viewer = Viewer(vars=potential, xmin=3.5, xmax=4.5, ymin=3.5, ymax=4.5)
#     viewer = Viewer(vars=(potential, charge))
    viewer.plot()

#     resviewer = Viewer(vars=res1a, log=True, datamin=1e-6, datamax=1e-2, cmap=cm.gray)
#     monviewer = Viewer(vars=monitor, log=True, datamin=1e-3, datamax=1)
Exemplo n.º 4
0
 def Norm2(self, vec):
     from fipy.tools import numerix
     return numerix.L2norm(numerix.asarray(vec))
Exemplo n.º 5
0
 def _calcRHSNorm(self):
     return numerix.L2norm(self.RHSvector)
Exemplo n.º 6
0
 def _calcResidual(self, residualFn=None):
     if residualFn is not None:
         return residualFn(self.var, self.matrix, self.RHSvector)
     else:
         return numerix.L2norm(self._calcResidualVector())
Exemplo n.º 7
0
 def Norm2(self, vec):
     return numerix.L2norm(vec)
Exemplo n.º 8
0
 def Norm2(self, vec):
     return numerix.L2norm(numerix.asarray(vec))