Skip to content
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ results/figures/*.png
results/*.xlsx
__pycache__/
*.egg-info
memmaps
memmaps
.claude
.venv
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.0
7 changes: 1 addition & 6 deletions lib/enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,7 @@ class PlotType(Enum):
Polymer_Concentration_Plot = 2
Surfactant_Concentration_Plot = 3


class ResevoirGeometry(Enum):
"""
Selection of the geometry of the resevoir for the simulation
"""

class ReservoirGeometry(Enum):
Rectilinear = 1
Quarter_Five_Spot = 2

Expand Down
780 changes: 731 additions & 49 deletions lib/simulation.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup, find_packages

setup(name="surfactant_polymer_flooding", packages=find_packages())
Empty file added tests/__init__.py
Empty file.
148 changes: 60 additions & 88 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,22 @@
import os

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../lib")))

import pytest
import numpy as np
from numpy.testing import assert_allclose
from lib.simulation import Simulation
from lib.polymer import Polymer
from lib.surfactant import Surfactant
from lib.enumerations import (
PolymerList,
ModelType,
PermeabilityType,
PlotType,
SurfactantList,
ResevoirGeometry,
SimulationConstants,
)

MODEL = {
"No Shear Thinning": 1,
"Sourav Implementation": 2,
"Shear Thinning": 3,
"No_Shear_Thinning": 1,
"Sourav_Implementation": 2,
"Shear_Thinning": 3,
}

GEOMETRY = {
"Rectilinear": 1,
"Quarter Five Spot": 2,
"Quarter_Five_Spot": 2,
}

PERMEABILITY = {
Expand All @@ -37,46 +28,51 @@
POLYMER = {
"Xanthane": 1,
"Schizophyllan": 2,
"No Polymer": 3,
"No_Polymer": 3,
}

SURFACTANT = {
"Alkyl Ether Sulfate": 1,
"No Surfactant": 2,
"Alkyl_Ether_Sulfate": 1,
"No_Surfactant": 2,
}

TRUE_VALUES_DIR = os.path.join(os.path.dirname(__file__), "true_values")

def load_true_values(sim_id):
base = f"true_values/sim_{sim_id}_"
return {
"COC": np.load(base + "COC.npy"),
"MFW": np.load(base + "MFW.npy"),
}
SIM_ID_TO_DIR = {
1: "simulation_one",
2: "simulation_two",
}


def load_coc(sim_id):
path = os.path.join(TRUE_VALUES_DIR, SIM_ID_TO_DIR[sim_id], "COC.csv")
return np.loadtxt(path).flatten()


@pytest.mark.e2e
@pytest.mark.parametrize(
"simulation_id, model_type, reservoir_geometry, permeability, polymer_type, polymer_concentration, surfactant_type, surfactant_concentration",
[
(
1,
MODEL["Shear Thinning"],
MODEL["Shear_Thinning"],
GEOMETRY["Rectilinear"],
PERMEABILITY["Homogeneous"],
PERMEABILITY["Heterogeneous"],
POLYMER["Xanthane"],
0.001,
SURFACTANT["No Surfactant"],
SURFACTANT["No_Surfactant"],
0,
) # ,
# (
# 2,
# MODEL["No Shear Thinning"],
# GEOMETRY["Rectilinear"],
# PERMEABILITY["Homogeneous"],
# POLYMER["Schizophyllan"],
# 0.001,
# SURFACTANT["No Surfactant"],
# 0,
# ),
),
(
2,
MODEL["No_Shear_Thinning"],
GEOMETRY["Rectilinear"],
PERMEABILITY["Heterogeneous"],
POLYMER["Schizophyllan"],
0.001,
SURFACTANT["No_Surfactant"],
0,
),
],
)
def test_e2e(
Expand All @@ -89,53 +85,29 @@ def test_e2e(
surfactant_type,
surfactant_concentration,
):
plot_type = PlotType.Saturation_Plot # TODO: MAKE DYNAMIC

model_type = ModelType(model_type)
reservoir_geometry = ResevoirGeometry(reservoir_geometry)
permeability_flag = PermeabilityType(permeability)
polymer_type = PolymerList.get_by_value(polymer_type)
polymer_concentration = polymer_concentration
surfactant_type = SurfactantList(surfactant_type)
surfactant_concentration = surfactant_concentration

polymer_obj = Polymer(
name=polymer_type,
initial_concentration=polymer_concentration,
e_coeff=polymer_type.e_coeff,
n_coeff=polymer_type.n_coeff,
)

surfactant_obj = Surfactant(
name=surfactant_type,
initial_concentration=surfactant_concentration,
IFT_conc_equ=lambda GG: 10.001 / (GG + 1)
- 0.001, # TODO: make dynamic depending on the surfactant type
derivative_IFT_conc_equ=lambda GG: (-10.001)
/ ((GG + 1) ** 2), # TODO: make dynamic depending on the surfactant type
)

SOG = SimulationConstants.Grid_Size.value

simulation = Simulation(
sim_id=simulation_id,
size_of_grid=SOG,
polymer=polymer_obj,
surfactant=surfactant_obj,
resevoir_geometry=reservoir_geometry,
permeability_flg=permeability_flag,
mdl_id=model_type,
plt_type=plot_type,
)

simulation_output = simulation.execute_simulation()
expected_output = load_true_values(simulation_id)

# compare simulation output with expected output
assert_allclose(
simulation_output["COC"],
expected_output["COC"],
rtol=1e-5,
atol=1e-8,
err_msg=f"COC mismatch in e2e test for simulation id = {simulation_id}",
)
user_dict = {
"simulation_id": simulation_id,
"model_type": model_type,
"reservoir_geometry": reservoir_geometry,
"permeability": permeability,
"polymer_type": polymer_type,
"polymer_concentration": polymer_concentration,
"surfactant_type": surfactant_type,
"surfactant_concentration": surfactant_concentration,
}

sim = Simulation(user_input_dict=user_dict)
sim.run()

expected_coc = load_coc(simulation_id)

print(f"sim.coc: {sim.COC[-1][-1]} and expected_coc: {expected_coc[-1]}")
assert abs(sim.COC[-1] - expected_coc[-1]) < 1e-5, f"Final COC mismatch for simulation_id={simulation_id}"

# assert_allclose(
# np.asarray(sim.COC).flatten()[-1],
# expected_coc[-1],
# rtol=1e-5,
# atol=1e-8,
# err_msg=f"Final COC mismatch for simulation_id={simulation_id}",
# )
Binary file removed tests/e2e/true_values/sim_1_COC.npy
Binary file not shown.
Binary file removed tests/e2e/true_values/sim_1_MFW.npy
Binary file not shown.
Binary file removed tests/e2e/true_values/sim_2_COC.npy
Binary file not shown.
Binary file removed tests/e2e/true_values/sim_2_MFW.npy
Binary file not shown.
Loading
Loading