MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_oneblock.t
Go to the documentation of this file.
1!=============================================================================
2! Module oneblock to hold a datastructure as output by convert_type='oneblock'.
3! Currently only ASCII
4! Can be handy to read in initial conditions.
5! 2015-02-18 Oliver Porth
6!=============================================================================
8 use mod_comm_lib, only: mpistop
9 implicit none
10 save
11
12 double precision, allocatable :: woneblock({^d&:|,},:)
13 double precision, allocatable :: xoneblock({^d&:|,},:)
14
15 integer, private :: nc^d
16 integer, private :: unit=15 !file unit to read on
17
18contains
19
20 subroutine read_oneblock(filename)
22
23 character(len=*), intent(in) :: filename
24
25 double precision :: time
26 integer :: ix^D, ixp^D, idim
27 integer :: sendbuff(^ND)
28 character(len=1024) :: outfilehead
29
30 if (mype == 0) &
31 write(*,*) 'mod_oneblock: reading ', nw,' variables on unit:', unit
32
33 !----------------------------------------
34 ! Root does the reading:
35 !----------------------------------------
36 if (mype == 0) then
37 open(unit,file=filename,status='unknown')
38 ! The header information:
39 read(unit,'(A)') outfilehead
40 read(unit,*) nc^d
41 read(unit,*) time
42
43 ! Allocate and read the grid and variables:
44 allocate(xoneblock(nc^d,1:^nd))
45 allocate(woneblock(nc^d,1:nw))
46
47 {do ix^db=1,nc^db\}
48 read(unit,*) xoneblock(ix^d,1:^nd), woneblock(ix^d,1:nw)
49 {end do\}
50
51 ! Close the file
52 close(unit)
53 end if! mype==0
54
55 !----------------------------------------
56 ! Broadcast what mype=0 read:
57 !----------------------------------------
58 if (npe > 1) then
59 {sendbuff(^d)=nc^d;}
60 call mpi_bcast(sendbuff,^nd,mpi_integer,0,icomm,ierrmpi)
61
62 if (mype /= 0) then
63 {nc^d=sendbuff(^d);}
64 ! Allocate the grid and variables:
65 allocate(xoneblock(nc^d,1:^nd))
66 allocate(woneblock(nc^d,1:nw))
67 end if
68
69 call mpi_bcast(xoneblock,{nc^d|*}*^nd,mpi_double_precision,0,icomm,ierrmpi)
70 call mpi_bcast(woneblock,{nc^d|*}*nw,mpi_double_precision,0,icomm,ierrmpi)
71 end if! npe>1
72
73 end subroutine read_oneblock
74
75 subroutine interpolate_oneblock(x,iw,out)
76
77 double precision, intent(in) :: x(^ND)
78 integer, intent(in) :: iw
79 double precision, intent(out) :: out
80 ! .. local ..
81 double precision :: xloc(^ND)
82 double precision :: xd^D
83 {^iftwod
84 double precision :: c00, c10
85 }
86 {^ifthreed
87 double precision :: c0, c1, c00, c10, c01, c11
88 }
89 integer :: ipivot^D, idir
90 integer :: ic^D, ic1^D, ic2^D
91
92 xloc = x
93
94 !--------------------------------------------
95 ! Hunt for the index closest to the point
96 ! This is a bit slow but allows for stretched grids
97 ! (still need to be orthogonal for interpolation though)
98 !--------------------------------------------
99 ipivot^d=1;
100 {^ifoned
101 ic1 = minloc(dabs(xloc(1)-xoneblock(:,1)),1,mask=.true.)
102 }
103 {^iftwod
104 do idir = 1, ^nd
105 select case (idir)
106 case (1)
107 ic1 = minloc(dabs(xloc(1)-xoneblock(:,ipivot2,idir)),1,mask=.true.)
108 case (2)
109 ic2 = minloc(dabs(xloc(2)-xoneblock(ipivot1,:,idir)),1,mask=.true.)
110 case default
111 call mpistop("error in interpolate_oneblock")
112 end select
113 end do
114 }
115 {^ifthreed
116 do idir = 1, ^nd
117 select case (idir)
118 case (1)
119 ic1 = minloc(dabs(xloc(1)-xoneblock(:,ipivot2,ipivot3,idir)),1, &
120 mask=.true.)
121 case (2)
122 ic2 = minloc(dabs(xloc(2)-xoneblock(ipivot1,:,ipivot3,idir)),1, &
123 mask=.true.)
124 case (3)
125 ic3 = minloc(dabs(xloc(3)-xoneblock(ipivot1,ipivot2,:,idir)),1, &
126 mask=.true.)
127 case default
128 call mpistop("error in interpolate_oneblock")
129 end select
130 end do
131 }
132
133 ! flat interpolation would simply be:
134 !out = woneblock(ic^D,iw)
135 !return
136
137 !-------------------------------------------
138 ! Get the left and right indices
139 !-------------------------------------------
140 {
141 if (xoneblock({ic^dd},^d) < xloc(^d)) then
142 ic1^d = ic^d
143 else
144 ic1^d = ic^d -1
145 end if
146 ic2^d = ic1^d + 1
147 \}
148
149 !--------------------------------------------
150 ! apply flat interpolation if outside of range,
151 ! change point-location to make this easy!
152 !--------------------------------------------
153 {
154 if (ic1^d < 1) then
155 ic1^d = 1
156 ic2^d = ic1^d + 1
157 xloc(^d) = xoneblock(ic^dd,^d)
158 end if
159 \}
160 {
161 if (ic2^d > nc^d) then
162 ic2^d = nc^d
163 ic1^d = ic2^d - 1
164 xloc(^d) = xoneblock(ic^dd,^d)
165 end if
166 \}
167
168
169 !-------------------------------------------
170 ! linear, bi- and tri- linear interpolations
171 !-------------------------------------------
172 {^ifoned
173 xd1 = (xloc(1)-xoneblock(ic11,1)) / (xoneblock(ic21,1) - xoneblock(ic11,1))
174 out = woneblock(ic11,iw) * (1.0d0 - xd1) + woneblock(ic21,iw) * xd1
175 }
176 {^iftwod
177 xd1 = (xloc(1)-xoneblock(ic11,ic12,1)) / (xoneblock(ic21,ic12,1) - xoneblock(ic11,ic12,1))
178 xd2 = (xloc(2)-xoneblock(ic11,ic12,2)) / (xoneblock(ic11,ic22,2) - xoneblock(ic11,ic12,2))
179 c00 = woneblock(ic11,ic12,iw) * (1.0d0 - xd1) + woneblock(ic21,ic12,iw) * xd1
180 c10 = woneblock(ic11,ic22,iw) * (1.0d0 - xd1) + woneblock(ic21,ic22,iw) * xd1
181 out = c00 * (1.0d0 - xd2) + c10 * xd2
182 }
183 {^ifthreed
184 xd1 = (xloc(1)-xoneblock(ic11,ic12,ic13,1)) / (xoneblock(ic21,ic12,ic13,1) - xoneblock(ic11,ic12,ic13,1))
185 xd2 = (xloc(2)-xoneblock(ic11,ic12,ic13,2)) / (xoneblock(ic11,ic22,ic13,2) - xoneblock(ic11,ic12,ic13,2))
186 xd3 = (xloc(3)-xoneblock(ic11,ic12,ic13,3)) / (xoneblock(ic11,ic12,ic23,3) - xoneblock(ic11,ic12,ic13,3))
187
188 c00 = woneblock(ic11,ic12,ic13,iw) * (1.0d0 - xd1) + woneblock(ic21,ic12,ic13,iw) * xd1
189 c10 = woneblock(ic11,ic22,ic13,iw) * (1.0d0 - xd1) + woneblock(ic21,ic22,ic13,iw) * xd1
190 c01 = woneblock(ic11,ic12,ic23,iw) * (1.0d0 - xd1) + woneblock(ic21,ic12,ic23,iw) * xd1
191 c11 = woneblock(ic11,ic22,ic23,iw) * (1.0d0 - xd1) + woneblock(ic21,ic22,ic23,iw) * xd1
192
193 c0 = c00 * (1.0d0 - xd2) + c10 * xd2
194 c1 = c01 * (1.0d0 - xd2) + c11 * xd2
195
196 out = c0 * (1.0d0 - xd3) + c1 * xd3
197 }
198
199 end subroutine interpolate_oneblock
200
201end module mod_oneblock
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer mype
The rank of the current MPI task.
subroutine read_oneblock(filename)
double precision, dimension({^d &:|,},:), allocatable xoneblock
subroutine interpolate_oneblock(x, iw, out)
double precision, dimension({^d &:|,},:), allocatable woneblock