|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
Posted on 2010年08月17日 by admin
分析了一下OpenFOAM的求解器源码, 基本上存放在下面这个地方
/opt/OpenFOAM/OpenFOAM-1.7.0/applications/solvers
该路径下按照不同的求解器类型又分别保存各自的求解器源码.
OpenFOAM/OpenFOAM-1.7.0/applications/solvers$ ls
basic discreteMethods financial lagrangian
combustion DNS heatTransfer multiphase
compressible electroics incompressible stressAnalysis
进入不可压求解器查看, 如下:
cd incompressible
OpenFOAM/OpenFOAM-1.7.0/applications/solvers/incompressible$ ls
boundaryFoam nonNewtonianIcoFoam pisoFoam simpleFoam
channelFoam pimpleDyMFoam porousSimpleFoam
icoFoam pimpleFoam shallowWaterFoam
以simple为例, 尝试将这个求解器源码做成一个图形IDE的开发环境. 开发工具采用eclipse-cpp, 其他的工具应该差不多.
从eclipse的网站下下载linux平台的eclipse cpp, 解压后可直接运行,解压到/opt/eclipse-cpp. 为了方便使用, 建议将eclipse的运行程序做成别名.
alias eclipse-cpp='/opt/eclipse-cpp/eclipse'
上面的命令放入开机脚本中即可, 如~/.bashrc或者./.profile. 如此便可以以eclipse-cpp命令方便启动eclipse了. 另外还要将OpenFOAM的环境变量的配置文件每次开机source一下. 将下面的代码也要加入启动脚本.
source [your OF install path]/etc/bashrc
此处发现一个问题, 在ubuntu 10.04下, 这个source命令只能放在用户目录下的.bashrc或者.profile才能生效, 置于全局的/etc/bashrc或者/etc/profile开机居然无效. 不知道其他的发行版是否存在该问题. 另外还发现一个怪现象, 定义了这些OpenFOAM的环境编量, 但是直接启动eclipse居然也不会认这些环境变量, 之后的步骤中要导入环境变量也没有办法导入. 只有先打一个console, 然后从console中启动的eclipse才能识别这些OpenFOAM的环境变量, 才能导入. 不知道是不是unbuntu的问题, 期待高手解决.
回到正题, 下面以命令行启动eclipse-cpp, 菜单上file | new | C++ Project | 自动定义路径到
/OpenFOAM-1.7.0/applications/solvers/incompressible/rhoSimpleFoam/
然后finish. 如此便建立一个叫做rhoSimpleFoam的项目, 项目会出现再eclipse IDE界面的项目树中. 下面还需进一步设置该项目的属性.
菜单上 Project | Build Automatically取消勾选. 然后配置属性, 该project上右键到Porperties, 左侧属性树上C++Build
对应设置界面中, Build Location设置为rhoSimpleFoam的源码路径.
/OpenFOAM-1.7.0/applications/solvers/incompressible/rhoSimpleFoam/
然后属性树上C++ Build | Environment | ADD 或者Select, 将前面OpenFOAM环境变量纷纷加入, 如果闲烦, 就一起全部select. 如果将来转换为Debug模式, 这个里面的OpenFOAM要全部重新导入一次.
之后回到主菜单Project | Make Target | Create, 新建两个target, 一个wmake一个wclean, 都要自定义命令, 分别是
/opt/OpenFOAM/OpenFOAM-1.7.0/wmake/wmake
/opt/OpenFOAM/OpenFOAM-1.7.0/wmake/wclean
同时same target name勾选空, 并留空. 如此make target便新建了两个target, 一个用以make, 一个用以clean. 反复尝试一下, 以wmake为目标编译, 则在console窗口显示编译输出如下:
**** Build of configuration Debug for project rhoSimpleFoam ****
/opt/OpenFOAM/OpenFOAM-1.7.0/wmake/wmake
Making dependency list for source file rhoSimpleFoam.C
SOURCE=rhoSimpleFoam.C ; g++ -m32 -Dlinux -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-40 -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/thermophysicalModels/basic/lnInclude -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/turbulenceModels -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/turbulenceModels/compressible/RAS/RASModel -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/cfdTools -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linuxGccDPOpt/rhoSimpleFoam.o
/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude/readSIMPLEControls.H: In function ‘int main(int, char**)’:
/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude/readSIMPLEControls.H:6: warning: unused variable ‘momentumPredictor’
g++ -m32 -Dlinux -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-40 -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/thermophysicalModels/basic/lnInclude -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/turbulenceModels -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/turbulenceModels/compressible/RAS/RASModel -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/cfdTools -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-1.7.0/src/OSspecific/POSIX/lnInclude -fPIC Make/linuxGccDPOpt/rhoSimpleFoam.o -L/opt/OpenFOAM/OpenFOAM-1.7.0/lib/linuxGccDPOpt \
-lbasicThermophysicalModels -lspecie -lcompressibleRASModels -lfiniteVolume -lmeshTools -lOpenFOAM -liberty -ldl -lm -o /opt/OpenFOAM/OpenFOAM-1.7.0/applications/bin/linuxGccDPOpt/rhoSimpleFoam
出现上述信息就表示设置成功了. 若之前编译过一次但没有clean, 则make时无任何显示, 建议先wclean一下.
这样的图形化只能简单的编译和修改程序, 还是不能调试. 因为目前尚未能找到能够自动导入OpenFOAM自用wmake脚本的编译环境, 看来调试环境也要自己手动配置了. 而OpenFOAM的代码关系比较复杂, 最好能够写一个转换工具, 能够将wmake的编译脚本转换成标准的make脚本或者是eclipse的配置文件, 如此便可方便许多.
[ 本帖最后由 apango 于 2010-8-18 04:36 编辑 ] |
-
|