Chi-Tech
test_modules_Diffusion_Diffusion2D_1Poly_lua.h
Go to the documentation of this file.
1/** \page test_modules_Diffusion_Diffusion2D_1Poly_lua test/modules/Diffusion/Diffusion2D_1Poly.lua
2\ingroup LuaInputExamples
3
4\code
5-- 2D Diffusion test with Dirichlet BCs.
6-- SDM: PWLC
7-- Test: Max-value=0.29480
8num_procs = 1
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
23nodes={}
24N=32
25L=2.0
26xmin = -1.0
27dx = L/N
28for i=1,(N+1) do
29 k=i-1
30 nodes[i] = xmin + k*dx
31end
32
33meshgen1 = chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {nodes,nodes} })
34chi_mesh.MeshGenerator.Execute(meshgen1)
35
36--############################################### Set Material IDs
37vol0 = chi_mesh.RPPLogicalVolume.Create({infx=true, infy=true, infz=true})
38chiVolumeMesherSetProperty(MATID_FROMLOGICAL,vol0,0)
39
40--############################################### Add materials
41materials = {}
42materials[0] = chiPhysicsAddMaterial("Test Material");
43
44chiPhysicsMaterialAddProperty(materials[0],SCALAR_VALUE)
45chiPhysicsMaterialSetProperty(materials[0],SCALAR_VALUE,SINGLE_VALUE,1.0)
46
47--############################################### Setup Physics
48phys1 = chiDiffusionCreateSolver()
49chiSolverSetBasicOption(phys1,"discretization_method","PWLC")
50chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-4)
51
52--############################################### Set boundary conditions
53--chiDiffusionSetProperty(phys1,"boundary_type",0,"reflecting",1.0)
54--chiDiffusionSetProperty(phys1,"boundary_type",1,"vacuum",2.0)
55--chiDiffusionSetProperty(phys1,"boundary_type",2,"reflecting",3.0)
56--chiDiffusionSetProperty(phys1,"boundary_type",3,"vacuum",4.0)
57
58--############################################### Initialize and Execute Solver
59chiDiffusionInitialize(phys1)
60chiDiffusionExecute(phys1)
61
62--############################################### Get field functions
63fftemp,count = chiSolverGetFieldFunctionList(phys1)
64
65--############################################### Slice plot
66slice2 = chiFFInterpolationCreate(SLICE)
67chiFFInterpolationSetProperty(slice2,SLICE_POINT,0.0,0.0,0.025)
68chiFFInterpolationSetProperty(slice2,ADD_FIELDFUNCTION,fftemp[1])
69
70chiFFInterpolationInitialize(slice2)
71chiFFInterpolationExecute(slice2)
72
73--############################################### Line plot
74line0 = chiFFInterpolationCreate(LINE)
75chiFFInterpolationSetProperty(line0,LINE_FIRSTPOINT,-1.0,0.1,0.0)
76chiFFInterpolationSetProperty(line0,LINE_SECONDPOINT, 1.0,0.1,0.0)
77chiFFInterpolationSetProperty(line0,LINE_NUMBEROFPOINTS, 100)
78chiFFInterpolationSetProperty(line0,ADD_FIELDFUNCTION,fftemp[1])
79
80chiFFInterpolationInitialize(line0)
81chiFFInterpolationExecute(line0)
82
83--############################################### Volume integrations
84ffi1 = chiFFInterpolationCreate(VOLUME)
85curffi = ffi1
86chiFFInterpolationSetProperty(curffi,OPERATION,OP_MAX)
87chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
88chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
89
90chiFFInterpolationInitialize(curffi)
91chiFFInterpolationExecute(curffi)
92maxval = chiFFInterpolationGetValue(curffi)
93
94chiLog(LOG_0,string.format("Max-value=%.5f", maxval))
95
96--############################################### Exports
97if (master_export == nil) then
98 chiFFInterpolationExportPython(slice2)
99 chiFFInterpolationExportPython(line0)
100 chiExportFieldFunctionToVTK(fftemp,"ZPhi")
101end
102
103--############################################### Plots
104if (chi_location_id == 0 and master_export == nil) then
105 local handle = io.popen("python3 ZPFFI00.py")
106 local handle = io.popen("python3 ZLFFI10.py")
107end
108\endcode
109*/
110
111