Example #1
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
Example #2
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
Example #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
Example #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
Example #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
def view_using_visu(aFieldProxy):
    # No more used
    raise Exception("view_using_visu: No more used")

    VIEWER_TMP_FILE = "/tmp/medop_viewer.med"

    # __GBO__ TO BE IMPROVED: we used a tmp file in this first step of
    # development, but we should used at last a MEDCoupling corba
    # object (see how to use the stuff in PARAVIS/src/Plugins)
    xmed.dataManager.saveFields(VIEWER_TMP_FILE, [aFieldProxy.id])

    # __GBO__: WARN due to a specific feature of VISU, when only one
    # field timestamps exists in the med file, we have to specify an
    # iteration number of 1, whatever the iteration value is in the
    # med file.
    iteration = 1 # __GBO__ for bug VISU
    # instead of:
    # iteration = aFieldProxy.iteration

    from xmed.driver_visu import visu_scalarmap
    result = visu_scalarmap(VIEWER_TMP_FILE,
                            aFieldProxy.meshname,
                            aFieldProxy.fieldname,
                            aFieldProxy.type,
                            iteration)
    if result is False:
        xmed.err("the field can't be displayed")
Example #7
0
def save(filename):
    """
    Dump your job in a med file. Only the fields marked as persistent
    are saved in the specified file.
    """
    try:
        xmed.dataManager.savePersistentFields(filename)
    except SALOME.SALOME_Exception, ex:
        xmed.err(ex.details.text)
Example #8
0
def save(filename):
    """
    Dump your job in a med file. Only the fields marked as persistent
    are saved in the specified file.
    """
    try:
        xmed.dataManager.savePersistentFields(filename)
    except SALOME.SALOME_Exception, ex:
        xmed.err(ex.details.text)
Example #9
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
Example #10
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
Example #11
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
Example #12
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
Example #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
Example #14
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
Example #15
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
Example #16
0
def view_using_visu(aFieldProxy):
    # __GBO__ TO BE IMPROVED: we used a tmp file in this first step of
    # development, but we should used at last a MEDCoupling corba
    # object (see how to use the stuff in PARAVIS/src/Plugins)
    xmed.dataManager.saveFields(VIEWER_TMP_FILE, [aFieldProxy.id])

    # __GBO__: WARN due to a specific feature of VISU, when only one
    # field timestamps exists in the med file, we have to specify an
    # iteration number of 1, whatever the iteration value is in the
    # med file.
    iteration = 1  # __GBO__ for bug VISU
    # instead of:
    # iteration = aFieldProxy.iteration

    from xmed.driver_visu import visu_scalarmap
    result = visu_scalarmap(VIEWER_TMP_FILE, aFieldProxy.meshname,
                            aFieldProxy.fieldname, aFieldProxy.type, iteration)
    if result is False:
        xmed.err("the field can't be displayed")
Example #17
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
Example #18
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
Example #19
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
Example #20
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