Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/Solvers/Emergence.F90
3204 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 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
! *
26
! * Authors: Thomas Zwinger,
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: 1 April 2014
34
! *
35
! *
36
! ****************************************************************************/
37
38
39
!-----------------------------------------------------------------------------
40
!> Routine for deducing the emergence velocity
41
!> as a scalar product of velcoity with a given surface normal
42
!-----------------------------------------------------------------------------
43
SUBROUTINE GetEmergenceVelocity( Model,Solver,dt,TransientSimulation )
44
USE DefUtils
45
USE Differentials
46
USE MaterialModels
47
IMPLICIT NONE
48
49
!------------------------------------------------------------------------------
50
! external variables
51
!------------------------------------------------------------------------------
52
TYPE(Model_t) :: Model
53
TYPE(Solver_t):: Solver
54
REAL(KIND=dp) :: dt
55
LOGICAL :: TransientSimulation
56
!------------------------------------------------------------------------------
57
! Local variables
58
!------------------------------------------------------------------------------
59
60
LOGICAL :: firstTime=.TRUE., Found, AllocationsDone = .FALSE., stat
61
INTEGER :: i,j,k, t,N,NMAX, DIM, NSDOFs, istat
62
INTEGER, POINTER :: FlowPerm(:), NodeIndexes(:), NPerm(:), Permutation(:)
63
REAL(KIND=dp), POINTER :: FlowSolution(:), Nvector(:), EmergenceVelocity(:)
64
REAL(KIND=dp), ALLOCATABLE :: Velo(:,:)
65
REAL(KIND=dp) :: LocalNormalVector(3)
66
CHARACTER(LEN=MAX_NAME_LEN) :: SolverName, FlowSolName,ConvectionFlag
67
TYPE(Nodes_t) :: ElementNodes
68
TYPE(Element_t),POINTER :: CurrentElement
69
TYPE(Variable_t), POINTER :: FlowSol, NormalSolution, EmergenceSol
70
TYPE(ValueList_t), POINTER :: SolverParams, Material, Equation
71
TYPE(Matrix_t), POINTER :: Systemmatrix
72
!---------------------------------------
73
74
SAVE SolverName, firstTime, DIM, Velo, AllocationsDone
75
76
IF (firstTime) THEN
77
WRITE(SolverName, '(A)') 'GetEmergenceVelocity'
78
WRITE(Message, '(A)') "Starting " // TRIM(SolverName)
79
CALL INFO(SolverName, Message)
80
DIM = CoordinateSystemDimension()
81
firstTime = .FALSE.
82
END IF
83
84
IF ( (.NOT.AllocationsDone) .OR. (Solver % Mesh % Changed) ) THEN
85
IF (AllocationsDone) DEALLOCATE(Velo)
86
NMAX = Model % MaxElementNodes
87
ALLOCATE(Velo( 3, NMAX ), STAT=istat )
88
IF ( istat /= 0 ) THEN
89
CALL Fatal(SolverName,'Memory allocation error 1, Aborting.')
90
END IF
91
AllocationsDone = .TRUE.
92
END IF
93
94
EmergenceSol => Solver % Variable
95
IF (.NOT.ASSOCIATED(EmergenceSol)) &
96
CALL Fatal(SolverName, 'Solver variable not found')
97
Permutation => EmergenceSol % Perm
98
EmergenceVelocity => EmergenceSol % Values
99
100
! get normal vectors
101
NormalSolution => VariableGet( Solver % Mesh % Variables, 'Normal Vector' )
102
IF ( ASSOCIATED( NormalSolution ) ) THEN
103
Nvector => NormalSolution % Values
104
NPerm => NormalSolution % Perm
105
ELSE
106
CALL Fatal(SolverName, '>Normal Vector< not found')
107
END IF
108
109
DO t=1,Solver % NumberOfActiveElements
110
CurrentElement => GetActiveElement(t)
111
N = GetElementNOFNodes()
112
NodeIndexes => CurrentElement % NodeIndexes
113
Equation => GetEquation()
114
Material => GetMaterial()
115
116
! get flow soulution and velocity field from it
117
!----------------------------------------------
118
ConvectionFlag = GetString( Equation, 'Convection', Found )
119
IF (.NOT. Found) &
120
CALL Fatal(SolverName, 'No string for keyword > Convection < found in Equation')
121
Velo = 0.0_dp
122
! constant (i.e., in section Material given) velocity
123
!----------------------------------------------------
124
IF ( ConvectionFlag == 'constant' ) THEN
125
Velo(1,1:N) = GetReal( Material, 'Convection Velocity 1', Found )
126
IF ( .NOT.Found ) &
127
Velo(1,1:N) = GetReal( Equation, 'Convection Velocity 1', Found )
128
129
Velo(2,1:N) = GetReal( Material, 'Convection Velocity 2', Found )
130
IF ( .NOT.Found ) &
131
Velo(2,1:N) = GetReal( Equation, 'Convection Velocity 2', Found )
132
133
Velo(3,1:N) = GetReal( Material, 'Convection Velocity 3', Found )
134
IF ( .NOT.Found ) &
135
Velo(3,1:N) = GetReal( Equation, 'Convection Velocity 3', Found )
136
! computed velocity
137
!------------------
138
ELSE IF (ConvectionFlag == 'computed' ) THEN
139
FlowSolName = GetString( Equation,'Flow Solution Name', Found)
140
IF(.NOT.Found) THEN
141
CALL WARN(SolverName,'Keyword > Flow Solution Name < not found in section >Equation<')
142
CALL WARN(SolverName,'Taking default value > Flow Solution <')
143
END IF
144
FlowSol => VariableGet( Solver % Mesh % Variables, FlowSolName )
145
IF ( ASSOCIATED( FlowSol ) ) THEN
146
FlowPerm => FlowSol % Perm
147
NSDOFs = FlowSol % DOFs
148
FlowSolution => FlowSol % Values
149
ELSE
150
WRITE(Message,'(A,A,A)') &
151
'Convection flag set to > computed <, but no variable >',FlowSolName,'< found'
152
CALL FATAL(SolverName,Message)
153
END IF
154
! get velocity profile
155
IF ( ASSOCIATED( FlowSol ) ) THEN
156
DO i=1,n
157
j = NSDOFs*FlowPerm(NodeIndexes(i))
158
IF((DIM == 2) .AND. (NSDOFs == 3)) THEN
159
Velo(1,i) = FlowSolution( j-2 )
160
Velo(2,i) = FlowSolution( j-1 )
161
Velo(3,i) = 0.0_dp
162
ELSE IF ((DIM == 3) .AND. (NSDOFs == 4)) THEN
163
Velo(1,i) = FlowSolution( j-3 )
164
Velo(2,i) = FlowSolution( j-2 )
165
Velo(3,i) = FlowSolution( j-1 )
166
ELSE IF ((CurrentCoordinateSystem() == CylindricSymmetric) &
167
.AND. (DIM == 2) .AND. (NSDOFs == 4)) THEN
168
Velo(1,i) = FlowSolution( j-3 )
169
Velo(2,i) = FlowSolution( j-2 )
170
Velo(3,i) = FlowSolution( j-1 )
171
ELSE
172
WRITE(Message,'(a,i0,a,i0,a)')&
173
'DIM=', DIM, ' NSDOFs=', NSDOFs, ' does not combine. Aborting'
174
CALL FATAL( SolverName, Message)
175
END IF
176
END DO
177
ELSE ! "none"
178
Velo=0.0_dp
179
CALL WARN(SolverName,'No variable for velocity found - reset to zero.')
180
END IF
181
END IF
182
DO i=1,N
183
k = NPerm(NodeIndexes( i ))
184
LocalNormalVector(1:DIM) = Nvector(DIM*(k-1)+1:DIM*k)
185
EmergenceVelocity(Permutation(NodeIndexes( i ))) = SUM(LocalNormalVector(1:DIM) * Velo(1:DIM,i))
186
END DO
187
END DO
188
END SUBROUTINE GetEmergenceVelocity
189
190