# Mixer calculation

### Request payload

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        "name": "mixer",
        "chemistryModel": "mixerChemistry",
        "externalStreams": [...<snip>...],
        "inletInputs": [...<snip>...],
        "temperature": {
            "unit": "°C",
            "value": 50
        },
        "pressure": {
            "unit": "bar",
            "value": 1.1
        }
    }
}
```

| **params**      | type                                                           | description                                                                                                                                                                                                                                                          |
| --------------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name            | string                                                         | name of output stream                                                                                                                                                                                                                                                |
| chemistryModel  | string                                                         | [chemistry model file (dbs) name](https://devdocs.olisystems.com/oli-scalechem-api/main-methods/..#chemistry-model) for mixer calculation                                                                                                                            |
| externalStreams | array of objects                                               | [inputs for external streams](#external-streams)                                                                                                                                                                                                                     |
| inletInputs     | array of objects                                               | [flow rate specifications for mixer inlet streams](#undefined)                                                                                                                                                                                                       |
| temperature     | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified temperature with [unit](https://devdocs.olisystems.com/input-unit-set)                                                                                                                                                                                     |
| pressure        | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified pressure with [unit](https://devdocs.olisystems.com/input-unit-set)                                                                                                                                                                                        |
| inheritOptions  | boolean                                                        | Optional, option to apply "[optionalProperties](https://devdocs.olisystems.com/optional-inputs#optional-properties)"  and "[unitSetInfo](https://devdocs.olisystems.com/optional-inputs#output-units)" to calculation objects in "externalStreams". Default is false |

### External streams

External streams can be calculated by three types of inputs at isothermal conditions: 1) ionic species composition, 2) inflow species composition, 3) mixer calculation to combine calculated external stream.&#x20;

{% tabs %}
{% tab title="ionic input stream" %}

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        ...<snip>...
        "externalStreams": [
            {
                "name": "brine example",
                "chemistryModel": "brineChemistry",
                "waterAnalysisInputs": [...<snip>...]
            },
            {
                "name": "another stream",
                ...<snip>...
            },
            ...<snip>...
        ]
    }
}
```

{% endtab %}

{% tab title="inflow input stream" %}

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        ...<snip>...
        "externalStreams": [
            {
                "name": "inflow example",
                "chemistryModel": "inflowChemistry",
                "inflows": {...<snip>...},
                "temperature": {
                    "value": 50.0,
                    "unit": "°C"
                },
                "pressure": {
                    "value": 1.5,
                    "unit": "atm"
                },
                "saturateWithH2O": "gas"
            },
            {
                "name": "another stream",
                ...<snip>...
            },
            ...<snip>...
        ]
    }
}
```

{% endtab %}

{% tab title="mixer calculation stream" %}

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        ...<snip>...
        "externalStreams": [
            {
                "name": "example stream 1",
                ...<snip>...
            },
            {
                "name": "example stream 2",
                ...<snip>...
            },
            {
                "name": "mixer example",
                "chemistryModel": "externalMixerChemistry",
                "inletInputs": [
                    {
                        "streamName": "example stream 1",
                        "streamType": "brine",
                        "totalAmount": {
                            "value": 1,
                            "unit": "bbl/day"
                        }
                    },
                    {
                        "streamName": "example stream 2",
                        ...<snip>...
                    }
                ],
                "temperature": {
                    "value": 50.0,
                    "unit": "°C"
                },
                "pressure": {
                    "value": 1.5,
                    "unit": "atm"
                }
            },
            {
                "name": "another stream",
                ...<snip>...
            },
            ...<snip>...
        ]
    }
}
```

{% endtab %}
{% endtabs %}

#### Common external stream inputs

| **params.externalStreams\[{}]** | type   | description                                                   |
| ------------------------------- | ------ | ------------------------------------------------------------- |
| name                            | string | external stream name                                          |
| chemistryModel                  | string | optional, chemistry model file (dbs) name for external stream |

{% hint style="success" %}
"chemistryModel" input is optional. The chemistry model file of the mixer calculation will be used if this input is missing.
{% endhint %}

#### External stream from ionic input

All inputs are specified as an array of objects in "waterAnalysisInputs", which are explained in[ water analysis ](https://devdocs.olisystems.com/group1/api-functions/wateranalysis#water-analysis)calculation.

#### External stream from inflow input

| **params.externalStreams\[{}]** | type                                                           | description                                                                                                                     |
| ------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| inflows                         | object                                                         | [inflow input](https://devdocs.olisystems.com/inflows-input)                                                                    |
| temperature                     | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified temperature with [unit](https://devdocs.olisystems.com/input-unit-set)                                                |
| pressure                        | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified pressure with [unit](https://devdocs.olisystems.com/input-unit-set)                                                   |
| saturateWithH2O                 | string                                                         | optional, could be specified as "gas" or "oil", which will add H2O to the system to saturate the corresponding phase with water |

#### External stream from mixer calculation

|                                 |                                                                |                                                                                                             |
| ------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **params.externalStreams\[{}]** | type                                                           | description                                                                                                 |
| inletInputs                     | array of objects                                               | name, type, and flow rate for combining stream, as explained in [inlet specification](#inlet-specification) |
| temperature                     | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified temperature with [unit](https://devdocs.olisystems.com/input-unit-set)                            |
| pressure                        | [valueObject](https://devdocs.olisystems.com/terms-definition) | specified pressure with [unit](https://devdocs.olisystems.com/input-unit-set)                               |

{% hint style="warning" %}
External streams are calculated in the order of the input array. Any mixer calculation specified in external streams can combine external streams that are already calculated.
{% endhint %}

{% hint style="info" %}
Any mixer calculation in external streams can be treated as an inlet for followed mixer calculations. In other words, mixer calculations can be specified cascadingly in external streams.
{% endhint %}

### Inlet specification

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        ...<snip>...
        "inletInputs": [
            {
                "streamName": "external stream 1",
                "streamType": "brine",
                "totalAmount": {
                    "value": 1.0, 
                    "unit": "bbl/day"
                }
            },
            {
                "streamName": "external stream 2",
                ...<snip>...
            },
            ...<snip>...
        ]
    }
}
```

|                             |                                                                |                                                                                                                                    |
| --------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| **params.inletInputs\[{}]** | type                                                           | description                                                                                                                        |
| streamName                  | string                                                         | name of the [external stream](#external-streams) to be combined in mixer                                                           |
| streamType                  | string                                                         | stream type, this determines target phases to be combined in mixer                                                                 |
| totalAmount                 | [valueObject](https://devdocs.olisystems.com/terms-definition) | inlet stream flow rate with unit explained below                                                                                   |
| automaticFlowRate           | boolean                                                        | optional, when speciefied as true, total flow rate specified in the external stream will be used, then "totalAmount" is not needed |

{% hint style="warning" %}
"automaticFlowRate" can only be specified true when the corresponding external stream is calculated in [flowing system](https://devdocs.olisystems.com/inflows-input#units-in-flowing-systems).
{% endhint %}

#### Inlet stream types

| **params.inletInputs\[{}].streamType** | phases to be combined     | phase property to be used in calculating flow rate |
| -------------------------------------- | ------------------------- | -------------------------------------------------- |
| brine                                  | liquid-1                  | liquid-1                                           |
| oil                                    | vapor, liquid-2           | liquid-2                                           |
| gas                                    | vapor, liquid-2           | vapor                                              |
| whole fluid                            | liquid-1, liquid-2, vapor | all phases                                         |

<table data-header-hidden><thead><tr><th width="221.79121149644584"></th><th></th></tr></thead><tbody><tr><td><strong>params.inletInputs[{}].streamType</strong></td><td><strong>params.inletInputs[{}].totalAmount.unit</strong> numerators</td></tr><tr><td>brine, whole fluid</td><td>bbl, L, ml, cm3, m3, E3m3, E6m3, ft3, Mft3, MMft3, gal, MMgal</td></tr><tr><td>oil</td><td>std bbl, std m3, std L, bbl, m3, L</td></tr><tr><td>gas</td><td>std MMft3, std Mft3, std ft3, std E3m3, std m3, std L, MMft3, Mft3, ft3, E3m3, m3, L</td></tr></tbody></table>

{% hint style="info" %}
**params.inletInputs\[{}].totalAmount.unit** is flow rate unit with volumetric units as shown above divide by a time unit, i.e. bbl/day. Available time units are s, min, hr, day, yr.
{% endhint %}

### Saturator option (optional)

This option can be specified to saturate one or more solid species by varying the inflow species.

```json
{
    "method": "scalechem.mixerCalculation",
    "params": {
        ...<snip>...
        "saturatorOptions": [
            {
                "mineralToSaturate": "BASO4PPT",
                "inflowToVary": "BASO4"
            },
            ...<snip>...
        ]
    }
}
```

|                                  |        |                                                                                                                                                                                 |
| -------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **params.saturatorOptions\[{}]** | type   | description                                                                                                                                                                     |
| mineralToSaturate                | string | solid species to be saturated, using "trueName"  for species with solid phase. See [chemistry information](https://devdocs.olisystems.com/group1/api-functions/chemistry-info). |
| inflowToVary                     | string | varying inflow species, using "baseName"  for inflows. See [chemistry information](https://devdocs.olisystems.com/group1/api-functions/chemistry-info).                         |

### Additional input

{% hint style="info" %}
In addition to the inputs shown above, some optional properties may also be specified. They can be viewed [here](https://devdocs.olisystems.com/optional-inputs).
{% endhint %}

### Response (status = PROCESSED)

```json
{
    "code": 200,
    "result": {
       "external stream 1": {...<snip>...},
       "external stream 2": {...<snip>...},
       ...<snip>...,
       "mixer outlet stream": {...<snip>...}
    },
    "message": "Results returned successfully", 
    "status": "PROCESSED"
}
```

The "result" contains all [stream outputs ](https://devdocs.olisystems.com/stream-output-json)for each external stream and the final mixer outlet stream by their names specified in the input.

### Survey Calculation

Survey calculation is supported for the variables below. Please refer to [Survey calculation](https://devdocs.olisystems.com/survey-calculation) for explained input schema.

| supported **params.surveyInputs\[{}].field**                                                                                        |
| ----------------------------------------------------------------------------------------------------------------------------------- |
| "/params/temperature/value"                                                                                                         |
| "/params/pressure/value"                                                                                                            |
| "/params/inletInputs/***i***/totalAmount/value" where ***i*** is the index (0 based) of the **params.inletInputs** array of objects |
