Importing mesh and entities

Asked by B. Emek Abali

I nearly achieved to import an abaqus input file with different element sets
by using

from dolfin.mesh.meshconvert import *
convert('...inp', XmlHandler('...xml'), 'abaqus')
mesh=Mesh('...xml')

while in meshconvert.py :
on line 924
            if sect == "element":
                pnames = ("type", "elset")

thus
*element, type=c3d4, elset=one
elemid ...
...
*element, type=c3d4, elset=two
elemid ...
...

on line 1028
                   handler.add_entity_meshfunction(elemids.index(elemid), i)

is written as a meshfunction entity into the mesh object. So the question is how to call and mark the entity as different cells
like
mesh.mark(one, 1)
mesh.mark(two, 2)

so that the assembly might be loop over dx(1) and dx(2) ?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

I am not too familiar with neither abaqus nor meshconverter, so it is
difficult to follow your question...

But are you telling us that from the abaqus file you get two different types
of markers, one and two, and these should be reflected in some meshfunction
which you cannot find or know how to access?

Have you tried to access them through the mesh.data?

  mf = mesh.data().mesh_function("cell_domains")

look at the docstring in:

  cpp.MeshData?

to get the different names of the possible mesh_function names.

Johan

On Tuesday April 19 2011 08:03:22 B. Emek Abali wrote:
> New question #153448 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/153448
>
> I nearly achieved to import an abaqus input file with different element
> sets by using
>
> from dolfin.mesh.meshconvert import *
> convert('...inp', XmlHandler('...xml'), 'abaqus')
> mesh=Mesh('...xml')
>
> while in meshconvert.py :
> on line 924
> if sect == "element":
> pnames = ("type", "elset")
>
> thus
> *element, type=c3d4, elset=one
> elemid ...
> ...
> *element, type=c3d4, elset=two
> elemid ...
> ...
>
> on line 1028
> handler.add_entity_meshfunction(elemids.index(elemid),
> i)
>
> is written as a meshfunction entity into the mesh object. So the question
> is how to call and mark the entity as different cells like
> mesh.mark(one, 1)
> mesh.mark(two, 2)
>
> so that the assembly might be loop over dx(1) and dx(2) ?

Revision history for this message
B. Emek Abali (bilenemek) said :
#2

Thanks Johan, You followed better than I could prescribe. I can understand the situation better and You started to to revise a bit in the meshconvert :)

Now,
python
from dolfin.mesh.meshconvert import *
convert('Input.inp', XmlHandler('Output.xml'), 'abaqus')

gets in meshconvert.py
1045
    handler.start_meshfunction("material", 3, num_entities)

starts
854
    def start_meshfunction(self, name, dim, size):
        DataHandler.start_meshfunction(self, name, dim, size)
        fname = os.path.splitext(self.__ofile.name)[0]
        self.__ofile_meshfunc = file("%s_%s.xml" % (fname, name), "wb")
        write_header_meshfunction(self.__ofile_meshfunc, dim, size)

makes only one intermediate data (for more than one material names), but I cannot read them
mesh = Mesh('Output_material.xml')

even the output
mesh = Mesh('Output.xml')
mf = mesh.data().mesh_function('material')

returns zero
:I

Revision history for this message
Johan Hake (johan-hake) said :
#3

On Wednesday April 20 2011 03:26:51 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> Status: Answered => Open
>
> B. Emek Abali is still having a problem:
> Thanks Johan, You followed better than I could prescribe. I can
> understand the situation better and You started to to revise a bit in
> the meshconvert :)

Well, I just applied a patch from Neilen. The code is all greek for me ;)

> Now,
> python
> from dolfin.mesh.meshconvert import *
> convert('Input.inp', XmlHandler('Output.xml'), 'abaqus')
>
> gets in meshconvert.py
> 1045
> handler.start_meshfunction("material", 3, num_entities)
>
> starts
> 854
> def start_meshfunction(self, name, dim, size):
> DataHandler.start_meshfunction(self, name, dim, size)
> fname = os.path.splitext(self.__ofile.name)[0]
> self.__ofile_meshfunc = file("%s_%s.xml" % (fname, name), "wb")
> write_header_meshfunction(self.__ofile_meshfunc, dim, size)
>
> makes only one intermediate data (for more than one material names), but I
> cannot read them mesh = Mesh('Output_material.xml')

I guess your meshfunction is stored in Output_material.xml and that it is a
function of uints. You can just look att the second line (or something) of the
file and you get the type. Then you should be able to do:

  mesh = Mesh('Output.xml')
  mf = MeshFunction('uint', mesh, 'Output_material.xml')

> even the output
> mesh = Mesh('Output.xml')
> mf = mesh.data().mesh_function('material')
>
> returns zero

That is because, apperently, meshconverter store the constructed meshfunction
in a separate file instead of in the mesh as data.

Johan

Revision history for this message
B. Emek Abali (bilenemek) said :
#4

its all greek even to me after many minutes of trial and error :)

Thanks Johan, now I get the idea more better, it is a much better idea to store in separate files, two open problems arise

first: only one material is written out, are all the meshfunction in that data? probably yes!

second: Illegal xml row index 2 out of range of (0 -1) if I try to run MeshFunction('uint', mesh, 'Output_material.xml')

1014
    for i, matname in enumerate(materials):
...
...
                handler.add_entity_meshfunction(elemids.index(elemid), i)

so it looks like (as you assumed) 'uint' and then the range 0 and 1 holds true for my data with two materials. Why tries MeshFunction to reach also the number 2 in mesh, is there sth. wrong in the header ?

1007
    for matname, elsetids in material2elsetids.items():
        if matname not in materials:
            handler.error("Unknown material %s referred to for element sets %s" %
                    (matname, ", ".join(elsetids)))
        num_entities += len(elsetids)
    handler.start_meshfunction("material", 3, num_entities)

may be len(elsetids) is 2 (I have two materials) but it should be starting from 0 so num_entities += len(elsetids)-1 kind of thing?

but programming is not my branch, what do You think Johan, any specific hope :)

Revision history for this message
Best Johan Hake (johan-hake) said :
#5

On Wednesday April 20 2011 10:53:14 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> Status: Answered => Open
>
> B. Emek Abali is still having a problem:
> its all greek even to me after many minutes of trial and error :)
>
> Thanks Johan, now I get the idea more better, it is a much better idea
> to store in separate files, two open problems arise
>
> first: only one material is written out, are all the meshfunction in
> that data? probably yes!

Yes that should be the case. You can just open it in a text editor and you
should be able to get a notion of what the stored values are. They come at the
end of the XML file in the meshfunction section.

> second: Illegal xml row index 2 out of range of (0 -1) if I try to run
> MeshFunction('uint', mesh, 'Output_material.xml')

Take a look in your file and check how many values are defined in the value
meshfunction section. It should be one for each cell. It almost looks like the
meshfunction only comes with two values, and the mesh comes with many more
cells. Note the different between the number of different values and the
actuall number of values. The former is two, I guess, in your case.

> 1014
> for i, matname in enumerate(materials):
> ...
> ...
> handler.add_entity_meshfunction(elemids.index(elemid), i)
>
> so it looks like (as you assumed) 'uint' and then the range 0 and 1
> holds true for my data with two materials. Why tries MeshFunction to
> reach also the number 2 in mesh, is there sth. wrong in the header ?

As I mentioned above. When the MeshFunction is read in it needs to read all
values from the mesh function which is more than two. That equals the number
of cells in the mesh.

> 1007
> for matname, elsetids in material2elsetids.items():
> if matname not in materials:
> handler.error("Unknown material %s referred to for element sets
> %s" % (matname, ", ".join(elsetids)))
> num_entities += len(elsetids)
> handler.start_meshfunction("material", 3, num_entities)
>
>
> may be len(elsetids) is 2 (I have two materials) but it should be starting
> from 0 so num_entities += len(elsetids)-1 kind of thing?
>
> but programming is not my branch, what do You think Johan, any specific
> hope :)

Not sure, but it definately looks like bug in MeshConverter...

Johan

Revision history for this message
B. Emek Abali (bilenemek) said :
#6

Thanks Johan Hake, that solved my question.

Revision history for this message
B. Emek Abali (bilenemek) said :
#7

Hi Johan, finally could find the time to sit and decifer the code :)

thanks for all the informations, I found out the problems and changed _abaqus(...) function a bit, you can see it under
http://www.lkm.tu-berlin.de/computational_reality

Supply, abaqus2xml.py

all the rest is the same, only _abaqus(..) is changed, the problem was the size of the MeshFunction which needs to be as big as the element ids, if you like you can implement it onto meshconverter.py , I am definitely not a programmer but it runs quite ok, you may find some print... commands not useful, I assume.

thanks again for the time and help.

Revision history for this message
Johan Hake (johan-hake) said :
#8

On Monday May 2 2011 07:19:44 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> B. Emek Abali posted a new comment:
> Hi Johan, finally could find the time to sit and decifer the code :)
>
> thanks for all the informations, I found out the problems and changed
> _abaqus(...) function a bit, you can see it under
> http://www.lkm.tu-berlin.de/computational_reality
>
> Supply, abaqus2xml.py

Thanks! Would it be possible for you to alter the meshconvert script from the
repository and make the changes in that file, and then post the diff?

> all the rest is the same, only _abaqus(..) is changed, the problem was
> the size of the MeshFunction which needs to be as big as the element
> ids, if you like you can implement it onto meshconverter.py , I am
> definitely not a programmer but it runs quite ok, you may find some
> print... commands not useful, I assume.
>
> thanks again for the time and help.

No prob and thank you!

Johan

Revision history for this message
B. Emek Abali (bilenemek) said :
#9

meshconverter.py @revision 5840 after line 912 in _abaqus(...) function:

942-944 changed to
    elset2eid = {}
    material2elsetnames = {}
    material2eids = {}
    materials = []
    elsets = []

after 947 added
    re_elset = re.compile(r"(\d+),\s*(\d+),\s*(\d+)")

957-977 changed to
            if sect == "element":
  print 'Section: ', sect
                pnames = ("type", "elset")
                params = read_params(params_spec, pnames, lineno)
  if "type" not in params and "elset" not in params:
                    handler.warn("Element on line %d doesn't declare TYPE" % (lineno,))
   supported_elem = False
  if "elset" in params:
   elsetname = params["elset"]
   elsets.append(elsetname)
   if re.search("generate", params_str):
    elset_loop=True
   else:
    elset_loop=False

   if re.search("internal", params_str):
    elset_internal=True
   else:
    elset_internal=False
   supported_elem = False
  else:
   tp = params["type"]
                 if tp not in ("c3d4", "dc3d4"):
                      handler.warn("Unsupported element type '%s' on line %d" % (tp, lineno))
                      supported_elem = False
                 else:
                      supported_elem = True
    elsetname = None

            elif sect == "solid section":
                pnames = ("material", "elset")
                params = read_params(params_spec, pnames, lineno)
                for pname in pnames:
                    if pname not in params:
                       handler.error("Solid section on line %d doesn't "
                                "declare %s" % (lineno, pname.upper()))
                matname = params["material"]
                material2elsetnames.setdefault(matname, []).append(params["elset"])

after 980 added
     elif sect == "elset":
  elsetname = read_params(params_spec, ["elset"], lineno)["elset"]
  elsets.append(elsetname)
  print elsets
  if re.search("generate", params_str):
   elset_loop=True
  else:
   elset_loop=False
            else:
  print 'line ',lineno, ' is ignored start of it:', sect

999-1001 changed to
        elif sect == "element":
            if not supported_elem and elset_internal:
      if elset_loop:
   m = re_elset.match(l)
   if m is None:
           handler.warn("Element set is not understood, line %d" % (lineno,))
    continue
   first, last, inc = [int(x) for x in m.groups()]
       if elsetname is None:
    handler.warn("Name of the element set is not known")
    continue
   eids = range(first,last+1,inc)
   if elsetname in elset2eid.keys():
    handler.warn("More than one element set: %s definition" % (elsetname,))
   print 'Element internal set ',elsetname,' has ',len(eids),' elements'
   elset2eid[elsetname] = eids
      else:
   if elsetname is None:
    handler.warn("Name of the element set is not known")
   else:
    handler.warn("Only element sets with generate are supported")
      continue

1008 changed to
     if elsetname is not None:
  if elsetname in elset2eid.keys():
   print 'Adding cell ',idx,' to element set ',elsetname
   elset2eid[elsetname].append(idx)
  else:
   elset2eid[elsetname] = idx
 elif sect == "elset":
            if elset_loop:
  m = re_elset.match(l)
         if m is None:
                 handler.warn("Element set is not understood, line %d" % (lineno,))
   continue
  first, last, inc = [int(x) for x in m.groups()]
             if elsetname is None:
   handler.warn("Name of the element set is not known")
   continue
  eids = range(first,last+1,inc)
  if elsetname in elset2eid.keys():
   handler.warn("More than one element set: %s definition" % (elsetname,))
  elset2eid[elsetname] = eids
  print 'Element set ',elsetname,' has ',len(eids),' elements'
     else:
  if elsetname is None:
   handler.warn("Name of the element set is not known")
  else:
   handler.warn("Only element sets with generate are supported")

1039-1062 changed to
    num_entities = 1
    for i, matname in enumerate(materials):
        try: elsetnames = material2elsetnames[matname]
        except KeyError:
            # No element sets for this material
            continue
        # For each element set associated with this material
 material2eids[i] = []
        for j, elsetname in enumerate(elsetnames):
     if elsetname in elsets:
  print 'Element set ',elsetname,' for ',matname,' is found'
  material2eids[i].extend(elset2eid[elsetname])
     else:
  handler.error("Material '%s' is assigned to undefined element set '%s', the known element sets: '%s'" % (matname, elsetname,elset2eid.keys()))
 num_entities +=len(material2eids[i])
 handler.start_meshfunction(matname, 3, len(elems))
 print 'adding ',len(material2eids[i]),' cells into ...',matname,'.xml'
 for eid in material2eids[i]:
  handler.add_entity_meshfunction(elemids.index(eid), i+1)
     handler.end_meshfunction()

    handler.start_meshfunction("material", 3, len(elems))
    print 'adding all material defined ',num_entities,' cells into ...-material.xml'
    for i in material2eids.keys():
        for eid in material2eids[i]:
  handler.add_entity_meshfunction(elemids.index(eid), i+1)
    handler.end_meshfunction()
    print "Conversion done"

Revision history for this message
B. Emek Abali (bilenemek) said :
#10

now it ignores the lines which has nothing, can handle generated and internal elsets

and at the end write out many datas, here is my help for the user
-----------------------------------------------------------------------------------------------------------------------------
Abaqus to Xml converter. Script reads the input data XXX.inp and writes out
- out.xml an Ascii which has the nodes and connectivity
- out-material.xml an Ascii which has materials dependent 1,2 values (let's say 1 is copper 2 is steel) for the cells
- out-copper.xml, out-steel.xml each with cells of each defined materials

Save this data and input data in the same directory and use these commands under python:
--------------------------------------------
from dolfin import *
from abaqus2xml import *
convert('XXX.inp', 'out.xml')
mesh = Mesh('out.xml')
mesh.order()

cells_copy = MeshFunction('uint', mesh, 3)

cells_copper = MeshFunction('uint',mesh,'out_copper.xml')
cells_steel = MeshFunction('uint',mesh,'out_steel.xml')

materials = MeshFunction('uint',mesh,'out_material.xml')

cells_copy.set_all(0)
cells_copper.set_all(1)
cells_steel.set_all(2)

copper_mesh = SubMesh(mesh, materials, 1)
steel_mesh = SubMesh(mesh, materials, 2)

plot(cells_copy, title='all cells')
plot(cells_copper, title='copper cells')
plot(cells_steel, title='steel cells')

plot(copper_mesh, title='copper')
plot(steel_mesh, title='steel')
interactive()
-------------------------------------------

Revision history for this message
B. Emek Abali (bilenemek) said :
#11

the code is under

www.lkm.tu-berlin.de/computational_reality

abaqus2xml.py

Revision history for this message
Johan Hake (johan-hake) said :
#12

Emek!

Sorry for being such a dumass, but what was that you just sent us? Was that a
diff or patch? I need something that shows the difference between the present
tip and your improvements.

I cannot manually go in and apply these changes. That would be too error
prone. Could you also send me an abaqus mesh which fails for the present
meshconverter and which is correctly converted with your patch. I can then
update the unit test.

Johan

On Tuesday May 3 2011 03:09:58 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> B. Emek Abali posted a new comment:
> meshconverter.py @revision 5840 after line 912 in _abaqus(...) function:
>
> 942-944 changed to
> elset2eid = {}
> material2elsetnames = {}
> material2eids = {}
> materials = []
> elsets = []
>
> after 947 added
> re_elset = re.compile(r"(\d+),\s*(\d+),\s*(\d+)")
>
> 957-977 changed to
> if sect == "element":
> print 'Section: ', sect
> pnames = ("type", "elset")
> params = read_params(params_spec, pnames, lineno)
> if "type" not in params and "elset" not in params:
> handler.warn("Element on line %d doesn't declare TYPE"
> % (lineno,)) supported_elem = False
> if "elset" in params:
> elsetname = params["elset"]
> elsets.append(elsetname)
> if re.search("generate", params_str):
> elset_loop=True
> else:
> elset_loop=False
>
> if re.search("internal", params_str):
> elset_internal=True
> else:
> elset_internal=False
> supported_elem = False
> else:
> tp = params["type"]
> if tp not in ("c3d4", "dc3d4"):
> handler.warn("Unsupported element type '%s' on
line
> %d" % (tp, lineno)) supported_elem = False
> else:
> supported_elem = True
> elsetname = None
>
> elif sect == "solid section":
> pnames = ("material", "elset")
> params = read_params(params_spec, pnames, lineno)
> for pname in pnames:
> if pname not in params:
> handler.error("Solid section on line %d doesn't "
> "declare %s" % (lineno, pname.upper()))
> matname = params["material"]
> material2elsetnames.setdefault(matname,
> []).append(params["elset"])
>
> after 980 added
> elif sect == "elset":
> elsetname = read_params(params_spec, ["elset"], lineno)
["elset"]
> elsets.append(elsetname)
> print elsets
> if re.search("generate", params_str):
> elset_loop=True
> else:
> elset_loop=False
> else:
> print 'line ',lineno, ' is ignored start of it:', sect
>
> 999-1001 changed to
> elif sect == "element":
> if not supported_elem and elset_internal:
> if elset_loop:
> m = re_elset.match(l)
> if m is None:
> handler.warn("Element set is not understood,
line %d" %
> (lineno,)) continue
> first, last, inc = [int(x) for x in m.groups()]
> if elsetname is None:
> handler.warn("Name of the element set is not
known")
> continue
> eids = range(first,last+1,inc)
> if elsetname in elset2eid.keys():
> handler.warn("More than one element set: %s
definition" % (elsetname,))
> print 'Element internal set ',elsetname,' has
',len(eids),' elements'
> elset2eid[elsetname] = eids
> else:
> if elsetname is None:
> handler.warn("Name of the element set is not
known")
> else:
> handler.warn("Only element sets with generate
are supported")
> continue
>
> 1008 changed to
> if elsetname is not None:
> if elsetname in elset2eid.keys():
> print 'Adding cell ',idx,' to element set ',elsetname
> elset2eid[elsetname].append(idx)
> else:
> elset2eid[elsetname] = idx
> elif sect == "elset":
> if elset_loop:
> m = re_elset.match(l)
> if m is None:
> handler.warn("Element set is not understood, line %d"
%
> (lineno,)) continue
> first, last, inc = [int(x) for x in m.groups()]
> if elsetname is None:
> handler.warn("Name of the element set is not known")
> continue
> eids = range(first,last+1,inc)
> if elsetname in elset2eid.keys():
> handler.warn("More than one element set: %s
definition" % (elsetname,))
> elset2eid[elsetname] = eids
> print 'Element set ',elsetname,' has ',len(eids),' elements'
> else:
> if elsetname is None:
> handler.warn("Name of the element set is not known")
> else:
> handler.warn("Only element sets with generate are
supported")
>
> 1039-1062 changed to
> num_entities = 1
> for i, matname in enumerate(materials):
> try: elsetnames = material2elsetnames[matname]
> except KeyError:
> # No element sets for this material
> continue
> # For each element set associated with this material
> material2eids[i] = []
> for j, elsetname in enumerate(elsetnames):
> if elsetname in elsets:
> print 'Element set ',elsetname,' for ',matname,' is found'
> material2eids[i].extend(elset2eid[elsetname])
> else:
> handler.error("Material '%s' is assigned to undefined element
set '%s',
> the known element sets: '%s'" % (matname, elsetname,elset2eid.keys()))
> num_entities +=len(material2eids[i])
> handler.start_meshfunction(matname, 3, len(elems))
> print 'adding ',len(material2eids[i]),' cells into ...',matname,'.xml'
> for eid in material2eids[i]:
> handler.add_entity_meshfunction(elemids.index(eid), i+1)
> handler.end_meshfunction()
>
> handler.start_meshfunction("material", 3, len(elems))
> print 'adding all material defined ',num_entities,' cells into
> ...-material.xml' for i in material2eids.keys():
> for eid in material2eids[i]:
> handler.add_entity_meshfunction(elemids.index(eid), i+1)
> handler.end_meshfunction()
> print "Conversion done"

Revision history for this message
B. Emek Abali (bilenemek) said :
#13

hi Johan,

sorry about not knowing the jargon of diff or patch, so I thought you wish to SEE the difference, ok lets try it so:

I did one small model in Abaqus by drawing parts, making one instance, partitioning them into sections and adding two different materials into these sections, the file : for_JohanHake.inp is the output from Abaqus 6.8 (will not work with meshconverter.py )

The script abaqus2xml.py has only _abaqus(...) method (which I manipulated) and some handler needed methods (which I just copied), all the rest is not included.

both of them under www.lkm.tu-berlin.de/computational_reality

pls. tell me if you got the .inp file so I can delete it from there.

Revision history for this message
Johan Hake (johan-hake) said :
#14

On Wednesday May 4 2011 00:40:02 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> B. Emek Abali posted a new comment:
> hi Johan,
>
> sorry about not knowing the jargon of diff or patch, so I thought you
> wish to SEE the difference, ok lets try it so:

Yes, I would very much like to see the changes and thank you for these. The
problem is to implement them into meshconverter, so more people benefit from
them. As the difference are so large I wont manually update meshconverter with
your changes.

A 'diff' is a line by line difference between two files generated by the unix
program diff. The result of such a call is often refered to as a diff.

  http://en.wikipedia.org/wiki/Diff

The cool thing with diffs are that these can be applied directly to the
original file and the file will be changed to the new one.

So if it would be possible to apply your changes to the original
meshconverter.py script and then take a diff of that against the unchanged
meshconverter script I would be very happy!

  diff new_meshconverter.py new_meshconverter.py > \
      dolfin_Emek_2011.05.04.diff

You can also look at for more elaborated ways of creating a patch:

  http://fenicsproject.org/developer/developer.html#contributing-code

Also if you want to be included as co-author on the meshconverter script you
need to fill out these two forms:

  http://fenicsproject.org/pub/copyright/forms

and _snail mail_ them to the correct adress.

Best regards,

Johan

> I did one small model in Abaqus by drawing parts, making one instance,
> partitioning them into sections and adding two different materials into
> these sections, the file : for_JohanHake.inp is the output from Abaqus
> 6.8 (will not work with meshconverter.py )
>
> The script abaqus2xml.py has only _abaqus(...) method (which I
> manipulated) and some handler needed methods (which I just copied), all
> the rest is not included.
>
> both of them under www.lkm.tu-berlin.de/computational_reality
>
> pls. tell me if you got the .inp file so I can delete it from there.

Got it!

Johan

Revision history for this message
B. Emek Abali (bilenemek) said :
#15

915c915,916
< The Abaqus 6.8 has Node->Element->Elset->Material
---
> The Abaqus format first defines a node block, then there should be a number
> of elements containing these nodes.
928a930,932
> else:
> handler.warn("Invalid parameter syntax on line %d: %s" % (lineno, p))
> continue
938,940c942,943
< elset2eid = {}
< material2elsetnames = {}
< material2eids = {}
---
> eid2elset = {}
> material2elsetids = {}
942d944
< elsets = []
946d947
< re_elset = re.compile(r"(\d+),\s*(\d+),\s*(\d+)")
957d957
< print 'Section: ', sect
960,984c960,968
< if "type" not in params and "elset" not in params:
< handler.warn("Element on line %d doesn't declare TYPE" % (lineno,))
< supported_elem = False
< if "elset" in params:
< elsetname = params["elset"]
< elsets.append(elsetname)
< if re.search("generate", params_str):
< elset_loop=True
< else:
< elset_loop=False
<
< if re.search("internal", params_str):
< elset_internal=True
< else:
< elset_internal=False
< supported_elem = False
< else:
< tp = params["type"]
< if tp not in ("c3d4", "dc3d4"):
< handler.warn("Unsupported element type '%s' on line %d" % (tp, lineno))
< supported_elem = False
< else:
< supported_elem = True
< elsetname = None
<
---
> if "type" not in params:
> handler.error("Element on line %d doesn't declare TYPE" %
> (lineno,))
> tp, elset = params["type"], params.get("elset")
> if tp not in ("c3d4", "dc3d4"):
> handler.warn("Unsupported element type '%s' on line %d" % (tp, lineno))
> supported_elem = False
> else:
> supported_elem = True
993c977
< material2elsetnames.setdefault(matname, []).append(params["elset"])
---
> material2elsetids.setdefault(matname, []).append(params["elset"])
995,1004c979,980
< matname = read_params(params_spec, ["name"], lineno)["name"]
< materials.append(matname)
< elif sect == "elset":
< elsetname = read_params(params_spec, ["elset"], lineno)["elset"]
< elsets.append(elsetname)
< print elsets
< if re.search("generate", params_str):
< elset_loop=True
< else:
< elset_loop=False
---
> name = read_params(params_spec, ["name"], lineno)["name"]
> materials.append(name)
1006,1008c982
< else:
< print 'line ',lineno, ' is ignored start of it:', sect #handler.warn("Unsupported section type '%s' on line %d" % (sect, lineno))
< continue
---
> continue
1026,1046c1000,1001
< if not supported_elem and elset_internal:
< if elset_loop:
< m = re_elset.match(l)
< if m is None:
< handler.warn("Element set is not understood, line %d" % (lineno,))
< continue
< first, last, inc = [int(x) for x in m.groups()]
< if elsetname is None:
< handler.warn("Name of the element set is not known")
< continue
< eids = range(first,last+1,inc)
< if elsetname in elset2eid.keys():
< handler.warn("More than one element set: %s definition" % (elsetname,))
< print 'Element internal set ',elsetname,' has ',len(eids),' elements'
< elset2eid[elsetname] = eids
< else:
< if elsetname is None:
< handler.warn("Name of the element set is not known")
< else:
< handler.warn("Only element sets with generate are supported")
< continue
---
> if not supported_elem:
> continue
1049,1050c1004,1005
< handler.warn("Blank line %d or sth. is bad, ignoring..." % (lineno,))
< continue
---
> handler.error("Node on line %d badly specified (expected 3 "
> "coordinates)" % (lineno,))
1053,1078c1008
< if elsetname is not None:
< if elsetname in elset2eid.keys():
< print 'Adding cell ',idx,' to element set ',elsetname
< elset2eid[elsetname].append(idx)
< else:
< elset2eid[elsetname] = idx
< elif sect == "elset":
< if elset_loop:
< m = re_elset.match(l)
< if m is None:
< handler.warn("Element set is not understood, line %d" % (lineno,))
< continue
< first, last, inc = [int(x) for x in m.groups()]
< if elsetname is None:
< handler.warn("Name of the element set is not known")
< continue
< eids = range(first,last+1,inc)
< if elsetname in elset2eid.keys():
< handler.warn("More than one element set: %s definition" % (elsetname,))
< elset2eid[elsetname] = eids
< print 'Element set ',elsetname,' has ',len(eids),' elements'
< else:
< if elsetname is None:
< handler.warn("Name of the element set is not known")
< else:
< handler.warn("Only element sets with generate are supported")
---
> eid2elset.setdefault(elset, set()).add(idx)
1106c1036,1045
<
---
>
> # Define the material function for the cells
>
> num_entities = 0
> for matname, elsetids in material2elsetids.items():
> if matname not in materials:
> handler.error("Unknown material %s referred to for element sets %s" %
> (matname, ", ".join(elsetids)))
> num_entities += len(elsetids)
> handler.start_meshfunction("material", 3, num_entities)
1108d1046
< num_entities = 1
1110c1048
< try: elsetnames = material2elsetnames[matname]
---
> try: elsetids = material2elsetids[matname]
1112c1050
< # No element sets for this material
---
> # No elements for this material
1115,1133c1053,1061
< material2eids[i] = []
< for j, elsetname in enumerate(elsetnames):
< if elsetname in elsets:
< print 'Element set ',elsetname,' for ',matname,' is found'
< material2eids[i].extend(elset2eid[elsetname])
< else:
< handler.error("Material '%s' is assigned to undefined element set '%s', the known element sets: '%s'" % (matname, elsetname,elset2eid.keys()))
< num_entities +=len(material2eids[i])
< handler.start_meshfunction(matname, 3, len(elems))
< print 'adding ',len(material2eids[i]),' cells into ...',matname,'.xml'
< for eid in material2eids[i]:
< handler.add_entity_meshfunction(elemids.index(eid), i+1)
< handler.end_meshfunction()
<
< handler.start_meshfunction("material", 3, len(elems))
< print 'adding all material defined ',num_entities,' cells into ...-material.xml'
< for i in material2eids.keys():
< for eid in material2eids[i]:
< handler.add_entity_meshfunction(elemids.index(eid), i+1)
---
> elsets = []
> for eid in elsetids:
> try: elsets.append(eid2elset[eid])
> except KeyError:
> handler.error("Material '%s' is assigned to undefined element "
> "set '%s'" % (matname, eid))
> for elset in elsets:
> for elemid in elset:
> handler.add_entity_meshfunction(elemids.index(elemid), i)
1135d1062
< print "Conversion done"

Revision history for this message
B. Emek Abali (bilenemek) said :
#16

please say if the sequence

diff new old

was not correct,

no need for making the list of contribution any longer :D but thanks a lot..

Revision history for this message
Johan Hake (johan-hake) said :
#17

Thanks for the diff! We are almost there!

Please switch the order of the files in the diff command, and attach the
result as a file.

  diff meshconverter.py newmeshconverter.py > meshconverter.diff

Johan

On Friday May 6 2011 00:51:20 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> B. Emek Abali posted a new comment:
> please say if the sequence
>
> diff new old
>
> was not correct,
>
> no need for making the list of contribution any longer :D but thanks a
> lot..

Revision history for this message
B. Emek Abali (bilenemek) said :
#18

pls find the
dolfin_Emek_2011.05.04.diff

under
tu-berlin.de/lkm/computational_reality

emek

Revision history for this message
Johan Hake (johan-hake) said :
#19

Got it!

Will see if I can apply it later today.

Johan

On Monday May 9 2011 03:20:58 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/153448
>
> B. Emek Abali posted a new comment:
> pls find the
> dolfin_Emek_2011.05.04.diff
>
> under
> tu-berlin.de/lkm/computational_reality
>
> emek