@@ -81,15 +81,14 @@ def bc_values_pressure(self, bg: pp.BoundaryGrid) -> np.ndarray:
8181 if self .is_well_grid (sd ):
8282 well = self .well_network .wells [sd .tags ["parent_well_index" ]]
8383 well_tag = well .tags ["well_name" ]
84- protocol = self .well_protocols ()[well_tag ]
8584 # Find indices of the well boundary sides.
8685 domain_sides = self .domain_boundary_sides (bg )
8786 # The top of the domain is '.top' in 3d, '.north' in 2d.
8887 inds = domain_sides .top if self .nd == 3 else domain_sides .north
8988 # Set pressure values according to the well protocol.
9089 values [inds ] = self .units .convert_units (
9190 self .get_well_value (
92- protocol [ "pressures" ] ,
91+ self . well_protocols ( well_tag , "pressures" ) ,
9392 self .time_manager .schedule ,
9493 self .time_manager .time ,
9594 ),
@@ -109,16 +108,14 @@ def bc_values_temperature(self, bg: pp.BoundaryGrid) -> np.ndarray:
109108 sd = bg .parent
110109 values = super ().bc_values_temperature (bg ) # type: ignore[misc]
111110 if self .is_well_grid (sd ):
112- # Retrieve well protocol.
113111 well_tag = self .well_names [sd .tags ["parent_well_index" ]]
114- protocol = self .well_protocols ()[well_tag ]
115112 # Find indices of the well boundary sides.
116113 domain_sides = self .domain_boundary_sides (bg )
117114 inds = domain_sides .top if self .nd == 3 else domain_sides .north
118115 # Set temperature values according to the well protocol.
119116 values [inds ] = self .units .convert_units (
120117 self .get_well_value (
121- protocol [ "temperatures" ] ,
118+ self . well_protocols ( well_tag , "temperatures" ) ,
122119 self .time_manager .schedule ,
123120 self .time_manager .time ,
124121 ),
@@ -153,45 +150,32 @@ def get_well_value(
153150 else :
154151 return float (np .interp (current_time , times , values ))
155152
156- def well_protocols (self ) -> dict [str , dict [str , NDArray [np .float64 ]]]:
157- """Dictionary mapping well tags to well protocols.
153+ def well_protocols (self , well_tag : str , variable : str ) -> NDArray [np .float64 ]:
154+ """Return the time-dependent protocol array for a given well and variable.
155+
156+ The value is read from ``self.params`` under the key
157+ ``"{well_tag}_{variable}"``. A scalar is broadcast to all schedule times; an
158+ array must match schedule length.
159+
160+ Parameters:
161+ well_tag: Name of the well (e.g. ``"injection_well"``).
162+ variable: Protocol variable name (e.g. ``"pressures"``, ``"temperatures"``,
163+ ``"mass_rates"``).
158164
159165 Returns:
160- Dictionary with well protocols, each containing a dictionary with
161- time-dependent temperatures and pressures, with each value being an array of
162- size equal to the number of scheduled times in the time manager.
166+ Array of protocol values, one entry per scheduled time point.
163167 """
164168 num_times = self .time_manager .schedule .size
165- protocols : dict [str , dict [str , NDArray [np .float64 ]]] = {}
166- # Construct protocols for each well.
167- for well_tag in self .well_names :
168- # Initialize protocol dictionary for the well.
169- protocols [well_tag ] = {}
170- # Set values for temperatures and pressures.
171- for variable in ["temperatures" , "pressures" ]:
172- input_values = self .params .get (f"{ well_tag } _{ variable } " , 0.0 )
173- if isinstance (input_values , (float , int )):
174- # Broadcast single value to all time steps for convenient user
175- # definition of well protocols.
176- values = np .full (num_times , input_values , dtype = float )
177-
178- elif isinstance (input_values , (list , np .ndarray )):
179- # Enforce array of float values.
180- values = np .array (input_values , dtype = float )
181- if values .size != num_times :
182- raise ValueError (
183- f"Well protocol for { well_tag } { variable } has size "
184- f"{ values .size } , expected { num_times } ."
185- )
186- else :
187- raise TypeError (
188- f"Well protocol for { well_tag } { variable } has unsupported "
189- f"type { type (input_values )} ."
190- )
191- # Populate well dictionary for the current variable.
192- protocols [well_tag ][variable ] = values
193-
194- return protocols
169+ raw = self .params .get (f"{ well_tag } _{ variable } " , 0.0 )
170+ if isinstance (raw , (int , float )):
171+ return np .full (num_times , float (raw ))
172+ values = np .asarray (raw , dtype = float )
173+ if values .size != num_times :
174+ raise ValueError (
175+ f"Protocol '{ well_tag } _{ variable } ' has { values .size } entries, "
176+ f"expected { num_times } (one per schedule point)."
177+ )
178+ return values
195179
196180
197181class NeumannWellBCsFirstTimeInterval (pp .PorePyModel ):
0 commit comments