Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/Meshers/MshGlacier.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: Olivier Gagliardini
26
! * Email:
27
! * Web: http://elmerice.elmerfem.org
28
! *
29
! * Original Date:
30
! *
31
! *****************************************************************************
32
!> Create a 2D mesh given by its bed and surface topography
33
!> By deforming a square 1x1 mesh
34
!>
35
!> Input :
36
!> NameMesh of the grd mesh (a square 1 x 1)
37
!> x_start end x_end
38
!> yi=surf(xi) and yi=bed(xi) are in NameMesh_surf.dat and NameMesh_bed.dat
39
!>
40
!> Output :
41
!> NameMesh/mesh.nodes
42
PROGRAM MshGlacier
43
USE GeneralUtils
44
USE types
45
USE DefUtils
46
!
47
IMPLICIT NONE
48
!
49
REAL(KIND=dp) :: x0, x1, x, y, z, hmin, xnew, ynew, zb, zs
50
REAL(KIND=dp) :: Xconstraint, XCubic
51
REAL(KIND=dp), ALLOCATABLE :: xbed(:), ybed(:), xsurf(:), ysurf(:)
52
REAL(KIND=dp), TARGET, ALLOCATABLE :: y2s(:), y2b(:)
53
REAL(KIND=dp), DIMENSION(:), POINTER :: y2s_p, y2b_p
54
REAL(KIND=dp), ALLOCATABLE :: xnode(:), ynode(:)
55
LOGICAL :: Constraint=.FALSE., Cubic=.FALSE.
56
CHARACTER :: NameMsh*20, NameSurf*20, NameBed*20, Rien*1
57
INTEGER :: NtN, i, j, NptS, NptB, n, NtNx, xi
58
!
59
!
60
!
61
!
62
! Read data input from mesh_input.dat
63
!
64
!
65
OPEN(10,file="mesh_input.dat")
66
READ(10,*)Rien
67
READ(10,*)NameMsh
68
READ(10,*)Rien
69
READ(10,*)XConstraint
70
! Xconstraint = 0 -> xnode given by the mesh
71
! Xconstraint = 1 -> xnode given by the dataset
72
IF (XConstraint > 0.5) Constraint = .TRUE.
73
! xCubic = 0 -> Linear interpolation
74
! xCubic = 1 -> Cubic Spline
75
READ(10,*)Rien
76
READ(10,*)xCubic
77
IF (XCubic > 0.5) Cubic = .TRUE.
78
READ(10,*)Rien
79
READ(10,*)NameSurf
80
READ(10,*)Rien
81
READ(10,*)NptS
82
READ(10,*)Rien
83
READ(10,*)NameBed
84
READ(10,*)Rien
85
READ(10,*)NptB
86
READ(10,*)Rien
87
READ(10,*)hmin
88
IF (.Not.Constraint) THEN
89
READ(10,*)Rien
90
READ(10,*)x0
91
READ(10,*)Rien
92
READ(10,*)x1
93
END IF
94
CLOSE(10)
95
96
ALLOCATE(xsurf(NptS), ysurf(NptS), y2s(NptS))
97
ALLOCATE(xbed(NptB), ybed(NptB), y2b(NptB))
98
99
OPEN(10,file=TRIM(NameMsh)//"/mesh.header")
100
READ(10,1000)NtN
101
CLOSE(10)
102
ALLOCATE(xnode(NtN), ynode(NtN))
103
104
OPEN(10,file=TRIM(NameSurf))
105
READ(10,*)(xsurf(i), ysurf(i), i=1,NptS)
106
CLOSE(10)
107
108
OPEN(10,file=TRIM(NameBed))
109
READ(10,*)(xbed(i), ybed(i), i=1,NptB)
110
CLOSE(10)
111
112
IF (.Not.Constraint) THEN
113
IF (((MINVAL(xbed)>x0) .OR. (MAXVAL(xbed)<x1)) ) THEN
114
WRITE(*,*)'MUST BE : x0> MIN(xbed) AND x1 < MAX(xbed)',&
115
&x0,MINVAL(xbed),x1,MAXVAL(xbed)
116
STOP
117
END IF
118
IF (((MINVAL(xsurf)>x0) .OR. (MAXVAL(xsurf)<x1)) ) THEN
119
WRITE(*,*)'MUST BE : x0 > MIN(xsurf) AND x1 < MAX(xsurf)'
120
STOP
121
END IF
122
END IF
123
124
IF (Cubic) THEN
125
CALL CubicSpline(NptS,xsurf,ysurf,y2s)
126
CALL CubicSpline(Nptb,xbed,ybed,y2b)
127
END IF
128
129
OPEN(12,file=TRIM(NameMsh)//"/mesh.nodes")
130
READ(12,*)(N, j, xnode(i), ynode(i), z, i=1,NtN)
131
REWIND(12)
132
133
134
IF (Constraint) THEN
135
WRITE(*,*)'Will have to check if number of nodes in x direction &
136
&equals number of data points'
137
! First test
138
IF (NptS/=NptB) THEN
139
WRITE(*,*)'Surface and Bed data must have the same number of &
140
&points'
141
STOP
142
END IF
143
NtNx = 0
144
DO n=1,NtN
145
IF (ABS(ynode(n))<1.0e-4) NtNx = NtNx + 1
146
END DO
147
IF (NptS/=NtNx) THEN
148
WRITE(*,*)'Mesh must have',NptS,' nodes in x direction'
149
STOP
150
END IF
151
x0 = MINVAL(xbed)
152
x1 = MAXVAL(xbed)
153
END IF
154
155
DO n=1, NtN
156
157
x = xnode(n)
158
y = ynode(n)
159
160
161
IF (Constraint) THEN
162
xi = ANINT(x / (1.0_dp / (NptS-1.0_dp))) + 1
163
x = (xsurf(xi)-x0)/(x1-x0)
164
END IF
165
166
xnew = x0 + x * (x1 - x0)
167
168
IF (Cubic) THEN
169
y2s_p => y2s
170
y2b_p => y2b
171
zs = InterpolateCurve(xsurf,ysurf,xnew,y2s_p)
172
zb = InterpolateCurve(xbed,ybed,xnew,y2b_p)
173
ELSE
174
zs = InterpolateCurve(xsurf,ysurf,xnew)
175
zb = InterpolateCurve(xbed,ybed,xnew)
176
END IF
177
178
ynew = zb + y * MAX((zs - zb),hmin)
179
180
WRITE(12,1200)N,j,xnew,ynew,z
181
END DO
182
WRITE(*,*)'END WITH NO TROUBLE ...'
183
!
184
1000 FORMAT(I6)
185
1200 FORMAT(i5,2x,i5,3(2x,e22.15))
186
187
End Program MshGlacier
188
189