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
|
#include <iostream>
using namespace std;
#include <vector>
using namespace std;
class Node {
public:
double X, Y;
Node():X(0),Y(0){};
Node(double x, double y) : X(x), Y(y) {}
};
class Cell {
public:
int I, J;
vector<Node> nodes;
Cell() : I(0), J(0), nodes() {}
//constructor
Cell(int i, int j, vector<Node>& cell_nodes) :
I(i), J(j), nodes(cell_nodes) {}
// copy assignment operator
Cell& operator=(const Cell& other) {
if (this != &other) {
I = other.I;
J = other.J;
nodes = other.nodes;
}
return *this;
}
//----------------------
double x() const {
double x_sum = 0.0;
for (const auto& node : nodes) {
x_sum += node.X;
}
return x_sum / nodes.size();
}
double y() const {
double y_sum = 0.0;
for (const auto& node : nodes) {
y_sum += node.Y;
}
return y_sum / nodes.size();
}
double area() const {
int n = nodes.size();
double area_sum = 0.0;
for (int i=0; i<n; i++) {
int j = (i+1) % n;
area_sum += nodes[i].X * nodes[j].Y - nodes[j].X * nodes[i].Y;
}
return 0.5 * area_sum;
}
};
class Edge{
private:
/* data */
public:
Edge
(/* args */);
~Edge
();
};
class Mesh2D {
public:
double L, H;
int NX, NY;
vector<Node> nodes;
vector<Cell> cells;
Mesh2D(double length, double height, int nx, int ny) :
L(length), H(height), NX(nx), NY(ny)
{
// Allocate memory for the nodes and cells
nodes.resize((NX+1)*(NY+1));
cells.resize(NX*NY);
// Initialize the nodes
double dx = L/NX;
double dy = H/NY;
for (int j=0; j<=NY; j++)
{
for (int i=0; i<=NX; i++)
{
nodes[i + j*(NX+1)] = Node(i*dx, j*dy);
}
}
// Initialize the cells
for (int j=0; j<NY; j++)
{
for (int i=0; i<NX; i++)
{
int n00 = i + j*(NX+1);
int n10 = (i+1) + j*(NX+1);
int n01 = i + (j+1)*(NX+1);
int n11 = (i+1) + (j+1)*(NX+1);
vector<Node> cell_nodes = { nodes[n00], nodes[n10], nodes[n11], nodes[n01] };
cells[i + j*NX] = Cell(i, j, cell_nodes);
}
}
}
};
int main (){
Mesh2D mesh(10.0, 2.0, 10, 2);
cout<<"Hello there!";
return 0;
}
|