diff --git a/src/alfasim_score/common.py b/src/alfasim_score/common.py new file mode 100644 index 0000000..6f29a53 --- /dev/null +++ b/src/alfasim_score/common.py @@ -0,0 +1,25 @@ +from typing import Any +from typing import Dict + +from barril.units import Array +from barril.units import Scalar + + +def prepare_for_regression(values: Dict[str, Any]) -> Dict[str, Any]: + """ "Prepare Scalar and Array to the be used in regression test""" + regression_values = {} + for key, value in values.items(): + if isinstance(value, Scalar): + regression_values[key] = { + "value": value.value, + "unit": value.unit, + } + elif isinstance(value, Array): + regression_values[key] = { + "values": value.values, + "unit": value.unit, + } + else: + regression_values[key] = value + + return regression_values diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing.py b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing.py index 43799e1..76e4d0a 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing.py +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing.py @@ -5,6 +5,7 @@ from pathlib import Path from pytest_regressions.data_regression import DataRegressionFixture +from alfasim_score.common import prepare_for_regression from alfasim_score.converter.alfacase.convert_alfacase import ScoreAlfacaseConverter from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader @@ -17,19 +18,21 @@ def test_convert_casing_list( casings = builder._convert_casing_list() data_regression.check( [ - { - "name": casing.name, - "hanger_depth": casing.hanger_depth.GetValue(), - "settings_depth": casing.settings_depth.GetValue(), - "hole_diameter": casing.hole_diameter.GetValue(), - "outer_diameter": casing.outer_diameter.GetValue(), - "inner_diameter": casing.inner_diameter.GetValue(), - "inner_roughness": casing.inner_roughness.GetValue(), - "material": casing.material, - "top_of_filler": casing.top_of_filler.GetValue(), - "filler_material": casing.filler_material, - "material_above_filler": casing.material_above_filler, - } + prepare_for_regression( + { + "name": casing.name, + "hanger_depth": casing.hanger_depth, + "settings_depth": casing.settings_depth, + "hole_diameter": casing.hole_diameter, + "outer_diameter": casing.outer_diameter, + "inner_diameter": casing.inner_diameter, + "inner_roughness": casing.inner_roughness, + "material": casing.material, + "top_of_filler": casing.top_of_filler, + "filler_material": casing.filler_material, + "material_above_filler": casing.material_above_filler, + } + ) for casing in casings ] ) @@ -43,14 +46,16 @@ def test_convert_tubing_list( tubings = builder._convert_tubing_list() data_regression.check( [ - { - "name": tubing.name, - "length": tubing.length.GetValue(), - "outer_diameter": tubing.outer_diameter.GetValue(), - "inner_diameter": tubing.inner_diameter.GetValue(), - "inner_roughness": tubing.inner_roughness.GetValue(), - "material": tubing.material, - } + prepare_for_regression( + { + "name": tubing.name, + "length": tubing.length, + "outer_diameter": tubing.outer_diameter, + "inner_diameter": tubing.inner_diameter, + "inner_roughness": tubing.inner_roughness, + "material": tubing.material, + } + ) for tubing in tubings ] ) @@ -64,11 +69,13 @@ def test_convert_packer_list( packers = builder._convert_packer_list() data_regression.check( [ - { - "name": packer.name, - "position": packer.position.GetValue(), - "material_above": packer.material_above, - } + prepare_for_regression( + { + "name": packer.name, + "position": packer.position, + "material_above": packer.material_above, + } + ) for packer in packers ] ) @@ -82,12 +89,14 @@ def test_convert_open_hole_list( open_holes = builder._convert_open_hole_list() data_regression.check( [ - { - "name": hole.name, - "length": hole.length.GetValue(), - "diameter": hole.diameter.GetValue(), - "inner_roughness": hole.inner_roughness.GetValue(), - } + prepare_for_regression( + { + "name": hole.name, + "length": hole.length, + "diameter": hole.diameter, + "inner_roughness": hole.inner_roughness, + } + ) for hole in open_holes ] ) diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_casing_list.yml b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_casing_list.yml index 485e92a..f7526fc 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_casing_list.yml +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_casing_list.yml @@ -1,55 +1,125 @@ - filler_material: cement - hanger_depth: 2072.0 - hole_diameter: 42.0 - inner_diameter: 33.0 - inner_roughness: 0.05 + hanger_depth: + unit: m + value: 2072.0 + hole_diameter: + unit: in + value: 42.0 + inner_diameter: + unit: in + value: 33.0 + inner_roughness: + unit: mm + value: 0.05 material: B material_above_filler: fluid_default name: CONDUCTOR_DRILLING_1 - outer_diameter: 36.0 - settings_depth: 2168.0 - top_of_filler: 2072.0 + outer_diameter: + unit: in + value: 36.0 + settings_depth: + unit: m + value: 2168.0 + top_of_filler: + unit: m + value: 2072.0 - filler_material: cement - hanger_depth: 2072.0 - hole_diameter: 20.0 - inner_diameter: 16.25 - inner_roughness: 0.05 + hanger_depth: + unit: m + value: 2072.0 + hole_diameter: + unit: in + value: 20.0 + inner_diameter: + unit: in + value: 16.25 + inner_roughness: + unit: mm + value: 0.05 material: X-80 material_above_filler: fluid_default name: SURFACE_CASING_1 - outer_diameter: 18.0 - settings_depth: 3490.0 - top_of_filler: 2072.0 + outer_diameter: + unit: in + value: 18.0 + settings_depth: + unit: m + value: 3490.0 + top_of_filler: + unit: m + value: 2072.0 - filler_material: cement - hanger_depth: 2072.0 - hole_diameter: 14.75 - inner_diameter: 10.711 - inner_roughness: 0.05 + hanger_depth: + unit: m + value: 2072.0 + hole_diameter: + unit: in + value: 14.75 + inner_diameter: + unit: in + value: 10.711 + inner_roughness: + unit: mm + value: 0.05 material: N-80 material_above_filler: fluid_default name: PRODUCTION_CASING_1 - outer_diameter: 11.875 - settings_depth: 3072.0 - top_of_filler: 4905.0 + outer_diameter: + unit: in + value: 11.875 + settings_depth: + unit: m + value: 3072.0 + top_of_filler: + unit: m + value: 4905.0 - filler_material: cement - hanger_depth: 3072.0 - hole_diameter: 14.75 - inner_diameter: 9.156 - inner_roughness: 0.05 + hanger_depth: + unit: m + value: 3072.0 + hole_diameter: + unit: in + value: 14.75 + inner_diameter: + unit: in + value: 9.156 + inner_roughness: + unit: mm + value: 0.05 material: C-110 HC material_above_filler: fluid_default name: PRODUCTION_CASING_2 - outer_diameter: 10.75 - settings_depth: 5441.0 - top_of_filler: 4905.0 + outer_diameter: + unit: in + value: 10.75 + settings_depth: + unit: m + value: 5441.0 + top_of_filler: + unit: m + value: 4905.0 - filler_material: cement - hanger_depth: 5441.0 - hole_diameter: 14.75 - inner_diameter: 8.684000000000001 - inner_roughness: 0.05 + hanger_depth: + unit: m + value: 5441.0 + hole_diameter: + unit: in + value: 14.75 + inner_diameter: + unit: in + value: 8.684000000000001 + inner_roughness: + unit: mm + value: 0.05 material: SDSS/125KSI material_above_filler: fluid_default name: PRODUCTION_CASING_3 - outer_diameter: 10.75 - settings_depth: 5607.0 - top_of_filler: 4905.0 + outer_diameter: + unit: in + value: 10.75 + settings_depth: + unit: m + value: 5607.0 + top_of_filler: + unit: m + value: 4905.0 diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_open_hole_list.yml b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_open_hole_list.yml index 1dfe220..0504ab9 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_open_hole_list.yml +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_open_hole_list.yml @@ -1,4 +1,10 @@ -- diameter: 9.5 - inner_roughness: 0.1 - length: 371.0 +- diameter: + unit: in + value: 9.5 + inner_roughness: + unit: mm + value: 0.1 + length: + unit: m + value: 371.0 name: OPEN_HOLE_1 diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_packer_list.yml b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_packer_list.yml index 8ef01db..beb9325 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_packer_list.yml +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_packer_list.yml @@ -1,3 +1,5 @@ - material_above: fluid_default name: 'Packer (HidrĂ¡ulico) #1' - position: 5565.18 + position: + unit: m + value: 5565.18 diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_tubing_list.yml b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_tubing_list.yml index 78379d9..4e843c3 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_tubing_list.yml +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_casing/test_convert_tubing_list.yml @@ -1,96 +1,224 @@ -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 40.210000000000036 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 40.210000000000036 material: SDSS/125KSI name: TUBING_1 - outer_diameter: 5.5 -- inner_diameter: 5.791 - inner_roughness: 0.05 - length: 732.9000000000001 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 5.791 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 732.9000000000001 material: SDSS/125KSI name: TUBING_2 - outer_diameter: 6.625 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 56.40000000000009 + outer_diameter: + unit: in + value: 6.625 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 56.40000000000009 material: SDSS/125KSI name: TUBING_3 - outer_diameter: 5.5 -- inner_diameter: 5.791 - inner_roughness: 0.05 - length: 48.90000000000009 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 5.791 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 48.90000000000009 material: SDSS/125KSI name: TUBING_4 - outer_diameter: 6.625 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 54.90000000000009 + outer_diameter: + unit: in + value: 6.625 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 54.90000000000009 material: SDSS/125KSI name: TUBING_5 - outer_diameter: 5.5 -- inner_diameter: 5.791 - inner_roughness: 0.05 - length: 2400.9 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 5.791 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 2400.9 material: SDSS/125KSI name: TUBING_6 - outer_diameter: 6.625 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 158.97000000000025 + outer_diameter: + unit: in + value: 6.625 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 158.97000000000025 material: SDSS/125KSI name: TUBING_7 - outer_diameter: 5.5 -- inner_diameter: 3.92 - inner_roughness: 0.05 - length: 31.039999999999964 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 3.92 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 31.039999999999964 material: SDSS/125KSI name: TUBING_8 - outer_diameter: 4.5 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 24.899999999999636 + outer_diameter: + unit: in + value: 4.5 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 24.899999999999636 material: SDSS/125KSI name: TUBING_9 - outer_diameter: 5.5 -- inner_diameter: 3.92 - inner_roughness: 0.05 - length: 21.670000000000073 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 3.92 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 21.670000000000073 material: SDSS/125KSI name: TUBING_10 - outer_diameter: 4.5 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 20.23999999999978 + outer_diameter: + unit: in + value: 4.5 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 20.23999999999978 material: SDSS/125KSI name: TUBING_11 - outer_diameter: 5.5 -- inner_diameter: 3.92 - inner_roughness: 0.05 - length: 27.420000000000073 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 3.92 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 27.420000000000073 material: SDSS/125KSI name: TUBING_12 - outer_diameter: 4.5 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 132.89999999999964 + outer_diameter: + unit: in + value: 4.5 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 132.89999999999964 material: SDSS/125KSI name: TUBING_13 - outer_diameter: 5.5 -- inner_diameter: 3.92 - inner_roughness: 0.05 - length: 21.670000000000073 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 3.92 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 21.670000000000073 material: SDSS/125KSI name: TUBING_14 - outer_diameter: 4.5 -- inner_diameter: 4.67 - inner_roughness: 0.05 - length: 20.23999999999978 + outer_diameter: + unit: in + value: 4.5 +- inner_diameter: + unit: in + value: 4.67 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 20.23999999999978 material: SDSS/125KSI name: TUBING_15 - outer_diameter: 5.5 -- inner_diameter: 3.92 - inner_roughness: 0.05 - length: 31.859999999999673 + outer_diameter: + unit: in + value: 5.5 +- inner_diameter: + unit: in + value: 3.92 + inner_roughness: + unit: mm + value: 0.05 + length: + unit: m + value: 31.859999999999673 material: SDSS/125KSI name: TUBING_16 - outer_diameter: 4.5 + outer_diameter: + unit: in + value: 4.5 diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_materials.py b/src/alfasim_score/converter/alfacase/_tests/test_convert_materials.py index 208a800..599dd62 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_materials.py +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_materials.py @@ -1,5 +1,6 @@ from pytest_regressions.data_regression import DataRegressionFixture +from alfasim_score.common import prepare_for_regression from alfasim_score.converter.alfacase.convert_alfacase import ScoreAlfacaseConverter from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader @@ -13,14 +14,16 @@ def test_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(), - } + prepare_for_regression( + { + "name": material.name, + "type": material.material_type.value, + "density": material.density, + "thermal_conductivity": material.thermal_conductivity, + "heat_capacity": material.heat_capacity, + "thermal_expansion": material.expansion, + } + ) for material in materials ] ) diff --git a/src/alfasim_score/converter/alfacase/_tests/test_convert_materials/test_convert_materials.yml b/src/alfasim_score/converter/alfacase/_tests/test_convert_materials/test_convert_materials.yml index 87b82d4..62b26c1 100644 --- a/src/alfasim_score/converter/alfacase/_tests/test_convert_materials/test_convert_materials.yml +++ b/src/alfasim_score/converter/alfacase/_tests/test_convert_materials/test_convert_materials.yml @@ -1,48 +1,112 @@ -- density: 15.7743 - heat_capacity: 837.9 +- density: + unit: kg/m3 + value: 15.7743 + heat_capacity: + unit: J/kg.K + value: 837.9 name: cement - thermal_conductivity: 0.983057 - thermal_expansion: 1.0e-06 + thermal_conductivity: + unit: W/m.K + value: 0.983057 + thermal_expansion: + unit: 1/K + value: 1.0e-06 type: solid -- density: 65.5035 - heat_capacity: 460.9 +- density: + unit: kg/m3 + value: 65.5035 + heat_capacity: + unit: J/kg.K + value: 460.9 name: B - thermal_conductivity: 45.345257 - thermal_expansion: 1.2e-05 + thermal_conductivity: + unit: W/m.K + value: 45.345257 + thermal_expansion: + unit: 1/K + value: 1.2e-05 type: solid -- density: 65.5035 - heat_capacity: 460.9 +- density: + unit: kg/m3 + value: 65.5035 + heat_capacity: + unit: J/kg.K + value: 460.9 name: X-80 - thermal_conductivity: 45.345257 - thermal_expansion: 1.2e-05 + thermal_conductivity: + unit: W/m.K + value: 45.345257 + thermal_expansion: + unit: 1/K + value: 1.2e-05 type: solid -- density: 65.5035 - heat_capacity: 460.9 +- density: + unit: kg/m3 + value: 65.5035 + heat_capacity: + unit: J/kg.K + value: 460.9 name: N-80 - thermal_conductivity: 45.345257 - thermal_expansion: 1.2e-05 + thermal_conductivity: + unit: W/m.K + value: 45.345257 + thermal_expansion: + unit: 1/K + value: 1.2e-05 type: solid -- density: 65.5035 - heat_capacity: 460.9 +- density: + unit: kg/m3 + value: 65.5035 + heat_capacity: + unit: J/kg.K + value: 460.9 name: C-110 HC - thermal_conductivity: 45.345257 - thermal_expansion: 1.2e-05 + thermal_conductivity: + unit: W/m.K + value: 45.345257 + thermal_expansion: + unit: 1/K + value: 1.2e-05 type: solid -- density: 65.5035 - heat_capacity: 460.9 +- density: + unit: kg/m3 + value: 65.5035 + heat_capacity: + unit: J/kg.K + value: 460.9 name: SDSS/125KSI - thermal_conductivity: 45.345257 - thermal_expansion: 1.2e-05 + thermal_conductivity: + unit: W/m.K + value: 45.345257 + thermal_expansion: + unit: 1/K + value: 1.2e-05 type: solid -- density: 1.0 - heat_capacity: 5.0 +- density: + unit: kg/m3 + value: 1.0 + heat_capacity: + unit: J/kg.K + value: 5.0 name: Folhelho - thermal_conductivity: 50.0 - thermal_expansion: 0.0 + thermal_conductivity: + unit: W/m.K + value: 50.0 + thermal_expansion: + unit: 1/K + value: 0.0 type: solid -- density: 1000.0 - heat_capacity: 4181.0 +- density: + unit: kg/m3 + value: 1000.0 + heat_capacity: + unit: J/kg.K + value: 4181.0 name: fluid_default - thermal_conductivity: 0.6 - thermal_expansion: 0.0004 + thermal_conductivity: + unit: W/m.K + value: 0.6 + thermal_expansion: + unit: 1/K + value: 0.0004 type: fluid