Path: blob/devel/elmerice/Solvers/DeformationalHeat.F90
3204 views
!/*****************************************************************************/1! *2! * Elmer/Ice, a glaciological add-on to Elmer3! * http://elmerice.elmerfem.org4! *5! *6! * This program is free software; you can redistribute it and/or7! * modify it under the terms of the GNU General Public License8! * as published by the Free Software Foundation; either version 29! * of the License, or (at your option) any later version.10! *11! * This program 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 the14! * GNU General Public License for more details.15! *16! * You should have received a copy of the GNU General Public License17! * along with this program (in file fem/GPL-2); if not, write to the18! * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19! * Boston, MA 02110-1301, USA.20! *21! *****************************************************************************/22! ******************************************************************************23! *24! * Authors:25! * Email:26! * Web: http://elmerice.elmerfem.org27! *28! * Original Date:29! *30! *****************************************************************************31!> DOXYGEN INFORMATION TO BE ADDED32SUBROUTINE DeformationalHeatSolver( Model,Solver,dt,TransientSimulation )33!------------------------------------------------------------------------------34!******************************************************************************35!36!37! ARGUMENTS:38!39! TYPE(Model_t) :: Model,40! INPUT: All model information (mesh, materials, BCs, etc...)41!42! TYPE(Solver_t) :: Solver43! INPUT: Linear & nonlinear equation solver options44!45! REAL(KIND=dp) :: dt,46! INPUT: Timestep size for time dependent simulations47!48! LOGICAL :: TransientSimulation49! INPUT: Steady state or transient simulation50!51!******************************************************************************52USE DefUtils5354IMPLICIT NONE55!------------------------------------------------------------------------------56TYPE(Solver_t) :: Solver57TYPE(Model_t) :: Model5859REAL(KIND=dp) :: dt60LOGICAL :: TransientSimulation61!------------------------------------------------------------------------------62! Local variables63!------------------------------------------------------------------------------64TYPE(Element_t),POINTER :: Element65TYPE(ValueList_t), POINTER :: SolverParams, Material66TYPE(Variable_t), POINTER :: PointerToVariable,FlowSol67TYPE(Solver_t), POINTER :: PointerToSolver6869LOGICAL :: AllocationsDone = .FALSE., Found,UnFoundFatal=.TRUE.7071INTEGER :: i, j,n, m, t, istat,k72INTEGER, POINTER :: Permutation(:), FlowPerm(:), NodeIndexes(:)7374REAL(KIND=dp), POINTER :: VariableValues(:), FlowSolution(:)75REAL(KIND=dp) :: Norm76Integer :: STDOFs,NSDOFs,dim7778REAL(KIND=dp), ALLOCATABLE :: STIFF(:,:), LOAD(:), FORCE(:), Velo(:,:), Viscosity(:)7980CHARACTER(LEN=MAX_NAME_LEN) :: FlowSolName,SolverName8182SAVE STIFF, LOAD, FORCE, Velo, AllocationsDone, Viscosity83!------------------------------------------------------------------------------84SolverName = 'Deformational Heat Solver'85PointerToVariable => Solver % Variable86Permutation => PointerToVariable % Perm87VariableValues => PointerToVariable % Values88STDOFs = PointerToVariable % DOFs8990dim = CoordinateSystemDimension()9192FlowSolName = GetString( Solver % Values, 'Flow Solver Name', Found )93IF (.NOT.Found) WRITE(FlowSolName,'(A)') 'Flow Solution'94FlowSol => VariableGet( Solver % Mesh % Variables, FlowSolName,UnFoundFatal=UnFoundFatal)95FlowPerm => FlowSol % Perm96NSDOFs = FlowSol % DOFs97FlowSolution => FlowSol % Values9899!Allocate some permanent storage, this is done first time only:100!--------------------------------------------------------------101IF ( (.NOT. AllocationsDone) .OR. Solver % MeshChanged ) THEN102N = Solver % Mesh % MaxElementNodes ! just big enough for elemental arrays103M = Model % Mesh % NumberOfNodes104IF (AllocationsDone) DEALLOCATE(FORCE, LOAD, STIFF, Viscosity, Velo)105106ALLOCATE( FORCE(2*STDOFs*N), LOAD(2*STDOFs*N), STIFF(2*STDOFs*N,2*STDOFs*N), Viscosity(N), Velo(3,N), &107STAT=istat )108IF ( istat /= 0 ) THEN109CALL Fatal( 'HessianSolve', 'Memory allocation error.' )110END IF111112113AllocationsDone = .TRUE.114END IF115116!Initialize the system and do the assembly:117!------------------------------------------118CALL DefaultInitialize()119120! bulk assembly121DO t=1,Solver % NumberOfActiveElements122Element => GetActiveElement(t)123n = GetElementNOFNodes()124NodeIndexes => Element % NodeIndexes125126Material => GetMaterial()127Viscosity(1:n) = GetReal( Material,'Viscosity', Found )128IF (.NOT.Found) CALL FATAL(SolverName,'Could not find >Viscosity<')129130131Velo = 0.0d0132Do i=1,n133j = NSDOFs*FlowPerm(NodeIndexes(i))134Do k=1,dim135Velo(k,i) = FlowSolution( j-dim+k-1 )136End do137End do138139CALL LocalMatrix( STIFF, FORCE, Element, n, Velo, Viscosity )140CALL DefaultUpdateEquations( STIFF, FORCE )141END DO142143144CALL DefaultFinishAssembly()145146Norm = DefaultSolve()147148CONTAINS149150!------------------------------------------------------------------------------151SUBROUTINE LocalMatrix( STIFF, FORCE, Element, n, Velo, Viscosity)152!------------------------------------------------------------------------------153USE MaterialModels154155REAL(KIND=dp) :: STIFF(:,:), FORCE(:), Velo(:,:), Viscosity(:)156INTEGER :: n,dim157TYPE(Element_t), POINTER :: Element158!------------------------------------------------------------------------------159REAL(KIND=dp) :: Basis(n),dBasisdx(n,3),ddBasisddx(n,3,3),DetJ,LGrad(3,3)160REAL(KIND=dp) :: mu,VeloIP(3)161LOGICAL :: Stat162INTEGER :: t, p,q , i163TYPE(GaussIntegrationPoints_t) :: IP164165TYPE(Nodes_t) :: Nodes166SAVE Nodes167!------------------------------------------------------------------------------168CALL GetElementNodes( Nodes )169STIFF = 0.0d0170FORCE = 0.0d0171LGrad = 0.0d0172173dim = CoordinateSystemDimension()174175IP = GaussPoints( Element )176DO t=1,IP % n177178stat = ElementInfo( Element, Nodes, IP % U(t), IP % V(t), &179IP % W(t), detJ, Basis, dBasisdx, ddBasisddx, .FALSE. )180181182183mu = SUM( Viscosity(1:n) * Basis(1:n) )184mu = EffectiveViscosity( mu, 1.0_dp , Velo(1,:) , Velo(2,:), Velo(3,:), &185Element, Nodes, n, n, IP % U(t), IP % V(t), IP % W(t), LocalIP=t )186187LGrad = MATMUL( Velo(:,1:n), dBasisdx(1:n,:) )188VeloIP=0.189VeloIP(1) = SUM( Velo(1,1:n)*Basis(1:n) )190VeloIP(2) = SUM( Velo(2,1:n)*Basis(1:n) )191IF ( dim > 2 ) VeloIP(3) = SUM(Velo(3,1:n)*Basis(1:n) )192193194DO p=1,n195DO q=1,n196STIFF(p,q) = STIFF(p,q) + IP % S(t) * detJ * Basis(p) * Basis(q)197End do198END DO199DO p=1,n200Force(p) = Force(p) + IP % S(t) * detJ * 0.5_dp * mu * SecondInvariant(VeloIP,LGrad) * Basis(p)201END DO202END DO203!------------------------------------------------------------------------------204END SUBROUTINE LocalMatrix205!------------------------------------------------------------------------------206!------------------------------------------------------------------------------207END SUBROUTINE DeformationalHeatSolver208!------------------------------------------------------------------------------209210211212