Safe to execute again?
The last post was about making an entry for force and angle, making sure that the format was in terms of two separate doubles in the argument and making a clean exit if that was not the case. From this point, it is not too hard to set up a way to break down the force and angle into two orthogonal force components. Making sure the code can cope with unexpected entry data is the top priority.
This also applies to other components parts in the framework of any truss system entered. Because these analyses are designed to be simplistic, there are just two components that the truss consists of, well until things get more complicated later on:
- Joints
- Structural Members
To start with, joints will have the following data in order to exist:
- Joint Number, an integer identifier which will help a number of things later
- X-Coordinate double value
- Y-Coordinate double value
Also at the beginning, the structural members will only need two things:
- Member Number, an integer to identify it within the structure
- Start Point, which can be defined by an integer joint number value
- End Point, another joint number integer value
Other bits of data can be added as the new product forms.
Encore, on y va?
Joints
The basic criteria of the joints are that they have some form of identification and that they have a position, defined in terms of standard x-y coordinates. Other criteria such as making sure that no two joints have the same identifier or no two joints have the same coordinates can be dealt with at a later date. Forces on frameworks are also applied at joints so these will have force values which will be converted to orthogonal x-y values for solving but this will also be looked at later.
Here's what I created to start with using the basic criteria listed.
public class PointTest {
private int PointNum;
private double XCoord;
private double YCoord;
protected void SetPntNum(int a){this.PointNum=a;}
protected int GetPntNum(){return this.PointNum;}
protected void SetXCoord(double b){this.XCoord=b;}
protected double GetXCoord(){return this.XCoord;}
protected void SetYCoord(double c){this.YCoord=c;}
protected double GetYCoord(){return this.YCoord;}
public void main(String[] args) {
try
{
SetPntNum(Integer.parseInt(args[0]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No arguments. Print error message, then exit with an error code.
System.out.println("No arguments!");
System.exit(1);
}
catch (NumberFormatException nfe)
{
//The first argument is not an integer. Print error message, then exit with an error code.
System.out.println("The first argument must be an integer value.");
System.exit(1);
}
try
{
SetXCoord(Double.parseDouble(args[1]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No argument for angle. Print error message, then exit with an error code.
System.out.println("No x-coordinate argument!");
}
catch (NumberFormatException nfe)
{
//The second argument is not a double. Print error message, then exit with an error code.
System.out.println("The x-coordinate argument must be a double value");
System.exit(1);
}
try
{
SetYCoord(Double.parseDouble(args[2]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No argument for angle. Print error message, then exit with an error code.
System.out.println("No y-coordinate argument!");
}
catch (NumberFormatException nfe)
{
//The third argument is not a double. Print error message, then exit with an error code.
System.out.println("The y-coordinate argument must be a double value");
System.exit(1);
}
System.out.println("Pass!");
}
}
As I have called this class PointTest, save the file as PointTest.java and compile using javac PointTest.java to create the class file.
Structural Members
The structural members are always going to be set between two points. So rather than having multiple complicated inputs at the start, the members are just going to be defined by an integer identifier and the identifiers of each point that the member is connected to. Properties such as length and angle can be derived from each of the points so there is no need to include them right now. Also included is a check that both connection points are not identical, there can be no structural members in the framework of zero length! Additional checks at a later date will include structural members having the same identifiers and having two or more structural members that have the same coordinate points, this will be added at a later date. At a more advanced stage, things like area and material properties can be added in order to determine the movement within any given framework.
However, here's the start of the structural member definition.
public class StructMem {
private int MemNum;
private int Point1;
private int Point2;
protected void SetPnt1(int a){this.Point1=a;}
protected int GetPnt1(){return this.Point1;}
protected void SetPnt2(int b){this.Point2=b;}
protected int GetPnt2(){return this.Point2;}
protected void SetMemNum(int c){this.MemNum=c;}
protected int GetMemNum(){return this.MemNum;}
public void main(String[] args) {
try
{
SetMemNum(Integer.parseInt(args[0]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No arguments. Print error message, then exit with an error code.
System.out.println("No arguments!");
System.exit(1);
}
catch (NumberFormatException nfe)
{
//The first argument is not an integer. Print error message, then exit with an error code.
System.out.println("The first argument must be an integer value.");
System.exit(1);
}
try
{
SetPnt1(Integer.parseInt(args[1]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No arguments. Print error message, then exit with an error code.
System.out.println("No second argument!");
System.exit(1);
}
catch (NumberFormatException nfe)
{
//The second argument is not an integer. Print error message, then exit with an error code.
System.out.println("The second argument must be an integer value.");
System.exit(1);
}
try
{
SetPnt2(Integer.parseInt(args[2]));
}
catch (ArrayIndexOutOfBoundsException nullStr)
{
//No arguments. Print error message, then exit with an error code.
System.out.println("No third argument!");
System.exit(1);
}
catch (NumberFormatException nfe)
{
//The third argument is not an integer. Print error message, then exit with an error code.
System.out.println("The third argument must be an integer value.");
System.exit(1);
}
if (this.GetPnt1()==this.GetPnt2()) {
System.out.println("Points cannot be the same!");
System.exit(1);
}
System.out.println("Pass!");
}
}
Save the file as StructMem.java and compile using javac StructMem.java to create the class file.
Quick overview
As with the force example, these are just making sure that the input values are valid. There is no point moving onto complex solving directly without making sure that the input values are valid, otherwise all hell breaks loose! It also gives plenty of time to think of solution methods.
Again, this is another baby step but the beginnings of all the basic input components of joints, members and forces are all there. These can be refined later, such as creating rigid joints and sliding joints to fix the framework providing the necessary reaction forces and stability.
Mitigation at the beginning lead to fewer surprises later on. It's a good philosopy of design, of software in particular.
Although only a few baby steps have been taken, the design is already forming.