diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1ffb95e..9ca011a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,21 +2,26 @@ - + + + + - - - + + + - + + + @@ -36,71 +41,136 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -109,13 +179,25 @@ - - + + + + + + + + + + + + + + @@ -136,13 +218,14 @@ @@ -155,6 +238,7 @@ + - + @@ -485,6 +569,7 @@ + @@ -495,7 +580,6 @@ - @@ -503,7 +587,9 @@ - + + @@ -523,40 +609,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -581,14 +633,6 @@ - - - - - - - - @@ -626,69 +670,164 @@ + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/src/main/java/com/henrypump/poc/AnalogIn.java b/src/main/java/com/henrypump/poc/AnalogIn.java index b9f1328..c5bde9f 100644 --- a/src/main/java/com/henrypump/poc/AnalogIn.java +++ b/src/main/java/com/henrypump/poc/AnalogIn.java @@ -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; } diff --git a/src/main/java/com/henrypump/poc/Card.java b/src/main/java/com/henrypump/poc/Card.java index 5353e70..db795ae 100644 --- a/src/main/java/com/henrypump/poc/Card.java +++ b/src/main/java/com/henrypump/poc/Card.java @@ -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; diff --git a/src/main/java/com/henrypump/poc/Database.java b/src/main/java/com/henrypump/poc/Database.java new file mode 100644 index 0000000..e3ab7a3 --- /dev/null +++ b/src/main/java/com/henrypump/poc/Database.java @@ -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 collection = database.getCollection("cards"); + MongoCursor 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 collection = database.getCollection("cards"); + List s_p = new ArrayList(); + for(Double pt: inpCard.getSurfacePosition()) { s_p.add(pt);} + + List s_l = new ArrayList(); + for(Double pt: inpCard.getSurfaceLoad()) { s_l.add(pt);} + + List d_p = new ArrayList(); + for(Double pt: inpCard.getDownholePosition()) { d_p.add(pt);} + + List d_l = new ArrayList(); + 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(); + } +} diff --git a/src/main/java/com/henrypump/poc/DigitalIn.java b/src/main/java/com/henrypump/poc/DigitalIn.java index d125cfe..2c3988d 100644 --- a/src/main/java/com/henrypump/poc/DigitalIn.java +++ b/src/main/java/com/henrypump/poc/DigitalIn.java @@ -4,31 +4,6 @@ package com.henrypump.poc; * Created by patrickjmcd on 1/31/17. */ -/* - * Author: Brendan Le Foll - * Author: Petre Eftime - * 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 { diff --git a/src/main/java/com/henrypump/poc/DigitalOut.java b/src/main/java/com/henrypump/poc/DigitalOut.java index 90ca71b..687fc54 100644 --- a/src/main/java/com/henrypump/poc/DigitalOut.java +++ b/src/main/java/com/henrypump/poc/DigitalOut.java @@ -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); diff --git a/src/main/java/com/henrypump/poc/POC.java b/src/main/java/com/henrypump/poc/POC.java index 89712d8..eac529b 100644 --- a/src/main/java/com/henrypump/poc/POC.java +++ b/src/main/java/com/henrypump/poc/POC.java @@ -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(); + } } diff --git a/src/main/java/com/henrypump/poc/Well.java b/src/main/java/com/henrypump/poc/Well.java index bb4d60c..0335a70 100644 --- a/src/main/java/com/henrypump/poc/Well.java +++ b/src/main/java/com/henrypump/poc/Well.java @@ -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]); diff --git a/target/classes/com/henrypump/poc/AnalogIn.class b/target/classes/com/henrypump/poc/AnalogIn.class index b2f07f2..d898522 100644 Binary files a/target/classes/com/henrypump/poc/AnalogIn.class and b/target/classes/com/henrypump/poc/AnalogIn.class differ diff --git a/target/classes/com/henrypump/poc/Card.class b/target/classes/com/henrypump/poc/Card.class index 5b0670f..14a21ca 100644 Binary files a/target/classes/com/henrypump/poc/Card.class and b/target/classes/com/henrypump/poc/Card.class differ diff --git a/target/classes/com/henrypump/poc/Database.class b/target/classes/com/henrypump/poc/Database.class new file mode 100644 index 0000000..e2d301f Binary files /dev/null and b/target/classes/com/henrypump/poc/Database.class differ diff --git a/target/classes/com/henrypump/poc/DigitalIn.class b/target/classes/com/henrypump/poc/DigitalIn.class index 082e196..ad6c7bb 100644 Binary files a/target/classes/com/henrypump/poc/DigitalIn.class and b/target/classes/com/henrypump/poc/DigitalIn.class differ diff --git a/target/classes/com/henrypump/poc/DigitalOut.class b/target/classes/com/henrypump/poc/DigitalOut.class index f533bfe..90ecc83 100644 Binary files a/target/classes/com/henrypump/poc/DigitalOut.class and b/target/classes/com/henrypump/poc/DigitalOut.class differ diff --git a/target/classes/com/henrypump/poc/POC.class b/target/classes/com/henrypump/poc/POC.class index 30898ce..810dfdf 100644 Binary files a/target/classes/com/henrypump/poc/POC.class and b/target/classes/com/henrypump/poc/POC.class differ diff --git a/target/classes/com/henrypump/poc/Well.class b/target/classes/com/henrypump/poc/Well.class index 5060538..ae66638 100644 Binary files a/target/classes/com/henrypump/poc/Well.class and b/target/classes/com/henrypump/poc/Well.class differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index b526ead..c167f71 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Wed Feb 01 18:42:01 CST 2017 +#Thu Feb 02 18:00:05 CST 2017 version=1.0-SNAPSHOT groupId=com.henrypump.poc artifactId=poc-java diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index a0eb504..826d4bb 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -6,5 +6,6 @@ com/henrypump/poc/DigitalIn.class com/henrypump/poc/POC.class com/henrypump/poc/App.class com/henrypump/poc/Well.class +com/henrypump/poc/Database.class com/henrypump/poc/LPStatus.class com/henrypump/poc/DigitalOut.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 3faf5db..fb01cbf 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -6,5 +6,6 @@ /Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/App.java /Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/Card.java /Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/POC.java +/Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/Database.java /Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/DigitalOut.java /Users/patrickjmcd/Henry_Pump/poc-java/src/main/java/com/henrypump/poc/DigitalIn.java diff --git a/target/original-poc-java-1.0-SNAPSHOT.jar b/target/original-poc-java-1.0-SNAPSHOT.jar index f5cae30..47bf08b 100644 Binary files a/target/original-poc-java-1.0-SNAPSHOT.jar and b/target/original-poc-java-1.0-SNAPSHOT.jar differ diff --git a/target/poc-java-1.0-SNAPSHOT.jar b/target/poc-java-1.0-SNAPSHOT.jar index a3f4fc8..e856cf1 100644 Binary files a/target/poc-java-1.0-SNAPSHOT.jar and b/target/poc-java-1.0-SNAPSHOT.jar differ diff --git a/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml b/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml index fbeefa1..be250c8 100644 --- a/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml +++ b/target/surefire-reports/TEST-com.henrypump.poc.AppTest.xml @@ -1,5 +1,5 @@ - + @@ -62,5 +62,5 @@ - + \ No newline at end of file diff --git a/target/surefire-reports/com.henrypump.poc.AppTest.txt b/target/surefire-reports/com.henrypump.poc.AppTest.txt index 17b617b..ca190c6 100644 --- a/target/surefire-reports/com.henrypump.poc.AppTest.txt +++ b/target/surefire-reports/com.henrypump.poc.AppTest.txt @@ -1,4 +1,4 @@ ------------------------------------------------------------------------------- Test set: com.henrypump.poc.AppTest ------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec