Skip to content

Commit

Permalink
Updated python doc
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 12, 2023
1 parent 78b35f8 commit 1efbabc
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 65 deletions.
135 changes: 135 additions & 0 deletions docs/rips/PythonExamples/create_surface_from_thermal_fracture.py
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()
)
)
21 changes: 21 additions & 0 deletions docs/rips/PythonExamples/import_fractures_on_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,25 @@
# Call update() to propagate changes from the Python object back to ResInsight
fracture_template.orientation = "Azimuth"
fracture_template.azimuth_angle = 60.0
fracture_template.user_defined_perforation_length = True
fracture_template.conductivity_type = "InfiniteConductivity"
fracture_template.perforation_length = 12.3
fracture_template.update()

# Scale the template
fracture_template.set_scale_factors(
half_length=2.0, height=2.0, d_factor=1.1, conductivity=1.2
)

# Output scale factors for all fracture templates
fmt_collection = project.descendants(rips.FractureTemplate)
for fracture_template in fmt_collection:
print(
"Fracture: '{}' Scale factors: Height={} Half Length={} D Factor={} Conductivity={}".format(
fracture_template.user_description,
fracture_template.height_scale_factor,
fracture_template.width_scale_factor,
fracture_template.d_factor_scale_factor,
fracture_template.conductivity_factor,
)
)
44 changes: 44 additions & 0 deletions docs/rips/PythonExamples/import_thermal_fracture_on_well.py
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()
4 changes: 2 additions & 2 deletions docs/rips/generated/RiaVersionInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# Python version of RiaVersionInfo.h
# Just sets version constants

RESINSIGHT_MAJOR_VERSION = "2022"
RESINSIGHT_MINOR_VERSION = "06"
RESINSIGHT_MAJOR_VERSION = "2023"
RESINSIGHT_MINOR_VERSION = "01"
RESINSIGHT_PATCH_VERSION = "0"
Empty file removed docs/rips/generated/__init__.py
Empty file.

0 comments on commit 1efbabc

Please sign in to comment.