On Thu, 2019-02-14 at 10:56 -0500, Max Orok wrote:
> Jeremy,
>
> You're right, there isn't any explicit averaging going on, it just
> goes through all the nodes and assigns values based on their number.
> After assigning I trusted Gmsh to display them nicely :):)
ok, I now finally understood your script... I made up a simplified 2d
version, see attached
> This does mean that node data values are set multiple times -> to the
> same value (magnitude at least).
yes, I can see... nodes 2 and 3 get scalars 5 and 8, whilst I would
expect and averaging between 2 and 5 in node 2 and 8 and 3 in node 3 :-
/
> A lot of the data on each row is duplicated elsewhere in the file, my
> idea was that if the elements were ordered correctly, the
> repeated overwrite wouldn't matter as long as the overwrite contained
> the same number.
this is the point, the data is not repeated! stresses or whatever
evaluated at the gauss points in different elements will surely contain
different values, even if they are near the same node... am I clear?
I am interesting in seeing how to average these values to assign them
to the shared node...
plain average? weighted average? how? using the element's volume? the
element's quality? etc
regards
--
jeremy theler
www.seamplex.com
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
6
1 0 0 0
2 1 0 0
3 1 1 0
4 0 1 0
5 2 0 0
6 2 1 0
$EndNodes
$Elements
2
1 3 2 1 1 1 2 3 4
2 3 2 1 1 2 5 6 3
$EndElements
import gmsh
import math
model = gmsh.model
factory = model.occ
# spin up gmsh API
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
# read in the stresses as arrays of floats
# -> assume 15 sigdigs is enough
with open("gauss-scalars.txt") as file:
bare_scalars = [[float(val) for val in line.split()] for line in file]
scalars = []
for scalar_line in bare_scalars:
s = scalar_line[0]
scalars.append([s])
print scalars
print len(scalars)
# --
# import the mesh
gmsh.open("quad.msh2")
# find element & node tags
# -> exit if the type isn't hexa (5) as a quick precaution
(elt_types, elt_tags, node_tags) = gmsh.model.mesh.getElements()
quad_type = 3 # (c.f. section 9.1 gmsh documentation)
if len(elt_types) != 1 or elt_types[0] != quad_type:
quit()
# comes back as array of arrays, get the nodes as a bare array of ints
elt_tags = elt_tags[0]
node_tags = node_tags[0]
# --
# get the model name
model_names = gmsh.model.list()
curr_model = model_names[0]
# add the stress data
# make a stress view tag
scalars_view_tag = gmsh.view.add("scalars")
# (c.f. the gmsh.py header)
# >> def addModelData(tag, step, modelName, dataType, tags, data, time=0., numComponents=-1, partition=0)
print node_tags
print scalars
gmsh.view.addModelData(scalars_view_tag, 0, curr_model, "NodeData", node_tags, scalars)
# --
# output the data
out_filename = "quad_data.msh"
# save as new mesh file
# first we save the stresses
# @arg False -> don't want to append for first view
gmsh.view.write(scalars_view_tag, out_filename, False)
# close gmsh
gmsh.finalize();
$MeshFormat
4 0 8
$EndMeshFormat
$Entities
0 0 1 0
1 0 0 0 2 1 0 1 1 0
$EndEntities
$Nodes
1 6
1 2 0 6
1 0 0 0
2 1 0 0
3 1 1 0
4 0 1 0
5 2 0 0
6 2 1 0
$EndNodes
$Elements
1 2
1 2 3 2
1 1 2 3 4
2 2 5 6 3
$EndElements
$InterpolationScheme
"INTERPOLATION_SCHEME"
1
4
2
4 4
0.25 -0.25 0.25 -0.25
0.25 0.25 -0.25 -0.25
0.25 0.25 0.25 0.25
0.25 -0.25 -0.25 0.25
4 2
0 0
1 0
1 1
0 1
$EndInterpolationScheme
$NodeData
1
"scalars"
1
0
3
0
1
6
1 1
2 5
3 8
4 4
5 6
6 7
$EndNodeData
_______________________________________________
gmsh mailing list
[email protected]
http://onelab.info/mailman/listinfo/gmsh