Chi-Tech
test_modules_Diffusion_Diffusion3D_2Ortho_lua.h
Go to the documentation of this file.
1/** \page test_modules_Diffusion_Diffusion3D_2Ortho_lua test/modules/Diffusion/Diffusion3D_2Ortho.lua
2\ingroup LuaInputExamples
3
4\code
5-- 3D Diffusion test with Dirichlet and Reflecting BCs.
6-- SDM: PWLC
7-- Test: Max-value=0.29480
8num_procs = 1
9-- Uses extruder mesh
10
11
12
13
14--############################################### Check num_procs
15if (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)
20end
21
22--############################################### Setup mesh
23L=2.0
24N=32
25ds=L/N
26nodes={}
27for k=0,N do
28 nodes[k+1] = -1.0 + ds*k
29end
30meshgen1 = chi_mesh.ExtruderMeshGenerator.Create
31({
32 inputs =
33 {
34 chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {nodes,nodes} }),
35 },
36 layers = {{z=0.2,n=2}}, -- layers
37 partitioner = chi.KBAGraphPartitioner.Create
38 ({
39 nx = 2, ny=2, nz=1,
40 xcuts = {0.0}, ycuts = {0.0}
41 })
42})
43chi_mesh.MeshGenerator.Execute(meshgen1)
44
45
46--############################################### Set Material IDs
47vol0 = chi_mesh.RPPLogicalVolume.Create({infx=true, infy=true, infz=true})
48chiVolumeMesherSetProperty(MATID_FROMLOGICAL,vol0,0)
49chiVolumeMesherSetupOrthogonalBoundaries()
50
51--############################################### Add materials
52materials = {}
53materials[0] = chiPhysicsAddMaterial("Test Material");
54
55chiPhysicsMaterialAddProperty(materials[0],SCALAR_VALUE)
56chiPhysicsMaterialSetProperty(materials[0],SCALAR_VALUE,SINGLE_VALUE,1.0)
57
58--############################################### Setup Physics
59phys1 = chiDiffusionCreateSolver()
60chiSolverSetBasicOption(phys1,"discretization_method","PWLC")
61chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-6)
62
63--############################################### Set boundary conditions
64chiDiffusionSetProperty(phys1,"boundary_type","ZMIN","reflecting")
65chiDiffusionSetProperty(phys1,"boundary_type","ZMAX","reflecting")
66
67--############################################### Initialize and Execute Solver
68chiDiffusionInitialize(phys1)
69chiDiffusionExecute(phys1)
70
71--############################################### Get field functions
72fftemp,count = chiSolverGetFieldFunctionList(phys1)
73
74--############################################### Slice plot
75slice1 = chiFFInterpolationCreate(SLICE)
76chiFFInterpolationSetProperty(slice1,SLICE_POINT,0.008,0.0,0.0)
77chiFFInterpolationSetProperty(slice1,SLICE_BINORM,0.0,0.0,1.0)
78chiFFInterpolationSetProperty(slice1,SLICE_TANGENT,0.0,-1.0,0.0)
79chiFFInterpolationSetProperty(slice1,SLICE_NORMAL,1.0,0.0,0.0)
80chiFFInterpolationSetProperty(slice1,ADD_FIELDFUNCTION,fftemp[1])
81
82chiFFInterpolationInitialize(slice1)
83chiFFInterpolationExecute(slice1)
84
85slice2 = chiFFInterpolationCreate(SLICE)
86chiFFInterpolationSetProperty(slice2,SLICE_POINT,0.0,0.0,0.025)
87chiFFInterpolationSetProperty(slice2,ADD_FIELDFUNCTION,fftemp[1])
88
89chiFFInterpolationInitialize(slice2)
90chiFFInterpolationExecute(slice2)
91
92--############################################### Line plot
93line0 = chiFFInterpolationCreate(LINE)
94chiFFInterpolationSetProperty(line0,LINE_FIRSTPOINT,-1.0,0.0,0.025)
95chiFFInterpolationSetProperty(line0,LINE_SECONDPOINT, 1.0,0.0,0.025)
96chiFFInterpolationSetProperty(line0,LINE_NUMBEROFPOINTS, 100)
97chiFFInterpolationSetProperty(line0,ADD_FIELDFUNCTION,fftemp[1])
98
99chiFFInterpolationInitialize(line0)
100chiFFInterpolationExecute(line0)
101
102--############################################### Volume integrations
103ffi1 = chiFFInterpolationCreate(VOLUME)
104curffi = ffi1
105chiFFInterpolationSetProperty(curffi,OPERATION,OP_MAX)
106chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
107chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
108
109chiFFInterpolationInitialize(curffi)
110chiFFInterpolationExecute(curffi)
111maxval = chiFFInterpolationGetValue(curffi)
112
113chiLog(LOG_0,string.format("Max-value=%.5f", maxval))
114
115--############################################### Exports
116if (master_export == nil) then
117 chiFFInterpolationExportPython(slice1)
118 chiFFInterpolationExportPython(slice2)
119 chiFFInterpolationExportPython(line0)
120 chiExportFieldFunctionToVTK(fftemp,"ZPhi")
121end
122
123--############################################### Plots
124if (chi_location_id == 0 and master_export == nil) then
125 local handle = io.popen("python3 ZPFFI00.py")
126 local handle = io.popen("python3 ZPFFI10.py")
127 local handle = io.popen("python3 ZLFFI20.py")
128 print("Execution completed")
129end
130
131\endcode
132*/
133
134