⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node.cpp

📁 一个计算悬臂梁的有限元vc源码
💻 CPP
字号:
// Node.cpp: implementation of the CNode class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "afxtempl.h"
#include "fstream.h"
#include "Node.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#define TWO_DOF		0
#define THREE_DOF	1	

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CNode::CNode()
{

}

CNode::~CNode()
{

}

void CNode::Initial()
{
	m_aiConstrainedNode.RemoveAll();
	m_aiIsFixedX.RemoveAll();
	m_aiIsFixedY.RemoveAll();
	m_aiIsFixedR.RemoveAll();
	m_adX.RemoveAll();
	m_adY.RemoveAll();
	m_adCurX.RemoveAll();
	m_adCurY.RemoveAll();
	m_adCurR.RemoveAll();
	m_aiXDOFIndex.RemoveAll();
	m_aiYDOFIndex.RemoveAll();
	m_aiRDOFIndex.RemoveAll();
	m_aiType.RemoveAll();
}

void CNode::SetNum(int nNode)
{
	m_nNode=nNode;
	m_adX.SetSize(m_nNode);
	m_adY.SetSize(m_nNode);

	m_adCurX.SetSize(m_nNode);
	m_adCurY.SetSize(m_nNode);
	m_adCurR.SetSize(m_nNode);

	for(int loop=0;loop<m_nNode;loop++)
		m_adCurR[loop]=0.0;
	
	m_aiXDOFIndex.SetSize(m_nNode);
	m_aiYDOFIndex.SetSize(m_nNode);
	m_aiRDOFIndex.SetSize(m_nNode);

	m_aiType.SetSize(m_nNode);
}

void CNode::SetType(int iIndex,int iType)
{
	m_aiType[iIndex]=iType;
}

void CNode::SetNodeX(int iIndex, double dX)
{
	m_adCurX[iIndex]=m_adX[iIndex]=dX;
}

void CNode::SetNodeY(int iIndex, double dY)
{
	m_adCurY[iIndex]=m_adY[iIndex]=dY;
}

double CNode::GetX(int iIndex)
{
	return m_adX[iIndex];
}

double CNode::GetY(int iIndex)
{
	return m_adY[iIndex];
}

double CNode::GetCurX(int iIndex)
{
	return m_adCurX[iIndex];
}

double CNode::GetCurY(int iIndex)
{
	return m_adCurY[iIndex];
}

double CNode::GetCurR(int iIndex)
{
	return m_adCurR[iIndex];
}

int CNode::GetTotalDOF()
{
	return m_nTotalDOF;
}

int CNode::GetFreeDOF()
{
	return m_nFreeDOF;
}

int CNode::GetXDOFIndex(int iNode)
{
	return m_aiXDOFIndex[iNode];
}

int CNode::GetYDOFIndex(int iNode)
{
	return m_aiYDOFIndex[iNode];
}

int CNode::GetRDOFIndex(int iNode)
{
	return m_aiRDOFIndex[iNode];
}


void CNode::SetConstrainedNodeDescription(int iNode,int iIsFixedX,int iIsFixedY,int iIsFixedR)
{
	m_aiConstrainedNode.Add(iNode);
	m_aiIsFixedX.Add(iIsFixedX);
	m_aiIsFixedY.Add(iIsFixedY);
	m_aiIsFixedR.Add(iIsFixedR);	
}


void CNode::CalcuDOFIndex()
{
	int loop,iBuf,iDOFIndex;
	int iNode;
	int nConstrainedNode,nConstrainedDOF;

	m_nTotalDOF=0;
	for(loop=0;loop<m_nNode;loop++){
		if(m_aiType[loop]==TWO_DOF){
			m_nTotalDOF+=2;
		}
		else{
			m_nTotalDOF+=3;
		}
	}

	for(loop=0;loop<m_nNode;loop++){
		m_aiXDOFIndex[loop]=0;
		m_aiYDOFIndex[loop]=0;
		m_aiRDOFIndex[loop]=0;
	}

	nConstrainedDOF=0;
	nConstrainedNode=m_aiConstrainedNode.GetSize();
	for(loop=0;loop<nConstrainedNode;loop++){
		iNode=m_aiConstrainedNode[loop];
		if(m_aiType[iNode]==TWO_DOF){
			m_aiXDOFIndex[iNode]=-m_aiIsFixedX[loop];
			m_aiYDOFIndex[iNode]=-m_aiIsFixedY[loop];
			nConstrainedDOF+=m_aiIsFixedX[loop]+m_aiIsFixedY[loop];
		}
		else
		{
			m_aiXDOFIndex[iNode]=-m_aiIsFixedX[loop];
			m_aiYDOFIndex[iNode]=-m_aiIsFixedY[loop];
			m_aiRDOFIndex[iNode]=-m_aiIsFixedR[loop];
			nConstrainedDOF+=m_aiIsFixedX[loop]+m_aiIsFixedY[loop]+m_aiIsFixedR[loop];
		}
	}

	iDOFIndex=0;
	iBuf=m_nFreeDOF=m_nTotalDOF-nConstrainedDOF;
	for(loop=0;loop<m_nNode;loop++){
		if(m_aiType[loop]==TWO_DOF){
			if(m_aiXDOFIndex[loop]<0)
				m_aiXDOFIndex[loop]=iBuf++;
			else
				m_aiXDOFIndex[loop]=iDOFIndex++;

			if(m_aiYDOFIndex[loop]<0)
				m_aiYDOFIndex[loop]=iBuf++;
			else
				m_aiYDOFIndex[loop]=iDOFIndex++;
		}
		else{
			if(m_aiXDOFIndex[loop]<0)
				m_aiXDOFIndex[loop]=iBuf++;
			else
				m_aiXDOFIndex[loop]=iDOFIndex++;

			if(m_aiYDOFIndex[loop]<0)
				m_aiYDOFIndex[loop]=iBuf++;
			else
				m_aiYDOFIndex[loop]=iDOFIndex++;

			if(m_aiRDOFIndex[loop]<0)
				m_aiRDOFIndex[loop]=iBuf++;
			else
				m_aiRDOFIndex[loop]=iDOFIndex++;
		}
	}
}

void CNode::SetCurCoordinate(double* adNodeDisp)
{
	for(int loop=0;loop<m_nNode;loop++){
		if(m_aiType[loop]==TWO_DOF){
			m_adCurX[loop]=m_adX[loop]+adNodeDisp[m_aiXDOFIndex[loop]];
			m_adCurY[loop]=m_adY[loop]+adNodeDisp[m_aiYDOFIndex[loop]];
			//m_adCurX[loop]+=adNodeDisp[m_aiXDOFIndex[loop]];
			//m_adCurY[loop]+=adNodeDisp[m_aiYDOFIndex[loop]];
		}
		else{
			m_adCurX[loop]=m_adX[loop]+adNodeDisp[m_aiXDOFIndex[loop]];
			m_adCurY[loop]=m_adY[loop]+adNodeDisp[m_aiYDOFIndex[loop]];
			m_adCurR[loop]=adNodeDisp[m_aiRDOFIndex[loop]];
			//m_adCurX[loop]+=adNodeDisp[m_aiXDOFIndex[loop]];
			//m_adCurY[loop]+=adNodeDisp[m_aiYDOFIndex[loop]];
			//m_adCurR[loop]+=adNodeDisp[m_aiRDOFIndex[loop]];
		}
	}	
}

int CNode::GetType(int iNode)
{
	return m_aiType[iNode];
}

void CNode::OutputConstrainedNodeDescription(ofstream& fout)
{
	int loop,nConstrainedNode;
	nConstrainedNode=m_aiConstrainedNode.GetSize();
	fout<<"受约束结点数:"<<nConstrainedNode<<endl;
	
	for(loop=0;loop<nConstrainedNode;loop++){
		fout<<"受约束结点号:"<<m_aiConstrainedNode[loop];
		if(m_aiType[m_aiConstrainedNode[loop]]==TWO_DOF){
			if(m_aiIsFixedX[loop])	fout<<"  X向固定";
			if(m_aiIsFixedY[loop])	fout<<"  Y向固定";
			fout<<endl;
		}
		else{
			if(m_aiIsFixedX[loop])	fout<<"  X向固定";
			if(m_aiIsFixedY[loop])	fout<<"  Y向固定";
			if(m_aiIsFixedR[loop])	fout<<"  转角固定";
			fout<<endl;
		}
	}
}

void CNode::OutputSupportReaction(ofstream& fout,const double* adLoadVector)
{
	int loop,iBuf,nConstrainedNode;
	int iNode;

	nConstrainedNode=m_aiConstrainedNode.GetSize();
	for(loop=0;loop<nConstrainedNode;loop++){
		fout<<"结点号:"<<m_aiConstrainedNode[loop];
		iNode=m_aiConstrainedNode[loop];
		if(m_aiType[iNode]==TWO_DOF){
			if(m_aiIsFixedX[loop]){
				iBuf=m_aiXDOFIndex[iNode];
				fout<<"  X向反力 "<<adLoadVector[iBuf];
			}
			if(m_aiIsFixedY[loop]){
				iBuf=m_aiYDOFIndex[iNode];
				fout<<"  Y向反力 "<<adLoadVector[iBuf];
			}
			fout<<endl;
		}
		else{
			if(m_aiIsFixedX[loop]){
				iBuf=m_aiXDOFIndex[iNode];
				fout<<"  X向反力 "<<adLoadVector[iBuf];
			}
			if(m_aiIsFixedY[loop]){
				iBuf=m_aiYDOFIndex[iNode];
				fout<<"  Y向反力 "<<adLoadVector[iBuf];
			}
			if(m_aiIsFixedR[loop]){
				iBuf=m_aiRDOFIndex[iNode];
				fout<<"  转角向反力 "<<adLoadVector[iBuf];
			}
			fout<<endl;
		}
	}
}

int CNode::GetNum()
{
	return m_nNode;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -