Path: blob/devel/fem/src/DiffuseConvectiveAnisotropic.F90
3203 views
!/*****************************************************************************/1! *2! * Elmer, A Finite Element Software for Multiphysical Problems3! *4! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5! *6! * This library is free software; you can redistribute it and/or7! * modify it under the terms of the GNU Lesser General Public8! * License as published by the Free Software Foundation; either9! * version 2.1 of the License, or (at your option) any later version.10! *11! * This library is distributed in the hope that it will be useful,12! * but WITHOUT ANY WARRANTY; without even the implied warranty of13! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14! * Lesser General Public License for more details.15! *16! * You should have received a copy of the GNU Lesser General Public17! * License along with this library (in file ../LGPL-2.1); if not, write18! * to the Free Software Foundation, Inc., 51 Franklin Street,19! * Fifth Floor, Boston, MA 02110-1301 USA20! *21! *****************************************************************************/22!23!/******************************************************************************24! *25! * Authors: Juha Ruokolainen26! * Email: [email protected]27! * Web: http://www.csc.fi/elmer28! * Address: CSC - IT Center for Science Ltd.29! * Keilaranta 1430! * 02101 Espoo, Finland31! *32! * Original Date: 01 Oct 199633! *34! ******************************************************************************/3536!----------------------------------------------------------------------37!> Diffuse-convective local matrix computing in cartesian coordinates.38!> Used nowadays only by HeatSolver.39!----------------------------------------------------------------------40!> \ingroup ElmerLib41!> \{42MODULE DiffuseConvective4344USE DefUtils45USE Differentials46USE MaterialModels4748IMPLICIT NONE4950CONTAINS5152!------------------------------------------------------------------------------53!> Return element local matrices and RHS vector for diffusion-convection54!> equation:55!------------------------------------------------------------------------------56SUBROUTINE DiffuseConvectiveCompose( MassMatrix,StiffMatrix,ForceVector, &57LoadVector,NodalCT,NodalC0,NodalC1,NodalC2,PhaseChange,NodalTemperature, &58Enthalpy,Ux,Uy,Uz,MUx,MUy,MUz,Nodalmu,Nodalrho,NodalPressure, &59NodaldPressureDt, NodalPressureCoeff, Compressible, Stabilize, &60UseBubbles, Element,n,Nodes )61!------------------------------------------------------------------------------62!63! REAL(KIND=dp) :: MassMatrix(:,:)64! OUTPUT: time derivative coefficient matrix65!66! REAL(KIND=dp) :: StiffMatrix(:,:)67! OUTPUT: rest of the equation coefficients68!69! REAL(KIND=dp) :: ForceVector(:)70! OUTPUT: RHS vector71!72! REAL(KIND=dp) :: LoadVector(:)73! INPUT:74!75! REAL(KIND=dp) :: NodalCT,NodalC0,NodalC176! INPUT: Coefficient of the time derivative term, 0 degree term, and77! the convection term respectively78!79! REAL(KIND=dp) :: NodalC2(:,:,:)80! INPUT: Nodal values of the diffusion term coefficient tensor81!82! LOGICAL :: PhaseChange83! INPUT: Do we model phase change here...84!85! REAL(KIND=dp) :: NodalTemperature86! INPUT: NodalTemperature from previous iteration87!88! REAL(KIND=dp) :: Enthalpy89! INPUT: Enthalpy from previous iteration, needed if we model90! phase change91!92! REAL(KIND=dp) :: UX(:),UY(:),UZ(:)93! INPUT: Nodal values of velocity components from previous iteration94! used only if coefficient of the convection term (C1) is nonzero95!96! REAL(KIND=dp) :: Nodalmu(:)97! INPUT: Nodal values of the viscosity98!99! LOGICAL :: Stabilize100! INPUT: Should stabilzation be used ? Used only if coefficient of the101! convection term (C1) is nonzero102!103! TYPE(Element_t) :: Element104! INPUT: Structure describing the element (dimension,nof nodes,105! interpolation degree, etc...)106!107! INTEGER :: n108! INPUT: Number of element nodes109!110! TYPE(Nodes_t) :: Nodes111! INPUT: Element node coordinates112!113!------------------------------------------------------------------------------114115REAL(KIND=dp), DIMENSION(:) :: ForceVector,UX,UY,UZ,MUX,MUY,MUZ,LoadVector116REAL(KIND=dp), DIMENSION(:,:) :: MassMatrix,StiffMatrix117REAL(KIND=dp) :: NodalTemperature(:),Enthalpy(:),Nodalmu(:), &118NodaldPressureDt(:),NodalPressure(:),NodalPressureCoeff(:),Nodalrho(:)119REAL(KIND=dp) :: NodalC0(:),NodalC1(:),NodalCT(:),NodalC2(:,:,:)120121LOGICAL :: UseBubbles,PhaseChange,Compressible,Stabilize, VectH122123INTEGER :: n124125TYPE(Nodes_t) :: Nodes126TYPE(Element_t), POINTER :: Element127128!------------------------------------------------------------------------------129! Local variables130!------------------------------------------------------------------------------131132CHARACTER(:), ALLOCATABLE :: StabilizeFlag133REAL(KIND=dp) :: dBasisdx(2*n,3),detJ134REAL(KIND=dp) :: Basis(2*n)135REAL(KIND=dp) :: ddBasisddx(n,3,3),dNodalBasisdx(n,n,3)136137REAL(KIND=dp) :: Velo(3),Grad(3,3),Force138139REAL(KIND=dp) :: A,M140REAL(KIND=dp) :: Load141142REAL(KIND=dp) :: VNorm,hK,mK,hScale143REAL(KIND=dp) :: Lambda=1.0,Pe,Pe1,Pe2,Tau,x,y,z144145REAL(KIND=dp) :: Tau_M, Tau_C, Gmat(3,3),Gvec(3), dt=0._dp, LC1, NodalVelo(4,n), &146RM(n),LC(3,n), gradP(n), VRM(3), GradNodal(n,4,3), PVelo(3), NodalPVelo(4,n), &147Work(3,n), Grav(3), expc, reft, temperature148149REAL(KIND=dp), POINTER :: gWrk(:,:)150151INTEGER :: i,j,k,c,p,q,t,dim,N_Integ,NBasis,Order152153TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff154REAL(KIND=dp) :: s,u,v,w,dEnth,dTemp,mu,DivVelo,Pressure,rho,&155Pcoeff, minl, maxl, SSCond156157REAL(KIND=dp) :: C0,C00,C1,CT,CL,C2(3,3),dC2dx(3,3,3),SU(n),SW(n)158159REAL(KIND=dp), DIMENSION(:), POINTER :: U_Integ,V_Integ,W_Integ,S_Integ160161LOGICAL :: Vms, Found, Transient, stat,Convection,ConvectAndStabilize,Bubbles, &162FrictionHeat, PBubbles163TYPE(ValueList_t), POINTER :: BodyForce, Material164LOGICAL :: GotCondModel165166!------------------------------------------------------------------------------167168VectH = GetLogical( GetSolverParams(), 'VectH', Found )169IF(.NOT. Found) VectH = .FALSE.170171StabilizeFlag = GetString( GetSolverParams(),'Stabilization Method',Found )172Vms = StabilizeFlag == 'vms'173174Material => GetMaterial()175GotCondModel = ListCheckPresent( Material,'Heat Conductivity Model')176177178dim = CoordinateSystemDimension()179c = dim + 1180181ForceVector = 0.0_dp182StiffMatrix = 0.0_dp183MassMatrix = 0.0_dp184Load = 0.0_dp185186CL = 0187188Convection = ANY( NodalC1 /= 0.0d0 )189NBasis = n190Bubbles = .FALSE.191IF ( Convection .AND. .NOT. (Vms .OR. Stabilize) .AND. UseBubbles ) THEN192PBubbles = isActivePElement(Element) .AND. Element % BDOFs > 0193IF ( PBubbles ) THEN194NBasis = n + Element % BDOFs195ELSE196NBasis = 2*n197Bubbles = .TRUE.198END IF199END IF200201!------------------------------------------------------------------------------202! Integration stuff203!------------------------------------------------------------------------------204IF ( Bubbles ) THEN205IntegStuff = GaussPoints( element, Element % TYPE % GaussPoints2 )206ELSE207IntegStuff = GaussPoints( element )208END IF209U_Integ => IntegStuff % u210V_Integ => IntegStuff % v211W_Integ => IntegStuff % w212S_Integ => IntegStuff % s213N_Integ = IntegStuff % n214215!------------------------------------------------------------------------------216! Stabilization parameters: hK, mK (take a look at Franca et.al.)217! If there is no convection term we don t need stabilization.218!------------------------------------------------------------------------------219hScale = GetCReal( GetSolverParams(), 'H scale', Found )220IF(.NOT.Found) hScale = 1._dp221222hK = element % hK * hScale223mK = element % StabilizationMK224225ConvectAndStabilize = .FALSE.226IF ( Vms .OR. VectH ) THEN227NodalVelo(1,1:n) = Ux(1:n)228NodalVelo(2,1:n) = Uy(1:n)229NodalVelo(3,1:n) = Uz(1:n)230NodalVelo(dim+1,1:n) = NodalPressure(1:n)231232dNodalBasisdx = 0._dp233GradNodal = 0._dp234DO p=1,n235u = Element % TYPE % NodeU(p)236v = Element % TYPE % NodeV(p)237w = Element % TYPE % NodeW(p)238stat = ElementInfo( Element, Nodes, u,v,w, detJ, Basis, dBasisdx )239240dNodalBasisdx(1:n,p,:) = dBasisdx(1:n,:)241GradNodal(p,1:dim,1:dim) = MATMUL( NodalVelo(1:dim,1:n), dBasisdx(1:n,1:dim) )242GradNodal(p,dim+1,1:dim) = MATMUL( NodalVelo(dim+1,1:n), dBasisdx(1:n,1:dim) )243END DO244245NodalPvelo = 0._dp246247! transient flag only needed for vms248Transient = GetString(GetSimulation(),'Simulation type',Found)=='transient'249SSCond = ListGetConstReal(GetSolverParams(), "Steady State Condition", Found)250IF(Found .AND. SSCond > 0.0_dp) Transient = .FALSE.251252IF ( Transient ) THEN253dt = CurrentModel % Solver % dt254Order = MIN(CurrentModel % Solver % DoneTime,CurrentModel % Solver % Order)255256CALL GetVectorLocalSolution( NodalPVelo, 'Flow Solution', tStep=-1 )257258IF ( Order<2 ) THEN259NodalPVelo(1:dim,1:n)=(NodalVelo(1:dim,1:n)-NodalPVelo(1:dim,1:n))/dt260ELSE261CALL GetVectorLocalSolution( Work, 'Flow Solution', tStep=-2 )262NodalPVelo(1:dim,1:n)=(1.5_dp*NodalVelo(1:dim,1:n) - &2632._dp*NodalPVelo(1:dim,1:n)+0.5_dp*Work(1:dim,1:n) )/dt264END IF265END IF266267expc = GetCReal(Material,'Heat Expansion Coefficient',Found)268reft = GetCReal(Material,'Reference Temperature',Found)269CALL GetConstRealArray( GetConstants(), gWrk, 'Grav',Found )270IF ( Found ) THEN271grav = gWrk(1:3,1)*gWrk(4,1)272ELSE273grav = 0.00_dp274grav(2) = -9.81_dp275END IF276277LC1 = 2._dp/mK278LC(1,1:n) = Element % TYPE % NodeU(1:n)279LC(2,1:n) = Element % TYPE % NodeV(1:n)280LC(3,1:n) = Element % TYPE % NodeW(1:n)281282DO i=1,Element % TYPE % DIMENSION283minl=MINVAL(LC(i,1:n))284maxl=MAXVAL(LC(i,1:n))285LC(i,1:n) = 2*(LC(i,1:n)-minl)/(maxl-minl)-1286END DO287ELSE IF ( Stabilize .AND. Convection ) THEN288ConvectAndStabilize = .TRUE.289hK = element % hK * hScale290mK = element % StabilizationMK291dNodalBasisdx = 0._dp292DO p=1,n293u = Element % TYPE % NodeU(p)294v = Element % TYPE % NodeV(p)295w = Element % TYPE % NodeW(p)296stat = ElementInfo( Element, Nodes, u,v,w, detJ, Basis, dBasisdx )297dNodalBasisdx(1:n,p,:) = dBasisdx(1:n,:)298END DO299END IF300301BodyForce => GetBodyForce()302FrictionHeat = .FALSE.303IF (ASSOCIATED(BodyForce)) &304FrictionHeat = GetLogical( BodyForce, 'Friction Heat', Found )305!------------------------------------------------------------------------------306! Now we start integrating307!------------------------------------------------------------------------------308DO t=1,N_Integ309310u = U_Integ(t)311v = V_Integ(t)312w = W_Integ(t)313314!------------------------------------------------------------------------------315! Basis function values & derivatives at the integration point316!------------------------------------------------------------------------------317stat = ElementInfo( Element,Nodes,u,v,w,detJ, &318Basis,dBasisdx, Bubbles=Bubbles )319320s = detJ * S_Integ(t)321!------------------------------------------------------------------------------322! Coefficient of the convection and time derivative terms323! at the integration point324!------------------------------------------------------------------------------325C0 = SUM( NodalC0(1:n) * Basis(1:n) )326C1 = SUM( NodalC1(1:n) * Basis(1:n) )327CT = SUM( NodalCT(1:n) * Basis(1:n) )328!------------------------------------------------------------------------------329! Compute effective heatcapacity, if modelling phase change,330! at the integration point.331! NOTE: This is for heat equation only, not generally for diff.conv. equ.332!------------------------------------------------------------------------------333IF ( PhaseChange ) THEN334dEnth = 0.0D0335dTemp = 0.0D0336DO i=1,3337dEnth = dEnth + SUM( Enthalpy(1:n) * dBasisdx(1:n,i) )**2338dTemp = dTemp + SUM( NodalTemperature(1:n) * dBasisdx(1:n,i) )**2339END DO340341IF( dTemp > TINY( dTemp ) ) THEN342CL = SQRT( dEnth/dTemp )343ELSE344CALL Info('DiffuseConvectiveCompose',&345'Temperature difference almost zero, cannot account for phase change!',Level=7)346CL = 0.0347END IF348CT = CT + CL349END IF350!------------------------------------------------------------------------------351! Coefficient of the diffusion term & it s derivatives at the352! integration point353!------------------------------------------------------------------------------354rho = SUM( Nodalrho(1:n) * Basis(1:n) )355356DO i=1,dim357DO j=1,dim358C2(i,j) = SUM( NodalC2(i,j,1:n) * Basis(1:n) )359END DO360END DO361362IF( GotCondModel ) THEN363DO i=1,dim364C2(i,i) = EffectiveConductivity( C2(i,i), rho, Element, &365NodalTemperature, UX,UY,UZ, Nodes, n, n, u, v, w )366END DO367END IF368369!------------------------------------------------------------------------------370! If there's no convection term we don't need the velocities, and371! also no need for stabilization372!------------------------------------------------------------------------------373Convection = .FALSE.374IF ( C1 /= 0.0D0 ) THEN375Convection = .TRUE.376IF ( PhaseChange ) C1 = C1 + CL377!------------------------------------------------------------------------------378! Velocity from previous iteration at the integration point379!------------------------------------------------------------------------------380Velo = 0.0D0381Velo(1) = SUM( (UX(1:n)-MUX(1:n))*Basis(1:n) )382Velo(2) = SUM( (UY(1:n)-MUY(1:n))*Basis(1:n) )383IF ( dim > 2 ) Velo(3) = SUM( (UZ(1:n)-MUZ(1:n))*Basis(1:n) )384385IF ( Compressible ) THEN386Grad = 0.0D0387DO i=1,3388Grad(1,i) = SUM( UX(1:n)*dBasisdx(1:n,i) )389Grad(2,i) = SUM( UY(1:n)*dBasisdx(1:n,i) )390IF ( dim > 2 ) Grad(3,i) = SUM( UZ(1:n)*dBasisdx(1:n,i) )391END DO392393Pressure = SUM( NodalPressure(1:n)*Basis(1:n) )394DivVelo = 0.0D0395DO i=1,dim396DivVelo = DivVelo + Grad(i,i)397END DO398END IF399400401IF ( Vms .OR. VectH ) THEN402mu = GetCReal( Material, 'Viscosity', Found )403mu = EffectiveViscosity( mu, rho, Ux, Uy, Uz, &404Element, Nodes, n, n, u,v,w,LocalIP=t )405406Grad = 0.0D0407DO i=1,3408Grad(1,i) = SUM( Ux(1:n)*dBasisdx(1:n,i) )409Grad(2,i) = SUM( Uy(1:n)*dBasisdx(1:n,i) )410Grad(3,i) = SUM( Uz(1:n)*dBasisdx(1:n,i) )411END DO412VNorm = SQRT( SUM(Velo(1:dim)**2) )413414Temperature = SUM(Basis(1:n)*NodalTemperature(1:n))415416DO i=1,dim417GradP(i) = SUM( NodalPressure(1:n)*dBasisdx(1:n,i) )418END DO419420Gmat = 0._dp421Gvec = 0._dp422DO i=1,dim423DO j=1,dim424Gvec(i) = Gvec(i) + SUM(LC(j,1:n)*dBasisdx(1:n,i))425DO k=1,dim426Gmat(i,j) = Gmat(i,j) + SUM(LC(k,1:n)*dBasisdx(1:n,i)) * &427SUM(LC(k,1:n)*dBasisdx(1:n,j))428END DO429END DO430END DO431432IF ( Transient ) THEN433Tau_M = 1._dp / SQRT( SUM(C1*Velo*MATMUL(Gmat,C1*Velo)) + &434C2(1,1)**2 * LC1**2*SUM(Gmat*Gmat)/dim + C1**2*4/dt**2 )435ELSE436Tau_M = 1._dp / SQRT( SUM(C1*Velo*MATMUL(Gmat,C1*Velo)) + &437C2(1,1)**2 * LC1**2 * SUM(Gmat*Gmat)/dim )438END IF439440IF(Vms) THEN441RM = 0._dp442DO p=1,n443RM(p) = C0 * Basis(p)444DO i=1,dim445RM(p) = RM(p) + C1 * Velo(i) * dBasisdx(p,i)446DO j=1,dim447RM(p) = RM(p) - C2(i,j)*SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))448END DO449END DO450END DO451452VRM = 0._dp453DO i=1,dim454VRM(i) = SUM(NodalPVelo(i,1:n)*Basis(1:n))455DO j=1,dim456VRM(i) = VRM(i) + Velo(j) * Grad(i,j)457VRM(i) = VRM(i) - (mu/rho)*SUM(GradNodal(1:n,i,j)*dBasisdx(1:n,j))458END DO459VRM(i) = VRM(i) + GradP(i)460VRM(i) = VRM(i) + Grav(i)*ExpC*( Temperature - RefT )461END DO462END IF463END IF464465IF ( .NOT.Vms.AND.Stabilize ) THEN466!------------------------------------------------------------------------------467! Stabilization parameter Tau468!------------------------------------------------------------------------------469VNorm = SQRT( SUM(Velo(1:dim)**2) )470471#if 1472Pe = MIN( 1.0D0, mK*hK*C1*VNorm/(2*ABS(C2(1,1))) )473Tau = 0.0D0474IF ( VNorm /= 0.0 ) THEN475Tau = hK * Pe / (2 * C1 * VNorm)476END IF477478IF (VectH) Tau = 2*Tau_M479#else480C00 = C0481IF ( DT /= 0.0d0 ) C00 = C0+CT/DT482483Pe1 = 0.0d0484IF ( C00 /= 0.0d0 ) THEN485Pe1 = 2*ABS(C2(1,1)) / (mK*C00*hK**2)486Pe1 = C00 * hK**2 * MAX( 1.0d0, Pe1 )487ELSE488Pe1 = 2 * ABS(C2(1,1)) / mK489END IF490491Pe2 = 0.0d0492IF ( C2(1,1) /= 0.0d0 ) THEN493Pe2 = ( mK * C1 * VNorm * hK ) / ABS(C2(1,1))494Pe2 = 2 * ABS(C2(1,1)) * MAX( 1.0d0, Pe2 ) / mK495Pe = MIN( 1.0D0, mK*hK*C1*VNorm/(2*ABS(C2(1,1))) )496ELSE497Pe2 = 2 * hK * C1 * VNorm498END IF499500Tau = hk**2 / ( Pe1 + Pe2 )501#endif502!------------------------------------------------------------------------------503504DO i=1,dim505DO j=1,dim506DO k=1,dim507dC2dx(i,j,k) = SUM( NodalC2(i,j,1:n)*dBasisdx(1:n,k) )508END DO509END DO510END DO511512!------------------------------------------------------------------------------513! Compute residual & stablization vectors514!------------------------------------------------------------------------------515DO p=1,N516SU(p) = C0 * Basis(p)517DO i = 1,dim518SU(p) = SU(p) + C1 * dBasisdx(p,i) * Velo(i)519DO j=1,dim520SU(p) = SU(p) - dC2dx(i,j,j) * dBasisdx(p,i)521SU(p) = SU(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))522END DO523END DO524525SW(p) = C0 * Basis(p)526DO i = 1,dim527SW(p) = SW(p) + C1 * dBasisdx(p,i) * Velo(i)528DO j=1,dim529SW(p) = SW(p) - dC2dx(i,j,j) * dBasisdx(p,i)530SW(p) = SW(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))531END DO532END DO533END DO534END IF535END IF536537!------------------------------------------------------------------------------538! Loop over basis functions of both unknowns and weights539!------------------------------------------------------------------------------540DO p=1,NBasis541DO q=1,NBasis542!------------------------------------------------------------------------------543! The diffusive-convective equation without stabilization544!------------------------------------------------------------------------------545M = CT * Basis(q) * Basis(p)546A = C0 * Basis(q) * Basis(p)547!------------------------------------------------------------------------------548! The diffusion term549!------------------------------------------------------------------------------550DO i=1,dim551DO j=1,dim552A = A + C2(i,j) * dBasisdx(q,i) * dBasisdx(p,j)553END DO554END DO555556IF ( Convection ) THEN557!------------------------------------------------------------------------------558! The convection term559!------------------------------------------------------------------------------560DO i=1,dim561A = A + C1 * Velo(i) * dBasisdx(q,i) * Basis(p)562END DO563!------------------------------------------------------------------------------564! Next we add the stabilization...565!------------------------------------------------------------------------------566IF ( Vms ) THEN567DO i=1,dim568A = A - C1 * Tau_M * VRM(i) * dBasisdx(q,i) * Basis(p)569570A = A + C1 * Velo(i) * Tau * RM(q) * dBasisdx(p,i)571M = M + C1 * Velo(i) * Tau * CT * Basis(q) * dBasisdx(p,i)572573A = A - C1 * Tau_M * VRM(i) * Tau * RM(q) * dBasisdx(p,i)574M = M - C1 * Tau_M * VRM(i) * Tau * CT * Basis(q) * dBasisdx(p,i)575END DO576ELSE IF ( Stabilize ) THEN577A = A + Tau * SU(q) * SW(p)578M = M + Tau * CT * Basis(q) * SW(p)579END IF580END IF581582StiffMatrix(p,q) = StiffMatrix(p,q) + s * A583MassMatrix(p,q) = MassMatrix(p,q) + s * M584END DO585END DO586587!------------------------------------------------------------------------------588! The righthand side...589!------------------------------------------------------------------------------590! Force at the integration point591!------------------------------------------------------------------------------592Force = SUM( LoadVector(1:n)*Basis(1:n) ) + &593JouleHeat( Element, Nodes, u, v, w, n )594595IF ( Convection ) THEN596! IF ( Compressible ) Force = Force - Pressure * DivVelo597598Pcoeff = SUM(NodalPressureCoeff(1:n)*Basis(1:n))599IF ( Pcoeff /= 0.0_dp ) THEN600Force = Force + Pcoeff * SUM(NodalDPressureDt(1:n)*Basis(1:n))601DO i=1,dim602Force = Force + Pcoeff*Velo(i)*SUM(NodalPressure(1:n)*dBasisdx(1:n,i))603END DO604END IF605606IF ( FrictionHeat ) THEN607mu = SUM( Nodalmu(1:n) * Basis(1:n) )608mu = EffectiveViscosity( mu, rho, Ux, Uy, Uz, &609Element, Nodes, n, n, u,v,w )610IF ( mu > 0.0d0 ) THEN611IF ( .NOT.Compressible ) THEN612Grad = 0.0D0613DO i=1,3614Grad(1,i) = SUM( UX(1:n)*dBasisdx(1:n,i) )615Grad(2,i) = SUM( UY(1:n)*dBasisdx(1:n,i) )616IF ( dim > 2 ) Grad(3,i) = SUM( UZ(1:n)*dBasisdx(1:n,i) )617END DO618END IF619Force = Force + 0.5d0 * mu*SecondInvariant(Velo,Grad)620END IF621END IF622END IF623!------------------------------------------------------------------------------624DO p=1,NBasis625Load = Force * Basis(p)626IF ( Vms ) THEN627DO i=1,dim628Load = Load + C1 * Velo(i) * Tau * Force * dBasisdx(p,i)629Load = Load - C1 * Tau_M * VRM(i) * Tau * Force * dBasisdx(p,i)630END DO631ELSE IF ( ConvectAndStabilize ) THEN632Load = Load + Tau * Force * SW(p)633END IF634ForceVector(p) = ForceVector(p) + s * Load635END DO636END DO637!------------------------------------------------------------------------------638END SUBROUTINE DiffuseConvectiveCompose639!------------------------------------------------------------------------------640641642!------------------------------------------------------------------------------643!> Return element local matrices and RSH vector for boundary conditions644!> of diffusion convection equation:645!------------------------------------------------------------------------------646SUBROUTINE DiffuseConvectiveBoundary( BoundaryMatrix,BoundaryVector, &647LoadVector,NodalAlpha,OpenBC,NodalCond,NodalExt,Element,n,Nodes )648!------------------------------------------------------------------------------649!650! REAL(KIND=dp) :: BoundaryMatrix(:,:)651! OUTPUT: coefficient matrix if equations652!653! REAL(KIND=dp) :: BoundaryVector(:)654! OUTPUT: RHS vector655!656! REAL(KIND=dp) :: LoadVector(:)657! INPUT: coefficient of the force term658!659! REAL(KIND=dp) :: NodalAlpha660! INPUT: coefficient for temperature dependent term661!662! TYPE(Element_t) :: Element663! INPUT: Structure describing the element (dimension,nof nodes,664! interpolation degree, etc...)665!666! INTEGER :: n667! INPUT: Number of element nodes668!669! TYPE(Nodes_t) :: Nodes670! INPUT: Element node coordinates671!672!------------------------------------------------------------------------------673674REAL(KIND=dp) :: BoundaryMatrix(:,:),BoundaryVector(:), &675LoadVector(:),NodalAlpha(:),NodalCond(:),NodalExt(:)676LOGICAL :: OpenBC677TYPE(Nodes_t) :: Nodes678TYPE(Element_t), POINTER :: Element679680INTEGER :: n681682REAL(KIND=dp) :: ddBasisddx(n,3,3)683REAL(KIND=dp) :: Basis(n)684REAL(KIND=dp) :: dBasisdx(n,3),detJ685686REAL(KIND=dp) :: U,V,W,S687REAL(KIND=dp) :: Force,Alpha,Normal(3),Coord(3),x,y,z688REAL(KIND=dp), POINTER :: U_Integ(:),V_Integ(:),W_Integ(:),S_Integ(:)689690INTEGER :: i,t,q,p,N_Integ691692TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff693694LOGICAL :: stat695!------------------------------------------------------------------------------696697BoundaryVector = 0.0D0698BoundaryMatrix = 0.0D0699!------------------------------------------------------------------------------700! Integration stuff701!------------------------------------------------------------------------------702IntegStuff = GaussPoints( Element )703U_Integ => IntegStuff % u704V_Integ => IntegStuff % v705W_Integ => IntegStuff % w706S_Integ => IntegStuff % s707N_Integ = IntegStuff % n708709!------------------------------------------------------------------------------710! Now we start integrating711!------------------------------------------------------------------------------712DO t=1,N_Integ713U = U_Integ(t)714V = V_Integ(t)715W = W_Integ(t)716!------------------------------------------------------------------------------717! Basis function values & derivatives at the integration point718!------------------------------------------------------------------------------719stat = ElementInfo( Element,Nodes,u,v,w,detJ, &720Basis,dBasisdx )721722S = detJ * S_Integ(t)723!------------------------------------------------------------------------------724Force = SUM( LoadVector(1:n)*Basis )725Alpha = SUM( NodalAlpha(1:n)*Basis )726727IF( OpenBC ) THEN728x = SUM( Nodes % x(1:n)*Basis(1:n) )729y = SUM( Nodes % y(1:n)*Basis(1:n) )730z = SUM( Nodes % z(1:n)*Basis(1:n) )731732Normal = NormalVector( Element, Nodes, u, v, .TRUE. )733Coord(1) = x734Coord(2) = y735Coord(3) = z736Alpha = SUM( Basis(1:n) * NodalCond(1:n) ) * &737SUM( Coord * Normal ) / SUM( Coord * Coord )738Force = Alpha * SUM( Basis(1:n) * NodalExt(1:n) )739END IF740741DO p=1,N742DO q=1,N743BoundaryMatrix(p,q) = BoundaryMatrix(p,q) + &744s * Alpha * Basis(q) * Basis(p)745END DO746END DO747748DO q=1,N749BoundaryVector(q) = BoundaryVector(q) + s * Basis(q) * Force750END DO751END DO752END SUBROUTINE DiffuseConvectiveBoundary753!------------------------------------------------------------------------------754755END MODULE DiffuseConvective756757!> \}758759760