> For the complete documentation index, see [llms.txt](https://devdocs.olisystems.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devdocs.olisystems.com/group1/api-functions/corrosion-rates.md).

# Corrosion rates

This function calculates the corrosion rates of a given metal contact surface under a specified solution condition.

{% hint style="danger" %}
This calculation is currently only supported for the **AQ thermodynamic framework**
{% endhint %}

## corrosion rates

<mark style="color:green;">`POST`</mark> `https://api.olisystems.com/engine/flash/{dbs_file_id}/corrosion-rates`

calculate the corrosion rate

#### Headers

| Name          | Type   | Description            |
| ------------- | ------ | ---------------------- |
| Authorization | string | Bearer {access\_token} |
| Content-Type  | string | application/json       |

{% tabs %}
{% tab title="200 Please look at "API call blueprint" page on how to obtain results" %}

```
{
	"code": 200,
	"data": {
		"file_id": "dee854a6-59db-487d-ad08-a20dee691133",
		"jobId": "f6b3375e-cd0f-4ace-a5ee-71e047b76754",
		"resultsLink": "https://api.olisystems.com/result/flash/f6b3375e-cd0f-4ace-a5ee-71e047b76754?context=engine",
		"status": "IN PROGRESS"
	},
	"message": "Process execution started Successfully",
	"status": "SUCCESS"
}
```

{% endtab %}
{% endtabs %}

### Request payload

```javascript
{
    "params": {
        "temperature": {
            "value": 40.0,
            "unit": "°C"
        },
        "pressure": {
            "value": 1.5,
            "unit": "atm"
        },
        "calculationType": "isothermal",
        "inflows": {
            "unit": "mol",
            "values": {
                "H2O": 50.0,
                "NACL": 0.01,
                "HNO3": 1,
                "FEEL": 0.0
            },
            "totalAmount":
            {
                "value": 51.01,
                "unit": "mol"
            }
        },
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "static"
        }
}
```

| **params**      | type                                | description                                                            |
| --------------- | ----------------------------------- | ---------------------------------------------------------------------- |
| temperature     | [valueObject](/terms-definition.md) | specified or initial guess temperature with [unit](/input-unit-set.md) |
| pressure        | [valueObject](/terms-definition.md) | specified or initial guess pressure with [unit](/input-unit-set.md)    |
| calculationType | string                              | single point flash calculation type of solution, e.g. isothermal       |

{% hint style="danger" %}
**params.calculationType** currently only supports the "isothermal" type.
{% endhint %}

### Corrosion parameters

| **params.corrosionParameters** | type   | description                                                                                                                              |
| ------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| contactSurface                 | string | contact surface metal name, which can be retrieved from [Corrosion contact surfaces](/group1/api-functions/corrosion-contact-surface.md) |
| flowType                       | string | flow configuration                                                                                                                       |

#### Options for flowType

| **params.corrosionParameters.flowType** | description                                                                |
| --------------------------------------- | -------------------------------------------------------------------------- |
| static                                  | mimics static flow                                                         |
| pipeFlow                                | mimics pipe flow                                                           |
| rotatingDisk                            | several parallel disks that are rotating                                   |
| rotatingCylinder                        | several parallel cylinders that are rotating                               |
| completeAgitation                       | liquid phase is completely agitated and no mass transfer limitations apply |
| definedShearStress                      | define the stress of applied force over material                           |
| approximateMultiPhaseFlow               | mimics an approximate multi-phase flow                                     |

{% hint style="info" %}
Additional corrosion parameters may be required for different flow types, which are explained as below
{% endhint %}

#### Additional parameters if flowType is pipeFlow

```javascript
{
    "params": {
        ...<snip>...,
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "pipeFlow",
            "pipeDiameter": {
                "value": 0.05,
                "unit": "m"
            },
            "pipeFlowVelocity": {
                "value": 6.0,
                "unit": "ft/s"
            }
        },
        ...<snip>...
}
```

| **params.corrosionParameters** | type                                | description                                       |
| ------------------------------ | ----------------------------------- | ------------------------------------------------- |
| pipeDiameter                   | [valueObject](/terms-definition.md) | pipe diameter and [unit](/inflows-input.md)       |
| pipeFlowVelocity               | [valueObject](/terms-definition.md) | pipe flow velocity and [unit](/input-unit-set.md) |

#### Additional parameters if flowType is rotatingDisk

```javascript
{
    "params": {
        ...<snip>...,
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "rotatingDisk",
            "diskDiameter": {
                "value": 0.6,
                "unit": "in"
            },
            "diskRotationSpeed": {
                "value": 15.0,
                "unit": "cycle/s"
            }
        },
        ...<snip>...
}
```

| **params.corrosionParameters** | type                                | description                                        |
| ------------------------------ | ----------------------------------- | -------------------------------------------------- |
| diskDiameter                   | [valueObject](/terms-definition.md) | disk diameter and [unit](/input-unit-set.md)       |
| diskRotationSpeed              | [valueObject](/terms-definition.md) | disk rotation speed and [unit](/input-unit-set.md) |

#### Additional parameters if flowType is rotatingCylinder

```javascript
{
    "params": {
        ...<snip>...,
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "rotatingCylinder",
            "rotorDiameter": {
                "value": 5,
                "unit": "mm"
            },
            "rotorRotation": {
                "value": 1000,
                "unit": "cycle/min"
            }
        },
        ...<snip>...
}
```

| **params.corrosionParameters** | type                                | description                                         |
| ------------------------------ | ----------------------------------- | --------------------------------------------------- |
| rotorDiameter                  | [valueObject](/terms-definition.md) | rotor diameter and [unit](/input-unit-set.md)       |
| rotorRotation                  | [valueObject](/terms-definition.md) | rotor rotation speed and [unit](/input-unit-set.md) |

#### Additional parameters if flowType is definedShearStress

```javascript
{
    "params": {
        ...<snip>...,
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "definedShearStress",
            "shearStress": {
                "value": 0.01,
                "unit": "kPa"
            }
        },
        ...<snip>...
}
```

| **params.corrosionParameters** | type                                | description                                 |
| ------------------------------ | ----------------------------------- | ------------------------------------------- |
| shearStress                    | [valueObject](/terms-definition.md) | shear stress and [unit](/input-unit-set.md) |

#### Additional parameters if flowType is approximateMultiPhaseFlow

```javascript
{
    "params": {
        ...<snip>...,
        "corrosionParameters":
        {
            "contactSurface": "Carbon steel G10100 (generic)",
            "flowType": "approximateMultiPhaseFlow",
            "pipeDiameter": {
                "value": 10.0,
                "unit": "cm"
            },
            "liquidFlowInPipe": {
                "value": 0.2,
                "unit": "m3/s"
            },
            "gasFlowInPipe": {
                "value": 0.1,
                "unit": "m3/s"
            },
            "pipeRoughness": {
                "value": 0.15,
                "unit": "cm"
            },
            "viscAbs2ndLiq": {
                "value": 15.0,
                "unit": "cP"
            },
            "waterCutAtPointOfDispersionInversion": 0.7,
            "maxRelViscosityOfDispersionAtInversion": 10.0
        },
        ...<snip>...
}
```

| **params.corrosionParameters**         | type                                | description                                                     |
| -------------------------------------- | ----------------------------------- | --------------------------------------------------------------- |
| pipeDiameter                           | [valueObject](/terms-definition.md) | pipe diameter and [unit](/input-unit-set.md)                    |
| liquidFlowInPipe                       | [valueObject](/terms-definition.md) | liquid flow in pipe and [unit](/input-unit-set.md)              |
| gasFlowInPipe                          | [valueObject](/terms-definition.md) | gas flow in pipe and [unit](/input-unit-set.md)                 |
| pipeRoughness                          | [valueObject](/terms-definition.md) | pipe roughness and [unit](/input-unit-set.md)                   |
| viscAbs2ndLiq                          | [valueObject](/terms-definition.md) | absolute viscosity of 2nd liquid and [unit](/input-unit-set.md) |
| waterCutAtPointOfDispersionInversion   | number                              | water cut at point of dispersion inversion                      |
| maxRelViscosityOfDispersionAtInversion | number                              | max relative viscosity of dispersion at inversion               |

{% hint style="info" %}
in addition to the inputs shown above some optional properties may also be specified. They can be viewed [here](/optional-inputs.md)
{% endhint %}

### Response (status = "PROCESSED")

```javascript
{
    "code": 200,
    "data": {
        "result": {
           ...<snip>...
            "corrosionOutputs": {
                "corrosionPotential": {
                    "value": -0.2751504098799078,
                    "unit": "V (SHE)"
                },
                "repassivationPotential": {
                    "value": -0.4851063187462839,
                    "unit": "V (SHE)"
                },
                "corrosionRateGPerMsqDay": {
                    "value": 382.2467320945027,
                    "unit": "g/m3-day"
                },
                "corrosionRateMmPerYear": {
                    "value": 17.728088591422296,
                    "unit": "mm/yr"
                },
                "corrosionRateMilPerYear": {
                    "value": 697.9562437567834,
                    "unit": "mil/yr"
                },
                "corrosionCurrentDensity": {
                    "value": 15.288766842782513,
                    "unit": "A/sq-m"
                },
                "maximumPitCurrentDensity": {
                    "value": 23.87887042448192,
                    "unit": "A/sq-m"
                }
            }
        }
    }, 
    "message": "Results returned successfully", 
    "status": "PROCESSED"
}
```

The output of this calculation is the [stream output ](/stream-output-json.md)which is common result output for all OLI's flash calculations or an [error](/error-output.md). In addition to this output the the corrosion output information can be conveniently retrieved from the **data.result.corrosionOutputs** array&#x20;

| data.result.corrosionOutputs | type                                | description                                |
| ---------------------------- | ----------------------------------- | ------------------------------------------ |
| corrosionPotential           | [valueObject](/terms-definition.md) | corrosion potential                        |
| repassivationPotential       | [valueObject](/terms-definition.md) | repassivation potential                    |
| corrosionRateGPerMsqDay      | [valueObject](/terms-definition.md) | corrosion rate in gram per cubic meter day |
| corrosionRateMmPerYear       | [valueObject](/terms-definition.md) | corrosion rate in mm per year              |
| corrosionRateMilPerYear      | [valueObject](/terms-definition.md) | corrosion rate in mil per year             |
| corrosionCurrentDensity      | [valueObject](/terms-definition.md) | corrosion current density                  |
| maximumPitCurrentDensity     | [valueObject](/terms-definition.md) | maximum pit current density                |

{% hint style="warning" %}
All output units are fixed to what is shown in this example
{% endhint %}

### Survey Calculation

Survey calculation is supported for the variables below. Please refer to [Survey calculation](/survey-calculation.md) for explained input schema.

| supported **params.surveyInputs\[{}].field** |
| -------------------------------------------- |
| "/params/temperature/value"                  |
| "/params/pressure/value"                     |
