Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/Solvers/DeformationalHeat.F90
3204 views
1
!/*****************************************************************************/
2
! *
3
! * Elmer/Ice, a glaciological add-on to Elmer
4
! * http://elmerice.elmerfem.org
5
! *
6
! *
7
! * This program is free software; you can redistribute it and/or
8
! * modify it under the terms of the GNU General Public License
9
! * as published by the Free Software Foundation; either version 2
10
! * of the License, or (at your option) any later version.
11
! *
12
! * This program 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
15
! * GNU General Public License for more details.
16
! *
17
! * You should have received a copy of the GNU General Public License
18
! * along with this program (in file fem/GPL-2); if not, write to the
19
! * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
! * Boston, MA 02110-1301, USA.
21
! *
22
! *****************************************************************************/
23
! ******************************************************************************
24
! *
25
! * Authors:
26
! * Email:
27
! * Web: http://elmerice.elmerfem.org
28
! *
29
! * Original Date:
30
! *
31
! *****************************************************************************
32
!> DOXYGEN INFORMATION TO BE ADDED
33
SUBROUTINE DeformationalHeatSolver( Model,Solver,dt,TransientSimulation )
34
!------------------------------------------------------------------------------
35
!******************************************************************************
36
!
37
!
38
! ARGUMENTS:
39
!
40
! TYPE(Model_t) :: Model,
41
! INPUT: All model information (mesh, materials, BCs, etc...)
42
!
43
! TYPE(Solver_t) :: Solver
44
! INPUT: Linear & nonlinear equation solver options
45
!
46
! REAL(KIND=dp) :: dt,
47
! INPUT: Timestep size for time dependent simulations
48
!
49
! LOGICAL :: TransientSimulation
50
! INPUT: Steady state or transient simulation
51
!
52
!******************************************************************************
53
USE DefUtils
54
55
IMPLICIT NONE
56
!------------------------------------------------------------------------------
57
TYPE(Solver_t) :: Solver
58
TYPE(Model_t) :: Model
59
60
REAL(KIND=dp) :: dt
61
LOGICAL :: TransientSimulation
62
!------------------------------------------------------------------------------
63
! Local variables
64
!------------------------------------------------------------------------------
65
TYPE(Element_t),POINTER :: Element
66
TYPE(ValueList_t), POINTER :: SolverParams, Material
67
TYPE(Variable_t), POINTER :: PointerToVariable,FlowSol
68
TYPE(Solver_t), POINTER :: PointerToSolver
69
70
LOGICAL :: AllocationsDone = .FALSE., Found,UnFoundFatal=.TRUE.
71
72
INTEGER :: i, j,n, m, t, istat,k
73
INTEGER, POINTER :: Permutation(:), FlowPerm(:), NodeIndexes(:)
74
75
REAL(KIND=dp), POINTER :: VariableValues(:), FlowSolution(:)
76
REAL(KIND=dp) :: Norm
77
Integer :: STDOFs,NSDOFs,dim
78
79
REAL(KIND=dp), ALLOCATABLE :: STIFF(:,:), LOAD(:), FORCE(:), Velo(:,:), Viscosity(:)
80
81
CHARACTER(LEN=MAX_NAME_LEN) :: FlowSolName,SolverName
82
83
SAVE STIFF, LOAD, FORCE, Velo, AllocationsDone, Viscosity
84
!------------------------------------------------------------------------------
85
SolverName = 'Deformational Heat Solver'
86
PointerToVariable => Solver % Variable
87
Permutation => PointerToVariable % Perm
88
VariableValues => PointerToVariable % Values
89
STDOFs = PointerToVariable % DOFs
90
91
dim = CoordinateSystemDimension()
92
93
FlowSolName = GetString( Solver % Values, 'Flow Solver Name', Found )
94
IF (.NOT.Found) WRITE(FlowSolName,'(A)') 'Flow Solution'
95
FlowSol => VariableGet( Solver % Mesh % Variables, FlowSolName,UnFoundFatal=UnFoundFatal)
96
FlowPerm => FlowSol % Perm
97
NSDOFs = FlowSol % DOFs
98
FlowSolution => FlowSol % Values
99
100
!Allocate some permanent storage, this is done first time only:
101
!--------------------------------------------------------------
102
IF ( (.NOT. AllocationsDone) .OR. Solver % MeshChanged ) THEN
103
N = Solver % Mesh % MaxElementNodes ! just big enough for elemental arrays
104
M = Model % Mesh % NumberOfNodes
105
IF (AllocationsDone) DEALLOCATE(FORCE, LOAD, STIFF, Viscosity, Velo)
106
107
ALLOCATE( FORCE(2*STDOFs*N), LOAD(2*STDOFs*N), STIFF(2*STDOFs*N,2*STDOFs*N), Viscosity(N), Velo(3,N), &
108
STAT=istat )
109
IF ( istat /= 0 ) THEN
110
CALL Fatal( 'HessianSolve', 'Memory allocation error.' )
111
END IF
112
113
114
AllocationsDone = .TRUE.
115
END IF
116
117
!Initialize the system and do the assembly:
118
!------------------------------------------
119
CALL DefaultInitialize()
120
121
! bulk assembly
122
DO t=1,Solver % NumberOfActiveElements
123
Element => GetActiveElement(t)
124
n = GetElementNOFNodes()
125
NodeIndexes => Element % NodeIndexes
126
127
Material => GetMaterial()
128
Viscosity(1:n) = GetReal( Material,'Viscosity', Found )
129
IF (.NOT.Found) CALL FATAL(SolverName,'Could not find >Viscosity<')
130
131
132
Velo = 0.0d0
133
Do i=1,n
134
j = NSDOFs*FlowPerm(NodeIndexes(i))
135
Do k=1,dim
136
Velo(k,i) = FlowSolution( j-dim+k-1 )
137
End do
138
End do
139
140
CALL LocalMatrix( STIFF, FORCE, Element, n, Velo, Viscosity )
141
CALL DefaultUpdateEquations( STIFF, FORCE )
142
END DO
143
144
145
CALL DefaultFinishAssembly()
146
147
Norm = DefaultSolve()
148
149
CONTAINS
150
151
!------------------------------------------------------------------------------
152
SUBROUTINE LocalMatrix( STIFF, FORCE, Element, n, Velo, Viscosity)
153
!------------------------------------------------------------------------------
154
USE MaterialModels
155
156
REAL(KIND=dp) :: STIFF(:,:), FORCE(:), Velo(:,:), Viscosity(:)
157
INTEGER :: n,dim
158
TYPE(Element_t), POINTER :: Element
159
!------------------------------------------------------------------------------
160
REAL(KIND=dp) :: Basis(n),dBasisdx(n,3),ddBasisddx(n,3,3),DetJ,LGrad(3,3)
161
REAL(KIND=dp) :: mu,VeloIP(3)
162
LOGICAL :: Stat
163
INTEGER :: t, p,q , i
164
TYPE(GaussIntegrationPoints_t) :: IP
165
166
TYPE(Nodes_t) :: Nodes
167
SAVE Nodes
168
!------------------------------------------------------------------------------
169
CALL GetElementNodes( Nodes )
170
STIFF = 0.0d0
171
FORCE = 0.0d0
172
LGrad = 0.0d0
173
174
dim = CoordinateSystemDimension()
175
176
IP = GaussPoints( Element )
177
DO t=1,IP % n
178
179
stat = ElementInfo( Element, Nodes, IP % U(t), IP % V(t), &
180
IP % W(t), detJ, Basis, dBasisdx, ddBasisddx, .FALSE. )
181
182
183
184
mu = SUM( Viscosity(1:n) * Basis(1:n) )
185
mu = EffectiveViscosity( mu, 1.0_dp , Velo(1,:) , Velo(2,:), Velo(3,:), &
186
Element, Nodes, n, n, IP % U(t), IP % V(t), IP % W(t), LocalIP=t )
187
188
LGrad = MATMUL( Velo(:,1:n), dBasisdx(1:n,:) )
189
VeloIP=0.
190
VeloIP(1) = SUM( Velo(1,1:n)*Basis(1:n) )
191
VeloIP(2) = SUM( Velo(2,1:n)*Basis(1:n) )
192
IF ( dim > 2 ) VeloIP(3) = SUM(Velo(3,1:n)*Basis(1:n) )
193
194
195
DO p=1,n
196
DO q=1,n
197
STIFF(p,q) = STIFF(p,q) + IP % S(t) * detJ * Basis(p) * Basis(q)
198
End do
199
END DO
200
DO p=1,n
201
Force(p) = Force(p) + IP % S(t) * detJ * 0.5_dp * mu * SecondInvariant(VeloIP,LGrad) * Basis(p)
202
END DO
203
END DO
204
!------------------------------------------------------------------------------
205
END SUBROUTINE LocalMatrix
206
!------------------------------------------------------------------------------
207
!------------------------------------------------------------------------------
208
END SUBROUTINE DeformationalHeatSolver
209
!------------------------------------------------------------------------------
210
211
212