Path: blob/devel/elmerice/Meshers/MshGlacierSynthetic.F90
3196 views
!/*****************************************************************************/1! *2! * Elmer/Ice, a glaciological add-on to Elmer3! * http://elmerice.elmerfem.org4! *5! *6! * This program is free software; you can redistribute it and/or7! * modify it under the terms of the GNU General Public License8! * as published by the Free Software Foundation; either version 29! * of the License, or (at your option) any later version.10! *11! * This program is distributed in the hope that it will be useful,12! * but WITHOUT ANY WARRANTY; without even the implied warranty of13! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14! * GNU General Public License for more details.15! *16! * You should have received a copy of the GNU General Public License17! * along with this program (in file fem/GPL-2); if not, write to the18! * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19! * Boston, MA 02110-1301, USA.20! *21! *****************************************************************************/22! ******************************************************************************23! *24! * Authors: Olivier Gagliardini25! * Email:26! * Web: http://elmerice.elmerfem.org27! *28! * Original Date:29! *30! *****************************************************************************31!> Create a Synthetic 2D or 3D mesh starting from a32!> 1m thick mesh using the right contour of the final mesh33!> and bedrock and surface elevations given as functions34!> Work for partitioned mesh35!> number of partitions in mesh_info.in36!>37!> Need to be compiled with38!> 2D : fbed(x) and fsurf(x)39!> 3D : fbed(x,y) and fsurf(x,y)40!>41PROGRAM MshGlacierSynthetic42USE types43!44IMPLICIT NONE45!46INTEGER :: NtN47!48REAL(KIND=dp) :: znew, zb, zs49REAL(KIND=dp) :: fbed, fsurf50REAL(KIND=dp), ALLOCATABLE :: x(:), y(:), z(:)51INTEGER, ALLOCATABLE :: Node(:)52Character :: Rien*153Character(len=10) :: iNp, iNN54CHARACTER :: NameMsh*3055Integer i, j, k, N, Np, dim56Logical :: Serial = .False.5758!59! Read the name mesh and number of partitions60!61OPEN(10,file="mesh_info.in")62READ(10,*)Rien63READ(10,*)NameMsh64READ(10,*)Rien65READ(10,*)Np66CLOSE(10)6768IF (Np==1) Serial=.True.6970IF (.NOT.Serial) THEN71IF (Np < 10) THEN72WRITE(iNp,'(i1.1)')Np73ELSE IF (Np < 100) THEN74WRITE(iNp,'(i2.2)')Np75ELSE IF (Np < 1000) THEN76WRITE(iNp,'(i3.3)')Np77ELSE IF (Np < 10000) THEN78WRITE(iNp,'(i4.4)')Np79ELSE80WRITE(*,*)'Work for a number of partitions < 1000'81STOP82END IF83iNp = ADJUSTL(iNp)84END IF8586DO k = 1, Np87WRITE(*,*)k,' of ', Np8889IF (.NOT.Serial) THEN90IF (k < 10) THEN91WRITE(iNN,'(i1.1)')k92ELSE IF (k < 100) THEN93WRITE(iNN,'(i2.2)')k94ELSE IF (k < 1000) THEN95WRITE(iNN,'(i3.3)')k96ELSE IF (k < 10000) THEN97WRITE(iNN,'(i4.4)')k98END IF99iNN = ADJUSTL(iNN)100WRITE(*,*)'iNN',iNN101102OPEN(11,file=TRIM(NameMsh)//"/partitioning."//TRIM(iNp)//"/part."//TRIM(iNN)//".header")103ELSE104OPEN(11,file=TRIM(NameMsh)//"/mesh.header")105END IF106107READ(11,*)NtN108CLOSE(11)109110ALLOCATE (Node(NtN), x(NtN), y(NtN), z(NtN))111WRITE(*,*)'Part ', k, ' NtN = ', NtN112113IF (.NOT.Serial) THEN114OPEN(12,file=TRIM(NameMsh)//"/partitioning."//TRIM(iNp)//"/part."//TRIM(iNN)//".nodes")115ELSE116OPEN(12,file=TRIM(NameMsh)//"/mesh.nodes")117END IF118DO i=1,NtN119READ(12,*)Node(i),j,x(i),y(i),z(i)120END DO121122! Check if we have a 2D or a 3D geometry123IF (k==1) THEN124IF (ANY(ABS(z)>AEPS)) THEN ! 3D Case125IF (ANY(z > 1.0_dp).OR.ANY(z<0.0_dp)) THEN126WRITE(*,*)'For 3D geometry, the initial mesh must fulfil 0 < z < 1'127STOP128END IF129dim = 3130WRITE(*,*)'Initial mesh verified, found to be a 3D geometry'131ELSE ! 2D Case132IF (ANY(y > 1.0_dp).OR.ANY(y<0.0_dp)) THEN133WRITE(*,*)'For 2D geometry, the initial mesh must fulfil 0 < y < 1'134STOP135END IF136dim = 2137WRITE(*,*)'Initial mesh verified, found to be a 2D geometry'138END IF139END IF140141REWIND(12)142143DO i=1,NtN144IF (dim==2) THEN145zs = fsurf(x(i))146zb = fbed(x(i))147ELSE148zs = fsurf(x(i),y(i))149zb = fbed(x(i),y(i))150END IF151IF ((zs-zb).LE.0.0) THEN152WRITE(*,*)'NEGATIVE OR NULL THICKNESS!!!'153STOP154END IF155156IF (dim==2) THEN157znew = zb + y(i)*(zs - zb)158WRITE(12,1200)Node(i),j,x(i),znew,z(i)159ELSE160znew = zb + z(i)*(zs - zb)161WRITE(12,1200)Node(i),j,x(i),y(i),znew162END IF163END DO164CLOSE(12)165166DEALLOCATE (Node, x, y, z)167END DO168!169!1701000 Format(a1)1711001 Format(28x,3(i3,x))1721002 Format(x,e14.8)1731741200 Format(i7,2x,i5,3(2x,e22.15))175176END PROGRAM MshGlacierSynthetic177178179