Create Transition::calculateProperties() to update component properties as needed instead of recalculating for shoulders every time they're called.

This commit is contained in:
JoePfeiffer 2023-12-13 09:57:35 -07:00
parent 4dd2c3a86a
commit b5b3ac2b3d
2 changed files with 19 additions and 31 deletions

View File

@ -32,11 +32,11 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
private double wetArea = Double.NaN;
private double planArea = Double.NaN;
private double planCenter = Double.NaN;
private double volume = Double.NaN;
protected double volume = Double.NaN;
private double fullVolume = Double.NaN;
private double longitudinalInertia = Double.NaN;
private double rotationalInertia = Double.NaN;
private Coordinate cg = null;
protected Coordinate cg = null;
public SymmetricComponent() {
super();
@ -417,7 +417,7 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
/**
* Performs integration over the length of the component and updates the cached variables.
*/
private void calculateProperties() {
protected void calculateProperties() {
wetArea = 0;
planArea = 0;
planCenter = 0;

View File

@ -671,58 +671,46 @@ public class Transition extends SymmetricComponent implements InsideColorCompone
}
@Override
public double getComponentVolume() {
double volume = super.getComponentVolume();
protected void calculateProperties() {
super.calculateProperties();
if (getForeShoulderLength() > 0.001) {
final double or = getForeShoulderRadius();
final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
volume += ringVolume( or, ir, getForeShoulderLength() );
}
if (isForeShoulderCapped()) {
final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
volume += ringVolume(ir, 0, getForeShoulderThickness() );
}
if (getAftShoulderLength() > 0.001) {
final double or = getAftShoulderRadius();
final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
volume += ringVolume(or, ir, getAftShoulderLength() );
}
if (isAftShoulderCapped()) {
final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
volume += ringVolume(ir, 0, getAftShoulderThickness() );
}
return volume;
}
@Override
public Coordinate getComponentCG() {
Coordinate cg = super.getComponentCG();
if (getForeShoulderLength() > 0.001) {
final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
cg = cg.average(ringCG(getForeShoulderRadius(), ir, -getForeShoulderLength(), 0,
getMaterial().getDensity()));
volume += ringVolume( or, ir, getForeShoulderLength() );
}
if (isForeShoulderCapped()) {
final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
cg = cg.average(ringCG(ir, 0, -getForeShoulderLength(),
getForeShoulderThickness() - getForeShoulderLength(),
getMaterial().getDensity()));
volume += ringVolume(ir, 0, getForeShoulderThickness() );
}
if (getAftShoulderLength() > 0.001) {
final double or = getAftShoulderRadius();
final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
cg = cg.average(ringCG(getAftShoulderRadius(), ir, getLength(),
getLength() + getAftShoulderLength(), getMaterial().getDensity()));
volume += ringVolume(or, ir, getAftShoulderLength() );
}
if (isAftShoulderCapped()) {
final double or = getAftShoulderRadius();
final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
cg = cg.average(ringCG(ir, 0,
getLength() + getAftShoulderLength() - getAftShoulderThickness(),
getLength() + getAftShoulderLength(), getMaterial().getDensity()));
volume += ringVolume(ir, 0, getAftShoulderThickness() );
}
return cg;
}