# HowTo Adding a new transport equation

From OpenFOAMWiki

Suppose you want to solve and additional scalar transport equation for the scalar ψ by adding it to an existing solver. The equation has the form

$\frac{\partial}{\partial t} \left(\rho \psi \right) + \nabla \cdot \phi \psi - \nabla \cdot \Gamma \nabla \psi = S_{\psi}$

where ρ and Γ are defined as dimensionedScalar and are retrieved from a dictionary using the lookup member function. Sφ is the source term.

To implement the equation, just add the line:

`dimensionedScalarField psi;`

to the createFields.H file of the solver,

Then, solve the equation by adding the following lines in the point of the solver where you want the equation to be solved.

``` 
solve
(
    fvm::ddt(rho, psi)
  + fvm::div(phi, psi)
  - fvm::laplacian(gamma, psi)
  ==
    S_psi
);```

In this example, the source term is treated explicitly. To manage it implicitly, OpenFOAM provides the Sp and the SuSp functions. Suppose we can write it as Sk = Κψ. The code lines to solve the same equation with an implicit treatment of the source term are:

``` 
solve
(
    fvm::ddt(rho, psi)
  + fvm::div(phi, psi)
  - fvm::laplacian(gamma, psi)
  ==
    fvm::Sp(kappa, psi)
);```

SuSp(kappa, psi) can be used to discretise the source term implicitly or explicitly according to the sign of kappa.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 1, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9223951101303101, "perplexity_flag": "middle"}