Chi-Tech
test_modules_Diffusion_Diffusion2D_1Poly_IP_lua.h
Go to the documentation of this file.
1
/** \page test_modules_Diffusion_Diffusion2D_1Poly_IP_lua test/modules/Diffusion/Diffusion2D_1Poly_IP.lua
2
\ingroup LuaInputExamples
3
4
\code
5
-- 2D Diffusion test with Vacuum and Reflecting BCs.
6
-- SDM: PWLD
7
-- Test: Max-value=2.50000
8
num_procs = 4
9
--Also tests integrating with a lua-function
10
11
12
13
14
--############################################### Check num_procs
15
if (check_num_procs==nil and chi_number_of_processes ~= num_procs) then
16
chiLog(LOG_0ERROR,"Incorrect amount of processors. " ..
17
"Expected "..tostring(num_procs)..
18
". Pass check_num_procs=false to override if possible.")
19
os.exit(false)
20
end
21
22
--############################################### Setup mesh
23
nodes={}
24
N=32
25
L=2.0
26
xmin = -1.0
27
dx = L/N
28
for i=1,(N+1) do
29
k=i-1
30
nodes[i] = xmin + k*dx
31
end
32
33
meshgen1 = chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {nodes,nodes} })
34
chi_mesh.MeshGenerator.Execute(meshgen1)
35
36
--############################################### Set Material IDs
37
vol0 = chi_mesh.RPPLogicalVolume.Create({infx=true, infy=true, infz=true})
38
chiVolumeMesherSetProperty(MATID_FROMLOGICAL,vol0,0)
39
40
e_vol = chi_mesh.RPPLogicalVolume.Create({xmin=0.99999,xmax=1000.0 , infy=true, infz=true})
41
w_vol = chi_mesh.RPPLogicalVolume.Create({xmin=-1000.0,xmax=-0.99999, infy=true, infz=true})
42
n_vol = chi_mesh.RPPLogicalVolume.Create({ymin=0.99999,ymax=1000.0 , infx=true, infz=true})
43
s_vol = chi_mesh.RPPLogicalVolume.Create({ymin=-1000.0,ymax=-0.99999, infx=true, infz=true})
44
45
e_bndry = "0"
46
w_bndry = "1"
47
n_bndry = "2"
48
s_bndry = "3"
49
50
chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,e_vol,e_bndry)
51
chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,w_vol,w_bndry)
52
chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,n_vol,n_bndry)
53
chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,s_vol,s_bndry)
54
55
--############################################### Add materials
56
materials = {}
57
materials[0] = chiPhysicsAddMaterial("Test Material");
58
59
chiPhysicsMaterialAddProperty(materials[0],SCALAR_VALUE)
60
chiPhysicsMaterialSetProperty(materials[0],SCALAR_VALUE,SINGLE_VALUE,1.0)
61
62
prop = chiPhysicsMaterialGetProperty(materials[0],SCALAR_VALUE)
63
if ((prop.is_empty ~=nil) and (not prop.is_empty)) then
64
print("Property table populated, value="..tostring(prop.value))
65
end
66
67
--############################################### Setup Physics
68
phys1 = chiDiffusionCreateSolver()
69
chiSolverSetBasicOption(phys1,"discretization_method","PWLD_MIP")
70
chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-8)
71
72
--############################################### Set boundary conditions
73
chiDiffusionSetProperty(phys1,"boundary_type",e_bndry,"vacuum")
74
chiDiffusionSetProperty(phys1,"boundary_type",w_bndry,"vacuum")
75
chiDiffusionSetProperty(phys1,"boundary_type",n_bndry,"reflecting")
76
chiDiffusionSetProperty(phys1,"boundary_type",s_bndry,"reflecting")
77
78
--############################################### Initialize and Execute Solver
79
chiDiffusionInitialize(phys1)
80
chiDiffusionExecute(phys1)
81
82
--############################################### Get field functions
83
fftemp,count = chiSolverGetFieldFunctionList(phys1)
84
85
--############################################### Slice plot
86
slice2 = chiFFInterpolationCreate(SLICE)
87
chiFFInterpolationSetProperty(slice2,SLICE_POINT,0.0,0.0,0.025)
88
chiFFInterpolationSetProperty(slice2,ADD_FIELDFUNCTION,fftemp[1])
89
90
chiFFInterpolationInitialize(slice2)
91
chiFFInterpolationExecute(slice2)
92
93
--############################################### Volume integrations
94
ffi1 = chiFFInterpolationCreate(VOLUME)
95
curffi = ffi1
96
chiFFInterpolationSetProperty(curffi,OPERATION,OP_MAX)
97
chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
98
chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
99
100
chiFFInterpolationInitialize(curffi)
101
chiFFInterpolationExecute(curffi)
102
maxval = chiFFInterpolationGetValue(curffi)
103
104
chiLog(LOG_0,string.format("Max-value=%.5f", maxval))
105
106
--==========================================
107
xwing=2.0
108
function IntegrateMaterialVolume(ff_value,mat_id)
109
return xwing
110
end
111
ffi2 = chiFFInterpolationCreate(VOLUME)
112
curffi = ffi2
113
chiFFInterpolationSetProperty(curffi,OPERATION,OP_SUM_LUA,"IntegrateMaterialVolume")
114
chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
115
chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
116
117
chiFFInterpolationInitialize(curffi)
118
chiFFInterpolationExecute(curffi)
119
print(chiFFInterpolationGetValue(curffi))
120
--==========================================
121
122
--############################################### Exports
123
if (master_export == nil) then
124
chiFFInterpolationExportPython(slice2)
125
chiExportFieldFunctionToVTK(fftemp,"ZPhi")
126
end
127
128
--############################################### Plots
129
if (chi_location_id == 0 and master_export == nil) then
130
local handle = io.popen("python ZPFFI00.py")
131
end
132
133
134
\endcode
135
*/
136
137
doc
generated_files
test
modules
Diffusion
test_modules_Diffusion_Diffusion2D_1Poly_IP_lua.h
Generated by
1.9.3