Path: blob/devel/fem/src/DiffuseConvectiveGeneralAnisotropic.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! ******************************************************************************/353637!---------------------------------------------------------------------------------38!> Diffuse-convective local matrix computing in general euclidean coordinates.39!---------------------------------------------------------------------------------40!> \ingroup ElmerLib41!> \{4243MODULE DiffuseConvectiveGeneral4445USE Integration46USE MaterialModels47USE Differentials4849IMPLICIT NONE5051CONTAINS5253!------------------------------------------------------------------------------54!> Return element local matrices and RSH vector for diffusion-convection55!> equation (genaral euclidean coordinate system):56!------------------------------------------------------------------------------57SUBROUTINE DiffuseConvectiveGenCompose( MassMatrix,StiffMatrix,ForceVector, &58LoadVector,NodalCT,NodalC0,NodalC1,NodalC2,PhaseChange,Temperature,Enthalpy,&59Ux,Uy,Uz,MUx,MUy, MUz, NodalViscosity,NodalDensity,NodalPressure, &60NodaldPressureDt,NodalPressureCoeff,Compressible, Stabilize,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, and the77! 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) :: Temperature86! INPUT: Temperature from previous iteration, needed if we model87! phase change88!89! REAL(KIND=dp) :: Enthalpy90! INPUT: Enthalpy from previous iteration, needed if we model91! phase change92!93! REAL(KIND=dp) :: Ux(:),Uy(:),Uz(:)94! INPUT: Nodal values of velocity components from previous iteration95! used only if coefficient of the convection term (C1) is nonzero96!97! REAL(KIND=dp) :: NodalViscosity(:)98! INPUT: Nodal values of the viscosity99!100! LOGICAL :: Stabilize101! INPUT: Should stabilzation be used ? Used only if coefficient of the102! convection term (C1) is nonzero103!104! TYPE(Element_t) :: Element105! INPUT: Structure describing the element (dimension,nof nodes,106! interpolation degree, etc...)107!108! TYPE(Nodes_t) :: Nodes109! INPUT: Element node coordinates110!111!------------------------------------------------------------------------------112113REAL(KIND=dp), DIMENSION(:) :: ForceVector,Ux,Uy,Uz,MUx,MUy,MUz,LoadVector114REAL(KIND=dp), DIMENSION(:,:) :: MassMatrix,StiffMatrix115REAL(KIND=dp) :: NodalC0(:),NodalC1(:),NodalCT(:),NodalC2(:,:,:)116REAL(KIND=dp) :: Temperature(:),Enthalpy(:),NodalViscosity(:), &117NodaldPressuredt(:),NodalPressureCoeff(:),NodalPressure(:),dT, NodalDensity(:)118119LOGICAL :: Stabilize,PhaseChange,Compressible120121INTEGER :: n122123TYPE(Nodes_t) :: Nodes124TYPE(Element_t), POINTER :: Element125126127!------------------------------------------------------------------------------128! Local variables129!------------------------------------------------------------------------------130!131REAL(KIND=dp) :: ddBasisddx(n,3,3),dNodalBasisdx(n,n,3)132REAL(KIND=dp) :: Basis(2*n)133REAL(KIND=dp) :: dBasisdx(2*n,3),detJ134135REAL(KIND=dp) :: Velo(3),Force136137REAL(KIND=dp) :: A,M138REAL(KIND=dp) :: Load139140REAL(KIND=dp) :: VNorm,hK,mK141REAL(KIND=dp) :: Lambda=1.0,Pe,Pe1,Pe2,C00,Tau,Delta,x,y,z142143INTEGER :: i,j,k,c,p,q,t,dim,N_Integ,NBasis144145REAL(KIND=dp) :: s,u,v,w,dEnth,dTemp,Viscosity,Pressure,pCoeff,DivVelo,dVelodx(3,3)146147REAL(KIND=dp) :: SqrtMetric,Metric(3,3),Symb(3,3,3),dSymb(3,3,3,3)148149REAL(KIND=dp), DIMENSION(:), POINTER :: U_Integ,V_Integ,W_Integ,S_Integ150151REAL(KIND=dp) :: C0,CT,CL,C1,C2(3,3),dC2dx(3,3,3),SU(n),SW(n),Density152153TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff154155LOGICAL :: stat,CylindricSymmetry,Convection,ConvectAndStabilize,Bubbles, &156FrictionHeat, Found157TYPE(ValueList_t), POINTER :: BodyForce, Material158159LOGICAL :: GotCondModel160161!------------------------------------------------------------------------------162163CylindricSymmetry = (CurrentCoordinateSystem() == CylindricSymmetric .OR. &164CurrentCoordinateSystem() == AxisSymmetric)165166167IF ( CylindricSymmetry ) THEN168dim = 3169ELSE170dim = CoordinateSystemDimension()171END IF172n = element % Type % NumberOfNodes173174ForceVector = 0.0D0175StiffMatrix = 0.0D0176MassMatrix = 0.0D0177Load = 0.0D0178179Convection = ANY( NodalC1 /= 0.0d0 )180NBasis = n181Bubbles = .FALSE.182IF ( Convection .AND. .NOT. Stabilize ) THEN183NBasis = 2*n184Bubbles = .TRUE.185END IF186187Material => GetMaterial()188GotCondModel = ListCheckPresent( Material,'Heat Conductivity Model')189190!------------------------------------------------------------------------------191! Integration stuff192!------------------------------------------------------------------------------193IF ( Bubbles ) THEN194IntegStuff = GaussPoints( element, Element % Type % GaussPoints2 )195ELSE196IntegStuff = GaussPoints( element )197END IF198U_Integ => IntegStuff % u199V_Integ => IntegStuff % v200W_Integ => IntegStuff % w201S_Integ => IntegStuff % s202N_Integ = IntegStuff % n203204!------------------------------------------------------------------------------205! Stabilization parameters: hK, mK (take a look at Franca et.al.)206! If there is no convection term we don't need stabilization.207!------------------------------------------------------------------------------208ConvectAndStabilize = .FALSE.209IF ( Stabilize .AND. ANY(NodalC1 /= 0.0D0) ) THEN210ConvectAndStabilize = .TRUE.211hK = element % hK212mK = element % StabilizationMK213dNodalBasisdx = 0._dp214DO p=1,n215u = Element % Type % NodeU(p)216v = Element % Type % NodeV(p)217w = Element % Type % NodeW(p)218stat = ElementInfo( Element, Nodes, u,v,w, detJ, Basis, dBasisdx )219dNodalBasisdx(1:n,p,:) = dBasisdx(1:n,:)220END DO221END IF222223!------------------------------------------------------------------------------224BodyForce => GetBodyForce()225FrictionHeat = .FALSE.226IF (ASSOCIATED(BodyForce)) &227FrictionHeat = GetLogical( BodyForce, 'Friction Heat', Found )228!------------------------------------------------------------------------------229! Now we start integrating230!------------------------------------------------------------------------------231DO t=1,N_Integ232233u = U_Integ(t)234v = V_Integ(t)235w = W_Integ(t)236!------------------------------------------------------------------------------237! Basis function values & derivatives at the integration point238!------------------------------------------------------------------------------239stat = ElementInfo( Element,Nodes,u,v,w,detJ, &240Basis,dBasisdx, Bubbles=Bubbles )241242!------------------------------------------------------------------------------243! Coordinatesystem dependent info244!------------------------------------------------------------------------------245IF ( CurrentCoordinateSystem()/= Cartesian ) THEN246x = SUM( nodes % x(1:n)*Basis(1:n) )247y = SUM( nodes % y(1:n)*Basis(1:n) )248z = SUM( nodes % z(1:n)*Basis(1:n) )249END IF250251CALL CoordinateSystemInfo( Metric,SqrtMetric,Symb,dSymb,x,y,z )252253s = SqrtMetric * detJ * S_Integ(t)254!------------------------------------------------------------------------------255! Coefficient of the convection and time derivative terms at the256! integration point257!------------------------------------------------------------------------------258C0 = SUM( NodalC0(1:n)*Basis(1:n) )259CT = SUM( NodalCT(1:n)*Basis(1:n) )260C1 = SUM( NodalC1(1:n)*Basis(1:n) )261!------------------------------------------------------------------------------262! Compute effective heatcapacity, if modelling phase change,263! at the integration point.264! NOTE: This is for heat equation only, not generally for diff.conv. equ.265!------------------------------------------------------------------------------266IF ( PhaseChange ) THEN267dEnth = 0.0D0268dTemp = 0.0D0269DO i=1,3270dEnth = dEnth + SUM( Enthalpy(1:n) * dBasisdx(1:n,i) )**2271dTemp = dTemp + SUM( Temperature(1:n) * dBasisdx(1:n,i) )**2272END DO273274CL = SQRT( dEnth / dTemp )275276CT = CT + CL277END IF278!------------------------------------------------------------------------------279! Coefficient of the diffusion term & its derivatives at the280! integration point281!------------------------------------------------------------------------------282Density = SUM( NodalDensity(1:n) * Basis(1:n) )283DO i=1,dim284DO j=1,dim285C2(i,j) = SQRT(Metric(i,i)) * SQRT(Metric(j,j)) * &286SUM( NodalC2(i,j,1:n) * Basis(1:n) )287END DO288END DO289290IF( GotCondModel ) THEN291DO i=1,dim292C2(i,i) = EffectiveConductivity( C2(i,i), Density, Element, &293Temperature, UX,UY,UZ, Nodes, n, n, u, v, w )294END DO295END IF296!------------------------------------------------------------------------------297! If there's no convection term we don't need the velocities, and298! also no need for stabilization299!------------------------------------------------------------------------------300Convection = .FALSE.301IF ( C1 /= 0.0D0 ) THEN302Convection = .TRUE.303IF ( PhaseChange ) C1 = C1 + CL304!------------------------------------------------------------------------------305! Velocity and pressure (deviation) from previous iteration306! at the integration point307!------------------------------------------------------------------------------308Velo = 0.0D0309Velo(1) = SUM( (Ux(1:n)-MUx(1:n))*Basis(1:n) )310Velo(2) = SUM( (Uy(1:n)-MUy(1:n))*Basis(1:n) )311IF ( dim > 2 .AND. CurrentCoordinateSystem()/= AxisSymmetric ) THEN312Velo(3) = SUM( (Uz(1:n)-MUz(1:n))*Basis(1:n) )313END IF314315IF ( Compressible ) THEN316Pressure = SUM( NodalPressure(1:n)*Basis(1:n) )317318dVelodx = 0.0D0319DO i=1,3320dVelodx(1,i) = SUM( Ux(1:n)*dBasisdx(1:n,i) )321dVelodx(2,i) = SUM( Uy(1:n)*dBasisdx(1:n,i) )322IF ( dim > 2 .AND. CurrentCoordinateSystem()/= AxisSymmetric ) &323dVelodx(3,i) = SUM( Uz(1:n)*dBasisdx(1:n,i) )324END DO325326DivVelo = 0.0D0327DO i=1,dim328DivVelo = DivVelo + dVelodx(i,i)329END DO330IF ( CurrentCoordinateSystem()>= Cylindric .AND. &331CurrentCoordinateSystem()<= AxisSymmetric ) THEN332! Cylindrical coordinates333DivVelo = DivVelo + Velo(1)/x334ELSE335! General coordinate system336DO i=1,dim337DO j=i,dim338DivVelo = DivVelo + Velo(j)*Symb(i,j,i)339END DO340END DO341END IF342END IF343344!------------------------------------------------------------------------------345! Stabilization parameters...346!------------------------------------------------------------------------------347IF ( Stabilize ) THEN348! VNorm = SQRT( SUM(Velo(1:dim)**2) )349350Vnorm = 0.0D0351DO i=1,dim352Vnorm = Vnorm + Velo(i)*Velo(i) / Metric(i,i)353END DO354Vnorm = SQRT( Vnorm )355356#if 1357Pe = MIN(1.0D0,mK*hK*C1*VNorm/(2*ABS(C2(1,1))))358359Tau = 0.0D0360IF ( VNorm /= 0.0D0 ) THEN361Tau = hK * Pe / (2 * C1 * VNorm)362END IF363#else364C00 = C0365IF ( dT > 0 ) C00 = C0 + CT366367Pe1 = 0.0d0368IF ( C00 > 0 ) THEN369Pe1 = 2 * ABS(C2(1,1)) / ( mK * C00 * hK**2 )370Pe1 = C00 * hK**2 * MAX( 1.0d0, Pe1 )371ELSE372Pe1 = 2 * ABS(C2(1,1)) / mK373END IF374375Pe2 = 0.0d0376IF ( C2(1,1) /= 0.0d0 ) THEN377Pe2 = ( mK * C1 * VNorm * hK ) / ABS(C2(1,1))378Pe2 = 2*ABS(C2(1,1)) * MAX( 1.0d0, Pe2 ) / mK379ELSE380Pe2 = 2 * hK * C1 * VNorm381END IF382383Tau = hk**2 / ( Pe1 + Pe2 )384#endif385386!------------------------------------------------------------------------------387DO i=1,dim388DO j=1,dim389DO k=1,3390dC2dx(i,j,k) = SQRT(Metric(i,i))*SQRT(Metric(j,j))* &391SUM(NodalC2(i,j,1:n)*dBasisdx(1:n,k))392END DO393END DO394END DO395!------------------------------------------------------------------------------396! Compute residual & stabilization weight vectors397!------------------------------------------------------------------------------398DO p=1,n399SU(p) = C0 * Basis(p)400DO i = 1,dim401SU(p) = SU(p) + C1 * dBasisdx(p,i) * Velo(i)402IF ( Element % Type % BasisFunctionDegree <= 1 ) CYCLE403404DO j=1,dim405SU(p) = SU(p) - dC2dx(i,j,j) * dBasisdx(p,i)406SU(p) = SU(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))407DO k=1,dim408SU(p) = SU(p) + C2(i,j) * Symb(i,j,k) * dBasisdx(p,k)409SU(p) = SU(p) - C2(i,k) * Symb(k,j,j) * dBasisdx(p,i)410SU(p) = SU(p) - C2(k,j) * Symb(k,j,i) * dBasisdx(p,i)411END DO412END DO413END DO414415SW(p) = C0 * Basis(p)416417DO i = 1,dim418SW(p) = SW(p) + C1 * dBasisdx(p,i) * Velo(i)419IF ( Element % Type % BasisFunctionDegree <= 1 ) CYCLE420421DO j=1,dim422SW(p) = SW(p) - dC2dx(i,j,j) * dBasisdx(p,i)423SW(p) = SW(p) - C2(i,j) * SUM(dNodalBasisdx(p,1:n,i)*dBasisdx(1:n,j))424DO k=1,dim425SW(p) = SW(p) + C2(i,j) * Symb(i,j,k) * dBasisdx(p,k)426SW(p) = SW(p) - C2(i,k) * Symb(k,j,j) * dBasisdx(p,i)427SW(p) = SW(p) - C2(k,j) * Symb(k,j,i) * dBasisdx(p,i)428END DO429END DO430END DO431END DO432END IF433END IF434!------------------------------------------------------------------------------435! Loop over basis functions of both unknowns and weights436!------------------------------------------------------------------------------437DO p=1,NBasis438DO q=1,NBasis439!------------------------------------------------------------------------------440! The diffusive-convective equation without stabilization441!------------------------------------------------------------------------------442M = CT * Basis(q) * Basis(p)443A = C0 * Basis(q) * Basis(p)444DO i=1,dim445DO j=1,dim446A = A + C2(i,j) * dBasisdx(q,i) * dBasisdx(p,j)447END DO448END DO449450IF ( Convection ) THEN451DO i=1,dim452A = A + C1 * Velo(i) * dBasisdx(q,i) * Basis(p)453END DO454455!------------------------------------------------------------------------------456! Next we add the stabilization...457!------------------------------------------------------------------------------458IF ( Stabilize ) THEN459A = A + Tau * SU(q) * SW(p)460M = M + Tau * CT * Basis(q) * SW(p)461END IF462END IF463464StiffMatrix(p,q) = StiffMatrix(p,q) + s * A465MassMatrix(p,q) = MassMatrix(p,q) + s * M466END DO467END DO468469!------------------------------------------------------------------------------470! Force at the integration point471!------------------------------------------------------------------------------472Force = SUM( LoadVector(1:n)*Basis(1:n) ) + &473JouleHeat( Element,Nodes,u,v,w,n )474IF ( Convection ) THEN475! IF ( Compressible ) Force = Force - Pressure * DivVelo476Pcoeff = SUM( NodalPressureCoeff(1:n) * Basis(1:n) )477IF ( Pcoeff /= 0.0_dp ) THEN478Force = Force + Pcoeff*SUM( NodalDPressureDt(1:n) * Basis(1:n) )479DO i=1,dim480Force = Force + Pcoeff*Velo(i)*SUM( NodalPressure(1:n)*dBasisdx(1:n,i) )481END DO482END IF483484IF ( FrictionHeat ) THEN485Viscosity = SUM( NodalViscosity(1:n) * Basis(1:n) )486Viscosity = EffectiveViscosity( Viscosity, Density, Ux, Uy, Uz, &487Element, Nodes, n, n, u, v, w, LocalIP=t )488IF ( Viscosity > 0.0d0 ) THEN489IF ( .NOT.Compressible ) THEN490dVelodx = 0.0D0491DO i=1,3492dVelodx(1,i) = SUM( Ux(1:n)*dBasisdx(1:n,i) )493dVelodx(2,i) = SUM( Uy(1:n)*dBasisdx(1:n,i) )494IF ( dim > 2 .AND. CurrentCoordinateSystem()/= AxisSymmetric ) &495dVelodx(3,i) = SUM( Uz(1:n)*dBasisdx(1:n,i) )496END DO497END IF498Force = Force + 0.5d0 * Viscosity * &499SecondInvariant( Velo,dVelodx,Metric,Symb )500END IF501END IF502END IF503!------------------------------------------------------------------------------504! The righthand side...505!------------------------------------------------------------------------------506DO p=1,NBasis507Load = Basis(p)508509IF ( ConvectAndStabilize ) THEN510Load = Load + Tau * SW(p)511END IF512513ForceVector(p) = ForceVector(p) + s * Load * Force514END DO515516END DO517!------------------------------------------------------------------------------518END SUBROUTINE DiffuseConvectiveGenCompose519!------------------------------------------------------------------------------520521522!------------------------------------------------------------------------------523!> Return element local matrices and RHS vector for boundary conditions524!> of diffusion convection equation.525!------------------------------------------------------------------------------526SUBROUTINE DiffuseConvectiveGenBoundary( BoundaryMatrix,BoundaryVector, &527LoadVector,NodalAlpha,Element,n,Nodes)528!------------------------------------------------------------------------------529!530! REAL(KIND=dp) :: BoundaryMatrix(:,:)531! OUTPUT: coefficient matrix if equations532!533! REAL(KIND=dp) :: BoundaryVector(:)534! OUTPUT: RHS vector535!536! REAL(KIND=dp) :: LoadVector(:)537! INPUT: coefficient of the force term538!539! REAL(KIND=dp) :: NodalAlpha540! INPUT: coefficient for temperature dependent term541!542! TYPE(Element_t) :: Element543! INPUT: Structure describing the element (dimension,nof nodes,544! interpolation degree, etc...)545!546! INTEGER :: n547! INPUT: Number of element nodes548!549! TYPE(Nodes_t) :: Nodes550! INPUT: Element node coordinates551!552!------------------------------------------------------------------------------553554REAL(KIND=dp) :: BoundaryMatrix(:,:),BoundaryVector(:)555REAL(KIND=dp) :: LoadVector(:),NodalAlpha(:)556TYPE(Nodes_t) :: Nodes557TYPE(Element_t),POINTER :: Element558559INTEGER :: n560!------------------------------------------------------------------------------561562REAL(KIND=dp) :: ddBasisddx(n,3,3)563REAL(KIND=dp) :: Basis(n)564REAL(KIND=dp) :: dBasisdx(n,3),detJ565566REAL(KIND=dp) :: u,v,w,s,x,y,z567REAL(KIND=dp) :: Force,Alpha568REAL(KIND=dp), POINTER :: U_Integ(:),V_Integ(:),W_Integ(:),S_Integ(:)569570REAL(KIND=dp) :: SqrtMetric,Metric(3,3),Symb(3,3,3),dSymb(3,3,3,3),normal(3)571572INTEGER :: i,t,q,p,N_Integ573574LOGICAL :: stat,CylindricSymmetry575576TYPE(GaussIntegrationPoints_t), TARGET :: IntegStuff577!------------------------------------------------------------------------------578579BoundaryVector = 0.0D0580BoundaryMatrix = 0.0D0581582!------------------------------------------------------------------------------583! Integration stuff584!------------------------------------------------------------------------------585IntegStuff = GaussPoints( element )586U_Integ => IntegStuff % u587V_Integ => IntegStuff % v588W_Integ => IntegStuff % w589S_Integ => IntegStuff % s590N_Integ = IntegStuff % n591592!------------------------------------------------------------------------------593! Now we start integrating594!------------------------------------------------------------------------------595DO t=1,N_Integ596u = U_Integ(t)597v = V_Integ(t)598w = W_Integ(t)599600!------------------------------------------------------------------------------601! Basis function values & derivatives at the integration point602!------------------------------------------------------------------------------603stat = ElementInfo( Element,Nodes,u,v,w,detJ, &604Basis,dBasisdx )605606s = S_Integ(t) * detJ607!------------------------------------------------------------------------------608! Coordinatesystem dependent info609!------------------------------------------------------------------------------610IF ( CurrentCoordinateSystem()/= Cartesian ) THEN611x = SUM( Nodes % x(1:n)*Basis )612y = SUM( Nodes % y(1:n)*Basis )613z = SUM( Nodes % z(1:n)*Basis )614s = s * CoordinateSqrtMetric( x,y,z )615END IF616!------------------------------------------------------------------------------617! Basis function values at the integration point618!------------------------------------------------------------------------------619Alpha = SUM( NodalAlpha(1:n)*Basis )620Force = SUM( LoadVector(1:n)*Basis )621622DO p=1,N623DO q=1,N624BoundaryMatrix(p,q) = BoundaryMatrix(p,q) + &625s * Alpha * Basis(q) * Basis(p)626END DO627END DO628629DO q=1,N630BoundaryVector(q) = BoundaryVector(q) + s * Basis(q) * Force631END DO632END DO633END SUBROUTINE DiffuseConvectiveGenBoundary634!------------------------------------------------------------------------------635636END MODULE DiffuseConvectiveGeneral637638!> \}639640641