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
8num_procs = 4
9--Also tests integrating with a lua-function
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
40e_vol = chi_mesh.RPPLogicalVolume.Create({xmin=0.99999,xmax=1000.0 , infy=true, infz=true})
41w_vol = chi_mesh.RPPLogicalVolume.Create({xmin=-1000.0,xmax=-0.99999, infy=true, infz=true})
42n_vol = chi_mesh.RPPLogicalVolume.Create({ymin=0.99999,ymax=1000.0 , infx=true, infz=true})
43s_vol = chi_mesh.RPPLogicalVolume.Create({ymin=-1000.0,ymax=-0.99999, infx=true, infz=true})
44
45e_bndry = "0"
46w_bndry = "1"
47n_bndry = "2"
48s_bndry = "3"
49
50chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,e_vol,e_bndry)
51chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,w_vol,w_bndry)
52chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,n_vol,n_bndry)
53chiVolumeMesherSetProperty(BNDRYID_FROMLOGICAL,s_vol,s_bndry)
54
55--############################################### Add materials
56materials = {}
57materials[0] = chiPhysicsAddMaterial("Test Material");
58
59chiPhysicsMaterialAddProperty(materials[0],SCALAR_VALUE)
60chiPhysicsMaterialSetProperty(materials[0],SCALAR_VALUE,SINGLE_VALUE,1.0)
61
62prop = chiPhysicsMaterialGetProperty(materials[0],SCALAR_VALUE)
63if ((prop.is_empty ~=nil) and (not prop.is_empty)) then
64 print("Property table populated, value="..tostring(prop.value))
65end
66
67--############################################### Setup Physics
68phys1 = chiDiffusionCreateSolver()
69chiSolverSetBasicOption(phys1,"discretization_method","PWLD_MIP")
70chiSolverSetBasicOption(phys1,"residual_tolerance",1.0e-8)
71
72--############################################### Set boundary conditions
73chiDiffusionSetProperty(phys1,"boundary_type",e_bndry,"vacuum")
74chiDiffusionSetProperty(phys1,"boundary_type",w_bndry,"vacuum")
75chiDiffusionSetProperty(phys1,"boundary_type",n_bndry,"reflecting")
76chiDiffusionSetProperty(phys1,"boundary_type",s_bndry,"reflecting")
77
78--############################################### Initialize and Execute Solver
79chiDiffusionInitialize(phys1)
80chiDiffusionExecute(phys1)
81
82--############################################### Get field functions
83fftemp,count = chiSolverGetFieldFunctionList(phys1)
84
85--############################################### Slice plot
86slice2 = chiFFInterpolationCreate(SLICE)
87chiFFInterpolationSetProperty(slice2,SLICE_POINT,0.0,0.0,0.025)
88chiFFInterpolationSetProperty(slice2,ADD_FIELDFUNCTION,fftemp[1])
89
90chiFFInterpolationInitialize(slice2)
91chiFFInterpolationExecute(slice2)
92
93--############################################### Volume integrations
94ffi1 = chiFFInterpolationCreate(VOLUME)
95curffi = ffi1
96chiFFInterpolationSetProperty(curffi,OPERATION,OP_MAX)
97chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
98chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
99
100chiFFInterpolationInitialize(curffi)
101chiFFInterpolationExecute(curffi)
102maxval = chiFFInterpolationGetValue(curffi)
103
104chiLog(LOG_0,string.format("Max-value=%.5f", maxval))
105
106--==========================================
107xwing=2.0
108function IntegrateMaterialVolume(ff_value,mat_id)
109 return xwing
110end
111ffi2 = chiFFInterpolationCreate(VOLUME)
112curffi = ffi2
113chiFFInterpolationSetProperty(curffi,OPERATION,OP_SUM_LUA,"IntegrateMaterialVolume")
114chiFFInterpolationSetProperty(curffi,LOGICAL_VOLUME,vol0)
115chiFFInterpolationSetProperty(curffi,ADD_FIELDFUNCTION,fftemp[1])
116
117chiFFInterpolationInitialize(curffi)
118chiFFInterpolationExecute(curffi)
119print(chiFFInterpolationGetValue(curffi))
120--==========================================
121
122--############################################### Exports
123if (master_export == nil) then
124 chiFFInterpolationExportPython(slice2)
125 chiExportFieldFunctionToVTK(fftemp,"ZPhi")
126end
127
128--############################################### Plots
129if (chi_location_id == 0 and master_export == nil) then
130 local handle = io.popen("python ZPFFI00.py")
131end
132
133
134\endcode
135*/
136
137