AnalogIn, DigitalIn, DigitalOut, Simulation, and Card classes all working correctly so far
This commit is contained in:
76
src/main/java/com/henrypump/poc/AnalogIn.java
Normal file
76
src/main/java/com/henrypump/poc/AnalogIn.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/1/17.
|
||||
*/
|
||||
|
||||
import mraa.Dir;
|
||||
import mraa.Aio;
|
||||
import mraa.mraa;
|
||||
import mraa.Platform;
|
||||
import mraa.Result;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
|
||||
public class AnalogIn {
|
||||
private int channel;
|
||||
private Aio gpioPin;
|
||||
private double lastValue;
|
||||
private double rawMin;
|
||||
private double rawMax;
|
||||
private double euMin;
|
||||
private double euMax;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
AnalogIn(int channel, double rawMin, double rawMax, double euMin, double euMax){
|
||||
Platform platform = mraa.getPlatformType();
|
||||
if (platform != Platform.INTEL_EDISON_FAB_C) {
|
||||
System.err.println("Error: This program can only be run on edison");
|
||||
System.exit(Result.ERROR_INVALID_PLATFORM.swigValue());
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Aio(this.channel);
|
||||
this.rawMax = rawMax;
|
||||
this.rawMin = rawMin;
|
||||
this.euMax = euMax;
|
||||
this.euMin = euMin;
|
||||
}
|
||||
|
||||
public long readRaw(){
|
||||
return gpioPin.read();
|
||||
}
|
||||
|
||||
public double readScaled(){
|
||||
double pv = ((euMax - euMin)/(rawMax - rawMin)) * gpioPin.read() + (euMax - ((euMax - euMin)/(rawMax - rawMin)) * rawMax);
|
||||
lastValue = pv;
|
||||
return pv;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println("Testing Analog Inputs Inputs...");
|
||||
boolean forceEnd = false;
|
||||
AnalogIn testIn0 = new AnalogIn(0, 0, 1020, 0, 4.6);
|
||||
|
||||
do {
|
||||
try{
|
||||
System.out.println("Raw = " + testIn0.readRaw());
|
||||
System.out.println("Scaled = " + testIn0.readScaled());
|
||||
sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (!forceEnd);
|
||||
}
|
||||
}
|
||||
13
src/main/java/com/henrypump/poc/App.java
Normal file
13
src/main/java/com/henrypump/poc/App.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/henrypump/poc/Card.java
Normal file
53
src/main/java/com/henrypump/poc/Card.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
public class Card {
|
||||
// Card Points
|
||||
private int maxPoints = 1500;
|
||||
private double[] surfacePosition = new double[maxPoints];
|
||||
private double[] downholePosition = new double[maxPoints];
|
||||
private double[] surfaceLoad = new double[maxPoints];
|
||||
private double[] downholeLoad = new double[maxPoints];
|
||||
|
||||
//Card
|
||||
private int strokeNumber;
|
||||
private LPPair surfacePositionMax;
|
||||
|
||||
public void setSurfacePosition(int i, double position){
|
||||
this.surfacePosition[i] = position;
|
||||
};
|
||||
|
||||
public void setDownholePosition(int i, double position){
|
||||
this.downholePosition[i] = position;
|
||||
};
|
||||
|
||||
public void setSurfaceLoad(int i, double load){
|
||||
this.surfaceLoad[i] = load;
|
||||
};
|
||||
|
||||
public void setDownholeLoad(int i, double load){
|
||||
this.downholeLoad[i] = load;
|
||||
};
|
||||
|
||||
public double[] getSurfacePosition() {
|
||||
return this.surfacePosition;
|
||||
}
|
||||
|
||||
public double[] getDownholePosition() {
|
||||
return this.downholePosition;
|
||||
}
|
||||
|
||||
public double[] getSurfaceLoad() {
|
||||
return this.surfaceLoad;
|
||||
}
|
||||
|
||||
public double[] getDownholeLoad() {
|
||||
return this.downholeLoad;
|
||||
}
|
||||
|
||||
public LPPair getSurfacePositionMax() {
|
||||
return this.surfacePositionMax;
|
||||
}
|
||||
}
|
||||
96
src/main/java/com/henrypump/poc/DigitalIn.java
Normal file
96
src/main/java/com/henrypump/poc/DigitalIn.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Petre Eftime <petre.p.eftime@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.mraa;
|
||||
import mraa.Platform;
|
||||
import mraa.Result;
|
||||
|
||||
public class DigitalIn {
|
||||
private int channel;
|
||||
private Gpio gpioPin;
|
||||
private int lastValue;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
DigitalIn(int channel){
|
||||
Platform platform = mraa.getPlatformType();
|
||||
|
||||
if (platform != Platform.INTEL_EDISON_FAB_C) {
|
||||
System.err.println("Error: This program can only be run on edison");
|
||||
System.exit(Result.ERROR_INVALID_PLATFORM.swigValue());
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_IN);
|
||||
}
|
||||
|
||||
public int read(){
|
||||
lastValue = gpioPin.read();
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println("Testing Digital Inputs. Script will loop until ch8 and ch9 both equal 1");
|
||||
boolean forceEnd = false;
|
||||
DigitalIn testIn8 = new DigitalIn(8);
|
||||
DigitalIn testIn9 = new DigitalIn(9);
|
||||
|
||||
DigitalOut testOut2 = new DigitalOut(2);
|
||||
DigitalOut testOut3 = new DigitalOut(3);
|
||||
|
||||
int in8val, in9val;
|
||||
do {
|
||||
in8val = testIn8.read();
|
||||
in9val = testIn9.read();
|
||||
|
||||
testOut2.write(in8val);
|
||||
testOut3.write(in9val);
|
||||
|
||||
if (in8val == 1 && in9val == 1) forceEnd = true;
|
||||
testOut2.write(0);
|
||||
testOut3.write(0);
|
||||
} while (!forceEnd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
84
src/main/java/com/henrypump/poc/DigitalOut.java
Normal file
84
src/main/java/com/henrypump/poc/DigitalOut.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/1/17.
|
||||
*/
|
||||
|
||||
import mraa.Dir;
|
||||
import mraa.Gpio;
|
||||
import mraa.mraa;
|
||||
import mraa.Platform;
|
||||
import mraa.Result;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
public class DigitalOut {
|
||||
private int channel;
|
||||
private Gpio gpioPin;
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("mraajava");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println(
|
||||
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||
e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
DigitalOut(int channel){
|
||||
Platform platform = mraa.getPlatformType();
|
||||
|
||||
if (platform != Platform.INTEL_EDISON_FAB_C) {
|
||||
System.err.println("Error: This program can only be run on edison");
|
||||
System.exit(Result.ERROR_INVALID_PLATFORM.swigValue());
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_OUT);
|
||||
}
|
||||
|
||||
public void write(int writeVal){
|
||||
gpioPin.write(writeVal);
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
DigitalOut testOut2 = new DigitalOut(2);
|
||||
testOut2.write(1);
|
||||
sleep(500);
|
||||
testOut2.write(0);
|
||||
|
||||
DigitalOut testOut3 = new DigitalOut(3);
|
||||
testOut3.write(1);
|
||||
sleep(500);
|
||||
testOut3.write(0);
|
||||
|
||||
DigitalOut testOut4 = new DigitalOut(4);
|
||||
testOut4.write(1);
|
||||
sleep(500);
|
||||
testOut4.write(0);
|
||||
|
||||
DigitalOut testOut5 = new DigitalOut(5);
|
||||
testOut5.write(1);
|
||||
sleep(500);
|
||||
testOut5.write(0);
|
||||
|
||||
DigitalOut testOut6 = new DigitalOut(6);
|
||||
testOut6.write(1);
|
||||
sleep(500);
|
||||
testOut6.write(0);
|
||||
|
||||
DigitalOut testOut7 = new DigitalOut(7);
|
||||
testOut7.write(1);
|
||||
sleep(500);
|
||||
testOut7.write(0);
|
||||
|
||||
} catch(InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
23
src/main/java/com/henrypump/poc/LPPair.java
Normal file
23
src/main/java/com/henrypump/poc/LPPair.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
public class LPPair {
|
||||
private double position;
|
||||
private double load;
|
||||
|
||||
public LPPair(double position, double load){
|
||||
this.position = position;
|
||||
this.load = load;
|
||||
};
|
||||
|
||||
public double getPosition(){
|
||||
return this.position;
|
||||
};
|
||||
|
||||
public double getLoad(){
|
||||
return this.load;
|
||||
};
|
||||
|
||||
}
|
||||
17
src/main/java/com/henrypump/poc/LPStatus.java
Normal file
17
src/main/java/com/henrypump/poc/LPStatus.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
public class LPStatus extends LPPair{
|
||||
private int status;
|
||||
|
||||
public LPStatus(double position, double load, int status) {
|
||||
super(position, load);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
8
src/main/java/com/henrypump/poc/POC.java
Normal file
8
src/main/java/com/henrypump/poc/POC.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/1/17.
|
||||
*/
|
||||
public class POC {
|
||||
|
||||
}
|
||||
72
src/main/java/com/henrypump/poc/Simulation.java
Normal file
72
src/main/java/com/henrypump/poc/Simulation.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/1/17.
|
||||
*/
|
||||
public class Simulation {
|
||||
|
||||
private double[] position = new double[1000];
|
||||
private double[] load = new double[1000];
|
||||
private int lastFilledIndex = 0;
|
||||
|
||||
private void parseCSV(String filename){
|
||||
BufferedReader br = null;
|
||||
String line = "";
|
||||
String cvsSplitBy = ",";
|
||||
int lineNum = 0;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(filename));
|
||||
while ((line = br.readLine()) != null) {
|
||||
// use comma as separator
|
||||
String[] splitLine = line.split(cvsSplitBy);
|
||||
position[lineNum] = Double.parseDouble(splitLine[0]);
|
||||
load[lineNum] = Double.parseDouble(splitLine[1]);
|
||||
lineNum++;
|
||||
}
|
||||
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
if (br != null) {
|
||||
lastFilledIndex = lineNum - 1;
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double positionAtIndex(int ind){
|
||||
return position[ind];
|
||||
}
|
||||
|
||||
public double loadAtIndex(int ind){
|
||||
return load[ind];
|
||||
}
|
||||
|
||||
Simulation(String simFilePath){
|
||||
parseCSV(simFilePath);
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
Simulation sim = new Simulation(args[0]);
|
||||
for(int i = 0; i <= sim.lastFilledIndex; i++){
|
||||
System.out.println("Position: " + sim.positionAtIndex(i) + ", Load: "+ sim.loadAtIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
595
src/main/java/com/henrypump/poc/Well.java
Normal file
595
src/main/java/com/henrypump/poc/Well.java
Normal file
@@ -0,0 +1,595 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.pow;
|
||||
import static java.lang.Math.sqrt;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 1/31/17.
|
||||
*/
|
||||
public class Well {
|
||||
private double[][] topPosArray = new double[10][100];
|
||||
private double[][] topLoadArray = new double[10][100];
|
||||
|
||||
// CONSTANTS
|
||||
private static double YM_STEEL = 30.5;
|
||||
private static double YM_FIBERGLASS = 7.2;
|
||||
private static final int BAD_STATUS = 0;
|
||||
private static final int GOOD_STATUS = 0;
|
||||
|
||||
// USER INPUTS
|
||||
private double dt;
|
||||
private double tubingHeadPressure;
|
||||
private double fluidGradient;
|
||||
private double sbfriction;
|
||||
private int numTapers;
|
||||
private double tubingAnchorDepth;
|
||||
private double pumpDiameter;
|
||||
private double tubingID, tubingOD;
|
||||
private double structuralRating;
|
||||
private double[] c = new double[11];
|
||||
private double[] rodLength = new double[11];
|
||||
private double[] rodDiameter = new double[11];
|
||||
private double[] rodYM = new double[11];
|
||||
private double[] rodWeightPerFoot = new double[11];
|
||||
|
||||
|
||||
// CALCULATED TAPER PARAMETERS
|
||||
private int nT1; // should always be equal to number of tapers + 1
|
||||
private double frictionEstimate;
|
||||
private double theoreticalMaxFluidLoad;
|
||||
private double[] a = new double[11];
|
||||
private double[] area = new double[11];
|
||||
private double[] pressure = new double[11];
|
||||
private double[] buoyantForce = new double[11];
|
||||
private double buoyantForceTotal;
|
||||
private double[] stretch = new double[11];
|
||||
private double[] weightData = new double[11];
|
||||
private double weightDataTotal;
|
||||
private double[] annularForceData = new double[11];
|
||||
private double annularForceDataTotal;
|
||||
private double[] force = new double[11];
|
||||
private double[] alpha = new double[11];
|
||||
private double[] xOverA = new double[11];
|
||||
private double[] factor = new double[11];
|
||||
private int[] lagIndex = new int[11];
|
||||
private int[] lengthRequired = new int[11];
|
||||
private int[] centerPoint = new int[11];
|
||||
private double[] rodDepth = new double[11];
|
||||
private double rodDepthTotal;
|
||||
private double[] rodWeightAir = new double[11];
|
||||
private double rodWeightAirTotal;
|
||||
private double[] rodWeightFluid = new double[11];
|
||||
private double rodWeightFluidTotal;
|
||||
|
||||
|
||||
private double pumpArea;
|
||||
private double tubingCrossSectionalArea;
|
||||
|
||||
// Intermediate Variables
|
||||
private double loadBefore = 0.0;
|
||||
private double loadAfter = 0.0;
|
||||
private double loadBefore3 = 0.0;
|
||||
private double loadAfter3 = 0.0;
|
||||
|
||||
private int[] count = new int[11];
|
||||
private double sPositionPrevious;
|
||||
|
||||
public double getDt() {
|
||||
return dt;
|
||||
}
|
||||
|
||||
public void setDt(double dt) {
|
||||
this.dt = dt;
|
||||
}
|
||||
|
||||
public double getTubingHeadPressure() {
|
||||
return tubingHeadPressure;
|
||||
}
|
||||
|
||||
public void setTubingHeadPressure(double tubingHeadPressure) {
|
||||
this.tubingHeadPressure = tubingHeadPressure;
|
||||
}
|
||||
|
||||
public double getFluidGradient() {
|
||||
return fluidGradient;
|
||||
}
|
||||
|
||||
public void setFluidGradient(double fluidGradient) {
|
||||
this.fluidGradient = fluidGradient;
|
||||
}
|
||||
|
||||
public double getSbfriction() {
|
||||
return sbfriction;
|
||||
}
|
||||
|
||||
public void setSbfriction(double sbfriction) {
|
||||
this.sbfriction = sbfriction;
|
||||
}
|
||||
|
||||
public int getNumTapers() {
|
||||
return numTapers;
|
||||
}
|
||||
|
||||
public void setNumTapers(int numTapers) {
|
||||
this.numTapers = numTapers;
|
||||
}
|
||||
|
||||
public double getTubingAnchorDepth() {
|
||||
return tubingAnchorDepth;
|
||||
}
|
||||
|
||||
public void setTubingAnchorDepth(double tubingAnchorDepth) {
|
||||
this.tubingAnchorDepth = tubingAnchorDepth;
|
||||
}
|
||||
|
||||
public double getPumpDiameter() {
|
||||
return pumpDiameter;
|
||||
}
|
||||
|
||||
public void setPumpDiameter(double pumpDiameter) {
|
||||
this.pumpDiameter = pumpDiameter;
|
||||
this.pumpArea = pow(pumpDiameter, 2) * Math.PI;
|
||||
}
|
||||
|
||||
public double getTubingID() {
|
||||
return tubingID;
|
||||
}
|
||||
|
||||
public void setTubingID(double tubingID) {
|
||||
this.tubingID = tubingID;
|
||||
this.tubingCrossSectionalArea = (Math.PI / 4) * (pow(this.tubingOD, 2) - pow(this.tubingID,2));
|
||||
}
|
||||
|
||||
public double getTubingOD() {
|
||||
return tubingOD;
|
||||
}
|
||||
|
||||
public void setTubingOD(double tubingOD) {
|
||||
this.tubingOD = tubingOD;
|
||||
this.tubingCrossSectionalArea = (Math.PI / 4) * (pow(this.tubingOD, 2) - pow(tubingID,2));
|
||||
|
||||
}
|
||||
|
||||
public void setDampingFactor(int i, double c) {
|
||||
this.c[i] = c;
|
||||
}
|
||||
|
||||
public double getDampingFactor(int i){ return c[i]; }
|
||||
|
||||
public void setRodLength(int i, double rodLength) {
|
||||
this.rodLength[i] = rodLength;
|
||||
}
|
||||
|
||||
public double getRodLength(int i){ return rodLength[i]; }
|
||||
|
||||
public void setRodDiameter(int i, double rodDiameter) {
|
||||
this.rodDiameter[i] = rodDiameter;
|
||||
}
|
||||
|
||||
public double getRodDiameter(int i){ return rodDiameter[i]; }
|
||||
|
||||
public void setRodYM(int i, String material) {
|
||||
|
||||
if (material.toLowerCase().equals("steel")) rodYM[i] = YM_STEEL;
|
||||
else if (material.toLowerCase().equals("fiberglass")) rodYM[i] = YM_FIBERGLASS;
|
||||
|
||||
}
|
||||
|
||||
public double getRodYM(int i){ return rodYM[i]; }
|
||||
|
||||
public String getRodMaterial(int i){
|
||||
if(rodYM[i] == YM_STEEL)
|
||||
return "steel";
|
||||
if(rodYM[i] == YM_FIBERGLASS)
|
||||
return "fiberglass";
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public double getStructuralRating() {
|
||||
return structuralRating;
|
||||
}
|
||||
|
||||
public void setStructuralRating(double structuralRating) {
|
||||
this.structuralRating = structuralRating;
|
||||
}
|
||||
|
||||
public static double lookupRodWeightPerFoot(double i_ym, double i_diam) {
|
||||
double wtPerFt;
|
||||
if (i_ym == YM_STEEL) {
|
||||
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 == YM_FIBERGLASS) {
|
||||
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;
|
||||
};
|
||||
|
||||
public void parseJSONFile(String jsonFilename){
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
Object obj = parser.parse(new FileReader(jsonFilename));
|
||||
JSONObject well = (JSONObject) obj;
|
||||
|
||||
Object newDeltaT = well.get("deltaT");
|
||||
if (newDeltaT != null) dt = (Double) newDeltaT;
|
||||
|
||||
Object newPumpDiameter = well.get("pumpDiameter");
|
||||
if (newPumpDiameter != null) setPumpDiameter((Double) newPumpDiameter);
|
||||
|
||||
Object newFluidGradient = well.get("fluidGradient");
|
||||
if (newFluidGradient != null) fluidGradient = (Double) newFluidGradient;
|
||||
|
||||
Object newTubingID = well.get("tubingID");
|
||||
if (newTubingID != null) setTubingID((Double) newTubingID);
|
||||
|
||||
Object newTubingOD = well.get("tubingOD");
|
||||
if (newTubingOD != null) setTubingOD((Double) newTubingOD);
|
||||
|
||||
Object newTubingAnchorDepth = well.get("tubingAnchorDepth");
|
||||
if (newTubingAnchorDepth != null) tubingAnchorDepth = (Double) newTubingAnchorDepth;
|
||||
|
||||
Object newStructuralRating = well.get("structuralRating");
|
||||
if (newStructuralRating != null) structuralRating = (Double) newStructuralRating;
|
||||
|
||||
Object newStuffingBoxFriction = well.get("stuffingBoxFriction");
|
||||
if (newStuffingBoxFriction != null) setSbfriction((Double) newStuffingBoxFriction);
|
||||
|
||||
Object newTubingHeadPressure = well.get("tubingOD");
|
||||
if (newTubingHeadPressure != null) setTubingOD((Double) newTubingHeadPressure);
|
||||
|
||||
JSONArray tapers = (JSONArray) well.get("tapers");
|
||||
numTapers = tapers.size();
|
||||
for (int i = 0; i < numTapers; i++){
|
||||
int currentTaperNum = i + 1;
|
||||
JSONObject taperObj = (JSONObject) tapers.get(i);
|
||||
|
||||
Object newLength = taperObj.get("length");
|
||||
if (newLength != null) setRodLength(currentTaperNum, (Double) newLength);
|
||||
|
||||
Object newDiameter = taperObj.get("diameter");
|
||||
if (newDiameter != null) setRodDiameter(currentTaperNum, (Double) newDiameter);
|
||||
|
||||
Object newMaterial = taperObj.get("material");
|
||||
System.out.println("found material " + (String) newMaterial);
|
||||
if (newMaterial != null) setRodYM(currentTaperNum, (String) newMaterial);
|
||||
|
||||
Object newDampingFactor = taperObj.get("dampingFactor");
|
||||
if (newDampingFactor != null) setDampingFactor(currentTaperNum, (Double) newDampingFactor);
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void printTapers(){
|
||||
System.out.println("=== INPUT PARAMETERS ===");
|
||||
System.out.println("DeltaT: " + getDt());
|
||||
System.out.println("Fluid Gradient: " + getFluidGradient());
|
||||
System.out.println("Pump Diameter: " + getPumpDiameter());
|
||||
System.out.println("Stuffing Box Friction: " + getSbfriction());
|
||||
System.out.println("Structural Rating: " + getStructuralRating());
|
||||
System.out.println("Tubing Anchor Depth: " + getTubingAnchorDepth());
|
||||
System.out.println("Tubing Head Pressure: " + getTubingHeadPressure());
|
||||
System.out.println("Tubing ID: " + getTubingID());
|
||||
System.out.println("Tubing OD: " + getTubingOD());
|
||||
System.out.println("Number of Tapers: " + getNumTapers());
|
||||
System.out.println("");
|
||||
|
||||
for(int i = 1; i <= numTapers; i++){
|
||||
System.out.printf("=== Taper %d === \n", i);
|
||||
System.out.println("Rod Length: " + getRodLength(i));
|
||||
System.out.println("Rod Diameter: " + getRodDiameter(i));
|
||||
System.out.println("Rod Damping Factor: " + getDampingFactor(i));
|
||||
System.out.println("Rod Material: " + getRodMaterial(i));
|
||||
System.out.println("Rod Young's Modulus: " + getRodYM(i));
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
public void updateTapers(){
|
||||
nT1 = numTapers + 1;
|
||||
|
||||
// start by setting everything to 0
|
||||
a[0] = 0.0;
|
||||
area[0] = 0.0;
|
||||
area[numTapers + 1] = 0.0;
|
||||
pressure[0] = tubingHeadPressure;
|
||||
buoyantForce[0] = 0.0;
|
||||
stretch[0] = 0.0;
|
||||
weightData[0] = 0.0;
|
||||
annularForceData[0] = 0.0;
|
||||
force[0] = 0.0;
|
||||
alpha[0] = 0.0;
|
||||
xOverA[0] = 0.0;
|
||||
factor[0] = 0.0;
|
||||
lagIndex[0] = 0;
|
||||
lengthRequired[0] = 0;
|
||||
centerPoint[0] = 0;
|
||||
rodDepth[0] = 0.0;
|
||||
rodWeightAir[0] = 0.0;
|
||||
rodWeightFluid[0] = 0.0;
|
||||
buoyantForceTotal = 0.0;
|
||||
weightDataTotal = 0.0;
|
||||
annularForceDataTotal = 0.0;
|
||||
rodDepthTotal = 0.0;
|
||||
rodWeightAirTotal = 0.0;
|
||||
rodWeightFluidTotal = 0.0;
|
||||
|
||||
for(int i = 1; i < nT1; i++){
|
||||
rodWeightPerFoot[i] = lookupRodWeightPerFoot(rodYM[i], rodDiameter[i]);
|
||||
}
|
||||
|
||||
for (int area_i = 1; area_i < nT1; area_i++)
|
||||
{
|
||||
area[area_i] = (Math.PI / 4) * pow(rodDiameter[area_i], 2);
|
||||
}
|
||||
|
||||
for (int i = 1; i < nT1; i++)
|
||||
{
|
||||
a[i] = 1000 * 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; l < numTapers; l++)
|
||||
{
|
||||
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] * pow(10, 6) * area[j]);
|
||||
stretch[j] = (stretch[j - 1] + (alpha[j] * rodLength[j])) - ((rodWeightPerFoot[j] * pow(rodLength[j], 2)) / (2 * rodYM[j] * pow(10, 6) * area[j]));
|
||||
}
|
||||
|
||||
for (int m = 1; m < nT1; m++)
|
||||
{
|
||||
xOverA[m] = rodLength[m] / a[m];
|
||||
lagIndex[m] = (int)(rodLength[m] / (a[m] * dt));
|
||||
factor[m] = (xOverA[m] - lagIndex[m] * dt) / dt;
|
||||
centerPoint[m] = lagIndex[m] + 2;
|
||||
lengthRequired[m] = 2 * (lagIndex[m] + 1) + 1;
|
||||
}
|
||||
|
||||
for (int t = 0; t < nT1; t++)
|
||||
{
|
||||
buoyantForceTotal += buoyantForce[t];
|
||||
rodWeightAirTotal += rodWeightAir[t];
|
||||
rodWeightFluidTotal += rodWeightFluid[t];
|
||||
rodDepthTotal += rodLength[t];
|
||||
annularForceDataTotal += annularForceData[t];
|
||||
weightDataTotal += weightData[t];
|
||||
}
|
||||
|
||||
theoreticalMaxFluidLoad = fluidGradient* rodDepthTotal* pumpArea;
|
||||
frictionEstimate = 0.10 * rodDepthTotal;
|
||||
}
|
||||
|
||||
private double position(int p)
|
||||
//generate the downhole position of the given rod part
|
||||
{
|
||||
loadBefore = 0;
|
||||
loadAfter = 0;
|
||||
loadBefore3 = 0;
|
||||
loadAfter3 = 0;
|
||||
|
||||
//Temporary Variables
|
||||
double a1 = a[p];
|
||||
double cd = c[p];
|
||||
double fact = factor[p];
|
||||
double rodLengthp = rodLength[p];
|
||||
int lagInd = lagIndex[p];
|
||||
double Y1 = rodYM[p] * pow(10, 6);
|
||||
double A1 = area[p];
|
||||
int centerOfArray = centerPoint[p];
|
||||
|
||||
int iBefore = centerOfArray - lagInd;
|
||||
int iAfter = centerOfArray + lagInd;
|
||||
|
||||
double pumpPOS = 0;
|
||||
//Do work
|
||||
pumpPOS = exp((cd * rodLengthp) / (2 * a1)) * (topPosArray[p][iAfter] + fact * (topPosArray[p][ iAfter + 1] - topPosArray[p][iAfter]));
|
||||
pumpPOS += exp(-(cd * rodLengthp) / (2 * a1)) * (topPosArray[p][iBefore] + fact * (topPosArray[p][iBefore - 1] - topPosArray[p][iBefore]));
|
||||
pumpPOS = pumpPOS / 2;
|
||||
double insideIntegral = 0;
|
||||
int q = 1;
|
||||
while (q < 2 * lagInd - 1)
|
||||
{
|
||||
insideIntegral += dt * (1 / (Y1 * A1)) * (exp(-(cd * (lagInd - q) * dt) / 2) * topLoadArray[p][iBefore + q]);
|
||||
q++;
|
||||
}
|
||||
insideIntegral += 0.5 * dt * (1 / (Y1 * A1)) * (exp(-(cd * lagInd * dt) / 2) * topLoadArray[p][iBefore] + exp(-(cd * (-lagInd) * dt) / 2) * topLoadArray[p][iAfter]);
|
||||
|
||||
loadBefore = exp(-(cd * lagInd * dt) / 2) * topLoadArray[p][iBefore] + fact * (exp(-(cd * (lagInd + 1) * dt) / 2) * topLoadArray[p][iBefore - 1] - exp(-(cd * lagInd * dt) / 2) * topLoadArray[p][iBefore]);
|
||||
loadAfter = exp(-(cd * (-lagInd) * dt) / 2) * topLoadArray[p][iAfter] + fact * (exp(-(cd * (-lagInd - 1) * dt) / 2) * topLoadArray[p][iAfter + 1] - exp(-(cd * (-lagInd) * dt) / 2) * topLoadArray[p][iAfter]);
|
||||
insideIntegral += 0.5 * fact * dt * (1 / (Y1 * A1)) * (loadBefore + exp(-(cd * (lagInd) * dt) / 2) * topLoadArray[p][iBefore]);
|
||||
insideIntegral += 0.5 * fact * dt * (1 / (Y1 * A1)) * (loadAfter + exp(-(cd * (-lagInd) * dt) / 2) * topLoadArray[p][iAfter]);
|
||||
insideIntegral = 0.5 * a1 * insideIntegral;
|
||||
pumpPOS += insideIntegral;
|
||||
|
||||
insideIntegral = 0;
|
||||
int r = 1;
|
||||
while (r < 2 * lagInd - 1)
|
||||
{
|
||||
insideIntegral += dt * (exp(-(cd * lagInd - r) * dt) / 2) * (topPosArray[p][iBefore + r]);
|
||||
r++;
|
||||
}
|
||||
insideIntegral += 0.5 * dt * (exp(-(cd * lagInd * dt) / 2) * topPosArray[p][iBefore] + exp(-(cd * (-lagInd) * dt) / 2) * topPosArray[p][iAfter]);
|
||||
loadBefore3 = exp(-(cd * (lagInd) * dt) / 2) * topPosArray[p][iBefore] + fact * (exp(-(cd * (lagInd + 1) * dt) / 2) * topPosArray[p][iBefore] - exp(-(cd * (lagInd) * dt) / 2) * topPosArray[p][iBefore]);
|
||||
loadAfter3 = exp(-(cd * (-lagInd) * dt) / 2) * topPosArray[p][iAfter] + fact * (exp(-(cd * (-lagInd - 1) * dt) / 2) * topPosArray[p][iAfter] - exp(-(cd * (-lagInd) * dt) / 2) * topPosArray[p][iAfter]);
|
||||
insideIntegral += 0.5 * fact * dt * (loadBefore3 + exp(-(cd * (lagInd) * dt) / 2) * topPosArray[p][iBefore]);
|
||||
insideIntegral += 0.5 * fact * dt * (loadAfter3 + exp(-(cd * (-lagInd) * dt) / 2) * topPosArray[p][iAfter]);
|
||||
insideIntegral = -((cd * rodLengthp) / 4) * (0.5 * (cd / (2 * a1))) * insideIntegral;
|
||||
pumpPOS += insideIntegral;
|
||||
//printf("Position: %f\n", pumpPOS);
|
||||
return pumpPOS;
|
||||
};
|
||||
|
||||
|
||||
private double load(int s)
|
||||
//calculate the downhole load of the given rod part
|
||||
{
|
||||
//temporary variables
|
||||
double a1 = a[s];
|
||||
double cd = c[s];
|
||||
double rodLengths = rodLength[s];
|
||||
int lagInd = lagIndex[s];
|
||||
double Y1 = rodYM[s] * pow(10, 6);
|
||||
double A1 = area[s];
|
||||
int centerOfArray = centerPoint[s];
|
||||
|
||||
int iBefore = centerOfArray - lagInd;
|
||||
int iAfter = centerOfArray + lagInd;
|
||||
|
||||
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 = (exp((cd * rodLengths) / (2 * a1)) * pointAfter - exp(-(cd * rodLengths) / (2 * a1)) * pointBefore) / (2 * a1);
|
||||
firstPart += (cd * exp((cd * rodLengths) / (2 * a1)) * topPosArray[s][iAfter] - cd * exp((-cd * rodLengths) / (2 * a1)) * topPosArray[s][iBefore]) / (4 * a1);
|
||||
pumpLOAD = Y1 * A1 * (firstPart + pumpLOAD);
|
||||
//printf("Load: %f\n", pumpLOAD);
|
||||
return pumpLOAD;
|
||||
};
|
||||
|
||||
public LPStatus calc(double sPosition, double sLoad){
|
||||
boolean useShift = false;
|
||||
int loadMult = 1;
|
||||
int tapersAllowed = 1;
|
||||
double dPosition = 0;
|
||||
double dLoad = 0;
|
||||
int status = BAD_STATUS;
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (useShift)
|
||||
{
|
||||
dPosition = -12 * (position(j) + stretch[numTapers]);
|
||||
}
|
||||
else
|
||||
{
|
||||
dPosition = -12 * position(j);
|
||||
}
|
||||
dLoad = load(j) + force[numTapers];
|
||||
status = GOOD_STATUS;
|
||||
}
|
||||
count[j]--;
|
||||
tapersAllowed += 1;
|
||||
if (tapersAllowed > numTapers)
|
||||
{
|
||||
tapersAllowed = numTapers;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
LPStatus downholeValues = new LPStatus(dPosition, dLoad, status);
|
||||
return downholeValues;
|
||||
};
|
||||
|
||||
public static void main( String[] args ){
|
||||
Well thisWell = new Well();
|
||||
thisWell.parseJSONFile(args[0]);
|
||||
// thisWell.parseJSONFile("/Users/patrickjmcd/Henry_Pump/poc-java/wellSetup.json");
|
||||
thisWell.printTapers();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user