99// Website: https://feascript.com/ \__| //
1010
1111/**
12- * Impose ConstantTemp boundary conditions
13- * @param {object } boundaryConditions - Object containing boundary conditions for the finite element analysis
14- * @param {array } boundaryElements - Array containing elements and their adjacent boundary side for each boundary
15- * @param {array } nop - Nodal numbering array
16- * @param {array } residualVector - Residual vector to be modified
17- * @param {array } jacobianMatrix - Jacobian matrix to be modified
18- * @param {string } dimension - The dimension of the mesh ('1D' or '2D')
12+ * Class to handle thermal boundary conditions application
1913 */
20- export function imposeConstantTempBoundaryConditions (
21- boundaryConditions ,
22- boundaryElements ,
23- nop ,
24- residualVector ,
25- jacobianMatrix ,
26- dimension
27- ) {
28- if ( dimension === "2D" ) {
29- const boundarySides = {
30- 0 : [ 0 , 3 , 6 ] , // Nodes at the bottom side of the reference element
31- 1 : [ 0 , 1 , 2 ] , // Nodes at the left side of the reference element
32- 2 : [ 2 , 5 , 8 ] , // Nodes at the top side of the reference element
33- 3 : [ 6 , 7 , 8 ] , // Nodes at the right side of the reference element
34- } ;
14+ export class ThermalBoundaryConditions {
15+ constructor ( boundaryConditions , boundaryElements , nop , dimension ) {
16+ this . boundaryConditions = boundaryConditions ;
17+ this . boundaryElements = boundaryElements ;
18+ this . nop = nop ;
19+ this . dimension = dimension ;
20+ }
3521
36- Object . keys ( boundaryConditions ) . forEach ( ( key ) => {
37- if ( boundaryConditions [ key ] [ 0 ] === "constantTemp" ) {
38- const tempValue = boundaryConditions [ key ] [ 1 ] ;
39- boundaryElements [ key ] . forEach ( ( [ elementIndex , side ] ) => {
40- boundarySides [ key ] . forEach ( ( nodeIndex ) => {
41- const globalNodeIndex = nop [ elementIndex ] [ nodeIndex ] - 1 ;
42- // Set the residual vector to the ConstantTemp value
43- residualVector [ globalNodeIndex ] = tempValue ;
44- // Set the Jacobian matrix row to zero
45- for ( let j = 0 ; j < residualVector . length ; j ++ ) {
46- jacobianMatrix [ globalNodeIndex ] [ j ] = 0 ;
47- }
48- // Set the diagonal entry of the Jacobian matrix to one
49- jacobianMatrix [ globalNodeIndex ] [ globalNodeIndex ] = 1 ;
22+ imposeConstantTempBoundaryConditions ( residualVector , jacobianMatrix ) {
23+ if ( this . dimension === "2D" ) {
24+ const boundarySides = {
25+ 0 : [ 0 , 3 , 6 ] , // Nodes at the bottom side of the reference element
26+ 1 : [ 0 , 1 , 2 ] , // Nodes at the left side of the reference element
27+ 2 : [ 2 , 5 , 8 ] , // Nodes at the top side of the reference element
28+ 3 : [ 6 , 7 , 8 ] , // Nodes at the right side of the reference element
29+ } ;
30+
31+ Object . keys ( this . boundaryConditions ) . forEach ( ( key ) => {
32+ if ( this . boundaryConditions [ key ] [ 0 ] === "constantTemp" ) {
33+ const tempValue = this . boundaryConditions [ key ] [ 1 ] ;
34+ this . boundaryElements [ key ] . forEach ( ( [ elementIndex , side ] ) => {
35+ boundarySides [ key ] . forEach ( ( nodeIndex ) => {
36+ const globalNodeIndex = this . nop [ elementIndex ] [ nodeIndex ] - 1 ;
37+ // Set the residual vector to the ConstantTemp value
38+ residualVector [ globalNodeIndex ] = tempValue ;
39+ // Set the Jacobian matrix row to zero
40+ for ( let j = 0 ; j < residualVector . length ; j ++ ) {
41+ jacobianMatrix [ globalNodeIndex ] [ j ] = 0 ;
42+ }
43+ // Set the diagonal entry of the Jacobian matrix to one
44+ jacobianMatrix [ globalNodeIndex ] [ globalNodeIndex ] = 1 ;
45+ } ) ;
5046 } ) ;
51- } ) ;
52- }
53- } ) ;
54- } else if ( dimension === "1D" ) {
55- // . . . implementation for 1D . . .
47+ }
48+ } ) ;
49+ } else if ( this . dimension === "1D" ) {
50+ // . . . implementation for 1D . . .
51+ }
5652 }
57- }
5853
59- /**
60- * Impose Convection boundary conditions
61- * @param {object } boundaryConditions - Object containing boundary conditions for the finite element analysis
62- * @param {array } boundaryElements - Array containing elements and their adjacent boundary side for each boundary
63- * @param {array } nop - Nodal numbering array
64- * @param {array } residualVector - Residual vector to be modified
65- * @param {array } jacobianMatrix - Jacobian matrix to be modified
66- * @param {string } dimension - The dimension of the mesh ('1D' or '2D')
67- * @param {array } gaussPoints - Gauss points for numerical integration
68- * @param {array } gaussWeights - Gauss weights for numerical integration
69- * @param {array } nodesXCoordinates - X coordinates of the nodes
70- * @param {array } nodesYCoordinates - Y coordinates of the nodes
71- * @param {object } basisFunctionsData - Basis functions data
72- * @param {array } convectionHeatTranfCoeff - Convection heat transfer coefficients
73- * @param {array } convectionExtTemp - External temperatures for convection
74- */
75- export function imposeConvectionBoundaryConditions (
76- boundaryConditions ,
77- boundaryElements ,
78- nop ,
79- residualVector ,
80- jacobianMatrix ,
81- dimension ,
82- gaussPoints ,
83- gaussWeights ,
84- nodesXCoordinates ,
85- nodesYCoordinates ,
86- basisFunctionsData ,
87- convectionHeatTranfCoeff ,
88- convectionExtTemp
89- ) {
90- if ( dimension === "2D" ) {
91- Object . keys ( boundaryConditions ) . forEach ( ( key ) => {
92- if ( boundaryConditions [ key ] [ 0 ] === "convection" ) {
93- const convectionCoeff = convectionHeatTranfCoeff [ key ] ;
94- const extTemp = convectionExtTemp [ key ] ;
95- boundaryElements [ key ] . forEach ( ( [ elementIndex , side ] ) => {
96- for ( let l = 0 ; l < 3 ; l ++ ) {
97- let gp1 , gp2 , firstNode , finalNode , nodeIncr ;
98- if ( side === 0 ) {
99- // Nodes at the bottom side of the reference element
100- gp1 = gaussPoints [ l ] ;
101- gp2 = 0 ;
102- firstNode = 0 ;
103- finalNode = 7 ;
104- nodeIncr = 3 ;
105- } else if ( side === 1 ) {
106- // Nodes at the left side of the reference element
107- gp1 = 0 ;
108- gp2 = gaussPoints [ l ] ;
109- firstNode = 0 ;
110- finalNode = 3 ;
111- nodeIncr = 1 ;
112- } else if ( side === 2 ) {
113- // Nodes at the top side of the reference element
114- gp1 = gaussPoints [ l ] ;
115- gp2 = 1 ;
116- firstNode = 2 ;
117- finalNode = 9 ;
118- nodeIncr = 3 ;
119- } else if ( side === 3 ) {
120- // Nodes at the right side of the reference element
121- gp1 = 1 ;
122- gp2 = gaussPoints [ l ] ;
123- firstNode = 6 ;
124- finalNode = 9 ;
125- nodeIncr = 1 ;
126- }
54+ imposeConvectionBoundaryConditions (
55+ residualVector ,
56+ jacobianMatrix ,
57+ gaussPoints ,
58+ gaussWeights ,
59+ nodesXCoordinates ,
60+ nodesYCoordinates ,
61+ basisFunctionsData ,
62+ convectionHeatTranfCoeff ,
63+ convectionExtTemp
64+ ) {
65+ if ( this . dimension === "2D" ) {
66+ Object . keys ( this . boundaryConditions ) . forEach ( ( key ) => {
67+ if ( this . boundaryConditions [ key ] [ 0 ] === "convection" ) {
68+ const convectionCoeff = convectionHeatTranfCoeff [ key ] ;
69+ const extTemp = convectionExtTemp [ key ] ;
70+ this . boundaryElements [ key ] . forEach ( ( [ elementIndex , side ] ) => {
71+ for ( let l = 0 ; l < 3 ; l ++ ) {
72+ let gp1 , gp2 , firstNode , finalNode , nodeIncr ;
73+ if ( side === 0 ) {
74+ // Nodes at the bottom side of the reference element
75+ gp1 = gaussPoints [ l ] ;
76+ gp2 = 0 ;
77+ firstNode = 0 ;
78+ finalNode = 7 ;
79+ nodeIncr = 3 ;
80+ } else if ( side === 1 ) {
81+ // Nodes at the left side of the reference element
82+ gp1 = 0 ;
83+ gp2 = gaussPoints [ l ] ;
84+ firstNode = 0 ;
85+ finalNode = 3 ;
86+ nodeIncr = 1 ;
87+ } else if ( side === 2 ) {
88+ // Nodes at the top side of the reference element
89+ gp1 = gaussPoints [ l ] ;
90+ gp2 = 1 ;
91+ firstNode = 2 ;
92+ finalNode = 9 ;
93+ nodeIncr = 3 ;
94+ } else if ( side === 3 ) {
95+ // Nodes at the right side of the reference element
96+ gp1 = 1 ;
97+ gp2 = gaussPoints [ l ] ;
98+ firstNode = 6 ;
99+ finalNode = 9 ;
100+ nodeIncr = 1 ;
101+ }
127102
128- let basisFunctionsAndDerivatives =
129- basisFunctionsData . getBasisFunctions ( gp1 , gp2 ) ;
130- let basisFunction = basisFunctionsAndDerivatives . basisFunction ;
131- let basisFunctionDerivKsi =
132- basisFunctionsAndDerivatives . basisFunctionDerivKsi ;
133- let xCoordinates = 0 ;
134- let ksiDerivX = 0 ;
135- for ( let k = 0 ; k < 9 ; k ++ ) {
136- xCoordinates +=
137- nodesXCoordinates [ nop [ elementIndex ] [ k ] - 1 ] * basisFunction [ k ] ;
138- ksiDerivX +=
139- nodesXCoordinates [ nop [ elementIndex ] [ k ] - 1 ] *
140- basisFunctionDerivKsi [ k ] ;
141- }
103+ let basisFunctionsAndDerivatives =
104+ basisFunctionsData . getBasisFunctions ( gp1 , gp2 ) ;
105+ let basisFunction = basisFunctionsAndDerivatives . basisFunction ;
106+ let basisFunctionDerivKsi =
107+ basisFunctionsAndDerivatives . basisFunctionDerivKsi ;
108+ let xCoordinates = 0 ;
109+ let ksiDerivX = 0 ;
110+ for ( let k = 0 ; k < 9 ; k ++ ) {
111+ xCoordinates +=
112+ nodesXCoordinates [ this . nop [ elementIndex ] [ k ] - 1 ] *
113+ basisFunction [ k ] ;
114+ ksiDerivX +=
115+ nodesXCoordinates [ this . nop [ elementIndex ] [ k ] - 1 ] *
116+ basisFunctionDerivKsi [ k ] ;
117+ }
142118
143- for ( let m = firstNode ; m < finalNode ; m += nodeIncr ) {
144- let m1 = nop [ elementIndex ] [ m ] - 1 ;
145- residualVector [ m1 ] +=
146- - gaussWeights [ l ] *
147- ksiDerivX *
148- basisFunction [ m ] *
149- convectionCoeff *
150- extTemp ;
151- for ( let n = firstNode ; n < finalNode ; n += nodeIncr ) {
152- let n1 = nop [ elementIndex ] [ n ] - 1 ;
153- jacobianMatrix [ m1 ] [ n1 ] +=
119+ for ( let m = firstNode ; m < finalNode ; m += nodeIncr ) {
120+ let m1 = this . nop [ elementIndex ] [ m ] - 1 ;
121+ residualVector [ m1 ] +=
154122 - gaussWeights [ l ] *
155123 ksiDerivX *
156124 basisFunction [ m ] *
157- basisFunction [ n ] *
158- convectionCoeff ;
125+ convectionCoeff *
126+ extTemp ;
127+ for ( let n = firstNode ; n < finalNode ; n += nodeIncr ) {
128+ let n1 = this . nop [ elementIndex ] [ n ] - 1 ;
129+ jacobianMatrix [ m1 ] [ n1 ] +=
130+ - gaussWeights [ l ] *
131+ ksiDerivX *
132+ basisFunction [ m ] *
133+ basisFunction [ n ] *
134+ convectionCoeff ;
135+ }
159136 }
160137 }
161- }
162- } ) ;
163- }
164- } ) ;
165- } else if ( dimension === "1D" ) {
166- // . . . implementation for 1D . . .
138+ } ) ;
139+ }
140+ } ) ;
141+ } else if ( this . dimension === "1D" ) {
142+ // . . . implementation for 1D . . .
143+ }
167144 }
168145}
0 commit comments