Skip to content

Commit

Permalink
make some minor changes to pytest file and also did some refactoring …
Browse files Browse the repository at this point in the history
…on the simulation class within simulation.py
  • Loading branch information
bhargavakula01 committed Jan 16, 2025
1 parent bc6e654 commit d3d1194
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 92 deletions.
129 changes: 38 additions & 91 deletions lib/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Simulation:
"""
Class is used to generate an instance of a simulation which will run the SP-flooding model based on the given parameters provided by the user
"""
def __init__(self, sim_id, polymer, surfactant, init_water_saturation, resevoir_geometry, permeability_flg, mesh_grid, is_surfactant, mdl_id, plt_type):
def __init__(self, sim_id, polymer, surfactant, init_water_saturation, resevoir_geometry, permeability_flg, mesh_grid, mdl_id, plt_type):
"""
creates instance of the simulation class which will enable for calculating changes in system parameters at every time-step
Expand All @@ -25,10 +25,10 @@ def __init__(self, sim_id, polymer, surfactant, init_water_saturation, resevoir_
:param polymer: Polymer object used in SP-flooding run
:type polymer: Polymer
:param surfactant: Surfactant object used in SP-flooding run
:type surfactant: Surfactant
:param surfactant: Surfactant object used in SP-flooding run (can also be non if surfactant concentration = 0)
:type surfactant: Surfactant, None
:param init_water_saturation: Initial Water Saturation
:param init_water_saturation: Initial Water Saturation (scalar quantitiy)
:type init_water_saturation: float
:param resevoir_geometry: Type of resevoir geometry (is it a rectilinear or quarter-five-spot geometry)
Expand All @@ -40,107 +40,47 @@ def __init__(self, sim_id, polymer, surfactant, init_water_saturation, resevoir_
:param mesh_grid: mesh_grid used in the SP-flooding run
:type mesh_grid: Box
:param is_surfactant: boolean that states whether there is surfactant in the system or not
:type is_surfactant: bool
:param mdl_id: the model id for the simulation (whether shear thinning is on or off)
:type mdl_id: enum 'ModelType'
:param plt_type: the plot type outputted by the program for the simulation run
:type plt_type: enum 'PlotType'
"""

#Polymer and Surfactant Properties
self._polymer_ = None
self._surfactant_ = None
self.sim_id = sim_id

#Instances of the polymer and surfactant objects
self.polymer = polymer
self.surfactant = surfactant

#User Inputs
self._resevoir_geometry_ = None
self._permeability_flag_ = None
self._mesh_ = Box()
#Simulaiton Properties
self.resevoir_geometry = resevoir_geometry
self.permeability_flg = permeability_flg
self.mesh = mesh_grid

#simulation properties
self._water_saturation_ = 0
self._init_water_saturation_scalar_ = init_water_saturation
self._aqueous_viscosity_ = 0
self._oleic_mobility_ = 0
self._aqueous_mobility_ = 0
self._phi_ = 0
self._sigma_ = 0 # interfacial tension

#General Parameters in Simulation
self.sim_id = sim_id
self.is_surfactant = is_surfactant #need to determine whether this is actually important!!!
self.mdl_id = mdl_id
self.plt_type = plt_type


@property
def polymer(self):
return self._polymer_

@polymer.setter
def polymer(self, value):
self._polymer_ = value
self.init_water_saturation_scalar = init_water_saturation

@property
def surfactant(self):
return self._surfactant_

@surfactant.setter
def surfactant(self, value):
self._surfactant_ = value

@property
def resevoir_geometry(self):
return self._resevoir_geometry_

@resevoir_geometry.setter
def resevoir_geometry(self, value):
self._resevoir_geometry_ = value

@property
def permeability_flg(self):
return self._permeability_flag_

@permeability_flg.setter
def permeability_flg(self, value):
self._permeability_flag_ = value

@property
def mesh(self):
return self._mesh_

@mesh.setter
def mesh(self, value):
self._mesh_ = value
#Model and plotting flags
self.mdl_id = mdl_id #Model type
self.plt_type = plt_type #types of plots to generate

### DEPENDENT VARIABLES OF SIMULATION CLASS:
_phi_ = 0
@property
def phi(self):
self._phi_ = self.get_phi_value()
if(self._phi_ is None):
self._phi_ = self.get_phi_value()
return self._phi_

_water_saturation_vector_form_ = 0
@property
def water_saturation(self):
return self._water_saturation_
def water_saturation(self): #vector version
return self._water_saturation_vector_form_

@water_saturation.setter
def water_saturation(self, value):
self._water_saturation_ = value

@property
def init_water_saturation_scalar(self):
return self._init_water_saturation_scalar_

@init_water_saturation_scalar.setter
def init_water_saturation_scalar(self, value):
self._init_water_saturation_scalar_ = value
self._water_saturation_vector_form_ = value

_aqueous_viscosity_ = 0
@property
def aqueous_viscosity(self):
return self._aqueous_viscosity_
Expand All @@ -149,6 +89,7 @@ def aqueous_viscosity(self):
def aqueous_viscosity(self, value):
self._aqueous_viscosity_ = value

_oleic_mobility_ = 0
@property
def oleic_mobility(self):
return self._oleic_mobility_
Expand All @@ -157,6 +98,7 @@ def oleic_mobility(self):
def oleic_mobility(self, value):
self._oleic_mobility_ = value

_aqueous_mobility_ = 0
@property
def aqueous_mobility(self):
return self._aqueous_mobility_
Expand All @@ -165,13 +107,24 @@ def aqueous_mobility(self):
def aqueous_mobility(self, value):
self._aqueous_mobility_ = value

_IFT_ = 0
@property
def sigma(self):
return self._sigma_
return self._IFT_

@sigma.setter
def sigma(self, value):
self._sigma_ = value
self._IFT_ = value

_is_surfactant_ = None
@property
def is_surfactant(self):
if(self._is_surfactant_ is None):
if(self.surfactant.initial_concentration == 0):
self._is_surfactant_ = False
else:
self._is_surfactant_ = True
return self._is_surfactant_


def get_phi_value(self):
Expand Down Expand Up @@ -203,12 +156,6 @@ def get_phi_value(self):

# --- Vectorized implementation
jj, ii = np.meshgrid(np.arange(1, n + 2), np.arange(1, m + 2))
# print("jj is: ", jj)
# print("ii is: ", ii)
# print("Left is: ", left)
# print("bottom is: ", bottom)
# print("dx is: ", dx)
# print("dy is: ", dy)
phi_vec = self.z_func_test(left + (ii - 1) * dx, bottom + (jj - 1) * dy)
return phi_vec
except Exception as e:
Expand Down Expand Up @@ -277,11 +224,11 @@ def initial_concentration_matrix(self):
else:
raise SimulationCalcInputException("SimulationError: phi value not calculated!")

if self.is_surfactant == 0 and self.polymer is not None and self.surfactant is not None:
if ( not self.is_surfactant ) and self.polymer is not None and self.surfactant is not None:
self.surfactant.vec_concentration = []
self.water_saturation = (~D) + D * (1 - s_0)
self.polymer.vec_concentration = (~D) * c_0
elif self.is_surfactant == 1 and self.polymer is not None and self.surfactant is not None:
elif self.is_surfactant and self.polymer is not None and self.surfactant is not None:
self.water_saturation = (~D) + D * (1 - s_0)
self.polymer.vec_concentration = (~D) * c_0
self.surfactant.vec_concentration = (~D) * g_0
Expand Down
12 changes: 11 additions & 1 deletion tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def test_compute_resid_saturations():
"""
This function will test the function that determines that residual saturations
"""

test_sim_object = initializing_simulation()
# Determining U:
u = np.zeros(( test_sim_object.mesh.n + 1, test_sim_object.mesh.m + 1 ))

# Determining V:
v = u

# Need to implement method to calculate sigma (using the IFT vs surfactant concentration relationship)
test_sim_object.compres(u, v)

pass

Expand All @@ -155,4 +165,4 @@ def test_solving_saturation_equations():


if __name__ == "__main__":
test_compute_viscosity()
test_compute_resid_saturations()

0 comments on commit d3d1194

Please sign in to comment.