-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbasisFunctions.js
More file actions
194 lines (177 loc) · 8.03 KB
/
Copy pathbasisFunctions.js
File metadata and controls
194 lines (177 loc) · 8.03 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* ════════════════════════════════════════════════════════════════
* FEAScript Core Library
* Lightweight Finite Element Simulation in JavaScript
* Version: 0.3.0 (RC) | https://feascript.com
* MIT License © 2023–2026 FEAScript
* ════════════════════════════════════════════════════════════════
*/
// Internal imports
import { basicLog, debugLog, errorLog } from "../utilities/logging.js";
/**
* Class to handle basis functions and their derivatives based on element configuration
*/
export class BasisFunctions {
/**
* Constructor to initialize the BasisFunctions class
* @param {string} meshDimension - The dimension of the mesh
* @param {string} elementOrder - The order of elements
*/
constructor({ meshDimension, elementOrder }) {
this.meshDimension = meshDimension;
this.elementOrder = elementOrder;
}
/**
* Function to calculate basis functions and their derivatives based on the dimension and order
* @param {number} ksi - Natural coordinate (for both 1D and 2D), in [0, 1]
* @param {number} [eta] - Second natural coordinate (only for 2D elements)
* @param {number} [elementLength] - Physical element length, only required for 1D 'hermiteCubic' elements
* @returns {object} An object containing:
* - basisFunction: Array of evaluated basis functions
* - basisFunctionDerivKsi: Array of derivatives of basis functions with respect to ksi
* - basisFunctionDerivEta: Array of derivatives of basis functions with respect to eta (only for 2D elements)
* - basisFunctionDerivKsi2: Array of second derivatives of basis functions with respect to ksi
* (only for 1D 'hermiteCubic' elements)
*
* 'hermiteCubic' is a general-purpose interpolation type, not specific to beams: it makes both
* the value and the slope continuous across elements (unlike the C0 Lagrange types above), which
* any fourth-order problem needs (e.g. beam or plate bending). eulerBernoulliBeam.js is currently
* the only place in this codebase that uses it.
*/
getBasisFunctions(ksi, eta = null, elementLength = null) {
let basisFunction = [];
let basisFunctionDerivKsi = [];
let basisFunctionDerivEta = [];
let basisFunctionDerivKsi2 = [];
if (this.meshDimension === "1D") {
if (this.elementOrder === "linear") {
// Linear basis functions for 1D elements
basisFunction[0] = 1 - ksi;
basisFunction[1] = ksi;
// Derivatives of basis functions with respect to ksi
basisFunctionDerivKsi[0] = -1;
basisFunctionDerivKsi[1] = 1;
} else if (this.elementOrder === "quadratic") {
// Quadratic basis functions for 1D elements
basisFunction[0] = 1 - 3 * ksi + 2 * ksi ** 2;
basisFunction[1] = 4 * ksi - 4 * ksi ** 2;
basisFunction[2] = -ksi + 2 * ksi ** 2;
// Derivatives of basis functions with respect to ksi
basisFunctionDerivKsi[0] = -3 + 4 * ksi;
basisFunctionDerivKsi[1] = 4 - 8 * ksi;
basisFunctionDerivKsi[2] = -1 + 4 * ksi;
} else if (this.elementOrder === "hermiteCubic") {
// Cubic Hermite basis functions for 1D Euler-Bernoulli beam elements
// DOF order: [w1, theta1, w2, theta2], with w = transverse deflection and
// theta = dw/dx the (physical) slope. The h-scaling on the theta-associated
// functions converts the interpolated dw/dksi at the nodes into the actual
// rotation DOF, so no extra scaling is required when mapping derivatives to x
if (elementLength === null) {
errorLog("elementLength is required to evaluate 'hermiteCubic' basis functions");
return;
}
const h = elementLength;
basisFunction[0] = 2 * ksi ** 3 - 3 * ksi ** 2 + 1;
basisFunction[1] = h * (ksi ** 3 - 2 * ksi ** 2 + ksi);
basisFunction[2] = -2 * ksi ** 3 + 3 * ksi ** 2;
basisFunction[3] = h * (ksi ** 3 - ksi ** 2);
// First derivatives of basis functions with respect to ksi
basisFunctionDerivKsi[0] = 6 * ksi ** 2 - 6 * ksi;
basisFunctionDerivKsi[1] = h * (3 * ksi ** 2 - 4 * ksi + 1);
basisFunctionDerivKsi[2] = -6 * ksi ** 2 + 6 * ksi;
basisFunctionDerivKsi[3] = h * (3 * ksi ** 2 - 2 * ksi);
// Second derivatives of basis functions with respect to ksi
basisFunctionDerivKsi2[0] = 12 * ksi - 6;
basisFunctionDerivKsi2[1] = h * (6 * ksi - 4);
basisFunctionDerivKsi2[2] = -12 * ksi + 6;
basisFunctionDerivKsi2[3] = h * (6 * ksi - 2);
}
} else if (this.meshDimension === "2D") {
if (eta === null) {
errorLog("Eta coordinate is required for 2D elements");
return;
}
if (this.elementOrder === "linear") {
// Linear basis functions for 2D elements
function l1(c) {
return 1 - c;
}
function l2(c) {
return c;
}
function dl1() {
return -1;
}
function dl2() {
return 1;
}
// Evaluate basis functions at (ksi, eta)
basisFunction[0] = l1(ksi) * l1(eta);
basisFunction[1] = l1(ksi) * l2(eta);
basisFunction[2] = l2(ksi) * l1(eta);
basisFunction[3] = l2(ksi) * l2(eta);
// Derivatives with respect to ksi
basisFunctionDerivKsi[0] = dl1() * l1(eta);
basisFunctionDerivKsi[1] = dl1() * l2(eta);
basisFunctionDerivKsi[2] = dl2() * l1(eta);
basisFunctionDerivKsi[3] = dl2() * l2(eta);
// Derivatives with respect to eta
basisFunctionDerivEta[0] = l1(ksi) * dl1();
basisFunctionDerivEta[1] = l1(ksi) * dl2();
basisFunctionDerivEta[2] = l2(ksi) * dl1();
basisFunctionDerivEta[3] = l2(ksi) * dl2();
} else if (this.elementOrder === "quadratic") {
// Quadratic basis functions for 2D elements
function l1(c) {
return 2 * c ** 2 - 3 * c + 1;
}
function l2(c) {
return -4 * c ** 2 + 4 * c;
}
function l3(c) {
return 2 * c ** 2 - c;
}
function dl1(c) {
return 4 * c - 3;
}
function dl2(c) {
return -8 * c + 4;
}
function dl3(c) {
return 4 * c - 1;
}
// Evaluate basis functions at (ksi, eta)
basisFunction[0] = l1(ksi) * l1(eta);
basisFunction[1] = l1(ksi) * l2(eta);
basisFunction[2] = l1(ksi) * l3(eta);
basisFunction[3] = l2(ksi) * l1(eta);
basisFunction[4] = l2(ksi) * l2(eta);
basisFunction[5] = l2(ksi) * l3(eta);
basisFunction[6] = l3(ksi) * l1(eta);
basisFunction[7] = l3(ksi) * l2(eta);
basisFunction[8] = l3(ksi) * l3(eta);
// Derivatives with respect to ksi
basisFunctionDerivKsi[0] = dl1(ksi) * l1(eta);
basisFunctionDerivKsi[1] = dl1(ksi) * l2(eta);
basisFunctionDerivKsi[2] = dl1(ksi) * l3(eta);
basisFunctionDerivKsi[3] = dl2(ksi) * l1(eta);
basisFunctionDerivKsi[4] = dl2(ksi) * l2(eta);
basisFunctionDerivKsi[5] = dl2(ksi) * l3(eta);
basisFunctionDerivKsi[6] = dl3(ksi) * l1(eta);
basisFunctionDerivKsi[7] = dl3(ksi) * l2(eta);
basisFunctionDerivKsi[8] = dl3(ksi) * l3(eta);
// Derivatives with respect to eta
basisFunctionDerivEta[0] = l1(ksi) * dl1(eta);
basisFunctionDerivEta[1] = l1(ksi) * dl2(eta);
basisFunctionDerivEta[2] = l1(ksi) * dl3(eta);
basisFunctionDerivEta[3] = l2(ksi) * dl1(eta);
basisFunctionDerivEta[4] = l2(ksi) * dl2(eta);
basisFunctionDerivEta[5] = l2(ksi) * dl3(eta);
basisFunctionDerivEta[6] = l3(ksi) * dl1(eta);
basisFunctionDerivEta[7] = l3(ksi) * dl2(eta);
basisFunctionDerivEta[8] = l3(ksi) * dl3(eta);
}
}
return { basisFunction, basisFunctionDerivKsi, basisFunctionDerivEta, basisFunctionDerivKsi2 };
}
}