-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1D_mesh_tools.hpp
More file actions
178 lines (153 loc) · 4.61 KB
/
1D_mesh_tools.hpp
File metadata and controls
178 lines (153 loc) · 4.61 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* \file 1D_mesh_tools.hpp
* \brief 1D mesh library
* \author Alp Dener <alp.dener@gmail.com>
* \version 1.0
*/
#pragma once
#include <vector>
#include "../Quasi1DEuler/inner_prod_vector.hpp"
using namespace std;
// =====================================================================
/*!
* \class Node
* \brief defines the nodes of a 2-D mesh
*/
class Node {
public:
int id;
int type[3]; // 0 for zero BC, 1 for free node, 2 for prescribed displacements
double coords[2];
double dispBC[3]; // 3 degrees of freedom per node (axial, trans, rotational)
double forceBC[3]; // forcing in two directions plus moment about the third
Node() {}
/*!
* \brief construct the node
* \param[in] num - global node id
* \param[in] c - vector of node coordinates
*/
Node(int num, double* c)
{
id = num;
for (int i=0; i<3; i++) {
coords[i] = c[i];
type[i] = 1; // node is initially free
}
}
~Node() {}
/*!
* \brief define nodal boundary conditions
* \param[in] BCtype - type of boundary conditions
* \param[in] BCval - value of the boundary conditions
*/
void DefineBCs(int* BCtype, double* BCval);
};
// =====================================================================
/*!
* \class Element
* \brief defines a 2D first order finite element beam
*/
class Element {
public:
int id, nen;
vector<Node> adjNodes;
Element() {}
/*!
* \brief construct the element
* \param[in] num - global element id
* \param[in] nodes - vector of nodes defining the element
*/
Element(int num, vector<Node> nodes);
~Element() {}
/*!
* \brief construct the element stiffness matrix and forcing vector
* \param[in] E - young's modulus
* \param[in] w - element width
* \param[in] t - element thickness
* \param[in] P - pressures on element nodes
* \param[in] gm - global equation number mapping
* \param[out] lm - local equation number mapping
* \param[out] KE - element stiffness matrix
* \param[out] FE - element forcing vector
*/
void GetElemStiff(double E, double w, double t, vector<double>& P,
vector< vector< vector<int> > >& gm,
vector< vector< vector<int> > >& lm,
vector< vector<double> >& KE, vector<double>& FE);
/*!
* \brief construct the element stiffness matrix and forcing vector
* \param[in] E - young's modulus
* \param[in] w - element width
* \param[in] t - element thickness
* \param[in] P - pressures on element nodes
* \param[in] gm - global equation number mapping
* \param[out] lm - local equation number mapping
* \param[out] KE - element stiffness matrix
* \param[out] FE - element forcing vector
*/
template <typename type>
void GetElemStiff(type x1, type x2, type y1, type y2,
type E, type w, type t, vector<type>& P,
vector< vector< vector<int> > >& gm,
vector< vector< vector<int> > >& lm,
vector< vector<type> >& KE, vector<type>& FE);
/*!
* \brief assemble the element contributions into global matrix/vectors
* \param[in] KE - element stiffness matrix
* \param[in] FE - element forcing vector
* \param[in] lm - local equation number mapping
* \param[in] G - global prescribed displacements vector
* \param[out] K - global stiffness matrix
* \param[out] F - global forcing vector
*/
template <typename type>
void Assemble(vector< vector<type> >& KE, vector<type>& FE,
vector< vector< vector<int> > >& lm,
vector<type>& G, vector<type>& F,
vector< vector<type> >& K);
};
// =====================================================================
/*!
* \class Mesh
* \brief defines a 2D finite element beam mesh
*/
class Mesh {
public:
int nnp, nel, ndof, ndog;
vector<Element> allElems;
vector<Node> allNodes;
/*!
* \brief class constructor
*/
Mesh() {
nnp = 0;
nel = 0;
}
/*!
* \brief construct the mesh
* \param[in] elems - vector of mesh elements
*/
void CreateMesh(vector<Element>& elems, vector<Node>& nodes)
{
allElems = elems;
allNodes = nodes;
nel = allElems.size();
nnp = allNodes.size();
}
/*!
* \brief default destructor
*/
~Mesh() {} //
void InspectNodes();
void InspectElements();
/*!
* \brief generate the global equation number map
* \param[out] gm - global equation number mapping
*/
void SetupEq(vector< vector< vector<int> > >& gm);
/*!
* \brief update the mesh
* \param[in] u_csm - nodal displacement vector
*/
void Update(const InnerProdVector& xCoords, const InnerProdVector & yCoords);
};