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

fix(dat-convert): change default conversion behavior to match UM #94

Merged
merged 10 commits into from
Nov 5, 2024
31 changes: 26 additions & 5 deletions src/python/sansmic/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
else str_or_buffer
) as fin:
scenario.title = "Converted from DAT-file"
scenario.comments = """\nConversion report:\n"""
first = True
logger.debug('Reading DAT-formatted file "{}"'.format(Path(fin.name).name))
while True:
Expand Down Expand Up @@ -241,14 +242,11 @@
+ "\n tdlay [depr.]: {}".format(tDelay)
+ "\n sep : {}".format(coallescing_well_separation)
)
if float(tDelay) != 0:
logger.warning("The TDLAY option should not be used. Ignoring.")
# First stage - block 9
if first:
logger.debug("First stage initialization")
logger.debug("Record 9 - Geometry\n data:")
geometry_data = list()
first = False
geometry_format = GeometryFormat(int(geometry_format))
if geometry_format == GeometryFormat.RADIUS_LIST:
radii = list()
Expand Down Expand Up @@ -300,6 +298,7 @@
logger.warning(
"The REFDEP is no longer used, only DEPTH. Ignoring REFDEP."
)
scenario.comments += "* The REFDEP value (field 3 in record 10) is unused; DEPTH (field 4) is used instead.\n"

Check warning on line 301 in src/python/sansmic/io.py

View check run for this annotation

Codecov / codecov/patch

src/python/sansmic/io.py#L301

Added line #L301 was not covered by tests
if float(dissolution_factor) != 1.0:
logger.warning("The ZDIS should almost always be 1.0 for NaCl(s)")
scenario.geometry_format = geometry_format
Expand All @@ -310,8 +309,14 @@
df = float(dissolution_factor)
if df != 1.0:
scenario.advanced.dissolution_factor = df
scenario.comments += "* Atypical dissolution factor set to {} in [advanced] options table.\n".format(
dissolution_factor
)
scenario.insolubles_ratio = float(insoluble_fraction)
scenario.floor_depth = float(depth)
scenario.comments += "* Floor depth was {} ft MD; all heights converted to MD using this value.\n".format(
depth
)
scenario.cavern_height = float(cavern_height)
scenario.ullage_standoff = float(ullage_standoff)
else:
Expand All @@ -326,12 +331,25 @@
)
)
raise TypeError("Invalid data in DAT file: RESETGEO not 0")
if not first and isinstance(cavern_sg, (float, int)) and cavern_sg > 1.0:
if float(tDelay) != 0:
logger.warning("The TDLAY option should not be used. Ignoring.")
scenario.comments += "* The TDLAY option ({}) was removed from stage {}, as it has been deprecated.\n".format(

Check warning on line 336 in src/python/sansmic/io.py

View check run for this annotation

Codecov / codecov/patch

src/python/sansmic/io.py#L335-L336

Added lines #L335 - L336 were not covered by tests
tDelay, len(scenario.stages) + 1
)
if not first and (cavern_sg is not None and float(cavern_sg) > 1.0):
scenario.comments += "* Initial cavern SG was changed from {} to 0 in subsequent stage number {}.\n".format(
cavern_sg, len(scenario.stages) + 1
)
scenario.comments += " If you truly meant to reset the cavern SG at the beginning of the stage,\n"
scenario.comments += " please add ``set-cavern-sg = {}`` into [[stages]] definition number {}\n".format(
cavern_sg, len(scenario.stages) + 1
)
logger.warning(
"The REPEAT option was supposed to turn off the cavern SG; it did not do so. sansmic is currently mimicing SANSMIC behavior and resetting the cavern brine to {} sg in stage {}. \n\nIf this is not what is intended, please manually remove the 'set-cavern-sg' entry from stages after stage 1. This behavior will change in future releases.".format(
"The REPEAT option now disables cavern SG initialization that is non-zero. Please add ``set-initial-conditions = true`` and ``set-cavern-sg = {}`` to [[stages]] {}".format(
cavern_sg, len(scenario.stages) + 1
)
)
cavern_sg = 0.0
stage.title = title
dbhart marked this conversation as resolved.
Show resolved Hide resolved
stage.simulation_mode = SimulationMode(int(mode))
stage.save_frequency = int(print_interval)
Expand Down Expand Up @@ -363,6 +381,7 @@
stage.injection_duration = float(injection_duration)
stage.product_injection_rate = float(fill_rate)
scenario.stages.append(stage)
first = False
logger.debug("Finished reading stage")
logger.debug(".DAT file converted successfully")
return scenario
Expand Down Expand Up @@ -429,6 +448,8 @@
continue
if isinstance(v, bool):
v = str(v).lower()
elif k == "comments":
v = '"""' + v + '"""'
elif isinstance(v, str):
v = repr(v)
elif isinstance(v, IntEnum):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ def test_convert_app(self):
"""Test the 'sansmic-convert' command line application."""
scenario0 = sansmic.io.read_scenario(self.withdrawal_dat)
scenario0.title = ""
scenario0.comments = ""
sansmic.app.convert(
[self.withdrawal_dat, self.withdrawal_toml], standalone_mode=False
)
scenario1 = sansmic.io.read_scenario(self.withdrawal_toml)
scenario1.title = ""
scenario1.comments = ""
self.assertEqual(scenario0, scenario1)
sansmic.app.convert(
[self.withdrawal_dat, self.withdrawal_toml, "--full"], standalone_mode=False
)
scenario2 = sansmic.io.read_scenario(self.withdrawal_toml)
scenario2.title = ""
scenario2.comments = ""
self.maxDiff = None
self.assertDictEqual(scenario0.to_dict(), scenario2.to_dict())

Expand Down
12 changes: 11 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,26 @@ def test_read_scenario_ordinary_reverse_multistage(self):
self.assertEqual(scenario.stages[2].outer_csg_inside_diam / 2, 8.925)
self.assertEqual(scenario.stages[2].outer_csg_outside_diam / 2, 9.375)
self.assertEqual(scenario.stages[2].brine_injection_sg, 1.03)
self.assertEqual(scenario.stages[2].set_cavern_sg, 1.2019)
self.assertIsNone(scenario.stages[2].set_cavern_sg) # Changed in version 1.1
self.assertEqual(scenario.stages[2].solver_timestep, 0.1)
self.assertEqual(scenario.stages[2].injection_duration, 72)
self.assertEqual(scenario.stages[2].product_injection_rate, 0.0)

def test_roundtrip_toml(self):
scenario = sansmic.io.read_scenario(self.withdrawal_dat)
scenario.title = ""
scenario.comments = ""
sansmic.io.write_scenario(scenario, self.withdrawal_toml)
scenario2 = sansmic.io.read_scenario(self.withdrawal_toml)
scenario2.title = ""
scenario2.comments = ""
self.assertEqual(scenario, scenario2)

def test_roundtrip_yaml(self):
self.maxDiff = None
scenario = sansmic.io.read_scenario(self.ordinary_rev_dat)
scenario.title = ""
scenario.comments = ""
scenario.stages[1].brine_interface_depth = 0
scenario.stages[2].brine_interface_depth = 0
scenario.stages[1].set_initial_conditions = None
Expand All @@ -284,35 +287,42 @@ def test_roundtrip_yaml(self):
sansmic.io.write_scenario(scenario, self.ordinary_rev_yaml, redundant=True)
scenario2 = sansmic.io.read_scenario(self.ordinary_rev_yaml)
scenario2.title = ""
scenario2.comments = ""
self.assertDictEqual(
scenario.to_dict(keep_empty=True), scenario2.to_dict(keep_empty=True)
)

def test_roundtrip_json(self):
scenario = sansmic.io.read_scenario(self.ordinary_dir_dat)
scenario.title = ""
scenario.comments = ""
sansmic.io.write_scenario(scenario, self.ordinary_dir_json)
scenario2 = sansmic.io.read_scenario(self.ordinary_dir_json)
scenario2.title = ""
scenario2.comments = ""
self.assertEqual(scenario, scenario2)

def test_roundtrip_spec_format(self):
scenario = sansmic.io.read_scenario(self.leach_fill_dat)
scenario.title = ""
scenario.comments = ""

sansmic.io.write_scenario(scenario, self.leach_fill_format, format="toml")
scenario2 = sansmic.io.read_scenario(self.leach_fill_format, format="toml")
scenario2.title = ""
scenario2.comments = ""
self.assertEqual(scenario, scenario2)

sansmic.io.write_scenario(scenario, self.leach_fill_format, format="json")
scenario3 = sansmic.io.read_scenario(self.leach_fill_format, format="json")
scenario3.title = ""
scenario3.comments = ""
self.assertEqual(scenario, scenario3)

sansmic.io.write_scenario(scenario, self.leach_fill_format, format="yaml")
scenario4 = sansmic.io.read_scenario(self.leach_fill_format, format="yaml")
scenario4.title = ""
scenario4.comments = ""
self.assertEqual(scenario, scenario4)

@classmethod
Expand Down
Loading