SUMMARY OF TECHNICAL DETAILS OF SOURCE CODE

SUMMARY OF TECHNICAL DETAILS OF SOURCE CODE

In this section source code of the module (Named as 2D Truss designer) is briefly described. This module contains following 14 Java files. Flow chart describes program flow more clearly

  1. PinApp.java
  2. AboutDialog.java
  3. CreateDia.java
  4. FrceComFrm.java
  5. MemProFrm.java
  6. NodeFrm.java
  7. ResFrm.java
  8. QuitDialog.java
  9. GlobalSystem.java
  10. TrussRun.java
  11. ViewPanel.java
  12. Element.java
  13. WarningDia.java
  14. Matrix.java

These modules can be categorized into 2 main types according to their functions. They are,

a. Computational modules

These modules handle calculation-oriented parts like stiffness matrix formulation, finding the inverse matrix etc. Element.java,GlobalSystem.java are these.

b. Interface modules

These modules provide Graphical user interface (GUI) facilities. All the other modules except the above-mentioned come under this category. However some of these serves as both computational and interface modules. PinApp.java and FrceComFrm.java are good examples for these kinds of modules.

Following code Element.java calculates the element stiffness matrix.

//Element.java

import java.awt.*;

import java.applet.*;

import java.util.Vector;

public class Element {

double k[][] = new double[4][4]; // local element stiffness

double x1,y1,x2,y2; // co-ordinates

double AE; // Area multiplied by Modulus

double L; // length of element

double c,s; // cosine and sine of direction of element

int node1,node2; // global node numbers for element

public Element(int myNode1, int myNode2, double myX1, double myY1, double myX2, double myY2, double myAE) {

int i,j;

node1 = myNode1;

node2 = myNode2;

x1 = (double)myX1;

y1 = (double)myY1;

x2 = (double)myX2;

y2 = (double)myY2;

AE = (double)myAE;

L = Math.pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),0.5);

c = (x2-x1)/L;

s = (y2-y1)/L;

// Now make local stiffness matrix

k[0][0]=c*c; k[0][1]=c*s; k[0][2]=-c*c; k[0][3]=-c*s;

k[1][0]=c*s; k[1][1]=s*s; k[1][2]=-c*s; k[1][3]=-s*s;

k[2][0]=-c*c; k[2][1]=-c*s; k[2][2]=c*c; k[2][3]=c*s;

k[3][0]=-c*s; k[3][1]=-s*s; k[3][2]=c*s; k[3][3]=s*s;

 

// Now multiply the matrix by AE/L

for (i=0;i<4;i++) {

for (j=0;j<4;j++) {

k[i][j] = k[i][j] * AE/L;

}

}

 

}

}

The module GlobalSystem.java calculates the structure stiffness matrix and reduces (Striking procedure) it to the required size and then solves it by using F=K.d, where K is the reduced matrix (for which all the known displacements are eliminated) and d is the displacement vector. First by calling the method GlobalSystem(int myDim) it initialises the structure stiffness matrix and assigns them zero (for safety precaution). Here myDim is number of nodes times two, since there are two degrees of freedom for each node.

public GlobalSystem(int myDim) {

dim = myDim;

globalK = new double[dim][dim];

force = new double[dim][dim];

disp = new double[dim][dim];

realdisp = new double[dim];

reducedIndex = new int[dim];

// Set all values to zero initially in global stiffness

for (int i=0;i<dim;i++) {

for (int j=0;j<dim;j++) {

globalK[i][j] = 0.0;

force[i][j] = 0.0;

}

}

}

 

In the addForce method it initialises force vector. It gives the force in x direction, y direction respectively.

public void addForce(double myForce[]) {

for (int i = 0; i<dim ;i++) {

force[i][0] = myForce[i];

}

}

In the addtoK(Element localElement) method it add the member stiffness matrix created by Element.java to structure stiffness matrix. Element is a new type of variable defined by Element.java(which was already mentioned in this discussion). This variable actually denotes the member information. This type has the following structure

Element.node1 – particular element’s first node’s number

Element.node2 – particular element’s second node’s number

Element.x1 – particular elements first node’s x co-ordinate

Element.y1 – particular elements first node’s y co-ordinate

Element.x2 – particular elements second node’s x co-ordinate

Element.y2 – particular elements second node’s y co-ordinate

Element.AE - particular elements Area, Young modulus product

To position member stiffness matrix in the structure stiffness matrix element node number times two minus one or two used. By this way for each two nodes two combination results into four places in the structure stiffness matrix.

public void addtoK(Element localElement) {

int dof[] = new int[4];

//calculate each elements stiffness matrix in structure

dof[0] = localElement.node1*2-2;

dof[1] = localElement.node1*2-1;

dof[2] = localElement.node2*2-2;

dof[3] = localElement.node2*2-1;

// Put local stiffness into structure

for (int i=0;i<4;i++) {

for (int j=0;j<4;j++) {

globalK[dof[i]][dof[j]] += localElement.k[i][j];

}

}

}

makeReducedIndex(int boundary[]) is most important part of the program. This part does the striking off of the stiffness matrix. It is very similar to manual method we are using with the simple structures (small stiffness matrices).

…Equation 1

In the above let d1 and d2 zero. Then the manual procedure to solve this will be as follows,

…Equation 2

Then it reduces to

…Equation 3

This is in the form of f=k.d and f is known and k is known. Therefore by finding k-1 [1] the equation can be solved for unknown displacement d. Then by substituting these known displacements in equation 1, entire system can be solved. However this gets complicated if matrices become big and striking off becomes more difficult if the known displacements are distributed here and there in the structure stiffness matrix. This is where machines come into scene. In this method makeReducedIndex(int boundary[]) as boundary[] integer array displacement restraints are sent into the method. If the displacement is restrained at particular node in particular direction then it is assigned as –1. Otherwise it is assigned as 1. This part was actually done in the ResFrm.java. In this method according to this –1 or 1 condition striking of process is done.

public void makeReducedIndex(int boundary[]) {

int prescribedIndex = -1;

int nonPrescribedIndex = -1;

for (int i=0;i<dim;i++) {

if (boundary[i] < 0 ) { // boundary node

numOfBound++; //calculates the no of boundaries which subjected to restraints

prescribedIndex--;

reducedIndex[i] = prescribedIndex;//determines the position of the number in the newly formed reduced stiffness matrix

} else {

nonPrescribedIndex++;

reducedIndex[i] = nonPrescribedIndex;

}

}

reducedK = new double[dim-numOfBound][dim-numOfBound];

reducedForce = new double[dim-numOfBound][dim-numOfBound];

}

Following method reduceDown() of code assigns the reduced down matrix.

public void reduceDown() {

for (int i=0;i<dim;i++) {

for(int j=0;j<dim;j++) {

if (reducedIndex[i] > -1 && reducedIndex[j] > -1) {

reducedK[reducedIndex[i]][reducedIndex[j]]=globalK[i][j];

reducedForce[reducedIndex[i]][0]=force[i][0];

}

}

}

}

solveThisSystem() method solves reduced stiffness matrix equation, which is very similar to equation 3, described above.

public void solveThisSystem() {

disp = Matrix.multiply(Matrix.invert(reducedK),reducedForce);

//solves the reduced stiffness matrix equation

int count=0;

for (int i=0;i<dim;i++) {

if (reducedIndex[i] > -1) {

realdisp[i]=disp[count][0];

count++;

} else realdisp[i]=0;

//assigns the solved displacement values to the global displacement vector

}

}

}

PinApp.java is the main module involved integrates everthing into single application. It enables the user to do graphical input or as a text input as necessary.

Following method takes the keyboard input (which were already entered in the specified text boxes by the user) on the click event of "Add members button".

/**

* On mouse click event

* takes node's information

*/

void AddPointBtn_Clicked(Event event) {

int node =Integer.parseInt(textField4.getText().trim());

NoOfClick = node;

if(node <NoOfNode){

NodeInfo[node][0]=node;

NodeInfo[node][1]=Double.valueOf(textField3.getText().trim()).doubleValue();//x -cord

NodeInfo[node][2]=Double.valueOf(textField5.getText().trim()).doubleValue();//y -cord

NodeList.clear();

for(int i = 1; i < NoOfNode; i++)

{

if( (int)NodeInfo[i][0] != 0)

NodeList.addItem(" "+ i+" "+ NodeInfo[i][1]

+" " +NodeInfo[i][2]) ;

}

textField4.setText("0");

MyVp.Send(NodeInfo);

MyVp.repaint();

NoOfClick++;

}

else

{

//this displays the warning dialog message if node numbers exceeded the initially allocated.

WarningDia.resize(250,80);

WarningDia.setTit("You can not add more Node ");

WarningDia.show();

}

}

 

 

REFERENCES

  1. William H.Press, Soul A.Teukalsky, Willia T. Veterling, Brian P.Flannery, "Numerical recipes in C", Cambridge University Press, 1992,Second edition.