Database and IO Simulation working
This commit is contained in:
@@ -21,6 +21,7 @@ public class AnalogIn {
|
||||
private double rawMax;
|
||||
private double euMin;
|
||||
private double euMax;
|
||||
private double[] history = new double[100];
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -34,20 +35,26 @@ public class AnalogIn {
|
||||
}
|
||||
|
||||
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;
|
||||
if (channel != 99) {
|
||||
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.gpioPin = new Aio(this.channel);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Aio(this.channel);
|
||||
this.rawMax = rawMax;
|
||||
this.rawMin = rawMin;
|
||||
this.euMax = euMax;
|
||||
this.euMin = euMin;
|
||||
}
|
||||
|
||||
public double getHistory(int pointIndex) {
|
||||
return history[pointIndex];
|
||||
}
|
||||
|
||||
public long readRaw(){
|
||||
return gpioPin.read();
|
||||
}
|
||||
@@ -55,6 +62,20 @@ public class AnalogIn {
|
||||
public double readScaled(){
|
||||
double pv = ((euMax - euMin)/(rawMax - rawMin)) * gpioPin.read() + (euMax - ((euMax - euMin)/(rawMax - rawMin)) * rawMax);
|
||||
lastValue = pv;
|
||||
for(int i = 98; i >= 0; i--){
|
||||
history[i+1] = history[i];
|
||||
}
|
||||
history[0] = lastValue;
|
||||
return pv;
|
||||
}
|
||||
|
||||
public double readScaledSim(double simRaw){
|
||||
double pv = ((euMax - euMin)/(rawMax - rawMin)) * simRaw + (euMax - ((euMax - euMin)/(rawMax - rawMin)) * rawMax);
|
||||
lastValue = pv;
|
||||
for(int i = 98; i >= 0; i--){
|
||||
history[i+1] = history[i];
|
||||
}
|
||||
history[0] = lastValue;
|
||||
return pv;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Card {
|
||||
private int numPointsUsed;
|
||||
|
||||
//Card
|
||||
private int strokeNumber;
|
||||
private long strokeNumber;
|
||||
private LPPair surfacePositionMax;
|
||||
private LPPair surfacePositionMin;
|
||||
private LPPair surfaceLoadMax;
|
||||
@@ -57,7 +57,7 @@ public class Card {
|
||||
|
||||
private long strokeStartTime;
|
||||
|
||||
Card(int strokeNumber){
|
||||
Card(long strokeNumber){
|
||||
this.strokeNumber = strokeNumber;
|
||||
strokeStartTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class Card {
|
||||
return this.surfacePositionMax;
|
||||
}
|
||||
|
||||
public int getStrokeNumber() {
|
||||
public long getStrokeNumber() {
|
||||
return strokeNumber;
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ public class Card {
|
||||
if (fillageCalculated > 100)
|
||||
fillageCalculated = 100.0;
|
||||
|
||||
fluidLoad = (downholeLoadMax.getLoad() - downholeLoadMin.getLoad()) - frictionEstimate;
|
||||
fluidLoad = downholeLoadSpan - frictionEstimate;
|
||||
pumpIntakePressure = fluidGradient * rodDepth - (fluidLoad / pumpArea);
|
||||
//printf("PIP = %f * %f - (%f / %f) = %f\n", fluidGradient, rodDepth, fluidLoad, pumpArea, pumpIntakePressure);
|
||||
fluidLevel = pumpIntakePressure / fluidGradient;
|
||||
|
||||
75
src/main/java/com/henrypump/poc/Database.java
Normal file
75
src/main/java/com/henrypump/poc/Database.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/2/17.
|
||||
*/
|
||||
|
||||
import com.mongodb.*;
|
||||
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
import com.mongodb.client.model.Sorts;
|
||||
import org.bson.Document;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.mongodb.client.MongoCursor;
|
||||
|
||||
import static com.mongodb.client.model.Aggregates.limit;
|
||||
import static com.mongodb.client.model.Filters.*;
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
import static com.mongodb.client.model.Updates.*;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class Database {
|
||||
private String pocDatabase = "poc";
|
||||
private MongoClient mongoClient;
|
||||
private MongoDatabase database;
|
||||
|
||||
Database(){
|
||||
mongoClient = new MongoClient();
|
||||
database = mongoClient.getDatabase(pocDatabase);
|
||||
}
|
||||
|
||||
public long getLastStrokeNum(){
|
||||
MongoCollection<Document> collection = database.getCollection("cards");
|
||||
MongoCursor<Document> cursor = collection.find().iterator();
|
||||
long lastStroke = 0;
|
||||
try {
|
||||
while (cursor.hasNext()) {
|
||||
long docStroke = (Long) cursor.next().get("strokeNumber");
|
||||
if (docStroke > lastStroke) { lastStroke = docStroke; }
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
return lastStroke;
|
||||
}
|
||||
|
||||
public long newCard(Card inpCard){
|
||||
MongoCollection<Document> collection = database.getCollection("cards");
|
||||
List<Double> s_p = new ArrayList<Double>();
|
||||
for(Double pt: inpCard.getSurfacePosition()) { s_p.add(pt);}
|
||||
|
||||
List<Double> s_l = new ArrayList<Double>();
|
||||
for(Double pt: inpCard.getSurfaceLoad()) { s_l.add(pt);}
|
||||
|
||||
List<Double> d_p = new ArrayList<Double>();
|
||||
for(Double pt: inpCard.getDownholePosition()) { d_p.add(pt);}
|
||||
|
||||
List<Double> d_l = new ArrayList<Double>();
|
||||
for(Double pt: inpCard.getDownholeLoad()) { d_l.add(pt);}
|
||||
|
||||
Document doc = new Document("strokeNumber", inpCard.getStrokeNumber())
|
||||
.append("surface_position", s_p)
|
||||
.append("surface_load", s_l)
|
||||
.append("downhole_position", d_p)
|
||||
.append("downhole_load", d_l);
|
||||
collection.insertOne(doc);
|
||||
return collection.count();
|
||||
}
|
||||
public void close(){
|
||||
mongoClient.close();
|
||||
}
|
||||
}
|
||||
@@ -4,31 +4,6 @@ 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;
|
||||
@@ -40,28 +15,21 @@ public class DigitalIn {
|
||||
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();
|
||||
this.channel = channel;
|
||||
if (channel != 99) {
|
||||
|
||||
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());
|
||||
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.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_IN);
|
||||
}
|
||||
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_IN);
|
||||
|
||||
}
|
||||
|
||||
public int read(){
|
||||
@@ -75,8 +43,8 @@ public class DigitalIn {
|
||||
DigitalIn testIn8 = new DigitalIn(8);
|
||||
DigitalIn testIn9 = new DigitalIn(9);
|
||||
|
||||
DigitalOut testOut2 = new DigitalOut(2);
|
||||
DigitalOut testOut3 = new DigitalOut(3);
|
||||
DigitalOut testOut2 = new DigitalOut(2,0);
|
||||
DigitalOut testOut3 = new DigitalOut(3,0);
|
||||
|
||||
int in8val, in9val;
|
||||
do {
|
||||
|
||||
@@ -15,6 +15,7 @@ import static java.lang.Thread.sleep;
|
||||
public class DigitalOut {
|
||||
private int channel;
|
||||
private Gpio gpioPin;
|
||||
private int value;
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -27,51 +28,66 @@ public class DigitalOut {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
DigitalOut(int channel, int startupValue){
|
||||
this.channel = channel;
|
||||
this.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_OUT);
|
||||
if (channel != 99) {
|
||||
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.gpioPin = new Gpio(this.channel);
|
||||
gpioPin.dir(Dir.DIR_OUT);
|
||||
this.value = startupValue;
|
||||
write(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int writeVal){
|
||||
gpioPin.write(writeVal);
|
||||
if ( value != writeVal & channel != 99) {
|
||||
gpioPin.write(writeVal);
|
||||
value = writeVal;
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int writeVal, boolean force){
|
||||
if ( value != writeVal || force) {
|
||||
if (channel != 99) {
|
||||
gpioPin.write(writeVal);
|
||||
value = writeVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
DigitalOut testOut2 = new DigitalOut(2);
|
||||
DigitalOut testOut2 = new DigitalOut(2, 0);
|
||||
testOut2.write(1);
|
||||
sleep(500);
|
||||
testOut2.write(0);
|
||||
|
||||
DigitalOut testOut3 = new DigitalOut(3);
|
||||
DigitalOut testOut3 = new DigitalOut(3, 0);
|
||||
testOut3.write(1);
|
||||
sleep(500);
|
||||
testOut3.write(0);
|
||||
|
||||
DigitalOut testOut4 = new DigitalOut(4);
|
||||
DigitalOut testOut4 = new DigitalOut(4, 0);
|
||||
testOut4.write(1);
|
||||
sleep(500);
|
||||
testOut4.write(0);
|
||||
|
||||
DigitalOut testOut5 = new DigitalOut(5);
|
||||
DigitalOut testOut5 = new DigitalOut(5, 0);
|
||||
testOut5.write(1);
|
||||
sleep(500);
|
||||
testOut5.write(0);
|
||||
|
||||
DigitalOut testOut6 = new DigitalOut(6);
|
||||
DigitalOut testOut6 = new DigitalOut(6, 0);
|
||||
testOut6.write(1);
|
||||
sleep(500);
|
||||
testOut6.write(0);
|
||||
|
||||
DigitalOut testOut7 = new DigitalOut(7);
|
||||
DigitalOut testOut7 = new DigitalOut(7, 0);
|
||||
testOut7.write(1);
|
||||
sleep(500);
|
||||
testOut7.write(0);
|
||||
|
||||
@@ -3,61 +3,96 @@ package com.henrypump.poc;
|
||||
/**
|
||||
* Created by patrickjmcd on 2/1/17.
|
||||
*/
|
||||
|
||||
public class POC implements Runnable{
|
||||
private Well thisWell;
|
||||
private Simulation sim;
|
||||
private int simLoops;
|
||||
private double tubingMovement;
|
||||
private double pumpIntakePressure;
|
||||
private double fluidLoad;
|
||||
private double fluidLevel;
|
||||
private Thread t;
|
||||
private DigitalIn startBtn = new DigitalIn(8);
|
||||
private DigitalIn stopBtn = new DigitalIn(9);
|
||||
private DigitalOut led2 = new DigitalOut(2, 0);
|
||||
private DigitalOut led3 = new DigitalOut(3, 0);
|
||||
private DigitalOut led4 = new DigitalOut(4, 0);
|
||||
private DigitalOut led5 = new DigitalOut(5, 0);
|
||||
private DigitalOut runIndicator = new DigitalOut(6,0);
|
||||
|
||||
|
||||
|
||||
POC(String wellName, String wellSetupJsonFile, String simFileName, int simLoops){
|
||||
POC(String wellName, String wellSetupJsonFile, int simLoops){
|
||||
thisWell = new Well(wellName);
|
||||
thisWell.parseJSONFile(wellSetupJsonFile);
|
||||
thisWell.printTapers();
|
||||
sim = new Simulation(simFileName);
|
||||
this.simLoops = simLoops;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
POC(String wellName, String wellSetupJsonFile, String simFileName, int simLoops){
|
||||
thisWell = new Well(wellName, simFileName);
|
||||
thisWell.parseJSONFile(wellSetupJsonFile);
|
||||
thisWell.printTapers();
|
||||
this.simLoops = simLoops;
|
||||
}
|
||||
|
||||
int loopCounter = 0, loopLimit = simLoops;
|
||||
public void allOutputsOff(){
|
||||
led2.write(0,true);
|
||||
led3.write(0,true);
|
||||
led4.write(0,true);
|
||||
led5.write(0,true);
|
||||
}
|
||||
|
||||
public void run(){
|
||||
int loopCounter = 0, loopLimit = simLoops, led2out, led3out, led4out,led5out;
|
||||
double pos;
|
||||
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
||||
|
||||
LPStatus downholePoint;
|
||||
while (loopCounter < loopLimit) {
|
||||
Card thisCard = new Card(loopCounter);
|
||||
for (int i = 0; i <= sim.getLastFilledIndex(); i++) {
|
||||
thisCard.setSurfacePosition(i, sim.getPositionAtIndex(i));
|
||||
thisCard.setSurfaceLoad(i, sim.getLoadAtIndex(i));
|
||||
downholePoint = thisWell.calc(sim.getPositionAtIndex(i), sim.getLoadAtIndex(i));
|
||||
if (downholePoint.getStatus() == Well.GOOD_STATUS) {
|
||||
thisCard.setDownholePosition(i, downholePoint.getPosition());
|
||||
thisCard.setDownholeLoad(i, downholePoint.getLoad());
|
||||
}
|
||||
try {
|
||||
Thread.sleep(sleepMilliseconds);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
thisWell.checkSafeties();
|
||||
while (true) {
|
||||
while (loopCounter < loopLimit && (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING)) {
|
||||
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
||||
if (startBtn.read() == 1) thisWell.start("startbutton");
|
||||
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
thisWell.eval(i);
|
||||
|
||||
pos = thisWell.getCurrentPosition();
|
||||
|
||||
led2.write(pos > 20.0 ? 1 : 0);
|
||||
led3.write(pos > 40.0 ? 1 : 0);
|
||||
led4.write(pos > 60.0 ? 1 : 0);
|
||||
led5.write(pos > 80.0 ? 1 : 0);
|
||||
|
||||
runIndicator.write(thisWell.getRunStatus()==Well.RUNSTATUS_RUNNING ? 1 : 0);
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepMilliseconds);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
loopCounter++;
|
||||
}
|
||||
thisCard.setNumPointsUsed(sim.getLastFilledIndex());
|
||||
thisCard.calcStrokeData(150, thisWell.getFluidGradient(),
|
||||
thisWell.getRodDepthTotal(), thisWell.getTubingAnchorDepth(),
|
||||
thisWell.getTubingCrossSectionalArea(), thisWell.getPumpArea(),
|
||||
thisWell.getFrictionEstimate(), thisWell.getStructuralRating());
|
||||
thisCard.printCard("none", true);
|
||||
loopCounter++;
|
||||
|
||||
if (startBtn.read() == 1) thisWell.start("startbutton");
|
||||
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
led2.write(0);
|
||||
led3.write(0);
|
||||
led4.write(0);
|
||||
led5.write(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void start () {
|
||||
System.out.println("Starting POC");
|
||||
System.out.println("Starting POC Thread");
|
||||
if (t == null) {
|
||||
t = new Thread (this, "POC-Thread");
|
||||
t.start ();
|
||||
@@ -66,15 +101,9 @@ public class POC implements Runnable{
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
POC thisPOC = new POC("Barney", args[0], args[1], 3);
|
||||
final POC thisPOC = new POC("Barney", args[0], args[1], 100);
|
||||
thisPOC.start();
|
||||
|
||||
try {
|
||||
Thread.sleep(15000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
POC otherPOC = new POC("NotBarney", args[0], args[1], 4);
|
||||
otherPOC.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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