WARPXM v1.10.0
|
The following contains coding standards for the WARPXM coding project.
apps
, dfem\variable_adjusters\boundary_condition\
.ndg.cc
, oscillating_wall.h
.WARPXM input files contain information for the set up of a WARPXM simulation (see page on working with input files for more details).
Input file names often use the run name (default behavior for warpy generated input files). Otherwise filenames should be descriptive enough to distinguish them from a mesh file, which can share the same filename extension .inp
.
WARPXM input files are written in XML format. When using the warpy library to run WARPXM simulations, the input file will be generated, and formatted, atomically.
The input file is case sensitive! Naming conventions have not been strictly followed in the past. Below is a list of common, and suggested, conventions:
plasma_gradient_ic
, dt_controller
.WmSolverBase
, WmHostAction
, mesh
..cc
file as a register string. When creating new kind names, conventions are either lower camel case, or lower case with underscore separation for apps: WmSolver
, patchProcessor
, explicit_runge_kutta
.setup
method. Convention currently varies a lot, but the preferred standard is upper camel case, and should be descriptive: BasisArraySet
, OutputFileName
, DensityMin
.The primary language of WARPXM is C++. Much of what is described here are standard C++ coding conventions, plus some preferences particular to this project.
Header files (indicated in this project by .h
) contain all declarations, along with a number of other important procedural functions that are useful to have separated from the meaty details in the implementation file. This list includes:
Include guards. Include guards prevent a header file from being included more than once during compilation. WARPXM previously used the #ifndef
style include guard, but now uses the #pragma once
convention as it is now widely supported and reduces the chance for programmer error. For more details on the pros and cons of both see this discussion.
Old style
New style
Implementation files (indicated in this project by .cc
) contain all the definitions that were not detailed in the header file.
WMAPPLICATIONFLAG_INTERNALFLUX
Wm
, Wx
): Application
, LogStream
debug_stream
, patch
, app
_cfl
, _omega_p_tau
.t
, x
.Methods or functions. Lower camel case, descriptive: getNumLayers()
.
Accessing methods or functions:
ClassPointer->methodName()
: Accessing a public field or method by referencing a class or object pointer.ClassInstance.methodName()
: Accessing variables and methods via object (class instance).ClassName::methodName()
: Accessing static variables and methods of a class, struct, or namespace, or from another scope.this->methodName()
: this
is a pointer to the instance of the object calling the method. It is automatically initialized. Used for when calling another objects method from within that same object. Somebody correct me.wxm
, dfem
, solver
_t
. Descriptive to not interfere with standard types. Use only when necessary. _t
should not be used for classes!: _t
: distributed_variable_t
Formatting conventions are outlined below. Formatting can be automatically enforced through Clang Format (instructions at end of this page).
+
,-
, and =
: a = b + c
a = b + (c - d)
for
and if
statements: for (int i = 0; i < 0; i++)
int[4] a = [0, 1, 2, 3]
Comments serve two purposes:
Commenting guidelines for the WARPXM project are described in the documentation commenting page.
Python is used within WARPXM for setting up and running simulations, as well as post-processing, most of which is handled by the warpy
library, and Python input files located in the examples
and user_runs
directories.
See naming conventions for C++, with the following additions/exceptions:
Currently following the formatting recommendations in the PEP 8 Style Guide for Python Code. This can be automatically enforced through the yapf
program (see Formatting Tools section for further details).
See documentation commenting page.
Clang Format is a formatting tool that reformats C/C++ files based on a set of rules. The .clang-format
file in the top level directory of the WARPXM repository describes the formatting rules for this project.
Clang Format can be integrated into Emacs, vim, and other IDEs, or run from the command line. Please see the "Clang Format Setup Guide" in the WARPXM group Dropbox folder for setup details. Official documentation for Clang Format can be found here.
yapf
is a Python formatting tool based on Clang Format. Usage is similar and is described here. It can be installed through source code from the previous link, or through the Python package manager Pip.
The style file for the WARPXM repository is .style.yapf
, located in the top level directory.
yapf
can be integrated into Emacs or Vim.
yapf
is not deterministic. It uses a penalty method to decide whether to split lines or add spaces. Which means if you rerun yapf
on the same file, you may not get the same result. That being said, the formatting is still more consistent than humans, and it takes the thinking out of enforcing a lot of nit-picky rules that greatly increase readability.
Following is an explanation of some of non trivial yapf
formatting rules:
reformats to