A rough outline of the (evolving) file naming conventions used in OpenFOAM.
OpenFOAM has historically used .H
for C++ header files and .C
for
C++ source/template files (may be changing in the future).
Header files
Naming | Type | Note / Description |
---|---|---|
.h | C/C++ | Rarely used in OpenFOAM |
.hh | C++ | Typically for generated code |
.hpp | C++ | Typically for code without OpenFOAM dependencies |
.hxx | C++ | Rarely used (may change in the future?) |
.H | C++ | Typical OpenFOAM header. Also misused for pasting together solver code |
fileFwd.H | Forward declarations for classes, data types and/or macros | |
fileI.H | Inline code implementation (header-like) | |
fileImpl.H | Declarations for implementation code (consider as private) | |
fileM.H | Declarations for macro code (often using pre-processor macros) | |
fileM.C | Implementation for macro code |
Source files
Naming | Type | Note / Description |
---|---|---|
.c | C | Rarely used in OpenFOAM |
.cc | C++ | Typically for generated code (eg, from ragel, lemon, ...) |
.cpp | C++ | Typically for code without OpenFOAM dependencies |
.cxx | C++ | OpenFOAM source code |
.C | C++ | OpenFOAM source code and/or template |
fileIO.* | IO related code for a given class | |
fileImpl.* | Implementation code (consider as private) | |
fileNew.* | Factory constructor code for a given class |
Using .cxx
instead of .cpp
is somewhat arbitrary, but cxx does
at least have corresponding CXXFLAGS
, for example.
Template files
As mentioned in the introduction, OpenFOAM has historically used .C
for both source and template files. This unfortunately also causes the
lnInclude
directory to become bloated with a number of source-only
files.
Moving forward, it is proposed that the source and template files be
properly distinguishable. This means that source will use the .cxx
extension and templates the .txx
extension.
Naming | Type | Note/Description |
---|---|---|
.C | C++ | OpenFOAM source code and/or template etc |
.tpp | C++ | currently rarely used |
.txx | C++ | OpenFOAM template code |
The legacy conventions for naming template code:
- fileTemplate.C : used by non-templated classes
- anything.C : template code for templated classes!
Future conventions for naming template code (future):
- .txx : templating code
File inclusion
Since OpenFOAM has a large number of interconnected classes, it was
decided to simplify their inclusion by simply dumping all
header-related items into a top-level lnInclude/
directory.
This avoids use of long relative paths in the respective #include
directives, at the cost of an additional (non-standard) step during
the build process.
As the name implies, the lnInclude/
directory is an include
directory generated with ln
symbolic links to the real files.
Copyright (C) 2023 OpenCFD Ltd.