Skip to content

Commit dc786f9

Browse files
Merge pull request #34 from softwareengineerprogrammer/fix-list-parameters
Fix list parameters
2 parents 034e2db + 7a5de3c commit dc786f9

File tree

8 files changed

+404
-37
lines changed

8 files changed

+404
-37
lines changed

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def read_input_file(return_dict_1, logger=None, input_file_name=None):
554554
comment = comment + elements[i]
555555

556556
# done with parsing, now create the object and add to the dictionary
557-
p_entry = ParameterEntry(description, s_val, comment)
557+
p_entry = ParameterEntry(description, s_val, comment, line)
558558
return_dict_1[description] = p_entry # make the dictionary element
559559

560560
else:

src/geophires_x/Parameter.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ParameterEntry:
4343
Name: str
4444
sValue: str
4545
Comment: Optional[str] = None
46+
raw_entry: Optional[str] = None
4647

4748

4849
@dataclass
@@ -253,10 +254,10 @@ def ReadParameter(ParameterReadIn: ParameterEntry, ParamToModify, model):
253254
"""
254255
ReadParameter: A method to take a single ParameterEntry object and use it to update the associated Parameter.
255256
Does validation as well as Unit and Currency conversion
256-
:param ParameterEntry: The value the user wants to change and the value they want to change it to (as a string)
257+
:param ParameterReadIn: The value the user wants to change and the value they want to change it to (as a string)
257258
and any comment they provided with it (as a string) - all in one object (ParameterEntry) that is passed in
258259
to this method as a parameter itself (ParameterReadIn) - see ParameterEntry class for details on the fields in it
259-
:type ParameterEntry: :class:`~geophires_x.Parameter.ParameterEntry`
260+
:type ParameterReadIn: :class:`~geophires_x.Parameter.ParameterEntry`
260261
:param ParamToModify: The Parameter that will be modified (assuming it passes validation and conversion) - this is
261262
the object that will be modified by this method - see Parameter class for details on the fields in it
262263
:type ParamToModify: :class:`~geophires_x.Parameter.Parameter`
@@ -293,9 +294,9 @@ def ReadParameter(ParameterReadIn: ParameterEntry, ParamToModify, model):
293294

294295
def default_parameter_value_message(new_val: Any, param_to_modify_name: str, default_value: Any) -> str:
295296
return (
296-
f'Parameter given ({str(New_val)}) for {ParamToModify.Name} is the same as the default value. '
297-
f'Consider removing {ParamToModify.Name} from the input file unless you wish '
298-
f'to change it from the default value of ({str(ParamToModify.DefaultValue)})'
297+
f'Parameter given ({str(new_val)}) for {param_to_modify_name} is the same as the default value. '
298+
f'Consider removing {param_to_modify_name} from the input file unless you wish '
299+
f'to change it from the default value of ({str(default_value)})'
299300
)
300301

301302
if isinstance(ParamToModify, intParameter):
@@ -370,16 +371,23 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
370371
model.logger.warning(msg)
371372
model.logger.info(f'Complete {str(__name__)}: {sys._getframe().f_code.co_name}')
372373
return
373-
# All is good. With a list, we have to use the last character of the Description to get the position.
374-
# I.e., "Gradient 1" should yield a position = 0 ("1" - 1)
375374
else:
376-
parts = ParameterReadIn.Name.split(' ')
377-
position = int(parts[1]) - 1
378-
if position >= len(ParamToModify.value):
379-
ParamToModify.value.append(New_val) # we are adding to the list, so use append
380-
else: # we are replacing a value, so pop the value we want to replace, then insert a new one
381-
ParamToModify.value.pop(position)
382-
ParamToModify.value.insert(position, New_val)
375+
if ' ' in ParamToModify.Name:
376+
# Some list parameters are read in with enumerated parameter names; in these cases we use the last
377+
# character of the description to get the position i.e., "Gradient 1" is position 0.
378+
parts = ParameterReadIn.Name.split(' ')
379+
position = int(parts[1]) - 1
380+
if position >= len(ParamToModify.value):
381+
ParamToModify.value.append(New_val) # we are adding to the list, so use append
382+
else: # we are replacing a value, so pop the value we want to replace, then insert a new one
383+
ParamToModify.value.pop(position)
384+
ParamToModify.value.insert(position, New_val)
385+
else:
386+
# In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
387+
# correct; however that would only be practical if ParameterEntry had typing information to know
388+
# whether to treat text after a second comma as a comment or list entry.
389+
ParamToModify.value = [float(x.strip()) for x in ParameterReadIn.raw_entry.split('--')[0].split(',')[1:]
390+
if x.strip() != '']
383391
elif isinstance(ParamToModify, boolParameter):
384392
if ParameterReadIn.sValue == "0":
385393
New_val = False

src/geophires_x/Reservoir.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -593,30 +593,15 @@ def read_parameters(self, model: Model) -> None:
593593
# fracshape = 4 Rectangular fracture
594594
ParameterToModify.value = FractureShape.RECTANGULAR
595595

596-
elif ParameterToModify.Name.startswith('Gradient'):
596+
elif ParameterToModify.Name.startswith('Gradient '):
597597
parts = ParameterReadIn.Name.split(' ')
598598
position = int(parts[1]) - 1
599599
model.reserv.gradient.value[position] = ParameterToModify.value
600-
if model.reserv.gradient.value[position] > 1.0:
601-
# TODO refactor to avoid heuristic-based unit conversions
602-
model.reserv.gradient.value[position] = model.reserv.gradient.value[
603-
position] / 1000.0 # convert C/m
604-
model.reserv.gradient.CurrentUnits = TemperatureGradientUnit.DEGREESCPERM
605600

606-
if model.reserv.gradient.value[position] < 1e-6:
607-
# convert 0 C/m gradients to very small number, avoids divide by zero errors later
608-
model.reserv.gradient.value[position] = 1e-6
609-
610-
elif ParameterToModify.Name.startswith('Thickness'):
601+
elif ParameterToModify.Name.startswith('Thickness '):
611602
parts = ParameterReadIn.Name.split(' ')
612603
position = int(parts[1]) - 1
613604
model.reserv.layerthickness.value[position] = ParameterToModify.value
614-
if model.reserv.layerthickness.value[position] < 100.0:
615-
model.reserv.layerthickness.value[position] = model.reserv.layerthickness.value[
616-
position] * 1000.0 # convert m
617-
model.reserv.layerthickness.CurrentUnits = LengthUnit.METERS
618-
# set thickness of bottom segment to large number to override lower, unused segments
619-
model.reserv.layerthickness.value[position + 1] = 100_000.0
620605

621606
elif ParameterToModify.Name.startswith("Fracture Separation"):
622607
self.fracsepcalc.value = self.fracsep.value
@@ -635,6 +620,31 @@ def read_parameters(self, model: Model) -> None:
635620

636621
coerce_int_params_to_enum_values(self.ParameterDict)
637622

623+
for position in range(len(model.reserv.gradient.value)):
624+
if model.reserv.gradient.value[position] > 1.0:
625+
# TODO refactor to avoid heuristic-based unit conversions
626+
model.reserv.gradient.value[position] = model.reserv.gradient.value[
627+
position] / 1000.0 # convert to C/m
628+
model.reserv.gradient.CurrentUnits = TemperatureGradientUnit.DEGREESCPERM
629+
630+
if model.reserv.gradient.value[position] < 1e-6:
631+
# convert 0 C/m gradients to very small number, avoids divide by zero errors later
632+
model.reserv.gradient.value[position] = 1e-6
633+
634+
for position in range(len(model.reserv.layerthickness.value)):
635+
if model.reserv.layerthickness.value[position] < 100.0:
636+
# TODO refactor to avoid heuristic-based unit conversions
637+
model.reserv.layerthickness.value[position] = model.reserv.layerthickness.value[
638+
position] * 1000.0 # convert to m
639+
model.reserv.layerthickness.CurrentUnits = LengthUnit.METERS
640+
641+
# set thickness of bottom segment to large number to override lower, unused segments
642+
while len(model.reserv.layerthickness.value) < model.reserv.numseg.value:
643+
model.reserv.layerthickness.value.append(100_000.0)
644+
645+
model.reserv.layerthickness.value[model.reserv.numseg.value-1] = 100_000.0
646+
647+
638648
model.logger.info(f'complete {str(__class__)}: {sys._getframe().f_code.co_name}')
639649

640650
@lru_cache(maxsize=1024)

src/geophires_x/SBTReservoir.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pandas as pd
66
from scipy.special import erf, erfc, jv, yv, exp1
77
from scipy.interpolate import interp1d
8+
import scipy.io as sio
89
import matplotlib.pyplot as plt
910

1011
import geophires_x.Model as Model
@@ -451,7 +452,7 @@ def Calculate_Coaxial(self, model):
451452
g = 9.81 # Gravitational acceleration [m/s²]
452453
gamma = 0.577215665 # Euler's constant
453454
alpha_m = self.krock.value / (self.rhorock.value * self.cprock.value) # Rock thermal diffusivity [m²/s]
454-
alpha_m_boiler = self.krock.value_boiler / (self.rhorock.value * self.cprock.value) # Boiler rock thermal diffusivity [m²/s]
455+
alpha_m_boiler = self.krock.value / (self.rhorock.value * self.cprock.value) # Boiler rock thermal diffusivity [m²/s]
455456

456457
outerradiuscenterpipe = radiuscenterpipe + thicknesscenterpipe # Outer radius of inner pipe [m]
457458
A_flow_annulus = np.pi * (radius ** 2 - outerradiuscenterpipe ** 2) # Flow area of annulus pipe [m²]

0 commit comments

Comments
 (0)