Adds pump-off logic

This commit is contained in:
Patrick McDonagh
2017-02-22 14:57:56 -06:00
parent 88d30e5a9b
commit 6b60d0f806
5 changed files with 137 additions and 5 deletions

View File

@@ -21,7 +21,16 @@ class CLScanner implements Runnable {
poc.thisWell.stop("commandline"); poc.thisWell.stop("commandline");
} }
private void pumpoffWell(){
poc.thisWell.pumpOff("commandline");
}
private void restartWell(){
poc.thisWell.restart("commandline");
}
private void exitPOC(){ private void exitPOC(){
poc.thisWell.db.newRunStatus("Shutdown", "commandline");
System.exit(99); System.exit(99);
} }
@@ -49,6 +58,8 @@ class CLScanner implements Runnable {
System.out.println("POSSIBLE COMMANDS"); System.out.println("POSSIBLE COMMANDS");
System.out.println("start -- Issues the start command"); System.out.println("start -- Issues the start command");
System.out.println("stop -- Issues the stop command"); System.out.println("stop -- Issues the stop command");
System.out.println("pumpoff -- Issues the pumpoff command");
System.out.println("restart -- Issues the restart command");
System.out.println("status -- Gets the current run status"); System.out.println("status -- Gets the current run status");
System.out.println("showtapers -- Gets the current taper and well parameters"); System.out.println("showtapers -- Gets the current taper and well parameters");
System.out.println("showtotals -- Gets the current totals and averages"); System.out.println("showtotals -- Gets the current totals and averages");
@@ -76,6 +87,12 @@ class CLScanner implements Runnable {
case "stop": case "stop":
stopWell(); stopWell();
break; break;
case "pumpoff":
pumpoffWell();
break;
case "restart":
restartWell();
break;
case "exit": case "exit":
exitPOC(); exitPOC();
break; break;

View File

@@ -224,4 +224,14 @@ public class Database {
} }
return frictionEstimate; return frictionEstimate;
} }
public long newRunStatus(String runStatus, String initiator){
MongoCollection<Document> collection = database.getCollection("runStatus");
Document doc = new Document("status", runStatus)
.append("initiator", initiator)
.append("timesstamp", Date.from(ZonedDateTime.now().toInstant()));
collection.insertOne(doc);
return collection.count();
}
} }

View File

@@ -34,6 +34,7 @@ public class IOControl implements Runnable {
} }
private void exitPOC(){ private void exitPOC(){
poc.thisWell.db.newRunStatus("Shutdown", "io");
allOutputsOff(); allOutputsOff();
System.exit(0); System.exit(0);
} }

View File

@@ -41,7 +41,7 @@ public class POC implements Runnable{
thisWell.setupFluidRatio(0.50, 0.50, 1.12); thisWell.setupFluidRatio(0.50, 0.50, 1.12);
thisWell.checkSafeties(); thisWell.checkSafeties();
while (true) { while (true) {
while (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING) { // while (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING) {
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) { for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
thisWell.eval(i); thisWell.eval(i);
@@ -52,7 +52,7 @@ public class POC implements Runnable{
e.printStackTrace(); e.printStackTrace();
} }
} }
} // }
} }
} }

View File

@@ -15,11 +15,10 @@ import static java.lang.Math.exp;
import static java.lang.Math.pow; import static java.lang.Math.pow;
import static java.lang.Math.sqrt; import static java.lang.Math.sqrt;
import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/** /**
* Created by patrickjmcd on 1/31/17. * Created by patrickjmcd on 1/31/17.
@@ -172,6 +171,16 @@ public class Well {
private Measurement pumpIntakePressure; private Measurement pumpIntakePressure;
private Measurement surfaceStrokeLength; private Measurement surfaceStrokeLength;
private Measurement tubingMovement; private Measurement tubingMovement;
private Measurement pumpFillPercent;
// Running Setpoints
private double pumpOffFillPercentSetpoint = 65;
private int pumpOffStrokes = 5;
private int lowFillageStrokes = 0;
private ZonedDateTime pumpedOffTime;
private long pumpOffDowntimeMinutes = 5;
private long minutesSincePumpOff = 0;
private long minutesSincePumpOff_last = 0;
Well(String dbHostname, int inclinometerChannel, int loadCellChannel, int runCommandChannel){ Well(String dbHostname, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
this.wellName = wellName; this.wellName = wellName;
@@ -182,6 +191,7 @@ public class Well {
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000); loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
initializeMeasurements(); initializeMeasurements();
db.newRunStatus("Boot", "io");
} }
Well(String dbHostname, String simFileName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){ Well(String dbHostname, String simFileName, int inclinometerChannel, int loadCellChannel, int runCommandChannel){
@@ -194,6 +204,7 @@ public class Well {
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000); loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
initializeMeasurements(); initializeMeasurements();
db.newRunStatus("Boot", "commandline");
} }
private void initializeMeasurements(){ private void initializeMeasurements(){
@@ -216,6 +227,7 @@ public class Well {
pumpIntakePressure = new Measurement("Pump Intake Pressure", db, 5.0, 600); pumpIntakePressure = new Measurement("Pump Intake Pressure", db, 5.0, 600);
surfaceStrokeLength = new Measurement("Surface Stroke", db, 0.5, 1800); surfaceStrokeLength = new Measurement("Surface Stroke", db, 0.5, 1800);
tubingMovement = new Measurement("Tubing Movement", db, 0.5, 600); tubingMovement = new Measurement("Tubing Movement", db, 0.5, 600);
pumpFillPercent = new Measurement("Pump Fill Percent", db, 0.5, 600);
} }
public double getDt() { public double getDt() {
@@ -456,6 +468,42 @@ public class Well {
this.kFactor = kFactor; this.kFactor = kFactor;
} }
public int getLowFillageStrokes() {
return lowFillageStrokes;
}
public ZonedDateTime getPumpedOffTime() {
return pumpedOffTime;
}
public long getMinutesSincePumpOff() {
return minutesSincePumpOff;
}
public double getPumpOffFillPercentSetpoint() {
return pumpOffFillPercentSetpoint;
}
public void setPumpOffFillPercentSetpoint(double pumpOffFillPercentSetpoint) {
this.pumpOffFillPercentSetpoint = pumpOffFillPercentSetpoint;
}
public int getPumpOffStrokes() {
return pumpOffStrokes;
}
public void setPumpOffStrokes(int pumpOffStrokes) {
this.pumpOffStrokes = pumpOffStrokes;
}
public long getPumpOffDowntimeMinutes() {
return pumpOffDowntimeMinutes;
}
public void setPumpOffDowntimeMinutes(long pumpOffDowntimeMinutes) {
this.pumpOffDowntimeMinutes = pumpOffDowntimeMinutes;
}
public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){ public void setupFluidRatio(double oilRatio, double waterRatio, double gasRatio){
fluidOilRatio = oilRatio; fluidOilRatio = oilRatio;
fluidWaterRatio = waterRatio; fluidWaterRatio = waterRatio;
@@ -468,13 +516,34 @@ public class Well {
System.out.println("Starting " + wellName + " from " + initiator + "..."); System.out.println("Starting " + wellName + " from " + initiator + "...");
runStatus = RUNSTATUS_STARTING; runStatus = RUNSTATUS_STARTING;
strokesSinceStart = 0; strokesSinceStart = 0;
db.newRunStatus(getRunStatusString(), initiator);
} }
} }
public void stop(String initiator){ public void stop(String initiator){
if (runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING){ if (runStatus == RUNSTATUS_STARTING || runStatus == RUNSTATUS_RUNNING || runStatus == RUNSTATUS_PUMPEDOFF){
System.out.println("Stopping " + wellName + " from " + initiator + "..."); System.out.println("Stopping " + wellName + " from " + initiator + "...");
runStatus = RUNSTATUS_STOPPED; runStatus = RUNSTATUS_STOPPED;
db.newRunStatus(getRunStatusString(), initiator);
}
}
public void restart(String initiator){
if (runStatus == RUNSTATUS_PUMPEDOFF && permissiveOK){
System.out.println("Restarting after pump-off from " + initiator + "...");
runStatus = RUNSTATUS_STARTING;
strokesSinceStart = 0;
db.newRunStatus(getRunStatusString(), initiator);
}
}
public void pumpOff(String initiator){
if (runStatus == RUNSTATUS_RUNNING){
System.out.println("Pumping off from " + initiator + "...");
System.out.println("Restarting in " + pumpOffDowntimeMinutes + " minutes.");
pumpedOffTime = ZonedDateTime.now();
runStatus = RUNSTATUS_PUMPEDOFF;
db.newRunStatus(getRunStatusString(), initiator);
} }
} }
@@ -941,6 +1010,7 @@ public class Well {
pumpIntakePressure.update(currentCard.getPumpIntakePressure()); pumpIntakePressure.update(currentCard.getPumpIntakePressure());
surfaceStrokeLength.update(currentCard.getSurfaceStrokeLength()); surfaceStrokeLength.update(currentCard.getSurfaceStrokeLength());
tubingMovement.update(currentCard.getTubingMovement()); tubingMovement.update(currentCard.getTubingMovement());
pumpFillPercent.update(currentCard.getFillageCalculated());
db.newCard(currentCard); db.newCard(currentCard);
currentCard = new Card(strokesLifetime); currentCard = new Card(strokesLifetime);
@@ -949,6 +1019,18 @@ public class Well {
runStatus = RUNSTATUS_RUNNING; runStatus = RUNSTATUS_RUNNING;
} }
if (runStatus == RUNSTATUS_RUNNING) {
if (pumpFillPercent.getCurrentValue() < pumpOffFillPercentSetpoint) {
lowFillageStrokes++;
} else {
lowFillageStrokes = 0;
}
if (lowFillageStrokes > pumpOffStrokes) {
pumpOff("lowpumpfill");
}
}
} }
public void gaugeOff(){ public void gaugeOff(){
@@ -1004,6 +1086,17 @@ public class Well {
pointCounter++; pointCounter++;
} }
if (runStatus == RUNSTATUS_PUMPEDOFF){
minutesSincePumpOff = ChronoUnit.MINUTES.between(ZonedDateTime.now(), pumpedOffTime);
if(minutesSincePumpOff_last != minutesSincePumpOff){
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
minutesSincePumpOff_last = minutesSincePumpOff;
}
if (minutesSincePumpOff > pumpOffDowntimeMinutes){
restart("pumpoffdowntime");
}
}
if(isNewDay()){ if(isNewDay()){
gaugeOff(); gaugeOff();
} }
@@ -1039,6 +1132,17 @@ public class Well {
pointCounter++; pointCounter++;
} }
if (runStatus == RUNSTATUS_PUMPEDOFF){
minutesSincePumpOff = ChronoUnit.MINUTES.between(pumpedOffTime, ZonedDateTime.now());
if(minutesSincePumpOff_last != minutesSincePumpOff){
System.out.println("Restarting in " + (pumpOffDowntimeMinutes - minutesSincePumpOff) + " minutes.");
minutesSincePumpOff_last = minutesSincePumpOff;
}
if (minutesSincePumpOff > pumpOffDowntimeMinutes){
restart("pumpoffdowntime");
}
}
if(isNewDay()){ if(isNewDay()){
gaugeOff(); gaugeOff();
} }