CaNS移植指南

CaNS移植指南

GitHub地址

CaNS介绍:

CaNS(Canonical Navier-Stokes)是用于流体流动的大规模并行数值模拟的代码。它旨在求解不可压缩牛顿流体的任何流体流动,该流体可以受益于基于 FFT 的求解器,用于 3D 笛卡尔网格中的二阶有限差分泊松方程。

获取源码

采用v1.1.4版本的代码

1
2
3
wget  https://github.com/p-costa/CaNS/archive/refs/tags/v1.1.4.tar.gz
tar xzvf v1.1.4.tar.gz
cd CaNS-1.1.4/

编译安装

进入src/main目录,修改Makefile中的LIBS

1
LIBS = -L/path/to/fftw/lib -lfftw3 -lfftw3_threads

然后执行make,在当前目录下生成cans,或者可以执行make run,将生成的cans、data、dns.ini移动到../run

1
2
3
4
make
make run
cd ../run
mpirun -np 4 cans dns.in

spack 安装脚本

package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *


class Cans(MakefilePackage):
"""FIXME: Put a proper description of your package here."""

homepage = "https://github.com/p-costa/CaNS"
url = "https://github.com/p-costa/CaNS/archive/refs/tags/v1.1.4.tar.gz"

maintainers = ['lhxone', 'github_user2']

version('1.1.4', sha256='8334c67810472edc18d5403a0bcb27fd57a620722c1e8c317518db4506867b81')
version('1.1.3', sha256='01fa42e51ddcf6161fb63a124a0f2218c67f85ff4cc5236b995a5650d85e7615')
version('1.1.2', sha256='31c8d6c1f619fb60b7919922c7a3a64dd614a1a2f89f38560184f75ed0526171')
version('1.1.0', sha256='e3fd84902e18715c6476fe780e2395ca04db9e6b0c830b55a7aa9204b1fd0886')

# FIXME: Add dependencies if required.
depends_on('openmpi', type = ('build', 'run'))
depends_on('fftw', type = ('build', 'run'))

def edit(self, spec, prefix):
with working_dir('src'):
makefile = FileFilter('Makefile')
makefile.filter('LIBS =.*', 'LIBS = -L{} -lfftw3 -lfftw3_threads'.format(spec['fftw'].prefix.lib))

def build(self, spec, prefix):
with working_dir('src'):
make()

def install(self, spec, prefix):
mkdir(prefix.bin)
with working_dir('src'):
install('cans', prefix.bin)