1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<stdio.h>
#include<conio.h>
#include<algorithm>
#include<ctime>
#include<iomanip>
#include<list>
using namespace std;
#define nconec 3
#define dimension 2
const int n_node = 246;
const int n_elem = 434;
double x[n_node];
double y[n_node];
template<typename T>
void read_data(ifstream& fin, vector <vector <T> >& m, int ROWS, int COLS)
{
for (int row = 0; row < ROWS; row++)
{
for (int col = 0; col < COLS; col++)
{
fin >> m[row][col];
}
}
}
template<typename T>
void print_data(const vector <vector<T> >& m, int ROWS, int COLS)
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
cout << std::setw(6) << m[i][j];
}
cout << endl;
}
}
class Elem_Area {
private:
double *x;
double *y;
int node_0;
int node_1;
int node_2;
public:
void setternode0(double Node_0) { node_0 = Node_0; }
int getternode0() { return node_0; }
void setternode1(double Node_1) { node_1 = Node_1; }
int getternode1() { return node_1; }
void setternode2(double Node_2) { node_2 = Node_2; }
int getternode2() { return node_2; }
void setterX(double *X) { x = X; }
double getterX() { return *x; }
void setterY(double *Y) { y = Y; }
double getterY() { return *y; }
void getarea(double *X, double *Y,int Node_0, int Node_1, int Node_2)
{
double element_area= abs(0.5*(((x[node_0] - x[node_2])*(y[node_1] - y[node_2])) - ((y[node_0] - y[node_2])*(x[node_1] - (x[node_2])))));
}
};
int main()
{
int no_rows = n_elem;
int no_cols = 4;
vector<vector<int>> connectivity(no_rows, vector<int>(no_cols));
ifstream myfile1;
myfile1.open("connec.txt");
read_data(myfile1, connectivity, no_rows, no_cols);
ofstream fout;
print_data(connectivity, no_rows, no_cols);
no_rows = n_node;
vector<vector<double>> coordinate(no_rows, vector<double>(no_cols));
ifstream myfile2;
myfile2.open("mesh.txt");
read_data(myfile2, coordinate, no_rows, no_cols);
print_data(coordinate, no_rows, no_cols);
for (int i = 0; i < n_node; i++)
{
x[i] = coordinate[i][1];
}
for (int i = 0; i < n_node; i++)
{
y[i] = coordinate[i][2];
}
Elem_Area *elem_area[n_elem];
for (int i = 0; i < n_elem; i++)
{
int node_0=((connectivity[i][1] - 1));
int node_1=((connectivity[i][2] - 1));
int node_2=((connectivity[i][3] - 1));
elem_area[i]->getarea(x, y, node_0, node_1, node_2);
}
fout.open("elem_area.txt");
fout << "variables = elem_area " << endl;
fout << "zone I = " << n_elem << endl;
for (int i = 0; i < n_elem; i++)
{
fout << i << " " << elem_area[i] << ' ';
fout << endl;
}
fout.close();
return 0;
}
| |