-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVGeomechanicsWorkflowVolumeSurface.py
More file actions
421 lines (361 loc) · 13.8 KB
/
PVGeomechanicsWorkflowVolumeSurface.py
File metadata and controls
421 lines (361 loc) · 13.8 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
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Martin Lemay
# ruff: noqa: E402 # disable Module level import not at top of file
import os
import sys
import numpy as np
from typing_extensions import Self
from vtkmodules.vtkCommonCore import vtkInformation, vtkInformationVector
from vtkmodules.vtkCommonDataModel import (
vtkMultiBlockDataSet,
)
dir_path = os.path.dirname(os.path.realpath(__file__))
parent_dir_path = os.path.dirname(dir_path)
if parent_dir_path not in sys.path:
sys.path.append(parent_dir_path)
import PVplugins #required to update sys path
from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
VTKPythonAlgorithmBase,
smdomain,
smhint,
smproperty,
smproxy,
)
from geos.utils.Logger import Logger, getLogger
from geos.utils.PhysicalConstants import (
DEFAULT_FRICTION_ANGLE_DEG,
DEFAULT_FRICTION_ANGLE_RAD,
DEFAULT_GRAIN_BULK_MODULUS,
DEFAULT_ROCK_COHESION,
WATER_DENSITY,
)
from PVplugins.PVExtractMergeBlocksVolumeSurface import (
PVExtractMergeBlocksVolumeSurface,
)
from PVplugins.PVGeomechanicsAnalysis import PVGeomechanicsAnalysis
from PVplugins.PVSurfaceGeomechanics import PVSurfaceGeomechanics
__doc__ = """
PVGeomechanicsWorkflowVolumeSurface is a Paraview plugin that execute
multiple filters to clean GEOS outputs and compute additional geomechanical
outputs on volume and surface.
Input and output types are vtkMultiBlockDataSet.
This filter results in 2 output pipelines:
* first pipeline contains the volume mesh. If multiple regions were defined in
the volume mesh, they are preserved as distinct blocks.
* second pipeline contains surfaces. If multiple surfaces were used, they are
preserved as distinct blocks.
To use it:
* Load the module in Paraview: Tools>Manage Plugins...>Load new>PVGeomechanicsWorkflowVolumeSurface.
* Select the Geos output .pvd file loaded in Paraview.
* Search and Apply PVGeomechanicsWorkflowVolumeSurface Filter.
"""
@smproxy.filter(
name="PVGeomechanicsWorkflowVolumeSurface",
label="Geos Geomechanics Workflow - Volume/Surface",
)
@smhint.xml(
"""
<ShowInMenu category="1- Geos Post-Processing Workflows"/>
<OutputPort index="0" name="VolumeMesh"/>
<OutputPort index="1" name="Surfaces"/>
"""
)
@smproperty.input(name="Input", port_index=0)
@smdomain.datatype(dataTypes=["vtkMultiBlockDataSet"], composite_data_supported=True)
class PVGeomechanicsWorkflowVolumeSurface(VTKPythonAlgorithmBase):
def __init__(self: Self) -> None:
"""Paraview plugin to clean and add new outputs Geos output mesh.
To apply in the case of output ".pvd" file contains Volume and Fault
elements.
"""
super().__init__(
nInputPorts=1,
nOutputPorts=2,
inputType="vtkMultiBlockDataSet",
outputType="vtkMultiBlockDataSet",
)
#: ouput volume mesh
self.m_volumeMesh: vtkMultiBlockDataSet
#: output surface mesh
self.m_surfaceMesh: vtkMultiBlockDataSet
self.m_computeAdvancedOutputs: bool = False
self.m_grainBulkModulus: float = DEFAULT_GRAIN_BULK_MODULUS
self.m_specificDensity: float = WATER_DENSITY
self.m_rockCohesion: float = DEFAULT_ROCK_COHESION
self.m_frictionAngle: float = DEFAULT_FRICTION_ANGLE_RAD
# set logger
self.m_logger: Logger = getLogger("Geomechanics Workflow Filter")
@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 b01SetGrainBulkModulus(self: Self, value: float) -> None:
"""Set grain bulk modulus.
Args:
value (float): grain bulk modulus (Pa)
"""
self.m_grainBulkModulus = value
self.Modified()
def getGrainBulkModulus(self: Self) -> float:
"""Access to the grain bulk modulus value.
Returns:
float: self.m_grainBulkModulus.
"""
return self.m_grainBulkModulus
@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 b02SetSpecificDensity(self: Self, value: float) -> None:
"""Set specific density.
Args:
value (float): Reference specific density (kg/m3)
"""
self.m_specificDensity = value
self.Modified()
def getSpecificDensity(self: Self) -> float:
"""Access the specific density value.
Returns:
float: self.m_specificDensity.
"""
return self.m_specificDensity
@smproperty.xml(
"""
<PropertyGroup label="Basic output parameters">
<Property name="GrainBulkModulus"/>
<Property name="SpecificDensity"/>
</PropertyGroup>
"""
)
def b09GroupBasicOutputParameters(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 d01SetRockCohesion(self: Self, value: float) -> None:
"""Set rock cohesion.
Args:
value (float): rock cohesion (Pa)
"""
self.m_rockCohesion = value
self.Modified()
def getRockCohesion(self: Self) -> float:
"""Get rock cohesion.
Returns:
float: rock cohesion.
"""
return self.m_rockCohesion
@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 10°.
</Documentation>
"""
)
def d02SetFrictionAngle(self: Self, value: float) -> None:
"""Set frition angle.
Args:
value (float): friction angle (°)
"""
self.m_frictionAngle = value * np.pi / 180.0
self.Modified()
def getFrictionAngle(self: Self) -> float:
"""Get friction angle in radian.
Returns:
float: friction angle.
"""
return self.m_frictionAngle
@smproperty.xml(
"""
<PropertyGroup
label="Surface parameters / Advanced volume parameters">
<Property name="RockCohesion"/>
<Property name="FrictionAngle"/>
</PropertyGroup>
"""
)
def d09GroupAdvancedOutputParameters(self: Self) -> None:
"""Organize groups."""
self.Modified()
@smproperty.intvector(
name="AdvancedOutputsUse",
label="Compute advanced geomechanical volume outputs",
default_values=0,
panel_visibility="default",
)
@smdomain.xml(
"""
<BooleanDomain name="AdvancedOutputsUse"/>
<Documentation>
Check to compute advanced geomechanical outputs including
reservoir stress paths and fracture indexes.
</Documentation>
"""
)
def e01SetAdvancedOutputs(self: Self, boolean: bool) -> None:
"""Set advanced output calculation option.
Args:
boolean (bool): if True advanced outputs are computed.
"""
self.m_computeAdvancedOutputs = boolean
self.Modified()
def getComputeAdvancedOutputs(self: Self) -> float:
"""Access the advanced outputs option.
Returns:
float: self.m_computeAdvancedOutputs.
"""
return self.m_computeAdvancedOutputs
def FillInputPortInformation(self: Self, port: int, info: vtkInformation) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestInformation.
Args:
port (int): input port
info (vtkInformationVector): info
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
if port == 0:
info.Set(self.INPUT_REQUIRED_DATA_TYPE(), "vtkMultiBlockDataSet")
return 1
def RequestInformation(
self: Self,
request: vtkInformation, # noqa: F841
inInfoVec: list[vtkInformationVector], # noqa: F841
outInfoVec: vtkInformationVector,
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestInformation.
Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
executive = self.GetExecutive() # noqa: F841
outInfo: vtkInformation = outInfoVec.GetInformationObject(0) # noqa: F841
return 1
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.
"""
try:
input: vtkMultiBlockDataSet = vtkMultiBlockDataSet.GetData(inInfoVec[0])
self.m_volumeMesh = self.GetOutputData(outInfoVec, 0)
self.m_surfaceMesh = self.GetOutputData(outInfoVec, 1)
assert input is not None, "Input MultiBlockDataSet is null."
assert self.m_volumeMesh is not None, "Output volume mesh is null."
assert self.m_surfaceMesh is not None, "Output surface mesh is null."
# 1. extract volume/surface
self.doExtractAndMerge()
# 2. compute Geomechanical outputs in volume mesh
self.computeAdditionalOutputsVolume()
# 3. compute geomechanical outputs on surface mesh
self.computeSurfaceGeomecanics()
except AssertionError as e:
mess: str = "Geomechanics workflow failed due to:"
self.m_logger.error(mess)
self.m_logger.error(str(e))
return 0
except Exception as e:
mess1: str = "Geomechanics workflow failed due to:"
self.m_logger.critical(mess1)
self.m_logger.critical(e, exc_info=True)
return 0
return 1
def doExtractAndMerge(self: Self) -> bool:
"""Apply block extraction and merge filter.
Args:
input (vtkMultiBlockDataSet): input multi block
Returns:
bool: True if extraction and merge successfully eneded, False otherwise
"""
filter: PVExtractMergeBlocksVolumeSurface = PVExtractMergeBlocksVolumeSurface()
filter.SetInputConnection(self.GetInputConnection(0, 0))
filter.SetLogger(self.m_logger)
filter.Update()
# recover output objects from PVExtractMergeBlocksVolumeSurface
self.m_volumeMesh.ShallowCopy(filter.GetOutputDataObject(0))
self.m_surfaceMesh.ShallowCopy(filter.GetOutputDataObject(1))
self.m_volumeMesh.Modified()
self.m_surfaceMesh.Modified()
return True
def computeAdditionalOutputsVolume(self: Self) -> bool:
"""Compute geomechanical outputs on the volume mesh.
Returns:
bool: True if calculation successfully eneded, False otherwise.
"""
filter = PVGeomechanicsAnalysis()
filter.SetInputDataObject(self.m_volumeMesh)
filter.b01SetGrainBulkModulus(self.getGrainBulkModulus())
filter.b02SetSpecificDensity(self.getSpecificDensity())
filter.d01SetRockCohesion(self.getRockCohesion())
filter.d02SetFrictionAngle(self.getFrictionAngle())
filter.c01SetAdvancedOutputs(self.m_computeAdvancedOutputs)
filter.SetLogger(self.m_logger)
filter.Update()
self.m_volumeMesh.ShallowCopy(filter.GetOutputDataObject(0))
self.m_volumeMesh.Modified()
return True
def computeSurfaceGeomecanics(self: Self) -> bool:
"""Compute surface geomechanics new attributes.
Returns:
bool: True if calculation successfully eneded, False otherwise.
"""
filter = PVSurfaceGeomechanics()
filter.SetInputDataObject(self.m_surfaceMesh)
filter.a01SetRockCohesion(self.getRockCohesion())
filter.a02SetFrictionAngle(self.getFrictionAngle())
filter.SetLogger(self.m_logger)
filter.Update()
self.m_surfaceMesh.ShallowCopy(filter.GetOutputDataObject(0))
self.m_surfaceMesh.Modified()
return True