📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream> // define ofstream class
#include <stdlib> // define exit() function
#include <cstdlib> // atof() convert string to double value
// atoi() convert string to int value
// atol() convert string to long value
using namespace std;
#include "Plate.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
//-----------------------------------------------------------------------
char nNodes[20], nElements[20], nDOF[20], nQuad[20], ns[20];
char nE[20], nv[20], nt[20];
char Coordinate[20], nConnect[20], nFreedom[20], nForce[20];
int Nodes, Elements, DOF, Quad, Solver;
double E, v, t;
double **XYZ, **Connect, **Freedom, **Force;
//-----------------------------------------------------------------------
ifstream infile1("NodesElements.txt", ios::in);
if (!infile1){
cout << "Error: NodesElements.txt could not be opened.";
cout << "\n\nPress any key to exit...";
getchar();
exit(1);
}
infile1 >> nNodes >> nElements >> nDOF >> nQuad >> nE >> nv >> nt >> ns;
Nodes = atoi(nNodes);
Elements = atoi(nElements);
DOF = atoi(nDOF);
Quad = atoi(nQuad);
E = atof(nE);
v = atof(nv);
t = atof(nt);
Solver = atoi(ns);
//-----------------------------------------------------------------------
TPlate Plate(Nodes, Elements, DOF, Quad, E, v, t, Solver);
//-----------------------------------------------------------------------
ifstream infile2("XYZ.txt", ios::in);
if (!infile2){
cout << "Error: XYZ.txt could not be opened.";
cout << "\n\nPress any key to exit...";
getchar();
exit(1);
}
XYZ = Plate.Allocate_2D_Matrix(XYZ, Nodes, DOF);
XYZ = Plate.SetZero_2D_Matrix(XYZ, Nodes, DOF);
for (int i = 0; i < Nodes; i++){
for (int j = 0; j < DOF; j++){
infile2 >> Coordinate;
XYZ[i][j] = atof(Coordinate);
// cout << "XYZ[" << i << "][" << j << "] = " << XYZ[i][j] << endl;
}
}
Plate.setXYZ(XYZ);
//-----------------------------------------------------------------------
ifstream infile3("PLTCON.txt", ios::in);
if (!infile3){
cout << "Error: PLTCON.txt could not be opened.";
cout << "\n\nPress any key to exit...";
getchar();
exit(1);
}
Connect = Plate.Allocate_2D_Matrix(Connect, Elements, Quad);
Connect = Plate.SetZero_2D_Matrix(Connect, Elements, Quad);
for (int i = 0; i < Elements; i++){
for (int j = 0; j < Quad; j++){
infile3 >> nConnect;
Connect[i][j] = atof(nConnect);
}
}
Plate.setConnect(Connect);
//-----------------------------------------------------------------------
ifstream infile4("FCOND.txt", ios::in);
if (!infile4){
cout << "Error: FCOND.txt could not be opened.";
cout << "\n\nPress any key to exit...";
getchar();
exit(1);
}
Freedom = Plate.Allocate_2D_Matrix(Freedom, Nodes, DOF);
Freedom = Plate.SetZero_2D_Matrix(Freedom, Nodes, DOF);
for (int i = 0; i < Nodes; i++){
for (int j = 0; j < DOF; j++){
infile4 >> nFreedom;
Freedom[i][j] = atof(nFreedom);
}
}
Plate.setFreedom(Freedom);
//-----------------------------------------------------------------------
ifstream infile5("Force.txt", ios::in);
if (!infile5){
cout << "Error: Force.txt could not be opened.";
cout << "\n\nPress any key to exit...";
getchar();
exit(1);
}
Force = Plate.Allocate_2D_Matrix(Force, Nodes, DOF);
Force = Plate.SetZero_2D_Matrix(Force, Nodes, DOF);
for (int i = 0; i < Nodes; i++){
for (int j = 0; j < DOF; j++){
infile5 >> nForce;
Force[i][j] = atof(nForce);
}
}
Plate.setForce(Force);
//-----------------------------------------------------------------------
Plate.Display();
//-----------------------------------------------------------------------
Plate.De_Allocate_2D_Matrix(XYZ, Nodes);
Plate.De_Allocate_2D_Matrix(Connect, Elements);
Plate.De_Allocate_2D_Matrix(Freedom, Nodes);
Plate.De_Allocate_2D_Matrix(Force, Nodes);
getchar();
return 0;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -