Database and IO Simulation working
This commit is contained in:
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user