11.1 MED salome module

The xdata module provides a way to interact with med objects in pure python or in the salome environment with the same lines of code. The template MEDFIELDCREATOR shows an exemple of that.

The sources of the template are included in the directory XDATA_INSTALLATION_PATH/share/xdata/templates. The example below is used in compiling and installing the MEDFIELDCREATOR template. To do that, you should copy the MEDFIELDCREATOR_SRC arborescence from XDATA_INSTALLATION_PATH/share/xdata/templates in a local directory to not «pollute» your xdata installation. Then, follow the instructions in the README file of MEDFIELDCREATOR_SRC

This file is reproduced here :

# --
# Copyright (C) CEA, EDF
# Author : Erwan ADAM (CEA)
# --

Introduction
============

You are in the template MEDFIELDCREATOR which use the xdata python
module for developpement. We assume as this level that xdata
is correctly installed on your system.

Building and Installing
=======================

cd MEDFIELDCREATOR_SRC
cd ..
mkdir MEDFIELDCREATOR_BUILD
cd MEDFIELDCREATOR_BUILD
../MEDFIELDCREATOR_SRC/build_configure
../MEDFIELDCREATOR_SRC/configure --prefix=INSTALLATION_PATH
make install
make check (optional)

After all, please define a MEDFIELDCREATOR_ROOT_DIR variable
to refer your INSTALLATION_PATH :

setenv MEDFIELDCREATOR_ROOT_DIR INSTALLATION_PATH (csh)
export MEDFIELDCREATOR_ROOT_DIR=INSTALLATION_PATH (sh)

Troubleshooting
===============

Please, send a mail to erwan.adam@cea.fr ...

In this template, we have defined only one class which is used to receive a med mesh at initialisation, and to product a field on this mesh. The code source is reproduced here:

# --
# Copyright (C) CEA, EDF
# Author : Erwan ADAM (CEA)
# --

from xdata import *

from libMEDClient import *

class MedFieldCreator(XNamedObject):
    __init__xattributes__ = [
        XAttribute("mesh", xtype=XInstance(MESH)),
        ]
    __object__xmethods__ = [
        XMethod("run"),
        ]
    __object__xattributes__ = [
        XAttribute("field", xtype=XInstance("libMEDClient.FIELD_")),
        ]
    
    def run(self):
        mesh = self.mesh
        support = SUPPORT(mesh, "my_support", MED_CELL)
        field = FIELDDOUBLE(support, 1)
        # Keep a ref (avoid garbage of local support)
        field.__ref__support__ = support
        field.setName("my_field")
        #
        from time import sleep
        print "very complex computation ... patience"
        sleep(3)
        #
        nb_vals = support.getNumberOfElements(MED_ALL_ELEMENTS)
        vals = [ float(i)/(nb_vals-1) for i in range(nb_vals) ]
        field.setValue(vals)
        self.field = field
        return
    
    pass



Subsections