参考
https://www.bilibili.com/video/BV1MP4y1u7rS?spm_id_from=333.337.search-card.all.click
安装软件准备
- ubuntu系统
- 安装cmake
- 安装VS Code
- 安装OpenFOAM(我的版本8.0)
准备文件
- CMakeLists.txt文件
- cavity文件夹
- myicoFoam2文件夹
以下会分别说明
注意:这三步无所谓先后顺序
1: 准备CMakeLists.txt
在桌面上新建一个文件夹myicoFoam2
内有一个文件,名为CMakeLists.txt
其内容如下
cmake_minimum_required(VERSION 3.21) #change here (optional)
if (DEFINED ENV{WM_PROJECT})
message("Using $ENV{WM_PROJECT}-$ENV{WM_PROJECT_VERSION}")
set(WM_PATH, ${CMAKE_SOURCE_DIR})
else()
message(FATAL_ERROR "OpenFOAM environment not set. Aborting.")
endif ()
project(myicoFoam2) #change here
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenFOAM_VERSION $ENV{WM_PROJECT_VERSION})
set(OpenFOAM_DIR $ENV{WM_PROJECT_DIR})
set(OpenFOAM_LIB_DIR $ENV{FOAM_LIBBIN})
set(OpenFOAM_SRC $ENV{FOAM_SRC})
set(DEFINITIONS_COMPILE "-std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -fPIC ") #change here
add_definitions("${DEFINITIONS_COMPILE}")
include_directories(
${OpenFOAM_SRC}/finiteVolume/lnInclude
${OpenFOAM_SRC}/meshTools/lnInclude
lnInclude
.
${OpenFOAM_SRC}/OpenFOAM/lnInclude
${OpenFOAM_SRC}/OSspecific/POSIX/lnInclude
) #change here
link_directories(${OpenFOAM_LIB_DIR} ${OpenFOAM_LIB_DIR}/dummy ${OpenFOAM_LIB_DIR}/${PATH_LIB_OPENMPI})
add_executable(${PROJECT_NAME} myicoFoam2.C) #change here
target_link_libraries(${PROJECT_NAME} OpenFOAM dl m Pstream finiteVolume fvOptions meshTools )
文件内容解释放到附录
2: 准备cavity文件夹
从tutorial复制过来
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .
也可手动复制
进入cavity并且用blockMesh
cd cavity
blockMesh
修改controlDict
3: 准备myicoFoam2文件夹
从官方solver复制过来
cp -r $FOAM_SOLVERS/incompressible/icoFoam .
更改:
- 文件夹icoFoam重命名为myicoFoam2
- icoFoam.C重命名为myicoFoam2.C
- Make文件夹中files改为
注意USER
步骤
step1: wmake
在myicoFoam2子文件夹下运行
wmake
这一长串的输出其实和CMakeLists里我们手动写的一样(我们就是抄的这里)
Making dependency list for source file myicoFoam2.C
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam8/src/finiteVolume/lnInclude -I/opt/openfoam8/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam8/src/OpenFOAM/lnInclude -I/opt/openfoam8/src/OSspecific/POSIX/lnInclude -fPIC -c myicoFoam2.C -o Make/linux64GccDPInt32Opt/myicoFoam2.o
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam8/src/finiteVolume/lnInclude -I/opt/openfoam8/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam8/src/OpenFOAM/lnInclude -I/opt/openfoam8/src/OSspecific/POSIX/lnInclude -fPIC -fuse-ld=bfd -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/myicoFoam2.o -L/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib \
-lfiniteVolume -lmeshTools -lOpenFOAM -ldl \
-lm -o /home/ubuntu1/OpenFOAM/ubuntu1-8/platforms/linux64GccDPInt32Opt/bin/myicoFoam2
当前的文件布局
step2: cmake
安装插件CMake tools
底边栏选择Debug
先configure
然后点build
会自动生成一个build文件夹
step3: debug
按F5调试,会告诉我们要配置launch.json文件
对launch,json做如下更改
再F5运行,即可调试
大功告成!!!
附录 CMakeLists.txt的解释
以后再说