Commit 9d0a36ce authored by Philippe Delandmeter's avatar Philippe Delandmeter
Browse files

slim3d Interface. Extrusion works now in parallel

parent abd3a5b6
Pipeline #1238 failed with stage
in 27 minutes and 31 seconds
......@@ -189,3 +189,48 @@ class mesh() :
vbentity.elements.append(f)
else :
e.faces[i] = allf[fs]
import re
def read_msh(filename, vals={}) :
try :
with open(filename, "r") as f:
for l in f :
if l.strip() == "$ElementNodeData" :
break
if l.strip() != "$ElementNodeData" :
raise NameError("No ElementNodeData in file \"%s\"" % filename)
nstr = int(f.readline())
for i in range(nstr) :
f.readline()
nfloat = int(f.readline())
for i in range(nfloat) :
f.readline()
nint = int(f.readline())
for i in range(nint) :
l = f.readline()
if i == 2:
nel = int(l)
for i in range (nel) :
w = f.readline().split()
vals[int(w[0])] = list((float(w[j+2])) for j in range(int(w[1])))
if f.readline().strip() == "$EndElementNodeData":
return vals
else :
raise NameError("Invalid ElementNodeData section")
except :
print("error in file \"%s\"" % filename)
raise
from os import path
def read_idx(filename) :
vals = {}
reMerge = re.compile("\s*Merge\s* \"(.*)\"\s*;")
dirname = path.dirname(filename)
with open(filename, "r") as f:
for l in f :
m = reMerge.match(l)
if m :
read_msh(dirname+'/'+m.group(1), vals)
return vals
......@@ -841,71 +841,68 @@ def get_distance(region, physical_tags):
return np.array(dist)
def extrude(mesh_file_name, bath_file_name, nb_layers=None, z_layers=None, layers_function=None, mesh_file_name_out='', factor_show=0, periodicity=None):
if (nb_layers and z_layers) or (nb_layers and layers_function) or (z_layers and layers_function):
dgpy.Msg.Fatal("Only one among nb_layers, z_layers and layers_function can be defined!")
if periodicity:
shiftOperation = periodicity[0]
cutTags = periodicity[1]
pasteTags = periodicity[2]
mapFilename = periodicity[3]
slim_private.periodicMap.periodicMap(mesh_file_name, '_tmp_mesh_file', 1, shiftOperation, cutTags, pasteTags, mapFilename)
slim_private.shutil.move('_tmp_mesh_file', mesh_file_name)
groups = dgpy.dgGroupCollection(mesh_file_name)
bathFunc = slim_private._load_function(bath_file_name, groups)
bathDof = dgpy.dgDofContainer(groups, 1)
bathDof.interpolate(bathFunc)
globNodeId2Bath = {}
dataProx = dgpy.fullMatrixDouble()
for iGroup in range(groups.getNbElementGroups()) :
group = groups.getElementGroup(iGroup)
for iElement in range(group.getNbElements()) :
el = group.getElement(iElement)
bathDof.getElementProxy(iGroup,iElement, dataProx)
for iPt in range(group.getNbNodes()) :
vId = groups.mesh().gmshVertexId(el.vertex(iPt))
globNodeId2Bath[vId] = dataProx(iPt,0)
def layersForZ(h) :
for i in range(len(z_layers)) :
if z_layers[i] > h :
return i
return len(z_layers)
def getLayers(e, v) :
h = globNodeId2Bath[v[3]]
if nb_layers:
return [z * h /nb_layers for z in range(nb_layers + 1)]
elif z_layers:
return [z_layers[i] for i in range(layersForZ(h))]
elif layers_function:
return layers_function(v[0], v[1], h)
else:
dgpy.Msg.Fatal("Neither nb_layers nor z_layers nor layers_function was defined")
def getLayersShow(e, v) :
layers = getLayers(e, v)
for i in range(len(layers)):
layers[i] = factor_show * layers[i]
return layers
if mesh_file_name_out:
mesh3d = mesh_file_name_out
mesh3dShow = mesh_file_name_out[:-4] + '_show.msh'
else:
mesh3d = mesh_file_name[:-4] + '_3d.msh'
mesh3dShow = mesh_file_name[:-4] + '_3d_show.msh'
if periodicity:
slim_private.extrudePeriodic.extrudePeriodic(slim_private.mesh.mesh(mesh_file_name), getLayers, mapFilename, mapFilename).write(mesh3d)
else:
slim_private.extrude.extrude(slim_private.mesh.mesh(mesh_file_name), getLayers).write(mesh3d)
if factor_show > 0:
slim_private.extrude.extrude(slim_private.mesh.mesh(mesh_file_name), getLayersShow).write(mesh3dShow)
if dgpy.Msg.GetCommRank() == 0:
if (nb_layers and z_layers) or (nb_layers and layers_function) or (z_layers and layers_function):
dgpy.Msg.Fatal("Only one among nb_layers, z_layers and layers_function can be defined!")
if periodicity:
shiftOperation = periodicity[0]
cutTags = periodicity[1]
pasteTags = periodicity[2]
mapFilename = periodicity[3]
slim_private.periodicMap.periodicMap(mesh_file_name, '_tmp_mesh_file', 1, shiftOperation, cutTags, pasteTags, mapFilename)
slim_private.shutil.move('_tmp_mesh_file', mesh_file_name)
globNodeId2Bath = {}
mesh = slim_private.mesh.mesh(mesh_file_name)
bath = slim_private.mesh.read_idx(bath_file_name)
for entity in mesh.entities :
if entity.dimension == 2 :
for e in entity.elements :
for (i, v) in enumerate(e.vertices):
if v[3] in globNodeId2Bath:
globNodeId2Bath[v[3]] = max(globNodeId2Bath[v[3]], bath[e.tag][i])
else:
globNodeId2Bath[v[3]] = bath[e.tag][i]
def layersForZ(h) :
for i in range(len(z_layers)) :
if z_layers[i] > h :
return i
return len(z_layers)
def getLayers(e, v) :
h = globNodeId2Bath[v[3]]
if nb_layers:
return [z * h /nb_layers for z in range(nb_layers + 1)]
elif z_layers:
return [z_layers[i] for i in range(layersForZ(h))]
elif layers_function:
return layers_function(v[0], v[1], h)
else:
dgpy.Msg.Fatal("Neither nb_layers nor z_layers nor layers_function was defined")
def getLayersShow(e, v) :
layers = getLayers(e, v)
for i in range(len(layers)):
layers[i] = factor_show * layers[i]
return layers
if mesh_file_name_out:
mesh3d = mesh_file_name_out
mesh3dShow = mesh_file_name_out[:-4] + '_show.msh'
else:
mesh3d = mesh_file_name[:-4] + '_3d.msh'
mesh3dShow = mesh_file_name[:-4] + '_3d_show.msh'
if periodicity:
slim_private.extrudePeriodic.extrudePeriodic(mesh, getLayers, mapFilename, mapFilename).write(mesh3d)
else:
slim_private.extrude.extrude(mesh, getLayers).write(mesh3d)
if factor_show > 0:
slim_private.extrude.extrude(mesh, getLayersShow).write(mesh3dShow)
dgpy.Msg.Barrier()
return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment