Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/fem/src/DiffuseConvectiveAnisotropic.F90
3203 views
1
!/*****************************************************************************/
2
! *
3
! * Elmer, A Finite Element Software for Multiphysical Problems
4
! *
5
! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6
! *
7
! * This library is free software; you can redistribute it and/or
8
! * modify it under the terms of the GNU Lesser General Public
9
! * License as published by the Free Software Foundation; either
10
! * version 2.1 of the License, or (at your option) any later version.
11
! *
12
! * This library is distributed in the hope that it will be useful,
13
! * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
! * Lesser General Public License for more details.
16
! *
17
! * You should have received a copy of the GNU Lesser General Public
18
! * License along with this library (in file ../LGPL-2.1); if not, write
19
! * to the Free Software Foundation, Inc., 51 Franklin Street,
20
! * Fifth Floor, Boston, MA 02110-1301 USA
21
! *
22
! *****************************************************************************/
23
!
24
!/******************************************************************************
25
! *
26
! * Authors: Juha Ruokolainen
27
! * Email: [email protected]
28
! * Web: http://www.csc.fi/elmer
29
! * Address: CSC - IT Center for Science Ltd.
30
! * Keilaranta 14
31
! * 02101 Espoo, Finland
32
! *
33
! * Original Date: 01 Oct 1996
34
! *
35
! ******************************************************************************/
36
37
!----------------------------------------------------------------------
38
!> Diffuse-convective local matrix computing in cartesian coordinates.
39
!> Used nowadays only by HeatSolver.
40
!----------------------------------------------------------------------
41
!> \ingroup ElmerLib
42
!> \{
43
MODULE DiffuseConvective
44
45
USE DefUtils
46
USE Differentials
47
USE MaterialModels
48
49
IMPLICIT NONE
50
51
CONTAINS
52
53
!------------------------------------------------------------------------------
54
!> Return element local matrices and RHS vector for diffusion-convection
55
!> equation:
56
!------------------------------------------------------------------------------
57
SUBROUTINE DiffuseConvectiveCompose( MassMatrix,StiffMatrix,ForceVector, &
58
LoadVector,NodalCT,NodalC0,NodalC1,NodalC2,PhaseChange,NodalTemperature, &
59
Enthalpy,Ux,Uy,Uz,MUx,MUy,MUz,Nodalmu,Nodalrho,NodalPressure, &
60
NodaldPressureDt, NodalPressureCoeff, Compressible, Stabilize, &
61
UseBubbles, Element,n,Nodes )
62
!------------------------------------------------------------------------------
63
!
64
! REAL(KIND=dp) :: MassMatrix(:,:)
65
! OUTPUT: time derivative coefficient matrix
66
!
67
! REAL(KIND=dp) :: StiffMatrix(:,:)
68
! OUTPUT: rest of the equation coefficients
69
!
70
! REAL(KIND=dp) :: ForceVector(:)
71
! OUTPUT: RHS vector
72
!
73
! REAL(KIND=dp) :: LoadVector(:)
74
! INPUT:
75
!
76
! REAL(KIND=dp) :: NodalCT,NodalC0,NodalC1
77
! INPUT: Coefficient of the time derivative term, 0 degree term, and
78
! the convection term respectively
79
!
80
! REAL(KIND=dp) :: NodalC2(:,:,:)
81
! INPUT: Nodal values of the diffusion term coefficient tensor
82
!
83
! LOGICAL :: PhaseChange
84
! INPUT: Do we model phase change here...
85
!
86
! REAL(KIND=dp) :: NodalTemperature
87
! INPUT: NodalTemperature from previous iteration
88
!
89
! REAL(KIND=dp) :: Enthalpy
90
! INPUT: Enthalpy from previous iteration, needed if we model
91
! phase change
92
!
93
! REAL(KIND=dp) :: UX(:),UY(:),UZ(:)
94
! INPUT: Nodal values of velocity components from previous iteration
95
! used only if coefficient of the convection term (C1) is nonzero
96
!
97
! REAL(KIND=dp) :: Nodalmu(:)
98
! INPUT: Nodal values of the viscosity
99
!
100
! LOGICAL :: Stabilize
101
! INPUT: Should stabilzation be used ? Used only if coefficient of the
102
! convection term (C1) is nonzero
103
!
104
! TYPE(Element_t) :: Element
105
! INPUT: Structure describing the element (dimension,nof nodes,
106
! interpolation degree, etc...)
107
!
108
! INTEGER :: n
109
! INPUT: Number of element nodes
110
!
111
! TYPE(Nodes_t) :: Nodes
112
! INPUT: Element node coordinates
113
!
114
!------------------------------------------------------------------------------
115
116
REAL(KIND=dp), DIMENSION(:) :: ForceVector,UX,UY,UZ,MUX,MUY,MUZ,LoadVector
117
REAL(KIND=dp), DIMENSION(:,:) :: MassMatrix,StiffMatrix
118
REAL(KIND=dp) :: NodalTemperature(:),Enthalpy(:),Nodalmu(:), &
119
NodaldPressureDt(:),NodalPressure(:),NodalPressureCoeff(:),Nodalrho(:)
120
REAL(KIND=dp) :: NodalC0(:),NodalC1(:),NodalCT(:),NodalC2(:,:,:)
121
122
LOGICAL :: UseBubbles,PhaseChange,Compressible,Stabilize, VectH
123
124
INTEGER :: n
125
126
TYPE(Nodes_t) :: Nodes
127
TYPE(Element_t), POINTER :: Element
128
129
!------------------------------------------------------------------------------
130
! Local variables
131
!------------------------------------------------------------------------------
132
133
CHARACTER(:), ALLOCATABLE :: StabilizeFlag
134
REAL(KIND=dp) :: dBasisdx(2*n,3),detJ
135
REAL(KIND=dp) :: Basis(2*n)
136
REAL(KIND=dp) :: ddBasisddx(n,3,3),dNodalBasisdx(n,n,3)
137
138
REAL(KIND=dp) :: Velo(3),Grad(3,3),Force
139
140
REAL(KIND=dp) :: A,M
141
REAL(KIND=dp) :: Load
142
143
REAL(KIND=dp) :: VNorm,hK,mK,hScale
144
REAL(KIND=dp) :: Lambda=1.0,Pe,Pe1,Pe2,Tau,x,y,z
145
146
REAL(KIND=dp) :: Tau_M, Tau_C, Gmat(3,3),Gvec(3), dt=0._dp, LC1, NodalVelo(4,n), &
147
RM(n),LC(3,n), gradP(n), VRM(3), GradNodal(n,4,3), PVelo(3), NodalPVelo(4,n), &
148
Work(3,n), Grav(3), expc, reft, temperature
149
150
REAL(KIND=dp), POINTER :: gWrk(:,:)
151
152
INTEGER :: i,j,k,c,p,q,t,dim,N_Integ,NBasis,Order
153
154
TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff
155
REAL(KIND=dp) :: s,u,v,w,dEnth,dTemp,mu,DivVelo,Pressure,rho,&
156
Pcoeff, minl, maxl, SSCond
157
158
REAL(KIND=dp) :: C0,C00,C1,CT,CL,C2(3,3),dC2dx(3,3,3),SU(n),SW(n)
159
160
REAL(KIND=dp), DIMENSION(:), POINTER :: U_Integ,V_Integ,W_Integ,S_Integ
161
162
LOGICAL :: Vms, Found, Transient, stat,Convection,ConvectAndStabilize,Bubbles, &
163
FrictionHeat, PBubbles
164
TYPE(ValueList_t), POINTER :: BodyForce, Material
165
LOGICAL :: GotCondModel
166
167
!------------------------------------------------------------------------------
168
169
VectH = GetLogical( GetSolverParams(), 'VectH', Found )
170
IF(.NOT. Found) VectH = .FALSE.
171
172
StabilizeFlag = GetString( GetSolverParams(),'Stabilization Method',Found )
173
Vms = StabilizeFlag == 'vms'
174
175
Material => GetMaterial()
176
GotCondModel = ListCheckPresent( Material,'Heat Conductivity Model')
177
178
179
dim = CoordinateSystemDimension()
180
c = dim + 1
181
182
ForceVector = 0.0_dp
183
StiffMatrix = 0.0_dp
184
MassMatrix = 0.0_dp
185
Load = 0.0_dp
186
187
CL = 0
188
189
Convection = ANY( NodalC1 /= 0.0d0 )
190
NBasis = n
191
Bubbles = .FALSE.
192
IF ( Convection .AND. .NOT. (Vms .OR. Stabilize) .AND. UseBubbles ) THEN
193
PBubbles = isActivePElement(Element) .AND. Element % BDOFs > 0
194
IF ( PBubbles ) THEN
195
NBasis = n + Element % BDOFs
196
ELSE
197
NBasis = 2*n
198
Bubbles = .TRUE.
199
END IF
200
END IF
201
202
!------------------------------------------------------------------------------
203
! Integration stuff
204
!------------------------------------------------------------------------------
205
IF ( Bubbles ) THEN
206
IntegStuff = GaussPoints( element, Element % TYPE % GaussPoints2 )
207
ELSE
208
IntegStuff = GaussPoints( element )
209
END IF
210
U_Integ => IntegStuff % u
211
V_Integ => IntegStuff % v
212
W_Integ => IntegStuff % w
213
S_Integ => IntegStuff % s
214
N_Integ = IntegStuff % n
215
216
!------------------------------------------------------------------------------
217
! Stabilization parameters: hK, mK (take a look at Franca et.al.)
218
! If there is no convection term we don t need stabilization.
219
!------------------------------------------------------------------------------
220
hScale = GetCReal( GetSolverParams(), 'H scale', Found )
221
IF(.NOT.Found) hScale = 1._dp
222
223
hK = element % hK * hScale
224
mK = element % StabilizationMK
225
226
ConvectAndStabilize = .FALSE.
227
IF ( Vms .OR. VectH ) THEN
228
NodalVelo(1,1:n) = Ux(1:n)
229
NodalVelo(2,1:n) = Uy(1:n)
230
NodalVelo(3,1:n) = Uz(1:n)
231
NodalVelo(dim+1,1:n) = NodalPressure(1:n)
232
233
dNodalBasisdx = 0._dp
234
GradNodal = 0._dp
235
DO p=1,n
236
u = Element % TYPE % NodeU(p)
237
v = Element % TYPE % NodeV(p)
238
w = Element % TYPE % NodeW(p)
239
stat = ElementInfo( Element, Nodes, u,v,w, detJ, Basis, dBasisdx )
240
241
dNodalBasisdx(1:n,p,:) = dBasisdx(1:n,:)
242
GradNodal(p,1:dim,1:dim) = MATMUL( NodalVelo(1:dim,1:n), dBasisdx(1:n,1:dim) )
243
GradNodal(p,dim+1,1:dim) = MATMUL( NodalVelo(dim+1,1:n), dBasisdx(1:n,1:dim) )
244
END DO
245
246
NodalPvelo = 0._dp
247
248
! transient flag only needed for vms
249
Transient = GetString(GetSimulation(),'Simulation type',Found)=='transient'
250
SSCond = ListGetConstReal(GetSolverParams(), "Steady State Condition", Found)
251
IF(Found .AND. SSCond > 0.0_dp) Transient = .FALSE.
252
253
IF ( Transient ) THEN
254
dt = CurrentModel % Solver % dt
255
Order = MIN(CurrentModel % Solver % DoneTime,CurrentModel % Solver % Order)
256
257
CALL GetVectorLocalSolution( NodalPVelo, 'Flow Solution', tStep=-1 )
258
259
IF ( Order<2 ) THEN
260
NodalPVelo(1:dim,1:n)=(NodalVelo(1:dim,1:n)-NodalPVelo(1:dim,1:n))/dt
261
ELSE
262
CALL GetVectorLocalSolution( Work, 'Flow Solution', tStep=-2 )
263
NodalPVelo(1:dim,1:n)=(1.5_dp*NodalVelo(1:dim,1:n) - &
264
2._dp*NodalPVelo(1:dim,1:n)+0.5_dp*Work(1:dim,1:n) )/dt
265
END IF
266
END IF
267
268
expc = GetCReal(Material,'Heat Expansion Coefficient',Found)
269
reft = GetCReal(Material,'Reference Temperature',Found)
270
CALL GetConstRealArray( GetConstants(), gWrk, 'Grav',Found )
271
IF ( Found ) THEN
272
grav = gWrk(1:3,1)*gWrk(4,1)
273
ELSE
274
grav = 0.00_dp
275
grav(2) = -9.81_dp
276
END IF
277
278
LC1 = 2._dp/mK
279
LC(1,1:n) = Element % TYPE % NodeU(1:n)
280
LC(2,1:n) = Element % TYPE % NodeV(1:n)
281
LC(3,1:n) = Element % TYPE % NodeW(1:n)
282
283
DO i=1,Element % TYPE % DIMENSION
284
minl=MINVAL(LC(i,1:n))
285
maxl=MAXVAL(LC(i,1:n))
286
LC(i,1:n) = 2*(LC(i,1:n)-minl)/(maxl-minl)-1
287
END DO
288
ELSE IF ( Stabilize .AND. Convection ) THEN
289
ConvectAndStabilize = .TRUE.
290
hK = element % hK * hScale
291
mK = element % StabilizationMK
292
dNodalBasisdx = 0._dp
293
DO p=1,n
294
u = Element % TYPE % NodeU(p)
295
v = Element % TYPE % NodeV(p)
296
w = Element % TYPE % NodeW(p)
297
stat = ElementInfo( Element, Nodes, u,v,w, detJ, Basis, dBasisdx )
298
dNodalBasisdx(1:n,p,:) = dBasisdx(1:n,:)
299
END DO
300
END IF
301
302
BodyForce => GetBodyForce()
303
FrictionHeat = .FALSE.
304
IF (ASSOCIATED(BodyForce)) &
305
FrictionHeat = GetLogical( BodyForce, 'Friction Heat', Found )
306
!------------------------------------------------------------------------------
307
! Now we start integrating
308
!------------------------------------------------------------------------------
309
DO t=1,N_Integ
310
311
u = U_Integ(t)
312
v = V_Integ(t)
313
w = W_Integ(t)
314
315
!------------------------------------------------------------------------------
316
! Basis function values & derivatives at the integration point
317
!------------------------------------------------------------------------------
318
stat = ElementInfo( Element,Nodes,u,v,w,detJ, &
319
Basis,dBasisdx, Bubbles=Bubbles )
320
321
s = detJ * S_Integ(t)
322
!------------------------------------------------------------------------------
323
! Coefficient of the convection and time derivative terms
324
! at the integration point
325
!------------------------------------------------------------------------------
326
C0 = SUM( NodalC0(1:n) * Basis(1:n) )
327
C1 = SUM( NodalC1(1:n) * Basis(1:n) )
328
CT = SUM( NodalCT(1:n) * Basis(1:n) )
329
!------------------------------------------------------------------------------
330
! Compute effective heatcapacity, if modelling phase change,
331
! at the integration point.
332
! NOTE: This is for heat equation only, not generally for diff.conv. equ.
333
!------------------------------------------------------------------------------
334
IF ( PhaseChange ) THEN
335
dEnth = 0.0D0
336
dTemp = 0.0D0
337
DO i=1,3
338
dEnth = dEnth + SUM( Enthalpy(1:n) * dBasisdx(1:n,i) )**2
339
dTemp = dTemp + SUM( NodalTemperature(1:n) * dBasisdx(1:n,i) )**2
340
END DO
341
342
IF( dTemp > TINY( dTemp ) ) THEN
343
CL = SQRT( dEnth/dTemp )
344
ELSE
345
CALL Info('DiffuseConvectiveCompose',&
346
'Temperature difference almost zero, cannot account for phase change!',Level=7)
347
CL = 0.0
348
END IF
349
CT = CT + CL
350
END IF
351
!------------------------------------------------------------------------------
352
! Coefficient of the diffusion term & it s derivatives at the
353
! integration point
354
!------------------------------------------------------------------------------
355
rho = SUM( Nodalrho(1:n) * Basis(1:n) )
356
357
DO i=1,dim
358
DO j=1,dim
359
C2(i,j) = SUM( NodalC2(i,j,1:n) * Basis(1:n) )
360
END DO
361
END DO
362
363
IF( GotCondModel ) THEN
364
DO i=1,dim
365
C2(i,i) = EffectiveConductivity( C2(i,i), rho, Element, &
366
NodalTemperature, UX,UY,UZ, Nodes, n, n, u, v, w )
367
END DO
368
END IF
369
370
!------------------------------------------------------------------------------
371
! If there's no convection term we don't need the velocities, and
372
! also no need for stabilization
373
!------------------------------------------------------------------------------
374
Convection = .FALSE.
375
IF ( C1 /= 0.0D0 ) THEN
376
Convection = .TRUE.
377
IF ( PhaseChange ) C1 = C1 + CL
378
!------------------------------------------------------------------------------
379
! Velocity from previous iteration at the integration point
380
!------------------------------------------------------------------------------
381
Velo = 0.0D0
382
Velo(1) = SUM( (UX(1:n)-MUX(1:n))*Basis(1:n) )
383
Velo(2) = SUM( (UY(1:n)-MUY(1:n))*Basis(1:n) )
384
IF ( dim > 2 ) Velo(3) = SUM( (UZ(1:n)-MUZ(1:n))*Basis(1:n) )
385
386
IF ( Compressible ) THEN
387
Grad = 0.0D0
388
DO i=1,3
389
Grad(1,i) = SUM( UX(1:n)*dBasisdx(1:n,i) )
390
Grad(2,i) = SUM( UY(1:n)*dBasisdx(1:n,i) )
391
IF ( dim > 2 ) Grad(3,i) = SUM( UZ(1:n)*dBasisdx(1:n,i) )
392
END DO
393
394
Pressure = SUM( NodalPressure(1:n)*Basis(1:n) )
395
DivVelo = 0.0D0
396
DO i=1,dim
397
DivVelo = DivVelo + Grad(i,i)
398
END DO
399
END IF
400
401
402
IF ( Vms .OR. VectH ) THEN
403
mu = GetCReal( Material, 'Viscosity', Found )
404
mu = EffectiveViscosity( mu, rho, Ux, Uy, Uz, &
405
Element, Nodes, n, n, u,v,w,LocalIP=t )
406
407
Grad = 0.0D0
408
DO i=1,3
409
Grad(1,i) = SUM( Ux(1:n)*dBasisdx(1:n,i) )
410
Grad(2,i) = SUM( Uy(1:n)*dBasisdx(1:n,i) )
411
Grad(3,i) = SUM( Uz(1:n)*dBasisdx(1:n,i) )
412
END DO
413
VNorm = SQRT( SUM(Velo(1:dim)**2) )
414
415
Temperature = SUM(Basis(1:n)*NodalTemperature(1:n))
416
417
DO i=1,dim
418
GradP(i) = SUM( NodalPressure(1:n)*dBasisdx(1:n,i) )
419
END DO
420
421
Gmat = 0._dp
422
Gvec = 0._dp
423
DO i=1,dim
424
DO j=1,dim
425
Gvec(i) = Gvec(i) + SUM(LC(j,1:n)*dBasisdx(1:n,i))
426
DO k=1,dim
427
Gmat(i,j) = Gmat(i,j) + SUM(LC(k,1:n)*dBasisdx(1:n,i)) * &
428
SUM(LC(k,1:n)*dBasisdx(1:n,j))
429
END DO
430
END DO
431
END DO
432
433
IF ( Transient ) THEN
434
Tau_M = 1._dp / SQRT( SUM(C1*Velo*MATMUL(Gmat,C1*Velo)) + &
435
C2(1,1)**2 * LC1**2*SUM(Gmat*Gmat)/dim + C1**2*4/dt**2 )
436
ELSE
437
Tau_M = 1._dp / SQRT( SUM(C1*Velo*MATMUL(Gmat,C1*Velo)) + &
438
C2(1,1)**2 * LC1**2 * SUM(Gmat*Gmat)/dim )
439
END IF
440
441
IF(Vms) THEN
442
RM = 0._dp
443
DO p=1,n
444
RM(p) = C0 * Basis(p)
445
DO i=1,dim
446
RM(p) = RM(p) + C1 * Velo(i) * dBasisdx(p,i)
447
DO j=1,dim
448
RM(p) = RM(p) - C2(i,j)*SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))
449
END DO
450
END DO
451
END DO
452
453
VRM = 0._dp
454
DO i=1,dim
455
VRM(i) = SUM(NodalPVelo(i,1:n)*Basis(1:n))
456
DO j=1,dim
457
VRM(i) = VRM(i) + Velo(j) * Grad(i,j)
458
VRM(i) = VRM(i) - (mu/rho)*SUM(GradNodal(1:n,i,j)*dBasisdx(1:n,j))
459
END DO
460
VRM(i) = VRM(i) + GradP(i)
461
VRM(i) = VRM(i) + Grav(i)*ExpC*( Temperature - RefT )
462
END DO
463
END IF
464
END IF
465
466
IF ( .NOT.Vms.AND.Stabilize ) THEN
467
!------------------------------------------------------------------------------
468
! Stabilization parameter Tau
469
!------------------------------------------------------------------------------
470
VNorm = SQRT( SUM(Velo(1:dim)**2) )
471
472
#if 1
473
Pe = MIN( 1.0D0, mK*hK*C1*VNorm/(2*ABS(C2(1,1))) )
474
Tau = 0.0D0
475
IF ( VNorm /= 0.0 ) THEN
476
Tau = hK * Pe / (2 * C1 * VNorm)
477
END IF
478
479
IF (VectH) Tau = 2*Tau_M
480
#else
481
C00 = C0
482
IF ( DT /= 0.0d0 ) C00 = C0+CT/DT
483
484
Pe1 = 0.0d0
485
IF ( C00 /= 0.0d0 ) THEN
486
Pe1 = 2*ABS(C2(1,1)) / (mK*C00*hK**2)
487
Pe1 = C00 * hK**2 * MAX( 1.0d0, Pe1 )
488
ELSE
489
Pe1 = 2 * ABS(C2(1,1)) / mK
490
END IF
491
492
Pe2 = 0.0d0
493
IF ( C2(1,1) /= 0.0d0 ) THEN
494
Pe2 = ( mK * C1 * VNorm * hK ) / ABS(C2(1,1))
495
Pe2 = 2 * ABS(C2(1,1)) * MAX( 1.0d0, Pe2 ) / mK
496
Pe = MIN( 1.0D0, mK*hK*C1*VNorm/(2*ABS(C2(1,1))) )
497
ELSE
498
Pe2 = 2 * hK * C1 * VNorm
499
END IF
500
501
Tau = hk**2 / ( Pe1 + Pe2 )
502
#endif
503
!------------------------------------------------------------------------------
504
505
DO i=1,dim
506
DO j=1,dim
507
DO k=1,dim
508
dC2dx(i,j,k) = SUM( NodalC2(i,j,1:n)*dBasisdx(1:n,k) )
509
END DO
510
END DO
511
END DO
512
513
!------------------------------------------------------------------------------
514
! Compute residual & stablization vectors
515
!------------------------------------------------------------------------------
516
DO p=1,N
517
SU(p) = C0 * Basis(p)
518
DO i = 1,dim
519
SU(p) = SU(p) + C1 * dBasisdx(p,i) * Velo(i)
520
DO j=1,dim
521
SU(p) = SU(p) - dC2dx(i,j,j) * dBasisdx(p,i)
522
SU(p) = SU(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))
523
END DO
524
END DO
525
526
SW(p) = C0 * Basis(p)
527
DO i = 1,dim
528
SW(p) = SW(p) + C1 * dBasisdx(p,i) * Velo(i)
529
DO j=1,dim
530
SW(p) = SW(p) - dC2dx(i,j,j) * dBasisdx(p,i)
531
SW(p) = SW(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))
532
END DO
533
END DO
534
END DO
535
END IF
536
END IF
537
538
!------------------------------------------------------------------------------
539
! Loop over basis functions of both unknowns and weights
540
!------------------------------------------------------------------------------
541
DO p=1,NBasis
542
DO q=1,NBasis
543
!------------------------------------------------------------------------------
544
! The diffusive-convective equation without stabilization
545
!------------------------------------------------------------------------------
546
M = CT * Basis(q) * Basis(p)
547
A = C0 * Basis(q) * Basis(p)
548
!------------------------------------------------------------------------------
549
! The diffusion term
550
!------------------------------------------------------------------------------
551
DO i=1,dim
552
DO j=1,dim
553
A = A + C2(i,j) * dBasisdx(q,i) * dBasisdx(p,j)
554
END DO
555
END DO
556
557
IF ( Convection ) THEN
558
!------------------------------------------------------------------------------
559
! The convection term
560
!------------------------------------------------------------------------------
561
DO i=1,dim
562
A = A + C1 * Velo(i) * dBasisdx(q,i) * Basis(p)
563
END DO
564
!------------------------------------------------------------------------------
565
! Next we add the stabilization...
566
!------------------------------------------------------------------------------
567
IF ( Vms ) THEN
568
DO i=1,dim
569
A = A - C1 * Tau_M * VRM(i) * dBasisdx(q,i) * Basis(p)
570
571
A = A + C1 * Velo(i) * Tau * RM(q) * dBasisdx(p,i)
572
M = M + C1 * Velo(i) * Tau * CT * Basis(q) * dBasisdx(p,i)
573
574
A = A - C1 * Tau_M * VRM(i) * Tau * RM(q) * dBasisdx(p,i)
575
M = M - C1 * Tau_M * VRM(i) * Tau * CT * Basis(q) * dBasisdx(p,i)
576
END DO
577
ELSE IF ( Stabilize ) THEN
578
A = A + Tau * SU(q) * SW(p)
579
M = M + Tau * CT * Basis(q) * SW(p)
580
END IF
581
END IF
582
583
StiffMatrix(p,q) = StiffMatrix(p,q) + s * A
584
MassMatrix(p,q) = MassMatrix(p,q) + s * M
585
END DO
586
END DO
587
588
!------------------------------------------------------------------------------
589
! The righthand side...
590
!------------------------------------------------------------------------------
591
! Force at the integration point
592
!------------------------------------------------------------------------------
593
Force = SUM( LoadVector(1:n)*Basis(1:n) ) + &
594
JouleHeat( Element, Nodes, u, v, w, n )
595
596
IF ( Convection ) THEN
597
! IF ( Compressible ) Force = Force - Pressure * DivVelo
598
599
Pcoeff = SUM(NodalPressureCoeff(1:n)*Basis(1:n))
600
IF ( Pcoeff /= 0.0_dp ) THEN
601
Force = Force + Pcoeff * SUM(NodalDPressureDt(1:n)*Basis(1:n))
602
DO i=1,dim
603
Force = Force + Pcoeff*Velo(i)*SUM(NodalPressure(1:n)*dBasisdx(1:n,i))
604
END DO
605
END IF
606
607
IF ( FrictionHeat ) THEN
608
mu = SUM( Nodalmu(1:n) * Basis(1:n) )
609
mu = EffectiveViscosity( mu, rho, Ux, Uy, Uz, &
610
Element, Nodes, n, n, u,v,w )
611
IF ( mu > 0.0d0 ) THEN
612
IF ( .NOT.Compressible ) THEN
613
Grad = 0.0D0
614
DO i=1,3
615
Grad(1,i) = SUM( UX(1:n)*dBasisdx(1:n,i) )
616
Grad(2,i) = SUM( UY(1:n)*dBasisdx(1:n,i) )
617
IF ( dim > 2 ) Grad(3,i) = SUM( UZ(1:n)*dBasisdx(1:n,i) )
618
END DO
619
END IF
620
Force = Force + 0.5d0 * mu*SecondInvariant(Velo,Grad)
621
END IF
622
END IF
623
END IF
624
!------------------------------------------------------------------------------
625
DO p=1,NBasis
626
Load = Force * Basis(p)
627
IF ( Vms ) THEN
628
DO i=1,dim
629
Load = Load + C1 * Velo(i) * Tau * Force * dBasisdx(p,i)
630
Load = Load - C1 * Tau_M * VRM(i) * Tau * Force * dBasisdx(p,i)
631
END DO
632
ELSE IF ( ConvectAndStabilize ) THEN
633
Load = Load + Tau * Force * SW(p)
634
END IF
635
ForceVector(p) = ForceVector(p) + s * Load
636
END DO
637
END DO
638
!------------------------------------------------------------------------------
639
END SUBROUTINE DiffuseConvectiveCompose
640
!------------------------------------------------------------------------------
641
642
643
!------------------------------------------------------------------------------
644
!> Return element local matrices and RSH vector for boundary conditions
645
!> of diffusion convection equation:
646
!------------------------------------------------------------------------------
647
SUBROUTINE DiffuseConvectiveBoundary( BoundaryMatrix,BoundaryVector, &
648
LoadVector,NodalAlpha,OpenBC,NodalCond,NodalExt,Element,n,Nodes )
649
!------------------------------------------------------------------------------
650
!
651
! REAL(KIND=dp) :: BoundaryMatrix(:,:)
652
! OUTPUT: coefficient matrix if equations
653
!
654
! REAL(KIND=dp) :: BoundaryVector(:)
655
! OUTPUT: RHS vector
656
!
657
! REAL(KIND=dp) :: LoadVector(:)
658
! INPUT: coefficient of the force term
659
!
660
! REAL(KIND=dp) :: NodalAlpha
661
! INPUT: coefficient for temperature dependent term
662
!
663
! TYPE(Element_t) :: Element
664
! INPUT: Structure describing the element (dimension,nof nodes,
665
! interpolation degree, etc...)
666
!
667
! INTEGER :: n
668
! INPUT: Number of element nodes
669
!
670
! TYPE(Nodes_t) :: Nodes
671
! INPUT: Element node coordinates
672
!
673
!------------------------------------------------------------------------------
674
675
REAL(KIND=dp) :: BoundaryMatrix(:,:),BoundaryVector(:), &
676
LoadVector(:),NodalAlpha(:),NodalCond(:),NodalExt(:)
677
LOGICAL :: OpenBC
678
TYPE(Nodes_t) :: Nodes
679
TYPE(Element_t), POINTER :: Element
680
681
INTEGER :: n
682
683
REAL(KIND=dp) :: ddBasisddx(n,3,3)
684
REAL(KIND=dp) :: Basis(n)
685
REAL(KIND=dp) :: dBasisdx(n,3),detJ
686
687
REAL(KIND=dp) :: U,V,W,S
688
REAL(KIND=dp) :: Force,Alpha,Normal(3),Coord(3),x,y,z
689
REAL(KIND=dp), POINTER :: U_Integ(:),V_Integ(:),W_Integ(:),S_Integ(:)
690
691
INTEGER :: i,t,q,p,N_Integ
692
693
TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff
694
695
LOGICAL :: stat
696
!------------------------------------------------------------------------------
697
698
BoundaryVector = 0.0D0
699
BoundaryMatrix = 0.0D0
700
!------------------------------------------------------------------------------
701
! Integration stuff
702
!------------------------------------------------------------------------------
703
IntegStuff = GaussPoints( Element )
704
U_Integ => IntegStuff % u
705
V_Integ => IntegStuff % v
706
W_Integ => IntegStuff % w
707
S_Integ => IntegStuff % s
708
N_Integ = IntegStuff % n
709
710
!------------------------------------------------------------------------------
711
! Now we start integrating
712
!------------------------------------------------------------------------------
713
DO t=1,N_Integ
714
U = U_Integ(t)
715
V = V_Integ(t)
716
W = W_Integ(t)
717
!------------------------------------------------------------------------------
718
! Basis function values & derivatives at the integration point
719
!------------------------------------------------------------------------------
720
stat = ElementInfo( Element,Nodes,u,v,w,detJ, &
721
Basis,dBasisdx )
722
723
S = detJ * S_Integ(t)
724
!------------------------------------------------------------------------------
725
Force = SUM( LoadVector(1:n)*Basis )
726
Alpha = SUM( NodalAlpha(1:n)*Basis )
727
728
IF( OpenBC ) THEN
729
x = SUM( Nodes % x(1:n)*Basis(1:n) )
730
y = SUM( Nodes % y(1:n)*Basis(1:n) )
731
z = SUM( Nodes % z(1:n)*Basis(1:n) )
732
733
Normal = NormalVector( Element, Nodes, u, v, .TRUE. )
734
Coord(1) = x
735
Coord(2) = y
736
Coord(3) = z
737
Alpha = SUM( Basis(1:n) * NodalCond(1:n) ) * &
738
SUM( Coord * Normal ) / SUM( Coord * Coord )
739
Force = Alpha * SUM( Basis(1:n) * NodalExt(1:n) )
740
END IF
741
742
DO p=1,N
743
DO q=1,N
744
BoundaryMatrix(p,q) = BoundaryMatrix(p,q) + &
745
s * Alpha * Basis(q) * Basis(p)
746
END DO
747
END DO
748
749
DO q=1,N
750
BoundaryVector(q) = BoundaryVector(q) + s * Basis(q) * Force
751
END DO
752
END DO
753
END SUBROUTINE DiffuseConvectiveBoundary
754
!------------------------------------------------------------------------------
755
756
END MODULE DiffuseConvective
757
758
!> \}
759
760