-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate.py
executable file
·91 lines (75 loc) · 3.35 KB
/
generate.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python
"""
Script to generate a range of XDMF files with Finite Element "Index + Data" format
"""
from dolfin import *
def output_scalar_xdmf(mesh, scalar_expression, file_suffix):
Q = FunctionSpace(mesh, "DG", 0)
F = Function(Q)
F.interpolate(Expression(scalar_expression, degree=1))
xdmf = XDMFFile("scalar_dg0_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = FunctionSpace(mesh, "DG", 1)
F = Function(Q)
F.interpolate(Expression(scalar_expression, degree=1))
xdmf = XDMFFile("scalar_dg1_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = FunctionSpace(mesh, "DG", 2)
F = Function(Q)
F.interpolate(Expression(scalar_expression, degree=1))
xdmf = XDMFFile("scalar_dg2_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = FunctionSpace(mesh, "CG", 1)
F = Function(Q)
F.interpolate(Expression(scalar_expression, degree=1))
xdmf = XDMFFile("scalar_cg1_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = FunctionSpace(mesh, "CG", 2)
F = Function(Q)
F.interpolate(Expression(scalar_expression, degree=1))
xdmf = XDMFFile("scalar_cg2_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
def output_vector_xdmf(mesh, vector_expression, file_suffix):
Q = VectorFunctionSpace(mesh, "DG", 0)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_dg0_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = VectorFunctionSpace(mesh, "DG", 1)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_dg1_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = VectorFunctionSpace(mesh, "DG", 2)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_dg2_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = VectorFunctionSpace(mesh, "CG", 1)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_cg1_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = VectorFunctionSpace(mesh, "CG", 2)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_cg2_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
Q = FunctionSpace(mesh, "RT", 1)
F = Function(Q)
F.interpolate(Expression(vector_expression, degree=1))
xdmf = XDMFFile("vector_rt1_" + file_suffix + ".xdmf")
xdmf.write_experimental(F, XDMFFile.Encoding_ASCII)
# 2D
mesh = UnitSquareMesh(10, 10)
output_scalar_xdmf(mesh, "sin(2*pi*x[0])*cos(2*pi*x[1])", "2D")
output_vector_xdmf(mesh, ("sin(2*pi*x[0])","cos(2*pi*x[1])"), "2D")
# 2D manifold
mesh = UnitDiscMesh(mpi_comm_world(), 5, 1, 3)
mesh.init_cell_orientations(Constant((0,0,1)))
output_scalar_xdmf(mesh, "sin(2*pi*x[0])*cos(2*pi*x[1])", "2D3")
output_vector_xdmf(mesh, ("sin(2*pi*x[0])","cos(2*pi*x[1])","1.0"), "2D3")
# 3D
mesh = UnitCubeMesh(5, 5, 5)
output_scalar_xdmf(mesh, "sin(2*pi*x[0])*cos(2*pi*x[1])", "3D")
output_vector_xdmf(mesh, ("sin(2*pi*x[0])","cos(2*pi*x[1])", "1.0"), "3D")