Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/UserFunctions/USF_Haf.F90
3196 views
1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2
! USF_Haf.f90
3
! Calculates height above floatation at the lower boundary based on ice thickness, density,
4
! lower surface height and grounded mask (latter is optional).
5
!
6
! Call this function from the lower boundary condition (BC) in the sif like this:
7
! Haf = real coord 3
8
! Real Procedure "ElmerIceUSF" "Calculate_Haf"
9
! (where coord 3 is NOT a dummy argument - we actually use this as height of current node
10
! relative to sea level!)
11
!
12
! Relevant parameters can be given in the lower BC like this:
13
! Haf GroundedMask = String GroundedMask
14
! Haf Thickness = String Depth
15
! Haf rhoRatio = Variable Coordinate 3
16
! Real MATC "1.0 * rhoi/rhow"
17
!
18
! The second and third are required, the first is optional. The third, rhoRatio, assumes that
19
! rhow and rhoi are defined at the start of the sif, e.g.
20
! $yearinsec = 365.25*24*60*60
21
! $rhoi = 910.0/(1.0e6*yearinsec^2)
22
! $rhow = 1000.0/(1.0e6*yearinsec^2)
23
!
24
! Note that if depth is a variable giving the vertical distance of each node from the upper
25
! surface then it is equal to the ice thickness when taken at the lower surface.
26
!
27
!
28
! In order to calculate volume above floatation, this user function can be used in conjunction
29
! with the SaveScalars Solver like this:
30
!
31
! Solver x
32
! Equation = SaveScalars
33
! Procedure = "SaveData" "SaveScalars"
34
! Filename = f.dat
35
! Variable 1 = Haf
36
! Operator 1 = Int
37
! Variable 2 = dummy
38
! Operator 2 = Area
39
! Exported Variable 1 = Haf
40
! End
41
!
42
! The SaveScalars solver needs, in the lower surface boundary condition:
43
!
44
! Save Scalars = True
45
!
46
47
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48
49
FUNCTION Calculate_Haf ( Model, nodenumber, nodeHeight) RESULT(Haf)
50
51
USE types
52
USE DefUtils
53
54
IMPLICIT NONE
55
56
TYPE(Model_t) :: Model
57
REAL(KIND=dp) :: nodeHeight
58
INTEGER :: nodenumber
59
60
REAL(KIND=dp) :: Haf
61
62
REAL(KIND=dp) :: rhoRatio, Thickness
63
LOGICAL :: FirstTime=.TRUE., GotIt, UseGroundedMask, UnFoundFatal=.TRUE.
64
65
CHARACTER(LEN=MAX_NAME_LEN) :: FunctionName = "USF_Haf", thickName, GroundedMaskName
66
TYPE(Variable_t), POINTER :: GroundedMask, thick
67
TYPE(ValueList_t), POINTER :: BC
68
69
SAVE FirstTime, UseGroundedMask, UnFoundFatal, thickName, GroundedMaskName
70
71
IF (FirstTime) THEN
72
FirstTime = .False.
73
74
BC => GetBC(Model % CurrentElement)
75
IF (.NOT.ASSOCIATED(BC))THEN
76
CALL Fatal(FunctionName, 'No BC Found')
77
END IF
78
79
GroundedMaskName = GetString( BC, 'Haf GroundedMask', GotIt )
80
IF (Gotit) THEN
81
UseGroundedMask = .TRUE.
82
ELSE
83
UseGroundedMask = .FALSE.
84
END IF
85
86
thickName = GetString( BC, 'Haf Thickness', GotIt )
87
IF (.NOT.Gotit) THEN
88
CALL Fatal(FunctionName, 'Can not find >Haf Thickness< in BC')
89
END IF
90
91
rhoRatio = GetConstReal( BC, 'Haf rhoRatio', GotIt )
92
IF (.NOT.Gotit) THEN
93
CALL Fatal(FunctionName, 'Can not find >Haf rhoRatio< in BC')
94
END IF
95
96
END IF
97
98
GroundedMask => VariableGet(Model % Variables,GroundedMaskName,UnFoundFatal=UnFoundFatal)
99
thick => VariableGet(Model % Variables,thickName,UnFoundFatal=UnFoundFatal)
100
101
Haf = 0.0_dp
102
103
thickness = thick%values(thick%perm( nodenumber ))
104
! nodeHeight = Model%Nodes%z
105
106
! we assume sea level is at zero height. Hence:
107
! (-nodeHeight/rhoRatio) =
108
! (vertical distance from lower surface to sea level)*rho_ocean / rho_ice =
109
! is the thickness of ice up to floatation.
110
IF (nodeHeight.GT.0.0_dp) THEN
111
Haf = thickness
112
ELSE
113
Haf = thickness + nodeHeight/rhoRatio
114
END IF
115
116
! We assume mask value for ungrounded ice is -1
117
IF (UseGroundedMask) THEN
118
IF (GroundedMask%values(GroundedMask%perm( nodenumber )) .LT.-0.5 ) THEN
119
Haf = 0.0_dp
120
END IF
121
END IF
122
123
END FUNCTION Calculate_Haf
124
125