Skip to content

Commit a95671f

Browse files
committed
Refactor solidHeatTransferScript.js to implement convection, constant temperature and symmetry boundary conditions
1 parent 80df7f2 commit a95671f

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

src/solvers/solidHeatTransferScript.js

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ export function assembleSolidHeatTrasnferMat(
3838
topBoundary,
3939
bottomBoundary,
4040
leftBoundary,
41-
rightBoundary,
42-
robinHeatTranfCoeff,
43-
robinExtTemp,
41+
rightBoundary
4442
} = boundaryConditions;
43+
let convectionHeatTranfCoeff = topBoundary[1];
44+
let convectionExtTemp = topBoundary[2];
45+
46+
console.log("convectionHeatTranfCoeff:", convectionHeatTranfCoeff);
47+
console.log("convectionExtTemp:", convectionExtTemp);
4548

4649
// Create a new instance of the meshGeneration class
4750
const meshGenerationData = new meshGeneration({
@@ -72,12 +75,12 @@ export function assembleSolidHeatTrasnferMat(
7275
// Initialize variables for matrix assembly
7376
const ne = numElementsX * numElementsY; // Total number of elements
7477
const np = totalNodesX * totalNodesY; // Total number of nodes
75-
let robinBoundaryFlagTop = new Array(ne).fill(0); // Robin boundary condition flag (elements at the top side of the domain)
76-
let robinBoundaryFlagBottom = new Array(ne).fill(0); // Robin boundary condition flag (elements at the bottom side of the domain)
77-
let robinBoundaryFlagLeft = new Array(ne).fill(0); // Robin boundary condition flag (elements at the left side of the domain)
78-
let robinBoundaryFlagRight = new Array(ne).fill(0); // Robin boundary condition flag (elements at the right side of the domain)
79-
let dirichletBoundaryFlag = new Array(np).fill(0); // Dirichlet boundary condition flag
80-
let dirichletBoundaryValue = new Array(np).fill(0); // Dirichlet boundary condition value
78+
let convectionBoundaryFlagTop = new Array(ne).fill(0); // Convection boundary condition flag (elements at the top side of the domain)
79+
let convectionBoundaryFlagBottom = new Array(ne).fill(0); // Convection boundary condition flag (elements at the bottom side of the domain)
80+
let convectionBoundaryFlagLeft = new Array(ne).fill(0); // Convection boundary condition flag (elements at the left side of the domain)
81+
let convectionBoundaryFlagRight = new Array(ne).fill(0); // Convection boundary condition flag (elements at the right side of the domain)
82+
let constantTempBoundaryFlag = new Array(np).fill(0); // ConstantTemp boundary condition flag
83+
let constantTempBoundaryValue = new Array(np).fill(0); // ConstantTemp boundary condition value
8184
let localNodalNumbers = []; // Local nodal numbering
8285
let gaussPoints = []; // Gauss points
8386
let gaussWeights = []; // Gauss weights
@@ -123,41 +126,41 @@ export function assembleSolidHeatTrasnferMat(
123126
gaussPoints = gaussPointsAndWeights.gaussPoints;
124127
gaussWeights = gaussPointsAndWeights.gaussWeights;
125128

126-
// Check for elements to impose Robin boundary conditions
129+
// Check for elements to impose Convection boundary conditions
127130
for (
128131
let i = 0;
129132
i < ne - numElementsY;
130133
i += numElementsY // Elements along yCoordinates=yStart (bottom side of the domain)
131134
) {
132-
if (bottomBoundary[0] == "robin") {
133-
robinBoundaryFlagBottom[i] = 1;
135+
if (bottomBoundary[0] == "convection") {
136+
convectionBoundaryFlagBottom[i] = 1;
134137
}
135138
}
136139
for (
137140
let i = 0;
138141
i < numElementsY;
139142
i++ // Elements along xCoordinates=xStart (left side of the domain)
140143
) {
141-
if (leftBoundary[0] == "robin") {
142-
robinBoundaryFlagLeft[i] = 1;
144+
if (leftBoundary[0] == "convection") {
145+
convectionBoundaryFlagLeft[i] = 1;
143146
}
144147
}
145148
for (
146149
let i = numElementsY - 1;
147150
i < ne;
148151
i += numElementsY // Elements along yCoordinates=maxY (top side of the domain)
149152
) {
150-
if (topBoundary[0] == "robin") {
151-
robinBoundaryFlagTop[i] = 1;
153+
if (topBoundary[0] == "convection") {
154+
convectionBoundaryFlagTop[i] = 1;
152155
}
153156
}
154157
for (
155158
let i = ne - numElementsY;
156159
i < ne;
157160
i++ // Elements along xCoordinates=maxX (right side of the domain)
158161
) {
159-
if (rightBoundary[0] == "robin") {
160-
robinBoundaryFlagRight[i] = 1;
162+
if (rightBoundary[0] == "convection") {
163+
convectionBoundaryFlagRight[i] = 1;
161164
}
162165
}
163166

@@ -236,38 +239,38 @@ export function assembleSolidHeatTrasnferMat(
236239
}
237240
}
238241

239-
// Impose Robin boundary conditions
242+
// Impose Convection boundary conditions
240243
if (
241-
robinBoundaryFlagTop[i] == 1 ||
242-
robinBoundaryFlagBottom[i] == 1 ||
243-
robinBoundaryFlagLeft[i] == 1 ||
244-
robinBoundaryFlagRight[i] == 1
244+
convectionBoundaryFlagTop[i] == 1 ||
245+
convectionBoundaryFlagBottom[i] == 1 ||
246+
convectionBoundaryFlagLeft[i] == 1 ||
247+
convectionBoundaryFlagRight[i] == 1
245248
) {
246249
for (let l = 0; l < 3; l++) {
247250
let gp1, gp2, firstNode, finalNode, nodeIncr;
248251
// Set gp1 and gp2 based on boundary conditions
249-
if (robinBoundaryFlagTop[i] == 1) {
252+
if (convectionBoundaryFlagTop[i] == 1) {
250253
// Set gp1 and gp2 for elements at the top side of the domain (nodes 2, 5, 8)
251254
gp1 = gaussPoints[l];
252255
gp2 = 1;
253256
firstNode = 2;
254257
finalNode = 9; // final node minus one
255258
nodeIncr = 3;
256-
} else if (robinBoundaryFlagBottom[i] == 1) {
259+
} else if (convectionBoundaryFlagBottom[i] == 1) {
257260
// Set gp1 and gp2 for elements at the bottom side of the domain (nodes 0, 3, 6)
258261
gp1 = gaussPoints[l];
259262
gp2 = 0;
260263
firstNode = 0;
261264
finalNode = 7;
262265
nodeIncr = 3;
263-
} else if (robinBoundaryFlagLeft[i] == 1) {
266+
} else if (convectionBoundaryFlagLeft[i] == 1) {
264267
// Set gp1 and gp2 for elements at the left side of the domain (nodes 0, 1, 2)
265268
gp1 = 0;
266269
gp2 = gaussPoints[l];
267270
firstNode = 0;
268271
finalNode = 3;
269272
nodeIncr = 1;
270-
} else if (robinBoundaryFlagRight[i] == 1) {
273+
} else if (convectionBoundaryFlagRight[i] == 1) {
271274
// Set gp1 and gp2 for elements at the right side of the domain (nodes 6, 7, 8)
272275
gp1 = 1;
273276
gp2 = gaussPoints[l];
@@ -298,68 +301,68 @@ export function assembleSolidHeatTrasnferMat(
298301
-gaussWeights[l] *
299302
ksiDerivX *
300303
basisFunction[m] *
301-
robinHeatTranfCoeff *
302-
robinExtTemp; // Add the Robin boundary term to the residual vector
304+
convectionHeatTranfCoeff *
305+
convectionExtTemp; // Add the Convection boundary term to the residual vector
303306
for (let n = firstNode; n < finalNode; n += nodeIncr) {
304307
let n1 = localNodalNumbers[n];
305308
jacobianMatrix[m1][n1] +=
306309
-gaussWeights[l] *
307310
ksiDerivX *
308311
basisFunction[m] *
309312
basisFunction[n] *
310-
robinHeatTranfCoeff; // Add the Robin boundary term to the Jacobian matrix
313+
convectionHeatTranfCoeff; // Add the Convection boundary term to the Jacobian matrix
311314
}
312315
}
313316
}
314317
}
315318
}
316319

317-
// Check for elements to impose Dirichlet boundary conditions
320+
// Check for elements to impose ConstantTemp boundary conditions
318321
for (
319322
let i = 0;
320323
i < np - totalNodesY + 1;
321-
i += totalNodesY // Define dirichletBoundaryFlag and dirichletBoundaryValue for nodes on yCoordinates=yStart (bottom side of the domain)
324+
i += totalNodesY // Define constantTempBoundaryFlag and constantTempBoundaryValue for nodes on yCoordinates=yStart (bottom side of the domain)
322325
) {
323-
if (bottomBoundary[0] == "dirichlet") {
324-
dirichletBoundaryFlag[i] = 1;
325-
dirichletBoundaryValue[i] = bottomBoundary[1];
326+
if (bottomBoundary[0] == "constantTemp") {
327+
constantTempBoundaryFlag[i] = 1;
328+
constantTempBoundaryValue[i] = bottomBoundary[1];
326329
}
327330
}
328331
for (
329332
let i = 0;
330333
i < totalNodesY;
331-
i++ // Define dirichletBoundaryFlag and dirichletBoundaryValue for nodes on xCoordinates=xStart (left side of the domain)
334+
i++ // Define constantTempBoundaryFlag and constantTempBoundaryValue for nodes on xCoordinates=xStart (left side of the domain)
332335
) {
333-
if (leftBoundary[0] == "dirichlet") {
334-
dirichletBoundaryFlag[i] = 1;
335-
dirichletBoundaryValue[i] = leftBoundary[1];
336+
if (leftBoundary[0] == "constantTemp") {
337+
constantTempBoundaryFlag[i] = 1;
338+
constantTempBoundaryValue[i] = leftBoundary[1];
336339
}
337340
}
338341
for (
339342
let i = totalNodesY - 1;
340343
i < np;
341-
i += totalNodesY // Define dirichletBoundaryFlag and dirichletBoundaryValue for nodes on yCoordinates=maxY (top side of the domain)
344+
i += totalNodesY // Define constantTempBoundaryFlag and constantTempBoundaryValue for nodes on yCoordinates=maxY (top side of the domain)
342345
) {
343-
if (topBoundary[0] == "dirichlet") {
344-
dirichletBoundaryFlag[i] = 1;
345-
dirichletBoundaryValue[i] = topBoundary[1];
346+
if (topBoundary[0] == "constantTemp") {
347+
constantTempBoundaryFlag[i] = 1;
348+
constantTempBoundaryValue[i] = topBoundary[1];
346349
}
347350
}
348351
for (
349352
let i = np - totalNodesY;
350353
i < np;
351-
i++ // Define dirichletBoundaryFlag and dirichletBoundaryValue for nodes on xCoordinates=maxX (right side of the domain)
354+
i++ // Define constantTempBoundaryFlag and constantTempBoundaryValue for nodes on xCoordinates=maxX (right side of the domain)
352355
) {
353-
if (rightBoundary[0] == "dirichlet") {
354-
dirichletBoundaryFlag[i] = 1;
355-
dirichletBoundaryValue[i] = rightBoundary[1];
356+
if (rightBoundary[0] == "constantTemp") {
357+
constantTempBoundaryFlag[i] = 1;
358+
constantTempBoundaryValue[i] = rightBoundary[1];
356359
}
357360
}
358361

359-
// Impose Dirichlet boundary conditions
362+
// Impose ConstantTemp boundary conditions
360363
for (let i = 0; i < np; i++) {
361-
if (dirichletBoundaryFlag[i] == 1) {
362-
residualVector[i] = dirichletBoundaryValue[i]; // Set the residual vector to the Dirichlet value
364+
if (constantTempBoundaryFlag[i] == 1) {
365+
residualVector[i] = constantTempBoundaryValue[i]; // Set the residual vector to the ConstantTemp value
363366
for (let j = 0; j < np; j++) {
364367
jacobianMatrix[i][j] = 0; // Set the Jacobian matrix to zero
365368
jacobianMatrix[i][i] = 1; // Set the diagonal entry to one

0 commit comments

Comments
 (0)