forked from ImperialCollegeLondon/multifluids_icferst
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransform_mesh.py
executable file
·48 lines (38 loc) · 1.43 KB
/
transform_mesh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
from optparse import OptionParser
import sys
import math
import fluidity.diagnostics.gmshtools as gmshtools
#####################################################################
# Script starts here.
optparser=OptionParser(usage='usage: %prog transformation mesh',
add_help_option=True,
description="""Applies a coordinate transformation to the given mesh.""")
optparser.set_usage(
"usage: %prog <transformation> <mesh>\n\n"+
"<transformation> is a python expression giving the coordinate transformation.\n"+
"<mesh> is the name of the gmsh mesh file. You need a mesh.msh file.\n"+
"\n"+
"Example:\n"
"To rescale the z-dimension by a factor of 1000,\n"
"%prog '(x,y,1000*z)' mesh.\n"
)
(options, argv) = optparser.parse_args()
if len(argv) != 2:
optparser.print_help()
sys.exit(1)
transformation = argv[0]
mesh_name = argv[1]
# make all definitions of the math module available in
# the transformation expression.
globals = math.__dict__
mesh = gmshtools.ReadMsh(mesh_name+'.msh')
dim = mesh.GetDim()
def remap(coords):
globals['x'] = coords[0]
globals['y'] = coords[1]
if dim == 3:
globals['z'] = coords[2]
return eval(transformation, globals)
mesh.RemapNodeCoords(remap)
gmshtools.WriteMsh(mesh, mesh_name+'.msh')