Back to index

salome-med  6.5.0
Functions | Variables
medutilities Namespace Reference

Functions

def my_remove
def sauv2med
def med2sauv
def convert
def avs2med_one_file
def avs2med

Variables

string msg = "Driver out %s is unknown"
 if file_out.find('.
list meshes = []
list fields = []
tuple driver = GIBI_MED_RDONLY_DRIVER(file_in)
tuple mesh = driver.getMesh()
tuple med = MEDFILEBROWSER(file_in)
tuple mesh_name = med.getMeshName( field_name )
tuple field = FIELDDOUBLE(MED_DRIVER, file_in, field_name, dtit.dt, dtit.it, mesh )
tuple mesh_dim = mesh.getSpaceDimension()
string file_out = '__format__'
tuple f = open(file_out)
tuple content = f.read()
string cmd = "sed"
string dgibi_stream = "\n"
tuple cl = CastemLauncher(dgibi_stream)
tuple typedField = field.castToTypedField()

Function Documentation

def medutilities.avs2med (   argv)

Definition at line 438 of file medutilities.py.

00438 
00439 def avs2med(*argv):
00440     argv = list(argv)
00441     #
00442     mesh_name = "mesh"
00443     field_name = "field"
00444     #
00445     for arg in argv[:]:
00446         if ( arg.find('--mesh_name') == 0 ) or ( arg.find('--mesh-name') == 0 ) :
00447             argv.remove(arg)
00448             try:
00449                 mesh_name = arg.split("=")[1]
00450             except IndexError:
00451                 usage(1)
00452                 pass
00453             pass
00454         if ( arg.find('--field_name') == 0 ) or ( arg.find('--field-name') == 0 ) :
00455             argv.remove(arg)
00456             try:
00457                 field_name = arg.split("=")[1]
00458             except IndexError:
00459                 usage(1)
00460                 pass
00461             pass
00462         pass
00463     #
00464     for arg in argv:
00465         avs2med_one_file(arg, arg + ".med", mesh_name, field_name)
00466         pass
00467     #
00468     return
00469 

Here is the call graph for this function:

def medutilities.avs2med_one_file (   file_in,
  file_out,
  mesh_name,
  field_name 
)
Convert an ucd avs inp file into a med file
inp Specifications can be found at :
http://people.scs.fsu.edu/~burkardt/data/ucd/ucd.html
http://help.avs.com/Express/doc/help/reference/dvmac/UCD_Form.htm

Definition at line 193 of file medutilities.py.

00193 
00194 def avs2med_one_file(file_in, file_out, mesh_name, field_name):
00195     """
00196     Convert an ucd avs inp file into a med file
00197     inp Specifications can be found at :
00198     http://people.scs.fsu.edu/~burkardt/data/ucd/ucd.html
00199     http://help.avs.com/Express/doc/help/reference/dvmac/UCD_Form.htm
00200     
00201     """
00202     my_remove(file_out)
00203     #
00204     meshing = MESHING()
00205     meshing.setName(mesh_name)
00206     #
00207     f = open(file_in)
00208     lines = f.readlines()
00209     f.close()
00210     nb_lines = len(lines)
00211     # ----
00212     # Skip the comments
00213     # ----
00214     while 1:
00215         l = lines[0]
00216         if l[0] != "#":
00217             break
00218         lines = lines[1:]
00219         pass
00220     # ----
00221     headers = [ int(i) for i in lines[0].split() ]
00222     lines = lines[1:]
00223     number_of_nodes = headers[0]
00224     number_of_cells = headers[1]
00225     number_of_nodes_data = headers[2]
00226     number_of_cells_data = headers[3]
00227     number_of_whole_data = headers[3]
00228     # ----------
00229     # Nodes
00230     # ----------
00231     nodes = lines[:number_of_nodes]
00232     lines = lines[number_of_nodes:]
00233     nodes = [ " ".join(l.split()[1:]) for l in nodes ]
00234     nodes = " ".join(nodes)
00235     nodes = [ float(v) for v in nodes.split() ]
00236     # --------
00237     # Space dimension
00238     # --------
00239     nodes_min = min(nodes)
00240     nodes_max = max(nodes)
00241     epsilon = 1.0e-5 * (nodes_max - nodes_min)
00242     nodes_z = [ nodes[i] for i in range(2, 3 * number_of_nodes, 3) ]
00243     nodes_z_min = min(nodes_z)
00244     nodes_z_max = max(nodes_z)
00245     space_dimension = 2
00246     if abs(nodes_z_max) > epsilon:
00247         space_dimension = 3
00248         pass
00249     if abs(nodes_z_min) > epsilon:
00250         space_dimension = 3
00251         pass
00252     #
00253     if space_dimension == 2:
00254         l = range(0, 3 * number_of_nodes, 3) + range(1, 3 * number_of_nodes, 3)
00255         l.sort()
00256         nodes = [ nodes[i] for i in l ]
00257         pass
00258     #
00259     meshing.setCoordinates(space_dimension, number_of_nodes, nodes, "CARTESIAN", MED_FULL_INTERLACE)
00260     # ----------
00261     # Cells
00262     # ----------
00263     cells = lines[:number_of_cells]
00264     lines = lines[number_of_cells:]
00265     cells = [ c.split() for c in cells ]
00266     #
00267     type2connectivity = {}
00268     for c in cells:
00269         cell_id = int(c[0])
00270         cell_mat = int(c[1])
00271         cell_type = c[2]
00272         cell_connectivity = c[3:]
00273         #
00274         avs_type = cell_type
00275         if 0:
00276             pass
00277         elif avs_type == 'tri':
00278             entity = MED_CELL
00279             nb2medtype = {
00280                 3: MED_TRIA3,
00281                 }
00282         elif avs_type == 'quad':
00283             entity = MED_CELL
00284             nb2medtype = {
00285                 4: MED_QUAD4,
00286                 8: MED_QUAD8,
00287                 }
00288         elif avs_type == 'tet':
00289             entity = MED_CELL
00290             nb2medtype = {
00291                 4: MED_TETRA4,
00292                 }
00293         elif avs_type == 'hex':
00294             entity = MED_CELL
00295             nb2medtype = {
00296                 8: MED_HEXA8,
00297                 }
00298         elif avs_type == 'pyr':
00299             entity = MED_CELL
00300             nb2medtype = {
00301                 5: MED_PYRA5,
00302                 }
00303         elif avs_type == 'prism':
00304             entity = MED_CELL
00305             nb2medtype = {
00306                 6: MED_PENTA6,
00307                 }
00308         else:
00309             raise Exception("unknown avs_type : %s"%(avs_type))
00310         #
00311         med_type = nb2medtype[len(cell_connectivity)]
00312         #
00313         try:
00314             d = type2connectivity[entity]
00315         except:
00316             type2connectivity[entity] = {}
00317             d = type2connectivity[entity]
00318             pass
00319         #
00320         try:
00321             l = d[med_type]
00322         except:
00323             d[med_type] = []
00324             l = d[med_type]
00325             pass
00326         #
00327         cell_connectivity = ' '.join(cell_connectivity)
00328         l.append(cell_connectivity)
00329         #
00330         pass
00331     #
00332     mesh_dimension = space_dimension
00333     #
00334     for entity, d in type2connectivity.items():
00335         meshing.setNumberOfTypes(len(d.keys()), entity)
00336         meshing.setTypes(d.keys(), entity)
00337         meshing.setNumberOfElements([len(v) for v in d.values()], entity)
00338         for key, value in d.items():
00339             connectivity = value
00340             connectivity = " ".join(connectivity)
00341             connectivity = [ int(v) for v in connectivity.split() ]
00342             meshing.setConnectivity(connectivity, entity, key)
00343             pass
00344         pass
00345     # -----------
00346     meshing.write(meshing.addDriver(MED_DRIVER,file_out,meshing.getName()))
00347     # -----------
00348     flag = -1
00349     for n in [number_of_nodes_data, number_of_cells_data]:
00350         flag += 1
00351         if n == 0:
00352             continue
00353         # -----------
00354         header = [ int(v) for v in lines[0].split() ]
00355         lines = lines[1:]
00356         nb_of_components = header[0]
00357         nb_of_values_by_component = header[1:]
00358         if len(nb_of_values_by_component) != nb_of_components:
00359             msg = "Error at line %d"%(nb_lines - len(lines))
00360             raise Exception(msg)
00361         #
00362         titles_by_component = []
00363         for i in range(nb_of_components):
00364             l = lines[0]
00365             lines = lines[1:]
00366             label = l.split(',')[0]
00367             unit = l[len(label)+1:]   # The +1 is for the comma
00368             label = label.strip()
00369             unit = unit.strip()
00370             labels_by_value = nb_of_values_by_component[i]*['']
00371             l = [label, unit, labels_by_value]
00372             titles_by_component.append(l)
00373             pass
00374         if nb_of_components > 1:
00375             if nb_of_values_by_component == nb_of_components * [1]:
00376                 nb_of_values_by_component = [ nb_of_components ]
00377                 nb_of_components = 1
00378                 if flag == 0:
00379                     if number_of_cells_data:
00380                         name = field_name + "_on_nodes"
00381                         pass
00382                     pass
00383                 else:
00384                     if number_of_nodes_data:
00385                         name = field_name + "_on_cells"
00386                         pass
00387                     pass
00388                 titles_by_component = [ [name, "", [t[0] for t in titles_by_component]] ]
00389                 pass
00390             pass
00391         if flag == 0:
00392             nb = number_of_nodes
00393         else:
00394             nb = number_of_cells
00395             pass
00396         values = lines[:nb]
00397         lines = lines[nb:]
00398         vals = []
00399         imin = 1
00400         for i in range(nb_of_components):
00401             imax = imin + nb_of_values_by_component[i]
00402             vals.append([ l.split()[imin:imax] for l in values ])
00403             imin = imax
00404             pass
00405         values = vals
00406         # ----------
00407         if flag == 0:
00408             support = SUPPORT(meshing, "support_on_nodes", MED_NODE)
00409         else:
00410             support = SUPPORT(meshing, "support_on_cells", MED_CELL)
00411             pass
00412         for i in range(nb_of_components):
00413             nb = nb_of_values_by_component[i]
00414             field = FIELDDOUBLE(support, nb)
00415             field.setName(titles_by_component[i][0])
00416             # field.setIterationNumber(-1)
00417             # field.setOrderNumber(-1)
00418             # field.setTime(0.0)
00419             for n in range(nb):
00420                 name = titles_by_component[i][2][n]
00421                 if name:
00422                     field.setComponentName(n+1,name)
00423                     pass
00424                 pass
00425             # ---------------
00426             value = values[i]
00427             value = [ " ".join(l) for l in value ]
00428             value = " ".join(value)
00429             value = [ float(v) for v in value.split() ]
00430             field.setValue(value)
00431             # -----
00432             field.write(field.addDriver(MED_DRIVER,file_out,field.getName()))
00433             # -------
00434             pass
00435         #
00436         pass
00437     return

Here is the call graph for this function:

Here is the caller graph for this function:

def medutilities.convert (   file_in,
  driver_in,
  driver_out,
  format = 1,
  file_out = None 
)

Definition at line 67 of file medutilities.py.

00067 
00068 def convert(file_in, driver_in, driver_out, format=1, file_out=None):
00069     #
00070     print file_in
00071     #
00072     if file_out is None:
        file_out = file_in

Here is the caller graph for this function:

def medutilities.med2sauv (   argv)

Definition at line 42 of file medutilities.py.

00042 
00043 def med2sauv(*argv):
00044     argv = list(argv)
00045     # argv = argv[1:]
00046     format = 1
00047     for arg in argv[:]:
00048         if arg.find('--format') == 0:
00049             argv.remove(arg)
00050             try:
00051                 value = arg.split("=")[1]
00052             except IndexError:
00053                 usage(1)
00054                 pass
00055             try:
00056                 value = int(value)
00057             except ValueError:
00058                 usage(1)
00059                 pass
00060             format = value
00061             pass
00062         pass
00063     for arg in argv:
00064         convert(arg, "MED", "GIBI", format)
00065         pass
00066     return

Here is the call graph for this function:

Definition at line 26 of file medutilities.py.

00026 
00027 def my_remove(f):
00028     from os import remove
00029     try:
00030         remove(f)
00031     except OSError:
00032         pass
00033     return

Here is the caller graph for this function:

def medutilities.sauv2med (   argv)

Definition at line 34 of file medutilities.py.

00034 
00035 def sauv2med(*argv):
00036     argv = list(argv)
00037     # argv = argv[1:]
00038     for arg in argv:
00039         convert(arg, "GIBI", "MED")
00040         pass
00041     return

Here is the call graph for this function:


Variable Documentation

tuple medutilities.cl = CastemLauncher(dgibi_stream)

Definition at line 179 of file medutilities.py.

string medutilities.cmd = "sed"

Definition at line 159 of file medutilities.py.

tuple medutilities.content = f.read()

Definition at line 151 of file medutilities.py.

Definition at line 173 of file medutilities.py.

Definition at line 101 of file medutilities.py.

tuple medutilities.f = open(file_out)

Definition at line 150 of file medutilities.py.

tuple medutilities.field = FIELDDOUBLE(MED_DRIVER, file_in, field_name, dtit.dt, dtit.it, mesh )

Definition at line 122 of file medutilities.py.

tuple medutilities.fields = []

Definition at line 99 of file medutilities.py.

tuple medutilities.file_out = '__format__'

Definition at line 136 of file medutilities.py.

tuple medutilities.med = MEDFILEBROWSER(file_in)

Definition at line 107 of file medutilities.py.

list medutilities.mesh = driver.getMesh()

Definition at line 103 of file medutilities.py.

tuple medutilities.mesh_dim = mesh.getSpaceDimension()

Definition at line 134 of file medutilities.py.

tuple medutilities.mesh_name = med.getMeshName( field_name )

Definition at line 115 of file medutilities.py.

Definition at line 98 of file medutilities.py.

string medutilities.msg = "Driver out %s is unknown"

if file_out.find('.

') != -1: suffix = file_in.split('.')[-1] if driver_in == "GIBI": test = "sauv" else: test = "med" pass if len(suffix) >= len(test): suffix = suffix[:len(test)] suffix = suffix.lower() if suffix == test: file_out = '.'.join(file_in.split('.')[:-1]) pass pass pass

Definition at line 93 of file medutilities.py.

tuple medutilities.typedField = field.castToTypedField()

Definition at line 188 of file medutilities.py.