Initial Commit of existing code, closes POC-100

This commit is contained in:
Patrick McDonagh
2016-06-23 12:21:18 -05:00
commit 5836f5ac7d
21 changed files with 1398 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadData", "ReadData\ReadData.csproj", "{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}.Debug|x86.ActiveCfg = Debug|x86
{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}.Debug|x86.Build.0 = Debug|x86
{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}.Release|x86.ActiveCfg = Release|x86
{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,12 @@
<Properties StartupItem="ReadData\ReadData.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="ReadData\Program.cs">
<Files>
<File FileName="ReadData\Program.cs" Line="47" Column="28" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
</Properties>

View File

@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Collections.Generic;
using Well;
namespace ReadData
{
class MainClass
{
public static void Main (string[] args)
{
List<double> bufferP = new List<double> ();
List<double> bufferL = new List<double> ();
WellStruct well1 = new WellStruct ();
well1.clearTopArrays ();
DateTime now = DateTime.Now;
string dtime = now.ToString("_yyyyMMdd_HHmmss");
well1.readSetup (@"C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Testing\Input\wellParamsIn_" + well1.wellID + ".csv");
well1.taperCompute(well1.buf_dt, well1.buf_tubingHeadPressure, well1.buf_fluidGradient, well1.buf_sbfriction, well1.buf_numTapers, well1.buf_c, well1.buf_rodLength, well1.buf_rodDiameter, well1.buf_rodYM);
well1.writeSetup (@"C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Testing\Output\wellParamsOut" + well1.wellID+dtime + ".csv");
var reader = new StreamReader (File.OpenRead (@"C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Testing\Input\test_surface.csv"));
var csv = new StreamWriter (@"C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Testing\Cards\test_downhole" + dtime + ".csv");
csv.WriteLine ("downhole_position, downhole_load, surface_position,surface_load,status");
csv.AutoFlush = true;
while (!reader.EndOfStream) {
var line = reader.ReadLine ();
var values = line.Split (',');
var val = well1.calc (Convert.ToDouble(values [0]), Convert.ToDouble(values [1]));
if (val.Item1 != 7) {
bufferP.Add (Convert.ToDouble (values [0]));
bufferL.Add (Convert.ToDouble (values [1]));
}
var wLine = string.Format("{0},{1},{2},{3},{4}", val.Item2, val.Item3, values[0], values[1],val.Item1 );
//Console.WriteLine (wLine);
if (val.Item1 == 7) {
csv.WriteLine (wLine);
}
}
//csv.WriteLine ("-,-");
for (var i = 0; i < bufferP.Count; i++) {
var val = well1.calc (bufferP[i], bufferL[i]);
var wLine = string.Format("{0},{1},{2},{3},{4}", val.Item2, val.Item3, bufferP[i], bufferL[i],val.Item1);
if (val.Item1 == 7) {
csv.WriteLine (wLine);
}
}
csv.Flush ();
}
}
}

View File

@@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("ReadData")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("pmcdonagh")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{11B4DFFB-DDDF-43FD-900B-AD4D6FD6873B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ReadData</RootNamespace>
<AssemblyName>ReadData</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Well">
<HintPath>..\..\..\Well\Well\Well\bin\Debug\Well.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@@ -0,0 +1,18 @@
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\bin\Debug\ReadData.exe
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\bin\Debug\ReadData.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\bin\Debug\Well.dll
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\bin\Debug\Well.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\obj\x86\Debug\ReadData.exe
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\obj\x86\Debug\ReadData.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Test_Cards\ReadData\ReadData\obj\x86\Debug\ReadData.csprojResolveAssemblyReference.cache
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.csprojResolveAssemblyReference.cache
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.exe
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\bin\Debug\ReadData.exe
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\bin\Debug\ReadData.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\bin\Debug\Well.dll
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\bin\Debug\Well.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.pdb
C:\Dropbox (Henry Pump)\Patrick_McDonagh\Customers\Oxy\Downhole Algorithm DLL\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.exe
C:\Dropbox (Henry Pump)\Patrick_McDonagh\Customers\Oxy\Downhole Algorithm DLL\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.pdb
C:\Users\Patrick\Documents\Henry_Pump\oxy-card-analysis\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.exe
C:\Users\Patrick\Documents\Henry_Pump\oxy-card-analysis\ReadData\ReadData\ReadData\obj\x86\Debug\ReadData.pdb

17
Well/Well/Well.sln Normal file
View File

@@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Well", "Well\Well.csproj", "{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}.Debug|x86.ActiveCfg = Debug|x86
{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}.Debug|x86.Build.0 = Debug|x86
{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}.Release|x86.ActiveCfg = Release|x86
{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal

12
Well/Well/Well.userprefs Normal file
View File

@@ -0,0 +1,12 @@
<Properties StartupItem="Well\Well.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="Well\Program.cs">
<Files>
<File FileName="Well\Program.cs" Line="28" Column="37" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
</Properties>

595
Well/Well/Well/Program.cs Normal file
View File

@@ -0,0 +1,595 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace Well
{
public class WellStruct
{
public int wellID;
private double[,] topPosArray = new double[10, 100];
private double[,] topLoadArray = new double[10, 100];
public double loadBefore, loadAfter, loadBefore3, loadAfter3;
public double dt;//delta T for measurements
public double tubingHeadPressure; //Tubing Head Pressure (PSI)
public double fluidGradient; //Tubing Fluid Gradient (PSI/ft)
public double sbfriction; //Stuffing Box Friction (lbs)
static int numTapers; //Number of Rod String Tapers
public int nT1 = numTapers + 1;
//Rod String Inputs
public double[] c = new double[10]; //User-Defined damping constant per taper (1/sec)
public double[] rodLength = new double[10]; //Length of each rod taper (top to bottom)(ft)
public double[] rodDiameter = new Double[10]; //Diameter of each rod taper (top to bottom)(in)
public double[] rodYM = new Double[10]; //Youngs modulus of each rod taper (top to bottom)(PSI) Steel=30.5, fiberglass=7.2
public double[] rodWeightPerFoot = new Double[10]; //Weight per foot of each rod (ft/lb)
//Buffer Values
public double buf_dt;//delta T for measurements
public double buf_tubingHeadPressure; //Tubing Head Pressure (PSI)
public double buf_fluidGradient; //Tubing Fluid Gradient (PSI/ft)
public double buf_sbfriction; //Stuffing Box Friction (lbs)
public int buf_numTapers; //Number of Rod String Tapers
//Rod String Inputs
public double[] buf_c = new double[10]; //User-Defined damping constant per taper (1/sec)
public double[] buf_rodLength = new double[10]; //Length of each rod taper (top to bottom)(ft)
public double[] buf_rodDiameter = new Double[10]; //Diameter of each rod taper (top to bottom)(in)
public double[] buf_rodYM = new Double[10]; //Youngs modulus of each rod taper (top to bottom)(PSI) Steel=30.5, fiberglass=7.2
public double[] buf_rodWeightPerFoot = new Double[10]; //Weight per foot of each rod (ft/lb)
public double[] a = new double[10];
public double[] area = new Double[11];
public double[] pressure = new double[10];
public double[] buoyantForce = new double[10];
public double buoyantForceTotal = 0;
public double[] stretch = new double[10];
public double[] weightData = new double[10];
public double weightDataTotal = 0;
public double[] annularForceData = new double[10];
public double annularForceDataTotal = 0;
public double[] force = new double[10];
public double[] alpha = new double[10];
public double[] xOverA = new double[10];
public double[] factorArray = new double[10];
public int[] lagIndexArray = new int[10];
public int[] centerPoint = new int[10];
public int[] sumCenterPoint = new int[10];
public int[] lengthRequired = new int[10];
public double[] rodDepth = new double[10];
public double rodDepthTotal = 0;
public double[] rodWeightAir = new double[10];
public double rodWeightAirTotal = 0;
public double[] rodWeightFluid = new double[10];
public double rodWeightFluidTotal = 0;
public int[] count = new int[10];
public double sPositionPrevious;
public void SetID(int id)
{
wellID = id;
}
public void UpdateTapers()
{
const double pi = Math.PI;
a[0] = 0;
area[0] = 0;
area[numTapers + 1] = 0;
pressure[0] = tubingHeadPressure;
buoyantForce[0] = 0;
stretch[0] = 0;
weightData[0] = 0;
annularForceData[0] = 0;
force[0] = 0;
alpha[0] = 0;
xOverA[0] = 0;
factorArray[0] = 0;
lagIndexArray[0] = 0;
centerPoint[0] = 0;
sumCenterPoint[0] = 0;
lengthRequired[0] = 0;
rodDepth[0] = 0;
rodWeightAir[0] = 0;
rodWeightFluid[0] = 0;
buoyantForceTotal = 0;
weightDataTotal = 0;
annularForceDataTotal = 0;
rodDepthTotal = 0;
rodWeightAirTotal = 0;
rodWeightFluidTotal = 0;
for (int area_i = 1; area_i < nT1; area_i++)
{
area[area_i] = (pi / 4) * Math.Pow(rodDiameter[area_i], 2);
}
for (int i = 1; i < nT1; i++)
{
a[i] = 1000 * Math.Sqrt(32.2 * rodYM[i] * area[i] / rodWeightPerFoot[i]);
rodDepth[i] = rodDepth[i - 1] + rodLength[i];
pressure[i] = pressure[i - 1] + fluidGradient * rodLength[i];
buoyantForce[i] = pressure[i] * (area[i + 1] - area[i]);
rodWeightAir[i] = rodWeightPerFoot[i] * rodLength[i];
rodWeightFluid[i] = rodWeightAir[i] + buoyantForce[i];
}
for (int j = 1; j < nT1; j++)
{
for (int k = j + 1; k < nT1; k++)
{
weightData[j] += rodWeightAir[k]; // how much weight is felt on each taper
}
for (int l = j; j < numTapers; j++)
{
annularForceData[j] += -buoyantForce[l]; //buoyant force exerted on each taper
}
force[j] = (-area[numTapers] * pressure[numTapers]) + weightData[j] - annularForceData[j];
alpha[j] = (force[j] + rodWeightAir[j]) / (rodYM[j] * Math.Pow(10, 6) * area[j]);
stretch[j] = stretch[j - 1] + alpha[j] * rodLength[j] - (rodWeightPerFoot[j] * Math.Pow(rodLength[j], 2)) / (2 * rodYM[j] * Math.Pow(10, 6) * area[j]);
}
for (int m = 1; m < nT1; m++)
{
xOverA[m] = rodLength[m] / a[m];
lagIndexArray[m] = (int)(rodLength[m] / (a[m] * dt));
factorArray[m] = (xOverA[m] - lagIndexArray[m] * dt) / dt;
centerPoint[m] = lagIndexArray[m] + 2;
lengthRequired[m] = 2 * (lagIndexArray[m] + 1) + 1;
}
sumCenterPoint[1] = centerPoint[1];
for (var n = 2; n < numTapers; n++)
{
sumCenterPoint[n] = sumCenterPoint[n - 1] + centerPoint[n] - 1;
}
for (var t = 0; t < nT1; t++)
{
buoyantForceTotal += buoyantForce[t];
rodWeightAirTotal += rodWeightAir[t];
rodWeightFluidTotal += rodWeightFluid[t];
rodDepthTotal += rodLength[t];
annularForceDataTotal += annularForceData[t];
weightDataTotal += weightData[t];
}
}
private double position(int p)
{
//Console.WriteLine ("position({0})", p);
loadBefore = 0;
loadAfter = 0;
loadBefore3 = 0;
loadAfter3 = 0;
//Temporary Variables
double a1 = a[p];
double cd = c[p];
double factor = factorArray[p];
double rodLengthp = rodLength[p];
int lagIndex = lagIndexArray[p];
double Y1 = rodYM[p] * Math.Pow(10, 6);
double A1 = area[p];
int centerOfArray = centerPoint[p];
int iBefore = centerOfArray - lagIndex;
int iAfter = centerOfArray + lagIndex;
double pumpPOS = 0;
//Do work
pumpPOS = Math.Exp((cd * rodLengthp) / (2 * a1)) * (topPosArray[p, iAfter] + factor * (topPosArray[p, iAfter + 1] - topPosArray[p, iAfter]));
pumpPOS += Math.Exp(-(cd * rodLengthp) / (2 * a1)) * (topPosArray[p, iBefore] + factor * (topPosArray[p, iBefore - 1] - topPosArray[p, iBefore]));
pumpPOS = pumpPOS / 2;
double insideIntegral = 0;
int q = 1;
while (q < 2 * lagIndex - 1)
{
insideIntegral += dt * (1 / (Y1 * A1)) * (Math.Exp(-(cd * (lagIndex - q) * dt) / 2) * topLoadArray[p, iBefore + q]);
q++;
}
insideIntegral += 0.5 * dt * (1 / (Y1 * A1)) * (Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore] + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
loadBefore = Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore] + factor * (Math.Exp(-(cd * (lagIndex + 1) * dt) / 2) * topLoadArray[p, iBefore - 1] - Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore]);
loadAfter = Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter] + factor * (Math.Exp(-(cd * (-lagIndex - 1) * dt) / 2) * topLoadArray[p, iAfter + 1] - Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
insideIntegral += 0.5 * factor * dt * (1 / (Y1 * A1)) * (loadBefore + Math.Exp(-(cd * (lagIndex) * dt) / 2) * topLoadArray[p, iBefore]);
insideIntegral += 0.5 * factor * dt * (1 / (Y1 * A1)) * (loadAfter + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
insideIntegral = 0.5 * a1 * insideIntegral;
pumpPOS += insideIntegral;
insideIntegral = 0;
int r = 1;
while (r < 2 * lagIndex - 1)
{
insideIntegral += dt * (Math.Exp(-(cd * lagIndex - r) * dt) / 2) * (topPosArray[p, iBefore + r]);
r++;
}
insideIntegral += 0.5 * dt * (Math.Exp(-(cd * lagIndex * dt) / 2) * topPosArray[p, iBefore] + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
loadBefore3 = Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore] + factor * (Math.Exp(-(cd * (lagIndex + 1) * dt) / 2) * topPosArray[p, iBefore] - Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore]);
loadAfter3 = Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter] + factor * (Math.Exp(-(cd * (-lagIndex - 1) * dt) / 2) * topPosArray[p, iAfter] - Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
insideIntegral += 0.5 * factor * dt * (loadBefore3 + Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore]);
insideIntegral += 0.5 * factor * dt * (loadAfter3 + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
insideIntegral = -((cd * rodLengthp) / 4) * (0.5 * (cd / (2 * a1))) * insideIntegral;
pumpPOS += insideIntegral;
return pumpPOS;
}
private double load(int s)
{
//Console.WriteLine ("load({0})", s);
//temporary variables
double a1 = a[s];
double cd = c[s];
double rodLengths = rodLength[s];
int lagIndex = lagIndexArray[s];
double Y1 = rodYM[s] * Math.Pow(10, 6);
double A1 = area[s];
int centerOfArray = centerPoint[s];
int iBefore = centerOfArray - lagIndex;
int iAfter = centerOfArray + lagIndex;
double pumpLOAD = 0;
pumpLOAD = 0.5 * (a1 / (Y1 * A1)) * (1 / a1) * (loadBefore + loadAfter);
pumpLOAD += -((cd * rodLengths) / 4) * (0.5 * (cd / (2 * a1))) * (1 / a1) * (loadBefore3 + loadAfter3);
double firstPart = 0;
double pointAfter = (topPosArray[s, iAfter + 1] - topPosArray[s, iAfter - 1]) / (2 * dt);
double pointBefore = (topPosArray[s, iBefore + 1] - topPosArray[s, iBefore - 1]) / (2 * dt);
firstPart = (Math.Exp((cd * rodLengths) / (2 * a1)) * pointAfter - Math.Exp(-(cd * rodLengths) / (2 * a1)) * pointBefore) / (2 * a1);
firstPart += (cd * Math.Exp((cd * rodLengths) / (2 * a1)) * topPosArray[s, iAfter] - cd * Math.Exp((-cd * rodLengths) / (2 * a1)) * topPosArray[s, iBefore]) / (4 * a1);
pumpLOAD = Y1 * A1 * (firstPart + pumpLOAD);
return pumpLOAD;
}
public Tuple<int, double, double> calc(double sPosition, double sLoad)
{
bool useShift = false;
int loadMult = 1;
int tapersAllowed = 1;
double dPosition = 0;
double dLoad = 0;
int status = 0;
for (int ii = 1; ii < lengthRequired[1] + 1; ii++)
{
topPosArray[1, ii - 1] = topPosArray[1, ii];
topLoadArray[1, ii - 1] = topLoadArray[1, ii];
}
topPosArray[1, lengthRequired[1]] = -(sPosition / 12); //stores current position in feet
if (sPosition > sPositionPrevious)
{
topLoadArray[1, lengthRequired[1]] = loadMult * (sLoad - rodWeightFluidTotal) - sbfriction;
}
else
{
topLoadArray[1, lengthRequired[1]] = loadMult * (sLoad - rodWeightFluidTotal) + sbfriction;
}
int j = 1;
while (j <= tapersAllowed)
{
count[j]++;
if (count[j] >= lengthRequired[j])
{
if ((j + 1) <= numTapers)
{
for (int jj = 2; jj < lengthRequired[j + 1] + 1; jj++)
{
topPosArray[j + 1, jj - 1] = topPosArray[j + 1, jj];
topLoadArray[j + 1, jj - 1] = topLoadArray[j + 1, jj];
}
topPosArray[j + 1, lengthRequired[j + 1]] = position(j);
topLoadArray[j + 1, lengthRequired[j + 1]] = load(j);
status = 1 + 4;
}
else
{
if (useShift)
{
dPosition = -12 * (position(j) + stretch[numTapers]);
}
else
{
dPosition = -12 * position(j);
}
dLoad = load(j) + force[numTapers];
status = 1 + 2 + 4;
}
count[j]--;
tapersAllowed += 1;
if (tapersAllowed > numTapers)
{
tapersAllowed = numTapers;
}
}
j++;
}
return Tuple.Create(status, dPosition, dLoad);
}
public void writeSetup(string filename)
{
var csv = new StreamWriter(filename);
csv.AutoFlush = true;
Dictionary<string, string> wellParams = new Dictionary<string, string>();
wellParams.Add("dt", Convert.ToString(dt));
wellParams.Add("tubingHeadPressure", Convert.ToString(tubingHeadPressure));
wellParams.Add("fluidGradient", Convert.ToString(fluidGradient));
wellParams.Add("sbfriction", Convert.ToString(sbfriction));
wellParams.Add("numTapers", Convert.ToString(numTapers));
wellParams.Add("c", ConvertDoubleArray(c));
wellParams.Add("rodLength", ConvertDoubleArray(rodLength));
wellParams.Add("rodDiameter", ConvertDoubleArray(rodDiameter));
wellParams.Add("rodYM", ConvertDoubleArray(rodYM));
wellParams.Add("rodWeightPerFoot", ConvertDoubleArray(rodWeightPerFoot));
wellParams.Add("a", ConvertDoubleArray(a));
wellParams.Add("area", ConvertDoubleArray(area));
wellParams.Add("pressure", ConvertDoubleArray(pressure));
wellParams.Add("buoyantForce", ConvertDoubleArray(buoyantForce));
wellParams.Add("buoyantForceTotal", Convert.ToString(buoyantForceTotal));
wellParams.Add("stretch", ConvertDoubleArray(stretch));
wellParams.Add("weightData", ConvertDoubleArray(weightData));
wellParams.Add("weightDataTotal", Convert.ToString(weightDataTotal));
wellParams.Add("annularForceData", ConvertDoubleArray(annularForceData));
wellParams.Add("annularForceDataTotal", Convert.ToString(annularForceDataTotal));
wellParams.Add("force", ConvertDoubleArray(force));
wellParams.Add("alpha", ConvertDoubleArray(alpha));
wellParams.Add("xOverA", ConvertDoubleArray(xOverA));
wellParams.Add("factorArray", ConvertDoubleArray(factorArray));
wellParams.Add("lagIndexArray", ConvertIntArray(lagIndexArray));
wellParams.Add("centerPoint", ConvertIntArray(centerPoint));
wellParams.Add("sumCenterPoint", ConvertIntArray(sumCenterPoint));
wellParams.Add("lengthRequired", ConvertIntArray(lengthRequired));
wellParams.Add("rodDepth", ConvertDoubleArray(rodDepth));
wellParams.Add("rodDepthTotal", Convert.ToString(rodDepthTotal));
wellParams.Add("rodWeightAir", ConvertDoubleArray(rodWeightAir));
wellParams.Add("rodWeightAirTotal", Convert.ToString(rodWeightAirTotal));
wellParams.Add("rodWeightFluid", ConvertDoubleArray(rodWeightFluid));
wellParams.Add("rodWeightFluidTotal", Convert.ToString(rodWeightFluidTotal));
foreach (string key in wellParams.Keys)
{
var wLine = string.Format("{0},{1}", key, wellParams[key]);
csv.WriteLine(wLine);
}
}
public void clearTopArrays()
{
for (int rowI = 0; rowI < 10; rowI++)
{
for (int colI = 0; colI < 100; colI++)
{
topLoadArray[rowI, colI] = 0;
topPosArray[rowI, colI] = 0;
}
}
}
public void taperCompute(double i_dt, double i_tubingHeadPressure, double i_fluidGradient, double i_sbfriction, int i_numTapers, double[] i_c, double[] i_rodLength, double[] i_rodDiameter, double[] i_rodYM)
{
dt = i_dt;
tubingHeadPressure = i_tubingHeadPressure;
fluidGradient = i_fluidGradient;
sbfriction = i_sbfriction;
numTapers = i_numTapers;
nT1 = numTapers + 1;
c = i_c;
rodLength = i_rodLength;
rodDiameter = i_rodDiameter;
rodYM = i_rodYM;
for (int i = 0; i < 10; i++)
{
rodWeightPerFoot[i] = lookupRodWeightPerFoot(rodYM[i], rodDiameter[i]);
}
UpdateTapers();
}
public void readSetup(string filename)
{
var reader = new StreamReader(File.OpenRead(filename));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
string key = values[0];
switch (key)
{
case "dt":
buf_dt = Convert.ToDouble(values[1]);
break;
case "tubingHeadPressure":
buf_tubingHeadPressure = Convert.ToDouble(values[1]);
break;
case "fluidGradient":
buf_fluidGradient = Convert.ToDouble(values[1]);
break;
case "sbfriction":
buf_sbfriction = Convert.ToDouble(values[1]);
break;
case "numTapers":
buf_numTapers = Convert.ToInt32(values[1]);
break;
case "c":
buf_c = ConvertDoubleString(values[1],10);
break;
case "rodLength":
buf_rodLength = ConvertDoubleString(values[1], 10);
break;
case "rodDiameter":
buf_rodDiameter = ConvertDoubleString(values[1], 10);
break;
case "rodYM":
buf_rodYM = ConvertDoubleString(values[1], 10);
break;
case "rodWeightPerFoot":
buf_rodWeightPerFoot = ConvertDoubleString(values[1], 10);
break;
}
}
}
static double lookupRodWeightPerFoot(double i_ym, double i_diam)
//looks up rod Weight per foot
{
double wtPerFt;
if (i_ym == 30.5)
{
if (i_diam <= 2 && i_diam > 1.75)
{
wtPerFt = 10.7;
}
else if (i_diam <= 1.75 && i_diam > 1.65)
{
wtPerFt = 8.2;
}
else if (i_diam <= 1.65 && i_diam > 1.5)
{
wtPerFt = 7;
}
else if (i_diam <= 1.5 && i_diam > 1.375)
{
wtPerFt = 6;
}
else if (i_diam <= 1.375 && i_diam > 1.125)
{
wtPerFt = 5;
}
else if (i_diam <= 1.125 && i_diam > 1)
{
wtPerFt = 3.676;
}
else if (i_diam <= 1 && i_diam > 0.875)
{
wtPerFt = 2.904;
}
else if (i_diam <= 0.875 && i_diam > 0.75)
{
wtPerFt = 2.224;
}
else if (i_diam <= 0.75 && i_diam > 0.625)
{
wtPerFt = 1.634;
}
else if (i_diam <= 0.625 && i_diam > 0.5)
{
wtPerFt = 1.13;
}
else if (i_diam <= 0.5)
{
wtPerFt = 0.72;
}
else
{
wtPerFt = 0;
}
}
else if (i_ym == 7.2)
{
if (i_diam <= 1.25 && i_diam > 1.125)
{
wtPerFt = 1.2879;
}
else if (i_diam <= 1.125 && i_diam > 1)
{
wtPerFt = 1.09;
}
else if (i_diam <= 1 && i_diam > 0.875)
{
wtPerFt = 0.8188;
}
else if (i_diam <= 0.875 && i_diam > 0.75)
{
wtPerFt = 0.6108;
}
else if (i_diam <= 0.75)
{
wtPerFt = 0.484;
}
else
{
wtPerFt = 0;
}
}
else
{
wtPerFt = 0;
}
return wtPerFt;
}
static string ConvertDoubleArray(double[] array)
{
string result = "";
foreach (double entry in array)
{
result += Convert.ToString(entry) + "&";
}
return result;
}
static string ConvertIntArray(int[] array)
{
string result = "";
foreach (int entry in array)
{
result += Convert.ToString(entry) + "&";
}
return result;
}
static double[] ConvertDoubleString(string inp, int size)
{
//Console.WriteLine("Convert {0}", inp);
string[] sep = new string[] { "&" };
var splt = inp.Split(sep, StringSplitOptions.RemoveEmptyEntries);
int arrSize = splt.Length;
var result = new double[size];
for (var i = 0; i < arrSize; i++)
{
result[i] = Convert.ToDouble(splt[i]);
//Console.WriteLine(result[i]);
}
return result;
}
static int[] ConvertIntString(string inp, int size)
{
string[] sep = new string[] { "&" };
var splt = inp.Split(sep, StringSplitOptions.RemoveEmptyEntries);
int arrSize = splt.Length;
var result = new int[size];
for (var i = 0; i < arrSize; i++)
{
result[i] = Convert.ToInt32(splt[i]);
}
return result;
}
}
}

View File

@@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Well")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("pmcdonagh")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{49F63B39-D6E0-4B8D-9F56-5A031BDE6FD3}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Well</RootNamespace>
<AssemblyName>Well</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,512 @@
public double buf_sbfriction; //Stuffing Box Friction (lbs)
public int buf_numTapers; //Number of Rod String Tapers
//Rod String Inputs
public double[] buf_c = new double[10]; //User-Defined damping constant per taper (1/sec)
public double[] buf_rodLength = new double[10]; //Length of each rod taper (top to bottom)(ft)
public double[] buf_rodDiameter = new Double[10]; //Diameter of each rod taper (top to bottom)(in)
public double[] buf_rodYM = new Double[10]; //Youngs modulus of each rod taper (top to bottom)(PSI) Steel=30.5, fiberglass=7.2
public double[] buf_rodWeightPerFoot = new Double[10]; //Weight per foot of each rod (ft/lb)
public double[] a = new double[10];
public double[] area = new Double[11];
public double[] pressure = new double[10];
public double[] buoyantForce = new double[10];
public double buoyantForceTotal = 0;
public double[] stretch = new double[10];
public double[] weightData = new double[10];
public double weightDataTotal = 0;
public double[] annularForceData = new double[10];
public double annularForceDataTotal = 0;
public double[] force = new double[10];
public double[] alpha = new double[10];
public double[] xOverA = new double[10];
public double[] factorArray = new double[10];
public int[] lagIndexArray = new int[10];
public int[] centerPoint = new int[10];
public int[] sumCenterPoint = new int[10];
public int[] lengthRequired = new int[10];
public double[] rodDepth = new double[10];
public double rodDepthTotal = 0;
public double[] rodWeightAir = new double[10];
public double rodWeightAirTotal = 0;
public double[] rodWeightFluid = new double[10];
public double rodWeightFluidTotal = 0;
public int[] count = new int[10];
public double sPositionPrevious;
public void SetID(int id)
{
wellID = id;
}
public void UpdateTapers()
{
const double pi = Math.PI;
a[0] = 0;
area[0] = 0;
area[numTapers + 1] = 0;
pressure[0] = tubingHeadPressure;
buoyantForce[0] = 0;
stretch[0] = 0;
weightData[0] = 0;
annularForceData[0] = 0;
force[0] = 0;
alpha[0] = 0;
xOverA[0] = 0;
factorArray[0] = 0;
lagIndexArray[0] = 0;
centerPoint[0] = 0;
sumCenterPoint[0] = 0;
lengthRequired[0] = 0;
rodDepth[0] = 0;
rodWeightAir[0] = 0;
rodWeightFluid[0] = 0;
buoyantForceTotal = 0;
weightDataTotal = 0;
annularForceDataTotal = 0;
rodDepthTotal = 0;
rodWeightAirTotal = 0;
rodWeightFluidTotal = 0;
for (int area_i = 1; area_i < nT1; area_i++)
{
area[area_i] = (pi / 4) * Math.Pow(rodDiameter[area_i], 2);
}
for (int i = 1; i < nT1; i++)
{
a[i] = 1000 * Math.Sqrt(32.2 * rodYM[i] * area[i] / rodWeightPerFoot[i]);
rodDepth[i] = rodDepth[i - 1] + rodLength[i];
pressure[i] = pressure[i - 1] + fluidGradient * rodLength[i];
buoyantForce[i] = pressure[i] * (area[i + 1] - area[i]);
rodWeightAir[i] = rodWeightPerFoot[i] * rodLength[i];
rodWeightFluid[i] = rodWeightAir[i] + buoyantForce[i];
}
for (int j = 1; j < nT1; j++)
{
for (int k = j + 1; k < nT1; k++)
{
weightData[j] += rodWeightAir[k]; // how much weight is felt on each taper
}
for (int l = j; j < numTapers; j++)
{
annularForceData[j] += -buoyantForce[l]; //buoyant force exerted on each taper
}
force[j] = (-area[numTapers] * pressure[numTapers]) + weightData[j] - annularForceData[j];
alpha[j] = (force[j] + rodWeightAir[j]) / (rodYM[j] * Math.Pow(10, 6) * area[j]);
stretch[j] = stretch[j - 1] + alpha[j] * rodLength[j] - (rodWeightPerFoot[j] * Math.Pow(rodLength[j], 2)) / (2 * rodYM[j] * Math.Pow(10, 6) * area[j]);
}
for (int m = 1; m < nT1; m++)
{
xOverA[m] = rodLength[m] / a[m];
lagIndexArray[m] = (int)(rodLength[m] / (a[m] * dt));
factorArray[m] = (xOverA[m] - lagIndexArray[m] * dt) / dt;
centerPoint[m] = lagIndexArray[m] + 2;
lengthRequired[m] = 2 * (lagIndexArray[m] + 1) + 1;
}
sumCenterPoint[1] = centerPoint[1];
for (var n = 2; n < numTapers; n++)
{
sumCenterPoint[n] = sumCenterPoint[n - 1] + centerPoint[n] - 1;
}
for (var t = 0; t < nT1; t++)
{
buoyantForceTotal += buoyantForce[t];
rodWeightAirTotal += rodWeightAir[t];
rodWeightFluidTotal += rodWeightFluid[t];
rodDepthTotal += rodLength[t];
annularForceDataTotal += annularForceData[t];
weightDataTotal += weightData[t];
}
}
private double position(int p)
{
//Console.WriteLine ("position({0})", p);
loadBefore = 0;
loadAfter = 0;
loadBefore3 = 0;
loadAfter3 = 0;
//Temporary Variables
double a1 = a[p];
double cd = c[p];
double factor = factorArray[p];
double rodLengthp = rodLength[p];
int lagIndex = lagIndexArray[p];
double Y1 = rodYM[p] * Math.Pow(10, 6);
double A1 = area[p];
int centerOfArray = centerPoint[p];
int iBefore = centerOfArray - lagIndex;
int iAfter = centerOfArray + lagIndex;
double pumpPOS = 0;
//Do work
pumpPOS = Math.Exp((cd * rodLengthp) / (2 * a1)) * (topPosArray[p, iAfter] + factor * (topPosArray[p, iAfter + 1] - topPosArray[p, iAfter]));
pumpPOS += Math.Exp(-(cd * rodLengthp) / (2 * a1)) * (topPosArray[p, iBefore] + factor * (topPosArray[p, iBefore - 1] - topPosArray[p, iBefore]));
pumpPOS = pumpPOS / 2;
double insideIntegral = 0;
int q = 1;
while (q < 2 * lagIndex - 1)
{
insideIntegral += dt * (1 / (Y1 * A1)) * (Math.Exp(-(cd * (lagIndex - q) * dt) / 2) * topLoadArray[p, iBefore + q]);
q++;
}
insideIntegral += 0.5 * dt * (1 / (Y1 * A1)) * (Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore] + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
loadBefore = Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore] + factor * (Math.Exp(-(cd * (lagIndex + 1) * dt) / 2) * topLoadArray[p, iBefore - 1] - Math.Exp(-(cd * lagIndex * dt) / 2) * topLoadArray[p, iBefore]);
loadAfter = Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter] + factor * (Math.Exp(-(cd * (-lagIndex - 1) * dt) / 2) * topLoadArray[p, iAfter + 1] - Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
insideIntegral += 0.5 * factor * dt * (1 / (Y1 * A1)) * (loadBefore + Math.Exp(-(cd * (lagIndex) * dt) / 2) * topLoadArray[p, iBefore]);
insideIntegral += 0.5 * factor * dt * (1 / (Y1 * A1)) * (loadAfter + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topLoadArray[p, iAfter]);
insideIntegral = 0.5 * a1 * insideIntegral;
pumpPOS += insideIntegral;
insideIntegral = 0;
int r = 1;
while (r < 2 * lagIndex - 1)
{
insideIntegral += dt * (Math.Exp(-(cd * lagIndex - r) * dt) / 2) * (topPosArray[p, iBefore + r]);
r++;
}
insideIntegral += 0.5 * dt * (Math.Exp(-(cd * lagIndex * dt) / 2) * topPosArray[p, iBefore] + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
loadBefore3 = Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore] + factor * (Math.Exp(-(cd * (lagIndex + 1) * dt) / 2) * topPosArray[p, iBefore] - Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore]);
loadAfter3 = Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter] + factor * (Math.Exp(-(cd * (-lagIndex - 1) * dt) / 2) * topPosArray[p, iAfter] - Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
insideIntegral += 0.5 * factor * dt * (loadBefore3 + Math.Exp(-(cd * (lagIndex) * dt) / 2) * topPosArray[p, iBefore]);
insideIntegral += 0.5 * factor * dt * (loadAfter3 + Math.Exp(-(cd * (-lagIndex) * dt) / 2) * topPosArray[p, iAfter]);
insideIntegral = -((cd * rodLengthp) / 4) * (0.5 * (cd / (2 * a1))) * insideIntegral;
pumpPOS += insideIntegral;
return pumpPOS;
}
private double load(int s)
{
//Console.WriteLine ("load({0})", s);
//temporary variables
double a1 = a[s];
double cd = c[s];
double rodLengths = rodLength[s];
int lagIndex = lagIndexArray[s];
double Y1 = rodYM[s] * Math.Pow(10, 6);
double A1 = area[s];
int centerOfArray = centerPoint[s];
int iBefore = centerOfArray - lagIndex;
int iAfter = centerOfArray + lagIndex;
double pumpLOAD = 0;
pumpLOAD = 0.5 * (a1 / (Y1 * A1)) * (1 / a1) * (loadBefore + loadAfter);
pumpLOAD += -((cd * rodLengths) / 4) * (0.5 * (cd / (2 * a1))) * (1 / a1) * (loadBefore3 + loadAfter3);
double firstPart = 0;
double pointAfter = (topPosArray[s, iAfter + 1] - topPosArray[s, iAfter - 1]) / (2 * dt);
double pointBefore = (topPosArray[s, iBefore + 1] - topPosArray[s, iBefore - 1]) / (2 * dt);
firstPart = (Math.Exp((cd * rodLengths) / (2 * a1)) * pointAfter - Math.Exp(-(cd * rodLengths) / (2 * a1)) * pointBefore) / (2 * a1);
firstPart += (cd * Math.Exp((cd * rodLengths) / (2 * a1)) * topPosArray[s, iAfter] - cd * Math.Exp((-cd * rodLengths) / (2 * a1)) * topPosArray[s, iBefore]) / (4 * a1);
pumpLOAD = Y1 * A1 * (firstPart + pumpLOAD);
return pumpLOAD;
}
public Tuple<int, double, double> calc(double sPosition, double sLoad)
{
bool useShift = false;
int loadMult = 1;
int tapersAllowed = 1;
double dPosition = 0;
double dLoad = 0;
int status = 0;
for (int ii = 1; ii < lengthRequired[1] + 1; ii++)
{
topPosArray[1, ii - 1] = topPosArray[1, ii];
topLoadArray[1, ii - 1] = topLoadArray[1, ii];
}
topPosArray[1, lengthRequired[1]] = -(sPosition / 12); //stores current position in feet
if (sPosition > sPositionPrevious)
{
topLoadArray[1, lengthRequired[1]] = loadMult * (sLoad - rodWeightFluidTotal) - sbfriction;
}
else
{
topLoadArray[1, lengthRequired[1]] = loadMult * (sLoad - rodWeightFluidTotal) + sbfriction;
}
int j = 1;
while (j <= tapersAllowed)
{
count[j]++;
if (count[j] >= lengthRequired[j])
{
if ((j + 1) <= numTapers)
{
for (int jj = 2; jj < lengthRequired[j + 1] + 1; jj++)
{
topPosArray[j + 1, jj - 1] = topPosArray[j + 1, jj];
topLoadArray[j + 1, jj - 1] = topLoadArray[j + 1, jj];
}
topPosArray[j + 1, lengthRequired[j + 1]] = position(j);
topLoadArray[j + 1, lengthRequired[j + 1]] = load(j);
status = 1 + 4;
}
else
{
if (useShift)
{
dPosition = -12 * (position(j) + stretch[numTapers]);
}
else
{
dPosition = -12 * position(j);
}
dLoad = load(j) + force[numTapers];
status = 1 + 2 + 4;
}
count[j]--;
tapersAllowed += 1;
if (tapersAllowed > numTapers)
{
tapersAllowed = numTapers;
}
}
j++;
}
return Tuple.Create(status, dPosition, dLoad);
}
public void writeSetup(string filename)
{
var csv = new StreamWriter(filename);
csv.AutoFlush = true;
Dictionary<string, string> wellParams = new Dictionary<string, string>();
wellParams.Add("dt", Convert.ToString(dt));
wellParams.Add("tubingHeadPressure", Convert.ToString(tubingHeadPressure));
wellParams.Add("fluidGradient", Convert.ToString(fluidGradient));
wellParams.Add("sbfriction", Convert.ToString(sbfriction));
wellParams.Add("numTapers", Convert.ToString(numTapers));
wellParams.Add("c", ConvertDoubleArray(c));
wellParams.Add("rodLength", ConvertDoubleArray(rodLength));
wellParams.Add("rodDiameter", ConvertDoubleArray(rodDiameter));
wellParams.Add("rodYM", ConvertDoubleArray(rodYM));
wellParams.Add("rodWeightPerFoot", ConvertDoubleArray(rodWeightPerFoot));
wellParams.Add("a", ConvertDoubleArray(a));
wellParams.Add("area", ConvertDoubleArray(area));
wellParams.Add("pressure", ConvertDoubleArray(pressure));
wellParams.Add("buoyantForce", ConvertDoubleArray(buoyantForce));
wellParams.Add("buoyantForceTotal", Convert.ToString(buoyantForceTotal));
wellParams.Add("stretch", ConvertDoubleArray(stretch));
wellParams.Add("weightData", ConvertDoubleArray(weightData));
wellParams.Add("weightDataTotal", Convert.ToString(weightDataTotal));
wellParams.Add("annularForceData", ConvertDoubleArray(annularForceData));
wellParams.Add("annularForceDataTotal", Convert.ToString(annularForceDataTotal));
wellParams.Add("force", ConvertDoubleArray(force));
wellParams.Add("alpha", ConvertDoubleArray(alpha));
wellParams.Add("xOverA", ConvertDoubleArray(xOverA));
wellParams.Add("factorArray", ConvertDoubleArray(factorArray));
wellParams.Add("lagIndexArray", ConvertIntArray(lagIndexArray));
wellParams.Add("centerPoint", ConvertIntArray(centerPoint));
wellParams.Add("sumCenterPoint", ConvertIntArray(sumCenterPoint));
wellParams.Add("lengthRequired", ConvertIntArray(lengthRequired));
wellParams.Add("rodDepth", ConvertDoubleArray(rodDepth));
wellParams.Add("rodDepthTotal", Convert.ToString(rodDepthTotal));
wellParams.Add("rodWeightAir", ConvertDoubleArray(rodWeightAir));
wellParams.Add("rodWeightAirTotal", Convert.ToString(rodWeightAirTotal));
wellParams.Add("rodWeightFluid", ConvertDoubleArray(rodWeightFluid));
wellParams.Add("rodWeightFluidTotal", Convert.ToString(rodWeightFluidTotal));
foreach (string key in wellParams.Keys)
{
var wLine = string.Format("{0},{1}", key, wellParams[key]);
csv.WriteLine(wLine);
}
}
public void clearTopArrays()
{
for (int rowI = 0; rowI < 10; rowI++)
{
for (int colI = 0; colI < 100; colI++)
{
topLoadArray[rowI, colI] = 0;
topPosArray[rowI, colI] = 0;
}
}
}
public void taperCompute(double i_dt, double i_tubingHeadPressure, double i_fluidGradient, double i_sbfriction, int i_numTapers, double[] i_c, double[] i_rodLength, double[] i_rodDiameter, double[] i_rodYM)
{
dt = i_dt;
tubingHeadPressure = i_tubingHeadPressure;
fluidGradient = i_fluidGradient;
sbfriction = i_sbfriction;
numTapers = i_numTapers;
nT1 = numTapers + 1;
c = i_c;
rodLength = i_rodLength;
rodDiameter = i_rodDiameter;
rodYM = i_rodYM;
for (int i = 0; i < 10; i++)
{
rodWeightPerFoot[i] = lookupRodWeightPerFoot(rodYM[i], rodDiameter[i]);
}
UpdateTapers();
}
public void readSetup(string filename)
{
var reader = new StreamReader(File.OpenRead(filename));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
string key = values[0];
switch (key)
{
case "dt":
buf_dt = Convert.ToDouble(values[1]);
break;
case "tubingHeadPressure":
buf_tubingHeadPressure = Convert.ToDouble(values[1]);
break;
case "fluidGradient":
buf_fluidGradient = Convert.ToDouble(values[1]);
break;
case "sbfriction":
buf_sbfriction = Convert.ToDouble(values[1]);
break;
case "numTapers":
buf_numTapers = Convert.ToInt32(values[1]);
break;
case "c":
buf_c = ConvertDoubleString(values[1],10);
break;
case "rodLength":
buf_rodLength = ConvertDoubleString(values[1], 10);
break;
case "rodDiameter":
buf_rodDiameter = ConvertDoubleString(values[1], 10);
break;
case "rodYM":
buf_rodYM = ConvertDoubleString(values[1], 10);
break;
case "rodWeightPerFoot":
buf_rodWeightPerFoot = ConvertDoubleString(values[1], 10);
break;
}
}
}
static double lookupRodWeightPerFoot(double i_ym, double i_diam)
//looks up rod Weight per foot
{
double wtPerFt;
if (i_ym == 30.5)
{
if (i_diam <= 2 && i_diam > 1.75)
{
wtPerFt = 10.7;
}
else if (i_diam <= 1.75 && i_diam > 1.65)
{
wtPerFt = 8.2;
}
else if (i_diam <= 1.65 && i_diam > 1.5)
{
wtPerFt = 7;
}
else if (i_diam <= 1.5 && i_diam > 1.375)
{
wtPerFt = 6;
}
else if (i_diam <= 1.375 && i_diam > 1.125)
{
wtPerFt = 5;
}
else if (i_diam <= 1.125 && i_diam > 1)
{
wtPerFt = 3.676;
}
else if (i_diam <= 1 && i_diam > 0.875)
{
wtPerFt = 2.904;
}
else if (i_diam <= 0.875 && i_diam > 0.75)
{
wtPerFt = 2.224;
}
else if (i_diam <= 0.75 && i_diam > 0.625)
{
wtPerFt = 1.634;
}
else if (i_diam <= 0.625 && i_diam > 0.5)
{
wtPerFt = 1.13;
}
else if (i_diam <= 0.5)
{
wtPerFt = 0.72;
}
else
{
wtPerFt = 0;
}
}
else if (i_ym == 7.2)
{
if (i_diam <= 1.25 && i_diam > 1.125)
{
wtPerFt = 1.2879;
}
else if (i_diam <= 1.125 && i_diam > 1)
{
wtPerFt = 1.09;
}
else if (i_diam <= 1 && i_diam > 0.875)
{
wtPerFt = 0.8188;
}
else if (i_diam <= 0.875 && i_diam > 0.75)
{
wtPerFt = 0.6108;
}
else if (i_diam <= 0.75)
{
wtPerFt = 0.484;
}
else
{
wtPerFt = 0;
}
}
else
{
wtPerFt = 0;
}
return wtPerFt;
}
static string ConvertDoubleArray(double[] array)
{
string result = "";
foreach (double entry in array)
{
result += Convert.ToString(entry) + "&";
}
return result;
}
static string ConvertIntArray(int[] array)
{
string result = "";
foreach (int entry in array)
{
result += Convert.ToString(entry) + "&";
}
return result;
}
static double[] ConvertDoubleString(string inp, int size)
{
//Console.WriteLine("Convert {0}", inp);
string[] sep = new string[] { "&" };
var splt = inp.Split(sep, StringSplitOptions.RemoveEmptyEntries);
int arrSize = splt.Length;
var result = new double[size];
for (var i = 0; i < arrSize; i++)
{
result[i] = Convert.ToDouble(splt[i]);
//Console.WriteLine(result[i]);
}
return result;
}
static int[] ConvertIntString(string inp, int size)
{
string[] sep = new string[] { "&" };
var splt = inp.Split(sep, StringSplitOptions.RemoveEmptyEntries);
int arrSize = splt.Length;
var result = new int[size];
for (var i = 0; i < arrSize; i++)
{
result[i] = Convert.ToInt32(splt[i]);
}
return result;
}
}
}
clear
setwd("C:/Users/Patrick/Dropbox (Henry Pump)/Patrick McDonagh/Customers/Oxy/Downhole Algorithm/Well/Well/Well/bin/Debug")
file.exists(well.dll)
file.exists("well.dll")
dyn.load('well.dll')

View File

@@ -0,0 +1,5 @@
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Well\Well\Well\bin\Debug\Well.dll
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Well\Well\Well\bin\Debug\Well.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Well\Well\Well\obj\x86\Debug\Well.dll
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Well\Well\Well\obj\x86\Debug\Well.pdb
C:\Users\Patrick\Dropbox (Henry Pump)\Patrick McDonagh\Customers\Oxy\Downhole Algorithm\Well\Well\Well\obj\x86\Debug\Well.csprojResolveAssemblyReference.cache

View File

@@ -0,0 +1,8 @@
<Properties StartupItem="Well\WellSetup.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
</Properties>