Exemplo n.º 1
0
 def __div__(self, operande):
     """
     This makes the division of two fields or the division of field
     by a scalar. It depends weither the operande is a FieldProxy
     or a simple scalar numerical value.
     """
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Division of %s by %s" %
                      (self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.div(self.__fieldHandler,
                                                 operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1. / operande
             offset = 0
             xmed.inf("Scaling %s by factor 1/%s" %
                      (self.fieldname, operande))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler,
                                                 factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 2
0
 def __add__(self, operande):
     """
     This makes the addition of two fields or the addition of a
     scalar to a field. It depends weither the operande is a
     FieldProxy or a simple scalar numerical value.
     """
     # The xmed calculator could raise exceptions coming from
     # MEDCoupling. Note that the fieldproxy instances are used
     # from within the python console, and for ergonomic reason, we
     # choose to not raise the possible exceptions to the console
     # by a clear message. Keep this in mind for unit test. You
     # have to test the return value, which should not be
     # null. This principle is applyed for all operations.
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Addition of  %s and %s"%(self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.add(self.__fieldHandler, operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1
             offset = operande
             xmed.inf("Application of the offset %s to %s" % (offset, self.fieldname))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler, factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 3
0
    def __rsub__(self, operande):
        """
        The user typed 'operande-self' where operande is not a field
        proxy. This function process the situation.
        """
        # The operande is a numerical value (because otherwise, the
        # "sub" method would have been called instead). We may apply
        # the command '(self-operande)*(-1)' to activate the __sub__
        # method of fieldpoxy.
        #
        #return (self-operande)*(-1)
        #
        # We prefer to apply a linear transformation because it can be
        # done in one single request to the med calculator.

        factor = -1
        offset = operande
        xmed.inf("Linear transformation %s%s*%s" %
                 (offset, factor, self.fieldname))
        try:
            rfieldHandler = xmed.calculator.lin(self.__fieldHandler, factor,
                                                offset)
        except SALOME.SALOME_Exception, ex:
            xmed.err(ex.details.text)
            return None
Exemplo n.º 4
0
 def __sub__(self, operande):
     """
     This makes the substraction of two fields or the substraction
     of a scalar to a field. It depends weither the operande is a
     FieldProxy or a simple scalar numerical value.
     """
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Substraction of %s by %s" %
                      (self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.sub(self.__fieldHandler,
                                                 operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1
             offset = -operande
             xmed.inf("Application of the offset %s to %s" %
                      (offset, self.fieldname))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler,
                                                 factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 5
0
 def __add__(self, operande):
     """
     This makes the addition of two fields or the addition of a
     scalar to a field. It depends weither the operande is a
     FieldProxy or a simple scalar numerical value.
     """
     # The xmed calculator could raise exceptions coming from
     # MEDCoupling. Note that the fieldproxy instances are used
     # from within the python console, and for ergonomic reason, we
     # choose to not raise the possible exceptions to the console
     # by a clear message. Keep this in mind for unit test. You
     # have to test the return value, which should not be
     # null. This principle is applyed for all operations.
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Addition of  %s and %s" %
                      (self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.add(self.__fieldHandler,
                                                 operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1
             offset = operande
             xmed.inf("Application of the offset %s to %s" %
                      (offset, self.fieldname))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler,
                                                 factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 6
0
 def dup(self):
     """
     This creates a duplicate of the field. The whole data are
     duplicated.
     """
     xmed.inf("Duplication of %s"%self.fieldname)
     try:
         rfieldHandler = xmed.calculator.dup(self.__fieldHandler)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 7
0
 def dup(self):
     """
     This creates a duplicate of the field. The whole data are
     duplicated.
     """
     xmed.inf("Duplication of %s" % self.fieldname)
     try:
         rfieldHandler = xmed.calculator.dup(self.__fieldHandler)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 8
0
 def __rdiv__(self, operande):
     """
     The user typed 'operande/self', we want to execute for each
     value of the field the operation 'operande/value'.
     """
     xmed.inf("Division of %s by %s" % (operande, self.fieldname))
     function  = "%s/u"%operande
     nbResComp = MEDOP.NBCOMP_DEFAULT
     try:
         rfieldHandler = xmed.calculator.fct(self.__fieldHandler,function,nbResComp)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 9
0
 def __rdiv__(self, operande):
     """
     The user typed 'operande/self', we want to execute for each
     value of the field the operation 'operande/value'.
     """
     xmed.inf("Division of %s by %s" % (operande, self.fieldname))
     function = "%s/u" % operande
     nbResComp = MEDOP.NBCOMP_DEFAULT
     try:
         rfieldHandler = xmed.calculator.fct(self.__fieldHandler, function,
                                             nbResComp)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 10
0
 def __setattr__(self, name, value):
     """
     This method realizes the write proxy pattern toward the field
     handler. Only some attributes are writable. The list is
     specified in the PROXY_ATTRIBUTES_MAP table.
     """
     if name in PROXY_ATTRIBUTES_MAP.keys():
         if PROXY_ATTRIBUTES_MAP[name] is not None:
             xmed.wrn("The modification of this attribute can't be done that way")
             msg="Use f.update(%s=\"%s\") instead to ensure synchronisation of data."
             xmed.inf(msg%(PROXY_ATTRIBUTES_MAP[name],value))
         else:
             xmed.err("The modification of the attribute %s is not possible"%name)
     else:
         self.__dict__[name] = value
Exemplo n.º 11
0
 def ope(self, function, duplicate=True):
     """
     This can be used to apply a transformation function to this
     field. The transformation is specified using a literal
     equation given as a string where u stands for the field.
     """
     # _GBO_ TO BE IMPLEMENTED: the case where duplicate = False
     # must modify the object itself and not create a new field
     xmed.inf("Operate the equation \"%s\" to %s" %
              (function, self.fieldname))
     try:
         rfieldHandler = xmed.calculator.fct(self.__fieldHandler, function,
                                             MEDOP.NBCOMP_DEFAULT)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 12
0
 def ope(self, function, duplicate=True):
     """
     This can be used to apply a transformation function to this
     field. The transformation is specified using a literal
     equation given as a string where u stands for the field.
     """
     # _GBO_ TO BE IMPLEMENTED: the case where duplicate = False
     # must modify the object itself and not create a new field
     xmed.inf("Operate the equation \"%s\" to %s"%(function,self.fieldname))
     try:
         rfieldHandler = xmed.calculator.fct(self.__fieldHandler,
                                             function,
                                             MEDOP.NBCOMP_DEFAULT)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 13
0
 def __setattr__(self, name, value):
     """
     This method realizes the write proxy pattern toward the field
     handler. Only some attributes are writable. The list is
     specified in the PROXY_ATTRIBUTES_MAP table.
     """
     if name in PROXY_ATTRIBUTES_MAP.keys():
         if PROXY_ATTRIBUTES_MAP[name] is not None:
             xmed.wrn(
                 "The modification of this attribute can't be done that way"
             )
             msg = "Use f.update(%s=\"%s\") instead to ensure synchronisation of data."
             xmed.inf(msg % (PROXY_ATTRIBUTES_MAP[name], value))
         else:
             xmed.err(
                 "The modification of the attribute %s is not possible" %
                 name)
     else:
         self.__dict__[name] = value
Exemplo n.º 14
0
 def __div__(self, operande):
     """
     This makes the division of two fields or the division of field
     by a scalar. It depends weither the operande is a FieldProxy
     or a simple scalar numerical value.
     """
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Division of %s by %s"%(self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.div(self.__fieldHandler, operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1./operande
             offset = 0
             xmed.inf("Scaling %s by factor 1/%s" % (self.fieldname, operande))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler, factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 15
0
 def __sub__(self,operande):
     """
     This makes the substraction of two fields or the substraction
     of a scalar to a field. It depends weither the operande is a
     FieldProxy or a simple scalar numerical value.
     """
     try:
         if isinstance(operande, FieldProxy):
             # The operande is an other field
             xmed.inf("Substraction of %s by %s"%(self.fieldname, operande.fieldname))
             rfieldHandler = xmed.calculator.sub(self.__fieldHandler, operande.__fieldHandler)
         else:
             # The operande is a scalar numerical value that must be
             # considered as an offset in a linear transformation
             factor = 1
             offset = -operande
             xmed.inf("Application of the offset %s to %s" % (offset, self.fieldname))
             rfieldHandler = xmed.calculator.lin(self.__fieldHandler, factor, offset)
     except SALOME.SALOME_Exception, ex:
         xmed.err(ex.details.text)
         return None
Exemplo n.º 16
0
def status(local=True, remote=False):
    """
    This function return the status of the medop context, i.e. the
    list of fields defined in this python session.
    """
    status = ""
    if local is True:
        dvars = pyConsoleGlobals
        if dvars is None:
            xmed.wrn(
                "The stat function required the specification of the python context"
            )
            xmed.inf(
                "Type this command \"import xmed; xmed.setConsoleGlobals(globals())"
            )
        if remote is True:
            status = "========= Fields used in the current context ===\n"
        for varkey in dvars.keys():
            var = dvars[varkey]
            if isinstance(var, FieldProxy):
                status += "%s \t(id=%s, name=%s)\n" % (varkey, var.id,
                                                       var.fieldname)

    if remote is True:
        if local is True:
            status += "\n========= Fields available in the data manager ===\n"
        fieldHandlerList = xmed.dataManager.getFieldHandlerList()
        for fieldHandler in fieldHandlerList:
            status += "id=%s\tname\t= %s\n\tmesh\t= %s\n\t(it,dt)\t= (%s,%s)\n\tsource\t= %s\n" % (
                fieldHandler.id, fieldHandler.fieldname, fieldHandler.meshname,
                fieldHandler.iteration, fieldHandler.order,
                fieldHandler.source)
            status += "---------\n"

        if len(fieldHandlerList) > 0:
            status += "(use 'f=get(id)' to get a field in the current context)"

    return status
Exemplo n.º 17
0
    def __rsub__(self, operande):
        """
        The user typed 'operande-self' where operande is not a field
        proxy. This function process the situation.
        """
        # The operande is a numerical value (because otherwise, the
        # "sub" method would have been called instead). We may apply
        # the command '(self-operande)*(-1)' to activate the __sub__
        # method of fieldpoxy.
        #
        #return (self-operande)*(-1)
        #
        # We prefer to apply a linear transformation because it can be
        # done in one single request to the med calculator.

        factor = -1
        offset = operande
        xmed.inf("Linear transformation %s%s*%s" % (offset, factor, self.fieldname))
        try:
            rfieldHandler = xmed.calculator.lin(self.__fieldHandler, factor, offset)
        except SALOME.SALOME_Exception, ex:
            xmed.err(ex.details.text)
            return None
Exemplo n.º 18
0
def status(local=True,remote=False):
    """
    This function return the status of the medop context, i.e. the
    list of fields defined in this python session.
    """
    status=""
    if local is True:
        dvars = pyConsoleGlobals
        if dvars is None:
            xmed.wrn("The stat function required the specification of the python context")
            xmed.inf("Type this command \"import xmed; xmed.setConsoleGlobals(globals())")
        if remote is True:
            status="========= Fields used in the current context ===\n"
        for varkey in dvars.keys():
            var = dvars[varkey]
            if isinstance(var, FieldProxy):
                status+="%s \t(id=%s, name=%s)\n"%(varkey,var.id,var.fieldname)

    if remote is True:
        if local is True:
            status+="\n========= Fields available in the data manager ===\n"
        fieldHandlerList = xmed.dataManager.getFieldHandlerList()
        for fieldHandler in fieldHandlerList:
            status+="id=%s\tname\t= %s\n\tmesh\t= %s\n\t(it,dt)\t= (%s,%s)\n\tsource\t= %s\n"%(
                fieldHandler.id,
                fieldHandler.fieldname,
                fieldHandler.meshname,
                fieldHandler.iteration,
                fieldHandler.order,
                fieldHandler.source)
            status+="---------\n"

        if len(fieldHandlerList) > 0:
            status+="(use 'f=get(id)' to get a field in the current context)"
    
    return status