Chi-Tech
Tutorial_02_Output.h
Go to the documentation of this file.
1
/** \page Tutorial02 Tutorial 2: Other forms of output
2
*
3
* Solver modules in ChiTech connect their solution information to a concept
4
* called a <B>Field Function</B>. A field function is considered fully defined
5
* when it is connected to both a grid (mesh) and a spatial discretization.
6
7
\image html "Physics/FieldFunctionHierarchy.png" "Figure 1 - Hierarchy of field functions" width=600px
8
9
## Step 1 - Make a copy of Tutorial01 input
10
In the same folder (or any of your choice) make a copy of the input you used for Tutorial 1.
11
We will be adding some items to this input file.
12
13
## Step 2 - Obtain a list of field functions associated with the solver
14
15
\code
16
fflist,count = chiGetFieldFunctionList(phys1)
17
\endcode
18
19
The function call chiGetFieldFunctionList() provides us with two items. A
20
lua-table and a count of how many items there are in the table. The items
21
in "fflist" are the text names of the field functions. Each solver has its
22
own defaults.
23
24
## Step 3 - Create a slice interpolator
25
26
\code
27
slice1 = chiFFInterpolationCreate(SLICE)
28
chiFFInterpolationSetProperty(slice1,SLICE_POINT,0.0,0.0,0.0)
29
chiFFInterpolationSetProperty(slice1,ADD_FIELDFUNCTION,fflist[1])
30
\endcode
31
32
The first call creates a interpolator of type SLICE. At the time of writing this
33
tutorial we support LINE, SLICE and VOLUME. The default orientation of a slice
34
interpolator is with the cutting plane's normal pointing in the direction
35
of \f$ \hat{k} \f$ and the reference point at (0,0,0). A change in reference
36
point is achieved with a call to chiFFInterpolationSetProperty() with
37
a property index SLICE_POINT. The last line here is to add a field function to
38
this interpolator. We use the same function but this time with a property index
39
ADD_FIELDFUNCTION.
40
41
## Step 4 - Initialize and execute
42
For very complex meshes it might be prudent to perform initialization before
43
actually solving the systems, since
44
this established the necessary interpolation parameters and allows one to
45
execute the interpolator multiple times after that with minimal cost.
46
47
\code
48
chiFFInterpolationInitialize(slice1)
49
chiFFInterpolationExecute(slice1)
50
chiFFInterpolationExportPython(slice1)
51
\endcode
52
53
The chiFFInterpolationInitialize() and chiFFInterpolationExecute() should be
54
intuitive to understand. The last function call here is chiFFInterpolationExportPython()
55
which is a utility to export a slice to a python file. Inside this python
56
file there are some default visualization commands but the major utility here
57
is that the field function is now represented as python variables so that
58
the user can define custom visualizations.
59
60
## Step 5 - Run the python file
61
Being a useful scripting system, the lua console can itself invoke processes.
62
Here the default export name of the python file will be "ZPFFI00.py". Its
63
actually "ZPFFI0", for Plane-Field-Function-Interpolator-0 but the last digit
64
denotes the processor identification in
65
such a way that the user merely needs to execute the 0-index and the rest will
66
be loaded.
67
68
\code
69
local handle = io.popen("python ZPFFI00.py")
70
\endcode
71
72
The output produced is shown below:
73
74
\image html "Physics/FFOutput.png" "Figure 2 - Output produced by python script" width=600px
75
76
## Fully commented code
77
78
\code
79
--############################################### Setup mesh
80
chiMeshHandlerCreate()
81
82
nodes={}
83
N=32
84
ds=2.0/N
85
for i=0,N do
86
nodes[i+1] = -1.0 + i*ds
87
end
88
surf_mesh,region1 = chiMeshCreateUnpartitioned3DOrthoMesh(nodes,nodes,nodes)
89
90
-- chiVolumeMesherSetProperty(PARTITION_TYPE,KBA_STYLE_XYZ)
91
-- chiVolumeMesherSetKBAPartitioningPxPyPz(2,2,1)
92
-- chiVolumeMesherSetKBACutsX({0.0})
93
-- chiVolumeMesherSetKBACutsY({0.0})
94
95
chiVolumeMesherExecute();
96
97
material = chiPhysicsAddMaterial("Test Material");
98
99
-- Set Material IDs
100
vol0 = chiLogicalVolumeCreate(RPP,-1000,1000,-1000,1000,-1000,1000)
101
chiVolumeMesherSetProperty(MATID_FROMLOGICAL,vol0,material)
102
103
chiRegionExportMeshToVTK(region1,"Mesh")
104
--############################################### Add material properties
105
106
107
-- Set material properties
108
chiPhysicsMaterialAddProperty(material,SCALAR_VALUE,"k")
109
chiPhysicsMaterialSetProperty(material,"k",SINGLE_VALUE,1.0)
110
111
chiPhysicsMaterialAddProperty(material,SCALAR_VALUE,"q")
112
chiPhysicsMaterialSetProperty(material,"q",SINGLE_VALUE,1.0)
113
114
115
--############################################### Setup Physics
116
phys1 = chiDiffusionCreateSolver();
117
chiSolverAddRegion(phys1,region1)
118
chiSolverSetBasicOption(phys1,"discretization_method","PWLC");
119
chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-6)
120
121
--############################################### Initialize and
122
-- Execute Solver
123
chiDiffusionInitialize(phys1)
124
chiDiffusionExecute(phys1)
125
126
----############################################### Visualize the field function
127
fflist,count = chiGetFieldFunctionList(phys1)
128
chiExportFieldFunctionToVTK(fflist[1],"Tutorial1Output","Temperature")
129
130
slice1 = chiFFInterpolationCreate(SLICE)
131
chiFFInterpolationSetProperty(slice1,SLICE_POINT,0.0,0.0,0.0)
132
chiFFInterpolationSetProperty(slice1,ADD_FIELDFUNCTION,fflist[1])
133
134
chiFFInterpolationInitialize(slice1)
135
chiFFInterpolationExecute(slice1)
136
chiFFInterpolationExportPython(slice1)
137
138
local handle = io.popen("python ZPFFI00.py")
139
\endcode
140
141
*/
doc
PAGES
Tutorials
Tutorial_02_Output.h
Generated by
1.9.3