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