← Back to team overview

dolfin team mailing list archive

Re: [Question #153448]: Importing mesh and entities

 

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"

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.



Follow ups

References