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
10In the same folder (or any of your choice) make a copy of the input you used for Tutorial 1.
11We 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
27slice1 = chiFFInterpolationCreate(SLICE)
28chiFFInterpolationSetProperty(slice1,SLICE_POINT,0.0,0.0,0.0)
29chiFFInterpolationSetProperty(slice1,ADD_FIELDFUNCTION,fflist[1])
30\endcode
31
32The 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
42For 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
48chiFFInterpolationInitialize(slice1)
49chiFFInterpolationExecute(slice1)
50chiFFInterpolationExportPython(slice1)
51\endcode
52
53The 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
61Being 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
69local handle = io.popen("python ZPFFI00.py")
70\endcode
71
72The 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
80chiMeshHandlerCreate()
81
82nodes={}
83N=32
84ds=2.0/N
85for i=0,N do
86 nodes[i+1] = -1.0 + i*ds
87end
88surf_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
95chiVolumeMesherExecute();
96
97material = chiPhysicsAddMaterial("Test Material");
98
99-- Set Material IDs
100vol0 = chiLogicalVolumeCreate(RPP,-1000,1000,-1000,1000,-1000,1000)
101chiVolumeMesherSetProperty(MATID_FROMLOGICAL,vol0,material)
102
103chiRegionExportMeshToVTK(region1,"Mesh")
104--############################################### Add material properties
105
106
107-- Set material properties
108chiPhysicsMaterialAddProperty(material,SCALAR_VALUE,"k")
109chiPhysicsMaterialSetProperty(material,"k",SINGLE_VALUE,1.0)
110
111chiPhysicsMaterialAddProperty(material,SCALAR_VALUE,"q")
112chiPhysicsMaterialSetProperty(material,"q",SINGLE_VALUE,1.0)
113
114
115--############################################### Setup Physics
116phys1 = chiDiffusionCreateSolver();
117chiSolverAddRegion(phys1,region1)
118chiSolverSetBasicOption(phys1,"discretization_method","PWLC");
119chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-6)
120
121--############################################### Initialize and
122-- Execute Solver
123chiDiffusionInitialize(phys1)
124chiDiffusionExecute(phys1)
125
126----############################################### Visualize the field function
127fflist,count = chiGetFieldFunctionList(phys1)
128chiExportFieldFunctionToVTK(fflist[1],"Tutorial1Output","Temperature")
129
130slice1 = chiFFInterpolationCreate(SLICE)
131chiFFInterpolationSetProperty(slice1,SLICE_POINT,0.0,0.0,0.0)
132chiFFInterpolationSetProperty(slice1,ADD_FIELDFUNCTION,fflist[1])
133
134chiFFInterpolationInitialize(slice1)
135chiFFInterpolationExecute(slice1)
136chiFFInterpolationExportPython(slice1)
137
138local handle = io.popen("python ZPFFI00.py")
139\endcode
140
141 */