{ minValueInput.setDefaultValue(0.0); meanInput = new ValueInput("Mean", "Key Inputs", 1.0d); meanInput.setUnitType(UserSpecifiedUnit.class); meanInput.setValidRange(0.0d, Double.POSITIVE_INFINITY); this.addInput(meanInput); }
{ minValueInput.setDefaultValue(0.0); meanInput = new ValueInput("Mean", "Key Inputs", 1.0d); meanInput.setUnitType(UserSpecifiedUnit.class); meanInput.setValidRange(0.0d, Double.POSITIVE_INFINITY); this.addInput(meanInput); shapeInput = new ValueInput("Shape", "Key Inputs", 1.0); shapeInput.setUnitType(DimensionlessUnit.class); shapeInput.setValidRange(1.0e-10d, Integer.MAX_VALUE); this.addInput(shapeInput); }
@Override public double calcOutletPressure(double inletPres, double flowAccel) { double dyn = this.getDynamicPressure(); // Note that dynamic pressure is negative for negative velocities double pres = inletPres; pres -= this.getFluid().getDensityxGravity() * heightChangeInput.getValue(); if (Math.abs(dyn) > 0.0 && this.getFluid().getViscosity() > 0.0) { this.setDarcyFrictionFactor(); pres -= darcyFrictionFactor * dyn * this.getLength() / this.getDiameter(); } else { darcyFrictionFactor = 0.0; } pres -= pressureLossCoefficientInput.getValue() * dyn; pres -= flowAccel * this.getFluid().getDensity() * lengthInput.getValue() / this.getFlowArea(); return pres; }
@Override protected double getNextSample() { double u2, b, sample; // Case 1 - Shape parameter < 1 if (shapeInput.getValue() < 1.0) { double threshold; b = 1.0 + (shapeInput.getValue() / Math.E); do { double p = b * rng2.nextUniform(); u2 = rng1.nextUniform(); if (p <= 1.0) { sample = Math.pow(p, 1.0 / shapeInput.getValue()); threshold = Math.exp(-sample); } else { sample = -Math.log((b - p) / shapeInput.getValue()); threshold = Math.pow(sample, shapeInput.getValue() - 1.0); } } while (u2 > threshold); } // Case 2 - Shape parameter >= 1 else { double u1, w, z; double a = 1.0 / Math.sqrt((2.0 * shapeInput.getValue()) - 1.0); b = shapeInput.getValue() - Math.log(4.0); double q = shapeInput.getValue() + (1.0 / a); double d = 1.0 + Math.log(4.5); do { u1 = rng1.nextUniform(); u2 = rng2.nextUniform(); double v = a * Math.log(u1 / (1.0 - u1)); sample = shapeInput.getValue() * Math.exp(v); z = u1 * u1 * u2; w = b + q * v - sample; } while ((w + d - 4.5 * z < 0.0) && (w < Math.log(z))); } // Scale the sample by the desired mean value return sample * meanInput.getValue() / shapeInput.getValue(); }
{ lengthInput = new ValueInput("Length", "Key Inputs", 1.0d); lengthInput.setValidRange(0.0, Double.POSITIVE_INFINITY); lengthInput.setUnitType(DistanceUnit.class); this.addInput(lengthInput); heightChangeInput = new ValueInput("HeightChange", "Key Inputs", 0.0d); heightChangeInput.setValidRange(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); heightChangeInput.setUnitType(DistanceUnit.class); this.addInput(heightChangeInput); roughnessInput = new ValueInput("Roughness", "Key Inputs", 0.0d); roughnessInput.setValidRange(0.0, Double.POSITIVE_INFINITY); roughnessInput.setUnitType(DistanceUnit.class); this.addInput(roughnessInput); pressureLossCoefficientInput = new ValueInput("PressureLossCoefficient", "Key Inputs", 0.0d); pressureLossCoefficientInput.setValidRange(0.0, Double.POSITIVE_INFINITY); pressureLossCoefficientInput.setUnitType(DimensionlessUnit.class); this.addInput(pressureLossCoefficientInput); ArrayList<Vec3d> defPoints = new ArrayList<>(); defPoints.add(new Vec3d(0.0d, 0.0d, 0.0d)); defPoints.add(new Vec3d(1.0d, 0.0d, 0.0d)); pointsInput = new Vec3dListInput("Points", "Key Inputs", defPoints); pointsInput.setValidCountRange(2, Integer.MAX_VALUE); pointsInput.setUnitType(DistanceUnit.class); this.addInput(pointsInput); widthInput = new ValueInput("Width", "Key Inputs", 1.0d); widthInput.setValidRange(1.0d, Double.POSITIVE_INFINITY); widthInput.setUnitType(DimensionlessUnit.class); this.addInput(widthInput); colourInput = new ColourInput("Colour", "Key Inputs", ColourInput.BLACK); this.addInput(colourInput); this.addSynonym(colourInput, "Color"); }
@Override public HasScreenPoints.PointsInfo[] getScreenPoints() { synchronized (screenPointLock) { if (cachedPointInfo == null) { cachedPointInfo = new HasScreenPoints.PointsInfo[1]; HasScreenPoints.PointsInfo pi = new HasScreenPoints.PointsInfo(); cachedPointInfo[0] = pi; pi.points = pointsInput.getValue(); pi.color = colourInput.getValue(); pi.width = widthInput.getValue().intValue(); if (pi.width < 1) pi.width = 1; } return cachedPointInfo; } }
/* * Return the Darcy Friction Factor for a turbulent flow. */ private double getTurbulentFrictionFactor(double reynoldsNumber) { double x = 1.0; // The present value for x = 1 / sqrt( frictionfactor ). double lastx = 0.0; double a = (roughnessInput.getValue() / this.getDiameter()) / 3.7; double b = 2.51 / reynoldsNumber; int n = 0; while (Math.abs(x - lastx) / lastx > 1.0e-10 && n < 20) { lastx = x; x = -2.0 * Math.log10(a + b * lastx); n++; } if (n >= 20) { error( "Darcy Friction Factor iterations did not converge: lastx = %f x = %f n = %d", lastx, x, n); } return 1.0 / (x * x); }
@Override protected void setUnitType(Class<? extends Unit> specified) { super.setUnitType(specified); meanInput.setUnitType(specified); }
@Override protected double getStandardDeviation() { return meanInput.getValue() / Math.sqrt(shapeInput.getValue()); }
@Override protected double getMeanValue() { return meanInput.getValue(); }
@Override protected double getStandardDeviation() { return meanInput.getValue(); }
@Override protected double getNextSample() { // Inverse transform method return (-meanInput.getValue() * Math.log(rng.nextUniform())); }
@Override public double getLength() { return lengthInput.getValue(); }