Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/Meshers/MshGlacierSynthetic.F90
3196 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 Synthetic 2D or 3D mesh starting from a
33
!> 1m thick mesh using the right contour of the final mesh
34
!> and bedrock and surface elevations given as functions
35
!> Work for partitioned mesh
36
!> number of partitions in mesh_info.in
37
!>
38
!> Need to be compiled with
39
!> 2D : fbed(x) and fsurf(x)
40
!> 3D : fbed(x,y) and fsurf(x,y)
41
!>
42
PROGRAM MshGlacierSynthetic
43
USE types
44
!
45
IMPLICIT NONE
46
!
47
INTEGER :: NtN
48
!
49
REAL(KIND=dp) :: znew, zb, zs
50
REAL(KIND=dp) :: fbed, fsurf
51
REAL(KIND=dp), ALLOCATABLE :: x(:), y(:), z(:)
52
INTEGER, ALLOCATABLE :: Node(:)
53
Character :: Rien*1
54
Character(len=10) :: iNp, iNN
55
CHARACTER :: NameMsh*30
56
Integer i, j, k, N, Np, dim
57
Logical :: Serial = .False.
58
59
!
60
! Read the name mesh and number of partitions
61
!
62
OPEN(10,file="mesh_info.in")
63
READ(10,*)Rien
64
READ(10,*)NameMsh
65
READ(10,*)Rien
66
READ(10,*)Np
67
CLOSE(10)
68
69
IF (Np==1) Serial=.True.
70
71
IF (.NOT.Serial) THEN
72
IF (Np < 10) THEN
73
WRITE(iNp,'(i1.1)')Np
74
ELSE IF (Np < 100) THEN
75
WRITE(iNp,'(i2.2)')Np
76
ELSE IF (Np < 1000) THEN
77
WRITE(iNp,'(i3.3)')Np
78
ELSE IF (Np < 10000) THEN
79
WRITE(iNp,'(i4.4)')Np
80
ELSE
81
WRITE(*,*)'Work for a number of partitions < 1000'
82
STOP
83
END IF
84
iNp = ADJUSTL(iNp)
85
END IF
86
87
DO k = 1, Np
88
WRITE(*,*)k,' of ', Np
89
90
IF (.NOT.Serial) THEN
91
IF (k < 10) THEN
92
WRITE(iNN,'(i1.1)')k
93
ELSE IF (k < 100) THEN
94
WRITE(iNN,'(i2.2)')k
95
ELSE IF (k < 1000) THEN
96
WRITE(iNN,'(i3.3)')k
97
ELSE IF (k < 10000) THEN
98
WRITE(iNN,'(i4.4)')k
99
END IF
100
iNN = ADJUSTL(iNN)
101
WRITE(*,*)'iNN',iNN
102
103
OPEN(11,file=TRIM(NameMsh)//"/partitioning."//TRIM(iNp)//"/part."//TRIM(iNN)//".header")
104
ELSE
105
OPEN(11,file=TRIM(NameMsh)//"/mesh.header")
106
END IF
107
108
READ(11,*)NtN
109
CLOSE(11)
110
111
ALLOCATE (Node(NtN), x(NtN), y(NtN), z(NtN))
112
WRITE(*,*)'Part ', k, ' NtN = ', NtN
113
114
IF (.NOT.Serial) THEN
115
OPEN(12,file=TRIM(NameMsh)//"/partitioning."//TRIM(iNp)//"/part."//TRIM(iNN)//".nodes")
116
ELSE
117
OPEN(12,file=TRIM(NameMsh)//"/mesh.nodes")
118
END IF
119
DO i=1,NtN
120
READ(12,*)Node(i),j,x(i),y(i),z(i)
121
END DO
122
123
! Check if we have a 2D or a 3D geometry
124
IF (k==1) THEN
125
IF (ANY(ABS(z)>AEPS)) THEN ! 3D Case
126
IF (ANY(z > 1.0_dp).OR.ANY(z<0.0_dp)) THEN
127
WRITE(*,*)'For 3D geometry, the initial mesh must fulfil 0 < z < 1'
128
STOP
129
END IF
130
dim = 3
131
WRITE(*,*)'Initial mesh verified, found to be a 3D geometry'
132
ELSE ! 2D Case
133
IF (ANY(y > 1.0_dp).OR.ANY(y<0.0_dp)) THEN
134
WRITE(*,*)'For 2D geometry, the initial mesh must fulfil 0 < y < 1'
135
STOP
136
END IF
137
dim = 2
138
WRITE(*,*)'Initial mesh verified, found to be a 2D geometry'
139
END IF
140
END IF
141
142
REWIND(12)
143
144
DO i=1,NtN
145
IF (dim==2) THEN
146
zs = fsurf(x(i))
147
zb = fbed(x(i))
148
ELSE
149
zs = fsurf(x(i),y(i))
150
zb = fbed(x(i),y(i))
151
END IF
152
IF ((zs-zb).LE.0.0) THEN
153
WRITE(*,*)'NEGATIVE OR NULL THICKNESS!!!'
154
STOP
155
END IF
156
157
IF (dim==2) THEN
158
znew = zb + y(i)*(zs - zb)
159
WRITE(12,1200)Node(i),j,x(i),znew,z(i)
160
ELSE
161
znew = zb + z(i)*(zs - zb)
162
WRITE(12,1200)Node(i),j,x(i),y(i),znew
163
END IF
164
END DO
165
CLOSE(12)
166
167
DEALLOCATE (Node, x, y, z)
168
END DO
169
!
170
!
171
1000 Format(a1)
172
1001 Format(28x,3(i3,x))
173
1002 Format(x,e14.8)
174
175
1200 Format(i7,2x,i5,3(2x,e22.15))
176
177
END PROGRAM MshGlacierSynthetic
178
179