<!-- Important: This file has been automatically generated by generate_example_docs.py. Do not edit this file directly! -->


| [:arrow_left: Back to the main documentation](../README.md) | [:arrow_left: Go back to part 4](fluidmaterial.md) |
|---|---:|

# Biomineralization - Solids

The main idea of biomineralization revolves around
biologically-induced mineral precipitation.
I our example, it is about precipitation of calcite
due to urea hydrolysis.
The resulting overall reaction equation is:

```math
\mathrm{CO(NH_2)_2} + 2\mathrm{H_2O} + \mathrm{Ca^{2+}} \xrightarrow{urease}
2\mathrm{NH_{4}^{+}} + \mathrm{CaCO_{3}} \downarrow.
```

To describe the processes, the minimum set of components is:
water (w), dissolved inorganic carbon (C<sub>tot</sub>),
sodium (Na), chloride (Cl), calcium (Ca), urea (u), glucose as a substrate (s), oxygen (O<sub>2</sub>), and suspended biomass (b),
as well as the solid components biofilm and calcite.
Thus, there are many components involved and keeping track of the components and their interactions,
necessitates a sophisticated handling.
This is why the material folder in this example is both separated from the regular material folder in dumux/dumux/material
and also documented separately.
For further specialization, the overview over the material subfolder is split into solid and fluid, this description considering the solids.

## Solids in the folder `material`

As this example is about biomineralization involving many components with complex inteactions, some specific solid material files are necessary.
First, `material/components/biofilm.hh` defines the solid component biofilm, which plays an essential role in biomineralization by providing the essential catalytic activity for biomineralization.
Second, as biofilm grows or calcite precipitates, the volume fractions of those non-inert solids change, influencing the overall properties of the solids in the system.
The specific solidsystem `material/solidsystems/biominsolids.hh` gives the relations on how to
calculate the resulting average solid properties based on the solids volume fractions.


The subsequent documentation is structured as follows:

[[_TOC_]]


[@Span1996]: https://aip.scitation.org/doi/abs/10.1063/1.555991 "A new equation of state for carbon dioxide covering the fluid region from the triple-point temperature to 1100 K at pressures up to 800 MPa"


## The biofilm component (`biofilm.hh`)

This file contains the __solid component class__ which defines the name, molar mass and density of biofilm


<details open>
<summary><b>Click to hide/show the file documentation</b> (or inspect the [source code](../material/components/biofilm.hh))</summary>


### Include files

```cpp
// including the base and the generic solid component
#include <dumux/material/components/base.hh>
#include <dumux/material/components/solid.hh>

#include <dumux/common/parameters.hh>
```

### The biofilm component

```cpp
namespace Dumux::Components {

// In Biofilm, we define the properties of the solid component biofilm
template <class Scalar>
class Biofilm
: public Components::Base<Scalar, Biofilm<Scalar> >
, public Components::Solid<Scalar, Biofilm<Scalar> >
{
public:
    // the name
    static std::string name()
    { return "Biofilm"; }
```

### The biofilm component's properties

```cpp
    // The molar mass, which is not really defined for biofilm. Thus, we read it from params.input or use a default of 1.
    // Based on a cell mass of 2.5e-16, the molar mass of cells would be 1.5e8 kg/mol, but biofilms are more than just cells and such high molar masses would lead to numerical problems.
    static Scalar molarMass()
    {
        Scalar molarMass = getParam<Scalar>("BioCoefficients.BiofilmMolarMass", 1);
        return molarMass;
    }

    // The density, or rather the dry density (dry biomass/wet volume), most of biofilm is water.
    // It is typically highly variable for different biofilms, thus we read it from params.input or use the default value of 10 kg/m^3
    static Scalar solidDensity(Scalar temperature)
    {
        Scalar rho = getParam<Scalar>("BioCoefficients.BiofilmDensity", 10);
        return rho;
    }
};

} // end namespace Dumux::Components
```


</details>



## The solid system (`biominsolids.hh`)

This file contains the __solidystem class__ which defines all functions needed to describe the solid and their properties,
which are needed to model biomineralization.


<details open>
<summary><b>Click to hide/show the file documentation</b> (or inspect the [source code](../material/solidsystems/biominsolids.hh))</summary>


### Include files

```cpp
#include <string>
#include <dune/common/exceptions.hh>

// we include all necessary solid components
#include <examples/biomineralization/material/components/biofilm.hh>
#include <dumux/material/components/calcite.hh>
#include <dumux/material/components/granite.hh>
```

### The solidsystem class
In the BioMinSolidPhase solid system, we define all functions needed to describe the solids and their properties accounted for in our simulation.
We enter the namespace Dumux. All Dumux functions and classes are in a namespace Dumux, to make sure they don`t clash with symbols from other libraries you may want to use in conjunction with Dumux.

```cpp
namespace Dumux::SolidSystems {

template <class Scalar>
class BioMinSolidPhase
{
public:
```

#### Component definitions
With the following function we define what solid components will be used by the solid system and define the indices used to distinguish  solid components in the course of the simulation.

```cpp
    // We use convenient declarations that we derive from the property system.
    using Biofilm = Components::Biofilm<Scalar>;
    using Calcite = Components::Calcite<Scalar>;
    using Granite = Components::Granite<Scalar>;

    /****************************************
     * Solid phase related static parameters
     ****************************************/
    static constexpr int numComponents = 3;
    static constexpr int numInertComponents = 1;
    static constexpr int BiofilmIdx = 0;
    static constexpr int CalciteIdx = 1;
    static constexpr int GraniteIdx = 2;

    // The component names
    const static std::string componentName(int compIdx)
    {
        switch (compIdx)
        {
            case BiofilmIdx: return Biofilm::name();
            case CalciteIdx: return Calcite::name();
            case GraniteIdx: return Granite::name();
            default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
        }
    }

    // The solid system's name
    static std::string name()
    { return "BiomineralizationMinSolidPhase"; }

    // We assume incompressible solids
    static constexpr bool isCompressible(int compIdx)
    { return false; }

    // we have one inert component, the others may change
    static constexpr bool isInert()
    { return (numComponents == numInertComponents); }
```

#### Component properties
This simply forwards the component properties (name, molar mass, density).

```cpp
    // The component molar masses
    static Scalar molarMass(int compIdx)
    {
        switch (compIdx)
        {
            case BiofilmIdx: return Biofilm::molarMass();
            case CalciteIdx: return Calcite::molarMass();
            case GraniteIdx: return Granite::molarMass();
            default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
        }
    }

    // The component densities
    template <class SolidState>
    static Scalar density(const SolidState& solidState, const int compIdx)
    {
        switch (compIdx)
        {
            case BiofilmIdx: return Biofilm::solidDensity(solidState.temperature());
            case CalciteIdx: return Calcite::solidDensity(solidState.temperature());
            case GraniteIdx: return Granite::solidDensity(solidState.temperature());
            default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
        }
    }

    // The component molar densities
    template <class SolidState>
    static Scalar molarDensity(const SolidState& solidState, const int compIdx)
    {
        switch (compIdx)
        {
            case BiofilmIdx: return Biofilm::solidDensity(solidState.temperature())/Biofilm::molarMass();
            case CalciteIdx: return Calcite::solidDensity(solidState.temperature())/Calcite::molarMass();
            case GraniteIdx: return Granite::solidDensity(solidState.temperature())/Calcite::molarMass();
            default: DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);
        }
    }
```

#### Averaged solid properties
The overall solid properties are calculated by a volume-weigthed average of the pure component's properties.

```cpp
    // The average density
    template <class SolidState>
    static Scalar density(const SolidState& solidState)
    {
        const Scalar rho1 = Biofilm::solidDensity(solidState.temperature());
        const Scalar rho2 = Calcite::solidDensity(solidState.temperature());
        const Scalar rho3 = Granite::solidDensity(solidState.temperature());
        const Scalar volFrac1 = solidState.volumeFraction(BiofilmIdx);
        const Scalar volFrac2 = solidState.volumeFraction(CalciteIdx);
        const Scalar volFrac3 = solidState.volumeFraction(GraniteIdx);

        return (rho1*volFrac1+
                rho2*volFrac2+
                rho3*volFrac3)
               /(volFrac1+volFrac2+volFrac3);
    }
```


</details>


| [:arrow_left: Back to the main documentation](../README.md) | [:arrow_left: Go back to part 4](fluidmaterial.md) |
|---|---:|

