-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVGeomechanicsWorkflow.py
More file actions
443 lines (370 loc) · 18.5 KB
/
PVGeomechanicsWorkflow.py
File metadata and controls
443 lines (370 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Martin Lemay, Romain Baville
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
import logging
from pathlib import Path
from typing_extensions import Self
# update sys.path to load all GEOS Python Package dependencies
geos_pv_path: Path = Path( __file__ ).parent.parent.parent.parent.parent.parent
sys.path.insert( 0, str( geos_pv_path / "src" ) )
from geos.pv.utils.config import update_paths
update_paths()
from geos.utils.Logger import ( CountVerbosityHandler, getLoggerHandlerType )
from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_DEG, DEFAULT_GRAIN_BULK_MODULUS,
DEFAULT_ROCK_COHESION, WATER_DENSITY )
from geos.pv.plugins.post_processing.PVGeosBlockExtractAndMerge import PVGeosBlockExtractAndMerge
from geos.pv.plugins.post_processing.PVGeomechanicsCalculator import PVGeomechanicsCalculator
from geos.pv.plugins.post_processing.PVSurfaceGeomechanics import PVSurfaceGeomechanics
from geos.pv.utils.details import FilterCategory
from vtkmodules.vtkCommonCore import vtkInformation, vtkInformationVector
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet
from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
VTKPythonAlgorithmBase, smdomain, smproperty, smproxy )
# source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
from paraview.detail.loghandler import VTKHandler # type: ignore[import-not-found]
# source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py
__doc__ = f"""
PVGeomechanicsWorkflow is a Paraview plugin that executes multiple plugins:
1. PVGeosBlockExtractAndMerge
2. PVGeomechanicsCalculator
3. PVSurfaceGeomechanics (if the input mesh contains faults)
PVGeosBlockExtractAndMerge is a Paraview plugin processing the input mesh at the current time in two steps:
1. Extraction of domains (volume, fault and well) from a GEOS output multiBlockDataSet mesh
2. Actions on each region of a GEOS output domain (volume, fault, wells) to:
* Merge Ranks
* Identify "Fluids" and "Rock" phases
* Rename "Rock" attributes depending on the phase they refer to for more clarity
* Convert volume meshes to surface if needed
* Copy "geomechanics" attributes from the initial timestep to the current one if they exist
PVGeomechanicsCalculator is a paraview plugin that allows to compute basic and advanced geomechanics properties from existing ones in the mesh. This is done on each block of the volume mesh.
The basic geomechanics properties computed on the mesh are:
- The elastic moduli not present on the mesh
- Biot coefficient
- Compressibility, oedometric compressibility and real compressibility coefficient
- Specific gravity
- Real effective stress ratio
- Total initial stress, total current stress and total stress ratio
- Elastic stain
- Real reservoir stress path and reservoir stress path in oedometric condition
The advanced geomechanics properties computed on the mesh are:
- Fracture index and threshold
- Critical pore pressure and pressure index
PVSurfaceGeomechanics is a Paraview plugin that allows to compute additional geomechanical attributes from the input surfaces, such as shear capacity utilization (SCU). This is done on each block of the fault mesh.
This filter results in 3 output pipelines with the vtkMultiBlockDataSet:
- "Volume" contains the volume domain
- "Fault" contains the fault domain if it exist
- "Well" contains the well domain if it exist
Input and output meshes are vtkMultiBlockDataSet.
To use it:
* Load the plugin in Paraview: Tools > Manage Plugins ... > Load New ... > .../geosPythonPackages/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow
* Select the Geos output .pvd file loaded in Paraview to process
* Select the filter: Filters > { FilterCategory.GEOS_POST_PROCESSING.value } > GEOS Geomechanics Workflow.
* Change the physical constants if needed
* Select computeAdvancedProperties to compute the advanced properties on volume mesh
* Apply
"""
HANDLER: logging.Handler = VTKHandler()
loggerTitle: str = "GEOS Geomechanics Workflow"
@smproxy.filter(
name="PVGeomechanicsWorkflow",
label="GEOS Geomechanics Workflow",
)
@smproperty.xml( f"""
<OutputPort index="0" name="Volume"/>
<OutputPort index="1" name="Fault"/>
<OutputPort index="2" name="Well"/>
<Hints>
<ShowInMenu category="{ FilterCategory.GEOS_POST_PROCESSING.value }"/>
<View type="RenderView" port="0"/>
<View type="None" port="1"/>
<View type="None" port="2"/>
</Hints>
""" )
@smproperty.input( name="Input", port_index=0 )
@smdomain.datatype( dataTypes=[ "vtkMultiBlockDataSet" ], composite_data_supported=True )
class PVGeomechanicsWorkflow( VTKPythonAlgorithmBase ):
def __init__( self: Self ) -> None:
"""Paraview plugin to compute geomechanics properties on volume and on surface directly from the GEOS simulation output mesh.
This plugin is the combination of three other:
- First PVGeosBlockExtractAndMerge
- Secondly PVGeomechanicsCalculator
- Thirdly PVSurfaceGeomechanics (if the input mesh contains faults)
"""
super().__init__(
nInputPorts=1,
nOutputPorts=3,
inputType="vtkMultiBlockDataSet",
outputType="vtkMultiBlockDataSet",
)
self.volumeMesh: vtkMultiBlockDataSet
self.faultMesh: vtkMultiBlockDataSet
self.wellMesh: vtkMultiBlockDataSet
self.extractFault: bool = True
self.extractWell: bool = True
self.computeAdvancedProperties: bool = False
# Defaults physical constants
## For basic properties on Volume
self.grainBulkModulus: float = DEFAULT_GRAIN_BULK_MODULUS
self.specificDensity: float = WATER_DENSITY
## For advanced properties on Volume and basic properties on Surface
self.rockCohesion: float = DEFAULT_ROCK_COHESION
self.frictionAngle: float = DEFAULT_FRICTION_ANGLE_DEG
self.logger = logging.getLogger( loggerTitle )
self.logger.setLevel( logging.INFO )
self.logger.addHandler( HANDLER )
self.logger.propagate = False
counter: CountVerbosityHandler = CountVerbosityHandler()
self.counter: CountVerbosityHandler
self.nbWarnings: int = 0
self.nbErrors: int = 0
try:
self.counter = getLoggerHandlerType( type( counter ), self.logger )
self.counter.resetWarningCount()
self.counter.resetErrorCount()
except ValueError:
self.counter = counter
self.counter.setLevel( logging.INFO )
self.logger.addHandler( self.counter )
@smproperty.doublevector(
name="GrainBulkModulus",
label="Grain bulk modulus (Pa)",
default_values=DEFAULT_GRAIN_BULK_MODULUS,
panel_visibility="default",
)
@smdomain.xml( """
<Documentation>
Reference grain bulk modulus to compute Biot coefficient.
The unit is Pa. Default is Quartz bulk modulus (i.e., 38GPa).
</Documentation>
""" )
def setGrainBulkModulus( self: Self, grainBulkModulus: float ) -> None:
"""Set grain bulk modulus.
Args:
grainBulkModulus (float): Grain bulk modulus (Pa).
"""
self.grainBulkModulus = grainBulkModulus
self.Modified()
@smproperty.doublevector(
name="SpecificDensity",
label="Specific Density (kg/m3)",
default_values=WATER_DENSITY,
panel_visibility="default",
)
@smdomain.xml( """
<Documentation>
Reference density to compute specific gravity.
The unit is kg/m3. Default is fresh water density (i.e., 1000 kg/m3).
</Documentation>
""" )
def setSpecificDensity( self: Self, specificDensity: float ) -> None:
"""Set specific density.
Args:
specificDensity (float): Reference specific density (kg/m3).
"""
self.specificDensity = specificDensity
self.Modified()
@smproperty.xml( """
<PropertyGroup label="Basic properties parameters">
<Property name="GrainBulkModulus"/>
<Property name="SpecificDensity"/>
</PropertyGroup>
""" )
def groupBasicPropertiesParameters( self: Self ) -> None:
"""Organize groups."""
self.Modified()
@smproperty.doublevector(
name="RockCohesion",
label="Rock Cohesion (Pa)",
default_values=DEFAULT_ROCK_COHESION,
panel_visibility="default",
)
@smdomain.xml( """
<Documentation>
Reference rock cohesion to compute critical pore pressure.
The unit is Pa.Default is fractured case (i.e., 0. Pa).
</Documentation>
""" )
def setRockCohesion( self: Self, rockCohesion: float ) -> None:
"""Set rock cohesion.
Args:
rockCohesion (float): Rock cohesion (Pa).
"""
self.rockCohesion = rockCohesion
self.Modified()
@smproperty.doublevector(
name="FrictionAngle",
label="Friction Angle (°)",
default_values=DEFAULT_FRICTION_ANGLE_DEG,
panel_visibility="default",
)
@smdomain.xml( """
<Documentation>
Reference friction angle to compute critical pore pressure.
The unit is °. Default is an average friction angle (i.e., 10°).
</Documentation>
""" )
def setFrictionAngle( self: Self, frictionAngle: float ) -> None:
"""Set friction angle.
Args:
frictionAngle (float): Friction angle (°).
"""
self.frictionAngle = frictionAngle
self.Modified()
@smproperty.xml( """
<PropertyGroup
label="Surface parameters / Advanced volume parameters">
<Property name="RockCohesion"/>
<Property name="FrictionAngle"/>
</PropertyGroup>
""" )
def groupAdvancedPropertiesAndSurfaceParameters( self: Self ) -> None:
"""Organize groups."""
self.Modified()
@smproperty.intvector(
name="ComputeAdvancedProperties",
label="Compute advanced geomechanics properties",
default_values=0,
panel_visibility="default",
)
@smdomain.xml( """
<BooleanDomain name="ComputeAdvancedProperties"/>
<Documentation>
Check to compute advanced geomechanics properties including
reservoir stress paths and fracture indexes.
</Documentation>
""" )
def setComputeAdvancedProperties( self: Self, computeAdvancedProperties: bool ) -> None:
"""Set advanced properties calculation option.
Args:
computeAdvancedProperties (bool): True to compute advanced geomechanics properties, False otherwise.
"""
self.computeAdvancedProperties = computeAdvancedProperties
self.Modified()
def RequestDataObject(
self: Self,
request: vtkInformation,
inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector,
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
inData = self.GetInputData( inInfoVec, 0, 0 )
assert inData is not None
outDataCells = self.GetOutputData( outInfoVec, 0 )
if outDataCells is None or ( not outDataCells.IsA( "vtkMultiBlockDataSet" ) ):
outDataCells = vtkMultiBlockDataSet()
outInfoVec.GetInformationObject( 0 ).Set( outDataCells.DATA_OBJECT(), outDataCells ) # type: ignore
outDataFaults = self.GetOutputData( outInfoVec, 1 )
if outDataFaults is None or ( not outDataFaults.IsA( "vtkMultiBlockDataSet" ) ):
outDataFaults = vtkMultiBlockDataSet()
outInfoVec.GetInformationObject( 1 ).Set( outDataFaults.DATA_OBJECT(), outDataFaults ) # type: ignore
outDataWells = self.GetOutputData( outInfoVec, 2 )
if outDataWells is None or ( not outDataWells.IsA( "vtkMultiBlockDataSet" ) ):
outDataWells = vtkMultiBlockDataSet()
outInfoVec.GetInformationObject( 2 ).Set( outDataWells.DATA_OBJECT(), outDataWells ) # type: ignore
return super().RequestDataObject( request, inInfoVec, outInfoVec ) # type: ignore[no-any-return]
def RequestData(
self: Self,
request: vtkInformation,
inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector,
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestData.
Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
self.logger.info( f"Apply plugin { self.logger.name }." )
try:
self.volumeMesh = self.GetOutputData( outInfoVec, 0 )
self.faultMesh = self.GetOutputData( outInfoVec, 1 )
self.wellMesh = self.GetOutputData( outInfoVec, 2 )
self.applyPVGeosBlockExtractAndMerge()
self.applyPVGeomechanicsCalculator()
if self.extractFault:
self.applyPVSurfaceGeomechanics()
result: str = f"The plugin { self.logger.name } succeeded"
if self.counter.warningCount > 0:
self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." )
else:
self.logger.info( f"{ result }." )
except ChildProcessError as e:
self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" )
except Exception as e:
mess: str = f"The plugin { self.logger.name } failed due to:\n{ e }"
self.logger.critical( mess, exc_info=True )
# Keep number of verbosity logged during the plugin application
self.nbWarnings = self.counter.warningCount
self.nbErrors = self.counter.errorCount
# Reset the CountVerbosityHandler in case the plugin is applied again
self.counter.resetWarningCount()
self.counter.resetErrorCount()
return 1
def applyPVGeosBlockExtractAndMerge( self: Self ) -> None:
"""Apply PVGeosBlockExtractAndMerge."""
extractAndMergeFilter: PVGeosBlockExtractAndMerge = PVGeosBlockExtractAndMerge()
extractAndMergeFilter.SetInputConnection( self.GetInputConnection( 0, 0 ) )
extractAndMergeFilter.Update()
# Add to the warning counter the number of warning logged with the call of GeosBlockExtractAndMerge plugin
self.counter.addExternalWarningCount( extractAndMergeFilter.nbWarnings )
# Add to the error counter the number of error logged with the call of GeosBlockExtractAndMerge plugin
self.counter.addExternalErrorCount( extractAndMergeFilter.nbErrors )
if self.counter.errorCount != 0:
raise ChildProcessError( "Error during the processing of the plugin PVGeosBlockExtractAndMerge." )
self.volumeMesh.ShallowCopy( extractAndMergeFilter.GetOutputDataObject( 0 ) )
self.volumeMesh.Modified()
self.extractFault = extractAndMergeFilter.extractFault
if self.extractFault:
self.faultMesh.ShallowCopy( extractAndMergeFilter.GetOutputDataObject( 1 ) )
self.faultMesh.Modified()
self.extractWell = extractAndMergeFilter.extractWell
if self.extractWell:
self.wellMesh.ShallowCopy( extractAndMergeFilter.GetOutputDataObject( 2 ) )
self.wellMesh.Modified()
return
def applyPVGeomechanicsCalculator( self: Self ) -> None:
"""Apply PVGeomechanicsCalculator."""
geomechanicsCalculatorPlugin = PVGeomechanicsCalculator()
geomechanicsCalculatorPlugin.SetInputDataObject( self.volumeMesh ),
geomechanicsCalculatorPlugin.setComputeAdvancedProperties( self.computeAdvancedProperties )
geomechanicsCalculatorPlugin.setGrainBulkModulus( self.grainBulkModulus )
geomechanicsCalculatorPlugin.setSpecificDensity( self.specificDensity )
geomechanicsCalculatorPlugin.setRockCohesion( self.rockCohesion )
geomechanicsCalculatorPlugin.setFrictionAngle( self.frictionAngle )
geomechanicsCalculatorPlugin.Update()
# Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator plugin
self.counter.addExternalWarningCount( geomechanicsCalculatorPlugin.nbWarnings )
# Add to the error counter the number of error logged with the call of GeomechanicsCalculator plugin
self.counter.addExternalErrorCount( geomechanicsCalculatorPlugin.nbErrors )
if self.counter.errorCount != 0:
raise ChildProcessError( "Error during the processing of the plugin PVGeomechanicsCalculators." )
self.volumeMesh.ShallowCopy( geomechanicsCalculatorPlugin.GetOutputDataObject( 0 ) )
self.volumeMesh.Modified()
return
def applyPVSurfaceGeomechanics( self: Self ) -> None:
"""Apply PVSurfaceGeomechanics."""
surfaceGeomechanicsPlugin = PVSurfaceGeomechanics()
surfaceGeomechanicsPlugin.SetInputDataObject( self.faultMesh )
surfaceGeomechanicsPlugin.a01SetRockCohesion( self.rockCohesion )
surfaceGeomechanicsPlugin.a02SetFrictionAngle( self.frictionAngle )
surfaceGeomechanicsPlugin.Update()
# Add to the warning counter the number of warning logged with the call of SurfaceGeomechanics plugin
self.counter.addExternalWarningCount( surfaceGeomechanicsPlugin.nbWarnings )
# Add to the error counter the number of error logged with the call of SurfaceGeomechanics plugin
self.counter.addExternalErrorCount( surfaceGeomechanicsPlugin.nbErrors )
if self.counter.errorCount != 0:
raise ChildProcessError( "Error during the processing of the plugin PVSurfaceGeomechanics." )
self.faultMesh.ShallowCopy( surfaceGeomechanicsPlugin.GetOutputDataObject( 0 ) )
self.faultMesh.Modified()
return