├── .gitignore ├── README.md ├── diagram.png ├── dropTest1 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── .gitignore ├── cfd_dropTest1.py ├── constant │ └── transportProperties ├── dropTest1.p3prj ├── dropTest1.png ├── pfc_dropTest1.py ├── pfc_single.py └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── dropTest2 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── cfd_dropTest2.py ├── constant │ └── transportProperties ├── dropTest2.p3prj ├── dropTest2.png ├── pfc_dropTest2.py └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── fluidized_bed_1 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── 1.png ├── cfd_fluidized_bed_1.py ├── constant │ └── transportProperties ├── fluidized_bed_1.p3prj ├── ini.sav ├── pfc_fluidized_bed_1.py └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── fluidized_bed_2 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── 1.png ├── 2.png ├── 3.png ├── cfd_fluidized_bed_2.py ├── constant │ └── transportProperties ├── fluidized_bed_2.p3prj ├── ini.sav ├── make_ini.py ├── pfc_fluidized_bed_2.py ├── solution.p3dat └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── fluidized_bed_3 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── cfd_fluidized_bed_3.py ├── constant │ └── transportProperties ├── fluidized_bed_3.p3prj ├── make_ini.p3dat ├── pfc_fluidized_bed_3.py ├── solution.p3dat └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── fluidized_bed_4 ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── cfd_fluidized_bed_4.py ├── constant │ └── transportProperties ├── fluidized_bed_4.p3prj ├── make_ini.p3dat ├── pfc_fluidized_bed_4.py └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── notes.org ├── pfc_cfd_coupler ├── pfc_cfd_coupler │ ├── __init__.py │ ├── cfd_coupler.py │ └── pfc_coupler.py └── setup.py ├── porous ├── 0 │ ├── U │ ├── f │ ├── n │ └── p ├── 1.png ├── 2.png ├── 3.png ├── cfd_porous.py ├── constant │ └── transportProperties ├── elements.geom ├── particles.p3dat ├── pfc_porous.py ├── porous.p3prj ├── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution └── vel.txt ├── porous1 ├── 0 │ ├── U │ ├── beta │ ├── f │ ├── n │ ├── p │ └── ubar ├── .gitignore ├── 1.png ├── cfd_porous1.py ├── constant │ └── transportProperties ├── particles.p3dat ├── pfc_porous1.py ├── porous1.p3prj ├── porous1.png ├── scfd_porous1.py ├── spfc_porous1.py └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── porous2 ├── 0 │ ├── U │ ├── beta │ ├── f │ ├── n │ ├── p │ └── ubar ├── cfd_porous2.py ├── constant │ └── transportProperties ├── particles.p3dat ├── pfc_porous2.py ├── porous2.p3prj └── system │ ├── blockMeshDict │ ├── controlDict │ ├── fvSchemes │ └── fvSolution ├── pyDemFoam ├── .gitignore ├── _pyDemFoam.pyx ├── demBaseFoam.C ├── demBaseFoam.H ├── demIcoFoam.C ├── demIcoFoam.H ├── demIcoFoamSemiImplicitDrag.C ├── demIcoFoamSemiImplicitDrag.H ├── demSimpleFoam.C ├── demSimpleFoam.H ├── icoFoam_expanded.C ├── pyDemFoam │ └── __init__.py └── setup.py ├── sctetracoupler ├── client_for_custom_server.py ├── customsocket.py ├── make_ini.p3dat ├── sctetracoupler.py └── test.py └── wrapper_tests ├── 0 ├── U ├── beta ├── f ├── n ├── p └── ubar ├── constant └── transportProperties ├── system ├── blockMeshDict ├── controlDict ├── fvSchemes └── fvSolution ├── test_pyDemIcoFoam.py └── test_pyDemSimpleFoam.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | polyMesh/ 3 | /pyDemIcoFoam/log.txt 4 | /porous1/gradp.dat 5 | /porous1/p.dat 6 | /porous1/u.dat 7 | /porous1/vvec.pvsm 8 | 0.*/ 9 | /pyDemFoam/_pyDemFoam.cpp 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/README.md -------------------------------------------------------------------------------- /diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/diagram.png -------------------------------------------------------------------------------- /dropTest1/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | droptest1.txt 3 | final.sav 4 | -------------------------------------------------------------------------------- /dropTest1/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type fixedValue; 31 | value uniform (0 0 0); 32 | } 33 | } 34 | 35 | // ************************************************************************* // 36 | -------------------------------------------------------------------------------- /dropTest1/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | fixedWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | } 35 | 36 | // ************************************************************************* // 37 | -------------------------------------------------------------------------------- /dropTest1/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type zeroGradient; 31 | } 32 | } 33 | 34 | // ************************************************************************* // 35 | -------------------------------------------------------------------------------- /dropTest1/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform 0; 27 | } 28 | 29 | fixedWalls 30 | { 31 | type zeroGradient; 32 | } 33 | } 34 | 35 | // ************************************************************************* // 36 | -------------------------------------------------------------------------------- /dropTest1/cfd_dropTest1.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | pfc_link.connect("127.0.0.1") 9 | 10 | pfc_link.send_data(solver.nodes()) 11 | pfc_link.send_data(solver.elements()) 12 | pfc_link.send_data(solver.rho()) 13 | pfc_link.send_data(solver.mu()) 14 | 15 | while True: 16 | deltat = pfc_link.read_data() 17 | if deltat == 0.0: 18 | print("solve finished") 19 | break 20 | solver.n(pfc_link.read_data()) 21 | solver.f(pfc_link.read_data()) 22 | 23 | solver.set_dt(deltat) 24 | solver.solve(deltat) 25 | 26 | pfc_link.send_data(solver.p()*solver.rho()) 27 | pfc_link.send_data(solver.gradp()*solver.rho()) 28 | pfc_link.send_data(solver.U()) 29 | 30 | pfc_link.close() 31 | del pfc_link 32 | -------------------------------------------------------------------------------- /dropTest1/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.1905e-3; 19 | rho [1 -3 0 0 0 0 0] 1260.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /dropTest1/dropTest1.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/dropTest1/dropTest1.p3prj -------------------------------------------------------------------------------- /dropTest1/dropTest1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/dropTest1/dropTest1.png -------------------------------------------------------------------------------- /dropTest1/pfc_dropTest1.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | it.command("python-reset-state false") 3 | from itasca import cfdarray as ca 4 | from itasca.util import p2pLinkServer 5 | 6 | import numpy as np 7 | 8 | cfd_link = p2pLinkServer() 9 | cfd_link.start() 10 | 11 | nodes = cfd_link.read_data() 12 | elements = cfd_link.read_data() 13 | fluid_density = cfd_link.read_data() 14 | fluid_viscosity = cfd_link.read_data() 15 | print(fluid_density, fluid_viscosity) 16 | nmin, nmax = np.amin(nodes,axis=0), np.amax(nodes,axis=0) 17 | diag = np.linalg.norm(nmin-nmax) 18 | dmin, dmax = nmin -0.1*diag, nmax+0.1*diag 19 | print(dmin, dmax) 20 | 21 | it.command(""" 22 | model new 23 | MODEL LARGE-STRAIN on 24 | domain extent {} {} {} {} {} {} 25 | """.format(dmin[0], dmax[0], 26 | dmin[1], dmax[1], 27 | dmin[2], dmax[2])) 28 | elements = elements.astype(np.longlong) # need to fix the c++ side, this is a work around for a platform type size issue. 29 | ca.create_mesh(nodes, elements) 30 | 31 | it.command(""" 32 | model config cfd 33 | model mechanical timestep max 1e-5 34 | element cfd ini density {} 35 | element cfd ini visc {} 36 | ;cfd porosity poly 37 | cfd buoy on 38 | ball create rad 0.005 pos 0.5 0.5 0.5 39 | ball ini dens 2500 40 | ball prop "kn" 1e2 "ks" 1e2 "fric" 0.25 41 | model gravity 0 0 -9.81 42 | def fluid_time 43 | global fluid_time = mech.time.total 44 | end 45 | history fish id 1 fluid_time 46 | ball history id 2 velocity-z id 1 47 | ball history id 3 force-unbalanced-z id 1 48 | ;ball cfd history id 4 zforce id 1 ;; does not seem to work?? 49 | ;plot clear 50 | ;plot add hist 2 vs 1 51 | ;plot add cfdelement shape arrow colorby vectorattribute "velocity" 52 | """.format(fluid_density, fluid_viscosity)) 53 | 54 | element_volume = ca.volume() 55 | dt = 0.005 56 | 57 | for i in range(75): 58 | it.command("solve age {}".format(it.mech_age()+dt)) 59 | cfd_link.send_data(dt) # solve interval 60 | cfd_link.send_data(ca.porosity()) 61 | cfd_link.send_data((ca.drag().T/element_volume).T/fluid_density) 62 | ca.set_pressure(cfd_link.read_data()) 63 | ca.set_pressure_gradient(cfd_link.read_data()) 64 | ca.set_velocity(cfd_link.read_data()) 65 | 66 | cfd_link.send_data(0.0) # solve interval 67 | cfd_link.close() 68 | del cfd_link 69 | 70 | print("ball z velocity", it.ball.find(1).vel_z()) 71 | it.command("history export 1,2,3 file 'droptest1.txt' truncate") 72 | it.command("model save 'final.sav'") 73 | -------------------------------------------------------------------------------- /dropTest1/pfc_single.py: -------------------------------------------------------------------------------- 1 | assert False, "this is a work in progress" 2 | import itasca as it 3 | it.command("python-reset-state false") 4 | from itasca import cfdarray as ca 5 | from pyDemFoam import pyDemIcoFoam 6 | import numpy as np 7 | 8 | solver = pyDemIcoFoam() 9 | nodes = solver.nodes() 10 | elements = solver.elements() 11 | fluid_density = solver.rho() 12 | fluid_viscosity = solver.mu() 13 | print(fluid_density, fluid_viscosity) 14 | nmin, nmax = np.amin(nodes,axis=0), np.amax(nodes,axis=0) 15 | diag = np.linalg.norm(nmin-nmax) 16 | dmin, dmax = nmin -0.1*diag, nmax+0.1*diag 17 | print(dmin, dmax) 18 | it.command(""" 19 | ;model new 20 | MODEL LARGE-STRAIN on 21 | domain extent {} {} {} {} {} {} 22 | """.format(dmin[0], dmax[0], 23 | dmin[1], dmax[1], 24 | dmin[2], dmax[2])) 25 | elements = elements.astype(np.longlong) # need to fix the c++ side, this is a work around for a platform type size issue. 26 | ca.create_mesh(nodes, elements) 27 | 28 | it.command(""" 29 | model config cfd 30 | model mechanical timestep max 1e-5 31 | element cfd ini density {} 32 | element cfd ini visc {} 33 | ;cfd porosity poly 34 | cfd buoy on 35 | ball create rad 0.005 pos 0.5 0.5 0.5 36 | ball ini dens 2500 37 | ball prop "kn" 1e2 "ks" 1e2 "fric" 0.25 38 | model gravity 0 0 -9.81 39 | def fluid_time 40 | global fluid_time = mech.time.total 41 | end 42 | history fish id 1 fluid_time 43 | ball history id 2 velocity-z id 1 44 | ball history id 3 force-unbalanced-z id 1 45 | ;ball cfd history id 4 zforce id 1 ;; does not seem to work?? 46 | ;plot clear 47 | ;plot add hist 2 vs 1 48 | ;plot add cfdelement shape arrow colorby vectorattribute "velocity" 49 | """.format(fluid_density, fluid_viscosity)) 50 | 51 | element_volume = ca.volume() 52 | dt = 0.005 53 | 1/0 54 | for i in range(75): 55 | it.command("solve age {}".format(it.mech_age()+dt)) 56 | solver.n(ca.porosity()) 57 | solver.f((ca.drag().T/element_volume).T/fluid_density) 58 | solver.set_dt(dt) 59 | solver.solve(dt) 60 | 61 | ca.set_pressure(solver.p()*solver.rho()) 62 | ca.set_pressure_gradient(solver.gradp()*solver.rho()) 63 | ca.set_velocity(solver.U()) 64 | 65 | print("ball z velocity", it.ball.find(1).vel_z()) 66 | it.command("history export 1,2,3 file 'droptest1.txt' truncate") 67 | it.command("model save 'final.sav'") 68 | -------------------------------------------------------------------------------- /dropTest1/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | //convertToMeters 0.1; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (1 0 0) 23 | (1 1 0) 24 | (0 1 0) 25 | (0 0 1) 26 | (1 0 1) 27 | (1 1 1) 28 | (0 1 1) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (11 11 11) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | topWall 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (4 5 6 7) 48 | ); 49 | } 50 | fixedWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (0 4 7 3) 56 | (2 6 5 1) 57 | (1 5 4 0) 58 | (0 3 2 1) 59 | (3 7 6 2) 60 | ); 61 | } 62 | ); 63 | 64 | mergePatchPairs 65 | ( 66 | ); 67 | 68 | // ************************************************************************* // 69 | -------------------------------------------------------------------------------- /dropTest1/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.5; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /dropTest1/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /dropTest1/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | pFinal 27 | { 28 | $p; 29 | relTol 0; 30 | } 31 | U 32 | { 33 | solver smoothSolver; 34 | smoother symGaussSeidel; 35 | tolerance 1e-05; 36 | relTol 0; 37 | } 38 | } 39 | 40 | PISO 41 | { 42 | nCorrectors 2; 43 | nNonOrthogonalCorrectors 0; 44 | pRefCell 0; 45 | pRefValue 0; 46 | } 47 | -------------------------------------------------------------------------------- /dropTest2/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type fixedValue; 31 | value uniform (0 0 0); 32 | } 33 | } 34 | 35 | // ************************************************************************* // 36 | -------------------------------------------------------------------------------- /dropTest2/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | fixedWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | } 35 | 36 | // ************************************************************************* // 37 | -------------------------------------------------------------------------------- /dropTest2/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type zeroGradient; 31 | } 32 | } 33 | 34 | // ************************************************************************* // 35 | -------------------------------------------------------------------------------- /dropTest2/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform 0; 27 | } 28 | 29 | fixedWalls 30 | { 31 | type zeroGradient; 32 | } 33 | } 34 | 35 | // ************************************************************************* // 36 | -------------------------------------------------------------------------------- /dropTest2/cfd_dropTest2.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.cell_centers()) 14 | pfc_link.send_data(solver.cell_volumes()) 15 | pfc_link.send_data(solver.rho()) 16 | pfc_link.send_data(solver.mu()) 17 | 18 | while True: 19 | deltat = pfc_link.read_data() 20 | if deltat == 0.0: 21 | print "solve finished" 22 | break 23 | solver.n(pfc_link.read_data()) 24 | solver.f(pfc_link.read_data()) 25 | 26 | solver.set_dt(deltat) 27 | solver.solve(deltat) 28 | 29 | pfc_link.send_data(solver.p()*solver.rho()) 30 | pfc_link.send_data(solver.gradp()*solver.rho()) 31 | pfc_link.send_data(solver.U()) 32 | 33 | pfc_link.close() 34 | del pfc_link -------------------------------------------------------------------------------- /dropTest2/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.1905e-3; 19 | rho [1 -3 0 0 0 0 0] 1260.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /dropTest2/dropTest2.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/dropTest2/dropTest2.p3prj -------------------------------------------------------------------------------- /dropTest2/dropTest2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/dropTest2/dropTest2.png -------------------------------------------------------------------------------- /dropTest2/pfc_dropTest2.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from pfc_cfd_coupler.pfc_coupler import pfc_coupler 3 | 4 | coupler = pfc_coupler() 5 | it.command(""" 6 | ball create rad 0.005 x 0.5 y 0.5 z 0.5 7 | ball ini dens 2500 8 | ball prop kn 1e2 ks 1e2 fric 0.25 9 | set gravity 0 0 -9.81 10 | def fluid_time 11 | global fluid_time = mech.age 12 | end 13 | def appforce 14 | global appforce = ball.force.app.z(ball.find(1)) 15 | end 16 | history add id 1 fish @fluid_time 17 | ball history id 2 zvelocity id 1 18 | ball history id 3 zunbalforce id 1 19 | history add id 4 fish @appforce 20 | plot clear 21 | plot add hist 2 vs 1 22 | plot add ball shape arrow 23 | plot add axes 24 | plot add domain 25 | plot add udvector 26 | """) 27 | 28 | coupler.dt = 0.005 29 | coupler.bandwidth = 0.3 30 | coupler.solve(100) 31 | coupler.plotFluidUnitVel() 32 | coupler.close() 33 | 34 | print "ball z velocity", it.ball.find(1).vel_z() 35 | it.command("history write 1,2,3,4 file 'droptest2.txt' truncate") -------------------------------------------------------------------------------- /dropTest2/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | //convertToMeters 0.1; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (1 0 0) 23 | (1 1 0) 24 | (0 1 0) 25 | (0 0 1) 26 | (1 0 1) 27 | (1 1 1) 28 | (0 1 1) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (11 11 11) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | topWall 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (4 5 6 7) 48 | ); 49 | } 50 | fixedWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (0 4 7 3) 56 | (2 6 5 1) 57 | (1 5 4 0) 58 | (0 3 2 1) 59 | (3 7 6 2) 60 | ); 61 | } 62 | ); 63 | 64 | mergePatchPairs 65 | ( 66 | ); 67 | 68 | // ************************************************************************* // 69 | -------------------------------------------------------------------------------- /dropTest2/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.5; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /dropTest2/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /dropTest2/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /fluidized_bed_1/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type uniformFixedValue; 26 | uniformValue table ((0 (0 0 0)) (0.01 (0 1.5 0)) (0.02 (0 0 0))); 27 | } 28 | 29 | outletWalls 30 | { 31 | type zeroGradient; 32 | } 33 | 34 | fixedWalls 35 | { 36 | type fixedValue; 37 | value uniform (0 0 0); 38 | //type slip; 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_1/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | fixedWalls 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_1/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /fluidized_bed_1/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | 34 | fixedWalls 35 | { 36 | type zeroGradient; 37 | } 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /fluidized_bed_1/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_1/1.png -------------------------------------------------------------------------------- /fluidized_bed_1/cfd_fluidized_bed_1.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.rho()) 14 | pfc_link.send_data(solver.mu()) 15 | 16 | while True: 17 | deltat = pfc_link.read_data() 18 | if deltat == 0.0: 19 | print "solve finished" 20 | break 21 | solver.n(pfc_link.read_data()) 22 | solver.f(pfc_link.read_data()) 23 | 24 | solver.set_dt(deltat) 25 | solver.solve(deltat) 26 | 27 | pfc_link.send_data(solver.p()*solver.rho()) 28 | pfc_link.send_data(solver.gradp()*solver.rho()) 29 | pfc_link.send_data(solver.U()) 30 | 31 | pfc_link.close() 32 | del pfc_link -------------------------------------------------------------------------------- /fluidized_bed_1/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.8e-5; 19 | rho [1 -3 0 0 0 0 0] 1.2; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /fluidized_bed_1/fluidized_bed_1.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_1/fluidized_bed_1.p3prj -------------------------------------------------------------------------------- /fluidized_bed_1/ini.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_1/ini.sav -------------------------------------------------------------------------------- /fluidized_bed_1/pfc_fluidized_bed_1.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from itasca import cfdarray as ca 3 | from itasca.util import p2pLinkServer 4 | 5 | import numpy as np 6 | 7 | cfd_link = p2pLinkServer() 8 | cfd_link.start() 9 | 10 | nodes = cfd_link.read_data() 11 | elements = cfd_link.read_data() 12 | fluid_density = cfd_link.read_data() 13 | fluid_viscosity = cfd_link.read_data() 14 | 15 | it.command(""" 16 | restore ../fluidized_bed_1/ini.sav 17 | set timestep max 1e-4 18 | set mechanical age 0.0 19 | """) 20 | 21 | ca.create_mesh(nodes, elements) 22 | 23 | it.command(""" 24 | config cfd 25 | element cfd ini density {} 26 | element cfd ini visc {} 27 | cfd porosity poly 28 | history add id 3 fish @pressure_drop 29 | plot clear 30 | plot add ball 31 | plot add axes 32 | plot add wall transparency 70 33 | plot add hist 3 vs 1 34 | plot add cfdelement shape arrow colorby vectorattribute "velocity" 35 | """.format(fluid_density, fluid_viscosity)) 36 | 37 | element_volume = ca.volume() 38 | max_dt = 0.0001 39 | smallest_size = 0.0016 40 | time = 0.0 41 | total_time = 0.02 42 | 43 | while time < total_time: 44 | dt = 100.0 45 | if (ca.velocity().max()>1.0e-7): 46 | dt = float(0.5*smallest_size/ca.velocity().max()) 47 | if (max_dt < dt): 48 | dt = max_dt 49 | it.command("solve time {}".format(dt)) 50 | cfd_link.send_data(dt) # solve interval 51 | cfd_link.send_data(ca.porosity()) 52 | cfd_link.send_data((ca.drag().T/element_volume).T/fluid_density) 53 | ca.set_pressure(cfd_link.read_data()) 54 | ca.set_pressure_gradient(cfd_link.read_data()) 55 | ca.set_velocity(cfd_link.read_data()) 56 | it.fish.set("cfd_pressure_drop",(ca.pressure()[12] - ca.pressure()[1887])) 57 | time += dt 58 | 59 | cfd_link.send_data(0.0) # solve interval 60 | cfd_link.close() 61 | del cfd_link 62 | 63 | #it.command("history write 1,2,3 file 'fluidized_bed_1.txt' truncate") 64 | -------------------------------------------------------------------------------- /fluidized_bed_1/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 0.01; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (4 0 0) 23 | (4 20 0) 24 | (0 20 0) 25 | (0 0 0.75) 26 | (4 0 0.75) 27 | (4 20 0.75) 28 | (0 20 0.75) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (25 100 1) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (1 5 4 0) 48 | ); 49 | } 50 | outletWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (3 7 6 2) 56 | ); 57 | } 58 | fixedWalls 59 | { 60 | type wall; 61 | faces 62 | ( 63 | (0 4 7 3) 64 | (2 6 5 1) 65 | (0 3 2 1) 66 | (4 5 6 7) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /fluidized_bed_1/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.5; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /fluidized_bed_1/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /fluidized_bed_1/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /fluidized_bed_2/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type uniformFixedValue; 26 | uniformValue table ((0 (0 0 0)) (0.1 (0 1.5 0)) (0.2 (0 0 0))); 27 | } 28 | 29 | outletWalls 30 | { 31 | type zeroGradient; 32 | } 33 | 34 | fixedWalls 35 | { 36 | //type fixedValue; 37 | //value uniform (0 0 0); 38 | type slip; 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_2/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | fixedWalls 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_2/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /fluidized_bed_2/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | 34 | fixedWalls 35 | { 36 | type zeroGradient; 37 | } 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /fluidized_bed_2/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_2/1.png -------------------------------------------------------------------------------- /fluidized_bed_2/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_2/2.png -------------------------------------------------------------------------------- /fluidized_bed_2/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_2/3.png -------------------------------------------------------------------------------- /fluidized_bed_2/cfd_fluidized_bed_2.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.cell_centers()) 14 | pfc_link.send_data(solver.cell_volumes()) 15 | pfc_link.send_data(solver.rho()) 16 | pfc_link.send_data(solver.mu()) 17 | 18 | while True: 19 | deltat = pfc_link.read_data() 20 | if deltat == 0.0: 21 | print "solve finished" 22 | break 23 | solver.n(pfc_link.read_data()) 24 | solver.f(pfc_link.read_data()) 25 | 26 | solver.set_dt(deltat) 27 | solver.solve(deltat) 28 | 29 | pfc_link.send_data(solver.p()*solver.rho()) 30 | pfc_link.send_data(solver.gradp()*solver.rho()) 31 | pfc_link.send_data(solver.U()) 32 | 33 | pfc_link.close() 34 | del pfc_link -------------------------------------------------------------------------------- /fluidized_bed_2/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.8e-5; 19 | rho [1 -3 0 0 0 0 0] 1.2; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /fluidized_bed_2/fluidized_bed_2.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_2/fluidized_bed_2.p3prj -------------------------------------------------------------------------------- /fluidized_bed_2/ini.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_2/ini.sav -------------------------------------------------------------------------------- /fluidized_bed_2/make_ini.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from pfc_cfd_coupler.pfc_coupler import pfc_coupler 3 | 4 | coupler = pfc_coupler() 5 | it.command(""" 6 | set timestep max 1e-5 7 | set deterministic on 8 | set random 1 9 | ball generate rad 0.00075 number 2160 box 0 0.04 0 0.06 0 0.0075 10 | wall generate box 0 0.04 0 0.2 0 0.0075 11 | ball ini dens 2000 12 | cmat default model linear property kn 5000 ks 5000 fric 0.15 dp_nratio 0.1 13 | set gravity 0 -9.81 0 14 | def ball_height 15 | local max = 0 16 | loop foreach local b ball.list 17 | if ball.pos.y(b) > max then 18 | max = ball.pos.y(b) 19 | endif 20 | endloop 21 | ball_height = max 22 | end 23 | define pressure_drop 24 | pressure_drop = cfd_pressure_drop 25 | end 26 | def fluid_time 27 | global fluid_time = mech.age 28 | end 29 | history add id 1 fish @fluid_time 30 | history add id 2 fish @ball_height 31 | cy 20000 32 | ball ini damp 0.7 33 | cy 20000 34 | save ini.sav 35 | """) 36 | coupler.stopSolve() 37 | coupler.close() 38 | 39 | #it.command("history write 1,2,3,4 file 'droptest2.txt' truncate") -------------------------------------------------------------------------------- /fluidized_bed_2/pfc_fluidized_bed_2.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from pfc_cfd_coupler.pfc_coupler import pfc_coupler 3 | 4 | coupler = pfc_coupler() 5 | it.command(""" 6 | restore ../fluidized_bed_2/ini.sav 7 | set timestep max 1e-4 8 | set mechanical age 0.0 9 | history add id 3 fish @pressure_drop 10 | plot clear 11 | plot add ball 12 | plot add axes 13 | plot add udvector 14 | plot add wall transparency 70 15 | plot add hist 3 vs 1 16 | plot add geometry contour 17 | """) 18 | 19 | coupler.max_dt = 0.001 20 | coupler.bandwidth = 0.016 21 | coupler.pressureMeasureCell1 = 12 22 | coupler.pressureMeasureCell2 = 1887 23 | coupler.smallest_size = 0.0016 24 | coupler.solve(0.2) 25 | coupler.plotFluidVel() 26 | coupler.plotPorosity() 27 | coupler.stopSolve() 28 | coupler.close() 29 | 30 | it.command("history write 1,2,3 file 'fluidized_bed_2.txt' truncate") -------------------------------------------------------------------------------- /fluidized_bed_2/solution.p3dat: -------------------------------------------------------------------------------- 1 | new 2 | set fish autocreate off 3 | 4 | def model_solution 5 | local rhof = 1.2 6 | local rhop = 2000 7 | local mu = 1.8e-5 8 | local g = 9.81 9 | local gprime = (rhop - rhof) * g 10 | local radius = 0.00075 11 | local volume = 4 / 3 * math.pi * radius ^ 3 12 | local v = 1.5 13 | local re = 2 * rhof * radius * v / mu 14 | local oo = io.out(string.build("Particle Reynolds number %1", re)) 15 | local cd = (0.63 + 4.8/math.sqrt(re))^2 16 | local f0 = 0.5 * cd * rhof * math.pi * radius^2 * v^2 17 | local chi = 3.7 - 0.65 * math.exp(-(1.5 - math.log(re))^2 / 2.0) 18 | local epsilon = (volume * gprime / f0) ^ (-1/chi) 19 | oo = io.out(string.build("steady porosity %1", epsilon)) 20 | local np = 2160 21 | local l = 0.04 22 | local w = 0.0075 23 | local h = np * volume / (1 - epsilon) / (l*w) 24 | oo = io.out(string.build("steady height %1", h)) 25 | end 26 | @model_solution 27 | -------------------------------------------------------------------------------- /fluidized_bed_2/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 0.01; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (4 0 0) 23 | (4 20 0) 24 | (0 20 0) 25 | (0 0 0.75) 26 | (4 0 0.75) 27 | (4 20 0.75) 28 | (0 20 0.75) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (25 100 1) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (1 5 4 0) 48 | ); 49 | } 50 | outletWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (3 7 6 2) 56 | ); 57 | } 58 | fixedWalls 59 | { 60 | type wall; 61 | faces 62 | ( 63 | (0 4 7 3) 64 | (2 6 5 1) 65 | (0 3 2 1) 66 | (4 5 6 7) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /fluidized_bed_2/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.5; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /fluidized_bed_2/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /fluidized_bed_2/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /fluidized_bed_3/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | //type zeroGradient; 26 | type fixedValue; 27 | value uniform (0 0 0.04); 28 | //type uniformFixedValue; 29 | //uniformValue table ((0 (0 0 0)) (0.5 (0 0 0.04)) (1.0 (0 0 0.04))); 30 | } 31 | 32 | outletWalls 33 | { 34 | type zeroGradient; 35 | } 36 | 37 | fixedWalls 38 | { 39 | //type fixedValue; 40 | //value uniform (0 0 0); 41 | type slip; 42 | } 43 | } 44 | 45 | // ************************************************************************* // 46 | -------------------------------------------------------------------------------- /fluidized_bed_3/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | fixedWalls 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_3/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /fluidized_bed_3/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | 34 | fixedWalls 35 | { 36 | type zeroGradient; 37 | } 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /fluidized_bed_3/cfd_fluidized_bed_3.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.cell_centers()) 14 | pfc_link.send_data(solver.cell_volumes()) 15 | pfc_link.send_data(solver.rho()) 16 | pfc_link.send_data(solver.mu()) 17 | 18 | while True: 19 | deltat = pfc_link.read_data() 20 | if deltat == 0.0: 21 | print "solve finished" 22 | break 23 | solver.n(pfc_link.read_data()) 24 | solver.f(pfc_link.read_data()) 25 | 26 | solver.set_dt(deltat) 27 | solver.solve(deltat) 28 | 29 | pfc_link.send_data(solver.p()*solver.rho()) 30 | pfc_link.send_data(solver.gradp()*solver.rho()) 31 | pfc_link.send_data(solver.U()) 32 | 33 | pfc_link.close() 34 | del pfc_link -------------------------------------------------------------------------------- /fluidized_bed_3/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.0e-6; 19 | rho [1 -3 0 0 0 0 0] 998.23; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /fluidized_bed_3/fluidized_bed_3.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_3/fluidized_bed_3.p3prj -------------------------------------------------------------------------------- /fluidized_bed_3/make_ini.p3dat: -------------------------------------------------------------------------------- 1 | set deterministic on 2 | set random 1 3 | 4 | domain extent -0.01 1.1e-2 -0.01 1.1e-2 -0.01 0.06 5 | cmat default model linear property kn 1e6 dp_nratio 0.2 fric 0.1 6 | 7 | def inline 8 | global dim = 9.5174e-3 9 | global radius = dim / 3 / 5 / 2 10 | global xdim = dim - radius 11 | global ydim = 2 * dim - radius 12 | end 13 | @inline 14 | set grav 0 0 -9.81 15 | 16 | ball generate cubic box @radius @xdim @radius @xdim ... 17 | [radius + 7 * 0.05 / 26] [xdim + radius + 7 * 0.05 / 26] ... 18 | rad @radius 19 | 20 | wall generate box 0 @dim 0 @dim [7 * 0.05 / 26] 0.06 21 | 22 | ball attr density 2465 23 | 24 | ball attr radius [0.95 * radius] 25 | 26 | def ball_height 27 | local min = 7 * 0.05 / 26 28 | local max = 0 29 | loop foreach local b ball.list 30 | if ball.pos.z(b) > max then 31 | max = ball.pos.z(b) 32 | endif 33 | endloop 34 | ball_height = max - min 35 | end 36 | 37 | def fluid_time 38 | global fluid_time = mech.age 39 | end 40 | 41 | history add id 1 fish @fluid_time 42 | history add id 2 fish @ball_height 43 | 44 | plot clear 45 | plot add ball 46 | plot add axes 47 | plot add wall transparency 70 48 | plot add hist 2 vs 1 49 | plot add udvector 50 | plot add geometry contour 51 | ;cy 20000 52 | 53 | ;ball ini damp 0.7 54 | ;cy 20000 55 | ;save ini.sav -------------------------------------------------------------------------------- /fluidized_bed_3/pfc_fluidized_bed_3.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from pfc_cfd_coupler.pfc_coupler import pfc_coupler 3 | 4 | coupler = pfc_coupler() 5 | it.command("call ../fluidized_bed_3/make_ini.p3dat") 6 | 7 | coupler.max_dt = 0.001 8 | coupler.smallest_size = 0.00095 9 | coupler.bandwidth = 2*coupler.smallest_size 10 | coupler.initialize() 11 | coupler.solve(4.0) 12 | coupler.plotFluidVel() 13 | coupler.plotPorosity() 14 | coupler.stopSolve() 15 | coupler.close() 16 | 17 | it.command("history write 1,2 file 'fluidized_bed_3.txt' truncate") -------------------------------------------------------------------------------- /fluidized_bed_3/solution.p3dat: -------------------------------------------------------------------------------- 1 | new 2 | set fish autocreate off 3 | 4 | def model_solution 5 | local rhof = 998.23 6 | local rhop = 2465 7 | local mu = 1.004e-3 8 | local g = 9.81 9 | local gprime = (rhop - rhof) * g 10 | local radius = 3.013843e-4 11 | local volume = 4 / 3 * math.pi * radius ^ 3 12 | local v = 0.04 13 | local re = 2 * rhof * radius * v / mu 14 | local oo=io.out(string.build("Particle Reynolds number %1", re)) 15 | local cd = (0.63 + 4.8/math.sqrt(re))^2 16 | local f0 = 0.5 * cd * rhof * math.pi * radius^2 * v^2 17 | local chi = 3.7 - 0.65 * math.exp(-(1.5 - math.log(re))^2 / 2.0) 18 | local epsilon = (volume * gprime / f0) ^ (-1/chi) 19 | oo = io.out(string.build("steady porosity %1", epsilon)) 20 | local np = 3375 21 | local l = 9.5174e-3 22 | local h = np * volume / (1 - epsilon) / l^2 23 | oo = io.out(string.build("steady height %1", h)) 24 | end 25 | @model_solution 26 | -------------------------------------------------------------------------------- /fluidized_bed_3/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | //convertToMeters 0.01; 18 | 19 | vertices 20 | ( 21 | ( 0 0 0 ) 22 | ( 0.0095174 0 0 ) 23 | ( 0.0095174 0.0095174 0 ) 24 | ( 0 0.0095174 0 ) 25 | ( 0 0 0.1 ) 26 | ( 0.0095174 0 0.1 ) 27 | ( 0.0095174 0.0095174 0.1 ) 28 | ( 0 0.0095174 0.1 ) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (10 10 100) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (0 1 2 3) 48 | ); 49 | } 50 | outletWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (4 5 6 7) 56 | ); 57 | } 58 | fixedWalls 59 | { 60 | type wall; 61 | faces 62 | ( 63 | (0 4 7 3) 64 | (2 6 5 1) 65 | (2 6 7 3) 66 | (1 5 4 0) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /fluidized_bed_3/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.02; 27 | 28 | deltaT 0.001; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT deltaT; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /fluidized_bed_3/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /fluidized_bed_3/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /fluidized_bed_4/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | //type zeroGradient; 26 | type fixedValue; 27 | value uniform (0 0 0.04); 28 | //type uniformFixedValue; 29 | //uniformValue table ((0 (0 0 0)) (0.01 (0 1.5 0)) (0.02 (0 0 0))); 30 | } 31 | 32 | outletWalls 33 | { 34 | type zeroGradient; 35 | } 36 | 37 | fixedWalls 38 | { 39 | //type fixedValue; 40 | //value uniform (0 0 0); 41 | type slip; 42 | } 43 | } 44 | 45 | // ************************************************************************* // 46 | -------------------------------------------------------------------------------- /fluidized_bed_4/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | fixedWalls 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_4/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /fluidized_bed_4/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | //type fixedValue; 27 | //value uniform 0.1; 28 | } 29 | 30 | outletWalls 31 | { 32 | type fixedValue; 33 | value uniform 0; 34 | } 35 | 36 | fixedWalls 37 | { 38 | type zeroGradient; 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /fluidized_bed_4/cfd_fluidized_bed_4.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.rho()) 14 | pfc_link.send_data(solver.mu()) 15 | 16 | while True: 17 | deltat = pfc_link.read_data() 18 | if deltat == 0.0: 19 | print "solve finished" 20 | break 21 | solver.n(pfc_link.read_data()) 22 | solver.f(pfc_link.read_data()) 23 | 24 | solver.set_dt(deltat) 25 | solver.solve(deltat) 26 | 27 | pfc_link.send_data(solver.p()*solver.rho()) 28 | pfc_link.send_data(solver.gradp()*solver.rho()) 29 | pfc_link.send_data(solver.U()) 30 | 31 | pfc_link.close() 32 | del pfc_link -------------------------------------------------------------------------------- /fluidized_bed_4/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.0e-6; 19 | rho [1 -3 0 0 0 0 0] 1000.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /fluidized_bed_4/fluidized_bed_4.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/fluidized_bed_4/fluidized_bed_4.p3prj -------------------------------------------------------------------------------- /fluidized_bed_4/make_ini.p3dat: -------------------------------------------------------------------------------- 1 | new 2 | 3 | set deterministic off 4 | ;set random 1 5 | 6 | domain extent -0.01 1.1e-2 -0.01 1.1e-2 -0.01 0.06 7 | cmat default model linear property kn 1e6 dp_nratio 0.2 fric 0.1 8 | 9 | def inline 10 | global dim = 9.5174e-3 11 | global radius = dim / 3 / 5 / 2 12 | global xdim = dim - radius 13 | global ydim = 2 * dim - radius 14 | end 15 | @inline 16 | set grav 0 0 -9.81 17 | 18 | ball generate cubic box @radius @xdim @radius @xdim ... 19 | [radius + 7 * 0.05 / 26] [xdim + radius + 7 * 0.05 / 26] ... 20 | rad @radius 21 | ;ball create radius @radius 22 | wall generate box 0 @dim 0 @dim [7 * 0.05 / 26] 0.06 23 | 24 | ball attr density 2465 25 | 26 | ball attr radius [0.95 * radius] 27 | 28 | def ball_height 29 | local min = 7 * 0.05 / 26 30 | local max = 0 31 | loop foreach local b ball.list 32 | if ball.pos.z(b) > max then 33 | max = ball.pos.z(b) 34 | endif 35 | endloop 36 | ball_height = max - min 37 | end 38 | 39 | def fluid_time 40 | global fluid_time = mech.age 41 | end 42 | 43 | history add id 1 fish @fluid_time 44 | history add id 2 fish @ball_height 45 | 46 | ;ball fix x y z 47 | 48 | plot clear 49 | plot add ball 50 | plot add axes 51 | plot add wall transparency 70 52 | plot add cfdelement shape arrow colorby vectorattribute "velocity" 53 | ;cy 20000 54 | 55 | ;ball ini damp 0.7 56 | ;cy 20000 57 | ;save ini.sav -------------------------------------------------------------------------------- /fluidized_bed_4/pfc_fluidized_bed_4.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from itasca import cfdarray as ca 3 | from itasca.util import p2pLinkServer 4 | 5 | import numpy as np 6 | 7 | cfd_link = p2pLinkServer() 8 | cfd_link.start() 9 | 10 | nodes = cfd_link.read_data() 11 | elements = cfd_link.read_data() 12 | fluid_density = cfd_link.read_data() 13 | fluid_viscosity = cfd_link.read_data() 14 | 15 | it.command("call ../fluidized_bed_4/make_ini.p3dat") 16 | ca.create_mesh(nodes, elements) 17 | 18 | it.command(""" 19 | config cfd 20 | element cfd ini density {} 21 | element cfd ini visc {} 22 | cfd porosity poly 23 | cfd buoy on 24 | cfd interval 0 25 | element cfd history id 3 zvelocity id 1 26 | plot add hist 2 vs 1 27 | """.format(fluid_density, fluid_viscosity)) 28 | 29 | element_volume = ca.volume() 30 | oldu = ca.velocity() 31 | old_force = (ca.drag().T/element_volume).T/fluid_density 32 | old_porosity = ca.porosity() 33 | r_factor = 0.5 34 | 35 | smallest_size = 0.00095 36 | time = 0.0 37 | total_time = 4.0 38 | max_dt = 0.0001 39 | 40 | while time < total_time: 41 | dt = 100.0 42 | if (ca.velocity().max()>1.0e-7): 43 | dt = float(0.5*smallest_size/ca.velocity().max()) 44 | if (max_dt < dt): 45 | dt = max_dt 46 | it.command("solve time {}".format(dt)) 47 | it.command("cfd update") 48 | cfd_link.send_data(dt) # solve interval 49 | 50 | new_porosity = ca.porosity() 51 | cfd_link.send_data(old_porosity*(1-r_factor)+new_porosity*r_factor) 52 | old_porosity = new_porosity 53 | 54 | new_force = (ca.drag().T/element_volume).T/fluid_density 55 | cfd_link.send_data(old_force*(1-r_factor)+new_force*r_factor) 56 | old_force = new_force 57 | 58 | ca.set_pressure(cfd_link.read_data()) 59 | ca.set_pressure_gradient(cfd_link.read_data()) 60 | 61 | time += dt 62 | newu = cfd_link.read_data() 63 | ca.set_velocity(oldu*(1-r_factor)+newu*r_factor) 64 | oldu = newu 65 | 66 | cfd_link.send_data(0.0) # solve interval 67 | cfd_link.close() 68 | del cfd_link 69 | 70 | it.command("history write 1,2 file 'fluidized_bed_4.txt' truncate") 71 | -------------------------------------------------------------------------------- /fluidized_bed_4/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | //convertToMeters 0.01; 18 | 19 | vertices 20 | ( 21 | ( 0 0 0 ) 22 | ( 0.0095174 0 0 ) 23 | ( 0.0095174 0.0095174 0 ) 24 | ( 0 0.0095174 0 ) 25 | ( 0 0 0.1 ) 26 | ( 0.0095174 0 0.1 ) 27 | ( 0.0095174 0.0095174 0.1 ) 28 | ( 0 0.0095174 0.1 ) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (10 10 100) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (0 1 2 3) 48 | ); 49 | } 50 | outletWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (4 5 6 7) 56 | ); 57 | } 58 | fixedWalls 59 | { 60 | type wall; 61 | faces 62 | ( 63 | (0 4 7 3) 64 | (2 6 5 1) 65 | (2 6 7 3) 66 | (1 5 4 0) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /fluidized_bed_4/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.02; 27 | 28 | deltaT 0.001; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT deltaT; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /fluidized_bed_4/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /fluidized_bed_4/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /notes.org: -------------------------------------------------------------------------------- 1 | 2 | 3 | \( 4 | \frac{\partial}{\partial t} \left(\epsilon \right) + \nabla\cdot\left( 5 | \epsilon u_f 6 | \right) 7 | \) 8 | 9 | 10 | \( 11 | \frac{\partial}{\partial t} \left(\epsilon u_f \right) +\nabla\left( 12 | \epsilon u_f u_f \right) = -\epsilon \nabla p + \epsilon \nu\nabla^2 13 | u_f 14 | +\frac{\epsilon}{V_c\rho_f} B_i(u_{pi}-u_{fi}) 15 | \) 16 | 17 | 18 | - Put node ordering into documentation. 19 | -------------------------------------------------------------------------------- /pfc_cfd_coupler/pfc_cfd_coupler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/pfc_cfd_coupler/pfc_cfd_coupler/__init__.py -------------------------------------------------------------------------------- /pfc_cfd_coupler/pfc_cfd_coupler/cfd_coupler.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/pfc_cfd_coupler/pfc_cfd_coupler/cfd_coupler.py -------------------------------------------------------------------------------- /pfc_cfd_coupler/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup(name='pfc_cfd_coupler', 4 | version='0.1', 5 | description='PFC3D 5 - OpenFoam 3+ coupler', 6 | url='http://github.com/drozdovgrigoriy/PFC3D_OpenFOAM/pfc_cfd_coupler', 7 | author='Grisha Drozdov', 8 | author_email='drozdovgrigoriy@gmail.com', 9 | license='MIT', 10 | packages=['pfc_cfd_coupler']) -------------------------------------------------------------------------------- /porous/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type slip; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /porous/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | fixedWalls 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /porous/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outletWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /porous/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | //type zeroGradient; 26 | type fixedValue; 27 | value uniform 0.1; 28 | } 29 | 30 | outletWalls 31 | { 32 | type fixedValue; 33 | value uniform 0; 34 | } 35 | 36 | fixedWalls 37 | { 38 | type zeroGradient; 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /porous/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous/1.png -------------------------------------------------------------------------------- /porous/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous/2.png -------------------------------------------------------------------------------- /porous/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous/3.png -------------------------------------------------------------------------------- /porous/cfd_porous.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import numpy as np 3 | from pyDemFoam import pyDemIcoFoam 4 | 5 | solver = pyDemIcoFoam() 6 | 7 | pfc_link = p2pLinkClient() 8 | #pfc_link.connect("10.0.2.2") # for VirtualBox 9 | pfc_link.connect("") # for WSL 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.cell_centers()) 14 | pfc_link.send_data(solver.cell_volumes()) 15 | pfc_link.send_data(solver.rho()) 16 | pfc_link.send_data(solver.mu()) 17 | 18 | while True: 19 | deltat = pfc_link.read_data() 20 | if deltat == 0.0: 21 | print("solve finished") 22 | break 23 | solver.n(pfc_link.read_data()) 24 | solver.f(pfc_link.read_data()) 25 | 26 | solver.set_dt(deltat) 27 | solver.solve(deltat) 28 | 29 | pfc_link.send_data(solver.p()*solver.rho()) 30 | pfc_link.send_data(solver.gradp()*solver.rho()) 31 | pfc_link.send_data(solver.U()) 32 | 33 | pfc_link.close() 34 | del pfc_link -------------------------------------------------------------------------------- /porous/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1e-6; 19 | rho [1 -3 0 0 0 0 0] 1000.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /porous/particles.p3dat: -------------------------------------------------------------------------------- 1 | model deterministic on 2 | model random 1 3 | fish automatic-create off 4 | 5 | contact cmat default model linear property kn 1e1 dp_nratio 0.2 6 | 7 | fish define inline 8 | local dim = 2.5e-2 9 | local radius = dim / 5 / 4 10 | global xdim = dim - radius 11 | global ydim = 2 * dim - radius 12 | end 13 | @inline 14 | 15 | ball generate cubic box [-1*xdim] @xdim [-1*ydim] @ydim [-1*xdim] @xdim radius [5e-2/5/2/4] 16 | 17 | ball attribute density 2600 18 | ball fix spin-x spin-y spin-z 19 | 20 | [global cfd_vel = 0] 21 | fish define vel 22 | vel = cfd_vel 23 | end 24 | fish define time 25 | time = mech.time.total 26 | end 27 | fish history name '1' @time 28 | fish history name '2' @vel 29 | -------------------------------------------------------------------------------- /porous/pfc_porous.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | it.command("python-reset-state false") 3 | from pfc_cfd_coupler.pfc_coupler import pfc_coupler 4 | 5 | coupler = pfc_coupler() 6 | it.command("call particles.p3dat") 7 | 8 | coupler.max_dt = 0.005 9 | coupler.bandwidth = 0.02 10 | coupler.smallest_size = 0.01 11 | 1/0 12 | coupler.initialize() 13 | time = 0.0 14 | while time < 0.1: 15 | dt = coupler.max_dt 16 | coupler.solve(dt) 17 | it.fish.set("cfd_vel",coupler.elements_vel[0][1]) 18 | time += dt 19 | coupler.plotFluidVel() 20 | coupler.plotPorosity() 21 | coupler.stopSolve() 22 | coupler.close() -------------------------------------------------------------------------------- /porous/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 0.05; 18 | 19 | vertices 20 | ( 21 | (.5 -1 -.5) 22 | (.5 1 -.5) 23 | (-.5 1 -.5) 24 | (-.5 -1 -.5) 25 | (.5 -1 .5) 26 | (.5 1 .5) 27 | (-.5 1 .5) 28 | (-.5 -1 .5) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (10 5 5) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (0 4 7 3) 48 | 49 | ); 50 | } 51 | outletWalls 52 | { 53 | type wall; 54 | faces 55 | ( 56 | (2 6 5 1) 57 | ); 58 | } 59 | fixedWalls 60 | { 61 | type wall; 62 | faces 63 | ( 64 | (3 7 6 2) 65 | (1 5 4 0) 66 | (0 3 2 1) 67 | (4 5 6 7) 68 | ); 69 | } 70 | ); 71 | 72 | mergePatchPairs 73 | ( 74 | ); 75 | 76 | // ************************************************************************* // 77 | -------------------------------------------------------------------------------- /porous/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | //application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.01; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /porous/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /porous/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | solvers 19 | { 20 | p 21 | { 22 | solver PCG; 23 | preconditioner DIC; 24 | tolerance 1e-06; 25 | relTol 0; 26 | } 27 | 28 | U 29 | { 30 | solver smoothSolver; 31 | smoother symGaussSeidel; 32 | tolerance 1e-05; 33 | relTol 0; 34 | } 35 | } 36 | 37 | PISO 38 | { 39 | nCorrectors 2; 40 | nNonOrthogonalCorrectors 0; 41 | pRefCell 0; 42 | pRefValue 0; 43 | } 44 | 45 | SIMPLE 46 | { 47 | 48 | nNonOrthogonalCorrectors 0; 49 | pRefCell 0; 50 | pRefValue 0; 51 | 52 | residualControl 53 | { 54 | p 1e-5; 55 | U 1e-5; 56 | } 57 | } 58 | 59 | relaxationFactors 60 | { 61 | fields 62 | { 63 | p 0.3; 64 | } 65 | equations 66 | { 67 | U 0.7; 68 | } 69 | } 70 | 71 | 72 | // ************************************************************************* // 73 | -------------------------------------------------------------------------------- /porous1/.gitignore: -------------------------------------------------------------------------------- 1 | final.sav 2 | -------------------------------------------------------------------------------- /porous1/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | 27 | // type directionMixed; 28 | // refValue uniform (0 0 0); 29 | // refGradient uniform (0 0 0); 30 | // valueFraction uniform (1 0 0 0 0 1); 31 | // value uniform (0 0 0); 32 | } 33 | outletWalls 34 | { 35 | type zeroGradient; 36 | } 37 | fixedWalls 38 | { 39 | type slip; 40 | } 41 | } 42 | 43 | // ************************************************************************* // 44 | -------------------------------------------------------------------------------- /porous1/0/beta: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object beta; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 -1 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous1/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous1/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous1/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type fixedValue; 26 | value uniform 0.1; 27 | } 28 | outletWalls 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | fixedWalls 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /porous1/0/ubar: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object ubar; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous1/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous1/1.png -------------------------------------------------------------------------------- /porous1/cfd_porous1.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import subprocess 3 | import numpy as np 4 | from pyDemFoam import pyDemIcoFoam 5 | 6 | solver = pyDemIcoFoam() 7 | 8 | with p2pLinkClient() as pfc_link: 9 | pfc_link.connect("127.0.0.1") 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.rho()) 14 | pfc_link.send_data(solver.mu()) 15 | 16 | oldn = solver.n() 17 | oldf = solver.f() 18 | r_factor = 1.0 19 | 20 | while True: 21 | print("waiting for run time") 22 | deltat = pfc_link.read_data() 23 | if deltat == 0.0: 24 | print ("solve finished") 25 | break 26 | print("got run time", deltat) 27 | newn = pfc_link.read_data() 28 | solver.n(oldn*(1-r_factor) + newn*r_factor) 29 | oldn = newn 30 | newf = pfc_link.read_data() 31 | solver.f(oldf*(1-r_factor) + newf*r_factor) 32 | oldf = newf 33 | print("got runtime and data") 34 | 35 | solver.set_dt(deltat) 36 | solver.solve(deltat) 37 | 38 | print("sending data to pfc") 39 | pfc_link.send_data(solver.p()*solver.rho()) 40 | pfc_link.send_data(solver.gradp()*solver.rho()) 41 | pfc_link.send_data(solver.U()) 42 | print("send finished") 43 | -------------------------------------------------------------------------------- /porous1/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1e-6; 19 | rho [1 -3 0 0 0 0 0] 1000.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /porous1/particles.p3dat: -------------------------------------------------------------------------------- 1 | fish automatic-create off 2 | contact cmat default model linear property kn 1e1 dp_nratio 0.2 3 | 4 | fish define inline 5 | local dim = 2.5e-2 6 | local radius = dim / 5 / 4 7 | global xdim = dim - radius 8 | global ydim = 2 * dim - radius 9 | end 10 | @inline 11 | 12 | ball generate cubic box [-1*xdim] @xdim [-1*ydim] @ydim [-1*xdim] @xdim radius [5e-2/5/2/4] 13 | 14 | ball attribute density 2600 15 | ball fix spin 16 | ball fix velocity 17 | [global cfd_vel = 0] 18 | fish define vel 19 | vel = cfd_vel 20 | end 21 | fish define time 22 | time = mech.time.total 23 | end 24 | fish history name '1' @time 25 | fish history name '2' @vel 26 | -------------------------------------------------------------------------------- /porous1/pfc_porous1.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | it.command("python-reset-state false") 3 | from itasca import cfdarray as ca 4 | from itasca.util import p2pLinkServer 5 | 6 | import numpy as np 7 | 8 | with p2pLinkServer() as cfd_link: 9 | cfd_link.start() 10 | 11 | nodes = cfd_link.read_data() 12 | elements = cfd_link.read_data() 13 | fluid_density = cfd_link.read_data() 14 | fluid_viscosity = cfd_link.read_data() 15 | print (fluid_density, fluid_viscosity) 16 | nmin, nmax = np.amin(nodes,axis=0), np.amax(nodes,axis=0) 17 | diag = np.linalg.norm(nmin-nmax) 18 | dmin, dmax = nmin -0.1*diag, nmax+0.1*diag 19 | print (dmin, dmax) 20 | it.command(""" 21 | model new 22 | MODEL LARGE-STRAIN on 23 | domain extent {} {} {} {} {} {} 24 | """.format(dmin[0], dmax[0], 25 | dmin[1], dmax[1], 26 | dmin[2], dmax[2])) 27 | elements = elements.astype(np.longlong) # need to fix the c++ side, this is a work around for a platform type size issue. 28 | ca.create_mesh(nodes, elements) 29 | it.command(f""" 30 | model config cfd 31 | element cfd ini density {fluid_density} 32 | element cfd ini visc {fluid_viscosity} 33 | call "particles.p3dat" 34 | cfd porosity poly 35 | cfd buoy on 36 | cfd relax 1 37 | cfd update 38 | """) 39 | 40 | 41 | element_volume = ca.volume() 42 | dt = 0.005 43 | oldu = ca.velocity() 44 | r_factor = 1.0 45 | vel_his = [] 46 | for i in range(20): 47 | it.command("solve age {}".format(it.mech_age()+dt)) 48 | print("sending solve time") 49 | cfd_link.send_data(dt) # solve interval 50 | cfd_link.send_data(ca.porosity()) 51 | new_force = (ca.drag().T/element_volume).T/fluid_density 52 | cfd_link.send_data(new_force) 53 | print(" cfd solve started") 54 | ca.set_pressure(cfd_link.read_data()) 55 | ca.set_pressure_gradient(cfd_link.read_data()) 56 | newu = cfd_link.read_data() 57 | print("current velocity", newu[0][1]) 58 | vel_his.append(newu[0][1]) 59 | ca.set_velocity(oldu*(1-r_factor)+newu*r_factor) 60 | oldu = newu 61 | print(" cfd solve ended") 62 | 63 | cfd_link.send_data(0.0) 64 | 65 | it.command("model save 'final.sav'") 66 | 67 | #it.command('plot bitmap filename "porous1.png"') 68 | -------------------------------------------------------------------------------- /porous1/porous1.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous1/porous1.p3prj -------------------------------------------------------------------------------- /porous1/porous1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous1/porous1.png -------------------------------------------------------------------------------- /porous1/scfd_porous1.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import subprocess 3 | import numpy as np 4 | from pyDemFoam import pyDemIcoFoamSemiImplicitDrag 5 | 6 | solver = pyDemIcoFoamSemiImplicitDrag() 7 | 8 | with p2pLinkClient() as pfc_link: 9 | pfc_link.connect("127.0.0.1") 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.rho()) 14 | pfc_link.send_data(solver.mu()) 15 | 16 | oldn = solver.n() 17 | r_factor = 1.0 18 | 19 | while True: 20 | print ("waiting for run time") 21 | deltat = pfc_link.read_data() 22 | if deltat == 0.0: 23 | print ("solve finished") 24 | break 25 | print ("got run time"), deltat 26 | newn = pfc_link.read_data() 27 | solver.n(oldn*(1-r_factor) + newn*r_factor) 28 | oldn=newn 29 | beta = pfc_link.read_data() 30 | #print "beta", beta 31 | ubar = pfc_link.read_data() 32 | #print "ubar", ubar 33 | 34 | solver.beta(beta) 35 | solver.ubar(ubar) 36 | print ("got runtime and data") 37 | 38 | solver.solve(deltat) 39 | 40 | print ("sending data to pfc") 41 | pfc_link.send_data(solver.p()*solver.rho()) 42 | pfc_link.send_data(solver.gradp()*solver.rho()) 43 | pfc_link.send_data(solver.U()) 44 | print ("send finished") 45 | -------------------------------------------------------------------------------- /porous1/spfc_porous1.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | it.command("python-reset-state false") 3 | from itasca import cfdarray as ca 4 | from itasca.util import p2pLinkServer 5 | 6 | import numpy as np 7 | 8 | with p2pLinkServer() as cfd_link: 9 | cfd_link.start() 10 | 11 | nodes = cfd_link.read_data() 12 | elements = cfd_link.read_data() 13 | fluid_density = cfd_link.read_data() 14 | fluid_viscosity = cfd_link.read_data() 15 | print (fluid_density, fluid_viscosity) 16 | nmin, nmax = np.amin(nodes,axis=0), np.amax(nodes,axis=0) 17 | diag = np.linalg.norm(nmin-nmax) 18 | dmin, dmax = nmin -0.1*diag, nmax+0.1*diag 19 | print (dmin, dmax) 20 | it.command(""" 21 | model new 22 | MODEL LARGE-STRAIN on 23 | domain extent {} {} {} {} {} {} 24 | """.format(dmin[0], dmax[0], 25 | dmin[1], dmax[1], 26 | dmin[2], dmax[2])) 27 | elements = elements.astype(np.longlong) # need to fix the c++ side, this is a work around for a platform type size issue. 28 | ca.create_mesh(nodes, elements) 29 | it.command(f""" 30 | model config cfd 31 | element cfd ini density {fluid_density} 32 | element cfd ini visc {fluid_viscosity} 33 | call "particles.p3dat" 34 | cfd porosity poly 35 | cfd buoy on 36 | cfd relax 1 37 | cfd update 38 | """) 39 | 40 | 41 | 42 | element_volume = ca.volume() 43 | dt = 0.005 44 | oldu = ca.velocity() 45 | r_factor = 1.0 46 | for i in range(20): 47 | print(i) 48 | it.command("solve age {}".format(it.mech_age()+dt)) 49 | print ("sending solve time") 50 | cfd_link.send_data(dt) # solve interval 51 | n = ca.porosity() 52 | cfd_link.send_data(n) 53 | ca.set_extra(1, np.zeros(it.element.cfd.count())) 54 | ca.set_extra(2, np.zeros(it.element.cfd.count())) 55 | ca.set_extra(3, np.zeros((it.element.cfd.count(),3))) 56 | for b in it.ball.cfd.list(): 57 | for e,v in zip(b.elements(), b.overlaps()): 58 | e.set_extra(1, e.extra(1)+v*b.ball().radius()) 59 | e.set_extra(2, e.extra(2)+v) 60 | e.set_extra(3, e.extra(3)+v*b.ball().vel()) 61 | dbar = 2*ca.extra(1)/ca.extra(2) 62 | ubar = (ca.extra(3).T/ca.extra(2)).T 63 | du = np.linalg.norm(ubar.T - ca.velocity().T,axis=0) 64 | re = (du*fluid_density*dbar/fluid_viscosity).T 65 | beta = fluid_viscosity*(1-n)/dbar**2/n*(150*(1-n)+1.75*re)/fluid_density 66 | print (beta[0], ubar[0], ca.velocity()[0][1]) 67 | new_force = (ca.drag().T/element_volume).T/fluid_density 68 | cfd_link.send_data(beta) 69 | cfd_link.send_data(ubar) 70 | print (" cfd solve started") 71 | ca.set_pressure(cfd_link.read_data()) 72 | ca.set_pressure_gradient(cfd_link.read_data()) 73 | newu = cfd_link.read_data() 74 | ca.set_velocity(oldu*(1-r_factor)+newu*r_factor) 75 | oldu = newu 76 | print (" cfd solve ended") 77 | 78 | cfd_link.send_data(0.0) 79 | it.command("model save 'sfinal.sav'") 80 | -------------------------------------------------------------------------------- /porous1/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 0.05; 18 | 19 | vertices 20 | ( 21 | (.5 -1 -.5) 22 | (.5 1 -.5) 23 | (-.5 1 -.5) 24 | (-.5 -1 -.5) 25 | (.5 -1 .5) 26 | (.5 1 .5) 27 | (-.5 1 .5) 28 | (-.5 -1 .5) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (10 5 5) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (0 4 7 3) 48 | 49 | ); 50 | } 51 | outletWalls 52 | { 53 | type wall; 54 | faces 55 | ( 56 | (2 6 5 1) 57 | ); 58 | } 59 | fixedWalls 60 | { 61 | type wall; 62 | faces 63 | ( 64 | (3 7 6 2) 65 | (1 5 4 0) 66 | (0 3 2 1) 67 | (4 5 6 7) 68 | ); 69 | } 70 | ); 71 | 72 | mergePatchPairs 73 | ( 74 | ); 75 | 76 | // ************************************************************************* // 77 | -------------------------------------------------------------------------------- /porous1/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | //application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.01; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 1; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /porous1/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /porous1/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | solvers 19 | { 20 | p 21 | { 22 | solver PCG; 23 | preconditioner DIC; 24 | tolerance 1e-06; 25 | relTol 0; 26 | } 27 | pFinal 28 | { 29 | $p; 30 | relTol 0; 31 | } 32 | U 33 | { 34 | solver smoothSolver; 35 | smoother symGaussSeidel; 36 | tolerance 1e-05; 37 | relTol 0; 38 | } 39 | } 40 | 41 | PISO 42 | { 43 | nCorrectors 2; 44 | nNonOrthogonalCorrectors 0; 45 | pRefCell 0; 46 | pRefValue 0; 47 | } 48 | 49 | SIMPLE 50 | { 51 | 52 | nNonOrthogonalCorrectors 0; 53 | pRefCell 0; 54 | pRefValue 0; 55 | 56 | residualControl 57 | { 58 | p 1e-5; 59 | U 1e-5; 60 | } 61 | } 62 | 63 | relaxationFactors 64 | { 65 | fields 66 | { 67 | p 0.3; 68 | } 69 | equations 70 | { 71 | U 0.7; 72 | } 73 | } 74 | 75 | 76 | // ************************************************************************* // 77 | -------------------------------------------------------------------------------- /porous2/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | // type zeroGradient; 26 | type fixedValue; 27 | value uniform (0 1e-2 0); 28 | 29 | // type directionMixed; 30 | // refValue uniform (0 0 0); 31 | // refGradient uniform (0 0 0); 32 | // valueFraction uniform (1 0 0 0 0 1); 33 | // value uniform (0 0 0); 34 | } 35 | outletWalls 36 | { 37 | type zeroGradient; 38 | } 39 | fixedWalls 40 | { 41 | type slip; 42 | } 43 | } 44 | 45 | // ************************************************************************* // 46 | -------------------------------------------------------------------------------- /porous2/0/beta: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object beta; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 -1 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous2/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous2/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous2/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | //type fixedValue; 27 | //value uniform 0.1; 28 | } 29 | outletWalls 30 | { 31 | type fixedValue; 32 | value uniform 0; 33 | } 34 | fixedWalls 35 | { 36 | type zeroGradient; 37 | } 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /porous2/0/ubar: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object ubar; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | inletWalls 24 | { 25 | type zeroGradient; 26 | } 27 | outletWalls 28 | { 29 | type zeroGradient; 30 | } 31 | fixedWalls 32 | { 33 | type zeroGradient; 34 | } 35 | } 36 | 37 | // ************************************************************************* // 38 | -------------------------------------------------------------------------------- /porous2/cfd_porous2.py: -------------------------------------------------------------------------------- 1 | from itasca import p2pLinkClient 2 | import subprocess 3 | import numpy as np 4 | from pyDemFoam import pyDemIcoFoam 5 | 6 | solver = pyDemIcoFoam() 7 | 8 | with p2pLinkClient() as pfc_link: 9 | pfc_link.connect("10.0.2.2") 10 | 11 | pfc_link.send_data(solver.nodes()) 12 | pfc_link.send_data(solver.elements()) 13 | pfc_link.send_data(solver.rho()) 14 | pfc_link.send_data(solver.mu()) 15 | 16 | oldn = solver.n() 17 | oldf = solver.f() 18 | r_factor = 1.0 19 | 20 | i = 0 21 | while True: 22 | print "waiting for run time" 23 | deltat = pfc_link.read_data() 24 | if deltat == 0.0: 25 | print "solve finished" 26 | break 27 | print "got run time", deltat 28 | newn = pfc_link.read_data() 29 | solver.n(oldn*(1-r_factor) + newn*r_factor) 30 | oldn=newn 31 | newf = pfc_link.read_data() 32 | solver.f(oldf*(1-r_factor) + newf*r_factor) 33 | oldf=newf 34 | print "got runtime and data" 35 | 36 | if i<3: 37 | solver.set_dt(deltat/1000.0) 38 | solver.solve(deltat/1000.0) 39 | 40 | elif i==3: 41 | solver.set_dt(deltat/100.0) 42 | solver.solve(deltat/100.0) 43 | else: 44 | solver.set_dt(deltat/100.0) 45 | solver.solve(deltat) 46 | 47 | print "sending data to pfc" 48 | pfc_link.send_data(solver.p()*solver.rho()) 49 | pfc_link.send_data(solver.gradp()*solver.rho()) 50 | pfc_link.send_data(solver.U()) 51 | print "send finished" 52 | i+=1 53 | -------------------------------------------------------------------------------- /porous2/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1e-6; 19 | rho [1 -3 0 0 0 0 0] 1000.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /porous2/particles.p3dat: -------------------------------------------------------------------------------- 1 | set fish autocreate off 2 | cmat default model linear property kn 1e1 dp_nratio 0.2 3 | 4 | def inline 5 | local dim = 2.5e-2 6 | local radius = dim / 5 / 4 7 | global xdim = dim - radius 8 | global ydim = 2 * dim - radius 9 | end 10 | @inline 11 | 12 | ball generate cubic box [-1*xdim] @xdim [-1*ydim] @ydim [-1*xdim] @xdim rad [5e-2/5/2/4] 13 | 14 | ball attr dens 2600 15 | ball fix x 16 | ball fix y 17 | ball fix z 18 | def ftime 19 | global ftime = mech.age 20 | end 21 | 22 | def fhist 23 | global fhist = element.cfd.vel.y(element.cfd.find(225)) 24 | end 25 | 26 | history id 1 fish @fhist 27 | history id 2 fish @ftime 28 | 29 | plot clear 30 | plot add hist 1 vs 2 31 | plot add cfdelement shape arrow colorby vectorattribute "velocity" coloropt scaled ramp minimum 0.011 maximum 0.015 interval 0.0005 32 | -------------------------------------------------------------------------------- /porous2/pfc_porous2.py: -------------------------------------------------------------------------------- 1 | import itasca as it 2 | from itasca import cfdarray as ca 3 | from itasca.util import p2pLinkServer 4 | 5 | import numpy as np 6 | 7 | with p2pLinkServer() as cfd_link: 8 | cfd_link.start() 9 | 10 | nodes = cfd_link.read_data() 11 | elements = cfd_link.read_data() 12 | fluid_density = cfd_link.read_data() 13 | fluid_viscosity = cfd_link.read_data() 14 | print fluid_density, fluid_viscosity 15 | nmin, nmax = np.amin(nodes,axis=0), np.amax(nodes,axis=0) 16 | diag = np.linalg.norm(nmin-nmax) 17 | dmin, dmax = nmin -0.1*diag, nmax+0.1*diag 18 | print dmin, dmax 19 | it.command(""" 20 | new 21 | domain extent {} {} {} {} {} {} 22 | """.format(dmin[0], dmax[0], 23 | dmin[1], dmax[1], 24 | dmin[2], dmax[2])) 25 | ca.create_mesh(nodes, elements) 26 | it.command(""" 27 | config cfd 28 | element cfd ini density {} 29 | element cfd ini visc {} 30 | cfd porosity poly 31 | cfd buoy on 32 | cfd relax 1 33 | cfd update 34 | call particles.p3dat 35 | """.format(fluid_density, fluid_viscosity)) 36 | 37 | 38 | element_volume = ca.volume() 39 | dt = 0.005 40 | oldu = ca.velocity() 41 | r_factor = 1.0 42 | for i in range(20): 43 | it.command("solve age {}".format(it.mech_age()+dt)) 44 | print "sending solve time" 45 | cfd_link.send_data(dt) # solve interval 46 | cfd_link.send_data(ca.porosity()) 47 | new_force = (ca.drag().T/element_volume).T/fluid_density 48 | cfd_link.send_data(new_force) 49 | print " cfd solve started" 50 | ca.set_pressure(cfd_link.read_data()) 51 | ca.set_pressure_gradient(cfd_link.read_data()) 52 | newu = cfd_link.read_data() 53 | ca.set_velocity(oldu*(1-r_factor)+newu*r_factor) 54 | oldu = newu 55 | print " cfd solve ended" 56 | 57 | cfd_link.send_data(0.0) 58 | 59 | it.command('plot bitmap filename "porous2.png"') 60 | -------------------------------------------------------------------------------- /porous2/porous2.p3prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itascaconsulting/PFC3D_OpenFOAM/39e6330a8c7efd383d99af9750ce7cc810ff7b0c/porous2/porous2.p3prj -------------------------------------------------------------------------------- /porous2/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 0.05; 18 | 19 | vertices 20 | ( 21 | (.5 -1 -.5) 22 | (.5 1 -.5) 23 | (-.5 1 -.5) 24 | (-.5 -1 -.5) 25 | (.5 -1 .5) 26 | (.5 1 .5) 27 | (-.5 1 .5) 28 | (-.5 -1 .5) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (10 5 5) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | inletWalls 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (0 4 7 3) 48 | 49 | ); 50 | } 51 | outletWalls 52 | { 53 | type wall; 54 | faces 55 | ( 56 | (2 6 5 1) 57 | ); 58 | } 59 | fixedWalls 60 | { 61 | type wall; 62 | faces 63 | ( 64 | (3 7 6 2) 65 | (1 5 4 0) 66 | (0 3 2 1) 67 | (4 5 6 7) 68 | ); 69 | } 70 | ); 71 | 72 | mergePatchPairs 73 | ( 74 | ); 75 | 76 | // ************************************************************************* // 77 | -------------------------------------------------------------------------------- /porous2/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | //application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.005; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl timeStep; 31 | 32 | writeInterval 10000000; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /porous2/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /porous2/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | -------------------------------------------------------------------------------- /pyDemFoam/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.so 3 | _pyDemIcoFoam.cpp 4 | _pyDemSimpleFoam.cpp 5 | log.txt -------------------------------------------------------------------------------- /pyDemFoam/demBaseFoam.C: -------------------------------------------------------------------------------- 1 | #include "demBaseFoam.H" 2 | 3 | demBaseFoam::demBaseFoam() { 4 | int argc=1; 5 | const char *argv[]={"demIcoFoam", NULL}; 6 | char ** argv2 = const_cast(argv); 7 | args_ = new Foam::argList(argc, argv2); 8 | if (!args_->checkRootCase()) Foam::FatalError.exit(); 9 | runTime_ = new Foam::Time(Foam::Time::controlDictName, *args_); 10 | mesh_ = new Foam::fvMesh(Foam::IOobject (Foam::fvMesh::defaultRegion, 11 | runTime_->timeName(), 12 | *runTime_, 13 | Foam::IOobject::MUST_READ)); 14 | 15 | 16 | IOdictionary transportProperties(IOobject("transportProperties", 17 | runTime_->constant(), 18 | *mesh_, 19 | IOobject::MUST_READ_IF_MODIFIED, 20 | IOobject::NO_WRITE)); 21 | 22 | nu_ = new dimensionedScalar("nu", dimViscosity, 23 | transportProperties.lookup("nu")); 24 | rho_ = new dimensionedScalar("rho", dimDensity, 25 | transportProperties.lookup("rho")); 26 | 27 | p_ = new volScalarField (IOobject ("p", runTime_->timeName(), *mesh_, 28 | IOobject::MUST_READ, 29 | IOobject::AUTO_WRITE), *mesh_); 30 | U_ = new volVectorField (IOobject ("U", runTime_->timeName(), *mesh_, 31 | IOobject::MUST_READ, 32 | IOobject::AUTO_WRITE), *mesh_); 33 | n_ = new volScalarField(IOobject ("n", runTime_->timeName(), *mesh_, 34 | IOobject::MUST_READ, 35 | IOobject::AUTO_WRITE), *mesh_); 36 | phi_ = new surfaceScalarField (IOobject ("phi", runTime_->timeName(), *mesh_, 37 | IOobject::READ_IF_PRESENT, 38 | IOobject::AUTO_WRITE), 39 | linearInterpolate(*U_) & mesh_->Sf()); 40 | 41 | pRefCell_ = 0; 42 | pRefValue_ = 0.0; 43 | setRefCell(*p_, mesh_->solutionDict().subDict("PISO"), pRefCell_, pRefValue_); 44 | mesh_->setFluxRequired(p_->name()); 45 | gradp_ = new volVectorField(fvc::grad(*p_)); 46 | cumulativeContErr_ = 0.0; 47 | } 48 | 49 | demBaseFoam::~demBaseFoam() { 50 | Info << "cleaning up demBaseFoam" << endl; 51 | if (gradp_) delete gradp_; 52 | if (phi_) delete phi_; 53 | if (n_) delete n_; 54 | if (U_) delete U_; 55 | if (p_) delete p_; 56 | if (rho_) delete rho_; 57 | if (nu_) delete nu_; 58 | if (mesh_) delete mesh_; 59 | if (runTime_) delete runTime_; 60 | if (args_) delete args_; 61 | } 62 | 63 | double demBaseFoam::flux_on_patch(char *patch_name) 64 | { 65 | label inletPatchi = (*mesh_).boundaryMesh().findPatchID(patch_name); 66 | if (inletPatchi == -1) 67 | throw std::runtime_error("Cannot find boundary patch"); 68 | scalar massFlux = sum((*phi_).boundaryField()[inletPatchi]); 69 | return massFlux; 70 | } 71 | 72 | double demBaseFoam::cell_flux(int cell, int face) { 73 | label gface = mesh_->cells()[cell][face]; 74 | if (mesh_->faceOwner()[gface]==cell) return (*phi_)[gface]; 75 | else return -(*phi_)[gface]; 76 | } 77 | 78 | int demBaseFoam::cell_near(double x, double y, double z) { 79 | meshSearch search(*mesh_); 80 | return search.findNearestCell(point(x,y,z)); 81 | } 82 | -------------------------------------------------------------------------------- /pyDemFoam/demBaseFoam.H: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "fvCFD.H" 3 | #include "pisoControl.H" 4 | #include "meshSearch.H" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define VEC_GET(T) double T(int i, int j) { return (*T##_)[i][j]; } 11 | #define VEC_SET(T) void set_##T(int i, int j, double v) { (*T##_)[i][j]=v; } 12 | #define VEC_SETGET(T) VEC_SET(T) VEC_GET(T) 13 | 14 | #define GET(T) double T(int i) { return (*T##_)[i]; } 15 | #define SET(T) void set_##T(int i, double v) { (*T##_)[i]=v; } 16 | #define SETGET(T) SET(T) GET(T) 17 | 18 | class demBaseFoam { 19 | public: 20 | demBaseFoam(); 21 | virtual ~demBaseFoam(); 22 | int nCells() { return mesh_->nCells(); } 23 | double rho() { return rho_->value(); } 24 | double nu() { return nu_->value(); } 25 | int nNodes() { return mesh_->nPoints(); } 26 | int nFaces() { return mesh_->nFaces(); } 27 | int face_node(int face, int node) { return mesh_->faces()[face][node]; } 28 | int cell_face(int cell, int face) { return mesh_->cells()[cell][face]; } 29 | double cell_flux(int cell, int face); 30 | int cell_near(double x, double y, double z); 31 | double flux_on_patch(char *patch_name); 32 | double cell_center(int cell, int j) { return mesh_->cellCentres()[cell][j]; } 33 | double cell_volume(int cell) { return mesh_->cellVolumes()[cell]; } 34 | double face_center(int face, int j) { return mesh_->faceCentres()[face][j]; } 35 | double node_pos(int i, int j) { return mesh_->points()[i][j]; } 36 | int element(int i, int j) { return mesh_->cellShapes()[i][j]; } 37 | void set_dt(double t) { runTime_->setDeltaT(t); } 38 | double dt() { return runTime_->deltaT().value(); } 39 | void set_endtime(double t) { runTime_->setEndTime(t); } 40 | virtual void run(double v)=0; 41 | 42 | SETGET(n) 43 | VEC_SETGET(U) 44 | SETGET(p) 45 | VEC_GET(gradp) 46 | GET(phi) 47 | 48 | Foam::argList *args_; 49 | Foam::Time *runTime_; 50 | Foam::fvMesh *mesh_; 51 | 52 | dimensionedScalar *nu_; 53 | dimensionedScalar *rho_; 54 | volScalarField *p_; 55 | volVectorField *U_; 56 | volScalarField *n_; 57 | surfaceScalarField *phi_; 58 | label pRefCell_; 59 | scalar pRefValue_; 60 | 61 | volVectorField *gradp_; 62 | scalar cumulativeContErr_; 63 | }; 64 | -------------------------------------------------------------------------------- /pyDemFoam/demIcoFoam.C: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | 5 | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation 6 | \\/ M anipulation | 7 | ---------------------------------------------------------------------------- 8 | License 9 | This file is not part of OpenFOAM. 10 | 11 | OpenFOAM is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with OpenFOAM. If not, see . 23 | no 24 | Application 25 | demIcoFoam 26 | \*------------------------------------------------------------------------*/ 27 | 28 | #include "demIcoFoam.H" 29 | 30 | demIcoFoam::demIcoFoam() { 31 | Info << "creating demIcoFoam object" << nl << endl; 32 | f_ = new volVectorField(IOobject ("f", runTime_->timeName(), *mesh_, 33 | IOobject::MUST_READ, 34 | IOobject::AUTO_WRITE), *mesh_); 35 | piso_ = new pisoControl(*mesh_); 36 | } 37 | 38 | demIcoFoam::~demIcoFoam() { 39 | Info << "cleaning up demIcoFoam" << nl << endl; 40 | if (piso_) delete piso_; 41 | if (f_) delete f_; 42 | } 43 | 44 | void demIcoFoam::run(double time_increment) { 45 | volVectorField &U = *U_; // aliases for convenience 46 | volVectorField &f = *f_; 47 | volScalarField &n = *n_; 48 | volScalarField &p = *p_; 49 | dimensionedScalar &nu = *nu_; 50 | surfaceScalarField &phi = *phi_; 51 | Foam::Time &runTime = *runTime_; 52 | Foam::fvMesh &mesh = *mesh_; 53 | scalar &cumulativeContErr = cumulativeContErr_; 54 | 55 | runTime.setEndTime(runTime.value() + time_increment); 56 | while (runTime.loop()) 57 | { 58 | Info<< "Time = " << runTime.timeName() << nl << endl; 59 | #include "CourantNo.H" 60 | 61 | fvVectorMatrix UEqn 62 | (fvm::ddt(U) + fvm::div(phi, U) - 63 | fvm::laplacian(nu, U) - f/n); 64 | 65 | if (piso_->momentumPredictor()) 66 | solve(UEqn == -fvc::grad(p)); 67 | 68 | while (piso_->correct()) 69 | { 70 | volScalarField rAU(1.0/UEqn.A()); 71 | // volVectorField HbyA("HbyA", U); 72 | // HbyA = rAU*UEqn.H(); 73 | // surfaceScalarField phiHbyA 74 | // ("phiHbyA", (fvc::interpolate(HbyA) & mesh_->Sf())); 75 | 76 | volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); 77 | surfaceScalarField phiHbyA ("phiHbyA", fvc::flux(HbyA) + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)); 78 | 79 | adjustPhi(phiHbyA, U, p); 80 | 81 | // Update the pressure BCs to ensure flux consistency 82 | constrainPressure(p, U, phiHbyA, rAU); 83 | 84 | 85 | adjustPhi(phiHbyA, U, p); 86 | 87 | while (piso_->correctNonOrthogonal()) 88 | { 89 | fvScalarMatrix pEqn 90 | (fvm::laplacian(rAU, p) == 91 | fvc::div(phiHbyA) //+ dndt 92 | ); 93 | pEqn.setReference(pRefCell_, pRefValue_); 94 | pEqn.solve(mesh.solver(p.select(piso_->finalInnerIter()))); 95 | if (piso_->finalNonOrthogonalIter()) phi = phiHbyA - pEqn.flux(); 96 | } 97 | 98 | 99 | #include "continuityErrs.H" 100 | 101 | U = HbyA - rAU*fvc::grad(p); 102 | U.correctBoundaryConditions(); 103 | } 104 | runTime.write(); 105 | Info<< "ExecutionTime = " << runTime_->elapsedCpuTime() << " s" 106 | << " ClockTime = " << runTime_->elapsedClockTime() << " s" 107 | << nl << endl; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /pyDemFoam/demIcoFoam.H: -------------------------------------------------------------------------------- 1 | #include "demBaseFoam.H" 2 | #include "pisoControl.H" 3 | 4 | class demIcoFoam : public demBaseFoam { 5 | public: 6 | demIcoFoam(); 7 | virtual ~demIcoFoam(); 8 | virtual void run(double t); 9 | 10 | volVectorField *f_; 11 | VEC_SETGET(f) 12 | 13 | pisoControl *piso_; 14 | }; 15 | -------------------------------------------------------------------------------- /pyDemFoam/demIcoFoamSemiImplicitDrag.C: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | 5 | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation 6 | \\/ M anipulation | 7 | ---------------------------------------------------------------------------- 8 | License 9 | This file is not part of OpenFOAM. 10 | 11 | OpenFOAM is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with OpenFOAM. If not, see . 23 | no 24 | Application 25 | demIcoFoam 26 | \*------------------------------------------------------------------------*/ 27 | 28 | #include "demIcoFoamSemiImplicitDrag.H" 29 | 30 | demIcoFoamSemiImplicitDrag::demIcoFoamSemiImplicitDrag() { 31 | Info << "creating demIcoFoamSemiImplicitDrag object" << nl << endl; 32 | ubar_ = new volVectorField(IOobject ("ubar", runTime_->timeName(), *mesh_, 33 | IOobject::MUST_READ, 34 | IOobject::AUTO_WRITE), *mesh_); 35 | beta_ = new volScalarField (IOobject ("beta", runTime_->timeName(), *mesh_, 36 | IOobject::MUST_READ, 37 | IOobject::AUTO_WRITE), *mesh_); 38 | piso_ = new pisoControl(*mesh_); 39 | } 40 | 41 | demIcoFoamSemiImplicitDrag::~demIcoFoamSemiImplicitDrag() { 42 | Info << "cleaning up demIcoFoamSemiImplicitDrag" << nl << endl; 43 | if (piso_) delete piso_; 44 | if (ubar_) delete ubar_; 45 | if (beta_) delete beta_; 46 | } 47 | 48 | void demIcoFoamSemiImplicitDrag::run(double time_increment) { 49 | volScalarField &beta = *beta_; // aliases for convenience 50 | volVectorField &ubar = *ubar_; 51 | volVectorField &U = *U_; 52 | volScalarField &n = *n_; 53 | volScalarField &p = *p_; 54 | dimensionedScalar &nu = *nu_; 55 | surfaceScalarField &phi = *phi_; 56 | Foam::Time &runTime = *runTime_; 57 | Foam::fvMesh &mesh = *mesh_; 58 | scalar &cumulativeContErr = cumulativeContErr_; 59 | 60 | runTime.setEndTime(runTime.value() + time_increment); 61 | while (runTime.loop()) 62 | { 63 | Info<< "Time = " << runTime.timeName() << nl << endl; 64 | #include "CourantNo.H" 65 | fvVectorMatrix UEqn 66 | (fvm::ddt(U) 67 | + fvm::div(phi, U) 68 | - fvm::laplacian(nu, U) 69 | - beta*ubar/n 70 | + fvm::Sp(beta/n, U)); 71 | 72 | if (piso_->momentumPredictor()) 73 | solve(UEqn == -fvc::grad(p)); 74 | 75 | while (piso_->correct()) 76 | { 77 | volScalarField rAU(1.0/UEqn.A()); 78 | 79 | volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); 80 | surfaceScalarField phiHbyA ("phiHbyA", fvc::flux(HbyA) + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)); 81 | 82 | adjustPhi(phiHbyA, U, p); 83 | 84 | // Update the pressure BCs to ensure flux consistency 85 | constrainPressure(p, U, phiHbyA, rAU); 86 | 87 | 88 | adjustPhi(phiHbyA, U, p); 89 | 90 | while (piso_->correctNonOrthogonal()) 91 | { 92 | fvScalarMatrix pEqn 93 | (fvm::laplacian(rAU, p) == 94 | fvc::div(phiHbyA) //+ dndt 95 | ); 96 | pEqn.setReference(pRefCell_, pRefValue_); 97 | pEqn.solve(mesh.solver(p.select(piso_->finalInnerIter()))); 98 | if (piso_->finalNonOrthogonalIter()) phi = phiHbyA - pEqn.flux(); 99 | } 100 | 101 | 102 | #include "continuityErrs.H" 103 | 104 | U = HbyA - rAU*fvc::grad(p); 105 | U.correctBoundaryConditions(); 106 | } 107 | runTime.write(); 108 | Info<< "ExecutionTime = " << runTime_->elapsedCpuTime() << " s" 109 | << " ClockTime = " << runTime_->elapsedClockTime() << " s" 110 | << nl << endl; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /pyDemFoam/demIcoFoamSemiImplicitDrag.H: -------------------------------------------------------------------------------- 1 | #include "demBaseFoam.H" 2 | #include "pisoControl.H" 3 | 4 | class demIcoFoamSemiImplicitDrag : public demBaseFoam { 5 | public: 6 | demIcoFoamSemiImplicitDrag(); 7 | virtual ~demIcoFoamSemiImplicitDrag(); 8 | virtual void run(double t); 9 | 10 | volVectorField *ubar_; 11 | volScalarField *beta_; 12 | VEC_SETGET(ubar) 13 | SETGET(beta) 14 | 15 | pisoControl *piso_; 16 | }; 17 | -------------------------------------------------------------------------------- /pyDemFoam/demSimpleFoam.C: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | 5 | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation 6 | \\/ M anipulation | 7 | --------------------------------------------------------------------- 8 | License 9 | This file is not part of OpenFOAM. 10 | 11 | OpenFOAM is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with OpenFOAM. If not, see . 23 | 24 | Application 25 | demSimpleFoam 26 | \*--------------------------------------------------------------*/ 27 | 28 | #include "demSimpleFoam.H" 29 | 30 | demSimpleFoam::demSimpleFoam() { 31 | Info << "creating demSimpleFoam object" << nl << endl; 32 | 33 | ubar_ = new volVectorField(IOobject ("ubar", runTime_->timeName(), *mesh_, 34 | IOobject::MUST_READ, 35 | IOobject::AUTO_WRITE), *mesh_); 36 | beta_ = new volScalarField (IOobject ("beta", runTime_->timeName(), *mesh_, 37 | IOobject::MUST_READ, 38 | IOobject::AUTO_WRITE), *mesh_); 39 | simple_ = new simpleControl(*mesh_); 40 | } 41 | 42 | demSimpleFoam::~demSimpleFoam() { 43 | Info << "cleaning up demSimpleFoam" << nl << endl; 44 | if (ubar_) delete ubar_; 45 | if (beta_) delete beta_; 46 | } 47 | 48 | void demSimpleFoam::run(double) { 49 | volScalarField &beta = *beta_; 50 | volVectorField &ubar = *ubar_; 51 | volVectorField &U = *U_; 52 | volScalarField &n = *n_; 53 | volScalarField &p = *p_; 54 | dimensionedScalar &nu = *nu_; 55 | surfaceScalarField &phi = *phi_; 56 | Foam::Time &runTime = *runTime_; 57 | Foam::fvMesh &mesh = *mesh_; 58 | scalar &cumulativeContErr = cumulativeContErr_; 59 | 60 | while (simple_->loop()) 61 | { 62 | Info<< "Time = " << runTime.timeName() << nl << endl; 63 | 64 | // --- Pressure-velocity SIMPLE corrector 65 | { 66 | // Momentum predictor 67 | tmp UEqn (fvm::div(phi, U) - 68 | fvm::laplacian(nu, U) - 69 | beta*ubar/n - 70 | fvm::Sp(beta/n, U) 71 | ); 72 | UEqn().relax(); 73 | 74 | solve(UEqn() == -fvc::grad(p)); 75 | 76 | //#include "pEqn.H" 77 | { 78 | volScalarField rAU(1.0/UEqn().A()); 79 | volVectorField HbyA("HbyA", U); 80 | HbyA = rAU*UEqn().H(); 81 | 82 | surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(HbyA) & 83 | mesh.Sf()); 84 | adjustPhi(phiHbyA, U, p); 85 | 86 | tmp rAtU(rAU); 87 | 88 | if (simple_->consistent()) 89 | { 90 | rAtU = 1.0/(1.0/rAU - UEqn().H1()); 91 | phiHbyA += 92 | fvc::interpolate(rAtU() - rAU)*fvc::snGrad(p)*mesh.magSf(); 93 | HbyA -= (rAU - rAtU())*fvc::grad(p); 94 | } 95 | 96 | UEqn.clear(); 97 | 98 | // Non-orthogonal pressure corrector loop 99 | while (simple_->correctNonOrthogonal()) 100 | { 101 | fvScalarMatrix pEqn (fvm::laplacian(rAtU(), p) == fvc::div(phiHbyA)); 102 | 103 | pEqn.setReference(pRefCell_, pRefValue_); 104 | 105 | pEqn.solve(); 106 | 107 | if (simple_->finalNonOrthogonalIter()) 108 | { 109 | phi = phiHbyA - pEqn.flux(); 110 | } 111 | } 112 | 113 | #include "continuityErrs.H" 114 | 115 | // Explicitly relax pressure for momentum corrector 116 | p.relax(); 117 | 118 | // Momentum corrector 119 | U = HbyA - rAtU()*fvc::grad(p); 120 | U.correctBoundaryConditions(); 121 | } 122 | } 123 | runTime.write(); 124 | 125 | Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" 126 | << " ClockTime = " << runTime.elapsedClockTime() << " s" 127 | << nl << endl; 128 | } 129 | Info << "SIMPLE Solve Ended. \n" << endl; 130 | } 131 | -------------------------------------------------------------------------------- /pyDemFoam/demSimpleFoam.H: -------------------------------------------------------------------------------- 1 | #include "demBaseFoam.H" 2 | #include "simpleControl.H" 3 | 4 | class demSimpleFoam : public demBaseFoam { 5 | public: 6 | demSimpleFoam(); 7 | virtual ~demSimpleFoam(); 8 | virtual void run(double t); 9 | 10 | volVectorField *ubar_; 11 | volScalarField *beta_; 12 | VEC_SETGET(ubar) 13 | SETGET(beta) 14 | 15 | simpleControl *simple_; 16 | }; 17 | -------------------------------------------------------------------------------- /pyDemFoam/pyDemFoam/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "2022.01.09" 2 | 3 | from _pyDemFoam import pyDemIcoFoam 4 | from _pyDemFoam import pyDemIcoFoamSemiImplicitDrag 5 | -------------------------------------------------------------------------------- /pyDemFoam/setup.py: -------------------------------------------------------------------------------- 1 | long_description = """ 2 | Python wrapper for demIcoFoam. 3 | 4 | demIcoFoam is an OpenFOAM CFD solver which can interact with a 5 | discrete element model. 6 | """ 7 | 8 | from distutils.core import setup 9 | from distutils.extension import Extension 10 | from Cython.Build import cythonize 11 | import os 12 | import string 13 | 14 | assert not os.getenv("FOAM_SRC") is None, "Cannot find OpenFOAM install. Did you source ~/OpenFOAM/OpenFOAM-v3.0+/etc/bashrc ?" 15 | 16 | assert os.path.isfile(os.getenv("FOAM_APPBIN")+"/icoFoam"), "Cannot find OpenFOAM binaries. Did you build OpenFOAM in the default location? " 17 | 18 | 19 | def get_version_number(module): 20 | f = open(os.path.join(module, "__init__.py")) 21 | v = (f.readline().split("=")[1]).strip()[1:-1] 22 | print(v) 23 | return v 24 | 25 | try: 26 | print("building version", get_version_number("pyDemFoam")) 27 | except: 28 | print("could not find version number in __init__.py") 29 | raise 30 | 31 | 32 | ext = [Extension("_pyDemFoam", 33 | sources=["_pyDemFoam.pyx", 34 | "demIcoFoam.C", 35 | "demIcoFoamSemiImplicitDrag.C", 36 | "demBaseFoam.C"], 37 | include_dirs = [ 38 | os.getenv("FOAM_SRC")+"/finiteVolume/lnInclude", 39 | os.getenv("FOAM_SRC")+"/meshTools/lnInclude", 40 | os.getenv("FOAM_SRC")+"/OpenFOAM/lnInclude", 41 | os.getenv("FOAM_SRC")+"/OSspecific/POSIX/lnInclude"], 42 | extra_compile_args= ["-m64", "-Dlinux64", "-DWM_ARCH_OPTION=64", 43 | "-DWM_DP", "-DWM_LABEL_SIZE=64", "-Wall", 44 | "-Wextra", "-Wold-style-cast", 45 | "-Wnon-virtual-dtor", 46 | "-Wno-unused-parameter", 47 | "-Wno-invalid-offsetof", "-O3", 48 | "-DNoRepository", "-ftemplate-depth-100"], 49 | extra_link_args=["-Xlinker", "--add-needed", 50 | "-Xlinker", "--no-as-needed"], 51 | libraries = ["finiteVolume", "meshTools", "OpenFOAM", "dl", "m"], 52 | library_dirs = [os.getenv("FOAM_LIBBIN")], 53 | language="c++", # generate C++ code 54 | )] 55 | 56 | 57 | setup( 58 | name = 'pyDemFoam', 59 | packages = ["pyDemFoam"], # this must be the same as the name above 60 | version = get_version_number("pyDemFoam"), 61 | description = "Python wrapper for Dem OpenFoam solvers.", 62 | long_description = long_description, 63 | author = 'Jason Furtney', 64 | requires = ['numpy'], 65 | author_email = 'jfurtney@itascacg.com', 66 | url = "https://github.com/jkfurtney/PFC3D_OpenFOAM", 67 | keywords = 'OpenFOAM,CFD,icoFoam,simpleFoam,PFC3D,PFC,DEM'.split(","), 68 | license = "BSD", 69 | classifiers = [ 70 | 'Programming Language :: Python :: 3', 71 | "Development Status :: 5 - Production/Stable", 72 | "License :: OSI Approved :: BSD License", 73 | 'Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator', 74 | "Intended Audience :: Science/Research" 75 | ], 76 | ext_modules = cythonize(ext, language_level=3)) 77 | -------------------------------------------------------------------------------- /sctetracoupler/client_for_custom_server.py: -------------------------------------------------------------------------------- 1 | import customsocket 2 | import create_mesh 3 | #reload(customsocket) 4 | 5 | 6 | #client = customsocket.CustomSocketClient(tcp_id='192.168.1.11',tcp_port=3333) 7 | client = customsocket.CustomSocketClient(tcp_id='127.0.0.1',tcp_port=3333) 8 | 9 | client.start() 10 | 11 | 12 | # UPDATE MESH 13 | # receive number of nodes 14 | nbNodes = client.read_data() 15 | print "Number of nodes: ",nbNodes 16 | 17 | # receive node information 18 | nodes = {} 19 | for n in range(0,nbNodes): 20 | i = client.read_data() # node id 21 | x = client.read_data() # node x 22 | y = client.read_data() # node y 23 | z = client.read_data() # node z 24 | nodes[i] = [x,y,z] 25 | #print "coord node {} : {} {} {}".format(n,x,y,z) 26 | 27 | # receive connectivity information 28 | nbElem = client.read_data() 29 | print "Number of elements: ",nbElem 30 | elements_nodes = {} 31 | for n in range(0,nbElem): 32 | i = client.read_data() # element ID (should be n) 33 | nn = client.read_data() # total number of nodes 34 | idx = [] 35 | for j in range(0,nn): 36 | nj = client.read_data() # index of node j 37 | idx.append(nj) 38 | elements_nodes[i] = idx 39 | # print "connection {} : {}".format(n,ic) 40 | 41 | 42 | # UPDATE MESHELEM 43 | # receive number of elements 44 | nbElem = client.read_data() 45 | print "Number of elements: ",nbElem 46 | elements_geom = {} 47 | for n in range(0,nbElem): 48 | x = client.read_data() 49 | y = client.read_data() 50 | z = client.read_data() 51 | v = client.read_data() 52 | elements_geom[n] = [x,y,z,v] 53 | #print "element {} : x = {} y = {} z = {} - vol = {}".format(n,x,y,z,v) 54 | 55 | 56 | # UPDATE FIELD 57 | # receive number of elements 58 | nbElem = client.read_data() 59 | print "Number of elements: ",nbElem 60 | elements_field = {} 61 | for n in range(0,nbElem): 62 | u = client.read_data() 63 | v = client.read_data() 64 | w = client.read_data() 65 | p = client.read_data() 66 | d = client.read_data() 67 | vi = client.read_data() 68 | elements_field[n] = [u,v,w,p,d,vi] 69 | #print "element {} : u = {} v = {} w = {} p = {} d = {} vi = {}".format(n,u,v,w,p,d,vi) 70 | 71 | #send communication status (success) 72 | client.send_data(1) 73 | 74 | client.close() 75 | 76 | # create mesh as a collection of geometry sets for visualization 77 | create_mesh.create_mesh(nodes,elements_nodes) -------------------------------------------------------------------------------- /sctetracoupler/customsocket.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import socket 3 | import select 4 | import time 5 | import subprocess 6 | import numpy as np 7 | 8 | class CustomSocketClient(object): 9 | """Low level details of the socket communication""" 10 | def __init__(self,tcp_id='127.0.0.1', tcp_port=3333): 11 | self.tcp_id = tcp_id 12 | self.tcp_port = tcp_port 13 | self.handshake = 178278912 14 | 15 | def start(self): 16 | """() -> None. Open the low level socket connection. Blocks but allows the Python thread scheduler to run. 17 | 18 | """ 19 | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 20 | self.socket.connect((self.tcp_id,self.tcp_port)) 21 | self.conn = self.socket 22 | self.send_data(self.handshake) 23 | 24 | def send_data(self, value): 25 | """(value: any) -> None. Send value to Itasca software. value must be int, float, length two list of doubles, length three list of doubles or a string. 26 | 27 | """ 28 | while True: 29 | _, write_ready, _ = select.select([], [self.conn], [], 0.0) 30 | if write_ready: break 31 | else: time.sleep(1e-8) 32 | 33 | if type(value) == int: 34 | self.conn.sendall(struct.pack("i", 1)) 35 | self.conn.sendall(struct.pack("i", value)) 36 | elif type(value) == float: 37 | self.conn.sendall(struct.pack("i", 2)) 38 | self.conn.sendall(struct.pack("d", value)) 39 | elif type(value) == list and len(value)==2: 40 | float_list = [float(x) for x in value] 41 | self.conn.sendall(struct.pack("i", 5)) 42 | self.conn.sendall(struct.pack("dd", float_list[0], float_list[1])) 43 | elif type(value) == list and len(value)==3: 44 | float_list = [float(x) for x in value] 45 | self.conn.sendall(struct.pack("i", 6)) 46 | self.conn.sendall(struct.pack("ddd", float_list[0], 47 | float_list[1], float_list[2])) 48 | elif type(value) == str: 49 | length = len(value) 50 | self.conn.sendall(struct.pack("ii", 3, length)) 51 | buffer_length = 4*(1+(length-1)/4) 52 | format_string = "%is" % buffer_length 53 | value += " "*(buffer_length - length) 54 | self.conn.sendall(struct.pack(format_string, value)) 55 | else: 56 | raise Exception("unknown type in send_data") 57 | 58 | def wait_for_data(self): 59 | """() -> None. Block until data is available. This call allows the Python thread scheduler to run. 60 | 61 | """ 62 | while True: 63 | input_ready, _, _ = select.select([self.conn],[],[], 0.0) 64 | if input_ready: return 65 | else: time.sleep(1e-8) 66 | 67 | def read_type(self, type_string): 68 | """(type: str) -> any. This method should not be called directly. Use the read_data method. 69 | 70 | """ 71 | byte_count = struct.calcsize(type_string) 72 | bytes_read = 0 73 | data = '' 74 | self.wait_for_data() 75 | while bytes_read < byte_count: 76 | self.wait_for_data() 77 | data_in = self.conn.recv(byte_count - bytes_read) 78 | data += data_in 79 | bytes_read += len(data) 80 | assert len(data)==byte_count, "bad packet data" 81 | return data 82 | 83 | def read_data(self): 84 | """() -> any. Read the next item from the socket connection.""" 85 | raw_data = self.read_type("i") 86 | type_code, = struct.unpack("i", raw_data) 87 | if type_code == 1: # int 88 | raw_data = self.read_type("i") 89 | value, = struct.unpack("i", raw_data) 90 | return value 91 | elif type_code == 2: # float 92 | raw_data = self.read_type("d") 93 | value, = struct.unpack("d", raw_data) 94 | return value 95 | elif type_code == 3: # string 96 | length_data = self.read_type("i") 97 | length, = struct.unpack("i", length_data) 98 | buffer_length = (4*(1+(length-1)/4)) 99 | format_string = "%is" % buffer_length 100 | data = self.read_type(format_string) 101 | return data [:length] 102 | elif type_code == 5: # V2 103 | raw_data = self.read_type("dd") 104 | value0, value1 = struct.unpack("dd", raw_data) 105 | return [value0, value1] 106 | elif type_code == 6: # V3 107 | raw_data = self.read_type("ddd") 108 | value0, value1, value3 = struct.unpack("ddd", raw_data) 109 | return [value0, value1, value3] 110 | assert False, "Data read type error %i" % type_code 111 | 112 | def close(self): 113 | """() -> None. Close the active socket connection.""" 114 | self.conn.close() -------------------------------------------------------------------------------- /sctetracoupler/make_ini.p3dat: -------------------------------------------------------------------------------- 1 | new 2 | 3 | [dp = 0.5*1.5e-3] 4 | domain extent -0.5e-2 4.5e-2 -0.5e-2 20.5e-2 -0.5e-2 1.25e-2 5 | 6 | wall generate box 0.0 4.0e-2 0.0 20.0e-2 0.0 0.75e-2 7 | wall tolerance etolerance 0.0 ctol [0.1*dp] 8 | 9 | cmat default model linear property kn 1e5 ks 1e5 fric 0.25 dp_nratio 0.2 10 | 11 | set gravity 0.0 -9.81 0.0 12 | 13 | ball generate number 5000 radius [0.5*dp] box 0.0 4.0e-2 0.0 6.0e-2 0.0 0.75e-2 14 | 15 | ball attribute density 2000.0 damp 0.7 16 | 17 | solve aratio 1e-3 18 | 19 | ball attribute damp 0.0 20 | cycle 10 21 | solve aratio 1e-3 22 | calm 23 | save ini2 24 | 25 | return 26 | wall generate plane position 0.0 10.0e-2 0.0 dip 90.0 27 | save ini-wall -------------------------------------------------------------------------------- /sctetracoupler/test.py: -------------------------------------------------------------------------------- 1 | import sctetracoupler 2 | reload(sctetracoupler) 3 | 4 | 5 | model = sctetracoupler.ScTetraCoupler("ini-wall") 6 | 7 | model.execute() -------------------------------------------------------------------------------- /wrapper_tests/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object U; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type fixedValue; 31 | value uniform (0 0 0); 32 | } 33 | 34 | frontAndBack 35 | { 36 | type fixedValue; 37 | value uniform (0 0 0); 38 | } 39 | } 40 | 41 | // ************************************************************************* // 42 | -------------------------------------------------------------------------------- /wrapper_tests/0/beta: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object beta; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 -1 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | 34 | frontAndBack 35 | { 36 | type fixedValue; 37 | value uniform 0; 38 | } 39 | } 40 | 41 | // ************************************************************************* // 42 | -------------------------------------------------------------------------------- /wrapper_tests/0/f: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object f; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -2 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | 29 | fixedWalls 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | 35 | frontAndBack 36 | { 37 | type fixedValue; 38 | value uniform (0 0 0); 39 | } 40 | } 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /wrapper_tests/0/n: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object n; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1.0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | frontAndBack 34 | { 35 | type zeroGradient; 36 | } 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /wrapper_tests/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 2 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type fixedValue; 26 | value uniform 0; 27 | } 28 | 29 | fixedWalls 30 | { 31 | type zeroGradient; 32 | } 33 | 34 | frontAndBack 35 | { 36 | type zeroGradient; 37 | } 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /wrapper_tests/0/ubar: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object ubar; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 -1 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | topWall 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | fixedWalls 29 | { 30 | type fixedValue; 31 | value uniform (0 0 0); 32 | } 33 | 34 | frontAndBack 35 | { 36 | type fixedValue; 37 | value uniform (0 0 0); 38 | } 39 | } 40 | 41 | 42 | // ************************************************************************* // 43 | -------------------------------------------------------------------------------- /wrapper_tests/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object transportProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | nu [0 2 -1 0 0 0 0] 1.1905e-3; 19 | rho [1 -3 0 0 0 0 0] 1260.0; 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /wrapper_tests/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | //convertToMeters 0.1; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (1 0 0) 23 | (1 1 0) 24 | (0 1 0) 25 | (0 0 1) 26 | (1 0 1) 27 | (1 1 1) 28 | (0 1 1) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (12 12 12) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | topWall 43 | { 44 | type wall; 45 | faces 46 | ( 47 | (4 5 6 7) 48 | ); 49 | } 50 | fixedWalls 51 | { 52 | type wall; 53 | faces 54 | ( 55 | (0 4 7 3) 56 | (2 6 5 1) 57 | (1 5 4 0) 58 | ); 59 | } 60 | frontAndBack 61 | { 62 | type wall; 63 | faces 64 | ( 65 | (0 3 2 1) 66 | (3 7 6 2) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /wrapper_tests/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application icoFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 0.005; 27 | 28 | deltaT 0.005; 29 | 30 | writeControl runTime; 31 | 32 | writeInterval 100000; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable true; 47 | 48 | maxCo 0.5; 49 | adjustTimeStep yes; 50 | maxDeltaT 1; 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /wrapper_tests/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | ddtSchemes 19 | { 20 | default Euler; 21 | } 22 | 23 | gradSchemes 24 | { 25 | default Gauss linear; 26 | grad(p) Gauss linear; 27 | } 28 | 29 | divSchemes 30 | { 31 | default none; 32 | div(phi,U) Gauss linear; 33 | } 34 | 35 | laplacianSchemes 36 | { 37 | default Gauss linear orthogonal; 38 | } 39 | 40 | interpolationSchemes 41 | { 42 | default linear; 43 | } 44 | 45 | snGradSchemes 46 | { 47 | default orthogonal; 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /wrapper_tests/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: v3.0+ | 5 | | \\ / A nd | Web: www.OpenFOAM.com | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | 17 | solvers 18 | { 19 | p 20 | { 21 | solver PCG; 22 | preconditioner DIC; 23 | tolerance 1e-06; 24 | relTol 0; 25 | } 26 | 27 | U 28 | { 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-05; 32 | relTol 0; 33 | } 34 | } 35 | 36 | PISO 37 | { 38 | nCorrectors 2; 39 | nNonOrthogonalCorrectors 0; 40 | pRefCell 0; 41 | pRefValue 0; 42 | } 43 | SIMPLE 44 | { 45 | 46 | nNonOrthogonalCorrectors 0; 47 | pRefCell 0; 48 | pRefValue 0; 49 | 50 | residualControl 51 | { 52 | p 1e-5; 53 | U 1e-5; 54 | } 55 | } 56 | 57 | relaxationFactors 58 | { 59 | fields 60 | { 61 | p 0.3; 62 | } 63 | equations 64 | { 65 | U 0.7; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /wrapper_tests/test_pyDemIcoFoam.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from pyDemFoam import pyDemIcoFoam 3 | 4 | solver = pyDemIcoFoam() 5 | 6 | assert solver.nFaces() == 5616 7 | assert solver.nNodes() == 2197 8 | assert solver.nCells() == 1728 9 | print solver.faces() 10 | print solver.cell_faces() 11 | print solver.face_centers() 12 | print solver.phi() 13 | print solver.phi().shape 14 | 15 | 16 | x,y,z = solver.cell_centers().T 17 | 18 | n=solver.n() 19 | n[abs(y-0.005)<1e-9]=0.5 20 | print (abs(y-0.005)<1e-9).sum() 21 | solver.n(n) 22 | 23 | solver.solve(0.005) 24 | 25 | cc = solver.cell_centers() 26 | flux = solver.cell_fluxes() 27 | cv = solver.cell_volumes() 28 | 29 | clist = range(120,130) 30 | 31 | print solver.U()[:,1][clist] 32 | 33 | for i in range(120,130): 34 | #print cc[i] 35 | flux[i] 36 | flux[i].sum()*solver.dt()/cv[i] 37 | 38 | assert type(solver.f()) is np.ndarray 39 | assert solver.f().shape == (solver.nCells(),3) 40 | assert solver.U().shape == (solver.nCells(),3) 41 | assert solver.n().shape == (solver.nCells(),) 42 | assert solver.gradp().shape == (solver.nCells(),3) 43 | 44 | 45 | print solver.flux_on_patch("topWall") 46 | print solver.flux_on_patch("fixedWalls") 47 | -------------------------------------------------------------------------------- /wrapper_tests/test_pyDemSimpleFoam.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from pyDemFoam import pyDemSimpleFoam 3 | 4 | solver = pyDemSimpleFoam() 5 | 6 | assert solver.nFaces() == 5616 7 | assert solver.nNodes() == 2197 8 | assert solver.nCells() == 1728 9 | print solver.faces() 10 | print solver.cell_faces() 11 | print solver.face_centers() 12 | print solver.phi() 13 | print solver.phi().shape 14 | 15 | x,y,z = solver.cell_centers().T 16 | print 1 17 | n=solver.n() 18 | print 2 19 | n[abs(y-0.005)<1e-9]=0.5 20 | print (abs(y-0.005)<1e-9).sum() 21 | solver.n(n) 22 | print 3 23 | 24 | solver.solve(0.0) 25 | print 4 26 | 27 | cc = solver.cell_centers() 28 | flux = solver.cell_fluxes() 29 | cv = solver.cell_volumes() 30 | 31 | clist = range(120,130) 32 | 33 | print solver.U()[:,1][clist] 34 | 35 | for i in range(120,130): 36 | #print cc[i] 37 | print i 38 | print flux[i] 39 | print flux[i].sum()/cv[i] 40 | 41 | assert type(solver.beta()) is np.ndarray 42 | assert solver.beta().shape == (solver.nCells(),) 43 | assert solver.ubar().shape == (solver.nCells(),3) 44 | assert solver.U().shape == (solver.nCells(),3) 45 | assert solver.n().shape == (solver.nCells(),) 46 | assert solver.gradp().shape == (solver.nCells(),3) 47 | 48 | 49 | print solver.flux_on_patch("topWall") 50 | print solver.flux_on_patch("fixedWalls") 51 | --------------------------------------------------------------------------------