Support Services Corporate Home EarthVision Events
 
FAQs


Creating a Mesh along a Well Path

October 2001

A recent question spurred the following script. Essentially what was needed was a regularly spaced mesh that conformed to a specific well path. It was also desired to be able to control the Z-spacing and the X,Y-spacing of the mesh as well as the color of the mesh.

Since this script would evolve to be somewhat complex, the Perl scripting language was used. For this script, the perl executable is found in /usr/local/bin; hence, the script must be modified if the perl executable is in a different location.

To make this utility easier to run, an evmacro script is also included; evmacro is used to create EarthVision-style interfaces. More information about evmacro is found in the EarthVision User's Guide, Appendix I.

The following image shows the kind of result that was desired:

The mesh output file, which is simply a series of XYZ locations connected via lines, is shown along with a faces file. It was set up with an X,Y-interval of 100 and a Z-interval of 200. The well tubes and caps were turned on in the 3D Viewer.
 

Essentially, the method to create the mesh is to create a script that:

  1. Flattens the path line and uses that as the basis for the horizontal lines.
  2. Identifies or interpolates the positions on the well path that fall at the exact X,Y user-specified interval. Lines created through these points from the Z-minimum to the Z-maximum form the horizontal lines of the mesh.
  3. Copies the well path to the output data file and surrounds it with a well tube for the final output.
The first requirement is to create the perl script. In order to later use with the evmacro script, all the arguments to run the script must be taken from the command line. Here is the script:
 

====================== start of wellmesh.pl ====================
#!/usr/local/bin/perl
# Shareware Disclaimer:
#   This software is SHAREWARE and is provided as a benefit
#   for our clients by Dynamic Graphics, Inc.; however, it is
#   unsupported. Dynamic Graphics accepts no responsibility for
#   the content, maintenance, or support of SHAREWARE.

# Assign command line arguments to variables
$FILENAME=$ARGV[0];
$ZMIN=$ARGV[1];
$ZMAX=$ARGV[2];
$XYINTERVAL=$ARGV[3];
$ZINTERVAL=$ARGV[4];
$MESHCOLOR=$ARGV[5];
$FINAL=$ARGV[6];

# Calculate some default values
$ZRANGE=$ZMAX-$ZMIN;
$ZINTS=int($ZRANGE/$ZINTERVAL);
$WELLNAME='11111';
$RAD='25';
$MESHRAD=2;

# Use formula processor to create a new file
# Note, the input file can only have one well
system("ev_fpfp << EOF
TEMP0.dat<x>=$FILENAME<x>;
TEMP0.dat<y>=$FILENAME<y>;
TEMP0.dat<z>=$FILENAME<z>;
TEMP0.dat<wellid>=$FILENAME<wellid>;
TEMP0.dat<radius>=$RAD;
TEMP0.dat<linecol>=4;
TEMP0.dat<symsize>=1.0;
EOF");

# Add original well back into the final file
system("ev_datcombine -o FINALZ.dat TEMP0.dat");

# Start setting up the horizontal lines of the mesh
system("ev_fpfp << EOF
TEMP1.dat<x>=$FILENAME<x>;
TEMP1.dat<y>=$FILENAME<y>;
TEMP1.dat<z>=$ZMAX;
TEMP1.dat<wellid>=$WELLNAME;
TEMP1.dat<linecol>=$MESHCOLOR;
TEMP1.dat<symsize>=0.0001;
TEMP1.dat<radius>=$MESHRAD;
EOF");

system("cp TEMP1.dat TEMP2.dat");

system("ev_fpfp << EOF
TEMP3.dat<x>=TEMP2.dat<x>;
TEMP3.dat<y>=TEMP2.dat<y>;
TEMP3.dat<z>=TEMP2.dat<z>;
TEMP3.dat<wellid>=22222;
TEMP3.dat<linecol>=$MESHCOLOR;
TEMP3.dat<symsize>=0.0001;
TEMP3.dat<radius>=$MESHRAD;
EOF");

system("cp FINALZ.dat TEMP4.dat");
system("ev_datcombine -o FINALZ.dat TEMP4.dat TEMP3.dat");

# Creating the entire set of horizontal mesh lines
for ($i=1;$i<=$ZINTS;$i++) {
    $WLID=($i+2)*11111;
    system("ev_fpfp << EOF
TEMP3.dat<z>=TEMP3.dat<z>-$ZINTERVAL;
TEMP3.dat<wellid>=$WLID;
EOF");
    system("cp FINALZ.dat TEMP4.dat");
    system("ev_datcombine -o FINALZ.dat TEMP4.dat TEMP3.dat");
    }

# Start work on the vertical lines
# Basically the task is to move from point
# to point in the well file and when the X,Y
# distance is beyond the X,Y interval, you
# figure out exactly where on the well the
# X,Y interval was hit. Then draw a 2 point
# line from ZMIN to ZMAX at that point.
open(INFILE,"TEMP0.dat") || die "Can't open source file: $!\n";
open(OUTFILE,">TEMP5.dat") || die "Can't open output file: $!\n";
print OUTFILE "# Type: scattered data
# Version: 5
# Format: free
# Field: 1 x
# Field: 2 y
# Field: 3 z
# Field: 4 wellid non-numeric
# Field: 5 symsize
# Field: 6 linecol
# Field: 7 radius
# Projection: Local Rectangular
# Units: unknown
# End:\n";

$FND=0;
$XYDIST=0;
$LNID='111000';
while(<INFILE>) {
        chop($_);
        if ("$_" =~ /^#/) {
            next;
            }
            # deal with the first record
        elsif ($FND == 0) {
            @fields=split(' ',$_);
            $PREV_X=$fields[0];
            $PREV_Y=$fields[1];
            $FND=1;
            $EXACT_X=$PREV_X;
            $EXACT_Y=$PREV_Y;
            print OUTFILE "$EXACT_X $EXACT_Y $ZMAX $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            print OUTFILE "$EXACT_X $EXACT_Y $ZMIN $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            next;
            }
            # deal with subsequent records
        else {
            @fields=split(' ',$_);
            $NEW_X=$fields[0];
            $NEW_Y=$fields[1];
            # calculate distance from one point to the next
            $SEGDIST=(($NEW_X-$PREV_X)**2+($NEW_Y-$PREV_Y)**2)**0.5;
            $XYDIST=$XYDIST+$SEGDIST;
            }
            # when the point lies within the interval
        if ($XYDIST < $XYINTERVAL) {
            $PREV_X=$NEW_X;
            $PREV_Y=$NEW_Y;
            next;
            }
            # when the point lines outside the interval
        elsif ($XYDIST > $XYINTERVAL) {
            $LNID++;
            $SEG2=$XYDIST-$XYINTERVAL;
            $SEG1=$SEGDIST-$SEG2;
            # calculate the exact X,Y of the interval boundary
            $EXACT_X=(($NEW_X-$PREV_X)*$SEG1/$SEGDIST)+$PREV_X;
            $EXACT_Y=(($NEW_Y-$PREV_Y)*$SEG1/$SEGDIST)+$PREV_Y;
            $PREV_X=$NEW_X;
            $PREV_Y=$NEW_Y;
            print OUTFILE "$EXACT_X $EXACT_Y $ZMAX $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            print OUTFILE "$EXACT_X $EXACT_Y $ZMIN $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            $XYDIST=$SEG2;
            }
            # when the point lies directly on the interval
        elsif ($XYDIST == $XYINTERVAL) {
            $LNID++;
            $EXACT_X=$NEW_X;
            $EXACT_Y=$NEW_Y;
            print OUTFILE "$EXACT_X $EXACT_Y $ZMAX $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            print OUTFILE "$EXACT_X $EXACT_Y $ZMIN $LNID ";
            print OUTFILE "0.0001 $MESHCOLOR $MESHRAD\n";
            $XYDIST=0;
            }
    }

close(INFILE);
close(OUTFILE);

system("cp FINALZ.dat TEMP4.dat");
system("ev_datcombine -o FINALZ.dat TEMP4.dat TEMP5.dat");
 

unlink("TEMP0.dat");
unlink("TEMP1.dat");
unlink("TEMP2.dat");
unlink("TEMP3.dat");
unlink("TEMP4.dat");
unlink("TEMP5.dat");
 

rename("FINALZ.dat","$FINAL");

====================== end of wellmesh.pl ======================


Note that the input data file can only have one well in it and must have an EarthVision header. This perl script also uses EarthVision modules via the UNIX system command. These modules must be in the user's path.

The method used to calculate the horizontal lines is straightforward but the creation of the vertical lines is a bit more complex. The method involves calculating and keeping track of the X,Y distance from point to point along the well path. When the X,Y distance is beyond the interval value (set for the X,Y spacing of the mesh), the program does a linear interpolation to identify the exact X,Y location of the interval boundary. Then a line is drawn from the Z-maximum to the Z-minimum at that X,Y location.

To make this script easier to use, an evmacro script is in order. The following script was written for this application:

====================== start of wellmesh ====================
#!/bin/sh
# Shareware Disclaimer:
#   This software is SHAREWARE and is provided as a benefit
#   for our clients by Dynamic Graphics, Inc.; however, it is
#   unsupported.  Dynamic Graphics accepts no responsibility for
#   the content, maintenance, or support of SHAREWARE.
evmacro "$@" \
-title "Wellmesh Utility" \
-file "dat" -label "Input Well File" -variable INFILE \
-file "dat" -label "Output File" -variable OUTFILE \
-separator \
-number -label "Z-maximum" -variable ZMAX \
-number -label "Z-minimum" -variable ZMIN \
-number -label "XY-interval" -variable XYINT \
-number -label "Z-interval" -variable ZINT \
-number -label "Mesh Color Number" -variable COLNUM \
-exec "wellmesh.pl \$INFILE \$ZMIN \$ZMAX \$XYINT \$ZINT \$COLNUM \$OUTFILE" \

====================== end of wellmesh ======================

When executed in an EarthVision environment (by typing wellmesh at the system prompt, this script produces the following interface:

 

 
[Home] [Corporate] [Events & News]
[EarthVision] [Support] [Services] [Contact Us]


© 1999-2007 Dynamic Graphics, Inc. All Rights Reserved. Legal Notices.
See Legal Notices for appropriate copyright trademark legend.
Feedback: webmaster@dgi.com

Last updated: March 22, 2007