Beispiel #1
0
    def __init__(self, coeff = (1.,)):
        """
        Create a `DiffusionTerm`.

        :Parameters:
          - `coeff`: `Tuple` or `list` of `FaceVariables` or numbers.
          
        """
        if type(coeff) not in (type(()), type([])):
            coeff = (coeff,)

        self.order = len(coeff) * 2


        if len(coeff) > 0:
            self.nthCoeff = coeff[0]

            from fipy.variables.variable import Variable
            if not isinstance(self.nthCoeff, Variable):
                self.nthCoeff = Variable(value = self.nthCoeff)

            from fipy.variables.cellVariable import CellVariable
            if isinstance(self.nthCoeff, CellVariable):
                self.nthCoeff = self.nthCoeff.getArithmeticFaceValue()

        else:
            self.nthCoeff = None

        Term.__init__(self, coeff = coeff)
        
        if self.order > 0:
            self.lowerOrderDiffusionTerm = DiffusionTerm(coeff = coeff[1:])
Beispiel #2
0
    def __init__(self):
        self.orderedKeys = ["TransientTerm", "ExplicitDiffusionTerm", 
          "DiffusionTerm", "ConvectionTerm", "ImplicitSourceTerm", 
          "_ExplicitSourceTerm"]

        self.terms = {}
        
        for type in self.orderedKeys:
            self.terms[type] = None

        self.nonAdditiveTerms = []

	Term.__init__(self)
Beispiel #3
0
    def __init__(self, coeff=1., term=None):
        """
        Create a `_MulTerm`.

        :Parameters:
          - `coeff`: Float` or `CellVariable`.
          - `term`: A subclass of `Term`
          
        """

        Term.__init__(self, coeff=coeff)
        self.term = term

        self.uniqueID += 1
Beispiel #4
0
    def __init__(self, coeff=1.):
        if self.__class__ is CellTerm:
            raise NotImplementedError, "can't instantiate abstract base class"
            
        from fipy.variables.variable import Variable
        if not isinstance(coeff, Variable):
            from fipy.variables.constant import _Constant
            coeff = _Constant(value=coeff)

        from fipy.variables.cellVariable import CellVariable
        if ((isinstance(coeff, CellVariable) and coeff.getRank() != 0)
            or (not isinstance(coeff, CellVariable) and coeff.shape != ())):
                raise TypeError, "The coefficient must be a rank-0 CellVariable or a scalar value."

        Term.__init__(self, coeff=coeff)
        self.coeffVectors = None
        self._var = None
Beispiel #5
0
    def __init__(self, term, other):

        if not isinstance(other, Term):
            other = _ExplicitSourceTerm(coeff=other, var=term.var)

        self.term = term
        self.other = other

        if term.var is None:
            if other.var is None:
                pass
            else:
                raise ExplicitVariableError
        else:
            if other.var is None:
                if isinstance(other, _ExplicitSourceTerm):
                    other.var = term.var
                else:
                    raise ExplicitVariableError

        Term.__init__(self, var=self._vars[0])
Beispiel #6
0
    def __init__(self, term, other):

        if not isinstance(other, Term):
            other = _ExplicitSourceTerm(coeff=other, var=term.var)

        self.term = term
        self.other = other

        if term.var is None:
            if other.var is None:
                pass
            else:
                raise ExplicitVariableError
        else:
            if other.var is None:
                if isinstance(other, _ExplicitSourceTerm):
                    other.var = term.var
                else:
                    raise ExplicitVariableError

        Term.__init__(self, var=self._vars[0])
Beispiel #7
0
 def __add__(self, other):
     if isinstance(other, DiffusionTerm):
         from fipy.terms.collectedDiffusionTerm import _CollectedDiffusionTerm
         if isinstance(other, _CollectedDiffusionTerm):
             return other + self
         elif other.order == self.order and self.order <= 2:
             if self.order == 0:
                 return self
             elif self.order == 2:
                 return self.__class__(coeff=self.coeff[0] + other.coeff[0])
         else:
             term = _CollectedDiffusionTerm()
             term += self
             term += other
             return term
     else:
         return Term.__add__(self, other)
Beispiel #8
0
 def __init__(self, coeff = None):
     Term.__init__(self)
     self.geomCoeff = coeff
Beispiel #9
0
 def __init__(self, coeff=1.):
     if self.__class__ is FaceTerm:
         raise NotImplementedError, "can't instantiate abstract base class"
         
     Term.__init__(self, coeff=coeff)
     self.coeffMatrix = None
Beispiel #10
0
 def __add__(self, other):
     if self.__class__ == other.__class__:
         return self._add(other)
     else:
         return Term.__add__(self, other)