Thermodynamic code is easier to review when readers can connect each quantity
to an equation, its units, and its independent variables. Prefer descriptive
names for algorithms and conventional symbols for equations; define the latter
where they first appear. Use three-space indentation, implicit none, explicit
imports where practical, and named closing statements.
In new code and pedagogical examples, put one variable on each declaration line, including scalars, arrays, loop indices, and derived-type components. This leaves room for a useful unit or physical meaning and makes changes easy to review. For example:
use yaeos, only: pr
implicit none
real(pr), intent(in) :: n(:) !! Component mole amounts [mol]
real(pr), intent(in) :: V !! Total volume [L], not molar volume
real(pr), intent(in) :: T !! Temperature [K]
real(pr), intent(out), optional :: ArV !! (dAr/dV) at fixed n,T [bar]
real(pr), allocatable :: kij(:, :) !! Dimensionless interaction matrix
integer :: i !! Component index
integer :: j !! Component index
This is a declaration fragment inside a procedure, not a standalone program.
Do not group these as real(pr) :: n(2), V, T or integer :: i, j. The
repository guide included below contains older grouped-array examples; use the
one-variable convention for new declarations rather than copying those groups.
Do not reformat unrelated source as part of a small fix.
The same rule applies to derived-type components and to dummy arguments:
type :: MyModel
real(pr), allocatable :: ac(:) !! Pure-component attraction parameters [bar L^2/mol^2]
real(pr), allocatable :: b(:) !! Pure-component covolumes [L/mol]
contains
procedure :: residual_helmholtz => my_ar !! Evaluate A^r and its derivatives
procedure :: get_v0 => my_v0 !! Volume scale for the liquid root [L]
end type MyModel
A reader comparing your code with the Fortran core guide of the developer handbook should find the same conventions in both.
Comments should add information: “total volume [L]” is useful; “variable V” is not. Array comments should explain index order when it matters, especially for interaction matrices and Hessians.
pr and use real(pr) and kind-qualified real literals such as
1.0_pr. Import R instead of hard-coding a gas constant with different units.n, V, T or n, P, T. Name optional outputs
at call sites when positional lists would obscure the derivative requested.ArV, ArT, ArTV, ArV2, Arn, Arn2, etc.;
general properties use names such as dPdV. State what stays fixed rather
than relying on a short variable name alone.size(n); the mole Hessian has two component
indices. A normalized composition derivative is not a mole derivative.Specify intent for procedure arguments when defining a new interface. When
overriding an existing deferred binding, however, match its declared attributes
exactly. The hyperdual Ar passed-object dummy has no intent; adding one can
break the override. Analytic residual_helmholtz, hyperdual Ar, and Tapenade
ar are different contracts, despite related names.
Guard optional outputs with present. Calculate shared working quantities in
local variables, not in an optional output that a caller may omit. Every
requested output must be assigned regardless of which others are present.
Document required initialization, array sizes, admissible domains, and any
assumptions such as symmetric parameter matrices.
Explain why a bound, step size, or tolerance is appropriate and give its units or scale. Avoid unexplained “magic” constants. Test ordinary states before edge cases, then add dilute, pure-component, and near-boundary cases relevant to the model. Do not turn a failed convergence check into a successful result by silently replacing nonfinite values.
For documentation, pair a mathematical definition with one minimal call and an interpretation of its output. Preserve existing examples and references when expanding a page. Compile runnable snippets against the current interface and label sketches honestly. See the contributing workflow for the build, test, and FORD preview steps, and the developer handbook for the surrounding codebase.
In guide text, link to the generated page, for example
[Mixing rules](../usage/eos/cubics/mixing.html), rather than a local .md
file. Resolve the path relative to the rendered page, and check any #anchor
against the generated HTML. FORD does not automatically rewrite ordinary
Markdown links from .md to .html.
This differs from FORD’s ordered_subpage front matter and include directives:
those identify source files and must retain their .md filenames.
An explicitly labelled external GitHub source-file link can also legitimately
end in .md; it is not an internal documentation navigation link.
yaeos Style GuideAdopting a consistent style can improve code legibility through the choice of good naming conventions.
In addition, style checks will be run during CI to flag any severe non-conformance.
This allows code review discussions to focus on semantics and substance rather than pedantry.
Consistent whitespace usage, and not polluting line endings with trailing white space makes git diffs considerably more legible.
This style guide is a living document and proposed changes may be adopted after discussing them and coming to a consensus.
common, pause, entry, arithmetic if and computed gotoreal*8 or etime(), use real(pr)R gas constant) should be upper casev and the total volume would be V.dXdy for first derivatives and dXdyz or dXdy2 for second order derivatives. The only exception is with energetic properties, like Ar, where derivatives are written like ArV, ArVn, etc.n, V, Tn, P, Thas_failed is preferred over hasfailedlinspace is preferred over lin_spaceArModelprogram, module, or submodule.f90 or .F90 if preprocessing is requiredmodule names should include its subdirectory, using yaeos__ for the parent
src directory. For example the module in src/equilibria/flash.f90
is named yaeos__equilibria_flash. If the module name is longer than the accepted number of columns of the compiler, it is possible to simplify to just initials of each word: yaeos__p_e_f_implementation
E.g., string_class.f90 and string_class_implementation.f90test subdirectory and have the same name as the module they are testing with the test_ prefix
added E.g., string_class.f90 and test/test_string_class.f90By setting and following a convention for indentation and whitespace, code reviews and git-diffs can focus on the semantics of the proposed changes rather than style and formatting.
We recommend ~~enforce~~ the use of findent to format your files.
intent for dummy arguments.dimension attribute to declare arrays because it is more verbose.
Use this:real, allocatable :: a(:), b(:,:)real, dimension(:), allocatable :: areal, dimension(:,:), allocatable :: bdimension can be used as an exception if it makes the code less verbose.optional attribute is used to declare a dummy argument, it should follow the intent attribute.Fortran allows certain block constructs or scopes to include the name of the program unit in the end statement.
The convention adopted herein is to include procedure names, module names and program names in the end statement
Documentation strings should be provided for all public and protected entities and their arguments or parameters. This is currently accomplished using the FORD tool. For help writing FORD style documentation please see the FORD wiki. The following sections are most relevant for contributing new code:
To write the “spec” (specification) for a new proposal, please place it in the
FORD “pages” directory at
doc/page/.
To get help please see the “Writing Pages”
and “Writing Documentation” pages
on the FORD wiki.