├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── examples ├── falling_ellipse │ ├── 0 │ │ ├── T │ │ ├── U │ │ └── p │ ├── constant │ │ ├── polyMesh │ │ │ ├── boundary │ │ │ ├── faces │ │ │ ├── neighbour │ │ │ ├── owner │ │ │ └── points │ │ └── transportProperties │ ├── solidDict │ └── system │ │ ├── blockMeshDict │ │ ├── controlDict │ │ ├── decomposeParDict │ │ ├── fvSchemes │ │ └── fvSolution ├── flow_past_cylinder │ └── re200 │ │ ├── 0 │ │ ├── As │ │ ├── T │ │ ├── U │ │ └── p │ │ ├── constant │ │ └── transportProperties │ │ ├── solidDict │ │ └── system │ │ ├── blockMeshDict │ │ ├── controlDict │ │ ├── decomposeParDict │ │ ├── fvSchemes │ │ └── fvSolution ├── readme ├── sedimentation │ ├── 0 │ │ ├── T │ │ ├── U │ │ └── p │ ├── constant │ │ └── transportProperties │ ├── solidDict │ └── system │ │ ├── blockMeshDict │ │ ├── controlDict │ │ ├── decomposeParDict │ │ ├── fvSchemes │ │ ├── fvSolution │ │ ├── refineMeshDict │ │ └── topoSetDict └── taylor_couette │ ├── 0 │ ├── T │ ├── U │ └── p │ ├── constant │ └── transportProperties │ ├── fdm.m │ ├── solidDict │ └── system │ ├── blockMeshDict │ ├── controlDict │ ├── decomposeParDict │ ├── fvSchemes │ └── fvSolution ├── figs ├── ani_T.gif ├── flow_past_cylinder_re200.gif ├── init_on_poly.png ├── planes.png ├── smooth_vs_rough.gif ├── traj.svg ├── vof.png └── vof_ani.gif ├── src ├── CMakeLists.txt ├── cellenumerator.cpp ├── cellenumerator.h ├── createFields.h ├── entitylibrary.h ├── genericfactory.h ├── geometrictools.cpp ├── geometrictools.h ├── libcollision │ ├── CMakeLists.txt │ ├── bbox.h │ ├── collision.cpp │ ├── collision.h │ ├── ugrid.cpp │ └── ugrid.h ├── libforcer │ ├── CMakeLists.txt │ ├── constant.h │ ├── forcerfactory.cpp │ ├── forcerfactory.h │ ├── iforcer.h │ ├── magnetic.h │ └── spring.h ├── libmaterial │ ├── CMakeLists.txt │ └── imaterial.h ├── libmotion │ ├── CMakeLists.txt │ ├── imotion.h │ ├── motion000002.h │ ├── motion01mask.h │ ├── motion110002.h │ ├── motion222000.h │ ├── motionfactory.cpp │ ├── motionfactory.h │ ├── motionopenclose.h │ ├── motionrotor.h │ └── motionsinedirectional.h ├── libshape │ ├── CMakeLists.txt │ ├── box.h │ ├── circle.h │ ├── circle_tail.h │ ├── circle_twotail.h │ ├── ellipse.h │ ├── ellipsoid.h │ ├── ishape.h │ ├── plane.h │ ├── rectangle.h │ ├── sdf │ │ └── sdf.h │ ├── shapefactory.cpp │ ├── shapefactory.h │ ├── sphere.h │ └── template.h ├── logger.cpp ├── logger.h ├── main.cpp ├── meshinfo.cpp ├── meshinfo.h ├── solid.cpp ├── solid.h ├── solidcloud.cpp ├── solidcloud.h ├── types.h └── utils.h └── tool_vof ├── Makefile ├── example ├── 0 │ ├── U │ ├── alpha.water │ └── p_rgh ├── alpha.water.orig ├── constant │ ├── g │ ├── polyMesh │ │ ├── blockMeshDict │ │ ├── boundary │ │ ├── faces │ │ ├── neighbour │ │ ├── owner │ │ └── points │ ├── transportProperties │ └── turbulenceProperties ├── run.sh ├── solidDict ├── system │ ├── controlDict │ ├── decomposeParDict │ ├── fvSchemes │ ├── fvSolution │ └── setFieldsDict └── view.foam ├── main.cpp ├── smoothvof ├── solidcloud.cpp └── solidcloud.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | TabWidth: 4 3 | IndentWidth: 4 4 | UseTab: Never 5 | ColumnLimit: 120 6 | 7 | Language: Cpp 8 | DisableFormat: false 9 | Standard: Cpp11 10 | 11 | AccessModifierOffset: -4 12 | AlignAfterOpenBracket: true 13 | AlignConsecutiveAssignments: false 14 | AlignConsecutiveDeclarations: false 15 | AlignEscapedNewlinesLeft: false 16 | AlignOperands: true 17 | AlignTrailingComments: false 18 | AllowAllParametersOfDeclarationOnNextLine: true 19 | AllowShortBlocksOnASingleLine: false 20 | AllowShortCaseLabelsOnASingleLine: false 21 | AllowShortFunctionsOnASingleLine: Empty 22 | AllowShortIfStatementsOnASingleLine: false 23 | AllowShortLoopsOnASingleLine: false 24 | AlwaysBreakAfterDefinitionReturnType: false 25 | AlwaysBreakAfterReturnType: None 26 | AlwaysBreakBeforeMultilineStrings: false 27 | AlwaysBreakTemplateDeclarations: true 28 | BinPackArguments: false 29 | BinPackParameters: false 30 | 31 | BreakBeforeBraces: Custom 32 | BraceWrapping: { 33 | AfterClass: 'true' 34 | AfterControlStatement: 'true' 35 | AfterEnum : 'true' 36 | AfterFunction : 'true' 37 | AfterNamespace : 'false' 38 | AfterStruct : 'true' 39 | AfterUnion : 'true' 40 | BeforeCatch : 'true' 41 | BeforeElse : 'true' 42 | IndentBraces : 'false' 43 | AfterExternBlock : 'true' 44 | SplitEmptyFunction : 'false' 45 | SplitEmptyRecord : 'false' 46 | SplitEmptyNamespace : 'true' 47 | } 48 | 49 | BreakBeforeInheritanceComma: false 50 | BreakBeforeBinaryOperators: None 51 | BreakBeforeTernaryOperators: true 52 | BreakConstructorInitializersBeforeComma: true 53 | BreakStringLiterals: true 54 | 55 | CompactNamespaces: false 56 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 57 | ConstructorInitializerIndentWidth: 4 58 | ContinuationIndentWidth: 4 59 | Cpp11BracedListStyle: true 60 | SpaceBeforeCpp11BracedList: false 61 | ExperimentalAutoDetectBinPacking: false 62 | IndentCaseLabels: false 63 | FixNamespaceComments: true 64 | IndentWrappedFunctionNames: false 65 | KeepEmptyLinesAtTheStartOfBlocks: true 66 | MacroBlockBegin: '' 67 | MacroBlockEnd: '' 68 | MaxEmptyLinesToKeep: 1 69 | NamespaceIndentation: None 70 | ObjCBlockIndentWidth: 4 71 | ObjCSpaceAfterProperty: true 72 | ObjCSpaceBeforeProtocolList: true 73 | 74 | PenaltyExcessCharacter: 1000000 75 | PenaltyReturnTypeOnItsOwnLine: 60 76 | DerivePointerAlignment: false 77 | PointerAlignment: Left 78 | SpaceAfterCStyleCast: false 79 | SpaceBeforeAssignmentOperators: true 80 | SpaceBeforeParens: ControlStatements 81 | SpaceInEmptyParentheses: false 82 | SpacesBeforeTrailingComments: 1 83 | SpacesInAngles: false 84 | SpacesInContainerLiterals: true 85 | SpacesInCStyleCastParentheses: false 86 | SpacesInParentheses: false 87 | SpacesInSquareBrackets: false 88 | SpaceAfterTemplateKeyword: true 89 | SpaceBeforeInheritanceColon: true 90 | 91 | SortUsingDeclarations: false 92 | SortIncludes: false 93 | 94 | ReflowComments: false 95 | IncludeBlocks: Preserve 96 | IndentPPDirectives: AfterHash 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # qt creator files 2 | cpc.* 3 | # Compiled source # 4 | ################### 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | *.a 10 | *.pro 11 | sdfibm 12 | 13 | # Packages # 14 | ############ 15 | *.7z 16 | *.gz 17 | *.rar 18 | *.tar 19 | *.zip 20 | 21 | *.log 22 | 23 | # OS generated files # 24 | ###################### 25 | .DS_Store 26 | .DS_Store? 27 | ._* 28 | .Spotlight-V100 29 | .Trashes 30 | 31 | ehthumbs.db 32 | Thumbs.db 33 | 34 | build 35 | .vscode 36 | .gitignore 37 | test_case 38 | test 39 | CMakePresets.json 40 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12 FATAL_ERROR) 2 | project(sdfibm LANGUAGES CXX C) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") 7 | 8 | if(DEFINED ENV{WM_PROJECT_DIR}) 9 | MESSAGE(STATUS "OpenFOAM: " $ENV{WM_PROJECT_DIR}) 10 | else() 11 | message(FATAL_ERROR "Cannot find OpenFOAM") 12 | endif(DEFINED ENV{WM_PROJECT_DIR}) 13 | 14 | set(FOAMVERSION $ENV{WM_PROJECT_VERSION}) 15 | set(FOAMDIR $ENV{WM_PROJECT_DIR}) 16 | set(FOAMLIB $ENV{FOAM_LIBBIN}) 17 | set(FOAMSRC $ENV{FOAM_SRC}) 18 | set(FOAMMPI $ENV{FOAM_MPI}) 19 | 20 | set(FOAMFLAG "-std=c++17 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wno-unused-parameter -Wno-overloaded-virtual -Wold-style-cast 21 | -Wnon-virtual-dtor -Wno-unused-variable -Wno-invalid-offsetof -DNoRepository -ftemplate-depth-100 -fPIC") 22 | 23 | set(FOAMINC 24 | ${FOAMSRC}/finiteVolume/lnInclude 25 | ${FOAMSRC}/OpenFOAM/lnInclude 26 | ${FOAMSRC}/OSspecific/POSIX/lnInclude 27 | ${FOAMSRC}/meshTools/lnInclude 28 | ${FOAMSRC}/dynamicFvMesh/lnInclude 29 | ) 30 | 31 | link_directories( 32 | ${FOAMLIB} 33 | ${FOAMLIB}/${FOAMMPI} 34 | ) 35 | 36 | add_subdirectory(src) 37 | -------------------------------------------------------------------------------- /examples/falling_ellipse/0/T: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object T; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 1 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | top {type fixedValue; value uniform 0; } 24 | bottom{type fixedValue; value uniform 0; } 25 | left {type fixedValue; value uniform 0; } 26 | right {type fixedValue; value uniform 0; } 27 | front {type empty;} 28 | back {type empty;} 29 | } 30 | 31 | // ************************************************************************* // 32 | -------------------------------------------------------------------------------- /examples/falling_ellipse/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | left 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | right 29 | { 30 | type fixedValue; 31 | value uniform (0 0 0); 32 | } 33 | bottom 34 | { 35 | type fixedValue; 36 | value uniform (0 0 0); 37 | } 38 | top 39 | { 40 | type fixedValue; 41 | value uniform (0 0 0); 42 | } 43 | front {type empty;} 44 | back {type empty;} 45 | } 46 | 47 | // ************************************************************************* // 48 | -------------------------------------------------------------------------------- /examples/falling_ellipse/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | left { type zeroGradient; } 24 | right { type zeroGradient; } 25 | // top { type fixedValue; value uniform 0; } 26 | top { type zeroGradient; } 27 | bottom{ type zeroGradient; } 28 | front {type empty;} 29 | back {type empty;} 30 | } 31 | 32 | // ************************************************************************* // 33 | -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/polyMesh/boundary: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 9 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | format binary; 11 | class polyBoundaryMesh; 12 | location "constant/polyMesh"; 13 | object boundary; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | 6 18 | ( 19 | left 20 | { 21 | type wall; 22 | inGroups List 1(wall); 23 | nFaces 200; 24 | startFace 39700; 25 | } 26 | right 27 | { 28 | type wall; 29 | inGroups List 1(wall); 30 | nFaces 200; 31 | startFace 39900; 32 | } 33 | bottom 34 | { 35 | type wall; 36 | inGroups List 1(wall); 37 | nFaces 100; 38 | startFace 40100; 39 | } 40 | top 41 | { 42 | type wall; 43 | inGroups List 1(wall); 44 | nFaces 100; 45 | startFace 40200; 46 | } 47 | front 48 | { 49 | type empty; 50 | inGroups List 1(empty); 51 | nFaces 20000; 52 | startFace 40300; 53 | } 54 | back 55 | { 56 | type empty; 57 | inGroups List 1(empty); 58 | nFaces 20000; 59 | startFace 60300; 60 | } 61 | ) 62 | 63 | // ************************************************************************* // 64 | -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/polyMesh/faces: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/examples/falling_ellipse/constant/polyMesh/faces -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/polyMesh/neighbour: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/examples/falling_ellipse/constant/polyMesh/neighbour -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/polyMesh/owner: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/examples/falling_ellipse/constant/polyMesh/owner -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/polyMesh/points: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/examples/falling_ellipse/constant/polyMesh/points -------------------------------------------------------------------------------- /examples/falling_ellipse/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 nu [ 0 2 -1 0 0 0 0 ] 0.01; 19 | alpha alpha [ 0 2 -1 0 0 0 0 ] 0.001; 20 | rho rho [ 1 -3 0 0 0 0 0 ] 1.0; 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /examples/falling_ellipse/solidDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 6.0.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object solids; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | meta 19 | { 20 | on_fluid 1; 21 | on_twod 1; 22 | gravity (0.0 -10.0 0.0); 23 | } 24 | 25 | shapes 26 | { 27 | shape1 28 | { 29 | name ellipse1; 30 | type Ellipse; 31 | radiusa 0.3; 32 | radiusb 0.15; 33 | com (0 0 0); 34 | } 35 | } 36 | 37 | materials 38 | { 39 | material1 40 | { 41 | name mat1; 42 | type General; 43 | rho 2.0; 44 | } 45 | } 46 | 47 | motions 48 | { 49 | motion1 50 | { 51 | name free1; 52 | type Motion01Mask; 53 | mask b111111; 54 | } 55 | } 56 | 57 | solids 58 | { 59 | solid1 60 | { 61 | shp_name ellipse1; 62 | mot_name free1; 63 | mat_name mat1; 64 | pos (0.5 3.5 0.0); 65 | vel (0.0 0.0 0.0); 66 | euler (0.0 0.0 -45.0); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /examples/falling_ellipse/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 1; 18 | 19 | xmin 0; 20 | xmax 2; 21 | ymin 0; 22 | ymax 4; 23 | nx 100; 24 | ny 200; 25 | 26 | vertices 27 | ( 28 | ($xmin $ymin -0.5) 29 | ($xmax $ymin -0.5) 30 | ($xmax $ymax -0.5) 31 | ($xmin $ymax -0.5) 32 | ($xmin $ymin 0.5) 33 | ($xmax $ymin 0.5) 34 | ($xmax $ymax 0.5) 35 | ($xmin $ymax 0.5) 36 | ); 37 | 38 | blocks 39 | ( 40 | hex (0 1 2 3 4 5 6 7) ($nx $ny 1) simpleGrading (1 1 1) 41 | ); 42 | 43 | edges 44 | ( 45 | ); 46 | 47 | boundary 48 | ( 49 | left { type wall; faces ( (0 4 7 3)); } 50 | right { type wall; faces ( (2 6 5 1)); } 51 | bottom{ type wall; faces ( (1 5 4 0)); } 52 | top { type wall; faces ( (3 7 6 2)); } 53 | front 54 | { 55 | type empty; 56 | faces 57 | ( 58 | (0 3 2 1) 59 | ); 60 | } 61 | back 62 | { 63 | type empty; 64 | faces 65 | ( 66 | (4 5 6 7) 67 | ); 68 | } 69 | ); 70 | 71 | mergePatchPairs 72 | ( 73 | ); 74 | 75 | // ************************************************************************* // 76 | -------------------------------------------------------------------------------- /examples/falling_ellipse/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | application ibm; 18 | 19 | startFrom startTime; 20 | 21 | startTime 0.0; 22 | 23 | stopAt endTime; 24 | 25 | endTime 3; 26 | 27 | deltaT 0.005; 28 | 29 | writeControl runTime; 30 | 31 | writeInterval 0.2; 32 | 33 | purgeWrite 0; 34 | 35 | writeFormat binary; 36 | 37 | writeCompression off; 38 | 39 | timeFormat general; 40 | 41 | timePrecision 6; 42 | 43 | runTimeModifiable false; 44 | adjustTimeStep no; 45 | 46 | -------------------------------------------------------------------------------- /examples/falling_ellipse/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 1.3 | 5 | | \\ / A nd | Web: http://www.openfoam.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | 9 | FoamFile 10 | { 11 | version 2.0; 12 | format ascii; 13 | 14 | root ""; 15 | case ""; 16 | instance ""; 17 | local ""; 18 | 19 | class dictionary; 20 | object decomposeParDict; 21 | } 22 | 23 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 | 25 | 26 | numberOfSubdomains 2; 27 | 28 | method simple; 29 | 30 | simpleCoeffs 31 | { 32 | n (2 1 1); 33 | delta 0.001; 34 | } 35 | 36 | hierarchicalCoeffs 37 | { 38 | n (1 1 1); 39 | delta 0.001; 40 | order xyz; 41 | } 42 | 43 | metisCoeffs 44 | { 45 | processorWeights 46 | ( 47 | 1 48 | 1 49 | 1 50 | ); 51 | } 52 | 53 | manualCoeffs 54 | { 55 | dataFile ""; 56 | } 57 | 58 | distributed no; 59 | 60 | roots 61 | ( 62 | ); 63 | 64 | 65 | // ************************************************************************* // 66 | -------------------------------------------------------------------------------- /examples/falling_ellipse/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | } 27 | 28 | divSchemes 29 | { 30 | default none; 31 | div(Fs) Gauss linear; 32 | div(phi,U) Gauss linear; 33 | div(phi_0,U_0) Gauss linear; 34 | div(phi,T) Gauss vanLeer; 35 | } 36 | 37 | laplacianSchemes 38 | { 39 | default Gauss linear orthogonal; 40 | } 41 | 42 | interpolationSchemes 43 | { 44 | default linear; 45 | } 46 | 47 | snGradSchemes 48 | { 49 | default orthogonal; 50 | } 51 | 52 | fluxRequired 53 | { 54 | default no; 55 | p ; 56 | } 57 | 58 | 59 | // ************************************************************************* // 60 | -------------------------------------------------------------------------------- /examples/falling_ellipse/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 GAMG; 23 | tolerance 1e-06; 24 | relTol 0; 25 | smoother GaussSeidel; 26 | nPreSweeps 0; 27 | nPostSweeps 2; 28 | cacheAgglomeration on; 29 | agglomerator faceAreaPair; 30 | nCellsInCoarsestLevel 10; 31 | mergeLevels 1; 32 | } 33 | 34 | U 35 | { 36 | solver smoothSolver; 37 | smoother symGaussSeidel; 38 | tolerance 1e-06; 39 | relTol 0; 40 | } 41 | T 42 | { 43 | solver smoothSolver; 44 | smoother symGaussSeidel; 45 | tolerance 1e-06; 46 | relTol 0; 47 | } 48 | } 49 | 50 | PISO 51 | { 52 | nCorrectors 1; 53 | nNonOrthogonalCorrectors 0; 54 | pRefCell 0; 55 | pRefValue 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/0/As: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/examples/flow_past_cylinder/re200/0/As -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/0/T: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object T; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 1 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | inlet 24 | { 25 | type fixedValue; 26 | value uniform 0; 27 | } 28 | 29 | outlet 30 | { 31 | type zeroGradient; 32 | } 33 | 34 | side1 {type zeroGradient; } 35 | side2 {type zeroGradient; } 36 | front {type empty;} 37 | back {type empty;} 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 (1 0 0); 20 | 21 | boundaryField 22 | { 23 | inlet 24 | { 25 | type fixedValue; 26 | value uniform (1 0 0); 27 | } 28 | 29 | outlet 30 | { 31 | type zeroGradient; 32 | } 33 | side1 34 | { 35 | type fixedValue; 36 | value uniform (1 0 0); 37 | } 38 | side2 39 | { 40 | type fixedValue; 41 | value uniform (1 0 0); 42 | } 43 | /* side1 { type cyclic; } */ 44 | /* side2 { type cyclic; } */ 45 | front {type empty;} 46 | back {type empty;} 47 | } 48 | 49 | // ************************************************************************* // 50 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | inlet 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | outlet 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | 34 | side1 { type zeroGradient; } 35 | side2 { type zeroGradient; } 36 | front {type empty;} 37 | back {type empty;} 38 | } 39 | 40 | // ************************************************************************* // 41 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 nu [ 0 2 -1 0 0 0 0 ] 0.01; 19 | alpha alpha [ 0 2 -1 0 0 0 0 ] 0.01; 20 | rho rho [ 1 -3 0 0 0 0 0 ] 1.0; 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/solidDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 6.0.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object solids; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | meta 19 | { 20 | on_fluid 1; 21 | on_twod 1; 22 | gravity (0.0 0.0 0.0); 23 | } 24 | 25 | shapes 26 | { 27 | shape1 28 | { 29 | name circle1; 30 | type Circle; 31 | radius 1.0; 32 | } 33 | } 34 | 35 | materials 36 | { 37 | material1 38 | { 39 | name mat1; 40 | type General; 41 | rho 1.0; 42 | rn 0.9; 43 | rt 0.9; 44 | } 45 | } 46 | 47 | motions 48 | { 49 | motion2 50 | { 51 | name static1; 52 | type Motion01Mask; 53 | mask b000000; 54 | } 55 | } 56 | 57 | solids 58 | { 59 | solid1 60 | { 61 | shp_name circle1; 62 | mot_name static1; 63 | mat_name mat1; 64 | pos (0.0 0.0 0.0); 65 | vel (0.0 0.0 0.0); 66 | } 67 | } 68 | 69 | planes {} 70 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*| ========= | | 2 | | \ / F ield | OpenFOAM: The Open Source CFD Toolbox | 3 | | \ / O peration | Version: 2.3.0 | 4 | | \ / A nd | Web: www.OpenFOAM.org | 5 | | \/ M anipulation | | 6 | \*---------------------------------------------------------------------------*/ 7 | FoamFile 8 | { 9 | version 2.0; 10 | format ascii; 11 | class dictionary; 12 | object blockMeshDict; 13 | } 14 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 15 | 16 | vertices 17 | ( 18 | (-32 -64 0.5 ) 19 | (-32 -6 0.5 ) 20 | (-32 6 0.5 ) 21 | (-32 64 0.5 ) 22 | ( -6 -64 0.5 ) 23 | ( -6 -6 0.5 ) 24 | ( -6 6 0.5 ) 25 | ( -6 64 0.5 ) 26 | ( 6 -64 0.5 ) 27 | ( 6 -6 0.5 ) 28 | ( 6 6 0.5 ) 29 | ( 6 64 0.5 ) 30 | ( 96 -64 0.5 ) 31 | ( 96 -6 0.5 ) 32 | ( 96 6 0.5 ) 33 | ( 96 64 0.5 ) 34 | (-32 -64 -0.5 ) 35 | (-32 -6 -0.5 ) 36 | (-32 6 -0.5 ) 37 | (-32 64 -0.5 ) 38 | ( -6 -64 -0.5 ) 39 | ( -6 -6 -0.5 ) 40 | ( -6 6 -0.5 ) 41 | ( -6 64 -0.5 ) 42 | ( 6 -64 -0.5 ) 43 | ( 6 -6 -0.5 ) 44 | ( 6 6 -0.5 ) 45 | ( 6 64 -0.5 ) 46 | ( 96 -64 -0.5 ) 47 | ( 96 -6 -0.5 ) 48 | ( 96 6 -0.5 ) 49 | ( 96 64 -0.5 ) 50 | ); 51 | blocks 52 | ( 53 | /* hex ( 16 20 21 17 0 4 5 1 ) (30 25 1) simpleGrading (0.033 0.05 1) */ 54 | /* hex ( 17 21 22 18 1 5 6 2 ) (30 60 1) simpleGrading (0.033 1 1) */ 55 | /* hex ( 18 22 23 19 2 6 7 3 ) (30 25 1) simpleGrading (0.033 20.0 1) */ 56 | /* hex ( 20 24 25 21 4 8 9 5 ) (60 25 1) simpleGrading (1 0.05 1) */ 57 | /* hex ( 21 25 26 22 5 9 10 6 ) (60 60 1) simpleGrading (1 1 1) */ 58 | /* hex ( 22 26 27 23 6 10 11 7 ) (60 25 1) simpleGrading (1 20.0 1) */ 59 | /* hex ( 24 28 29 25 8 12 13 9 ) (40 25 1) simpleGrading (30. 0.05 1) */ 60 | /* hex ( 25 29 30 26 9 13 14 10 )(40 60 1) simpleGrading (30. 1 1) */ 61 | /* hex ( 26 30 31 27 10 14 15 11)(40 25 1) simpleGrading (30. 20.0 1) */ 62 | 63 | hex ( 16 20 21 17 0 4 5 1 ) ( 40 80 1) simpleGrading (0.05 0.05 1) 64 | hex ( 17 21 22 18 1 5 6 2 ) ( 40 120 1) simpleGrading (0.05 1 1) 65 | hex ( 18 22 23 19 2 6 7 3 ) ( 40 80 1) simpleGrading (0.05 20.0 1) 66 | hex ( 20 24 25 21 4 8 9 5 ) (120 80 1) simpleGrading (1 0.05 1) 67 | hex ( 21 25 26 22 5 9 10 6 ) (120 120 1) simpleGrading (1 1 1) 68 | hex ( 22 26 27 23 6 10 11 7 ) (120 80 1) simpleGrading (1 20.0 1) 69 | hex ( 24 28 29 25 8 12 13 9 ) (120 80 1) simpleGrading (20. 0.05 1) 70 | hex ( 25 29 30 26 9 13 14 10 )(120 120 1) simpleGrading (20. 1 1) 71 | hex ( 26 30 31 27 10 14 15 11)(120 80 1) simpleGrading (20. 20.0 1) 72 | ); 73 | edges(); 74 | 75 | boundary 76 | ( 77 | front 78 | { 79 | type empty; 80 | faces ( 81 | ( 0 4 5 1 ) 82 | ( 1 5 6 2 ) 83 | ( 2 6 7 3 ) 84 | ( 4 8 9 5 ) 85 | ( 5 9 10 6 ) 86 | ( 6 10 11 7 ) 87 | ( 8 12 13 9 ) 88 | ( 9 13 14 10 ) 89 | ( 10 14 15 11 ) 90 | ); 91 | } 92 | back 93 | { 94 | type empty; 95 | faces ( 96 | ( 16 20 21 17 ) 97 | ( 17 21 22 18 ) 98 | ( 18 22 23 19 ) 99 | ( 20 24 25 21 ) 100 | ( 21 25 26 22 ) 101 | ( 22 26 27 23 ) 102 | ( 24 28 29 25 ) 103 | ( 25 29 30 26 ) 104 | ( 26 30 31 27 ) 105 | ); 106 | } 107 | side1 108 | { 109 | /* type cyclic; */ 110 | /* neighbourPatch side2; */ 111 | type wall; 112 | faces ( 113 | ( 16 20 4 0 ) 114 | ( 20 24 8 4 ) 115 | ( 24 28 12 8 ) 116 | ); 117 | } 118 | side2 119 | { 120 | /* type cyclic; */ 121 | /* neighbourPatch side1; */ 122 | type wall; 123 | faces ( 124 | ( 19 23 7 3 ) 125 | ( 23 27 11 7 ) 126 | ( 27 31 15 11 ) 127 | ); 128 | } 129 | outlet 130 | { 131 | type wall; 132 | faces ( 133 | ( 28 29 13 12 ) 134 | ( 29 30 14 13 ) 135 | ( 30 31 15 14 ) 136 | ); 137 | } 138 | inlet 139 | { 140 | type wall; 141 | faces ( 142 | ( 16 17 1 0 ) 143 | ( 17 18 2 1 ) 144 | ( 18 19 3 2 ) 145 | ); 146 | } 147 | ); 148 | mergePatchPairs 149 | ( 150 | ); 151 | 152 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | application sdfibm; 18 | 19 | startFrom startTime; 20 | 21 | startTime 0; 22 | 23 | stopAt endTime; 24 | 25 | endTime 200; 26 | 27 | deltaT 0.01; 28 | 29 | writeControl runTime; 30 | 31 | writeInterval 10; 32 | 33 | purgeWrite 0; 34 | 35 | writeFormat binary; 36 | 37 | writeCompression off; 38 | 39 | timeFormat general; 40 | 41 | timePrecision 6; 42 | 43 | runTimeModifiable false; 44 | adjustTimeStep no; 45 | 46 | functions 47 | { 48 | } 49 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 1.3 | 5 | | \\ / A nd | Web: http://www.openfoam.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | 9 | FoamFile 10 | { 11 | version 2.0; 12 | format ascii; 13 | 14 | root ""; 15 | case ""; 16 | instance ""; 17 | local ""; 18 | 19 | class dictionary; 20 | object decomposeParDict; 21 | } 22 | 23 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 | 25 | 26 | numberOfSubdomains 4; 27 | 28 | method simple; 29 | 30 | simpleCoeffs 31 | { 32 | n (2 2 1); 33 | delta 0.001; 34 | } 35 | 36 | distributed no; 37 | 38 | roots 39 | ( 40 | ); 41 | 42 | 43 | // ************************************************************************* // 44 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | } 27 | 28 | divSchemes 29 | { 30 | default none; 31 | div(Fs) Gauss linear; 32 | div(phi,U) Gauss linear; 33 | div(phi_0,U_0) Gauss linear; 34 | div(phi,T) Gauss vanLeer; 35 | } 36 | 37 | laplacianSchemes 38 | { 39 | default Gauss linear orthogonal; 40 | } 41 | 42 | interpolationSchemes 43 | { 44 | default linear; 45 | } 46 | 47 | snGradSchemes 48 | { 49 | default orthogonal; 50 | } 51 | 52 | fluxRequired 53 | { 54 | default no; 55 | p ; 56 | } 57 | 58 | 59 | // ************************************************************************* // 60 | -------------------------------------------------------------------------------- /examples/flow_past_cylinder/re200/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 GAMG; 23 | tolerance 1e-10; 24 | smoother GaussSeidel; 25 | nPreSweeps 0; 26 | nPostSweeps 2; 27 | cacheAgglomeration on; 28 | agglomerator faceAreaPair; 29 | nCellsInCoarsestLevel 10; 30 | mergeLevels 1; 31 | } 32 | 33 | U 34 | { 35 | solver smoothSolver; 36 | smoother symGaussSeidel; 37 | tolerance 1e-10; 38 | relTol 0; 39 | } 40 | 41 | T 42 | { 43 | solver smoothSolver; 44 | smoother symGaussSeidel; 45 | tolerance 1e-08; 46 | relTol 0; 47 | } 48 | } 49 | 50 | PISO 51 | { 52 | nCorrectors 1; 53 | nNonOrthogonalCorrectors 0; 54 | pRefCell 0; 55 | pRefValue 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/readme: -------------------------------------------------------------------------------- 1 | for some cases, run blockMesh first to create the mesh 2 | -------------------------------------------------------------------------------- /examples/sedimentation/0/T: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format binary; 12 | class volScalarField; 13 | location "0"; 14 | object T; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 0 0 1 0 0 0]; 19 | 20 | internalField uniform 0; 21 | 22 | boundaryField 23 | { 24 | left 25 | { 26 | type fixedValue; 27 | value uniform 0; 28 | } 29 | right 30 | { 31 | type fixedValue; 32 | value uniform 0; 33 | } 34 | bottom 35 | { 36 | type fixedValue; 37 | value uniform 0; 38 | } 39 | top 40 | { 41 | type fixedValue; 42 | value uniform 0; 43 | } 44 | front 45 | { 46 | type empty; 47 | } 48 | back 49 | { 50 | type empty; 51 | } 52 | } 53 | 54 | 55 | // ************************************************************************* // 56 | -------------------------------------------------------------------------------- /examples/sedimentation/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format binary; 12 | class volVectorField; 13 | location "0"; 14 | object U; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 1 -1 0 0 0 0]; 19 | 20 | internalField uniform (0 0 0); 21 | 22 | boundaryField 23 | { 24 | left 25 | { 26 | type fixedValue; 27 | value uniform (0 0 0); 28 | } 29 | right 30 | { 31 | type fixedValue; 32 | value uniform (0 0 0); 33 | } 34 | bottom 35 | { 36 | type fixedValue; 37 | value uniform (0 0 0); 38 | } 39 | top 40 | { 41 | type fixedValue; 42 | value uniform (0 0 0); 43 | } 44 | front 45 | { 46 | type empty; 47 | } 48 | back 49 | { 50 | type empty; 51 | } 52 | } 53 | 54 | 55 | // ************************************************************************* // 56 | -------------------------------------------------------------------------------- /examples/sedimentation/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format binary; 12 | class volScalarField; 13 | location "0"; 14 | object p; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 2 -2 0 0 0 0]; 19 | 20 | internalField uniform 0; 21 | 22 | boundaryField 23 | { 24 | left 25 | { 26 | type zeroGradient; 27 | } 28 | right 29 | { 30 | type zeroGradient; 31 | } 32 | bottom 33 | { 34 | type zeroGradient; 35 | } 36 | top 37 | { 38 | type zeroGradient; 39 | } 40 | front 41 | { 42 | type empty; 43 | } 44 | back 45 | { 46 | type empty; 47 | } 48 | } 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /examples/sedimentation/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 nu [ 0 2 -1 0 0 0 0 ] 0.01; 19 | alpha alpha [ 0 2 -1 0 0 0 0 ] 0.001; 20 | rho rho [ 1 -3 0 0 0 0 0 ] 1.0; 21 | -------------------------------------------------------------------------------- /examples/sedimentation/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 1; 18 | 19 | vertices 20 | ( 21 | (-4 0 -0.5) 22 | ( 4 0 -0.5) 23 | ( 4 8 -0.5) 24 | (-4 8 -0.5) 25 | (-4 0 0.5) 26 | ( 4 0 0.5) 27 | ( 4 8 0.5) 28 | (-4 8 0.5) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (400 400 1) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | left { type wall; faces ( (0 4 7 3)); } 43 | right { type wall; faces ( (2 6 5 1)); } 44 | bottom{ type wall; faces ( (1 5 4 0)); } 45 | top { type wall; faces ( (3 7 6 2)); } 46 | front 47 | { 48 | type empty; 49 | faces 50 | ( 51 | (0 3 2 1) 52 | ); 53 | } 54 | back 55 | { 56 | type empty; 57 | faces 58 | ( 59 | (4 5 6 7) 60 | ); 61 | } 62 | ); 63 | 64 | mergePatchPairs 65 | ( 66 | ); 67 | 68 | // ************************************************************************* // 69 | -------------------------------------------------------------------------------- /examples/sedimentation/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | application ibm; 18 | 19 | startFrom startTime; 20 | 21 | startTime 0; 22 | 23 | stopAt endTime; 24 | 25 | endTime 6; 26 | 27 | deltaT 0.0005; 28 | 29 | writeControl runTime; 30 | 31 | writeInterval 0.1; 32 | 33 | purgeWrite 0; 34 | 35 | writeFormat binary; 36 | 37 | writePrecision 6; 38 | 39 | writeCompression off; 40 | 41 | timeFormat general; 42 | 43 | timePrecision 6; 44 | 45 | runTimeModifiable true; 46 | adjustTimeStep no; 47 | 48 | -------------------------------------------------------------------------------- /examples/sedimentation/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 3.0.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | note "mesh decomposition control dictionary"; 14 | object decomposeParDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | numberOfSubdomains 8; 19 | 20 | method simple; 21 | 22 | simpleCoeffs 23 | { 24 | n (2 4 1); 25 | delta 0.001; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/sedimentation/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | } 27 | 28 | divSchemes 29 | { 30 | default Gauss linear; 31 | div(Fs) Gauss linear; 32 | div(phi,U) Gauss linear; 33 | div(phi_0,U_0) Gauss linear; 34 | div(phi,T) Gauss vanLeer; 35 | } 36 | 37 | laplacianSchemes 38 | { 39 | default Gauss linear orthogonal; 40 | } 41 | 42 | interpolationSchemes 43 | { 44 | default linear; 45 | } 46 | 47 | snGradSchemes 48 | { 49 | default orthogonal; 50 | } 51 | 52 | fluxRequired 53 | { 54 | default no; 55 | p ; 56 | } 57 | 58 | 59 | // ************************************************************************* // 60 | -------------------------------------------------------------------------------- /examples/sedimentation/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 GAMG; 23 | tolerance 1e-06; 24 | relTol 0; 25 | smoother GaussSeidel; 26 | nPreSweeps 0; 27 | nPostSweeps 2; 28 | cacheAgglomeration on; 29 | agglomerator faceAreaPair; 30 | nCellsInCoarsestLevel 10; 31 | mergeLevels 1; 32 | } 33 | 34 | U 35 | { 36 | solver smoothSolver; 37 | smoother symGaussSeidel; 38 | tolerance 1e-06; 39 | relTol 0; 40 | } 41 | T 42 | { 43 | solver smoothSolver; 44 | smoother symGaussSeidel; 45 | tolerance 1e-06; 46 | relTol 0; 47 | } 48 | } 49 | 50 | PISO 51 | { 52 | nCorrectors 1; 53 | nNonOrthogonalCorrectors 0; 54 | pRefCell 0; 55 | pRefValue 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/sedimentation/system/refineMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.2.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object refineMeshDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | // Cells to refine; name of 'cellSet' 19 | set refine; 20 | 21 | // Type of coordinate system: 22 | // - global : coordinate system same for every cell. Usually aligned with 23 | // x,y,z axis. Specify in globalCoeffs section below. 24 | // - patchLocal : coordinate system different for every cell. Specify in 25 | // patchLocalCoeffs section below. 26 | coordinateSystem global; 27 | 28 | // Specifies 2 directions by a name and a vector. The normal direction is 29 | // calculated as tan1^tan2 30 | globalCoeffs 31 | { 32 | tan1 ( 1 0 0 ); 33 | tan2 ( 0 1 0 ); 34 | } 35 | 36 | patchLocalCoeffs 37 | { 38 | // Normal direction is face normal of zero'th face of patch 39 | patch outside; 40 | tan1 ( 1 0 0 ); 41 | tan2 ( 0 0 1 ); 42 | } 43 | 44 | // Specifies the direction to be refined by the name used above 45 | // To refine in the third direction, use the keyword 'normal' 46 | directions 47 | ( 48 | tan1 49 | tan2 50 | ); 51 | 52 | // Whether to use hex topology. This will 53 | // - if patchLocal: all cells on selected patch should be hex 54 | // - split all hexes in 2x2x2 through the middle of edges. 55 | useHexTopology yes; 56 | 57 | // Cut purely geometric (will cut hexes through vertices) or take 58 | // topology into account. Incompatible with 'useHexTopology' 59 | geometricCut no; 60 | 61 | // Write meshes from intermediate steps 62 | writeMesh no; 63 | -------------------------------------------------------------------------------- /examples/taylor_couette/0/T: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 3.0.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | location "0"; 14 | object T; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 0 0 1 0 0 0]; 19 | 20 | internalField uniform 0; 21 | 22 | boundaryField 23 | { 24 | "(Top|Btm)" 25 | { 26 | type empty; 27 | } 28 | Cyl { type zeroGradient; } 29 | } 30 | 31 | 32 | // ************************************************************************* // 33 | -------------------------------------------------------------------------------- /examples/taylor_couette/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 3.0.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | location "0"; 14 | object U; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 1 -1 0 0 0 0]; 19 | 20 | internalField uniform (0 0 0); 21 | 22 | boundaryField 23 | { 24 | "(Top|Btm)" 25 | { 26 | type empty; 27 | } 28 | Cyl 29 | { 30 | type rotatingWallVelocity; 31 | origin (0 0 0); 32 | axis (0 0 1); 33 | omega 6.28; 34 | } 35 | } 36 | 37 | 38 | // ************************************************************************* // 39 | -------------------------------------------------------------------------------- /examples/taylor_couette/0/p: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 3.0.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | location "0"; 14 | object p; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 2 -2 0 0 0 0]; 19 | 20 | internalField uniform 0; 21 | 22 | boundaryField 23 | { 24 | "(Top|Btm)" 25 | { type empty; } 26 | Cyl { type zeroGradient; } 27 | } 28 | 29 | 30 | // ************************************************************************* // 31 | -------------------------------------------------------------------------------- /examples/taylor_couette/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.1.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 nu [ 0 2 -1 0 0 0 0 ] 0.1; 19 | rho rho [ 0 0 -1 0 0 0 0 ] 1; 20 | alpha alpha [ 0 2 -1 0 0 0 0 ] 0.1; 21 | 22 | 23 | // ************************************************************************* // 24 | -------------------------------------------------------------------------------- /examples/taylor_couette/fdm.m: -------------------------------------------------------------------------------- 1 | ri = 0.3; % inner radius, ri must < 1 2 | ro = 1.0; % outer radius 3 | nr = 31; % radial resolution 4 | 5 | U0 = 2*pi; % outer wall velocity 6 | nu = 0.1; % kinematic viscosity 7 | 8 | rhof = 1.0; % fluid density 9 | rhos = 2.0; % core solid density 10 | 11 | r = linspace(ri, 1, nr); % space axis 12 | t = linspace(0, 6, 1201);% time axix 13 | dt = t(2) - t(1); 14 | dr = r(2) - r(1); 15 | 16 | % initial condition of flow field 17 | u = 0*r; 18 | 19 | beta = 0.0; % core wall speed 20 | beta_ts = t*0; % time series of core wall speed 21 | beta_ts(1) = 0.0; % initial speed of core wall 22 | 23 | % time loop 24 | for n = 2:length(t) 25 | dudr = [(-3*u(1)+4*u(2)-u(3)) (u(3:nr) - u(1:nr-2)) (3*u(nr)-4*u(nr-1)+u(nr-2))]/(2*dr); 26 | 27 | rdudr = r.*dudr; 28 | 29 | rdudrdr = [(-3*rdudr(1)+4*rdudr(2)-rdudr(3)) (rdudr(3:nr) - rdudr(1:nr-2)) (3*rdudr(nr)-4*rdudr(nr-1)+rdudr(nr-2))]/(2*dr); 30 | 31 | rhs = nu * (rdudrdr./r); 32 | 33 | % semi-implicit time update 34 | un = (u./dt + rhs)./(1/dt + nu./(r.^2)); 35 | 36 | % now it's time to update beta, simplest Euler forward step 37 | % mind the evaluation of the wall shear stress, the -u(1)/ri was missed 38 | % previously 39 | dudr0 = ( (-3*u(1)+4*u(2)-u(3))/(2*dr)) - u(1)/ri; 40 | beta = beta + 4.0*rhof/rhos*nu/ri*dudr0 * dt; 41 | beta_ts(n) = beta; 42 | 43 | % set boundary condition 44 | un(1) = beta; 45 | un(nr)= U0; 46 | 47 | % update time 48 | u = un; 49 | end 50 | 51 | %% validation of steady-state (outer speed = 1, inner speed = 0) 52 | % beta = 0 ; 53 | % A = ri*(ri-beta)/(ri*ri-1); 54 | % B = (ri*beta-1)/(ri*ri-1); 55 | % plot(r, u,'ro', r, A./r + B*r, 'k-') 56 | 57 | %% validation of steady-state (outer speed = 1, du/dr = 0 at core) 58 | % A = U0*ri*ri/(1+ri*ri); 59 | % B = U0/(1+ri*ri); 60 | % plot(r, u, 'ro', r, A./r + B*r, 'k-') 61 | %% plot against openfoam 62 | foam = load('./cloud.out'); 63 | exact = U0; % t->infty state 64 | % 65 | clf 66 | hold on 67 | plot(t(1:40:end), beta_ts(1:40:end)/ri/(2*pi), 'ko') 68 | plot(foam(:,1), foam(:,16)/(2*pi), 'k-') 69 | plot([0, t(end)], [exact, exact]/(2*pi), 'k--') 70 | hold off 71 | xlim([0 6]) 72 | ylim([0 1.1]) 73 | xlabel('t') 74 | ylabel('\omega_{i}') 75 | legend('finite difference', 'immersed boundary', '\omega_o = 1') -------------------------------------------------------------------------------- /examples/taylor_couette/solidDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 6.0.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object solids; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | meta 19 | { 20 | on_fluid 1; 21 | on_twod 1; 22 | gravity (0.0 0.0 0.0); 23 | } 24 | 25 | shapes 26 | { 27 | shape1 28 | { 29 | name circle1; 30 | type Circle; 31 | radius 0.3; 32 | } 33 | } 34 | 35 | materials 36 | { 37 | material1 38 | { 39 | name mat1; 40 | type General; 41 | rho 2.0; 42 | } 43 | } 44 | 45 | motions 46 | { 47 | motion1 48 | { 49 | name onlyzrot1; 50 | type Motion01Mask; 51 | mask b000001; 52 | } 53 | } 54 | 55 | solids 56 | { 57 | solid1 58 | { 59 | shp_name circle1; 60 | mot_name onlyzrot1; 61 | mat_name mat1; 62 | pos (0.0 0.0 0.0); 63 | vel (0.0 0.0 0.0); 64 | euler (0.0 0.0 0.0); 65 | } 66 | } 67 | 68 | planes {} 69 | -------------------------------------------------------------------------------- /examples/taylor_couette/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.1.1 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 1.0; 18 | 19 | vertices 20 | ( 21 | (0.5 0 -0.5) 22 | (0 -0.5 -0.5) 23 | (-0.5 0 -0.5) 24 | (0 0.5 -0.5) 25 | (1 0 -0.5) 26 | (0 -1 -0.5) 27 | (-1 0 -0.5) 28 | (0 1 -0.5) 29 | 30 | (0.5 0 0.5) 31 | (0 -0.5 0.5) 32 | (-0.5 0 0.5) 33 | (0 0.5 0.5) 34 | (1 0 0.5) 35 | (0 -1 0.5) 36 | (-1 0 0.5) 37 | (0 1 0.5) 38 | ); 39 | 40 | 41 | blocks 42 | ( 43 | hex (8 9 10 11 0 1 2 3) (50 50 1) simpleGrading (1 1 1) 44 | hex (8 12 13 9 0 4 5 1) (50 50 1) simpleGrading (1 1 1) 45 | hex (9 13 14 10 1 5 6 2) (50 50 1) simpleGrading (1 1 1) 46 | hex (10 14 15 11 2 6 7 3) (50 50 1) simpleGrading (1 1 1) 47 | hex (11 15 12 8 3 7 4 0) (50 50 1) simpleGrading (1 1 1) 48 | ); 49 | 50 | edges 51 | ( 52 | arc 4 5 (0.707 -0.707 -0.5) 53 | arc 5 6 (-0.707 -0.707 -0.5) 54 | arc 6 7 (-0.707 0.707 -0.5) 55 | arc 7 4 (0.707 0.707 -0.5) 56 | arc 12 13 (0.707 -0.707 0.5) 57 | arc 13 14 (-0.707 -0.707 0.5) 58 | arc 14 15 (-0.707 0.707 0.5) 59 | arc 15 12 (0.707 0.707 0.5) 60 | ); 61 | 62 | boundary 63 | ( 64 | Top 65 | { 66 | type empty; 67 | faces 68 | ( 69 | (8 11 10 9) 70 | (8 9 13 12) 71 | (9 10 14 13) 72 | (10 11 15 14) 73 | (11 8 12 15) 74 | ); 75 | } 76 | Btm 77 | { 78 | type empty; 79 | faces 80 | ( 81 | (0 1 2 3) 82 | (0 4 5 1) 83 | (1 5 6 2) 84 | (2 6 7 3) 85 | (3 7 4 0) 86 | ); 87 | } 88 | Cyl 89 | { 90 | type wall; 91 | faces 92 | ( 93 | (4 12 13 5) 94 | (5 13 14 6) 95 | (6 14 15 7) 96 | (7 15 12 4) 97 | ); 98 | } 99 | ); 100 | 101 | mergePatchPairs 102 | ( 103 | ); 104 | 105 | // ************************************************************************* // 106 | -------------------------------------------------------------------------------- /examples/taylor_couette/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | application sdfibm; 18 | 19 | startFrom startTime; 20 | 21 | startTime 0.0; 22 | 23 | stopAt endTime; 24 | 25 | endTime 6; 26 | 27 | deltaT 0.001; 28 | 29 | writeControl runTime; 30 | 31 | writeInterval 1; 32 | 33 | purgeWrite 0; 34 | 35 | writeFormat binary; 36 | 37 | writePrecision 6; 38 | 39 | writeCompression off; 40 | 41 | timeFormat general; 42 | 43 | timePrecision 6; 44 | 45 | runTimeModifiable true; 46 | adjustTimeStep no; 47 | 48 | -------------------------------------------------------------------------------- /examples/taylor_couette/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 1.3 | 5 | | \\ / A nd | Web: http://www.openfoam.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | 9 | FoamFile 10 | { 11 | version 2.0; 12 | format ascii; 13 | 14 | root ""; 15 | case ""; 16 | instance ""; 17 | local ""; 18 | 19 | class dictionary; 20 | object decomposeParDict; 21 | } 22 | 23 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 | 25 | 26 | numberOfSubdomains 6; 27 | 28 | method simple; 29 | 30 | simpleCoeffs 31 | { 32 | n (2 3 1); 33 | delta 0.001; 34 | } 35 | 36 | hierarchicalCoeffs 37 | { 38 | n (1 1 1); 39 | delta 0.001; 40 | order xyz; 41 | } 42 | 43 | metisCoeffs 44 | { 45 | processorWeights 46 | ( 47 | 1 48 | 1 49 | 1 50 | ); 51 | } 52 | 53 | manualCoeffs 54 | { 55 | dataFile ""; 56 | } 57 | 58 | distributed no; 59 | 60 | roots 61 | ( 62 | ); 63 | 64 | 65 | // ************************************************************************* // 66 | -------------------------------------------------------------------------------- /examples/taylor_couette/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 | } 27 | 28 | divSchemes 29 | { 30 | default none; 31 | div(Fs) Gauss linear; 32 | div(phi,U) Gauss linear; 33 | div(phi_0,U_0) Gauss linear; 34 | div(phi,T) Gauss vanLeer; 35 | } 36 | 37 | laplacianSchemes 38 | { 39 | default Gauss linear corrected; 40 | } 41 | 42 | interpolationSchemes 43 | { 44 | default linear; 45 | } 46 | 47 | snGradSchemes 48 | { 49 | default corrected; 50 | } 51 | 52 | fluxRequired 53 | { 54 | default no; 55 | p ; 56 | } 57 | 58 | 59 | // ************************************************************************* // 60 | -------------------------------------------------------------------------------- /examples/taylor_couette/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 GAMG; 23 | tolerance 1e-08; 24 | smoother GaussSeidel; 25 | nPreSweeps 0; 26 | nPostSweeps 2; 27 | cacheAgglomeration on; 28 | agglomerator faceAreaPair; 29 | nCellsInCoarsestLevel 10; 30 | mergeLevels 1; 31 | } 32 | 33 | U 34 | { 35 | solver smoothSolver; 36 | smoother symGaussSeidel; 37 | tolerance 1e-08; 38 | relTol 0; 39 | } 40 | T 41 | { 42 | solver smoothSolver; 43 | smoother symGaussSeidel; 44 | tolerance 1e-07; 45 | relTol 0; 46 | } 47 | } 48 | 49 | PISO 50 | { 51 | nCorrectors 1; 52 | nNonOrthogonalCorrectors 0; 53 | pRefCell 0; 54 | pRefValue 0; 55 | } 56 | -------------------------------------------------------------------------------- /figs/ani_T.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/ani_T.gif -------------------------------------------------------------------------------- /figs/flow_past_cylinder_re200.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/flow_past_cylinder_re200.gif -------------------------------------------------------------------------------- /figs/init_on_poly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/init_on_poly.png -------------------------------------------------------------------------------- /figs/planes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/planes.png -------------------------------------------------------------------------------- /figs/smooth_vs_rough.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/smooth_vs_rough.gif -------------------------------------------------------------------------------- /figs/vof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/vof.png -------------------------------------------------------------------------------- /figs/vof_ani.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/figs/vof_ani.gif -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(libshape) 2 | add_subdirectory(libmotion) 3 | add_subdirectory(libforcer) 4 | add_subdirectory(libmaterial) 5 | add_subdirectory(libcollision) 6 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 7 | add_subdirectory(test) 8 | endif() 9 | 10 | add_library(sdfibm_util STATIC cellenumerator.cpp geometrictools.cpp meshinfo.cpp) 11 | target_include_directories(sdfibm_util PUBLIC ${FOAMINC}) 12 | target_link_libraries(sdfibm_util PUBLIC m) 13 | 14 | add_executable(${PROJECT_NAME} main.cpp logger.cpp solid.cpp solidcloud.cpp) 15 | add_definitions(${FOAMFLAG}) 16 | 17 | target_include_directories(${PROJECT_NAME} PUBLIC $FOAMINC) 18 | target_link_libraries(${PROJECT_NAME} PUBLIC 19 | OpenFOAM finiteVolume meshTools Pstream 20 | dl m motion shape collision sdfibm_util) 21 | 22 | -------------------------------------------------------------------------------- /src/cellenumerator.cpp: -------------------------------------------------------------------------------- 1 | #include "cellenumerator.h" 2 | #include "solid.h" 3 | 4 | namespace sdfibm { 5 | 6 | void CellEnumerator::_next() 7 | { 8 | int icur = m_queue.front(); 9 | forAll(m_c2c[icur], _) 10 | { 11 | label inb = m_c2c[icur][_]; 12 | if (m_ct[inb] == CELL_TYPE::UNVISITED) // unvisited 13 | { 14 | int n_v_inside = CountVertexInside(inb, pred_); 15 | 16 | if (n_v_inside==0) 17 | { 18 | m_ct[inb] = CELL_TYPE::ALL_OUTSIDE; 19 | is_[m_ct[inb]].insert(inb); 20 | continue; 21 | } 22 | 23 | // at this point the cell is both unvisited and intersected 24 | m_queue.push(inb); 25 | if (n_v_inside == m_c2p[icur].size()) 26 | m_ct[inb] = CELL_TYPE::ALL_INSIDE; 27 | else if (pred_(m_cc[inb])) 28 | m_ct[inb] = CELL_TYPE::CENTER_INSIDE; 29 | else 30 | m_ct[inb] = CELL_TYPE::CENTER_OUTSIDE; 31 | is_[m_ct[inb]].insert(inb); 32 | } 33 | } 34 | } 35 | 36 | int CellEnumerator::CountVertexInside(int icell, const Predicate& p) const 37 | { 38 | int n_v_inside = 0; 39 | forAll(m_c2p[icell], _) 40 | { 41 | int nodeid = m_c2p[icell][_]; 42 | n_v_inside += p(m_pp[nodeid]); 43 | } 44 | return n_v_inside; 45 | } 46 | 47 | CellEnumerator::CellEnumerator(const Foam::fvMesh& mesh, const Predicate& pred, int seed) : 48 | MeshInfo(mesh), 49 | m_ct(mesh.nCells(), CELL_TYPE::UNVISITED), 50 | pred_(pred) 51 | { 52 | if (CountVertexInside(seed, pred_) == 0) 53 | { 54 | seed = -1; 55 | forAll(m_cc, icell) 56 | { 57 | if (CountVertexInside(icell, pred_) > 0) 58 | { 59 | seed = icell; 60 | break; 61 | } 62 | } 63 | } 64 | 65 | if (seed >= 0) 66 | { 67 | m_queue.push(seed); 68 | 69 | if (CountVertexInside(seed, pred_) == m_c2p[seed].size()) 70 | m_ct[seed] = CELL_TYPE::ALL_INSIDE; 71 | else 72 | if (pred_(m_cc[seed])) 73 | m_ct[seed] = CELL_TYPE::CENTER_INSIDE; 74 | else 75 | m_ct[seed] = CELL_TYPE::CENTER_OUTSIDE; 76 | is_[m_ct[seed]].insert(seed); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/cellenumerator.h: -------------------------------------------------------------------------------- 1 | #ifndef CELLENUMERATOR_H 2 | #define CELLENUMERATOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "meshinfo.h" 12 | #include "meshSearch.H" 13 | #include "types.h" 14 | 15 | // [08-27-2020] Thanks to Mr. Haorang Wang for the idea of using an enumerator class, and for 16 | // the code from which the currently class is adapted. 17 | 18 | namespace sdfibm { 19 | 20 | class CellEnumerator : public MeshInfo 21 | { 22 | public: 23 | enum CELL_TYPE {UNVISITED, ALL_INSIDE, CENTER_INSIDE, CENTER_OUTSIDE, ALL_OUTSIDE}; 24 | using Predicate = std::function; 25 | using IntersectionSet = std::unordered_map>; 26 | private: 27 | std::vector m_ct; // cell type, size = #mesh cell 28 | Predicate pred_; 29 | IntersectionSet is_; 30 | 31 | std::queue m_queue; 32 | 33 | void _next(); 34 | 35 | int CountVertexInside(int icell, const Predicate& p) const; 36 | 37 | public: 38 | CellEnumerator(const Foam::fvMesh& mesh, const Predicate& pred, int seed = -1); // TODO, use optional 39 | ~CellEnumerator() = default; 40 | 41 | inline void Next() 42 | { 43 | _next(); 44 | m_queue.pop(); 45 | } 46 | 47 | const IntersectionSet& intersect() 48 | { 49 | while(!Empty()) 50 | Next(); 51 | return is_; 52 | } 53 | 54 | inline int GetCurCellInd() const 55 | { 56 | return m_queue.front(); 57 | } 58 | 59 | inline CELL_TYPE GetCurCellType() const 60 | { 61 | return m_ct[m_queue.front()]; 62 | } 63 | 64 | inline bool Empty() const 65 | { 66 | return m_queue.empty(); 67 | } 68 | }; 69 | 70 | } 71 | #endif // CELLENUMERATOR_H 72 | -------------------------------------------------------------------------------- /src/createFields.h: -------------------------------------------------------------------------------- 1 | using namespace Foam; 2 | 3 | volScalarField p(IOobject("p", runTime.name(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh); 4 | volVectorField U(IOobject("U", runTime.name(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh); 5 | surfaceScalarField phi(IOobject("phi", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), 6 | linearInterpolate(U) & mesh.Sf()); 7 | label pRefCell = 0; 8 | scalar pRefValue = 0; 9 | setRefCell(p, mesh.solution().dict().subDict("PISO"), pRefCell, pRefValue); 10 | 11 | IOdictionary transportProperties( 12 | IOobject("transportProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)); 13 | dimensionedScalar nu(transportProperties.lookup("nu")); 14 | 15 | // sdfibm related 16 | dimensionedScalar rho(transportProperties.lookup("rho")); 17 | dimensionedScalar alpha(transportProperties.lookup("alpha")); 18 | 19 | volScalarField As(IOobject("As", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), 20 | mesh, 21 | dimensionedScalar("As", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0), 22 | "zeroGradient"); 23 | 24 | volScalarField Ct(IOobject("Ct", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), 25 | mesh, 26 | dimensionedScalar("Ct", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0), 27 | "zeroGradient"); 28 | volVectorField Fs(IOobject("Fs", runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), 29 | mesh, 30 | dimensionedVector("Fs", dimAcceleration, vector::zero), 31 | "fixedValue"); 32 | volScalarField T(IOobject("T", runTime.name(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh); 33 | volScalarField Ts(IOobject("Ts", runTime.name(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), 34 | mesh, 35 | dimensionedScalar("NULL", dimensionSet(0, 0, 0, 1, 0, 0, 0), 0.0)); 36 | -------------------------------------------------------------------------------- /src/entitylibrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "types.h" 5 | #include "genericfactory.h" 6 | 7 | namespace sdfibm 8 | { 9 | template 10 | class EntityLibrary : public std::unordered_map> 11 | { 12 | public: 13 | EntityLibrary() = default; 14 | EntityLibrary(const dictionary& def) 15 | { 16 | for (int i=0; i < def.size(); ++i) 17 | { 18 | const dictionary& def_ = def.subDict(def.toc()[i]); 19 | std::string type = Foam::word(def_.lookup("type")); 20 | std::string name = Foam::word(def_.lookup("name")); 21 | 22 | this->emplace(name, std::move(GenericFactory::create(type, def_))); 23 | } 24 | } 25 | 26 | friend std::ostream& operator<<(std::ostream& os, const EntityLibrary& lib) 27 | { 28 | os << "Objects in the library:\n"; 29 | int i = 1; 30 | for (const auto& [key, value] : lib) 31 | { 32 | (void) value; 33 | os << '[' << i++ << "] " << key << std::endl; 34 | } 35 | return os; 36 | } 37 | }; 38 | } -------------------------------------------------------------------------------- /src/genericfactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace sdfibm { 9 | 10 | template 11 | class GenericFactory 12 | { 13 | public: 14 | using Creator = std::function(const ParaType&)>; 15 | using CreatorMap = std::unordered_map; 16 | 17 | public: 18 | static bool add(const std::string& name, Creator fn) 19 | { 20 | auto it = creators_.find(name); 21 | if(it == creators_.end()) 22 | { 23 | creators_[name] = fn; 24 | return true; 25 | } 26 | return false; 27 | } 28 | 29 | static std::unique_ptr create(const std::string& name, const ParaType& para) 30 | { 31 | auto it = creators_.find(name); 32 | if(it != creators_.end()) 33 | { 34 | return it->second(para); 35 | } 36 | else 37 | { 38 | throw std::runtime_error(std::string("Cannot create unrecognized object: " + name + '\n')); 39 | } 40 | } 41 | 42 | static void report(std::ostream& os = std::cout) 43 | { 44 | os << "Objects the factory can \"produce\":\n"; 45 | int i = 1; 46 | for(const auto& it : creators_) 47 | { 48 | os << '[' << i++ << "] " << it.first << std::endl; 49 | } 50 | } 51 | 52 | friend std::ostream& operator<<(std::ostream& os, const GenericFactory& factory) 53 | { 54 | factory.report(os); 55 | return os; 56 | } 57 | 58 | private: 59 | static CreatorMap creators_; 60 | };; 61 | 62 | #define MAKESPECIALFACTORY(type, basetype, paratype) \ 63 | using type##Factory = GenericFactory; \ 64 | template<> \ 65 | type##Factory::CreatorMap type##Factory::creators_ = {}; 66 | } 67 | -------------------------------------------------------------------------------- /src/geometrictools.cpp: -------------------------------------------------------------------------------- 1 | #include "geometrictools.h" 2 | #include "solid.h" 3 | 4 | namespace sdfibm { 5 | 6 | scalar GeometricTools::UpdateCache(label vertexInd, const Solid& solid) 7 | { 8 | if (phiCache.find(vertexInd) == phiCache.end()) 9 | phiCache[vertexInd] = solid.phi(m_pp[vertexInd]); 10 | return phiCache[vertexInd]; 11 | } 12 | 13 | scalar GeometricTools::calcLineFraction(const scalar& phia, const scalar& phib) const 14 | { 15 | if (phia > 0 && phib > 0) 16 | return 0; 17 | if (phia <= 0 && phib <= 0) 18 | return 1; 19 | if (phia > 0) // phib < 0 20 | return -phib/(phia-phib); 21 | else 22 | return -phia/(phib-phia); 23 | } 24 | 25 | vector GeometricTools::calcApex(const Foam::labelList& vertexInds, CacheMap& phis) const 26 | { 27 | label nvertex = vertexInds.size(); // #face vertex 28 | 29 | const vector& A = m_pp[vertexInds[0]]; 30 | scalar phiA = phis[vertexInds[0]]; 31 | 32 | vector B = vector::zero; 33 | scalar phiB = 0.0; 34 | label i; 35 | for (i = 1; i < nvertex; ++i) 36 | { 37 | B = m_pp[vertexInds[i]]; 38 | phiB = phis[vertexInds[i]]; 39 | 40 | if (phiA * phiB <= 0) 41 | break; 42 | } 43 | 44 | return A - std::abs(phiA)/(SMALL + std::fabs(phiA)+std::fabs(phiB))*(A-B); 45 | } 46 | 47 | scalar GeometricTools::calcCellVolume(label cellInd, const Solid& solid, bool isTWOD = false) 48 | { 49 | const Foam::labelList& vertexInds = m_c2p[cellInd]; 50 | // prepare cell's vertex phi 51 | forAll(vertexInds, ivertex) 52 | { 53 | UpdateCache(vertexInds[ivertex], solid); 54 | } 55 | 56 | vector apex = calcApex(vertexInds, phiCache); 57 | if (isTWOD) 58 | apex[2] = 0.0; 59 | 60 | scalar volume = 0.0; 61 | const Foam::cell& faceInds = m_mesh.cells()[cellInd]; // cell is a labelList of faces 62 | forAll(faceInds, iface) 63 | { 64 | // visit each cell face (face is labelList) 65 | label faceInd = faceInds[iface]; 66 | Foam::face myface = m_mesh.faces()[faceInd]; 67 | Foam::scalar eps_f = calcFaceAreaFraction(myface, phiCache, faceInd); 68 | 69 | volume += (1.0/3.0)*eps_f*std::fabs((apex - m_fc[faceInd]) & m_fa[faceInd]); 70 | } 71 | return volume; 72 | } 73 | 74 | scalar GeometricTools::calcFaceArea(const Foam::face& vertexInds, CacheMap& phis) 75 | { 76 | label nvertex = vertexInds.size(); // #face vertex 77 | 78 | vector apex = calcApex(vertexInds, phis); 79 | 80 | std::vector phiarr(nvertex); 81 | forAll(vertexInds, ivertex) 82 | { 83 | phiarr[ivertex] = phis[vertexInds[ivertex]]; 84 | } 85 | 86 | scalar area = 0.0; 87 | for (int iseg = 0; iseg < nvertex; ++iseg) 88 | { 89 | const scalar& phiO = phiarr[iseg]; 90 | const scalar& phiA = phiarr[(iseg+1)%nvertex]; 91 | const vector& O = m_pp[vertexInds[iseg]]; 92 | const vector& A = m_pp[vertexInds[(iseg+1)%nvertex]]; 93 | area += std::fabs(0.5*Foam::mag((A-O) ^ (apex-O))) * calcLineFraction(phiO, phiA); 94 | } 95 | return area; 96 | } 97 | 98 | scalar GeometricTools::calcFaceAreaFraction(const Foam::face& vertexInds, CacheMap& phis, label faceInd) 99 | { 100 | label nvertex = vertexInds.size(); 101 | int sign_sum = 0; 102 | forAll(vertexInds, ivertex) 103 | { 104 | if (phis[vertexInds[ivertex]] > 0) 105 | ++sign_sum; 106 | else 107 | --sign_sum; 108 | } 109 | 110 | if (sign_sum == nvertex) // ALL_OUT 111 | return 0.0; 112 | if (sign_sum ==-nvertex) // ALL_IN 113 | return 1.0; 114 | 115 | return calcFaceArea(vertexInds, phis)/Foam::mag(m_fa[faceInd]); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/geometrictools.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOMETRICTOOLS_H 2 | #define GEOMETRICTOOLS_H 3 | 4 | #include 5 | #include 6 | #include "meshinfo.h" 7 | #include "types.h" 8 | 9 | namespace sdfibm { 10 | 11 | class Solid; 12 | 13 | class GeometricTools : public MeshInfo 14 | { 15 | typedef std::unordered_map CacheMap; // vertexInd-phi 16 | public: 17 | GeometricTools(const Foam::fvMesh& mesh) : MeshInfo(mesh) {} 18 | 19 | scalar UpdateCache(label vertexInd, const Solid& solid); 20 | 21 | vector calcApex(const Foam::labelList& vertexInds, CacheMap& phis) const; 22 | scalar calcFaceArea(const Foam::face& vertexInds, CacheMap& phis); 23 | scalar calcLineFraction(const scalar& phia, const scalar& phib) const; 24 | scalar calcFaceAreaFraction(const Foam::face& vertexInds, CacheMap& phis, label faceInd); 25 | scalar calcCellVolume(label cellInd, const Solid& solid, bool isTWOD); 26 | inline void clearCache() {phiCache.clear();} 27 | private: 28 | CacheMap phiCache; 29 | }; 30 | 31 | } 32 | #endif // GEOMETRICTOOLS_H 33 | -------------------------------------------------------------------------------- /src/libcollision/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(libName collision) 2 | 3 | set(libSrc 4 | ugrid.cpp 5 | collision.cpp 6 | ) 7 | 8 | set(libInc 9 | bbox.h 10 | ugrid.h 11 | collision.h 12 | ) 13 | 14 | add_library( 15 | ${libName} 16 | STATIC 17 | ${libSrc} 18 | ${libInc} 19 | ) 20 | 21 | add_definitions(${FOAMFLAG}) 22 | target_include_directories(${libName} PUBLIC ${FOAMINC}) 23 | target_link_libraries(${libName} PUBLIC m) 24 | -------------------------------------------------------------------------------- /src/libcollision/bbox.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDINGBOX_HPP 2 | #define BOUNDINGBOX_HPP 3 | 4 | #include 5 | 6 | namespace sdfibm { 7 | struct BBox 8 | { 9 | double low[3], high[3]; 10 | 11 | BBox(){}; 12 | BBox(const double* low_in, const double* high_in) 13 | { 14 | for(int i = 0; i < 3; ++i) { 15 | low[i] = low_in[i]; 16 | high[i] = high_in[i]; 17 | } 18 | } 19 | 20 | void report(std::ostream& os = std::cout) const 21 | { 22 | char msg[200]; 23 | sprintf(msg, "[BBox] [%g,%g,%g]x[%g,%g,%g]\n", low[0], low[1], low[2], high[0], high[1], high[2]); 24 | os << msg; 25 | } 26 | }; 27 | 28 | } 29 | #endif // BOUNDINGBOX_HPP 30 | -------------------------------------------------------------------------------- /src/libcollision/collision.cpp: -------------------------------------------------------------------------------- 1 | #include "collision.h" 2 | namespace sdfibm{ 3 | /* 0. shapeShapeCollision takes two solids, and two references of the collision position (cP) and normal (cN) 4 | 1. it returns the overlap between two shapes -- collision occur when overlap > 0 5 | 2. the normal points from the first towards the second shape */ 6 | 7 | scalar sphereSphereCollision(const Solid& s1, const Solid& s2, vector& cP, vector& cN) 8 | { 9 | Foam::vector s2s = s2.getCenter() - s1.getCenter(); 10 | cN = Foam::normalised(s2s); 11 | 12 | scalar r1 = s1.getShape()->getRadiusB(); 13 | scalar r2 = s2.getShape()->getRadiusB(); 14 | 15 | cP = 0.5*(s1.getCenter() + s2.getCenter() + (r1 - r2)*cN); 16 | return r1 + r2 - Foam::mag(s2s); 17 | } 18 | scalar circleCircleCollision(const Solid& s1, const Solid& s2, vector& cP, vector& cN) { 19 | return sphereSphereCollision(s1, s2, cP, cN); } 20 | 21 | scalar planeSphereCollision(const Solid& p, const Solid& s, vector& cP, vector& cN) 22 | { 23 | vector s_center = Foam::conjugate(p.getOrientation()).transform(s.getCenter() - p.getCenter()); 24 | scalar p2s = s_center.y(); 25 | cN = p.getOrientation().transform(Foam::vector(0,1,0)); 26 | cP = s.getCenter() - s.getRadiusB()*cN; 27 | return s.getRadiusB() - p2s; 28 | } 29 | 30 | scalar planeCircleCollision(const Solid& p, const Solid& s, vector& cP, vector& cN) { 31 | return planeSphereCollision(p, s, cP, cN); } 32 | scalar spherePlaneCollision(const Solid& s, const Solid& p, vector& cP, vector& cN) { 33 | return planeSphereCollision(p, s, cP, cN); } 34 | scalar circlePlaneCollision(const Solid& s, const Solid& p, vector& cP, vector& cN) { 35 | return spherePlaneCollision(s, p, cP, cN); } 36 | 37 | collisionFunc collisionFuncTable[kNUM_COL_FUNC][kNUM_COL_FUNC]; 38 | 39 | void InitCollisionFuncTable() 40 | { 41 | for(label i = 0; i < kNUM_COL_FUNC; i++){ 42 | for(label j = 0; j < kNUM_COL_FUNC; j++) { 43 | collisionFuncTable[i][j] = nullptr; 44 | } } 45 | 46 | collisionFuncTable[SHAPE2ID["Circle"]][SHAPE2ID["Plane"] ] = circlePlaneCollision; 47 | collisionFuncTable[SHAPE2ID["Plane"] ][SHAPE2ID["Circle"]] = planeCircleCollision; 48 | collisionFuncTable[SHAPE2ID["Sphere"]][SHAPE2ID["Plane"] ] = spherePlaneCollision; 49 | collisionFuncTable[SHAPE2ID["Plane"] ][SHAPE2ID["Sphere"]] = planeSphereCollision; 50 | collisionFuncTable[SHAPE2ID["Circle"]][SHAPE2ID["Circle"]] = circleCircleCollision; 51 | collisionFuncTable[SHAPE2ID["Sphere"]][SHAPE2ID["Sphere"]] = sphereSphereCollision; 52 | } 53 | 54 | collisionFunc getCollisionFunc(const std::string& name1, const std::string& name2) 55 | { 56 | return collisionFuncTable[SHAPE2ID[name1]][SHAPE2ID[name2]]; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/libcollision/collision.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLISION_HPP 2 | #define COLLISION_HPP 3 | 4 | #include "../types.h" 5 | #include "../utils.h" 6 | #include "../solid.h" 7 | #include 8 | namespace sdfibm{ 9 | 10 | const int kNUM_COL_FUNC = 10; 11 | static std::map SHAPE2ID = { 12 | {"Plane", 0}, 13 | {"Circle", 1}, 14 | {"Sphere", 2} 15 | }; 16 | 17 | // 2d collision 18 | scalar circlePlaneCollision (const Solid& c, const Solid& p, vector& cP, vector& cN); 19 | scalar circleCircleCollision(const Solid& c1, const Solid& c2, vector& cP, vector& cN); 20 | 21 | // 3d collision 22 | scalar spherePlaneCollision (const Solid& c, const Solid& p, vector& cP, vector& cN); 23 | scalar sphereSphereCollision(const Solid& c1, const Solid& c2, vector& cP, vector& cN); 24 | 25 | typedef scalar (*collisionFunc)(const Solid& s1, const Solid& s2, vector& cP, vector& cN); 26 | extern collisionFunc collisionFuncTable[kNUM_COL_FUNC][kNUM_COL_FUNC]; // table of collsion handling functions 27 | // extern scalar (*collisionFuncTable[kNUM_COL_FUNC][kNUM_COL_FUNC])(Solid& s1, Solid& s2, vector& cP, vector& cN); 28 | void InitCollisionFuncTable(); 29 | collisionFunc getCollisionFunc(const std::string& name1, const std::string& name2); 30 | 31 | } 32 | #endif // COLLISION_HPP 33 | -------------------------------------------------------------------------------- /src/libcollision/ugrid.cpp: -------------------------------------------------------------------------------- 1 | #include "ugrid.h" 2 | #include 3 | namespace sdfibm{ 4 | 5 | UGrid::UGrid(BBox& bbox, scalar delta) 6 | { 7 | m_bbox = bbox; 8 | m_delta = delta; 9 | m_deltaINV = 1.0/m_delta; 10 | 11 | m_nx = std::ceil((bbox.high[0] - bbox.low[0])*m_deltaINV); 12 | m_ny = std::ceil((bbox.high[1] - bbox.low[1])*m_deltaINV); 13 | m_nz = std::ceil((bbox.high[2] - bbox.low[2])*m_deltaINV); 14 | 15 | m_nynz = m_ny*m_nz; 16 | m_num_cells = m_nx*m_ny*m_nz; 17 | 18 | std::vector slot; 19 | slot.reserve(10); // by default each cell has room for 10 objects 20 | for(int i = 0; i < m_num_cells; ++i) 21 | m_map[i] = slot; 22 | } 23 | 24 | void UGrid::report(std::ostream& os, bool detail) 25 | { 26 | os << "[UGrid]\n"; 27 | m_bbox.report(os); 28 | os << "[UGrid] Cells: " << m_num_cells << std::endl; 29 | if (detail) 30 | { 31 | for(int i = 0; i < m_nx; ++i) { 32 | for(int j = 0; j < m_ny; ++j) { 33 | for(int k = 0; k < m_nz; ++k) { 34 | std::vector& lst = getObjectList(i, j, k); 35 | if(!lst.empty()) 36 | { 37 | char msg[80]; 38 | sprintf(msg, "\tC[%d,%d,%d](%ld):", i,j,k,lst.size()); 39 | os << msg; 40 | for(int pid : lst) 41 | { 42 | os << pid << ' '; 43 | } 44 | os << std::endl; 45 | } 46 | } } } // end of triple loop 47 | } 48 | } 49 | 50 | void UGrid::generateCollisionPairs(std::vector& collision_pairs) 51 | { 52 | for(int i = 0; i < m_nx; ++i) { 53 | for(int j = 0; j < m_ny; ++j) { 54 | for(int k = 0; k < m_nz; ++k) { 55 | int myid = hash(i, j, k); 56 | if(m_map[myid].empty()) 57 | continue; 58 | // note: if use unsigned nbi, -1 is implicitly casted into 0 59 | for(int nbi = i-1; nbi <= i+1; ++nbi) { 60 | for(int nbj = j-1; nbj <= j+1; ++nbj) { 61 | for(int nbk = k-1; nbk <= k+1; ++nbk) { 62 | if(nbi < 0 || nbi > m_nx-1) continue; 63 | if(nbj < 0 || nbj > m_ny-1) continue; 64 | if(nbk < 0 || nbk > m_nz-1) continue; 65 | 66 | int nbid = hash(nbi, nbj, nbk); 67 | if(m_map[nbid].empty()) continue; 68 | 69 | std::vector& lst = m_map[myid]; 70 | std::vector& nblist = m_map[nbid]; 71 | for(int pi : lst) 72 | for(int qi : nblist) 73 | if(pi < qi) 74 | collision_pairs.push_back(CollisionPair(pi, qi)); 75 | } } } // end of inner triple loop 76 | } } } // end of outer triple loop 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/libcollision/ugrid.h: -------------------------------------------------------------------------------- 1 | #ifndef UGRID_HPP 2 | #define UGRID_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "bbox.h" 9 | #include "../types.h" 10 | typedef std::pair CollisionPair; 11 | 12 | namespace sdfibm { 13 | 14 | class UGrid 15 | { 16 | private: 17 | BBox m_bbox; 18 | int m_nx, m_ny, m_nz, m_nynz, m_num_cells; 19 | scalar m_delta; 20 | scalar m_deltaINV; 21 | std::unordered_map> m_map; 22 | 23 | public: 24 | UGrid(BBox& bbox, scalar delta); 25 | 26 | void generateCollisionPairs(std::vector &collision_pairs); 27 | void report(std::ostream& os = std::cout, bool detail = false); 28 | 29 | inline void insert(scalar x, scalar y, scalar z, int id) 30 | { 31 | m_map[hash(x, y, z)].push_back(id); 32 | } 33 | 34 | std::vector& getObjectList(int i, int j, int k) 35 | { 36 | return m_map.find(hash(i,j,k))->second; 37 | } 38 | 39 | void clear() 40 | { 41 | for(auto& item : m_map) 42 | item.second.clear(); 43 | } 44 | 45 | private: 46 | inline int hash(int i, int j, int k) const 47 | { 48 | return i*m_nynz + j*m_nz + k; 49 | } 50 | 51 | inline int hash(scalar x, scalar y, scalar z) const 52 | { 53 | int i = std::floor((x-m_bbox.low[0])*m_deltaINV); 54 | int j = std::floor((y-m_bbox.low[1])*m_deltaINV); 55 | int k = std::floor((z-m_bbox.low[2])*m_deltaINV); 56 | return hash(i, j, k); 57 | } 58 | }; 59 | 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /src/libforcer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(libName force) 2 | 3 | set( 4 | libSrc 5 | forcerfactory.cpp 6 | ) 7 | 8 | set( 9 | libInc 10 | iforcer.h 11 | constant.h 12 | spring.h 13 | magnetic.h 14 | forcerfactory.h 15 | ) 16 | 17 | add_library( 18 | ${libName} 19 | STATIC 20 | ${libSrc} 21 | ${libInc} 22 | ) 23 | 24 | add_definitions(${FOAMFLAG}) 25 | target_include_directories(${libName} PUBLIC ${FOAMINC}) 26 | target_link_libraries(${libName} PUBLIC m) 27 | -------------------------------------------------------------------------------- /src/libforcer/constant.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "iforcer.h" 4 | namespace sdfibm::forcer { 5 | 6 | class Constant : public IForcer, _creator 7 | { 8 | public: 9 | virtual Force generate(const scalar&, const vector&, const vector&, const quaternion&, const vector&) override final; 10 | virtual ~Constant() override final {} 11 | TYPENAME("Constant") 12 | virtual std::string description() const override {return "forcer with const force and torque";} 13 | 14 | Constant(const dictionary& para) 15 | { 16 | force = para.lookup("force"); 17 | torque = para.lookup("torque"); 18 | } 19 | 20 | private: 21 | vector force, torque; 22 | }; 23 | 24 | IForcer::Force Constant::generate( 25 | const scalar& time, 26 | const vector& position, 27 | const vector& velocity, 28 | const quaternion& orientation, 29 | const vector& omega 30 | ) 31 | { 32 | return {force, torque}; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/libforcer/forcerfactory.cpp: -------------------------------------------------------------------------------- 1 | #include "forcerfactory.h" 2 | -------------------------------------------------------------------------------- /src/libforcer/forcerfactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../types.h" 4 | #include "../genericfactory.h" 5 | #include "iforcer.h" 6 | namespace sdfibm::forcer { 7 | MAKESPECIALFACTORY(Forcer, IForcer, Foam::dictionary); 8 | #define REGISTERFORCE(m) \ 9 | bool sdfibm::m::added = ForcerFactory::add(sdfibm::m::typeName(), sdfibm::m::create); 10 | 11 | #include "constant.h" 12 | REGISTERFORCE(forcer::Constant); 13 | #include "spring.h" 14 | REGISTERFORCE(forcer::Spring); 15 | #include "magnetic.h" 16 | REGISTERFORCE(forcer::Magnetic); 17 | } -------------------------------------------------------------------------------- /src/libforcer/iforcer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../types.h" 4 | #include 5 | 6 | namespace sdfibm::forcer { 7 | 8 | #define TYPENAME(name) \ 9 | static std::string typeName() {return name;} \ 10 | static bool added; 11 | 12 | class IForcer; 13 | template 14 | class _creator 15 | { 16 | public: 17 | static std::unique_ptr create(const dictionary& para) 18 | { 19 | return std::make_unique(para); 20 | } 21 | }; 22 | 23 | class IForcer 24 | { 25 | public: 26 | using Force = std::pair; 27 | IForcer() = default; 28 | virtual ~IForcer() = default; 29 | 30 | virtual Force generate( 31 | const scalar& time, 32 | const vector& position, 33 | const vector& velocity, 34 | const quaternion& orientation, 35 | const vector& omega 36 | ) = 0; 37 | virtual std::string description() const = 0; 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/libforcer/magnetic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "iforcer.h" 4 | 5 | namespace sdfibm::forcer { 6 | 7 | class Magnetic : public IForcer, _creator 8 | { 9 | public: 10 | virtual Force generate(const scalar&, const vector&, const vector&, const quaternion&, const vector&) override final; 11 | 12 | Magnetic(const dictionary& para) 13 | { 14 | direction = para.lookup("direction"); 15 | // normalize the direction 16 | try { 17 | A = Foam::readScalar(para.lookup("A")); 18 | w = Foam::readScalar(para.lookup("w")); 19 | } catch (const std::exception& e) { 20 | std::cout << "Problem in creating Magnetic force" << ' ' 21 | << e.what() << std::endl; 22 | std::exit(1); 23 | } 24 | } 25 | virtual ~Magnetic() override final {} 26 | TYPENAME("Magnetic") 27 | virtual std::string description() const override {return "Magnetic forcer: A*cos(omega*t)*direction";} 28 | private: 29 | vector direction; // direction, should be a unit vector 30 | scalar A; // A 31 | scalar w; // omega, set to zero to have a constant force 32 | }; 33 | 34 | IForcer::Force Magnetic::generate( 35 | const scalar& time, 36 | const vector& position, 37 | const vector& velocity, 38 | const quaternion& orientation, 39 | const vector& omega 40 | ) 41 | { 42 | // hardcoded magnetic moment as magnitude * unit direction vector 43 | static vector m_original = (1.0) * (vector(0.0, 0.0, 1.0)); 44 | vector B = A * std::cos(w*time)*direction; // magnetic field 45 | vector m = Foam::conjugate(orientation).transform(m_original); 46 | return {vector::zero, m ^ B}; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/libforcer/spring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "iforcer.h" 4 | 5 | namespace sdfibm::forcer { 6 | 7 | class Spring : public IForcer, _creator 8 | { 9 | public: 10 | virtual Force generate(const scalar&, const vector&, const vector&, const quaternion&, const vector&) override final; 11 | 12 | Spring(const dictionary& para) 13 | { 14 | pivot = para.lookup("pivot"); 15 | try { 16 | k = Foam::readScalar(para.lookup("k")); 17 | l = Foam::readScalar(para.lookup("l")); 18 | } catch (const std::exception& e) { 19 | std::cout << "Problem in creating Spring force" << ' ' 20 | << e.what() << std::endl; 21 | std::exit(1); 22 | } 23 | } 24 | virtual ~Spring() override final {} 25 | TYPENAME("Spring") 26 | virtual std::string description() const override {return "Spring forcer with a pivot, stiffness (k), and rest length (l)";} 27 | private: 28 | vector pivot; 29 | scalar k; 30 | scalar l; 31 | }; 32 | 33 | IForcer::Force Spring::generate( 34 | const scalar& time, 35 | const vector& position, 36 | const vector& velocity, 37 | const quaternion& orientation, 38 | const vector& omega 39 | ) 40 | { 41 | vector r = position - pivot; 42 | auto force {vector::zero}; 43 | if (mag(r) > SMALL) 44 | force = -k * r * (1.0 - l/mag(r)); 45 | return {force, vector::zero}; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/libmaterial/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/src/libmaterial/CMakeLists.txt -------------------------------------------------------------------------------- /src/libmaterial/imaterial.h: -------------------------------------------------------------------------------- 1 | #ifndef IMATERIAL_HPP 2 | #define IMATERIAL_HPP 3 | 4 | #include "../types.h" 5 | namespace sdfibm{ 6 | 7 | class IMaterial 8 | { 9 | private: 10 | // density 11 | scalar m_rho; 12 | public: 13 | IMaterial(scalar rho = 1.0) 14 | { 15 | m_rho = rho; 16 | } 17 | const scalar& getRho() const {return m_rho;} 18 | }; 19 | 20 | class MaterialDefault : public IMaterial 21 | { 22 | public: 23 | MaterialDefault():IMaterial() {} 24 | }; 25 | 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /src/libmotion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(libName motion) 2 | 3 | set( 4 | libSrc 5 | motionfactory.cpp 6 | ) 7 | 8 | set( 9 | libInc 10 | imotion.h 11 | motion01mask.h 12 | motion000002.h 13 | motion110002.h 14 | motion222000.h 15 | motionfactory.h 16 | motionopenclose.h 17 | motionrotor.h 18 | motionsinedirectional.h 19 | ) 20 | 21 | add_library( 22 | ${libName} 23 | STATIC 24 | ${libSrc} 25 | ${libInc} 26 | ) 27 | 28 | add_definitions(${FOAMFLAG}) 29 | target_include_directories(${libName} PUBLIC ${FOAMINC}) 30 | target_link_libraries(${libName} PUBLIC m) 31 | -------------------------------------------------------------------------------- /src/libmotion/imotion.h: -------------------------------------------------------------------------------- 1 | #ifndef IMOTION_H_INCLUDED 2 | #define IMOTION_H_INCLUDED 3 | 4 | #include "../types.h" 5 | 6 | namespace sdfibm{ 7 | // nameing convention: 0 completely frozen, 1 totally free, 2 user specified 8 | 9 | #define TYPENAME(name) \ 10 | static std::string typeName() {return name;} \ 11 | static bool added; 12 | 13 | // define templated base to insert creator function into child class 14 | // equivalent to manually adding the following line into each child class 15 | //static IMotion* create(const Node& node){return new Motion000000(node);} 16 | class IMotion; 17 | template 18 | class _creator 19 | { 20 | public: 21 | static IMotion* create(const dictionary& node) 22 | { 23 | return new T(node); 24 | } 25 | }; 26 | 27 | class IMotion 28 | { 29 | public: 30 | IMotion() = default; 31 | virtual ~IMotion() = default; 32 | 33 | // the work horse 34 | virtual void constraint(const scalar& time, vector& velocity, vector& omega) = 0; 35 | virtual std::string description() const = 0; // more detailed information 36 | }; 37 | 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /src/libmotion/motion000002.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTION000002_H 2 | #define MOTION000002_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm{ 6 | 7 | class Motion000002:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | Motion000002(const dictionary& para) 18 | { 19 | try { 20 | m_period = Foam::readScalar(para.lookup("period")); 21 | } catch (const std::exception& e) { 22 | std::cout << "Problem in creating Motion000002 (aka const rotation)" << ' ' 23 | << e.what() << std::endl; 24 | std::exit(1); 25 | } 26 | m_omega = 2*M_PI/m_period; 27 | } 28 | virtual ~Motion000002() override final {} 29 | TYPENAME("Motion000002") // a linear motion 30 | virtual std::string description() const override {return "only rotate in z with prescribed omega";} 31 | private: 32 | scalar m_period, m_omega; // m_omegaz is only the z component 33 | }; 34 | 35 | void Motion000002::constraint(const scalar &time, vector &velocity, vector &omega) 36 | { 37 | velocity = vector::zero; 38 | omega = vector::zero; 39 | omega[2] = m_omega; 40 | } 41 | 42 | } 43 | #endif // MOTION000002_H 44 | -------------------------------------------------------------------------------- /src/libmotion/motion01mask.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTION01MASK_H 2 | #define MOTION01MASK_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm{ 6 | 7 | class Motion01Mask:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | virtual ~Motion01Mask() override final {} 18 | TYPENAME("Motion01Mask") 19 | virtual std::string description() const override {return "general (0|1){6} motion mask";} 20 | 21 | Motion01Mask(const dictionary& para) 22 | { 23 | vmask = vector::zero; 24 | omask = vector::zero; 25 | 26 | std::string mask = Foam::word(para.lookup("mask")); 27 | 28 | // sanity check 29 | if(mask[0]!='b') 30 | { 31 | std::cout << "Mask starts with b\n"; 32 | std::exit(1); 33 | } 34 | if(mask.size() != 7) 35 | { 36 | std::cout << "Mask size != 7\n"; 37 | std::exit(1); 38 | } 39 | for(int i = 1; i<=6; i++) 40 | { 41 | if(mask[i]!='0' && mask[i]!='1') 42 | { 43 | std::cout << "Mask ele != 0 or 1\n"; 44 | std::exit(1); 45 | } 46 | } 47 | 48 | vmask[0] = (mask[1]=='0') ? 0 : 1; 49 | vmask[1] = (mask[2]=='0') ? 0 : 1; 50 | vmask[2] = (mask[3]=='0') ? 0 : 1; 51 | omask[0] = (mask[4]=='0') ? 0 : 1; 52 | omask[1] = (mask[5]=='0') ? 0 : 1; 53 | omask[2] = (mask[6]=='0') ? 0 : 1; 54 | } 55 | 56 | private: 57 | vector vmask, omask; 58 | }; 59 | 60 | void Motion01Mask::constraint(const scalar &time, vector &velocity, vector &omega) 61 | { 62 | velocity = cmptMultiply(velocity, vmask); 63 | omega = cmptMultiply(omega, omask); 64 | } 65 | 66 | } 67 | #endif // MOTION01MASK 68 | -------------------------------------------------------------------------------- /src/libmotion/motion110002.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTION110002_H 2 | #define MOTION110002_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm{ 6 | 7 | class Motion110002:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | Motion110002(const dictionary& para) 18 | { 19 | try { 20 | m_period = Foam::readScalar(para.lookup("period")); 21 | } catch (const std::exception& e) { 22 | std::cout << "Problem in creating Motion110002 (aka const rotation)" << ' ' 23 | << e.what() << std::endl; 24 | std::exit(1); 25 | } 26 | m_omega = 2*M_PI/m_period; 27 | } 28 | virtual ~Motion110002() override final {} 29 | TYPENAME("Motion110002") // a linear motion 30 | virtual std::string description() const override {return "only rotate in z with prescribed omega";} 31 | private: 32 | scalar m_period, m_omega; // m_omegaz is only the z component 33 | }; 34 | 35 | void Motion110002::constraint(const scalar &time, vector &velocity, vector &omega) 36 | { 37 | velocity[2] = 0.0; 38 | omega = vector::zero; 39 | omega[2] = m_omega; 40 | } 41 | 42 | } 43 | #endif // MOTION110002_H 44 | -------------------------------------------------------------------------------- /src/libmotion/motion222000.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTION222000_H 2 | #define MOTION222000_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm{ 6 | 7 | class Motion222000:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | Motion222000(const dictionary& para) 18 | { 19 | try { 20 | m_u = Foam::readScalar(para.lookup("u")); 21 | m_v = Foam::readScalar(para.lookup("v")); 22 | m_w = Foam::readScalar(para.lookup("w")); 23 | } catch (const std::exception& e) { 24 | std::cout << "Problem in creating Motion222000 (aka linear motion)" 25 | << e.what() << std::endl; 26 | } 27 | } 28 | virtual ~Motion222000() override final {} 29 | TYPENAME("Motion222000") // a linear motion 30 | virtual std::string description() const override {return "move at prescribed (u,v,w), no rotation";} 31 | private: 32 | scalar m_u, m_v, m_w; 33 | }; 34 | 35 | void Motion222000::constraint(const scalar &time, vector &velocity, vector &omega) 36 | { 37 | velocity = vector(m_u, m_v, m_w); 38 | omega = vector::zero; 39 | } 40 | 41 | } 42 | #endif // MOTION222000_H 43 | -------------------------------------------------------------------------------- /src/libmotion/motionfactory.cpp: -------------------------------------------------------------------------------- 1 | #include "imotion.h" 2 | #include "motionfactory.h" 3 | 4 | #include 5 | namespace sdfibm{ 6 | 7 | #define REGISTERMOTION(m) \ 8 | bool sdfibm::m::added = MotionFactory::add(sdfibm::m::typeName(), sdfibm::m::create); 9 | 10 | bool MotionFactory::add(const std::string& name, TCreateMethod create_method) 11 | { 12 | auto it = m_methods.find(name); 13 | // std::cout << "Registering..." << name << std::endl; 14 | if(it == m_methods.end()) 15 | { 16 | m_methods[name] = create_method; 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | IMotion* MotionFactory::create(const std::string& name, const dictionary& node) 23 | { 24 | auto it = m_methods.find(name); 25 | if(it != m_methods.end()) 26 | { 27 | return it->second(node); 28 | } 29 | return nullptr; 30 | } 31 | 32 | std::map MotionFactory::m_methods; 33 | 34 | } 35 | // add motions 36 | #include "motion000002.h" 37 | REGISTERMOTION(Motion000002); 38 | #include "motion110002.h" 39 | REGISTERMOTION(Motion110002); 40 | #include "motion222000.h" 41 | REGISTERMOTION(Motion222000); 42 | #include "motionsinedirectional.h" 43 | REGISTERMOTION(MotionSineDirectional); 44 | #include "motion01mask.h" 45 | REGISTERMOTION(Motion01Mask); 46 | #include "motionrotor.h" 47 | REGISTERMOTION(MotionRotor); 48 | #include "motionopenclose.h" 49 | REGISTERMOTION(MotionOpenClose); 50 | 51 | -------------------------------------------------------------------------------- /src/libmotion/motionfactory.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTIONFACTORY_H 2 | #define MOTIONFACTORY_H 3 | 4 | #include 5 | #include 6 | #include "../types.h" 7 | namespace sdfibm{ 8 | 9 | class IMotion; 10 | 11 | class MotionFactory 12 | { 13 | public: 14 | using TCreateMethod = IMotion* (*)(const dictionary&); 15 | 16 | public: 17 | // ideally should be a singleton (TODO?), for now just disable ctor 18 | MotionFactory() = delete; 19 | 20 | static bool add(const std::string& name, TCreateMethod create_method); 21 | static IMotion* create(const std::string& name, const dictionary&); 22 | 23 | static void report(std::ostream& os = std::cout) 24 | { 25 | // displays all the motions the factory can "produce" 26 | int i = 1; 27 | for(auto it : m_methods) 28 | { 29 | os << '[' << i << "] " << it.first << std::endl; 30 | ++i; 31 | } 32 | } 33 | 34 | private: 35 | static std::map m_methods; 36 | }; 37 | 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /src/libmotion/motionopenclose.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTIONOPENCLOSE_H 2 | #define MOTIONOPENCLOSE_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm { 6 | 7 | class MotionOpenClose:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | MotionOpenClose(const dictionary& para) 18 | { 19 | } 20 | virtual ~MotionOpenClose() override final {} 21 | TYPENAME("MotionOpenClose") 22 | virtual std::string description() const override {return "model the open-close operation of a gate";} 23 | private: 24 | scalar getOpenCloseVelocity(const scalar& time) 25 | { 26 | scalar t = fmod(time, 5.0); 27 | scalar v = 0.0; 28 | if (t > 1 && t < 2) 29 | v = -1.0; 30 | if (t > 3 && t < 4) 31 | v = 1.0; 32 | return v; 33 | } 34 | }; 35 | 36 | void MotionOpenClose::constraint(const scalar &time, vector &velocity, vector &omega) 37 | { 38 | velocity = vector(0,getOpenCloseVelocity(time),0); 39 | omega = vector::zero; 40 | } 41 | 42 | } 43 | #endif // MOTIONOPENCLOSE_H 44 | -------------------------------------------------------------------------------- /src/libmotion/motionrotor.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTIONROTOR_H 2 | #define MOTIONROTOR_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm { 6 | 7 | class MotionRotor:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | MotionRotor(const dictionary& para) 18 | { 19 | try { 20 | m_period = Foam::readScalar(para.lookup("period")); 21 | m_radius = Foam::readScalar(para.lookup("radius")); 22 | m_theta0 = Foam::readScalar(para.lookup("theta0")); 23 | m_selfom = Foam::readScalar(para.lookup("selfom")); 24 | } catch (const std::exception& e) { 25 | std::cout << "Problem in creating MotionRotor" << ' ' 26 | << e.what() << std::endl; 27 | std::exit(1); 28 | } 29 | m_omega = 2*M_PI/m_period; 30 | } 31 | virtual ~MotionRotor() override final {} 32 | TYPENAME("MotionRotor") 33 | virtual std::string description() const override {return "rotate around origin with prescribed omega";} 34 | private: 35 | scalar m_period, m_omega; 36 | scalar m_radius, m_theta0; 37 | scalar m_selfom; 38 | }; 39 | 40 | void MotionRotor::constraint(const scalar &time, vector &velocity, vector &omega) 41 | { 42 | velocity = vector::zero; 43 | velocity[0] = -m_radius*m_omega*std::sin(m_omega*time + m_theta0); 44 | velocity[1] = m_radius*m_omega*std::cos(m_omega*time + m_theta0); 45 | omega = vector::zero; 46 | omega[2] = m_selfom; 47 | } 48 | 49 | } 50 | #endif // MOTIONROTOR_H 51 | -------------------------------------------------------------------------------- /src/libmotion/motionsinedirectional.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTIONSINEDIRECTIONAL_H 2 | #define MOTIONSINEDIRECTIONAL_H 3 | 4 | #include "imotion.h" 5 | namespace sdfibm { 6 | 7 | class MotionSineDirectional:public IMotion, _creator 8 | { 9 | public: 10 | // same signature for all motions 11 | virtual void constraint( 12 | const scalar& time, 13 | vector& velocity, 14 | vector& omega) override final; 15 | 16 | // update below 17 | MotionSineDirectional(const dictionary& para) 18 | { 19 | try { 20 | m_amplitude = Foam::readScalar(para.lookup("amplitude")); 21 | m_period = Foam::readScalar(para.lookup("period")); 22 | m_omega = 2*M_PI/m_period; 23 | 24 | vector direction = para.lookup("direction"); 25 | m_direction = direction; 26 | 27 | if(Foam::magSqr(m_direction) > 1.001) 28 | throw("direction vector not normalized!"); 29 | } catch (const std::exception& e) { 30 | std::cout << "Problem in creating MotionSineDirectional (aka linear oscillation)" 31 | << e.what() << std::endl; 32 | } 33 | } 34 | virtual ~MotionSineDirectional() override final {} 35 | TYPENAME("MotionSineDirectional") // a linear motion 36 | virtual std::string description() const override {return "oscillate as vec(x) = vec(x0) + a*sin(omega t)*vec(n), no rotation";} 37 | private: 38 | scalar m_amplitude, m_period; 39 | vector m_direction; 40 | 41 | scalar m_omega; 42 | }; 43 | 44 | void MotionSineDirectional::constraint(const scalar &time, vector &velocity, vector &omega) 45 | { 46 | velocity = m_amplitude * m_omega * std::cos(m_omega* time)*m_direction; 47 | omega = vector::zero; 48 | } 49 | 50 | } 51 | #endif // MOTIONSINEDIRECTIONAL_H 52 | -------------------------------------------------------------------------------- /src/libshape/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(libName shape) 2 | 3 | set( 4 | libSrc 5 | shapefactory.cpp 6 | ) 7 | 8 | set( 9 | libInc 10 | ishape.h 11 | shapefactory.h 12 | box.h 13 | circle.h 14 | circle_tail.h 15 | circle_twotail.h 16 | ellipse.h 17 | ellipsoid.h 18 | plane.h 19 | rectangle.h 20 | sphere.h 21 | ) 22 | 23 | add_library( 24 | ${libName} 25 | STATIC 26 | ${libSrc} 27 | ${libInc} 28 | ) 29 | 30 | add_definitions(${FOAMFLAG}) 31 | target_include_directories(${libName} PUBLIC ${FOAMINC}) 32 | target_link_libraries(${libName} PUBLIC m) 33 | -------------------------------------------------------------------------------- /src/libshape/box.h: -------------------------------------------------------------------------------- 1 | #ifndef BOX_H 2 | #define BOX_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm { 6 | 7 | class Box : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radiusa, m_radiusb, m_radiusc; 11 | 12 | public: 13 | // const static int shape_id = SHAPE::CIRC; 14 | Box(const dictionary& para) 15 | { 16 | m_radiusa = Foam::readScalar(para.lookup("radiusa")); 17 | m_radiusb = Foam::readScalar(para.lookup("radiusb")); 18 | m_radiusc = Foam::readScalar(para.lookup("radiusc")); 19 | m_com = para.lookupOrDefault("com", vector::zero); 20 | 21 | // set inherited variables 22 | m_volume = 8.0*m_radiusa*m_radiusb*m_radiusc; 23 | m_volumeINV = 1.0/m_volume; 24 | 25 | m_moi[0] = 1.0/3.0*m_volume*(m_radiusb*m_radiusb + m_radiusc*m_radiusc); 26 | m_moi[4] = 1.0/3.0*m_volume*(m_radiusa*m_radiusa + m_radiusc*m_radiusc); 27 | m_moi[8] = 1.0/3.0*m_volume*(m_radiusb*m_radiusb + m_radiusa*m_radiusa); 28 | m_moiINV = Foam::inv(m_moi); 29 | m_radiusB = std::max(std::max(m_radiusa, m_radiusb),m_radiusc); 30 | } 31 | inline scalar getRadiusa() const { return m_radiusa;} 32 | inline scalar getRadiusb() const { return m_radiusb;} 33 | inline scalar getRadiusc() const { return m_radiusc;} 34 | inline scalar getVolume() const { return m_volume;} 35 | 36 | SHAPETYPENAME("Box") 37 | virtual std::string description() const override {return "Box, [ra, rb, rc] = " + std::to_string(m_radiusa) + ", " + std::to_string(m_radiusb) + ", " + std::to_string(m_radiusc);} 38 | 39 | // implement interface 40 | virtual inline bool isInside(const vector& p) const override 41 | { 42 | return sdf::box_bool( 43 | m_com + p, 44 | m_radiusa, 45 | m_radiusb, 46 | m_radiusc); 47 | } 48 | 49 | virtual inline scalar signedDistance(const vector& p) const override 50 | { 51 | return sdf::filter(sdf::box( 52 | m_com + p, 53 | m_radiusa, 54 | m_radiusb, 55 | m_radiusc) 56 | ); 57 | } 58 | }; 59 | 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /src/libshape/circle.h: -------------------------------------------------------------------------------- 1 | #ifndef CIRCLE_H 2 | #define CIRCLE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm{ 6 | 7 | class Circle : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radius; 11 | scalar m_radiusSQR; 12 | 13 | public: 14 | // const static int shape_id = SHAPE::CIRC; 15 | Circle(const dictionary& para) 16 | { 17 | m_radius = Foam::readScalar(para.lookup("radius")); 18 | m_com = para.lookupOrDefault("com", vector::zero); 19 | m_radiusSQR = m_radius * m_radius; 20 | 21 | // set inherited variables 22 | m_volume = M_PI*m_radiusSQR; 23 | m_volumeINV = 1.0/m_volume; 24 | scalar tmp = 0.5*m_volume*m_radiusSQR; 25 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 26 | m_moiINV = Foam::inv(m_moi); 27 | m_radiusB = m_radius; 28 | } 29 | inline scalar getRadius() const { return m_radius;} 30 | inline scalar getVolume() const { return m_volume;} 31 | inline void setRadius(scalar r) {m_radius = r;} 32 | 33 | // typename and description 34 | SHAPETYPENAME("Circle") 35 | virtual std::string description() const override {return "circle (x-y plane), r = " + std::to_string(m_radius);} 36 | 37 | // implement interface 38 | virtual inline bool isInside(const vector& p) const override 39 | { 40 | return sdf::circle_bool_fast(m_com + vector(p.x(), p.y(), 0.0), m_radiusSQR); 41 | } 42 | 43 | virtual inline scalar signedDistance(const vector& p) const override 44 | { 45 | return sdf::filter(sdf::circle(m_com + vector(p.x(), p.y(), 0.0), m_radius)); 46 | } 47 | }; 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/libshape/circle_tail.h: -------------------------------------------------------------------------------- 1 | #ifndef CIRCLE_TAIL_H 2 | #define CIRCLE_TAIL_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm{ 6 | 7 | class Circle_Tail : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radius; 11 | scalar m_ratio; // tail-length/circle-radius to derive tail length 12 | scalar m_radiusb; // tail-thickness 13 | 14 | scalar m_radiusSQR; 15 | scalar m_radiusa; 16 | 17 | public: 18 | Circle_Tail(const dictionary& para) 19 | { 20 | m_radius = Foam::readScalar(para.lookup("radius")); 21 | m_ratio = Foam::readScalar(para.lookup("ratio")); 22 | m_radiusb = Foam::readScalar(para.lookup("thickness")); 23 | m_com = para.lookupOrDefault("com", vector::zero); 24 | 25 | m_radiusSQR = m_radius * m_radius; 26 | m_radiusa = (m_ratio + 1)*0.5*m_radius; 27 | // set inherited variables 28 | m_volume = M_PI*m_radiusSQR; 29 | m_volumeINV = 1.0/m_volume; 30 | scalar tmp = 0.5*m_volume*m_radiusSQR; 31 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 32 | m_moiINV = Foam::inv(m_moi); 33 | m_radiusB = 2*m_radiusa; 34 | } 35 | inline scalar getRadius() const { return m_radius;} 36 | inline scalar getVolume() const { return m_volume;} 37 | 38 | // implement interface 39 | SHAPETYPENAME("Circle_Tail") 40 | virtual std::string description() const override {return "Circle_Tail (x-y plane), r = " + std::to_string(m_radius);} 41 | 42 | virtual inline bool isInside(const vector& p) const override 43 | { 44 | vector p2d = m_com + p; p2d.z() = 0.0; 45 | 46 | bool b1 = sdf::rectangle_bool(sdf::offset(p2d, vector(m_radiusa, 0.0, 0.0)), m_radiusa, m_radiusb); 47 | bool b2 = sdf::circle_bool_fast(vector(p2d.x(), p2d.y(), 0.0), m_radiusSQR); 48 | 49 | return sdf::U({b1, b2}); 50 | } 51 | 52 | virtual inline scalar signedDistance(const vector& p) const override 53 | { 54 | vector p2d = m_com + p; p2d.z() = 0.0; 55 | 56 | scalar d1 = sdf::circle(p2d, m_radius); 57 | scalar d2 = sdf::rectangle(sdf::offset(p2d, vector(m_radiusa, 0.0, 0.0)), 58 | m_radiusa, m_radiusb); 59 | 60 | return sdf::filter(sdf::U({d1, d2})); 61 | } 62 | }; 63 | 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /src/libshape/circle_twotail.h: -------------------------------------------------------------------------------- 1 | #ifndef CIRCLE_TWOTAIL_H 2 | #define CIRCLE_TWOTAIL_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm{ 6 | 7 | class Circle_TwoTail : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radius; 11 | scalar m_ratio; // tail-length/circle-radius to derive tail length 12 | scalar m_radiusb; // tail-thickness 13 | 14 | scalar m_radiusSQR; 15 | scalar m_radiusa; 16 | 17 | public: 18 | Circle_TwoTail(const dictionary& para) 19 | { 20 | m_radius = Foam::readScalar(para.lookup("radius")); 21 | m_ratio = Foam::readScalar(para.lookup("ratio")); 22 | m_radiusb = Foam::readScalar(para.lookup("thickness"))*0.5; 23 | m_com = para.lookupOrDefault("com", vector::zero); 24 | 25 | m_radiusSQR = m_radius * m_radius; 26 | m_radiusa = (m_ratio + 1)*0.5*m_radius; 27 | // set inherited variables 28 | m_volume = M_PI*m_radiusSQR; 29 | m_volumeINV = 1.0/m_volume; 30 | scalar tmp = 0.5*m_volume*m_radiusSQR; 31 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 32 | m_moiINV = Foam::inv(m_moi); 33 | m_radiusB = 2*m_radiusa; 34 | } 35 | inline scalar getRadius() const { return m_radius;} 36 | inline scalar getVolume() const { return m_volume;} 37 | 38 | // implement interface 39 | SHAPETYPENAME("Circle_TwoTail") 40 | virtual std::string description() const override {return "Circle_TwoTail (x-y plane), r = " + std::to_string(m_radius);} 41 | 42 | virtual inline bool isInside(const vector& p) const override 43 | { 44 | vector p2d = m_com + p; p2d.z() = 0.0; 45 | 46 | bool dc = sdf::circle_bool_fast(p2d, m_radiusSQR); 47 | bool d1 = sdf::rectangle_bool(sdf::offset(sdf::rot30( p2d), vector(m_radiusa, 0, 0)), 48 | m_radiusa, m_radiusb); 49 | bool d2 = sdf::rectangle_bool(sdf::offset(sdf::rot30(sdf::flipy(p2d)), vector(m_radiusa, 0, 0)), 50 | m_radiusa, m_radiusb); 51 | 52 | return sdf::U({dc, d1, d2}); 53 | } 54 | 55 | virtual inline scalar signedDistance(const vector& p) const override 56 | { 57 | vector p2d = m_com + p; p2d.z() = 0.0; 58 | 59 | scalar dc = sdf::circle(p2d, m_radius); 60 | scalar d1 = sdf::rectangle(sdf::offset(sdf::rot30( p2d), vector(m_radiusa, 0, 0)), 61 | m_radiusa, m_radiusb); 62 | scalar d2 = sdf::rectangle(sdf::offset(sdf::rot30(sdf::flipy(p2d)), vector(m_radiusa, 0, 0)), 63 | m_radiusa, m_radiusb); 64 | 65 | return sdf::filter(sdf::U({dc, d1, d2})); 66 | } 67 | }; 68 | 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /src/libshape/ellipse.h: -------------------------------------------------------------------------------- 1 | #ifndef ELLIPSE_H 2 | #define ELLIPSE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm { 6 | 7 | class Ellipse : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radiusa, m_radiusb; 11 | scalar m_radiusaSQRINV, m_radiusbSQRINV; 12 | 13 | public: 14 | Ellipse(const dictionary& para) 15 | { 16 | m_radiusa = Foam::readScalar(para.lookup("radiusa")); 17 | m_radiusb = Foam::readScalar(para.lookup("radiusb")); 18 | m_com = para.lookupOrDefault("com", vector::zero); 19 | 20 | m_radiusaSQRINV = 1.0/(m_radiusa * m_radiusa); 21 | m_radiusbSQRINV = 1.0/(m_radiusb * m_radiusb); 22 | 23 | // set inherited variables 24 | m_volume = M_PI*m_radiusa*m_radiusb; 25 | m_volumeINV = 1.0/m_volume; 26 | 27 | scalar tmp = 0.25*m_volume*(m_radiusa*m_radiusa + m_radiusb*m_radiusb); 28 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 29 | m_moiINV = Foam::inv(m_moi); 30 | m_radiusB = std::max(m_radiusa, m_radiusb); 31 | } 32 | inline scalar getRadiusa() const { return m_radiusa;} 33 | inline scalar getRadiusb() const { return m_radiusb;} 34 | inline scalar getVolume() const { return m_volume;} 35 | 36 | // implement interface 37 | SHAPETYPENAME("Ellipse") 38 | virtual std::string description() const override {return "ellipse (x-y plane), [ra, rb] = " + std::to_string(m_radiusa) + ", " + std::to_string(m_radiusb);} 39 | 40 | virtual inline bool isInside(const vector& p) const override 41 | { 42 | vector p2d = m_com + p; p2d.z() = 0.0; 43 | 44 | return sdf::ellipse_bool_fast(p2d, m_radiusaSQRINV, m_radiusbSQRINV); 45 | } 46 | 47 | virtual inline scalar signedDistance(const vector& p) const override 48 | { 49 | vector p2d = m_com + p; p2d.z() = 0.0; 50 | 51 | return sdf::filter( 52 | sdf::ellipse(p2d, m_radiusaSQRINV, m_radiusbSQRINV) 53 | ); 54 | } 55 | }; 56 | 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /src/libshape/ellipsoid.h: -------------------------------------------------------------------------------- 1 | #ifndef ELLIPSOID_H 2 | #define ELLIPSOID_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm { 6 | 7 | class Ellipsoid : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radiusa, m_radiusb, m_radiusc; 11 | scalar m_radiusaSQRINV, m_radiusbSQRINV, m_radiuscSQRINV; 12 | 13 | public: 14 | // const static int shape_id = SHAPE::CIRC; 15 | Ellipsoid(const dictionary& para) 16 | { 17 | m_radiusa = Foam::readScalar(para.lookup("radiusa")); 18 | m_radiusb = Foam::readScalar(para.lookup("radiusb")); 19 | m_radiusc = Foam::readScalar(para.lookup("radiusc")); 20 | m_radiusaSQRINV = 1.0/(m_radiusa * m_radiusa); 21 | m_radiusbSQRINV = 1.0/(m_radiusb * m_radiusb); 22 | m_radiuscSQRINV = 1.0/(m_radiusc * m_radiusc); 23 | 24 | // set inherited variables 25 | m_volume = 4.0/3.0*M_PI*m_radiusa*m_radiusb*m_radiusc; 26 | m_volumeINV = 1.0/m_volume; 27 | 28 | m_moi[0] = 0.2*m_volume*(m_radiusb*m_radiusb + m_radiusc*m_radiusc); 29 | m_moi[4] = 0.2*m_volume*(m_radiusa*m_radiusa + m_radiusc*m_radiusc); 30 | m_moi[8] = 0.2*m_volume*(m_radiusa*m_radiusa + m_radiusb*m_radiusb); 31 | m_moiINV = Foam::inv(m_moi); 32 | m_radiusB = std::max(std::max(m_radiusa, m_radiusb),m_radiusc); 33 | } 34 | inline scalar getRadiusa() const { return m_radiusa;} 35 | inline scalar getRadiusb() const { return m_radiusb;} 36 | inline scalar getRadiusc() const { return m_radiusc;} 37 | inline scalar getVolume() const { return m_volume;} 38 | 39 | SHAPETYPENAME("Ellipsoid") 40 | virtual std::string description() const override {return "ellipsoid, [ra, rb, rc] = " + std::to_string(m_radiusa) + ", " + std::to_string(m_radiusb) + ", " + std::to_string(m_radiusc);} 41 | 42 | // implement interface 43 | virtual inline bool isInside(const vector& p) const override 44 | { 45 | return sdf::ellipsoid_bool_fast(p, m_radiusaSQRINV, m_radiusbSQRINV, m_radiuscSQRINV); 46 | } 47 | 48 | virtual inline scalar signedDistance(const vector& p) const override 49 | { 50 | return sdf::filter( 51 | sdf::ellipsoid( p, m_radiusaSQRINV, m_radiusbSQRINV, m_radiuscSQRINV) 52 | ); 53 | } 54 | }; 55 | 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /src/libshape/ishape.h: -------------------------------------------------------------------------------- 1 | #ifndef ISHAPE_H 2 | #define ISHAPE_H 3 | 4 | #include "../types.h" 5 | #include "./sdf/sdf.h" 6 | #include 7 | #include 8 | namespace sdfibm { 9 | 10 | #define SHAPETYPENAME(name) \ 11 | static std::string typeName() {return name;} \ 12 | static bool added; \ 13 | virtual std::string getTypeName() const {return name;} 14 | 15 | class IShape; 16 | 17 | template 18 | class _shapecreator 19 | { 20 | public: 21 | static std::unique_ptr create(const dictionary& para) 22 | { 23 | return std::make_unique(para); 24 | } 25 | }; 26 | 27 | class IShape 28 | { 29 | public: 30 | struct Transformation {vector t; quaternion q;}; 31 | const static int m_id = -1; 32 | scalar m_radiusB {0.0}; // radius of bounding sphere 33 | scalar m_volume {0.0}; 34 | scalar m_volumeINV {0.0}; 35 | vector m_com {vector::zero}; 36 | tensor m_moi {tensor::I}; // in principal frame, diagonal 37 | tensor m_moiINV {tensor::I}; 38 | bool finite {true}; 39 | 40 | public: 41 | SHAPETYPENAME("IShape"); 42 | 43 | inline static vector world2local(const vector& p, const Transformation& tr) 44 | { 45 | return Foam::conjugate(tr.q).transform(p - tr.t); 46 | } 47 | 48 | virtual int getShapeID() const {return m_id;} 49 | virtual scalar getRadiusB() const {return m_radiusB;} 50 | 51 | bool phi01(const vector& p, const Transformation& tr) { return isInside (world2local(p, tr)); } 52 | scalar phi(const vector& p, const Transformation& tr) { return signedDistance(world2local(p, tr)); } 53 | 54 | virtual std::string description() const = 0; 55 | 56 | virtual ~IShape(){} 57 | 58 | private: 59 | virtual bool isInside (const vector& p) const = 0; // local coordinate 60 | virtual scalar signedDistance(const vector& p) const = 0; // local coordinate 61 | }; 62 | 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /src/libshape/plane.h: -------------------------------------------------------------------------------- 1 | #ifndef PLANE_H 2 | #define PLANE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm { 6 | 7 | class Plane : public IShape, _shapecreator 8 | { 9 | private: 10 | 11 | public: 12 | // const static int shape_id = SHAPE::CIRC; 13 | Plane(const dictionary& para) {finite = false;} 14 | 15 | // typename and description 16 | SHAPETYPENAME("Plane") 17 | virtual std::string description() const override {return "Plane (x-z plane)";} 18 | 19 | // implement interface 20 | virtual inline bool isInside(const vector& p) const override 21 | { 22 | return p.y() < 0; 23 | } 24 | 25 | virtual inline scalar signedDistance(const vector& p) const override 26 | { 27 | return p.y(); 28 | } 29 | }; 30 | 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /src/libshape/rectangle.h: -------------------------------------------------------------------------------- 1 | #ifndef RECTANGLE_H 2 | #define RECTANGLE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm{ 6 | 7 | class Rectangle : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radiusa, m_radiusb; 11 | scalar m_radiusaSQR; 12 | scalar m_radiusbSQR; 13 | 14 | public: 15 | // const static int shape_id = SHAPE::CIRC; 16 | Rectangle(const dictionary& para) 17 | { 18 | m_radiusa = Foam::readScalar(para.lookup("radiusa")); 19 | m_radiusb = Foam::readScalar(para.lookup("radiusb")); 20 | m_com = para.lookupOrDefault("com", vector::zero); 21 | m_radiusaSQR = m_radiusa * m_radiusa; 22 | m_radiusbSQR = m_radiusb * m_radiusb; 23 | 24 | // set inherited variables 25 | m_volume = 4.0*m_radiusa*m_radiusb; 26 | m_volumeINV = 1.0/m_volume; 27 | 28 | scalar tmp = 1.0/3.0*m_volume*(m_radiusaSQR + m_radiusbSQR); 29 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 30 | m_moiINV = Foam::inv(m_moi); 31 | m_radiusB = std::max(m_radiusa, m_radiusb); 32 | } 33 | inline scalar getRadiusa() const { return m_radiusa;} 34 | inline scalar getRadiusb() const { return m_radiusb;} 35 | inline scalar getVolume() const { return m_volume;} 36 | 37 | // implement interface 38 | SHAPETYPENAME("Rectangle") 39 | virtual std::string description() const override {return "rectangle (x-y plane), [ra, rb] = " + std::to_string(m_radiusa) + ", " + std::to_string(m_radiusb);} 40 | 41 | virtual inline bool isInside(const vector& p) const override 42 | { 43 | vector p2d = m_com + p; p2d.z() = 0.0; 44 | return sdf::rectangle_bool( 45 | p2d, 46 | m_radiusa, 47 | m_radiusb); 48 | } 49 | 50 | virtual inline scalar signedDistance(const vector& p) const override 51 | { 52 | vector p2d = m_com + p; p2d.z() = 0.0; 53 | return sdf::filter(sdf::rectangle( 54 | p2d, 55 | m_radiusa, 56 | m_radiusb) 57 | ); 58 | } 59 | }; 60 | 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /src/libshape/sdf/sdf.h: -------------------------------------------------------------------------------- 1 | #include "vector.H" 2 | 3 | /* This namespace collects sdf-related functions (mostly inlined for efficency). */ 4 | namespace sdf 5 | { 6 | using Foam::scalar; 7 | using Foam::vector; 8 | 9 | const scalar TOL = 1e-8; 10 | /********************************************************************************************* 11 | * Shape primitives * 12 | * Note: all sdf are calculated in the object space * 13 | ********************************************************************************************/ 14 | // circle 15 | inline bool circle_bool(const vector& p, const scalar& r) 16 | { 17 | return Foam::magSqr(p) < r*r; 18 | } 19 | inline bool circle_bool_fast(const vector& p, const scalar& rSQR) 20 | { 21 | return Foam::magSqr(p) < rSQR; 22 | } 23 | inline scalar circle(const vector& p, const scalar& r) 24 | { 25 | return Foam::mag(p) - r; 26 | } 27 | 28 | // rectangle 29 | inline scalar rectangle_bool(const vector& p, const scalar& ra, const scalar& rb) 30 | { 31 | return std::fabs(p.x()) < ra && std::fabs(p.y()) < rb; 32 | } 33 | inline scalar rectangle(const vector& p, const scalar& ra, const scalar& rb) 34 | { 35 | scalar dx = std::fabs(p.x()) - ra; 36 | scalar dy = std::fabs(p.y()) - rb; 37 | scalar dxp = std::max(0.0, dx); 38 | scalar dyp = std::max(0.0, dy); 39 | return std::sqrt(dxp*dxp + dyp*dyp) + std::min(0.0, std::max(dx, dy)); 40 | } 41 | 42 | // box 43 | inline scalar box_bool(const vector& p, const scalar& ra, const scalar& rb, const scalar& rc) 44 | { 45 | return std::fabs(p.x()) < ra && std::fabs(p.y()) < rb && std::fabs(p.z()) < rc; 46 | } 47 | inline scalar box(const vector& p, const scalar& ra, const scalar& rb, const scalar& rc) 48 | { 49 | scalar dx = std::fabs(p.x()) - ra; 50 | scalar dy = std::fabs(p.y()) - rb; 51 | scalar dz = std::fabs(p.z()) - rc; 52 | scalar dxp = std::max(0.0, dx); 53 | scalar dyp = std::max(0.0, dy); 54 | scalar dzp = std::max(0.0, dz); 55 | return std::sqrt(dxp*dxp+dyp*dyp+dzp*dzp)+std::min(0.0,std::max(dz,std::max(dx, dy))); 56 | } 57 | 58 | // ellipse 59 | inline scalar ellipse_bool_fast(const vector& p, const scalar& raSQRINV, const scalar& rbSQRINV) 60 | { 61 | return p.x()*p.x()*raSQRINV + p.y()*p.y()*rbSQRINV < 1.0; 62 | } 63 | inline scalar ellipse(const vector& p, const scalar& raSQRINV, const scalar& rbSQRINV) 64 | { 65 | // raSQRINV = 1/(a*a) and so on 66 | scalar xbyaSQR = p.x()*p.x()*raSQRINV; // (x/a)^2 67 | scalar ybybSQR = p.y()*p.y()*rbSQRINV; // (y/b)^2 68 | return 0.5*(xbyaSQR+ybybSQR-1.0)/(std::sqrt(xbyaSQR*raSQRINV+ybybSQR*rbSQRINV)); 69 | } 70 | 71 | // ellipsoid 72 | inline scalar ellipsoid_bool_fast(const vector& p, const scalar& raSQRINV, const scalar& rbSQRINV, const scalar& rcSQRINV) 73 | { 74 | return p.x()*p.x()*raSQRINV + p.y()*p.y()*rbSQRINV + p.z()*p.z()*rcSQRINV < 1.0; 75 | } 76 | inline scalar ellipsoid(const vector& p, const scalar& raSQRINV, const scalar& rbSQRINV, const scalar& rcSQRINV) 77 | { 78 | // raSQRINV = 1/(a*a), and so on 79 | scalar xbyaSQR = p.x()*p.x()*raSQRINV; // (x/a)^2 80 | scalar ybybSQR = p.y()*p.y()*rbSQRINV; // (y/b)^2 81 | scalar zbycSQR = p.z()*p.z()*rcSQRINV; // (z/c)^2 82 | return 0.5*(xbyaSQR+ybybSQR+zbycSQR-1.0)/(std::sqrt(xbyaSQR*raSQRINV+ybybSQR*rbSQRINV+zbycSQR*rcSQRINV)); 83 | } 84 | 85 | /********************************************************************************************* 86 | * Transformations * 87 | * Note: to transform the field, the point transformation is reversed. * 88 | * For example, to rotate the field +30\degree, hte point is rotated -30\degree. * 89 | ********************************************************************************************/ 90 | // rotation 91 | inline vector rot30(const vector& p) 92 | { 93 | return vector(0.866025404*p.x()+0.5*p.y(), 0.866025404*p.y()-0.5*p.x(), 0.0); 94 | } 95 | inline vector rot45(const vector& p) 96 | { 97 | return 0.707106781*vector(p.x()+p.y(),-p.x()+p.y(), 0.0); 98 | } 99 | inline vector rot60(const vector& p) 100 | { 101 | return vector(0.866025404*p.y()+0.5*p.x(),-0.866025404*p.x()+0.5*p.y(), 0.0); 102 | } 103 | inline vector rot90(const vector& p) 104 | { 105 | return vector(p.y(), -p.x(), 0.0); 106 | } 107 | inline vector rotth(const vector& p, const scalar& th) 108 | { 109 | scalar s = std::sin(th); 110 | scalar c = std::cos(th); 111 | return vector(p.x()*c+p.y()*s,-p.x()*s+p.y()*c, 0.0); 112 | } 113 | 114 | // reflection 115 | inline vector flipy(const vector& p) 116 | { 117 | return vector( p.x(), -p.y(), p.z()); 118 | } 119 | inline vector flipx(const vector& p) 120 | { 121 | return vector(-p.x(), p.y(), p.z()); 122 | } 123 | inline vector offset(const vector& p, const vector& offset) 124 | { 125 | return p - offset; 126 | } 127 | 128 | /********************************************************************************************* 129 | * Boolean Operations * 130 | * Note: the operation on Boolean and floating point values are different * 131 | ********************************************************************************************/ 132 | // difference (a binary operation) 133 | inline scalar D(const scalar& d1, const scalar& d2) { return std::max(d1,-d2);} 134 | inline bool D(bool d1, bool d2 ) { return d1 && (!d2);} 135 | 136 | // union 137 | inline scalar U(const std::initializer_list& phis) {return std::min(phis);} 138 | inline bool U(const std::initializer_list & phis) {return std::max(phis);} 139 | 140 | // intersection 141 | inline scalar I(const std::initializer_list& phis) {return std::max(phis);} 142 | inline bool I(const std::initializer_list & phis) {return std::min(phis);} 143 | 144 | /********************************************************************************************* 145 | * Helper functions * 146 | ********************************************************************************************/ 147 | inline scalar filter(const scalar& phi) 148 | { 149 | return (std::fabs(phi)b) ? b: ((x 7 | #include 8 | namespace sdfibm { 9 | MAKESPECIALFACTORY(Shape, IShape, Foam::dictionary); 10 | 11 | #define REGISTERSHAPE(m) \ 12 | bool sdfibm::m::added = ShapeFactory::add(sdfibm::m::typeName(), sdfibm::m::create); 13 | 14 | #include "circle.h" 15 | REGISTERSHAPE(Circle); 16 | 17 | #include "sphere.h" 18 | REGISTERSHAPE(Sphere); 19 | 20 | #include "ellipse.h" 21 | REGISTERSHAPE(Ellipse); 22 | 23 | #include "ellipsoid.h" 24 | REGISTERSHAPE(Ellipsoid); 25 | 26 | #include "rectangle.h" 27 | REGISTERSHAPE(Rectangle); 28 | 29 | #include "circle_tail.h" 30 | REGISTERSHAPE(Circle_Tail); 31 | 32 | #include "circle_twotail.h" 33 | REGISTERSHAPE(Circle_TwoTail); 34 | 35 | #include "box.h" 36 | REGISTERSHAPE(Box); 37 | 38 | #include "plane.h" 39 | REGISTERSHAPE(Plane); 40 | } 41 | -------------------------------------------------------------------------------- /src/libshape/sphere.h: -------------------------------------------------------------------------------- 1 | #ifndef SPHERE_H 2 | #define SPHERE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm { 6 | 7 | class Sphere : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radius; 11 | scalar m_radiusSQR; 12 | 13 | public: 14 | Sphere(const dictionary& para) 15 | { 16 | m_radius = Foam::readScalar(para.lookup("radius")); 17 | m_com = para.lookupOrDefault("com", vector::zero); 18 | 19 | m_radiusSQR = m_radius * m_radius; 20 | 21 | m_volume = 4.0/3.0*M_PI*m_radiusSQR*m_radius; 22 | m_volumeINV = 1.0/m_volume; 23 | 24 | scalar tmp = 0.4*m_volume*m_radiusSQR; 25 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; 26 | 27 | m_moiINV = Foam::inv(m_moi); 28 | m_radiusB = m_radius; 29 | } 30 | 31 | inline scalar getRadius() const { return m_radius;} 32 | inline scalar getVolume() const { return m_volume;} 33 | 34 | SHAPETYPENAME("Sphere") 35 | virtual std::string description() const override {return "sphere, r = " + std::to_string(m_radius);} 36 | 37 | virtual inline bool isInside(const vector& p) const 38 | { 39 | return sdf::circle_bool_fast(m_com + p, m_radiusSQR); 40 | } 41 | 42 | virtual inline scalar signedDistance(const vector& p) const 43 | { 44 | return sdf::filter(sdf::circle(m_com + p, m_radius)); 45 | } 46 | 47 | }; 48 | 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/libshape/template.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANGE_H 2 | #define CHANGE_H 3 | 4 | #include "ishape.h" 5 | namespace sdfibm{ 6 | 7 | class CHANGE : public IShape, _shapecreator 8 | { 9 | private: 10 | scalar m_radius; // define properties of your shape CHANGE 11 | 12 | public: 13 | // const static int shape_id = SHAPE::CIRC; 14 | CHANGE(const dictionary& para) 15 | { 16 | // fetch needed property from para 17 | m_radius = Foam::readScalar(para.lookup("radius")); // CHANGE 18 | m_com = para.lookupOrDefault("com", vector::zero); 19 | 20 | m_volume = M_PI*m_radiusSQR; // volume of your shape CHANGE 21 | m_volumeINV = 1.0/m_volume; 22 | scalar tmp = 0.5*m_volume*m_radiusSQR; // moi of your shape CHANGE 23 | m_moi[0] = tmp; m_moi[4] = tmp; m_moi[8] = tmp; // moi of your shape CHANGE 24 | m_moiINV = Foam::inv(m_moi); 25 | m_radiusB = m_radius; // bounding radius of your shape CHANGE 26 | } 27 | // how to get properties of your shape 28 | inline scalar getRadius() const { return m_radius;} 29 | inline scalar getVolume() const { return m_volume;} 30 | 31 | // typename and description 32 | SHAPETYPENAME("CHANGE") 33 | // describe your shape 34 | virtual std::string description() const override {return "CHANGE r = " + std::to_string(m_radius);} // CHANGE 35 | 36 | // implement interface 37 | virtual inline bool isInside( 38 | const vector& p, 39 | const vector& shape_center, 40 | const quaternion& shape_orientation) const override 41 | { 42 | // tell if a point is inside or outside of your shape 43 | return _sdf_circle_bool_fast(m_com + vector(p.x(), p.y(),0.0)-shape_center, m_radiusSQR); // CHANGE 44 | } 45 | 46 | virtual inline scalar signedDistance( 47 | const vector& p, 48 | const vector& shape_center, 49 | const quaternion& shape_orientation) const override 50 | { 51 | // sdf of your shape, final result must be wrapped by _sdf_filter to 52 | // avoid possible floating-point error 53 | return _sdf_filter(_sdf_circle_real(m_com + vector(p.x(), p.y(),0.0)-shape_center, m_radius)); // CHANGE 54 | } 55 | }; 56 | 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /src/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "logger.h" 2 | #include 3 | 4 | namespace sdfibm { 5 | Logger *Logger::m_this = nullptr; 6 | const std::string Logger::m_logfilename = "cloud.log"; 7 | std::ofstream Logger::m_logfile; 8 | } // namespace sdfibm 9 | -------------------------------------------------------------------------------- /src/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGGER_H 2 | #define LOGGER_H 3 | // adapted from: https://cppcodetips.wordpress.com/2014/01/02/a-simple-logger-class-in-c/ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "utils.h" 11 | 12 | #define LOG(m) Logger::GetLogger()->log(m) 13 | #define LOGF Logger::m_logfile 14 | 15 | namespace sdfibm { 16 | 17 | class Logger 18 | { 19 | public: 20 | void log(const std::string& msg) 21 | { 22 | m_logfile << '[' << GetTimeString() << "]\t" << msg << '\n'; 23 | } 24 | static Logger* GetLogger() 25 | { 26 | if (m_this == nullptr) 27 | { 28 | m_this = new Logger(); 29 | m_logfile.open(m_logfilename, std::ios::out); 30 | } 31 | return m_this; 32 | } 33 | ~Logger() 34 | { 35 | m_logfile.close(); 36 | } 37 | static const std::string m_logfilename; 38 | static std::ofstream m_logfile; 39 | 40 | private: 41 | Logger(){} 42 | Logger(const Logger&){} 43 | Logger& operator=(const Logger&){return *this;} 44 | 45 | static Logger* m_this; 46 | }; 47 | 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "fvMesh.H" 2 | #include "Time.H" 3 | #include "argList.H" // TODO: add some cmd arguments 4 | #include "findRefCell.H" 5 | #include "adjustPhi.H" 6 | 7 | #include "fvcGrad.H" 8 | 9 | #include "fvmDdt.H" 10 | #include "fvmDiv.H" 11 | #include "fvmLaplacian.H" 12 | 13 | #include "solidcloud.h" 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | #include "setRootCase.H" 18 | #include "createTime.H" 19 | #include "createMesh.H" 20 | #include "createFields.h" 21 | #include "initContinuityErrs.H" 22 | 23 | std::string dictfile; 24 | 25 | // if start-time > 0, read from start-time-folder for solidDict, otherwise read from case root 26 | if (runTime.time().value() > 0) 27 | { 28 | if (!Foam::Pstream::parRun()) 29 | dictfile = mesh.time().name() + "/solidDict"; 30 | else 31 | dictfile = "processor0/" + mesh.time().name() + "/solidDict"; 32 | } 33 | else 34 | { 35 | dictfile = "solidDict"; 36 | } 37 | 38 | sdfibm::SolidCloud solidcloud(runTime.globalPath() + "/" + dictfile, U, runTime.value()); 39 | solidcloud.saveState(); // write the initial condition 40 | 41 | while (runTime.loop()) 42 | { 43 | Foam::Info << "Time = " << runTime.name() << Foam::endl; 44 | 45 | #include "CourantNo.H" 46 | Foam::dimensionedScalar dt = runTime.deltaT(); 47 | 48 | if (solidcloud.isOnFluid()) 49 | { 50 | Foam::fvVectorMatrix UEqn(fvm::ddt(U) + 1.5 * fvc::div(phi, U) - 51 | 0.5 * fvc::div(phi.oldTime(), U.oldTime()) == 52 | 0.5 * fvm::laplacian(nu, U) + 0.5 * fvc::laplacian(nu, U)); 53 | UEqn.solve(); 54 | 55 | phi = linearInterpolate(U) & mesh.Sf(); 56 | Foam::fvScalarMatrix pEqn(fvm::laplacian(p) == fvc::div(phi) / dt - fvc::div(Fs)); 57 | pEqn.solve(); 58 | 59 | U = U - dt * fvc::grad(p); 60 | phi = phi - dt * fvc::snGrad(p) * mesh.magSf(); 61 | 62 | Foam::fvScalarMatrix TEqn(fvm::ddt(T) + fvm::div(phi, T) == fvm::laplacian(alpha, T)); 63 | TEqn.solve(); 64 | } 65 | 66 | solidcloud.interact(runTime.value(), dt.value()); 67 | 68 | if (solidcloud.isOnFluid()) 69 | { 70 | U = U - Fs * dt; 71 | phi = phi - dt * (linearInterpolate(Fs) & mesh.Sf()); 72 | 73 | U.correctBoundaryConditions(); 74 | adjustPhi(phi, U, p); 75 | 76 | T = (1.0 - As) * T + Ts; 77 | T.correctBoundaryConditions(); 78 | 79 | #include "continuityErrs.H" 80 | } 81 | 82 | solidcloud.evolve(runTime.value(), dt.value()); 83 | solidcloud.saveState(); 84 | 85 | if (solidcloud.isOnFluid()) 86 | { 87 | solidcloud.fixInternal(dt.value()); 88 | } 89 | 90 | if (runTime.writeTime()) 91 | { 92 | runTime.write(); 93 | 94 | if (Foam::Pstream::master()) 95 | { 96 | std::string file_name; 97 | if (Foam::Pstream::parRun()) 98 | file_name = "./processor0/" + runTime.name() + "/solidDict"; 99 | else 100 | file_name = "./" + runTime.name() + "/solidDict"; 101 | solidcloud.saveRestart(file_name); 102 | } 103 | } 104 | } 105 | 106 | Foam::Info << "DONE\n" << Foam::endl; 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /src/meshinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "meshinfo.h" 2 | -------------------------------------------------------------------------------- /src/meshinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef MESHINFO_H 2 | #define MESHINFO_H 3 | 4 | #include "fvc.H" 5 | 6 | namespace sdfibm { 7 | 8 | class MeshInfo 9 | { 10 | protected: 11 | const Foam::fvMesh& m_mesh; 12 | const Foam::labelListList& m_c2c; // cell to cell connectivity 13 | const Foam::labelListList& m_c2p; // cell to point connectivity 14 | const Foam::pointField & m_pp; // mesh points 15 | const Foam::vectorField & m_cc; // mesh centers 16 | const Foam::scalarField & m_cv; // cell volumes 17 | const Foam::vectorField & m_fc; // face centers 18 | const Foam::vectorField & m_fa; // face areas 19 | public: 20 | MeshInfo(const Foam::fvMesh& mesh): 21 | m_mesh(mesh), 22 | m_c2c(mesh.cellCells()), 23 | m_c2p(mesh.cellPoints()), 24 | m_pp(mesh.points()), 25 | m_cc(mesh.cellCentres()), 26 | m_cv(mesh.V()), 27 | m_fc(mesh.faceCentres()), 28 | m_fa(mesh.faceAreas()) 29 | {} 30 | }; 31 | 32 | } 33 | #endif // MESHINFO_H 34 | -------------------------------------------------------------------------------- /src/solid.cpp: -------------------------------------------------------------------------------- 1 | #include "solid.h" 2 | 3 | namespace sdfibm { 4 | 5 | std::ostream& operator<<(std::ostream& os, const Solid& s) 6 | { 7 | vector v; 8 | v = s.getCenter(); os << v.x() << ' ' << v.y() << ' ' << v.z() << ' '; 9 | v = s.getVelocity();os << v.x() << ' ' << v.y() << ' ' << v.z() << ' '; 10 | v = s.getForce(); os << v.x() << ' ' << v.y() << ' ' << v.z() << ' '; 11 | 12 | v = s.getOrientation().eulerAngles(quaternion::XYZ); 13 | os << v.x() << ' ' << v.y() << ' ' << v.z() << ' '; 14 | v = s.getOmega(); os << v.x() << ' ' << v.y() << ' ' << v.z() << ' '; 15 | v = s.getTorque(); os << v.x() << ' ' << v.y() << ' ' << v.z(); 16 | return os; 17 | } 18 | 19 | void write2D(std::ostream& os, const Solid& s) 20 | { 21 | vector v; 22 | v = s.getCenter(); os << v.x() << ' ' << v.y() << ' '; 23 | v = s.getVelocity();os << v.x() << ' ' << v.y() << ' '; 24 | v = s.getForce(); os << v.x() << ' ' << v.y() << ' '; 25 | v = s.getOrientation().eulerAngles(quaternion::XYZ); 26 | os << v.z() << ' '; 27 | v = s.getOmega(); os << v.z() << ' '; 28 | v = s.getTorque(); os << v.z(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/solid.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLID_H_INCLUDED 2 | #define SOLID_H_INCLUDED 3 | 4 | #include "types.h" 5 | #include "./libshape/ishape.h" 6 | #include "./libmotion/imotion.h" 7 | #include "./libmaterial/imaterial.h" 8 | #include "./libforcer/iforcer.h" 9 | #include "utils.h" 10 | #include "fvc.H" 11 | 12 | namespace sdfibm { 13 | 14 | class Solid 15 | { 16 | protected: 17 | label id; // integer label 18 | label hostid {-1}; // id of the mesh cell that host the solid center 19 | 20 | // state 21 | vector center; 22 | quaternion orientation; 23 | 24 | // state's 1st time derivative 25 | vector velocity {vector::zero}; 26 | vector omega {vector::zero}; 27 | 28 | // state's 2nd time derivative 29 | vector force {vector::zero}; 30 | vector torque {vector::zero}; 31 | 32 | // fluid only force 33 | vector fluid_force {vector::zero}; 34 | vector fluid_torque {vector::zero}; 35 | // fluid only force from last time step 36 | vector fluid_force_old {vector::zero}; 37 | vector fluid_torque_old {vector::zero}; 38 | bool first_fluid_step {true}; 39 | 40 | vector forcer_force {vector::zero}; 41 | vector forcer_torque {vector::zero}; 42 | vector forcer_force_old {vector::zero}; 43 | vector forcer_torque_old {vector::zero}; 44 | bool first_forcer_step {true}; 45 | 46 | // property pointers 47 | IMotion* ptr_motion {nullptr}; 48 | IShape* ptr_shape {nullptr}; 49 | forcer::IForcer* ptr_forcer {nullptr}; 50 | IMaterial* ptr_material {nullptr}; 51 | 52 | // object properties = shape x material 53 | scalar mass {0}; 54 | scalar mass_inv {0}; 55 | tensor moi_inv {tensor::I}; 56 | 57 | public: 58 | // getters 59 | inline label getID() const {return id;} 60 | inline const vector& getCenter() const {return center;} 61 | inline const vector& getVelocity() const {return velocity;} 62 | inline const vector& getOmega() const {return omega;} 63 | inline const vector& getForce() const {return force;} 64 | inline const vector& getTorque() const {return torque;} 65 | inline const quaternion& getOrientation() const {return orientation;} 66 | 67 | inline const vector& getFluidForce() {return fluid_force; } 68 | inline const vector& getFluidTorque() {return fluid_torque; } 69 | 70 | // setters 71 | inline void setCenter (const vector& c){ center = c; } 72 | inline void setVelocity(const vector& v){ velocity = v; } 73 | inline void setOmega (const vector& o){ omega = o; } 74 | inline void setForce (const vector& f){ force = f; } 75 | inline void setTorque (const vector& t){ torque= t; } 76 | inline void setOrientation(const vector& angles) 77 | { 78 | // from a fixed order of Euler angles 79 | orientation = quaternion(quaternion::XYZ, angles); 80 | } 81 | 82 | inline IMotion* getMotion() const {return ptr_motion; } 83 | inline IShape* getShape() const {return ptr_shape; } 84 | inline IMaterial* getMaterial() const {return ptr_material;} 85 | inline scalar getRadiusB() const {return ptr_shape->getRadiusB();} 86 | inline bool isFinite() const {return ptr_shape->finite;} 87 | 88 | inline void setShape(IShape* shape) { 89 | ptr_shape = shape; 90 | } 91 | void setForcer(forcer::IForcer* forcer) 92 | { 93 | ptr_forcer = forcer; 94 | } 95 | inline void setMaterial(IMaterial* material) 96 | { 97 | ptr_material = material; 98 | 99 | scalar rho = ptr_material->getRho(); 100 | mass = ptr_shape->m_volume * rho; 101 | mass_inv = ptr_shape->m_volumeINV / rho; 102 | moi_inv = ptr_shape->m_moiINV / rho; 103 | } 104 | 105 | // control of solid motion 106 | inline void setMotion(IMotion* solid_motion) { ptr_motion = solid_motion; } 107 | inline void unsetMotion() { ptr_motion = nullptr; } 108 | 109 | // sdf01 at point, true if inside 110 | inline bool phi01(const vector& p) const 111 | { 112 | return ptr_shape->phi01(p, {center, orientation}); 113 | } 114 | 115 | // sdf at point, negative if inside 116 | inline scalar phi(const vector& p) const 117 | { 118 | return ptr_shape->phi(p, {center, orientation}); 119 | } 120 | 121 | inline vector evalPointVelocity(const vector& p) const 122 | { 123 | return velocity + (omega^(p - center)); 124 | } 125 | 126 | inline void addAcceleration(const vector& acc) 127 | { 128 | // dedicated to body force which needs the (priviate) mass info 129 | force += mass*acc; 130 | } 131 | inline void clearForceAndTorque() 132 | { 133 | force = vector::zero; 134 | torque = vector::zero; 135 | } 136 | inline void setFluidForceAndTorque(const vector& fluid_force_in, const vector& fluid_torque_in) 137 | { 138 | fluid_force = fluid_force_in; 139 | fluid_torque = fluid_torque_in; 140 | } 141 | inline void storeOldForce() 142 | { 143 | fluid_force_old = fluid_force; 144 | fluid_torque_old = fluid_torque; 145 | forcer_force_old = forcer_force; 146 | forcer_torque_old = forcer_torque; 147 | } 148 | inline void applyForcer(scalar& time) 149 | { 150 | if (!ptr_forcer) 151 | return; 152 | auto [f_,t_] = ptr_forcer->generate(time, center, velocity, orientation, omega); 153 | forcer_force = f_; 154 | forcer_torque = t_; 155 | if (first_forcer_step) 156 | { 157 | forcer_force_old = forcer_force; 158 | forcer_torque_old = forcer_torque; 159 | first_forcer_step = false; 160 | } 161 | force += (1.5*forcer_force - 0.5*forcer_force_old); 162 | torque += (1.5*forcer_torque - 0.5*forcer_torque_old); 163 | } 164 | inline void addMidFluidForceAndTorque() 165 | { 166 | if (first_fluid_step) 167 | { 168 | fluid_force_old = fluid_force; 169 | fluid_torque_old = fluid_torque; 170 | first_fluid_step = false; 171 | } 172 | force += (1.5*fluid_force - 0.5*fluid_force_old); 173 | torque += (1.5*fluid_torque - 0.5*fluid_torque_old); 174 | } 175 | inline void addForceAndTorque(const vector& external_force, const vector& external_torque) 176 | { 177 | force += external_force; 178 | torque += external_torque; 179 | } 180 | 181 | void move(const scalar& time, const scalar& dt) 182 | { 183 | // motion = velocity & omega 184 | // temporarily store motion at time n 185 | vector velocity_old = velocity; 186 | vector omega_old = omega; 187 | 188 | // update motion to n+1 using force at time n+1/2 189 | velocity += force*mass_inv*dt; // velocity updated to t + dt 190 | tensor R = orientation.R(); 191 | tensor moi_inv_world = R & moi_inv & R.T(); 192 | omega += (moi_inv_world & torque)*dt; // omega updated to t + dt 193 | 194 | // constrain motion 195 | if(ptr_motion != nullptr) 196 | ptr_motion->constraint(time, velocity, omega); 197 | 198 | // position & orientation updated AFTER constraint 199 | center += 0.5*(velocity + velocity_old)*dt; 200 | orientation += 0.5*quaternion(0.5*(omega + omega_old))*orientation*dt; 201 | orientation.normalise(); // no need to normalise every step, but cheap anyway 202 | } 203 | 204 | Solid(label solid_id, 205 | const vector& solid_center, 206 | const quaternion& solid_quaternion): 207 | id (solid_id), 208 | center (solid_center), 209 | orientation (solid_quaternion) 210 | { 211 | } 212 | 213 | ~Solid(){} 214 | friend std::ostream& operator<<(std::ostream& os, const Solid& s); 215 | friend void write2D(std::ostream& os, const Solid& s); 216 | }; 217 | 218 | } 219 | #endif 220 | -------------------------------------------------------------------------------- /src/solidcloud.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLIDCLOUD_H 2 | #define SOLIDCLOUD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "dimensionedScalar.H" 10 | #include "fvm.H" 11 | #include "types.h" 12 | #include "solid.h" 13 | 14 | #include "utils.h" 15 | #include "logger.h" 16 | #include "geometrictools.h" 17 | #include "cellenumerator.h" 18 | 19 | #include "entitylibrary.h" 20 | 21 | #include "./libcollision/ugrid.h" 22 | #include "./libcollision/bbox.h" 23 | #include "./libcollision/collision.h" 24 | 25 | class IMotion; 26 | class IMaterial; 27 | class IShape; 28 | 29 | namespace sdfibm::forcer { 30 | class IForcer; 31 | } 32 | 33 | namespace sdfibm { 34 | 35 | class SolidCloud 36 | { 37 | private: 38 | bool m_ON_FLUID; 39 | bool m_ON_TWOD; 40 | bool m_ON_VOFONLY; 41 | bool m_ON_RESTART; 42 | bool m_ON_MEANFIELD {false}; 43 | 44 | unsigned int m_timeStepCounter; 45 | unsigned int m_writeFrequency; 46 | scalar m_time; 47 | std::string m_sampler; 48 | 49 | std::vector m_solids; 50 | dictionary m_solidDict; 51 | 52 | // collision handling 53 | BBox* m_ptr_bbox; 54 | UGrid* m_ptr_ugrid; 55 | std::vector collision_pairs; 56 | scalar m_radiusB; 57 | 58 | // environmental info 59 | vector m_gravity; 60 | scalar m_rhof; 61 | 62 | // variables on mesh 63 | const Foam::fvMesh& m_mesh; 64 | Foam::volVectorField& m_Uf; 65 | Foam::volScalarField& m_ct; 66 | Foam::volScalarField& m_As; 67 | Foam::volVectorField& m_Fs; 68 | Foam::volScalarField& m_Ts; 69 | 70 | GeometricTools m_geotools; 71 | std::unique_ptr m_ms; 72 | 73 | std::map m_libmotion; 74 | std::map m_libmat; 75 | EntityLibrary m_libshape; 76 | EntityLibrary m_libforcer; 77 | std::ofstream statefile; 78 | std::ofstream meanFieldFile; 79 | 80 | void solidSolidInteract(); 81 | void solidSolidCollision(Solid& s1, Solid& s2); 82 | void resolveCollisionPairs(); 83 | 84 | void solidFluidInteract(Solid& s, scalar dt); 85 | void solidFluidCorrect (Solid& s, scalar dt); 86 | template 87 | Type calcMeanField(Solid& s, IShape* shape, const Foam::GeometricField& field); 88 | 89 | public: 90 | SolidCloud(const Foam::word& dictfile, Foam::volVectorField& U, scalar time); 91 | ~SolidCloud(); 92 | 93 | // setup 94 | inline void addSolid(Solid&& solid) { m_solids.emplace_back(solid); } 95 | void addBoundingBox(const BBox& particle_bbox); 96 | 97 | // io 98 | void saveState(); 99 | void initFromDictionary(const Foam::word& dictname); 100 | void saveRestart(const std::string& filename); 101 | const Solid& operator[](label i) const; 102 | 103 | // info 104 | void checkAlpha() const; 105 | scalar totalSolidVolume() const; 106 | bool inline isOnFluid() const {return m_ON_FLUID;} 107 | bool inline isOnTwoD() const {return m_ON_TWOD;} 108 | 109 | // time stepping 110 | void storeOld(); 111 | void restoreOld(); 112 | void writeMeanField(); 113 | void evolve (scalar time, scalar dt); 114 | void interact(scalar time, scalar dt); 115 | void addMidEnvironment(); 116 | void fixInternal(scalar dt); 117 | void initialCorrect(); 118 | 119 | friend std::ostream& operator<<(std::ostream& os, const SolidCloud& sc); 120 | 121 | // deleted methods 122 | SolidCloud (const SolidCloud&) = delete; 123 | SolidCloud& operator=(const SolidCloud&) = delete; 124 | }; 125 | 126 | } 127 | #endif 128 | -------------------------------------------------------------------------------- /src/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include "tensor.H" 5 | #include "vector.H" 6 | #include "quaternion.H" 7 | #include "dictionary.H" 8 | #include 9 | 10 | namespace sdfibm { 11 | 12 | using Foam::label; 13 | using Foam::scalar; 14 | using Foam::vector; 15 | using Foam::tensor; 16 | using Foam::quaternion; 17 | using Foam::dictionary; 18 | 19 | constexpr scalar SMALL = 1e-6; 20 | 21 | } // namespace sdfibm 22 | #endif // TYPES_H 23 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include 5 | #include 6 | #include "types.h" 7 | 8 | namespace sdfibm{ 9 | 10 | #define CHECK_BAD_ARGUMENT(expression) \ 11 | if (! (expression)) { \ 12 | throw std::invalid_argument("Invalid argument!"); \ 13 | } 14 | 15 | namespace AsciiColors{ 16 | static const std::string COLOR_NORMAL ="\033[0m"; 17 | static const std::string COLOR_RED ="\033[0;31;49m"; 18 | static const std::string COLOR_GREEN ="\033[0;32;49m"; 19 | static const std::string COLOR_YELLOW ="\033[0;33;49m"; 20 | static const std::string COLOR_BLUE ="\033[0;34;49m"; 21 | static const std::string COLOR_MAGENTA="\033[0;35;49m"; 22 | static const std::string COLOR_CYAN ="\033[0;36;49m"; 23 | static const std::string COLOR_WHITE ="\033[0;37;49m"; 24 | static const std::string COLOR_INFO ="\033[0;32;49m"; 25 | static const std::string COLOR_WARNING="\033[4;33;49m"; 26 | static const std::string COLOR_ERROR ="\033[1;31;43m"; 27 | } 28 | 29 | inline std::string GenBanner(const std::string& title) 30 | { 31 | unsigned int nside = (78 - title.length())/2; 32 | return std::string(nside, '*') + ' ' + title + ' ' + std::string(nside, '*') + '\n'; 33 | } 34 | 35 | inline void PrintInfo(const std::string& message) 36 | { 37 | std::cout << AsciiColors::COLOR_INFO << message << AsciiColors::COLOR_NORMAL << std::endl; 38 | } 39 | inline void PrintWarning(const std::string& message) 40 | { 41 | std::cout << AsciiColors::COLOR_WARNING << message << AsciiColors::COLOR_NORMAL << std::endl; 42 | } 43 | inline void PrintError(const std::string& message) 44 | { 45 | std::cout << AsciiColors::COLOR_ERROR << message << AsciiColors::COLOR_NORMAL << std::endl; 46 | } 47 | 48 | inline void Quit(const std::string& msg) 49 | { 50 | std::cout << msg << std::endl; 51 | std::exit(1); 52 | } 53 | 54 | // below requires rather new c++ version 55 | inline std::string GetTimeStringNew() 56 | { 57 | std::time_t t = std::time(nullptr); 58 | std::tm tm = *std::localtime(&t); 59 | std::stringstream ss; 60 | ss << std::put_time(&tm, "%h %d %Y %H:%M:%S"); 61 | return ss.str(); 62 | } 63 | 64 | inline std::string GetTimeString() 65 | { 66 | char buf[80]; 67 | time_t t = time(NULL); 68 | struct tm *tstruct = localtime(&t); 69 | strftime(buf, sizeof(buf), "%y/%m/%d %X", tstruct); 70 | return buf; 71 | } 72 | 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /tool_vof/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS =-m64 -Dlinux32 -DWM_DP 3 | 4 | C_DEBUG_FLAGS = -ggdb -O0 5 | C_RELEASE_FLAGS = -s -O3 6 | 7 | CFLAGS+=-Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor 8 | CFLAGS+=-DNoRepository -ftemplate-depth-100 -fPIC -std=c++11 9 | CFLAGS+=-DWM_ARCH_OPTION=64 -DWM_LABEL_SIZE=32 10 | 11 | INFLAGS =-I. 12 | INFLAGS+=-I../src 13 | INFLAGS+=-IlnInclude 14 | INFLAGS+=-I$(FOAM_SRC)/finiteVolume/lnInclude 15 | INFLAGS+=-I$(FOAM_SRC)/OpenFOAM/lnInclude 16 | INFLAGS+=-I$(FOAM_SRC)/dynamicFvMesh/lnInclude 17 | INFLAGS+=-I$(FOAM_SRC)/OSspecific/POSIX/lnInclude 18 | INFLAGS+=-I$(FOAM_SRC)/meshTools/lnInclude 19 | 20 | LIBMPI=-L$(FOAM_LIBBIN)/openmpi-system -lPstream 21 | 22 | LDFLAGS =-lm 23 | LDFLAGS+=-L$(FOAM_LIBBIN) -lfiniteVolume -lOpenFOAM -ldynamicFvMesh -lmeshTools 24 | 25 | 26 | APPSOURCES=main.cpp solidcloud.cpp 27 | APPOBJECTS=$(APPSOURCES:.cpp=.o) ../src/meshinfo.o ../src/cellenumerator.o ../src/geometrictools.o 28 | 29 | APPTARGET=smoothvof 30 | LIBTARGETLINK=-L. -L../src/libmotion -lmotion -L../src/libshape -lshape -L../src/libshape -lshape -L../src/libcollision -lcollision 31 | 32 | # release 33 | .PHONY : RELEASE 34 | RELEASE : CFLAGS+=$(C_RELEASE_FLAGS) 35 | RELEASE : all 36 | # debug 37 | .PHONY : DEBUG 38 | DEBUG : CFLAGS+=$(C_DEBUG_FLAGS) 39 | DEBUG : all 40 | 41 | .PHONY: $(APPTARGET) 42 | 43 | all: $(APPTARGET) 44 | 45 | $(APPTARGET): $(APPOBJECTS) 46 | @echo Building application $(APPTARGET) 47 | $(CC) -o $@ $(APPOBJECTS) $(LIBMPI) $(LIBTARGETLINK) $(LDFLAGS) 48 | 49 | clean: 50 | rm $(LIBOBJECTS) $(APPSOURCES:.cpp=.o) $(APPTARGET) 51 | 52 | .cpp.o: 53 | $(CC) $(CFLAGS) $< -o $@ $(INFLAGS) -c 54 | -------------------------------------------------------------------------------- /tool_vof/example/0/U: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | location "0"; 14 | object U; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 1 -1 0 0 0 0]; 19 | 20 | internalField uniform (0 0 0); 21 | 22 | boundaryField 23 | { 24 | left 25 | { 26 | type noSlip; 27 | } 28 | right 29 | { 30 | type noSlip; 31 | } 32 | bottom 33 | { 34 | type noSlip; 35 | } 36 | top 37 | { 38 | type pressureInletOutletVelocity; 39 | value uniform (0 0 0); 40 | } 41 | "(front|back)" 42 | { 43 | type empty; 44 | } 45 | } 46 | 47 | 48 | // ************************************************************************* // 49 | -------------------------------------------------------------------------------- /tool_vof/example/0/alpha.water: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/0/alpha.water -------------------------------------------------------------------------------- /tool_vof/example/0/p_rgh: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object p_rgh; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [1 -1 -2 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | left 24 | { 25 | type fixedFluxPressure; 26 | value uniform 0; 27 | } 28 | 29 | right 30 | { 31 | type fixedFluxPressure; 32 | value uniform 0; 33 | } 34 | 35 | bottom 36 | { 37 | type fixedFluxPressure; 38 | value uniform 0; 39 | } 40 | 41 | top 42 | { 43 | type totalPressure; 44 | p0 uniform 0; 45 | } 46 | 47 | "(front|back)" 48 | { 49 | type empty; 50 | } 51 | } 52 | 53 | // ************************************************************************* // 54 | -------------------------------------------------------------------------------- /tool_vof/example/alpha.water.orig: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object alpha.water; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 0; 20 | 21 | boundaryField 22 | { 23 | left 24 | { 25 | type zeroGradient; 26 | } 27 | 28 | right 29 | { 30 | type zeroGradient; 31 | } 32 | 33 | bottom 34 | { 35 | type zeroGradient; 36 | } 37 | 38 | top 39 | { 40 | type inletOutlet; 41 | inletValue uniform 0; 42 | value uniform 0; 43 | } 44 | 45 | "(front|back)" 46 | { 47 | type empty; 48 | } 49 | } 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /tool_vof/example/constant/g: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class uniformDimensionedVectorField; 13 | location "constant"; 14 | object g; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dimensions [0 1 -2 0 0 0 0]; 19 | value (0 0 0); 20 | 21 | 22 | // ************************************************************************* // 23 | -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 2.3.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 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 1; 18 | 19 | vertices 20 | ( 21 | ( 0 0 -0.5) 22 | ( 4 0 -0.5) 23 | ( 4 4 -0.5) 24 | ( 0 4 -0.5) 25 | ( 0 0 0.5) 26 | ( 4 0 0.5) 27 | ( 4 4 0.5) 28 | ( 0 4 0.5) 29 | ); 30 | 31 | blocks 32 | ( 33 | hex (0 1 2 3 4 5 6 7) (200 200 1) simpleGrading (1 1 1) 34 | ); 35 | 36 | edges 37 | ( 38 | ); 39 | 40 | boundary 41 | ( 42 | left { type wall; faces ( (0 4 7 3)); } 43 | right { type wall; faces ( (2 6 5 1)); } 44 | bottom{ type wall; faces ( (1 5 4 0)); } 45 | top { type wall; faces ( (3 7 6 2)); } 46 | front 47 | { 48 | type empty; 49 | faces 50 | ( 51 | (0 3 2 1) 52 | ); 53 | } 54 | back 55 | { 56 | type empty; 57 | faces 58 | ( 59 | (4 5 6 7) 60 | ); 61 | } 62 | ); 63 | 64 | mergePatchPairs 65 | ( 66 | ); 67 | 68 | // ************************************************************************* // 69 | -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/boundary: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format binary; 12 | class polyBoundaryMesh; 13 | location "constant/polyMesh"; 14 | object boundary; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | 6 19 | ( 20 | left 21 | { 22 | type wall; 23 | inGroups 1(wall); 24 | nFaces 200; 25 | startFace 79600; 26 | } 27 | right 28 | { 29 | type wall; 30 | inGroups 1(wall); 31 | nFaces 200; 32 | startFace 79800; 33 | } 34 | bottom 35 | { 36 | type wall; 37 | inGroups 1(wall); 38 | nFaces 200; 39 | startFace 80000; 40 | } 41 | top 42 | { 43 | type wall; 44 | inGroups 1(wall); 45 | nFaces 200; 46 | startFace 80200; 47 | } 48 | front 49 | { 50 | type empty; 51 | inGroups 1(empty); 52 | nFaces 40000; 53 | startFace 80400; 54 | } 55 | back 56 | { 57 | type empty; 58 | inGroups 1(empty); 59 | nFaces 40000; 60 | startFace 120400; 61 | } 62 | ) 63 | 64 | // ************************************************************************* // 65 | -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/faces: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/constant/polyMesh/faces -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/neighbour: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/constant/polyMesh/neighbour -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/owner: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/constant/polyMesh/owner -------------------------------------------------------------------------------- /tool_vof/example/constant/polyMesh/points: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/constant/polyMesh/points -------------------------------------------------------------------------------- /tool_vof/example/constant/transportProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 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 | phases (water air); 19 | nu nu [ 0 2 -1 0 0 0 0 ] 0.01; 20 | alpha alpha [ 0 2 -1 0 0 0 0 ] 0.001; 21 | rho rho [ 1 -3 0 0 0 0 0 ] 1.0; 22 | 23 | water 24 | { 25 | transportModel Newtonian; 26 | nu 0.001; 27 | rho 1000; 28 | } 29 | 30 | air 31 | { 32 | transportModel Newtonian; 33 | nu 1e-05; 34 | rho 1; 35 | } 36 | 37 | sigma 50; 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /tool_vof/example/constant/turbulenceProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object turbulenceProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | simulationType laminar; 19 | 20 | 21 | // ************************************************************************* // 22 | -------------------------------------------------------------------------------- /tool_vof/example/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp alpha.water.orig 0/alpha.water 3 | ../smoothvof 4 | -------------------------------------------------------------------------------- /tool_vof/example/solidDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 6.0.0 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object solidDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | meta 17 | { 18 | on_twod 1; 19 | } 20 | 21 | shapes 22 | { 23 | shape1 24 | { 25 | name circle1; 26 | type Circle; 27 | radius 0.3; 28 | } 29 | shape2 30 | { 31 | name circle_tail1; 32 | type Circle_Tail; 33 | radius 0.3; 34 | ratio 1; 35 | thickness 0.1; 36 | } 37 | shape3 38 | { 39 | name ellipse1; 40 | type Ellipse; 41 | radiusa 0.3; 42 | radiusb 0.2; 43 | } 44 | shape4 45 | { 46 | name rectangle1; 47 | type Rectangle; 48 | radiusa 0.3; 49 | radiusb 0.2; 50 | } 51 | shape5 52 | { 53 | name plane1; 54 | type Plane; 55 | } 56 | } 57 | 58 | solids 59 | { 60 | solid1 61 | { 62 | shp_name circle_tail1; 63 | pos ( 0.5 1.5 0 ); 64 | euler ( 0 0 -45); 65 | } 66 | solid2 67 | { 68 | shp_name circle_tail1; 69 | pos ( 0.5 2.5 0 ); 70 | euler ( 0 0 0); 71 | } 72 | solid3 73 | { 74 | shp_name circle_tail1; 75 | pos ( 0.5 3.5 0 ); 76 | euler ( 0 0 45); 77 | } 78 | solid4 79 | { 80 | shp_name rectangle1; 81 | pos ( 1.5 1.5 0 ); 82 | euler ( 0 0 0 ); 83 | } 84 | solid5 85 | { 86 | shp_name rectangle1; 87 | pos ( 1.5 2.5 0 ); 88 | euler ( 0 0 30); 89 | } 90 | solid6 91 | { 92 | shp_name rectangle1; 93 | pos ( 1.5 3.5 0 ); 94 | euler ( 0 0 60); 95 | } 96 | solid7 97 | { 98 | shp_name ellipse1; 99 | pos ( 2.5 1.5 0 ); 100 | euler ( 0 0 0 ); 101 | } 102 | solid8 103 | { 104 | shp_name ellipse1; 105 | pos ( 2.5 2.5 0 ); 106 | euler ( 0 0 60); 107 | } 108 | solid9 109 | { 110 | shp_name ellipse1; 111 | pos ( 2.5 3.5 0 ); 112 | euler ( 0 0 120); 113 | } 114 | solid10 115 | { 116 | shp_name circle1; 117 | pos ( 3.5 1.0 0 ); 118 | euler ( 0 0 0 ); 119 | } 120 | solid11 121 | { 122 | shp_name circle1; 123 | pos ( 3.5 2.5 0 ); 124 | euler ( 0 0 0 ); 125 | } 126 | solid12 127 | { 128 | shp_name circle1; 129 | pos ( 3.5 3.5 0 ); 130 | euler ( 0 0 0 ); 131 | } 132 | } 133 | 134 | planes 135 | { 136 | plane1 137 | { 138 | shp_name plane1; 139 | pos ( 0 0 0 ); 140 | euler ( 0 0 15 ); 141 | } 142 | plane2 143 | { 144 | shp_name plane1; 145 | pos ( 0 0 0 ); 146 | euler ( 0 0 -90 ); 147 | } 148 | } 149 | 150 | // Feb 29 2020 22:04:43 151 | -------------------------------------------------------------------------------- /tool_vof/example/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 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 interFoam; 19 | 20 | startFrom latestTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 6; 27 | 28 | deltaT 0.001; 29 | 30 | writeControl adjustableRunTime; 31 | 32 | writeInterval 0.05; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat binary; 37 | 38 | writePrecision 6; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | runTimeModifiable yes; 47 | 48 | adjustTimeStep yes; 49 | 50 | maxCo 1; 51 | maxAlphaCo 1; 52 | 53 | maxDeltaT 1; 54 | 55 | 56 | // ************************************************************************* // 57 | -------------------------------------------------------------------------------- /tool_vof/example/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object decomposeParDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | numberOfSubdomains 4; 19 | 20 | method simple; 21 | 22 | simpleCoeffs 23 | { 24 | n (2 2 1); 25 | delta 0.001; 26 | } 27 | 28 | hierarchicalCoeffs 29 | { 30 | n (1 1 1); 31 | delta 0.001; 32 | order xyz; 33 | } 34 | 35 | manualCoeffs 36 | { 37 | dataFile ""; 38 | } 39 | 40 | distributed no; 41 | 42 | roots ( ); 43 | 44 | 45 | // ************************************************************************* // 46 | -------------------------------------------------------------------------------- /tool_vof/example/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 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 | } 27 | 28 | divSchemes 29 | { 30 | div(rhoPhi,U) Gauss linearUpwind grad(U); 31 | div(phi,alpha) Gauss vanLeer; 32 | div(phirb,alpha) Gauss linear; 33 | div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear; 34 | } 35 | 36 | laplacianSchemes 37 | { 38 | default Gauss linear corrected; 39 | } 40 | 41 | interpolationSchemes 42 | { 43 | default linear; 44 | } 45 | 46 | snGradSchemes 47 | { 48 | default corrected; 49 | } 50 | 51 | 52 | // ************************************************************************* // 53 | -------------------------------------------------------------------------------- /tool_vof/example/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 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 | "alpha.water.*" 21 | { 22 | nAlphaCorr 2; 23 | nAlphaSubCycles 1; 24 | cAlpha 1; 25 | 26 | MULESCorr yes; 27 | nLimiterIter 5; 28 | 29 | solver smoothSolver; 30 | smoother symGaussSeidel; 31 | tolerance 1e-8; 32 | relTol 0; 33 | } 34 | 35 | "pcorr.*" 36 | { 37 | solver PCG; 38 | preconditioner DIC; 39 | tolerance 1e-5; 40 | relTol 0; 41 | } 42 | 43 | p_rgh 44 | { 45 | solver PCG; 46 | preconditioner DIC; 47 | tolerance 1e-07; 48 | relTol 0.05; 49 | } 50 | 51 | p_rghFinal 52 | { 53 | $p_rgh; 54 | relTol 0; 55 | } 56 | 57 | U 58 | { 59 | solver smoothSolver; 60 | smoother symGaussSeidel; 61 | tolerance 1e-06; 62 | relTol 0; 63 | } 64 | } 65 | 66 | PIMPLE 67 | { 68 | momentumPredictor no; 69 | nOuterCorrectors 1; 70 | nCorrectors 3; 71 | nNonOrthogonalCorrectors 0; 72 | } 73 | 74 | relaxationFactors 75 | { 76 | equations 77 | { 78 | ".*" 1; 79 | } 80 | } 81 | 82 | PISO 83 | { 84 | nCorrectors 1; 85 | nNonOrthogonalCorrectors 0; 86 | pRefCell 0; 87 | pRefValue 0; 88 | } 89 | 90 | 91 | // ************************************************************************* // 92 | 93 | -------------------------------------------------------------------------------- /tool_vof/example/system/setFieldsDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Version: 6 6 | \\/ M anipulation | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object setFieldsDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | defaultFieldValues 19 | ( 20 | volScalarFieldValue alpha.water 0 21 | ); 22 | 23 | regions 24 | ( 25 | boxToCell 26 | { 27 | box (0 0 -1) (0.1461 0.292 1); 28 | fieldValues 29 | ( 30 | volScalarFieldValue alpha.water 1 31 | ); 32 | } 33 | ); 34 | 35 | 36 | // ************************************************************************* // 37 | -------------------------------------------------------------------------------- /tool_vof/example/view.foam: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/example/view.foam -------------------------------------------------------------------------------- /tool_vof/main.cpp: -------------------------------------------------------------------------------- 1 | #include "fvCFD.H" 2 | #include "solidcloud.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | argList::noParallel(); 7 | argList::addOption("name", "word", "Name of field to be initialized"); 8 | 9 | #include "setRootCase.H" 10 | #include "createTime.H" 11 | #include "createMesh.H" 12 | 13 | if (!args.checkRootCase()) 14 | Foam::FatalError.exit(); 15 | 16 | Foam::word field_name; 17 | if(args.options().empty()) 18 | { 19 | field_name = "alpha.water"; 20 | Foam::Info << "* No field name provided, default to " << field_name << "\n"; 21 | } 22 | else 23 | { 24 | args.optionReadIfPresent("name", field_name); 25 | } 26 | 27 | sdfibm::SolidCloud solidcloud("solidDict", mesh); 28 | solidcloud.writeVOF(field_name); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tool_vof/smoothvof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChenguangZhang/sdfibm/70e95f25a7482dac794579e8975e211b56d2db54/tool_vof/smoothvof -------------------------------------------------------------------------------- /tool_vof/solidcloud.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "fvCFD.H" 6 | 7 | #include "solidcloud.h" 8 | #include "./libmotion/motionfactory.h" 9 | #include "./libshape/shapefactory.h" 10 | namespace sdfibm { 11 | 12 | SolidCloud::SolidCloud(const Foam::word& dictfile, const Foam::fvMesh& mesh): 13 | m_mesh(mesh), 14 | m_geotools(GeometricTools(m_mesh)), 15 | m_cellenum(CellEnumerator(m_mesh)) 16 | { 17 | if(Foam::Pstream::master()) 18 | { 19 | logfile.open("cloud.log"); 20 | logfile << GenBanner("INIT SOLIDCLOUD"); 21 | } 22 | m_solids.reserve(10); 23 | m_planes.reserve(10); 24 | 25 | Foam::IFstream ifstream = Foam::IFstream(dictfile); 26 | dictionary root(ifstream()); 27 | 28 | if(Foam::Pstream::master()) 29 | logfile << "reading solids from: " << root.name() << '\n'; 30 | 31 | const dictionary& meta = root.subDict("meta"); 32 | m_ON_TWOD = Foam::readBool(meta.lookup("on_twod")); 33 | 34 | if(Foam::Pstream::master()) 35 | { 36 | logfile << GenBanner("SUMMARY"); 37 | std::string dim = m_ON_TWOD ? "2D" : "3D"; 38 | logfile << "Binary was compiled at " << __DATE__ << ' ' << __TIME__ << '\n'; 39 | logfile << "Simulation starts at " << GetTimeString() << '\n'; 40 | } 41 | 42 | // read and create shape, motion, and material 43 | try { 44 | // read and create shapes 45 | if(Foam::Pstream::master()) 46 | { 47 | logfile << GenBanner("CREATE: SHAPES"); 48 | logfile << "--> Available shape types:\n"; 49 | ShapeFactory::report(logfile); 50 | logfile << "--> Used shapes:\n"; 51 | } 52 | const dictionary& shapes = root.subDict("shapes"); 53 | for (int i=0; i < shapes.size(); ++i) 54 | { 55 | const dictionary& para = shapes.subDict(shapes.toc()[i]); 56 | std::string type = Foam::word(para.lookup("type")); 57 | std::string name = Foam::word(para.lookup("name")); 58 | 59 | m_libshape[name] = ShapeFactory::create(type, para); 60 | if(m_libshape[name] == nullptr) 61 | throw std::runtime_error(std::string("Unrecognized shape type " + type + '\n')); 62 | 63 | if(Foam::Pstream::master()) 64 | logfile << "[+] " << type << " as " << name << " (" << m_libshape[name]->description() << ")\n"; 65 | } 66 | 67 | m_libmat["mat"] = new IMaterial(1.0); 68 | } 69 | catch (const std::exception& e) 70 | { 71 | if(Foam::Pstream::master()) 72 | { 73 | std::cout << e.what(); 74 | logfile << "Error when creating shape/motion/material!" << e.what() << '\n'; 75 | } 76 | std::exit(1); 77 | } 78 | 79 | // create solids 80 | if(Foam::Pstream::master()) 81 | logfile << GenBanner("CREATE: SOLIDS & PLANES"); 82 | 83 | const dictionary &solids = root.subDict("solids"); 84 | forAll(solids, i) 85 | { 86 | const dictionary &solid = solids.subDict(solids.toc()[i]); 87 | 88 | vector pos = solid.lookup("pos"); 89 | if (m_ON_TWOD) 90 | { 91 | // sanity check for 2d simulation: solid must have z = 0 92 | if(pos.z() != 0) 93 | Quit("Solid must has z=0 in 2D simulation, violated by solid # " + std::to_string(i)); 94 | } 95 | // create solid 96 | Solid s(i, pos, quaternion::I); 97 | // read velocity, euler angle, angular velocity 98 | vector euler = solid.lookupOrDefault("euler", vector::zero); 99 | s.setOrientation(euler*M_PI/180.0); 100 | 101 | std::string shp_name = Foam::word(solid.lookup("shp_name")); 102 | s.setMaterialAndShape(m_libmat["mat"], m_libshape[shp_name]); 103 | this->addSolid(s); 104 | 105 | if(Foam::Pstream::master()) 106 | logfile << "Solid " << i << " shape = " << shp_name << "\n"; 107 | } 108 | 109 | if(Foam::Pstream::master()) 110 | { 111 | logfile << "Totally [" << m_solids.size() << "] solids and [" << m_planes.size() << "] planes.\n"; 112 | logfile << GenBanner("END OF INIT"); 113 | } 114 | } 115 | 116 | 117 | void SolidCloud::solidFluidInteract(Solid& solid, const scalar& dt) 118 | { 119 | m_geotools.clearCache(); 120 | m_cellenum.SetSolid(solid); 121 | 122 | const Foam::scalarField& cv = m_mesh.V(); 123 | 124 | scalar alpha = 0.0; 125 | while (!m_cellenum.Empty()) 126 | { 127 | int icur = m_cellenum.GetCurCellInd(); 128 | if (m_cellenum.GetCurCellType() == CellEnumerator::ALL_INSIDE) 129 | alpha = 1.0; 130 | else 131 | alpha = m_geotools.calcCellVolume(icur, solid, m_ON_TWOD)/cv[icur]; 132 | 133 | m_ptr_As->operator[](icur) += alpha; 134 | if (m_ptr_As->operator[](icur) > 1.0) 135 | m_ptr_As->operator[](icur) = 1.0; 136 | 137 | m_cellenum.Next(); 138 | } 139 | } 140 | 141 | void SolidCloud::writeVOF(const Foam::word& name) 142 | { 143 | dimensionedScalar zero("zero", Foam::dimless, 0.0); 144 | volScalarField tmp( IOobject("tmp", "0", m_mesh, IOobject::NO_READ, IOobject::NO_WRITE ), m_mesh, zero); 145 | surfaceScalarField phi( IOobject("phi", "0", m_mesh, IOobject::NO_READ, IOobject::NO_WRITE ), m_mesh, zero); 146 | volScalarField field( IOobject( name, "0", m_mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), m_mesh); 147 | 148 | m_ptr_As = &tmp; 149 | for(Solid& solid : m_solids) 150 | solidFluidInteract(solid, 0.0); 151 | 152 | for(Solid& solid : m_planes) 153 | solidFluidInteract(solid, 0.0); 154 | 155 | tmp.correctBoundaryConditions(); 156 | 157 | forAll(m_mesh.cells(), icell) 158 | { 159 | scalar alpha = tmp[icell]; 160 | if(alpha < 0 || alpha > 1 + 1e-6) 161 | Foam::Info << "Wrong volume fraction " << alpha << " at cell " << icell << '\n'; 162 | field[icell] = alpha; 163 | } 164 | field.correctBoundaryConditions(); 165 | 166 | field.write(); 167 | const Foam::scalarField& cell_vol = m_mesh.V(); 168 | Foam::Info << "* Write smooth phase field [" << name << "] to ./0, total volume = " 169 | << Foam::gSum(tmp*cell_vol) << '\n'; 170 | Foam::Info << "* Finished at " << sdfibm::GetTimeString() << '\n'; 171 | 172 | logfile.close(); 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /tool_vof/solidcloud.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLIDCLOUD_H 2 | #define SOLIDCLOUD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "fvm.H" 10 | #include "types.h" 11 | #include "solid.h" 12 | #include "./libmaterial/imaterial.h" 13 | #include "utils.h" 14 | #include "geometrictools.h" 15 | #include "cellenumerator.h" 16 | 17 | namespace sdfibm { 18 | 19 | class SolidCloud 20 | { 21 | private: 22 | bool m_ON_TWOD; 23 | 24 | private: 25 | std::vector m_solids; 26 | std::vector m_planes; 27 | 28 | const Foam::fvMesh& m_mesh; 29 | Foam::volScalarField* m_ptr_As; 30 | 31 | private: 32 | void solidFluidInteract(Solid& s, const scalar& dt); 33 | 34 | std::map m_libmotion; 35 | std::map m_libmat; 36 | std::map m_libshape; 37 | std::ofstream logfile; 38 | 39 | GeometricTools m_geotools; 40 | CellEnumerator m_cellenum; 41 | 42 | public: 43 | SolidCloud(const Foam::word& dictfile, const Foam::fvMesh& mesh); 44 | ~SolidCloud(){}; 45 | 46 | inline void addSolid(const Solid& solid) { m_solids.push_back(solid); } 47 | inline void addPlane(const Solid& solid) { m_planes.push_back(solid); } 48 | void writeVOF(const Foam::word& field_name); 49 | }; 50 | 51 | } 52 | #endif 53 | 54 | --------------------------------------------------------------------------------