-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
497 additions
and
65 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
docs/rips/PythonExamples/create_surface_from_thermal_fracture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
import rips | ||
import tempfile | ||
from os.path import expanduser | ||
from pathlib import Path | ||
import numpy as np | ||
import pyvista as pv | ||
|
||
|
||
def generate_surface_from_file(path): | ||
point_cloud_data = np.loadtxt(path, delimiter=" ", skiprows=1) | ||
|
||
# Get [x, y, z] components in separate matrix | ||
num_rows = point_cloud_data.shape[0] | ||
xyz = point_cloud_data[0:num_rows, 0:3] | ||
|
||
# Generate surface | ||
cloud = pv.PolyData(xyz) | ||
surf = cloud.delaunay_2d() | ||
|
||
# Read properties names from header data | ||
f = open(path) | ||
header = f.readline() | ||
properties = header.strip().split(" ") | ||
|
||
return (surf, point_cloud_data, properties) | ||
|
||
|
||
def export_surface_as_ts_file(surf, point_cloud, properties, path): | ||
|
||
# open text file | ||
text_file = open(path, "w") | ||
|
||
# write GOCAD header | ||
top_header = """GOCAD TSurf 1 | ||
HEADER { | ||
name:MF_027_SU | ||
} | ||
""" | ||
|
||
properties_str = "PROPERTIES " + " ".join(properties) | ||
|
||
bottom_header = """ | ||
GOCAD_ORIGINAL_COORDINATE_SYSTEM | ||
NAME Default | ||
AXIS_NAME "X" "Y" "Z" | ||
AXIS_UNIT "m" "m" "m" | ||
ZPOSITIVE Depth | ||
END_ORIGINAL_COORDINATE_SYSTEM | ||
TFACE | ||
""" | ||
|
||
text_file.write(top_header) | ||
text_file.write(properties_str) | ||
text_file.write(bottom_header) | ||
|
||
i = 1 | ||
(num_rows, num_props) = point_cloud.shape | ||
for row in range(0, num_rows): | ||
x = point_cloud[row, 0] | ||
y = point_cloud[row, 1] | ||
z = point_cloud[row, 2] | ||
txt = "PVRTX {} {:.3f} {:.3f} {:.3f} ".format(i, x, y, z) | ||
for property_index in range(0, num_props): | ||
txt += "{:.3f} ".format(point_cloud[row, property_index]) | ||
txt += "\n" | ||
text_file.write(txt) | ||
i += 1 | ||
|
||
mysurface = surf.faces.reshape(-1, 4) | ||
for p in mysurface: | ||
txt = "TRGL {} {} {}\n".format(p[1] + 1, p[2] + 1, p[3] + 1) | ||
text_file.write(txt) | ||
|
||
text_file.write("END") | ||
text_file.close() | ||
|
||
|
||
# Connect to ResInsight instance | ||
resinsight = rips.Instance.find() | ||
project = resinsight.project | ||
|
||
|
||
fractures = project.descendants(rips.ThermalFractureTemplate) | ||
print("Number of thermal fractures: ", len(fractures)) | ||
|
||
|
||
temp_folder = tempfile.gettempdir() | ||
|
||
# Write results to a suitable directory | ||
home_dir = expanduser("~") | ||
|
||
for fracture in fractures: | ||
|
||
fracture_name = fracture.user_description | ||
|
||
# Create the ouput directory | ||
output_directory = ( | ||
Path(home_dir) / "thermal_fracture_surfaces" / "{}".format(fracture_name) | ||
) | ||
|
||
output_directory.mkdir(parents=True, exist_ok=True) | ||
print("Creating result directory: ", output_directory.as_posix()) | ||
|
||
time_steps = fracture.time_steps().values | ||
for time_step_index, time_step in enumerate(time_steps): | ||
print( | ||
"Generating surface for time step #{}: {}".format( | ||
time_step_index, time_step | ||
) | ||
) | ||
temp_file_path = Path(temp_folder) / "output.xyz" | ||
fracture.export_to_file( | ||
file_path=temp_file_path.as_posix(), time_step=time_step_index | ||
) | ||
|
||
# Reconstruct a surface from the exported values file | ||
(surface, point_cloud, properties) = generate_surface_from_file( | ||
temp_file_path.as_posix() | ||
) | ||
|
||
# Export surface ts file from the surface data | ||
output_file_path = output_directory / "time_step_{:03d}.ts".format( | ||
time_step_index | ||
) | ||
export_surface_as_ts_file( | ||
surface, point_cloud, properties, output_file_path.as_posix() | ||
) | ||
print( | ||
"Wrote surface for time step #{} to {}".format( | ||
time_step, output_file_path.as_posix() | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
docs/rips/PythonExamples/import_thermal_fracture_on_well.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Load ResInsight Processing Server Client Library | ||
import rips | ||
import tempfile | ||
from os.path import expanduser | ||
from pathlib import Path | ||
|
||
# Connect to ResInsight instance | ||
resinsight = rips.Instance.find() | ||
project = resinsight.project | ||
|
||
# Look for input files in the home directory of the user | ||
home_dir = expanduser("~") | ||
fracture_file_path = (Path(home_dir) / "fracture.csv").as_posix() | ||
print("Thermal fracture file path:", fracture_file_path) | ||
|
||
# Find a case | ||
cases = resinsight.project.cases() | ||
case = cases[0] | ||
|
||
# Create thermal template | ||
fmt_collection = project.descendants(rips.FractureTemplateCollection)[0] | ||
fracture_template = fmt_collection.append_thermal_fracture_template( | ||
file_path=fracture_file_path | ||
) | ||
|
||
well_name = "F-1 H" | ||
|
||
# Find a well | ||
well_path = project.well_path_by_name(well_name) | ||
print("Well path:", well_path.name) | ||
|
||
# Create fracture and place it using data from the fracture template | ||
fracture = well_path.add_thermal_fracture( | ||
fracture_template=fracture_template, | ||
place_using_template_data=True, | ||
) | ||
|
||
|
||
time_steps = fracture_template.time_steps().values | ||
for time_step_index, time_stamp in enumerate(time_steps): | ||
print("Time step #{}: {}".format(time_step_index, time_stamp)) | ||
fracture_template.active_time_step_index = time_step_index | ||
fracture_template.conductivity_result_name = "Conductivity" | ||
fracture_template.update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.