Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert score materials from the SCORE to alfacase #2

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/alfasim_score/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
from pathlib import Path

from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader


@pytest.fixture
def score_input_example(shared_datadir: Path) -> ScoreInputReader:
return ScoreInputReader(shared_datadir / "score_input_example.json")
2 changes: 2 additions & 0 deletions src/alfasim_score/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
WELLBORE_TOP_NODE = "WELBORE_TOP_NODE"
WELLBORE_BOTTOM_NODE = "WELBORE_BOTTOM_NODE"
ANNULUS_TOP_NODE_NAME = "WELLBORE_ANNULUS_TOP_NODE"

CEMENT_NAME = "cement"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pytest_regressions.data_regression import DataRegressionFixture

from alfasim_score.converter.alfacase.convert_alfacase import ScoreAlfacaseConverter
from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader


def test_convert_materials(
data_regression: DataRegressionFixture,
score_input_example: ScoreInputReader,
) -> None:
builder = ScoreAlfacaseConverter(score_input_example)
materials = builder.convert_materials()

data_regression.check(
[
{
"name": material.name,
"type": material.material_type.value,
"density": material.density.GetValue(),
"thermal_conductivity": material.thermal_conductivity.GetValue(),
"heat_capacity": material.heat_capacity.GetValue(),
"thermal_expansion": material.expansion.GetValue(),
}
for material in materials
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
- density: 15.7743
heat_capacity: 837.9
name: cement
thermal_conductivity: 0.983057
thermal_expansion: 1.0e-06
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 65.5035
heat_capacity: 460.9
name: SDSS/125KSI
thermal_conductivity: 45.345257
thermal_expansion: 1.2e-05
type: solid
- density: 1.0
heat_capacity: 5.0
name: Folhelho
thermal_conductivity: 50.0
thermal_expansion: 0.0
type: solid
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader


@pytest.fixture
def score_input_example(shared_datadir: Path) -> ScoreInputReader:
return ScoreInputReader(shared_datadir / "score_input_example.json")


def test_convert_well_trajectory(
num_regression: NumericRegressionFixture,
score_input_example: ScoreInputReader,
) -> None:
builder = ScoreAlfacaseConverter(score_input_example)
well_description = builder.build_well()

num_regression.check(
{
"x": well_description.profile.x_and_y.x.GetValues("m"),
Expand Down
25 changes: 25 additions & 0 deletions src/alfasim_score/converter/alfacase/convert_alfacase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import List

from alfasim_sdk import AnnulusDescription
from alfasim_sdk import FormationDescription
from alfasim_sdk import MaterialDescription
from alfasim_sdk import MaterialType
from alfasim_sdk import ProfileDescription
from alfasim_sdk import WellDescription
from alfasim_sdk import XAndYDescription
Expand All @@ -26,6 +30,27 @@ def _convert_well_trajectory(self) -> ProfileDescription:
x, y = self.score_input.read_well_trajectory()
return ProfileDescription(x_and_y=XAndYDescription(x=x, y=y))

def convert_materials(self) -> List[MaterialDescription]:
"""Convert list of materials from SCORE file"""
material_descriptions = []
material_list = (
self.score_input.read_cement_material()
+ self.score_input.read_tubing_materials()
+ self.score_input.read_lithology_materials()
)
for data in material_list:
material_descriptions.append(
MaterialDescription(
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
name=data["name"],
material_type=MaterialType.Solid,
density=data["density"],
thermal_conductivity=data["thermal_conductivity"],
heat_capacity=data["specific_heat"],
expansion=data["thermal_expansion"],
)
)
return material_descriptions

# TODO PWPA-1937: implement this method
def _convert_annulus(self) -> AnnulusDescription:
return AnnulusDescription(has_annulus_flow=False, top_node=ANNULUS_TOP_NODE_NAME)
Expand Down
82 changes: 81 additions & 1 deletion src/alfasim_score/converter/alfacase/score_input_reader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from typing import Dict
from typing import List
from typing import Tuple
from typing import Union

import json
from barril.units import Array
from barril.units import Scalar
from pathlib import Path
from typing import Tuple

from alfasim_score.constants import CEMENT_NAME
from alfasim_score.units import DENSITY_UNIT
from alfasim_score.units import FRACTION_UNIT
from alfasim_score.units import LENGTH_UNIT
from alfasim_score.units import SPECIFIC_HEAT_UNIT
from alfasim_score.units import THERMAL_CONDUCTIVITY_UNIT
from alfasim_score.units import THERMAL_EXPANSION_UNIT
from alfasim_score.units import YOUNG_MODULUS_UNIT


class ScoreInputReader:
Expand All @@ -17,3 +29,71 @@ def read_well_trajectory(self) -> Tuple[Array, Array]:
x = [entry["displacement"] for entry in self.input_content["trajectory"]["data"]]
y = [-entry["vertical_depth"] for entry in self.input_content["trajectory"]["data"]]
return Array(x, LENGTH_UNIT), Array(y, LENGTH_UNIT)

def read_tubing_materials(self) -> List[Dict[str, Union[Scalar, str]]]:
"""Read the data for the tubings from SCORE input file."""
tubing_data = []
for section in self.input_content["operation"]["tubing_string"]["string_sections"]:
thermal_property = section["pipe"]["grade"]["thermomechanical_property"]
tubing_data.append(
{
"name": section["pipe"]["grade"]["name"],
"density": Scalar(thermal_property["density"], DENSITY_UNIT),
"thermal_conductivity": Scalar(
thermal_property["thermal_conductivity"], THERMAL_CONDUCTIVITY_UNIT
),
"specific_heat": Scalar(thermal_property["specific_heat"], SPECIFIC_HEAT_UNIT),
"thermal_expansion": Scalar(
thermal_property["thermal_expansion_coefficient"], THERMAL_EXPANSION_UNIT
),
"young_modulus": Scalar(thermal_property["e"], YOUNG_MODULUS_UNIT),
"poisson_ratio": Scalar(thermal_property["nu"], FRACTION_UNIT),
}
)
return tubing_data

def read_cement_material(self) -> List[Dict[str, Union[Scalar, str]]]:
"""
Read the data for the cement from SCORE input file.
This method assumes all configured cement properties are the same and that
the first_slurry and second_slurry have the same properties.
"""
properties = self.input_content["well_strings"][0]["cementing"]["first_slurry"][
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
"thermomechanical_property"
]
return [
{
"name": CEMENT_NAME,
"density": Scalar(properties["density"], DENSITY_UNIT),
"thermal_conductivity": Scalar(
properties["thermal_conductivity"], THERMAL_CONDUCTIVITY_UNIT
),
"specific_heat": Scalar(properties["specific_heat"], SPECIFIC_HEAT_UNIT),
"thermal_expansion": Scalar(
properties["thermal_expansion_coefficient"], THERMAL_EXPANSION_UNIT
),
"young_modulus": Scalar(properties["e"], YOUNG_MODULUS_UNIT),
"poisson_ratio": Scalar(properties["nu"], FRACTION_UNIT),
}
]

def read_lithology_materials(self) -> List[Dict[str, Union[Scalar, str]]]:
"""Read the data for the lithologies from SCORE input file."""
lithology_data = []
for lithology in self.input_content["lithologies"]:
properties = lithology["thermomechanical_property"]
lithology_data.append(
{
"name": lithology["display_name"],
"density": Scalar(properties["density"], DENSITY_UNIT),
"thermal_conductivity": Scalar(
properties["thermal_conductivity"], THERMAL_CONDUCTIVITY_UNIT
),
"specific_heat": Scalar(properties["specific_heat"], SPECIFIC_HEAT_UNIT),
# expansion in the file has null value and APB assumes 0.0 for this parameter
"thermal_expansion": Scalar(0.0, THERMAL_EXPANSION_UNIT),
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
"young_modulus": Scalar(properties["e"], YOUNG_MODULUS_UNIT),
"poisson_ratio": Scalar(properties["nu"], FRACTION_UNIT),
}
)
return lithology_data
9 changes: 9 additions & 0 deletions src/alfasim_score/converter/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from pathlib import Path

from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader


@pytest.fixture
def score_input_example(shared_datadir: Path) -> ScoreInputReader:
return ScoreInputReader(shared_datadir / "score_input_example.json")
6 changes: 6 additions & 0 deletions src/alfasim_score/units.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
LENGTH_UNIT = "m"
DENSITY_UNIT = "kg/m3"
SPECIFIC_HEAT_UNIT = "J/kg.K"
THERMAL_CONDUCTIVITY_UNIT = "W/m.K"
THERMAL_EXPANSION_UNIT = "1/K"
YOUNG_MODULUS_UNIT = "psi"
FRACTION_UNIT = "-"
Loading