Database and IO Simulation working
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
|
||||
import de.vandermeer.asciitable.v2.RenderedTable;
|
||||
import de.vandermeer.asciitable.v2.V2_AsciiTable;
|
||||
import de.vandermeer.asciitable.v2.render.V2_AsciiTableRenderer;
|
||||
import de.vandermeer.asciitable.v2.render.WidthAbsoluteEven;
|
||||
import de.vandermeer.asciitable.v2.themes.V2_E_TableThemes;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
@@ -19,8 +24,19 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Well {
|
||||
private String wellName;
|
||||
private double[][] topPosArray = new double[10][100];
|
||||
private double[][] topLoadArray = new double[10][100];
|
||||
protected Simulation sim;
|
||||
protected Database db;
|
||||
|
||||
// IO
|
||||
AnalogIn inclinometer = new AnalogIn(99, 0, 100, 0, 100);
|
||||
AnalogIn loadCell = new AnalogIn(99, 0, 50000, 0, 50000);
|
||||
DigitalOut runCommand = new DigitalOut(7, 0);
|
||||
private double currentPosition;
|
||||
private double currentLoad;
|
||||
|
||||
// CARDS
|
||||
private Card currentCard;
|
||||
private Card[] cardStorage = new Card[100];
|
||||
|
||||
// CONSTANTS
|
||||
private static double YM_STEEL = 30.5;
|
||||
@@ -72,22 +88,62 @@ public class Well {
|
||||
private double rodWeightAirTotal;
|
||||
private double[] rodWeightFluid = new double[11];
|
||||
private double rodWeightFluidTotal;
|
||||
|
||||
|
||||
private double pumpArea;
|
||||
private double tubingCrossSectionalArea;
|
||||
|
||||
// Statuses
|
||||
private int runStatus;
|
||||
public static final int RUNSTATUS_STOPPED = 0;
|
||||
public static final int RUNSTATUS_STARTING = 1;
|
||||
public static final int RUNSTATUS_RUNNING = 2;
|
||||
public static final int RUNSTATUS_PUMPEDOFF = 3;
|
||||
public static final int RUNSTATUS_FAULTED = 4;
|
||||
public static final int RUNSTATUS_LOCKEDOUT = 5;
|
||||
|
||||
private boolean permissiveOK;
|
||||
private long strokesSinceStart = 0;
|
||||
private long startupStrokes = 1;
|
||||
private long strokesToday = 0;
|
||||
private long strokesLifetime;
|
||||
private int pointCounter =0;
|
||||
|
||||
// DIRECTION
|
||||
private static final int DIRECTION_UNKNOWN = 0;
|
||||
private static final int DIRECTION_UP = 1;
|
||||
private static final int DIRECTION_DOWN = 2;
|
||||
private int direction = DIRECTION_UNKNOWN;
|
||||
private int lastDirection = DIRECTION_UNKNOWN;
|
||||
|
||||
// Modes
|
||||
private int runMode;
|
||||
public static final int RUNMODE_POC = 0;
|
||||
public static final int RUNMODE_MANUAL = 1;
|
||||
public static final int RUNMODE_TIMER = 2;
|
||||
|
||||
|
||||
// Intermediate Variables
|
||||
private double[][] topPosArray = new double[10][100];
|
||||
private double[][] topLoadArray = new double[10][100];
|
||||
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;
|
||||
|
||||
Well(String wellName){
|
||||
this.wellName = wellName;
|
||||
db = new Database();
|
||||
strokesLifetime = db.getLastStrokeNum() + 1;
|
||||
currentCard = new Card(strokesLifetime);
|
||||
}
|
||||
|
||||
Well(String wellName, String simFileName){
|
||||
this.wellName = wellName;
|
||||
sim = new Simulation(simFileName);
|
||||
db = new Database();
|
||||
strokesLifetime = db.getLastStrokeNum() + 1;
|
||||
currentCard = new Card(strokesLifetime);
|
||||
}
|
||||
|
||||
public double getDt() {
|
||||
@@ -225,6 +281,76 @@ public class Well {
|
||||
this.structuralRating = structuralRating;
|
||||
}
|
||||
|
||||
public String getWellName() {
|
||||
return wellName;
|
||||
}
|
||||
|
||||
public boolean isPermissiveOK() {
|
||||
return permissiveOK;
|
||||
}
|
||||
|
||||
public int getRunStatus() {
|
||||
return runStatus;
|
||||
}
|
||||
|
||||
public int getRunMode() {
|
||||
return runMode;
|
||||
}
|
||||
|
||||
public double getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
public double getCurrentLoad() {
|
||||
return currentLoad;
|
||||
}
|
||||
|
||||
public long getStartupStrokes() {
|
||||
return startupStrokes;
|
||||
}
|
||||
|
||||
public void setStartupStrokes(long startupStrokes) {
|
||||
this.startupStrokes = startupStrokes;
|
||||
}
|
||||
|
||||
public long getStrokesSinceStart() {
|
||||
return strokesSinceStart;
|
||||
}
|
||||
|
||||
public long getStrokesToday() {
|
||||
return strokesToday;
|
||||
}
|
||||
|
||||
public long getStrokesLifetime() {
|
||||
return strokesLifetime;
|
||||
}
|
||||
|
||||
public int getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
// WELL COMMAND FUNCTIONS
|
||||
public void start(String initiator){
|
||||
if (runStatus == RUNSTATUS_STOPPED && permissiveOK){
|
||||
System.out.println("Starting " + wellName + " from " + initiator + "...");
|
||||
runStatus = RUNSTATUS_STARTING;
|
||||
strokesSinceStart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(String initiator){
|
||||
if (runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING){
|
||||
System.out.println("Stopping " + wellName + " from " + initiator + "...");
|
||||
runStatus = RUNSTATUS_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
public void checkSafeties(){
|
||||
permissiveOK = true;
|
||||
}
|
||||
|
||||
// WELL CALCULATION FUNCTIONS
|
||||
|
||||
public static double lookupRodWeightPerFoot(double i_ym, double i_diam) {
|
||||
double wtPerFt;
|
||||
if (i_ym == YM_STEEL) {
|
||||
@@ -337,29 +463,48 @@ public class Well {
|
||||
}
|
||||
|
||||
public void printTapers(){
|
||||
System.out.println("!!!!!! " + wellName + " !!!!!!");
|
||||
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("Friction Estimate: " + getFrictionEstimate());
|
||||
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("");
|
||||
|
||||
System.out.println("===== " + wellName + " =====");
|
||||
System.out.println("--- INPUT PARAMETERS ---");
|
||||
|
||||
V2_AsciiTable inputTable = new V2_AsciiTable();
|
||||
inputTable.addRule();
|
||||
inputTable.addRow("DeltaT", getDt());
|
||||
inputTable.addStrongRule();
|
||||
inputTable.addRow("Fluid Gradient", getFluidGradient());
|
||||
inputTable.addRow("Pump Diameter", getPumpDiameter());
|
||||
inputTable.addRow("Stuffing Box Friction", getSbfriction());
|
||||
inputTable.addRow("Friction Estimate", getFrictionEstimate());
|
||||
inputTable.addRule();
|
||||
inputTable.addRow("Tubing Anchor Depth", getTubingAnchorDepth());
|
||||
inputTable.addRow("Tubing ID", getTubingID());
|
||||
inputTable.addRow("Tubing OD", getTubingOD());
|
||||
inputTable.addRule();
|
||||
inputTable.addRow("Number of Tapers", getNumTapers());
|
||||
inputTable.addRule();
|
||||
V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer();
|
||||
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
|
||||
rend.setWidth(new WidthAbsoluteEven(50));
|
||||
RenderedTable rt = rend.render(inputTable);
|
||||
System.out.println(rt);
|
||||
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("");
|
||||
V2_AsciiTable taperTable = new V2_AsciiTable();
|
||||
taperTable.addRule();
|
||||
taperTable.addRow("Taper", i);
|
||||
taperTable.addStrongRule();
|
||||
taperTable.addRow("Rod Length", getRodLength(i));
|
||||
taperTable.addRow("Rod Diameter", getRodDiameter(i));
|
||||
taperTable.addRow("Rod Damping Factor", getDampingFactor(i));
|
||||
taperTable.addRow("Rod Material", getRodMaterial(i));
|
||||
taperTable.addRow("Rod Young's Modulus", getRodYM(i));
|
||||
taperTable.addRule();
|
||||
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
|
||||
rend.setWidth(new WidthAbsoluteEven(50));
|
||||
rt = rend.render(taperTable);
|
||||
System.out.println(rt);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
@@ -540,7 +685,7 @@ public class Well {
|
||||
return pumpLOAD;
|
||||
};
|
||||
|
||||
public LPStatus calc(double sPosition, double sLoad){
|
||||
private LPStatus calc(double sPosition, double sLoad){
|
||||
boolean useShift = false;
|
||||
int loadMult = 1;
|
||||
int tapersAllowed = 1;
|
||||
@@ -605,6 +750,104 @@ public class Well {
|
||||
return downholeValues;
|
||||
};
|
||||
|
||||
public void eval(){
|
||||
checkSafeties();
|
||||
currentPosition = inclinometer.readScaled();
|
||||
currentLoad = loadCell.readScaled();
|
||||
LPStatus lastPoint = calc(currentPosition, currentLoad);
|
||||
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
|
||||
if (lastPoint.getStatus() == GOOD_STATUS) {
|
||||
currentCard.setSurfacePosition(pointCounter, currentPosition);
|
||||
currentCard.setSurfaceLoad(pointCounter, currentLoad);
|
||||
currentCard.setDownholePosition(pointCounter, lastPoint.getPosition());
|
||||
currentCard.setDownholeLoad(pointCounter, lastPoint.getLoad());
|
||||
}
|
||||
|
||||
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
|
||||
direction = DIRECTION_UP;
|
||||
else if (inclinometer.getHistory(0) < inclinometer.getHistory(1))
|
||||
direction = DIRECTION_DOWN;
|
||||
|
||||
if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) {
|
||||
currentCard.setNumPointsUsed(pointCounter + 1);
|
||||
currentCard.calcStrokeData(150, fluidGradient,
|
||||
rodDepthTotal, tubingAnchorDepth,
|
||||
tubingCrossSectionalArea, pumpArea,
|
||||
frictionEstimate, structuralRating);
|
||||
for (int j = 98; j >= 0; j--) {
|
||||
cardStorage[j + 1] = cardStorage[j];
|
||||
}
|
||||
cardStorage[0] = currentCard;
|
||||
currentCard.printCard("none", true);
|
||||
System.out.println("Cards in DB: " + db.newCard(currentCard));
|
||||
strokesSinceStart++;
|
||||
strokesToday++;
|
||||
strokesLifetime++;
|
||||
currentCard = new Card(strokesLifetime);
|
||||
pointCounter = -1;
|
||||
if (strokesSinceStart > startupStrokes) {
|
||||
runStatus = RUNSTATUS_RUNNING;
|
||||
}
|
||||
}
|
||||
lastDirection = direction;
|
||||
pointCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
public void eval(int simPoint){
|
||||
checkSafeties();
|
||||
currentPosition = inclinometer.readScaledSim(sim.getPositionAtIndex(simPoint));
|
||||
currentLoad = loadCell.readScaledSim(sim.getLoadAtIndex(simPoint));
|
||||
LPStatus lastPoint = calc(currentPosition, currentLoad);
|
||||
if(runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING) {
|
||||
if (lastPoint.getStatus() == GOOD_STATUS) {
|
||||
currentCard.setSurfacePosition(pointCounter, currentPosition);
|
||||
currentCard.setSurfaceLoad(pointCounter, currentLoad);
|
||||
currentCard.setDownholePosition(pointCounter, lastPoint.getPosition());
|
||||
currentCard.setDownholeLoad(pointCounter, lastPoint.getLoad());
|
||||
}
|
||||
|
||||
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
|
||||
direction = DIRECTION_UP;
|
||||
else if (inclinometer.getHistory(0) < inclinometer.getHistory(1))
|
||||
direction = DIRECTION_DOWN;
|
||||
|
||||
if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) {
|
||||
currentCard.setNumPointsUsed(pointCounter + 1);
|
||||
currentCard.calcStrokeData(150, fluidGradient,
|
||||
rodDepthTotal, tubingAnchorDepth,
|
||||
tubingCrossSectionalArea, pumpArea,
|
||||
frictionEstimate, structuralRating);
|
||||
for (int j = 98; j >= 0; j--) {
|
||||
cardStorage[j + 1] = cardStorage[j];
|
||||
}
|
||||
cardStorage[0] = currentCard;
|
||||
currentCard.printCard("none", true);
|
||||
System.out.println("Cards in DB: " + db.newCard(currentCard));
|
||||
strokesSinceStart++;
|
||||
strokesToday++;
|
||||
strokesLifetime++;
|
||||
currentCard = new Card(strokesLifetime);
|
||||
pointCounter = -1;
|
||||
if (strokesSinceStart > startupStrokes){
|
||||
runStatus = RUNSTATUS_RUNNING;
|
||||
}
|
||||
}
|
||||
lastDirection = direction;
|
||||
pointCounter++;
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_RUNNING || runStatus == RUNSTATUS_STARTING){
|
||||
runCommand.write(1);
|
||||
} else {
|
||||
runCommand.write(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void allOutputsOff(){
|
||||
runCommand.write(0, true);
|
||||
}
|
||||
|
||||
public static void main( String[] args ){
|
||||
Well thisWell = new Well("Barney");
|
||||
thisWell.parseJSONFile(args[0]);
|
||||
|
||||
Reference in New Issue
Block a user