Channelflow: a spectral Navier-Stokes simulator in C++
Introduction
Channelflow is a software system for numerical analysis of the
incompressible Navier-Stokes flow in rectangular geometries, written
in C++. The core engine of channelflow is a spectral CFD algorithm
for integrating the Navier-Stokes equations. This engine drives a number
of higher-level algorithms that (for example) compute equilibria,
traveling waves, and periodic orbits of Navier-Stokes. Channelflow
provides these algorithms in an easy-to-use, flexible, and intelligible
form by using relatively modern software design.
The main goals of Channelflow are
- to lower the barrier to entry to numerical research in fluid dynamics
- to enable creation of short, readable, easily-modified CFD codes
- to provide easy access to advanced algorithms for computing exact solutions of Navier-Stokes
- to show how modern software design and project management can benefit CFD
The following programs illustrate how channelflow's libraries
can function as a high-level, Matlab-like language for CFD research.
Each defines an initial condition and a base flow, configures a DNS
algorithm method, runs a time-stepping loop, and produces output, in
about a hundred lines of code.
- couette.cpp, a plane Couette simulation (75 lines)
- couette2.cpp, a plane Couette simulation
illustrating a variable time-stepping, loading of stored velocity fields,
and computation of simple statistics (86 lines)
- channel.cpp, a pressure-driven channel flow (150 lines)
- walllaw.cpp, verification of the "law of the wall"
in a pressure-driven channel flow (190 lines) (and walllaw.m, a
matlab script for plotting the results).
Channelflow is maintained as part of a research program in the dynamics
of low-Reynolds turbulence at the Center for Nonlinear Studies, Georgia
Institute of Technology. The channelflow distribution contains a number
of command-line utilities programs used in our daily research, for purposes
such as
These utility programs typically read a velocity field from disk, operate on it according
to command-line arguments, and store the result(s) to disk. The programs provide good
illustrations of channelflow's building-block approach to CFD. Further examples can be
found in the PCF-utils subdirectory of the channelflow tarball.
Flexible object-oriented programming
Channelflow is written as a C++ class library. The classes
act as building blocks for expressing particular channel-flow
simulations and associated data analysis, and underneath these, the
mathematical structures needed to perform the calculations.
Channelflow provides classes for representing Chebyshev expansions,
Fourier x Chebyshev x Fourier expansions, DNS algorithms, and a number
of differential equations. Each class has automatic memory management
and a set of high-level elemental operations, so that auxiliary data
fields and computations can be added to a program with a few lines of
code.
In channelflow, even the DNS algorithm is an object. This greatly
increases the flexibility of DNS computations. For example, a DNS can
be reparameterized and restarted multiple times within a single
program, multiple independent DNS computations can run side-by-side
within the same program, and DNS computations can run as small
components within a larger, more complex computations. As a result,
comparative calculations that formerly required coordination of
several programs through shell scripts and saved data files can be
done within single channelflow program.
Organized, readable library code
Channelflow uses object-oriented programming and data abstraction to
maximize the organization and readability of its library code.
Channelflow defines about a dozen C++ classes that act as abstract
data types for the major components of spectral channel-flow
simulation (diagram of class libraries).
Each class forms a level of abstraction in which a set of
mathematical operations are performed in terms of lower-level
abstractions, from time-stepping equations at the top to linear
algebra at the bottom. The channelflow library code thus naturally
reflects mathematical algorithm, both in overall structure and
line-by-line. One can look at any part of the code and quickly
understand what role it plays in the overall algorithm. One can learn
the algorithm in stages, either top-down or bottom-up, by focusing on
one level of abstraction at a time.
Other features
Channelflow is also
- Configurable: For example, channelflow's DNS algorithms
implement a variety of time-stepping schemes, external constraints,
and methods of calculating nonlinear terms.
- Extendable: The library code is structured to
take small-scale extensions such as additional time-stepping schemes.
Channelflow's object-oriented, modular structure allows channelflow
simulations to be embedded as small components within larger, more
complex computations.
- Moderately general: Channelflow provides elemental algebraic and
differential operators for its mathematical classes, so that most
quantities of interest can be calculated with a few lines of code.
However, Channelflow is not general regarding geometry: it works only with
rectangular geometries with two periodic and one nonhomogeneous direction.
- Verifiable: The source distribution contains a test suite
that verifies the correct behavior of major classes.
- Documented: The
Channelflow User's Manual contains annotated program examples,
discussion of design, an overview of the main classes from a user's
perspective, and a review of the mathematical algorithm.
- Supported: Channelflow is currently supported by its author via email.
Its support website is currently transitioning from the GNU Savannah project-management
system to www.channelflow.org. The old Savannah website is
here.
- Fast: Channelflow is as fast as comparable Fortran codes
- Free: Channelflow is
free software.
It is licensed under the
GNU GPL version 2
and available for download.
Channelflow's CFD core algorithm uses spectral discretization in
spatial directions (Fourier x Chebyshev x Fourier),
finite-differencing in time, and primitive variables (3d velocity and
pressure) to integrate the incompressible Navier-Stokes equations. The
algorithm is based on Kleiser and Schuman's primitive-variables
formulation, which uses a Chebyshev tau method for enforcement of the
no-slip conditions and influence-matrix and tau-correction algorithms
to determine the pressure. Channelflow generalizes this algorithm in
several ways, as described in the
Channelflow User's Manual. Channelflow's generalizations include
- Seven semi-implicit time-stepping algorithms: backwards differentiation
of orders 1-4, two 2nd-order Runge-Kutta schemes, and the classic 2nd-order
Crank-Nicolson Adams-Bashforth algorithm.
- Computation of the nonlinear term in seven forms: skew-symmetric,
rotational, convection, divergence, alternating convection/divergence,
or linearized about the base flow.
- Enforcement of pressure-gradient or mean-velocity constraints, either
constant or time-varying.
- Integration of total or fluctuating velocity fields.
- Arbitrary base-flow profiles U(y).
- Dealiased or aliased collocation calculations.
The algorithms for computing invariant solutions for plane Couette flow were
developed by Divakar Viswanath.
These algorithms combine a "hookstep" trust-region modification of the classic
Newton search with Krylov-subspace methods for solving the Newton-hookstep
equations, and use Arnoldi iteration for linear stability analysis.
Channelflow uses the elegant and powerful FFTW
library for its Fourier transforms.
References
- L. Kleiser and U. Schuman,
"Treatment of incompressibility and boundary conditions
in 3-D numerical spectral simulations of plane channel flows," in
Proc. 3rd GAMM Conf. Numerical Methods in Fluid Mechanics, ed. E. Hirsch (1980)
- Canuto, Hussaini, Quarteroni, and Zang,
Spectral Methods in Fluid Dynamics,
Springer-Verlag (1998)
- R. Peyret, Spectral Methods for Incompressible Flows,
Springer-Verlag (2002)
- D. Viswanath, "Recurrent motions within plane Couette turbulence,"
J. Fluid Mech. 580 (2007), arXiv:/physics/0604062
- M. Frigo and S.G. Johnson, "The Design and Implementation of FFTW3,"
Proceedings of the IEEE 93 (2) (2005)
Channelflow began in 1999 as a part of my Ph.D. research in
Theoretical and Applied Mechanics at Cornell University. It has been
under active development since; it nows serves as the primary platform
for numerical research in plane Couette dynamics at the Center for
Nonlinear Science in the Georgia Tech School of Physics. I know of
about 10-20 other active users of channelflow.
As of 2007 (release 1.2.x), channelflow contains utilities for
computing equilibria, periodic orbits, and linear stability modes for
plane Couette flow. Its DNS algorithms are verified as correct by the
test suite: correct integration of Orr-Sommerfeld eigenfunctions,
Poiseuille flow, and sinusoidal disturbances to Poiseuille flow.
Channelflow has also been verified against independent Fortran codes
in the computation of equilibria, eigenvalues, and periodic orbits of
plane Couette flow. Channelflow's test suite is not exhaustive, so
some inessential utility functions might still contain errors.
Channelflow releases are available as tar.gz files from the
download page.
If you have comments, questions, or suggestions regarding channelflow,
don't hesitate to email me. If you're interested in helping with development,
--anything from minor improvements to major enhancements--
please email me.
John Gibson
Last modified: Thu Mar 20 17:21:24 IST 2008