Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A CMake build system for cfl3d and some bug fixes (at least in Linux) #4

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f3d6a2f
gfortran compilation, major part can be run
Jul 21, 2017
9a8ba1e
add *.swp to .gitignore
Jul 21, 2017
7ae0997
precfl compile pass
Jul 21, 2017
49e93f0
fixed spalart.F for complex cfl3d
Jul 21, 2017
bf1a88e
linux_gfortran_openmpi OK
Jul 21, 2017
a0b48e7
fix makefile_linux_gfotran_openmpi
Jul 21, 2017
9e1d076
add 编译修正过程.md
Jul 21, 2017
0eff618
Update 编译修正过程.md
Jul 21, 2017
d95f7ec
Update 编译修正过程.md
Jul 21, 2017
a7b8607
add test cases
Jul 22, 2017
e49799d
Merge branch 'master' of https://github.com/chengdi123000/CFL3D
Jul 22, 2017
15eb56e
Update 编译修正过程.md
Jul 22, 2017
cf7efe5
update .gitignore
Jul 26, 2017
eaa891b
add create_use_cfl3d
Jul 26, 2017
2d1fc87
exclude test cases, just download it by your self
Aug 1, 2017
3e5f4da
slightly modified .gitignore
Aug 1, 2017
6790612
remove Chinese name
Aug 1, 2017
2501e29
cfl3d_seq compiled successfully.
Aug 4, 2017
3f8dfc6
added CGNS as submodule
Aug 6, 2017
2ffd086
remove CGNS
Aug 6, 2017
a3eecce
add CGNS as IMPORTED library in CMake system
Aug 6, 2017
1034f7b
cgns lib fix
Aug 7, 2017
683b1eb
CMakeLists.txt fix: no MPI, no FASTIO
Aug 7, 2017
1413d32
found BC2010 error
Aug 8, 2017
1bdf4d3
fixed cfl3d/libs/bc2010.F: add real() to variabls who might be comple…
Aug 8, 2017
cff1cb5
successfully compiled all components with CGNS and OpenMPI using gfor…
Aug 8, 2017
1e9b0dd
README.md updated
Aug 8, 2017
c35f779
remove CFL3D bin: there is CFL3D/build/bin
Aug 8, 2017
3943606
modify README.md: add usage section and test section
Aug 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 6 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,55 +1,7 @@
# Untracked files:
*.o
build/makefile
build/tools/seq/*.F*
build/splitcmplx/seq/*.F*
build/split/seq/*.F*
build/ron/seq/*.F*
build/preron/seq/*.F*
build/precfl/seq/*.F*
build/mag/seq/*.F*
build/cflcmplx/seq/*.F*
build/cflcmplx/mpi/*.F*
build/cflcmplx/libs/*.F*
build/cflcmplx/libs/bessel.c
build/cfl/libs/bessel.c
build/cfl/seq/*.F*
build/cfl/mpi/*.F*
build/cfl/libs/*.F*
build/cfl/libs/*.mod
libcommon.a
libdist.a
cfl3d_seq
cfl3d_mpi
cfl3dcmplx_seq
cfl3dcmplx_mpi
maggie
precfl3d
preronnie
ronnie
splitter
splittercmplx
build/mag/seq/mag1.h
build/tools/seq/Get_FD
build/tools/seq/INGRID_to_p3d
build/tools/seq/XINTOUT_to_ovrlp
build/tools/seq/cfl3d_to_nmf
build/tools/seq/cfl3d_to_pegbc
build/tools/seq/cfl3dinp_to_FVBND
build/tools/seq/cgns_readhist
build/tools/seq/cgns_to_cfl3dinput
build/tools/seq/everyother_xyz
build/tools/seq/grid_perturb
build/tools/seq/grid_perturb_cmplx
build/tools/seq/initialize_field
build/tools/seq/libs.a
build/tools/seq/moovmaker
build/tools/seq/nmf_to_cfl3dinput
build/tools/seq/p3d_to_INGRID
build/tools/seq/p3d_to_cfl3drst
build/tools/seq/plot3dg_to_cgns
build/tools/seq/v6_restart_mod
build/tools/seq/v6_ronnie_mod
build/tools/seq/v6inpdoubhalf
build/tools/seq/gridswitchijk
build/tools/seq/v6inpswitchijk
build/
testcase/

*.swp
bin/
external/cgns/cgnslib_2.5/
155 changes: 155 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_policy(SET CMP0048 NEW) #used to set Version Number
project(CFL3D VERSION 6.7)
enable_language(Fortran C)
SET (CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include CACHE PATH "Single Directory for all fortran modules.")

## options
option(USE_SINGLE "use single precision? " OFF)
option(USE_CGNS "use CGNS? " ON)
option(USE_NO_REDIRECT "use no-redirect? " OFF)
option(USE_FASTIO "use fast-io of mpi? It is effective when mpi is found. " ON)
option(BUILD_MPI "build MPI version? " ON)
option(BUILD_CMPLX "build complex version? " ON)

## default Build Type is Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

## no redirect
if(USE_NO_REDIRECT)
add_definitions(-DNOREDIRECT)
endif(USE_NO_REDIRECT)


## use options to setup flags and find libraries
if(USE_SINGLE)
# do nothing
else(USE_SINGLE)
add_definitions(-DDBLE_PRECSN)

if(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
message(STATUS "Using the Intel Fortran compiler")
add_compile_options(-r8)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
message(STATUS "Using the GNU Fortran compiler")
add_compile_options(-fdefault-real-8)
else(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
message(WARNING "compiler do not match Intel/GNU! use Intel's setting instead.")
add_compile_options(-r8)
endif(CMAKE_Fortran_COMPILER_ID MATCHES Intel)

endif(USE_SINGLE)


# no FindCGNS in CMake release
# using Paraview's FindCGNS.cmake
# https://github.com/Kitware/ParaView/raw/master/CMake/FindCGNS.cmake
# modified to find `cgnslib_f.h` and `libcgns.a`
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

if(USE_CGNS)
find_package(CGNS 2.4 REQUIRED)
if(CGNS_FOUND)
message("Found CGNS for CFL3D")
message("CGNS include dir: ${CGNS_INCLUDE_DIR}")
message("CGNS library: ${CGNS_LIBRARY}")
add_library(cgns STATIC IMPORTED)
set_property(TARGET cgns PROPERTY IMPORTED_LOCATION ${CGNS_LIBRARY})
set_property(TARGET cgns PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES Fortran)
set_property(TARGET cgns PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CGNS_INCLUDE_DIR}>)
set_property(TARGET cgns PROPERTY INTERFACE_COMPILE_DEFINITIONS CGNS)
# If using libcgns.so in system lib, it is required to find and use libhdf5.so
#find_package(HDF5 REQUIRED)
#if(HDF5_FOUND)
# message("HDF5_lib:${HDF5_hdf5_LIBRARY_RELEASE}")
# set_property(TARGET cgns PROPERTY INTERFACE_LINK_LIBRARIES ${HDF5_hdf5_LIBRARY_RELEASE})
#else(HDF5_FOUND)
# message(WARNING "HDF5 not found, there might be some error when linking to libcgns.so")
#endif(HDF5_FOUND)
else(CGNS_FOUND)
message(WARNING "system CGNS not found for CFL3D")
set(USE_CGNS OFF CACHE BOOL "use CGNS? (not available)" FORCE) # set the CGNS not available
endif(CGNS_FOUND)
else(USE_CGNS)
endif(USE_CGNS)

if(BUILD_MPI)
find_package(MPI 1.0 REQUIRED)
if(MPI_Fortran_FOUND)
message("Found MPI for Fortran")
## add mpi library
add_library(mpi STATIC IMPORTED)
set_property(TARGET mpi PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MPI_Fortran_INCLUDE_PATH})
set(other_elems ${MPI_Fortran_LIBRARIES})
list(GET other_elems 0 first_elem)
list(REMOVE_AT other_elems 0)
set_property(TARGET mpi PROPERTY IMPORTED_LOCATION ${first_elem})
set_property(TARGET mpi PROPERTY INTERFACE_LINK_LIBRARIES ${other_elems})
set_property(TARGET mpi APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "DIST_MPI")
set_property(TARGET mpi APPEND PROPERTY LINK_FLAGS "${MPI_Fortran_LINK_FLAGS}")
set_property(TARGET mpi APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${MPI_Fortran_COMPILE_FLAGS}")
## FAST-io
if(USE_FASTIO)
set_property(TARGET mpi APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "FASTIO")
endif(USE_FASTIO)
else(MPI_Fortran_FOUND)
## FAST-io
if(USE_FASTIO)
message(WARNING "no mpi, no fast-io.")
set(USE_FASTIO OFF CACHE BOOL "build MPI? (not available)" FORCE) # set the fastio not available
endif(USE_FASTIO)
set(BUILD_MPI OFF CACHE BOOL "build MPI? (not available)" FORCE) # set the MPI not available
endif(MPI_Fortran_FOUND)
else(BUILD_MPI)
endif(BUILD_MPI)

# in LINUX system
if(UNIX AND NOT APPLE)
add_definitions(-DLINUX)
## usually the Linux OS uses `ld` as linker, so add `-z muldefs` option
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z muldefs" )
endif(UNIX AND NOT APPLE)

## project compiler dependent settings
if(${CMake_Fortran_COMPILER_ID} MATCHES Intel)
add_definitions(-DINTEL)
add_compile_options(-xHost )
add_compile_options(-traceback)
add_compile_options(-fpe0) #
#add_compile_options(-w) #bad behavior, old codes usually use common block incorrectly. However, the warning is harmless.
add_compile_options(-ip) # interprocedural optimization
add_compile_options(-fno-alias) #gcc by default uses `-fargument-noalias-global`
elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES GNU)
add_compile_options(-march=native)
add_compile_options(-Wno-align-commons) #suppress some warnings about the padding of commons
add_compile_options(-fbacktrace)
else(${CMAKE_Fortran_COMPILER_ID} MATCHES Intel)
message(WARNING "Unsupported compiler iD: " ${CMAKE_Fortran_COMPILER_ID})
message(WARNING "Supported compiler iD: Intel/GNU")
message(WARNING "Try to use GNU options")
add_compile_options(-march=native)
add_compile_options(-Wno-align-commons) #suppress some warnings about the padding of commons
add_compile_options(-fbacktrace)
endif(${CMake_Fortran_COMPILER_ID} MATCHES Intel)

# it seems always use P3D_SINGLE in original Install script
add_definitions(-DP3D_SINGLE)

message("---------------------CFL3D programs summary--------------------------")
message("Build type? " ${CMAKE_BUILD_TYPE})
message("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message("CMAKE Fortran compiler ID: " ${CMAKE_Fortran_COMPILER_ID})
message("---------------------------------------------------------------------")

# set output library
# use CMAKE_XXX_OUTPUT_DIRECTORY to set the default dirs when create targets
# set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/lib/fortran)
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

add_subdirectory(source)
#add_subdirectory(testcases)

49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,52 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

------------
## About the CMake branch
As a practice of cmake, I had ported the make system of cfl3d to CMake, a modern industry-level build system. Which is much more easy to use, understand, modify and maintain.

### Compilation
```shell
## prerequirement (tested in Ubuntu 16.04)
sudo apt-get install libopenmpi-dev gfortran build-essential git cmake -y
# in RHEL/CentOS, you may try this:
# sudo yum install openmpi-devel gcc gcc-gfortran git cmake

## download the CMake branch only
git clone -b CMake --single-branch https://github.com/chengdi123000/CFL3D.git

## manually build cgns 2.5 without hdf5 and mpi
# you can also use your own cgns library if you put your cgnslib_f.h and libcgns.a in /usr/share/include and /usr/share/lib respectively
cd CFL3D/external/cgns
./build_cgns

## build cfl3d executables out of source
cd ../../build
cmake ..
make
# or you may benefit from parallel run, try:
# make -j`nproc`
# There will be a lot of warnings because I do not turn off all warnings as the original CFL3D build system do.
```

### Test
First set the PATH
```shell
## When completed, the executables will be in CFL3D/build/bin directory.
# suggest to use this line of script to add executables to PATH
# export PATH=$PWD/bin:$PATH
# You can use following line of script to add a command `use_cfl3d` to load executables ready to run after re-login
# echo "alias use_cfl3d='export PATH=$PWD/bin:\$PATH'">>$HOME/.bashrc
```
Then you need to download testcases
```shell
cd CFL3D/testcase
./download_testcases #wget is needed.
cd cfl3d.larc.nasa.gov/Cfl3dv6/2DTestcases/Flatplate
tar xvf Flatplate.tar.Z
# use_cfl3d
splitter < split.inp_1blk
cfl3d_seq < grdflat5.inp &
tail -f cfl3d.out #monitor the steps and residuals
```
Loading