Importing mesh and entities
I nearly achieved to import an abaqus input file with different element sets
by using
from dolfin.
convert('...inp', XmlHandler(
mesh=Mesh('...xml')
while in meshconvert.py :
on line 924
if sect == "element":
thus
*element, type=c3d4, elset=one
elemid ...
...
*element, type=c3d4, elset=two
elemid ...
...
on line 1028
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
|
#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(
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:/
>
> I nearly achieved to import an abaqus input file with different element
> sets by using
>
> from dolfin.
> convert('...inp', XmlHandler(
> 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.
> 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
|
#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.
convert(
gets in meshconvert.py
1045
handler.
starts
854
def start_meshfunct
fname = os.path.
makes only one intermediate data (for more than one material names), but I cannot read them
mesh = Mesh('Output_
even the output
mesh = Mesh('Output.xml')
mf = mesh.data(
returns zero
:I
Revision history for this message
|
#3 |
On Wednesday April 20 2011 03:26:51 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https:/
>
> 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.
> convert(
>
> gets in meshconvert.py
> 1045
> handler.
>
> starts
> 854
> def start_meshfunct
> DataHandler.
> fname = os.path.
> self.__
> write_header_
>
> makes only one intermediate data (for more than one material names), but I
> cannot read them mesh = Mesh('Output_
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(
> even the output
> mesh = Mesh('Output.xml')
> mf = mesh.data(
>
> 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
|
#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(
1014
for i, matname in enumerate(
...
...
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 material2elseti
if matname not in materials:
handler.
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
|
#5 |
On Wednesday April 20 2011 10:53:14 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https:/
>
> 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(
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(
> ...
> ...
> handler.
>
> 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 material2elseti
> if matname not in materials:
> handler.
> %s" % (matname, ", ".join(elsetids)))
> num_entities += len(elsetids)
> handler.
>
>
> 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
|
#6 |
Thanks Johan Hake, that solved my question.
Revision history for this message
|
#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://
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
|
#8 |
On Monday May 2 2011 07:19:44 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https:/
>
> 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://
>
> 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
|
#9 |
meshconverter.py @revision 5840 after line 912 in _abaqus(...) function:
942-944 changed to
elset2eid = {}
material2el
material2eids = {}
materials = []
elsets = []
after 947 added
re_elset = re.compile(
957-977 changed to
if sect == "element":
print 'Section: ', sect
if "type" not in params and "elset" not in params:
supported_elem = False
if "elset" in params:
elsetname = params["elset"]
elsets.
if re.search(
elset_loop=True
else:
elset_
if re.search(
elset_
else:
elset_
supported_elem = False
else:
tp = params["type"]
if tp not in ("c3d4", "dc3d4"):
elsetname = None
elif sect == "solid section":
for pname in pnames:
after 980 added
elif sect == "elset":
elsetname = read_params(
elsets.
print elsets
if re.search(
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:
continue
first, last, inc = [int(x) for x in m.groups()]
if elsetname is None:
handler.
continue
eids = range(first,
if elsetname in elset2eid.keys():
handler.
print 'Element internal set ',elsetname,' has ',len(eids),' elements'
elset2eid[
else:
if elsetname is None:
handler.
else:
handler.
continue
1008 changed to
if elsetname is not None:
if elsetname in elset2eid.keys():
print 'Adding cell ',idx,' to element set ',elsetname
elset2eid[
else:
elset2eid[
elif sect == "elset":
if elset_loop:
m = re_elset.match(l)
if m is None:
continue
first, last, inc = [int(x) for x in m.groups()]
if elsetname is None:
handler.
continue
eids = range(first,
if elsetname in elset2eid.keys():
handler.
elset2eid[
print 'Element set ',elsetname,' has ',len(eids),' elements'
else:
if elsetname is None:
handler.
else:
handler.
1039-1062 changed to
num_entities = 1
for i, matname in enumerate(
try: elsetnames = material2elsetn
except KeyError:
# No element sets for this material
# For each element set associated with this material
material2eids[i] = []
for j, elsetname in enumerate(
if elsetname in elsets:
print 'Element set ',elsetname,' for ',matname,' is found'
material2eids
else:
handler.
num_entities +=len(material2
handler.
print 'adding ',len(material2
for eid in material2eids[i]:
handler.
handler.
handler.
print 'adding all material defined ',num_entities,' cells into ...-material.xml'
for i in material2eids.
for eid in material2eids[i]:
handler.
handler.
print "Conversion done"
Revision history for this message
|
#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(
cells_copper = MeshFunction(
cells_steel = MeshFunction(
materials = MeshFunction(
cells_copy.
cells_copper.
cells_steel.
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
|
#11 |
the code is under
www.lkm.
abaqus2xml.py
Revision history for this message
|
#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:/
>
> 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(
>
> 957-977 changed to
> if sect == "element":
> print 'Section: ', sect
> pnames = ("type", "elset")
> params = read_params(
> if "type" not in params and "elset" not in params:
> handler.
> % (lineno,)) supported_elem = False
> if "elset" in params:
> elsetname = params["elset"]
> elsets.
> if re.search(
> elset_loop=True
> else:
> elset_loop=False
>
> if re.search(
> elset_internal=True
> else:
> elset_internal=
> supported_elem = False
> else:
> tp = params["type"]
> if tp not in ("c3d4", "dc3d4"):
> handler.
line
> %d" % (tp, lineno)) supported_elem = False
> else:
> supported_elem = True
> elsetname = None
>
> elif sect == "solid section":
> pnames = ("material", "elset")
> params = read_params(
> for pname in pnames:
> if pname not in params:
> handler.
> "declare %s" % (lineno, pname.upper()))
> matname = params["material"]
> material2elsetn
> []).append(
>
> after 980 added
> elif sect == "elset":
> elsetname = read_params(
["elset"]
> elsets.
> print elsets
> if re.search(
> 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.
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,
> 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[
> 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[
> else:
> elset2eid[
> elif sect == "elset":
> if elset_loop:
> m = re_elset.match(l)
> if m is None:
> handler.
%
> (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,
> if elsetname in elset2eid.keys():
> handler.warn("More than one element set: %s
definition" % (elsetname,))
> elset2eid[
> 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(
> try: elsetnames = material2elsetn
> except KeyError:
> # No element sets for this material
> continue
> # For each element set associated with this material
> material2eids[i] = []
> for j, elsetname in enumerate(
> if elsetname in elsets:
> print 'Element set ',elsetname,' for ',matname,' is found'
> material2eids[
> else:
> handler.
set '%s',
> the known element sets: '%s'" % (matname, elsetname,
> num_entities +=len(material2
> handler.
> print 'adding ',len(material2
> for eid in material2eids[i]:
> handler.
> handler.
>
> handler.
> print 'adding all material defined ',num_entities,' cells into
> ...-material.xml' for i in material2eids.
> for eid in material2eids[i]:
> handler.
> handler.
> print "Conversion done"
Revision history for this message
|
#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.
pls. tell me if you got the .inp file so I can delete it from there.
Revision history for this message
|
#14 |
On Wednesday May 4 2011 00:40:02 B. Emek Abali wrote:
> Question #153448 on DOLFIN changed:
> https:/
>
> 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://
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_meshconvert
dolfin_
You can also look at for more elaborated ways of creating a patch:
http://
Also if you want to be included as co-author on the meshconverter script you
need to fill out these two forms:
http://
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.
>
> pls. tell me if you got the .inp file so I can delete it from there.
Got it!
Johan
Revision history for this message
|
#15 |
915c915,916
< The Abaqus 6.8 has Node->Element-
---
> The Abaqus format first defines a node block, then there should be a number
> of elements containing these nodes.
928a930,932
> else:
> handler.
> continue
938,940c942,943
< elset2eid = {}
< material2elsetnames = {}
< material2eids = {}
---
> eid2elset = {}
> material2elsetids = {}
942d944
< elsets = []
946d947
< re_elset = re.compile(
957d957
< print 'Section: ', sect
960,984c960,968
< if "type" not in params and "elset" not in params:
< handler.
< supported_elem = False
< if "elset" in params:
< elsetname = params["elset"]
< elsets.
< if re.search(
< elset_loop=True
< else:
< elset_loop=False
<
< if re.search(
< elset_internal=True
< else:
< elset_internal=
< supported_elem = False
< else:
< tp = params["type"]
< if tp not in ("c3d4", "dc3d4"):
< handler.
< supported_elem = False
< else:
< supported_elem = True
< elsetname = None
<
---
> if "type" not in params:
> handler.
> (lineno,))
> tp, elset = params["type"], params.get("elset")
> if tp not in ("c3d4", "dc3d4"):
> handler.
> supported_elem = False
> else:
> supported_elem = True
993c977
< material2elsetn
---
> material2elseti
995,1004c979,980
< matname = read_params(
< materials.
< elif sect == "elset":
< elsetname = read_params(
< elsets.
< print elsets
< if re.search(
< elset_loop=True
< else:
< elset_loop=False
---
> name = read_params(
> materials.
1006,1008c982
< else:
< print 'line ',lineno, ' is ignored start of it:', sect #handler.
< 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.
< 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,
< 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[
< 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[
< else:
< elset2eid[
< elif sect == "elset":
< if elset_loop:
< m = re_elset.match(l)
< if m is None:
< handler.
< 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,
< if elsetname in elset2eid.keys():
< handler.warn("More than one element set: %s definition" % (elsetname,))
< elset2eid[
< 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.
1106c1036,1045
<
---
>
> # Define the material function for the cells
>
> num_entities = 0
> for matname, elsetids in material2elseti
> if matname not in materials:
> handler.
> (matname, ", ".join(elsetids)))
> num_entities += len(elsetids)
> handler.
1108d1046
< num_entities = 1
1110c1048
< try: elsetnames = material2elsetn
---
> try: elsetids = material2elseti
1112c1050
< # No element sets for this material
---
> # No elements for this material
1115,1133c1053,1061
< material2eids[i] = []
< for j, elsetname in enumerate(
< if elsetname in elsets:
< print 'Element set ',elsetname,' for ',matname,' is found'
< material2eids[
< else:
< handler.
< num_entities +=len(material2
< handler.
< print 'adding ',len(material2
< for eid in material2eids[i]:
< handler.
< handler.
<
< handler.
< print 'adding all material defined ',num_entities,' cells into ...-material.xml'
< for i in material2eids.
< for eid in material2eids[i]:
< handler.
---
> elsets = []
> for eid in elsetids:
> try: elsets.
> except KeyError:
> handler.
> "set '%s'" % (matname, eid))
> for elset in elsets:
> for elemid in elset:
> handler.
1135d1062
< print "Conversion done"
Revision history for this message
|
#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
|
#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:/
>
> 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
|
#18 |
pls find the
dolfin_
under
tu-berlin.
emek
Revision history for this message
|
#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:/
>
> B. Emek Abali posted a new comment:
> pls find the
> dolfin_
>
> under
> tu-berlin.
>
> emek