fbitonti
11-21-2006, 04:54 AM
I have been working on this plugin using the api it hasn't given me trouble in the past but I recently added a frew for loops towards the end. I don't get any errors when I complie the code but when I run the plugin from maya I don't get any of the output i specified and i don't know if the command is even running. I'm new to this api stuff so I thougt maybe some one could take a look and see if they know why it's acting like this. Thank you in a advance for any informaion you can give me.
//
// This will be the function that calculates the stiffness matrix.
//
#include <maya/MSimple.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshEdge.h>
#include <maya/MDagPath.h>
#include <stdio.h>
#include <math.h>
DeclareSimpleCommand( stiffnessMatrix, "Francis Bitonti", "1.0" );
MStatus stiffnessMatrix::doIt( const MArgList& args )
{
MStatus stat = MS::kSuccess;
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MDagPath dagPath;
MObject component;
//E modulus of elasticity
int e = 200000;
//A area of section
float a = 4000;
float edgeCount, v0Index, v1Index, edgeIndex;
MPoint v0, v1;
//edgeNodes[edgenumber] followed by [vertexIndes0][vertexIndex1]
//for zero and one is second value
//you will use these values for the assembly process.
float edgeNodes[10000][2];
float freedomDeg[10000][2][2];
float vertexPos[10000][2][3];
float length[10000];
float ls[10000];
float ms[10000];
float stiffMatrix[10000][4][4];
float globalMatrix[10000][10000];
int count;
count = 0;
MString txt;
MItSelectionList iter( selection );
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath( dagPath, component );
MItMeshEdge edgeIter( dagPath, component, &stat );
if( stat == MS::kSuccess )
{
txt += dagPath.fullPathName() + "\n";
edgeCount = edgeIter.count();
txt += MString("# Edges: ") + edgeCount + "\n";
//sort vertext positions
for( ; !edgeIter.isDone(); edgeIter.next() )
{
edgeIndex = edgeIter.index();
v0Index = edgeIter.index(0);
v1Index = edgeIter.index(1);
v0 = edgeIter.point( 0, MSpace::kWorld );
v1 = edgeIter.point( 1, MSpace::kWorld );
//store edges and the nodes they are connected to
edgeNodes[count][0] = v0Index;
edgeNodes[count][1] = v1Index;
//establish degress of freedom for each memeber
freedomDeg[count][0][0] = 2*(edgeNodes[count][0])-1;
freedomDeg[count][0][1] = 2*(edgeNodes[count][0]);
freedomDeg[count][1][0] = 2*(edgeNodes[count][1])-1;
freedomDeg[count][1][1] = 2*(edgeNodes[count][1]);
vertexPos[count][0][1] = (v0.x)*(1000);
vertexPos[count][0][2] = (v0.y)*(1000);
vertexPos[count][0][3] = (v0.z)*(1000);
vertexPos[count][1][1] = (v1.x)*(1000);
vertexPos[count][1][2] = (v1.y)*(1000);
vertexPos[count][1][3] = (v1.z)*(1000);
txt = txt + "Edge " + edgeIndex + ": " +
v0Index + " (" + v0.x + ", " + v0.y + ", " + v0.z + ") " +
v1Index + " (" + v1.x + ", " + v1.y + ", " + v1.z + ")\n\n";
txt = txt + "count =" + count + "\n\n";
txt = txt + "Edge zero " + edgeIndex + "\n " +
"vertex1: x, " + vertexPos[count][0][1] + "y, " + vertexPos[count][0][2] + "z, " + vertexPos[count][0][3] + ") " +
"vertex2: x, " + vertexPos[count][1][1] + "y, " + vertexPos[count][1][2] + "z, " + vertexPos[count][1][3] + ")\n\n";
length[count] = sqrt(pow(vertexPos[count][0][3] - vertexPos[count][1][3],2)+pow(vertexPos[count][0][1] - vertexPos[count][1][1],2));
ls[count] = (vertexPos[count][0][3] - vertexPos[count][1][3])/length[count];
ms[count] = (vertexPos[count][0][1] - vertexPos[count][1][1])/length[count];
count = count+1;
}
}
}
//set global matrix to zero
int z;
int q;
for(z=0; z < count; z++){
for(q=0; q < count; q++){
//calculate row one
globalMatrix[z][q]= 0;
}
}
int i;
for(i=0; i < count + 1; i++){
//calculate stiffness matrix for each element and store in three dimensional array.
//int node1 = edgeNodes[i][0];
int freeVector1 = freedomDeg[i][0][0];
int freeVector2 = freedomDeg[i][0][1];
int freeVector3 = freedomDeg[i][1][0];
int freeVector4 = freedomDeg[i][1][1];
//calculate row one u1
stiffMatrix[i][0][0] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][1][0] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][2][0] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][3][0] = ((e*a)/length[i])*(-ls[i]*ms[i]);
//gloabl matrix for u1
globalMatrix[freeVector1][freeVector1] = stiffMatrix[i][0][0] + globalMatrix[freeVector1][freeVector1];
globalMatrix[freeVector1][freeVector2] = stiffMatrix[i][1][0] + globalMatrix[freeVector1][freeVector2];
globalMatrix[freeVector1][freeVector3] = stiffMatrix[i][2][0] + globalMatrix[freeVector1][freeVector3];
globalMatrix[freeVector1][freeVector4] = stiffMatrix[i][3][0] + globalMatrix[freeVector1][freeVector4];
//calculate row two v1
stiffMatrix[i][0][1] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][1][1] = ((e*a)/length[i])*(pow(ms[i],2));
stiffMatrix[i][2][1] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][3][1] = ((e*a)/length[i])*(-pow(ms[i],2));
//gloabl matrix for v1
globalMatrix[freeVector2][freeVector1] = stiffMatrix[i][0][1] + globalMatrix[freeVector2][freeVector1];
globalMatrix[freeVector2][freeVector2] = stiffMatrix[i][1][1] + globalMatrix[freeVector2][freeVector2];
globalMatrix[freeVector2][freeVector3] = stiffMatrix[i][2][1] + globalMatrix[freeVector2][freeVector3];
globalMatrix[freeVector2][freeVector4] = stiffMatrix[i][3][1] + globalMatrix[freeVector2][freeVector4];
//calculate row three u2
stiffMatrix[i][0][2] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][1][2] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][2][2] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][3][2] = ((e*a)/length[i])*(ls[i]*ms[i]);
//gloabl matrix for u2
globalMatrix[freeVector3][freeVector1] = stiffMatrix[i][0][2] + globalMatrix[freeVector3][freeVector1];
globalMatrix[freeVector3][freeVector2] = stiffMatrix[i][1][2] + globalMatrix[freeVector3][freeVector2];
globalMatrix[freeVector3][freeVector3] = stiffMatrix[i][2][2] + globalMatrix[freeVector3][freeVector3];
globalMatrix[freeVector3][freeVector4] = stiffMatrix[i][3][2] + globalMatrix[freeVector3][freeVector4];
//calculate row four v2
stiffMatrix[i][0][3] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][1][3] = ((e*a)/length[i])*(-pow(ms[i],2));
stiffMatrix[i][2][3] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][3][3] = ((e*a)/length[i])*(pow(ms[i],2));
//gloabl matrix for v2
globalMatrix[freeVector4][freeVector1] = stiffMatrix[i][0][3] + globalMatrix[freeVector4][freeVector1];
globalMatrix[freeVector4][freeVector2] = stiffMatrix[i][1][3] + globalMatrix[freeVector4][freeVector2];
globalMatrix[freeVector4][freeVector3] = stiffMatrix[i][2][3] + globalMatrix[freeVector4][freeVector3];
globalMatrix[freeVector4][freeVector4] = stiffMatrix[i][3][3] + globalMatrix[freeVector4][freeVector4];
}
//print global matrix
int g;
int h;
for(g=0; g < count; g++){
for(h=0; h < count; h++){
txt = txt + globalMatrix[g][h] + "\n";
}
}
//print local matrix
int w;
for(w=0; w < count; w++){
//this text is for testing against the book example.
txt = txt + " x2 " + vertexPos[w][0][3] + " x1 " + vertexPos[w][1][3] + " y2 " + vertexPos[w][0][1] + " y1 " + vertexPos[w][1][1] + "\n\n";
txt = txt + "length of member zero is" + length[w] + "\n\n";
txt = txt + "ls of member zero is" + ls[w] + "\n\n";
txt = txt + "ms of member zero is" + ms[w] + "\n\n";
txt = txt + "stiffness matrix for element three" + "\n";
txt = txt + stiffMatrix[w][0][0] + "\n";
txt = txt + stiffMatrix[w][1][0] + "\n";
txt = txt + stiffMatrix[w][2][0] + "\n";
txt = txt + stiffMatrix[w][3][0] + "\n";
txt = txt + stiffMatrix[w][0][1] + "\n";
txt = txt + stiffMatrix[w][1][1] + "\n";
txt = txt + stiffMatrix[w][2][1] + "\n";
txt = txt + stiffMatrix[w][3][1] + "\n";
txt = txt + stiffMatrix[w][0][2] + "\n";
txt = txt + stiffMatrix[w][1][2] + "\n";
txt = txt + stiffMatrix[w][2][2] + "\n";
txt = txt + stiffMatrix[w][3][2] + "\n";
txt = txt + stiffMatrix[w][0][3] + "\n";
txt = txt + stiffMatrix[w][1][3] + "\n";
txt = txt + stiffMatrix[w][2][3] + "\n";
txt = txt + stiffMatrix[w][3][3] + "\n";
}
MGlobal::displayInfo( txt );
return MS::kSuccess;
}
This is the one that works
//
// This will be the function that calculates the stiffness matrix.
//
#include <maya/MSimple.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshEdge.h>
#include <maya/MDagPath.h>
#include <stdio.h>
#include <math.h>
DeclareSimpleCommand( stiffnessMatrix, "Francis Bitonti", "1.0" );
MStatus stiffnessMatrix::doIt( const MArgList& args )
{
MStatus stat = MS::kSuccess;
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MDagPath dagPath;
MObject component;
//E modulus of elasticity
int e = 200000;
//A area of section
float a = 4000;
float edgeCount, v0Index, v1Index, edgeIndex;
MPoint v0, v1;
//edgeNodes[edgenumber] followed by [vertexIndes0][vertexIndex1]
//for zero and one is second value
//you will use these values for the assembly process.
float edgeNodes[10000][2];
float vertexPos[10000][2][3];
float length[10000];
float ls[10000];
float ms[10000];
float stiffMatrix[10000][4][4];
int count;
count = 0;
MString txt;
MItSelectionList iter( selection );
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath( dagPath, component );
MItMeshEdge edgeIter( dagPath, component, &stat );
if( stat == MS::kSuccess )
{
txt += dagPath.fullPathName() + "\n";
edgeCount = edgeIter.count();
txt += MString("# Edges: ") + edgeCount + "\n";
//sort vertext positions
for( ; !edgeIter.isDone(); edgeIter.next() )
{
edgeIndex = edgeIter.index();
v0Index = edgeIter.index(0);
v1Index = edgeIter.index(1);
v0 = edgeIter.point( 0, MSpace::kWorld );
v1 = edgeIter.point( 1, MSpace::kWorld );
//store edges and the nodes they are connected to
edgeNodes[count][0] = v0Index;
edgeNodes[count][1] = v1Index;
vertexPos[count][0][1] = (v0.x)*(1000);
vertexPos[count][0][2] = (v0.y)*(1000);
vertexPos[count][0][3] = (v0.z)*(1000);
vertexPos[count][1][1] = (v1.x)*(1000);
vertexPos[count][1][2] = (v1.y)*(1000);
vertexPos[count][1][3] = (v1.z)*(1000);
txt = txt + "Edge " + edgeIndex + ": " +
v0Index + " (" + v0.x + ", " + v0.y + ", " + v0.z + ") " +
v1Index + " (" + v1.x + ", " + v1.y + ", " + v1.z + ")\n\n";
txt = txt + "count =" + count + "\n\n";
txt = txt + "Edge zero " + edgeIndex + "\n " +
"vertex1: x, " + vertexPos[count][0][1] + "y, " + vertexPos[count][0][2] + "z, " + vertexPos[count][0][3] + ") " +
"vertex2: x, " + vertexPos[count][1][1] + "y, " + vertexPos[count][1][2] + "z, " + vertexPos[count][1][3] + ")\n\n";
length[count] = sqrt(pow(vertexPos[count][0][3] - vertexPos[count][1][3],2)+pow(vertexPos[count][0][1] - vertexPos[count][1][1],2));
ls[count] = (vertexPos[count][0][3] - vertexPos[count][1][3])/length[count];
ms[count] = (vertexPos[count][0][1] - vertexPos[count][1][1])/length[count];
count = count+1;
}
}
}
//this text is for testing against the book example.
txt = txt + " x2 " + vertexPos[3][0][3] + " x1 " + vertexPos[3][1][3] + " y2 " + vertexPos[3][0][1] + " y1 " + vertexPos[3][1][1] + "\n\n";
txt = txt + "length of member zero is" + length[3] + "\n\n";
txt = txt + "ls of member zero is" + ls[3] + "\n\n";
txt = txt + "ms of member zero is" + ms[3] + "\n\n";
//calculate stiffness matrix for each element and store in three dimensional array.
int i;
for(i=0; i < count; i++){
//calculate row one u1
stiffMatrix[i][0][0] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][1][0] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][2][0] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][3][0] = ((e*a)/length[i])*(-ls[i]*ms[i]);
//calculate row two v1
stiffMatrix[i][0][1] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][1][1] = ((e*a)/length[i])*(pow(ms[i],2));
stiffMatrix[i][2][1] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][3][1] = ((e*a)/length[i])*(-pow(ms[i],2));
//calculate row three u2
stiffMatrix[i][0][2] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][1][2] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][2][2] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][3][2] = ((e*a)/length[i])*(ls[i]*ms[i]);
//calculate row four v2
stiffMatrix[i][0][3] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][1][3] = ((e*a)/length[i])*(-pow(ms[i],2));
stiffMatrix[i][2][3] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][3][3] = ((e*a)/length[i])*(pow(ms[i],2));
}
//this text is for testing against the book example.
txt = txt + "stiffness matrix for element three" + "\n";
txt = txt + stiffMatrix[3][0][0] + "\n";
txt = txt + stiffMatrix[3][1][0] + "\n";
txt = txt + stiffMatrix[3][2][0] + "\n";
txt = txt + stiffMatrix[3][3][0] + "\n";
txt = txt + stiffMatrix[3][0][1] + "\n";
txt = txt + stiffMatrix[3][1][1] + "\n";
txt = txt + stiffMatrix[3][2][1] + "\n";
txt = txt + stiffMatrix[3][3][1] + "\n";
txt = txt + stiffMatrix[3][0][2] + "\n";
txt = txt + stiffMatrix[3][1][2] + "\n";
txt = txt + stiffMatrix[3][2][2] + "\n";
txt = txt + stiffMatrix[3][3][2] + "\n";
txt = txt + stiffMatrix[3][0][3] + "\n";
txt = txt + stiffMatrix[3][1][3] + "\n";
txt = txt + stiffMatrix[3][2][3] + "\n";
txt = txt + stiffMatrix[3][3][3] + "\n";
MGlobal::displayInfo( txt );
return MS::kSuccess;
}
//
// This will be the function that calculates the stiffness matrix.
//
#include <maya/MSimple.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshEdge.h>
#include <maya/MDagPath.h>
#include <stdio.h>
#include <math.h>
DeclareSimpleCommand( stiffnessMatrix, "Francis Bitonti", "1.0" );
MStatus stiffnessMatrix::doIt( const MArgList& args )
{
MStatus stat = MS::kSuccess;
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MDagPath dagPath;
MObject component;
//E modulus of elasticity
int e = 200000;
//A area of section
float a = 4000;
float edgeCount, v0Index, v1Index, edgeIndex;
MPoint v0, v1;
//edgeNodes[edgenumber] followed by [vertexIndes0][vertexIndex1]
//for zero and one is second value
//you will use these values for the assembly process.
float edgeNodes[10000][2];
float freedomDeg[10000][2][2];
float vertexPos[10000][2][3];
float length[10000];
float ls[10000];
float ms[10000];
float stiffMatrix[10000][4][4];
float globalMatrix[10000][10000];
int count;
count = 0;
MString txt;
MItSelectionList iter( selection );
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath( dagPath, component );
MItMeshEdge edgeIter( dagPath, component, &stat );
if( stat == MS::kSuccess )
{
txt += dagPath.fullPathName() + "\n";
edgeCount = edgeIter.count();
txt += MString("# Edges: ") + edgeCount + "\n";
//sort vertext positions
for( ; !edgeIter.isDone(); edgeIter.next() )
{
edgeIndex = edgeIter.index();
v0Index = edgeIter.index(0);
v1Index = edgeIter.index(1);
v0 = edgeIter.point( 0, MSpace::kWorld );
v1 = edgeIter.point( 1, MSpace::kWorld );
//store edges and the nodes they are connected to
edgeNodes[count][0] = v0Index;
edgeNodes[count][1] = v1Index;
//establish degress of freedom for each memeber
freedomDeg[count][0][0] = 2*(edgeNodes[count][0])-1;
freedomDeg[count][0][1] = 2*(edgeNodes[count][0]);
freedomDeg[count][1][0] = 2*(edgeNodes[count][1])-1;
freedomDeg[count][1][1] = 2*(edgeNodes[count][1]);
vertexPos[count][0][1] = (v0.x)*(1000);
vertexPos[count][0][2] = (v0.y)*(1000);
vertexPos[count][0][3] = (v0.z)*(1000);
vertexPos[count][1][1] = (v1.x)*(1000);
vertexPos[count][1][2] = (v1.y)*(1000);
vertexPos[count][1][3] = (v1.z)*(1000);
txt = txt + "Edge " + edgeIndex + ": " +
v0Index + " (" + v0.x + ", " + v0.y + ", " + v0.z + ") " +
v1Index + " (" + v1.x + ", " + v1.y + ", " + v1.z + ")\n\n";
txt = txt + "count =" + count + "\n\n";
txt = txt + "Edge zero " + edgeIndex + "\n " +
"vertex1: x, " + vertexPos[count][0][1] + "y, " + vertexPos[count][0][2] + "z, " + vertexPos[count][0][3] + ") " +
"vertex2: x, " + vertexPos[count][1][1] + "y, " + vertexPos[count][1][2] + "z, " + vertexPos[count][1][3] + ")\n\n";
length[count] = sqrt(pow(vertexPos[count][0][3] - vertexPos[count][1][3],2)+pow(vertexPos[count][0][1] - vertexPos[count][1][1],2));
ls[count] = (vertexPos[count][0][3] - vertexPos[count][1][3])/length[count];
ms[count] = (vertexPos[count][0][1] - vertexPos[count][1][1])/length[count];
count = count+1;
}
}
}
//set global matrix to zero
int z;
int q;
for(z=0; z < count; z++){
for(q=0; q < count; q++){
//calculate row one
globalMatrix[z][q]= 0;
}
}
int i;
for(i=0; i < count + 1; i++){
//calculate stiffness matrix for each element and store in three dimensional array.
//int node1 = edgeNodes[i][0];
int freeVector1 = freedomDeg[i][0][0];
int freeVector2 = freedomDeg[i][0][1];
int freeVector3 = freedomDeg[i][1][0];
int freeVector4 = freedomDeg[i][1][1];
//calculate row one u1
stiffMatrix[i][0][0] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][1][0] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][2][0] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][3][0] = ((e*a)/length[i])*(-ls[i]*ms[i]);
//gloabl matrix for u1
globalMatrix[freeVector1][freeVector1] = stiffMatrix[i][0][0] + globalMatrix[freeVector1][freeVector1];
globalMatrix[freeVector1][freeVector2] = stiffMatrix[i][1][0] + globalMatrix[freeVector1][freeVector2];
globalMatrix[freeVector1][freeVector3] = stiffMatrix[i][2][0] + globalMatrix[freeVector1][freeVector3];
globalMatrix[freeVector1][freeVector4] = stiffMatrix[i][3][0] + globalMatrix[freeVector1][freeVector4];
//calculate row two v1
stiffMatrix[i][0][1] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][1][1] = ((e*a)/length[i])*(pow(ms[i],2));
stiffMatrix[i][2][1] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][3][1] = ((e*a)/length[i])*(-pow(ms[i],2));
//gloabl matrix for v1
globalMatrix[freeVector2][freeVector1] = stiffMatrix[i][0][1] + globalMatrix[freeVector2][freeVector1];
globalMatrix[freeVector2][freeVector2] = stiffMatrix[i][1][1] + globalMatrix[freeVector2][freeVector2];
globalMatrix[freeVector2][freeVector3] = stiffMatrix[i][2][1] + globalMatrix[freeVector2][freeVector3];
globalMatrix[freeVector2][freeVector4] = stiffMatrix[i][3][1] + globalMatrix[freeVector2][freeVector4];
//calculate row three u2
stiffMatrix[i][0][2] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][1][2] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][2][2] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][3][2] = ((e*a)/length[i])*(ls[i]*ms[i]);
//gloabl matrix for u2
globalMatrix[freeVector3][freeVector1] = stiffMatrix[i][0][2] + globalMatrix[freeVector3][freeVector1];
globalMatrix[freeVector3][freeVector2] = stiffMatrix[i][1][2] + globalMatrix[freeVector3][freeVector2];
globalMatrix[freeVector3][freeVector3] = stiffMatrix[i][2][2] + globalMatrix[freeVector3][freeVector3];
globalMatrix[freeVector3][freeVector4] = stiffMatrix[i][3][2] + globalMatrix[freeVector3][freeVector4];
//calculate row four v2
stiffMatrix[i][0][3] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][1][3] = ((e*a)/length[i])*(-pow(ms[i],2));
stiffMatrix[i][2][3] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][3][3] = ((e*a)/length[i])*(pow(ms[i],2));
//gloabl matrix for v2
globalMatrix[freeVector4][freeVector1] = stiffMatrix[i][0][3] + globalMatrix[freeVector4][freeVector1];
globalMatrix[freeVector4][freeVector2] = stiffMatrix[i][1][3] + globalMatrix[freeVector4][freeVector2];
globalMatrix[freeVector4][freeVector3] = stiffMatrix[i][2][3] + globalMatrix[freeVector4][freeVector3];
globalMatrix[freeVector4][freeVector4] = stiffMatrix[i][3][3] + globalMatrix[freeVector4][freeVector4];
}
//print global matrix
int g;
int h;
for(g=0; g < count; g++){
for(h=0; h < count; h++){
txt = txt + globalMatrix[g][h] + "\n";
}
}
//print local matrix
int w;
for(w=0; w < count; w++){
//this text is for testing against the book example.
txt = txt + " x2 " + vertexPos[w][0][3] + " x1 " + vertexPos[w][1][3] + " y2 " + vertexPos[w][0][1] + " y1 " + vertexPos[w][1][1] + "\n\n";
txt = txt + "length of member zero is" + length[w] + "\n\n";
txt = txt + "ls of member zero is" + ls[w] + "\n\n";
txt = txt + "ms of member zero is" + ms[w] + "\n\n";
txt = txt + "stiffness matrix for element three" + "\n";
txt = txt + stiffMatrix[w][0][0] + "\n";
txt = txt + stiffMatrix[w][1][0] + "\n";
txt = txt + stiffMatrix[w][2][0] + "\n";
txt = txt + stiffMatrix[w][3][0] + "\n";
txt = txt + stiffMatrix[w][0][1] + "\n";
txt = txt + stiffMatrix[w][1][1] + "\n";
txt = txt + stiffMatrix[w][2][1] + "\n";
txt = txt + stiffMatrix[w][3][1] + "\n";
txt = txt + stiffMatrix[w][0][2] + "\n";
txt = txt + stiffMatrix[w][1][2] + "\n";
txt = txt + stiffMatrix[w][2][2] + "\n";
txt = txt + stiffMatrix[w][3][2] + "\n";
txt = txt + stiffMatrix[w][0][3] + "\n";
txt = txt + stiffMatrix[w][1][3] + "\n";
txt = txt + stiffMatrix[w][2][3] + "\n";
txt = txt + stiffMatrix[w][3][3] + "\n";
}
MGlobal::displayInfo( txt );
return MS::kSuccess;
}
This is the one that works
//
// This will be the function that calculates the stiffness matrix.
//
#include <maya/MSimple.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshEdge.h>
#include <maya/MDagPath.h>
#include <stdio.h>
#include <math.h>
DeclareSimpleCommand( stiffnessMatrix, "Francis Bitonti", "1.0" );
MStatus stiffnessMatrix::doIt( const MArgList& args )
{
MStatus stat = MS::kSuccess;
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MDagPath dagPath;
MObject component;
//E modulus of elasticity
int e = 200000;
//A area of section
float a = 4000;
float edgeCount, v0Index, v1Index, edgeIndex;
MPoint v0, v1;
//edgeNodes[edgenumber] followed by [vertexIndes0][vertexIndex1]
//for zero and one is second value
//you will use these values for the assembly process.
float edgeNodes[10000][2];
float vertexPos[10000][2][3];
float length[10000];
float ls[10000];
float ms[10000];
float stiffMatrix[10000][4][4];
int count;
count = 0;
MString txt;
MItSelectionList iter( selection );
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath( dagPath, component );
MItMeshEdge edgeIter( dagPath, component, &stat );
if( stat == MS::kSuccess )
{
txt += dagPath.fullPathName() + "\n";
edgeCount = edgeIter.count();
txt += MString("# Edges: ") + edgeCount + "\n";
//sort vertext positions
for( ; !edgeIter.isDone(); edgeIter.next() )
{
edgeIndex = edgeIter.index();
v0Index = edgeIter.index(0);
v1Index = edgeIter.index(1);
v0 = edgeIter.point( 0, MSpace::kWorld );
v1 = edgeIter.point( 1, MSpace::kWorld );
//store edges and the nodes they are connected to
edgeNodes[count][0] = v0Index;
edgeNodes[count][1] = v1Index;
vertexPos[count][0][1] = (v0.x)*(1000);
vertexPos[count][0][2] = (v0.y)*(1000);
vertexPos[count][0][3] = (v0.z)*(1000);
vertexPos[count][1][1] = (v1.x)*(1000);
vertexPos[count][1][2] = (v1.y)*(1000);
vertexPos[count][1][3] = (v1.z)*(1000);
txt = txt + "Edge " + edgeIndex + ": " +
v0Index + " (" + v0.x + ", " + v0.y + ", " + v0.z + ") " +
v1Index + " (" + v1.x + ", " + v1.y + ", " + v1.z + ")\n\n";
txt = txt + "count =" + count + "\n\n";
txt = txt + "Edge zero " + edgeIndex + "\n " +
"vertex1: x, " + vertexPos[count][0][1] + "y, " + vertexPos[count][0][2] + "z, " + vertexPos[count][0][3] + ") " +
"vertex2: x, " + vertexPos[count][1][1] + "y, " + vertexPos[count][1][2] + "z, " + vertexPos[count][1][3] + ")\n\n";
length[count] = sqrt(pow(vertexPos[count][0][3] - vertexPos[count][1][3],2)+pow(vertexPos[count][0][1] - vertexPos[count][1][1],2));
ls[count] = (vertexPos[count][0][3] - vertexPos[count][1][3])/length[count];
ms[count] = (vertexPos[count][0][1] - vertexPos[count][1][1])/length[count];
count = count+1;
}
}
}
//this text is for testing against the book example.
txt = txt + " x2 " + vertexPos[3][0][3] + " x1 " + vertexPos[3][1][3] + " y2 " + vertexPos[3][0][1] + " y1 " + vertexPos[3][1][1] + "\n\n";
txt = txt + "length of member zero is" + length[3] + "\n\n";
txt = txt + "ls of member zero is" + ls[3] + "\n\n";
txt = txt + "ms of member zero is" + ms[3] + "\n\n";
//calculate stiffness matrix for each element and store in three dimensional array.
int i;
for(i=0; i < count; i++){
//calculate row one u1
stiffMatrix[i][0][0] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][1][0] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][2][0] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][3][0] = ((e*a)/length[i])*(-ls[i]*ms[i]);
//calculate row two v1
stiffMatrix[i][0][1] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][1][1] = ((e*a)/length[i])*(pow(ms[i],2));
stiffMatrix[i][2][1] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][3][1] = ((e*a)/length[i])*(-pow(ms[i],2));
//calculate row three u2
stiffMatrix[i][0][2] = ((e*a)/length[i])*(-pow(ls[i],2));
stiffMatrix[i][1][2] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][2][2] = ((e*a)/length[i])*(pow(ls[i],2));
stiffMatrix[i][3][2] = ((e*a)/length[i])*(ls[i]*ms[i]);
//calculate row four v2
stiffMatrix[i][0][3] = ((e*a)/length[i])*(-ls[i]*ms[i]);
stiffMatrix[i][1][3] = ((e*a)/length[i])*(-pow(ms[i],2));
stiffMatrix[i][2][3] = ((e*a)/length[i])*(ls[i]*ms[i]);
stiffMatrix[i][3][3] = ((e*a)/length[i])*(pow(ms[i],2));
}
//this text is for testing against the book example.
txt = txt + "stiffness matrix for element three" + "\n";
txt = txt + stiffMatrix[3][0][0] + "\n";
txt = txt + stiffMatrix[3][1][0] + "\n";
txt = txt + stiffMatrix[3][2][0] + "\n";
txt = txt + stiffMatrix[3][3][0] + "\n";
txt = txt + stiffMatrix[3][0][1] + "\n";
txt = txt + stiffMatrix[3][1][1] + "\n";
txt = txt + stiffMatrix[3][2][1] + "\n";
txt = txt + stiffMatrix[3][3][1] + "\n";
txt = txt + stiffMatrix[3][0][2] + "\n";
txt = txt + stiffMatrix[3][1][2] + "\n";
txt = txt + stiffMatrix[3][2][2] + "\n";
txt = txt + stiffMatrix[3][3][2] + "\n";
txt = txt + stiffMatrix[3][0][3] + "\n";
txt = txt + stiffMatrix[3][1][3] + "\n";
txt = txt + stiffMatrix[3][2][3] + "\n";
txt = txt + stiffMatrix[3][3][3] + "\n";
MGlobal::displayInfo( txt );
return MS::kSuccess;
}
