MPI-AMRVAC  3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
mod_bc_data.t
Go to the documentation of this file.
1 !> Module to set boundary conditions from user data
2 module mod_bc_data
4  use mod_global_parameters, only: std_len
5 
6  implicit none
7  private
8 
9  integer, parameter :: max_boundary_conds = 10
10 
11  type bc_data_t
12  integer :: n_variables
13  double precision :: origin(3)
14  double precision :: dx(3)
15  integer :: n_points(3)
16  character(len=40), allocatable :: names(:)
17  double precision, allocatable :: values(:, :, :, :)
18  end type bc_data_t
19 
20  type(LT_t) :: lt_1d(max_boundary_conds)
21  type(LT2_t) :: lt_2d(max_boundary_conds)
22  type(LT3_t) :: lt_3d(max_boundary_conds)
23 
24  !> Whether boundary condition data is time varying
25  logical, public, protected :: bc_data_time_varying = .false.
26 
27  !> Integer array for indexing lookup tables per variable per direction
28  integer, public, protected, allocatable :: bc_data_ix(:, :)
29 
30  !> data file name
31  character(len=std_len), public, protected :: boundary_data_file_name
32  logical, public, protected :: interp_phy_first_row=.true.
33  logical, public, protected :: interp_phy_first_row_same=.false.
34  logical, public, protected :: bc_phy_first_row=.false.
35  logical, public, protected :: boundary_data_primitive=.false.
36 
37  public :: bc_data_init
38  public :: bc_data_set
39  public :: bc_data_get_2d
40  public :: bc_data_get_3d
41 
42 contains
43 
44  subroutine bc_data_init()
46  use mod_comm_lib, only: mpistop
47 
48  integer :: i, iw, ib, n_files, n_bc
49  double precision :: xmax(3)
50  type(bc_data_t) :: bc
51 
53 
54  allocate(bc_data_ix(nwfluxbc, 2*ndim))
55 
56  bc_data_ix(:, :) = -1
57  n_bc = 0
58 
59  if(any(typeboundary(1:nwfluxbc,1:2*ndim)==bc_data ) .or. any(typeboundary(1:nwfluxbc,1:2*ndim)==bc_icarus)) then
61  xmax = bc%origin + (bc%n_points-1) * bc%dx
62  bc_data_time_varying = (bc%n_points(ndim) > 1)
63 
64  endif
65 
66  do ib = 1, 2 * ndim
67  do iw = 1, nwfluxbc
68  if (typeboundary(iw, ib)==bc_data .or. typeboundary(iw, ib)==bc_icarus) then
69  n_bc = n_bc + 1
70  bc_data_ix(iw, ib) = n_bc
71 
72 
73  {^ifoned
74  call mpistop("bc_data_init: 1D case not supported")
75  }
76  {^iftwod
77  if (bc_data_time_varying) then
78  lt_2d(n_bc) = lt2_create_from_data(bc%origin(1:ndim), &
79  xmax(1:ndim), bc%values(:, :, 1:1, n_bc))
80  else
81  ! Use first point in time
82  lt_1d(n_bc) = lt_create_from_data(bc%origin(1), &
83  xmax(1), bc%values(:, 1, 1:1, n_bc))
84  end if
85  }
86  {^ifthreed
87  if (bc_data_time_varying) then
88  lt_3d(n_bc) = lt3_create_from_data(bc%origin(1:ndim), &
89  xmax(1:ndim), bc%values(:, :, :, n_bc:n_bc))
90  else
91  ! Use first point in time
92  lt_2d(n_bc) = lt2_create_from_data(bc%origin(1:ndim-1), &
93  xmax(1:ndim-1), bc%values(:, :, 1:1, n_bc))
94  end if
95  }
96  end if
97  end do
98  end do
99 
100  end subroutine bc_data_init
101 
102  !> Read this module"s parameters from a file
103  subroutine bc_read_params(files)
105  character(len=*), intent(in) :: files(:)
106  integer :: n
107 
110 
111  do n = 1, size(files)
112  open(unitpar, file=trim(files(n)), status="old")
113  read(unitpar, bd_list, end=111)
114 111 close(unitpar)
115  end do
116 
117  end subroutine bc_read_params
118 
119  elemental function bc_data_get_3d(n_bc, x1, x2, qt) result(val)
120  integer, intent(in) :: n_bc
121  double precision, intent(in) :: x1, x2, qt
122  double precision :: val
123 
124  if (bc_data_time_varying) then
125  val = lt3_get_col(lt_3d(n_bc), 1, x1, x2, qt)
126  else
127  val = lt2_get_col(lt_2d(n_bc), 1, x1, x2)
128  end if
129  end function bc_data_get_3d
130 
131  elemental function bc_data_get_2d(n_bc, x1, qt) result(val)
132  integer, intent(in) :: n_bc
133  double precision, intent(in) :: x1, qt
134  double precision :: val
135 
136  if (bc_data_time_varying) then
137  val = lt2_get_col(lt_2d(n_bc), 1, x1, qt)
138  else
139  val = lt_get_col(lt_1d(n_bc), 1, x1)
140  end if
141  end function bc_data_get_2d
142 
143  !> Set boundary conditions according to user data
144  subroutine bc_data_set(qt,ixI^L,ixO^L,iB,w,x)
147  use mod_comm_lib, only: mpistop
148 
149  integer, intent(in) :: ixi^l, ixo^l, ib
150  double precision, intent(in) :: qt, x(ixi^s,1:ndim)
151  double precision, intent(inout) :: w(ixi^s,1:nw)
152  double precision :: tmp(ixo^s)
153  integer :: i, ix, iw, n_bc
154 
155  integer :: ixoo^l
156 
157  ixoo^l=ixo^l;
158 
159  {^iftwod
160  select case (ib)
161  case (1, 2)
162  if(interp_phy_first_row) then
163  if (ib == 1) then
164  ix = ixomax1+1
165  else
166  ix = ixomin1-1
167  end if
168  if(boundary_data_primitive) then
169  call phys_to_primitive(ixi^l,ix,ixomin2,ix,ixomax2,w,x)
170  endif
171  endif
172  ! the reason for this is that not all bc for all the vars
173  ! might be set with bc_data
174  if(bc_phy_first_row)then
175  if (ib == 1) then
176  ixoomax1=ixoomax1+1
177  else
178  ixoomin1=ixoomin1-1
179  endif
180  if(boundary_data_primitive) then
181  if (ib == 1) then
182  ixoomin1=ixoomax1
183  else
184  ixoomax1=ixoomin1
185  endif
186  call phys_to_primitive(ixi^l,ixoo^l,w,x)
187  if (ib == 1) then
188  ixoomin1=ixomin1 ! to be used later in to_conserved
189  else
190  ixoomax1=ixomax1
191  endif
192  endif
193  endif
194  do iw = 1, nwfluxbc
195  n_bc = bc_data_ix(iw, ib)
196  if (n_bc == -1) cycle
197 
198  tmp(ixomin1, ixomin2:ixomax2) = bc_data_get_2d(n_bc, &
199  x(ixomin1, ixomin2:ixomax2, 2), qt)
200  if(interp_phy_first_row) then
201  ! Approximate boundary value by linear interpolation to first ghost
202  ! cell, rest of ghost cells contains the same value
204  do i = 0, ixoomax1-ixoomin1
205  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
206  2 * tmp(ixomin1, ixomin2:ixomax2) - &
207  w(ix, ixomin2:ixomax2, iw)
208  end do
209  else
210  if (ib==1) then
211  do i = 0, ixoomax1-ixoomin1
212  if (i==0) then
213  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
214  4 * tmp(ixomin1, ixomin2:ixomax2) - &
215  3 * w(ix, ixomin2:ixomax2, iw)
216  elseif (i==1)then
217  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
218  2 * tmp(ixomin1, ixomin2:ixomax2) - &
219  w(ix, ixomin2:ixomax2, iw)
220  else
221  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
222  tmp(ixomin1, ixomin2:ixomax2)
223  endif
224 
225  end do
226  else
227  do i = 0, ixoomax1-ixoomin1
228  if (i==ixoomax1-ixoomin1) then
229  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
230  4 * tmp(ixomin1, ixomin2:ixomax2) - &
231  3 * w(ix, ixomin2:ixomax2, iw)
232  elseif (i==ixoomax1-ixoomin1-1)then
233  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
234  2 * tmp(ixomin1, ixomin2:ixomax2) - &
235  w(ix, ixomin2:ixomax2, iw)
236  else
237  w(ixoomin1+i, ixomin2:ixomax2, iw) = &
238  tmp(ixomin1, ixomin2:ixomax2)
239  endif
240 
241  end do
242  endif
243 
244  endif
245  else
246  do i = ixoomin1, ixoomax1
247  w(i, ixomin2:ixomax2, iw) = &
248  tmp(ixomin1, ixomin2:ixomax2)
249  end do
250 
251  endif
252  end do
253  if(interp_phy_first_row) then
254  if(boundary_data_primitive) then
255  call phys_to_conserved(ixi^l,ix,ixomin2,ix,ixomax2,w,x)
256  endif
257  endif
258  case (3, 4)
259  if(interp_phy_first_row) then
260  if (ib == 3) then
261  ix = ixomax2+1
262  else
263  ix = ixomin2-1
264  end if
265  if(boundary_data_primitive) then
266  call phys_to_primitive(ixi^l,ixomin1,ix,ixomax1,ix,w,x)
267  endif
268  endif
269  if(bc_phy_first_row)then
270  if (ib == 3) then
271  ixoomax2=ixoomax2+1
272  else
273  ixoomin2=ixoomin2-1
274  endif
275  if(boundary_data_primitive) then
276  if (ib == 3) then
277  ixoomin2=ixoomax2
278  else
279  ixoomax2=ixoomin2
280  endif
281  call phys_to_primitive(ixi^l,ixoo^l,w,x)
282  if (ib == 3) then
283  ixoomin2=ixomin2 ! to be used later in to_conserved
284  else
285  ixoomax2=ixomax2
286  endif
287  endif
288  endif
289  do iw = 1, nwfluxbc
290  n_bc = bc_data_ix(iw, ib)
291  if (n_bc == -1) cycle
292 
293  tmp(ixomin1:ixomax1, ixomin2) = bc_data_get_2d(n_bc, &
294  x(ixomin1:ixomax1, ixomin2, 1), qt)
295 
296  if(interp_phy_first_row) then
297 
298  ! Approximate boundary value by linear interpolation to first ghost
299  ! cell, rest of ghost cells contains the same value
301  do i = 0, ixoomax2-ixoomin2
302  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
303  2 * tmp(ixomin1:ixomax1, ixomin2) - &
304  w(ixomin1:ixomax1, ix, iw)
305  end do
306  else
307  if (ib==3) then
308  do i = 0, ixoomax2-ixoomin2
309  if (i==0) then
310  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
311  4 * tmp(ixomin1:ixomax1, ixomin2) - &
312  3 * w(ixomin1:ixomax1, ix, iw)
313  elseif (i==1)then
314  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
315  2 * tmp(ixomin1:ixomax1, ixomin2) - &
316  w(ixomin1:ixomax1, ix, iw)
317  else
318  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
319  tmp(ixomin1:ixomax1, ixomin2)
320  endif
321 
322  end do
323  else
324  do i = 0, ixoomax2-ixoomin2
325  if (i==ixoomax2-ixoomin2) then
326  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
327  4 * tmp(ixomin1:ixomax1, ixomin2) - &
328  3 * w(ixomin1:ixomax1, ix, iw)
329  elseif (i==ixoomax2-ixoomin2-1)then
330  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
331  2 * tmp(ixomin1:ixomax1, ixomin2) - &
332  w(ixomin1:ixomax1, ix, iw)
333  else
334  w(ixomin1:ixomax1, ixoomin2+i, iw) = &
335  tmp(ixomin1:ixomax1, ixomin2)
336  endif
337 
338  end do
339  endif
340 
341  endif
342  else
343  do i = ixoomin2, ixoomax2
344  w(ixomin1:ixomax1, i, iw) = &
345  tmp(ixomin1:ixomax1, ixomin2)
346  end do
347 
348  endif
349  end do
350  if(interp_phy_first_row) then
351  if(boundary_data_primitive) then
352  call phys_to_conserved(ixi^l,ixomin1,ix,ixomax1,ix,w,x)
353  endif
354  endif
355  case default
356  call mpistop("bc_data_set: unknown iB")
357  end select
358  }
359 
360  {^ifthreed
361  select case (ib)
362  case (1, 2)
363  if(interp_phy_first_row) then
364  if (ib == 1) then
365  ix = ixomax1+1
366  else
367  ix = ixomin1-1
368  end if
369  if(boundary_data_primitive) then
370  call phys_to_primitive(ixi^l,ix,ixomin2,ixomin3,ix,ixomax2,ixomax3,w,x)
371  endif
372  endif
373  if(bc_phy_first_row)then
374  if (ib == 1) then
375  ixoomax1=ixoomax1+1
376  else
377  ixoomin1=ixoomin1-1
378  endif
379  if(boundary_data_primitive) then
380  if (ib == 1) then
381  ixoomin1=ixoomax1
382  else
383  ixoomax1=ixoomin1
384  endif
385  call phys_to_primitive(ixi^l,ixoo^l,w,x)
386  if (ib == 1) then
387  ixoomin1=ixomin1 ! to be used later in to_conserved
388  else
389  ixoomax1=ixomax1
390  endif
391  endif
392  endif
393  do iw = 1, nwfluxbc
394  n_bc = bc_data_ix(iw, ib)
395  if (n_bc == -1) cycle
396 
397  tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) = bc_data_get_3d(n_bc, &
398  x(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3, 2), &
399  x(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3, 3), qt)
400 
401  if(interp_phy_first_row) then
402 
403  ! Approximate boundary value by linear interpolation to first ghost
404  ! cell, rest of ghost cells contains the same value
406  do i = 0, ixoomax1-ixoomin1
407  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
408  2 * tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) - &
409  w(ix, ixomin2:ixomax2, ixomin3:ixomax3, iw)
410  end do
411  else
412  if (ib==1) then
413  do i = 0, ixoomax1-ixoomin1
414  if (i==0) then
415  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
416  4 * tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) - &
417  3*w(ix, ixomin2:ixomax2, ixomin3:ixomax3, iw)
418  elseif (i==1)then
419  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
420  2 * tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) - &
421  w(ix, ixomin2:ixomax2, ixomin3:ixomax3, iw)
422  else
423  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
424  tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3)
425  endif
426 
427  end do
428  else
429  do i = 0, ixoomax1-ixoomin1
430  if (i==ixoomax1-ixoomin1) then
431  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
432  4 * tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) - &
433  3*w(ix, ixomin2:ixomax2, ixomin3:ixomax3, iw)
434  elseif (i==ixoomax1-ixoomin1-1)then
435  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
436  2 * tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3) - &
437  w(ix, ixomin2:ixomax2, ixomin3:ixomax3, iw)
438  else
439  w(ixoomin1+i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
440  tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3)
441  endif
442 
443  end do
444  endif
445 
446  endif
447  else
448  do i = ixoomin1,ixoomax1
449  w(i, ixomin2:ixomax2, ixomin3:ixomax3, iw) = &
450  tmp(ixomin1, ixomin2:ixomax2, ixomin3:ixomax3)
451  end do
452  end if
453 
454  end do
455  if(interp_phy_first_row) then
456  if(boundary_data_primitive) then
457  call phys_to_conserved(ixi^l,ix,ixomin2,ixomin3,ix,ixomax2,ixomax3,w,x)
458  endif
459  endif
460  case (3, 4)
461  if(interp_phy_first_row) then
462  if (ib == 3) then
463  ix = ixomax2+1
464  else
465  ix = ixomin2-1
466  end if
467  if(boundary_data_primitive) then
468  call phys_to_primitive(ixi^l,ixomin1,ix,ixomin3,ixomax1,ix,ixomax3,w,x)
469  endif
470  endif
471  if(bc_phy_first_row)then
472  if (ib == 3) then
473  ixoomax2=ixoomax2+1
474  else
475  ixoomin2=ixoomin2-1
476  endif
477  if(boundary_data_primitive) then
478  if (ib == 3) then
479  ixoomin2=ixoomax2
480  else
481  ixoomax2=ixoomin2
482  endif
483  call phys_to_primitive(ixi^l,ixoo^l,w,x)
484  if (ib == 3) then
485  ixoomin2=ixomin2 ! to be used later in to_conserved
486  else
487  ixoomax2=ixomax2
488  endif
489  endif
490  endif
491  do iw = 1, nwfluxbc
492  n_bc = bc_data_ix(iw, ib)
493  if (n_bc == -1) cycle
494 
495  tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) = bc_data_get_3d(n_bc, &
496  x(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3, 1), &
497  x(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3, 3), qt)
498 
499  if(interp_phy_first_row) then
500 
502  ! Approximate boundary value by linear interpolation to first ghost
503  ! cell, rest of ghost cells contains the same value
504  do i = 0, ixoomax2-ixoomin2
505  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
506  2 * tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) - &
507  w(ixomin1:ixomax1, ix, ixomin3:ixomax3, iw)
508  end do
509  else
510  if (ib==3) then
511  do i = 0, ixoomax2-ixoomin2
512  if (i==0) then
513  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
514  4 * tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) - &
515  3* w(ixomin1:ixomax1, ix, ixomin3:ixomax3, iw)
516  elseif (i==1)then
517  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
518  2 * tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) - &
519  w(ixomin1:ixomax1, ix, ixomin3:ixomax3, iw)
520  else
521  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
522  tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3)
523  endif
524 
525  end do
526  else
527  do i = 0, ixoomax2-ixoomin2
528  if (i==ixoomax2-ixoomin2) then
529  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
530  4 * tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) - &
531  3* w(ixomin1:ixomax1, ix, ixomin3:ixomax3, iw)
532  elseif (i==ixoomax2-ixoomin2-1)then
533  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
534  2 * tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3) - &
535  w(ixomin1:ixomax1, ix, ixomin3:ixomax3, iw)
536  else
537  w(ixomin1:ixomax1, ixoomin2+i, ixomin3:ixomax3, iw) = &
538  tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3)
539  endif
540 
541  end do
542  endif
543 
544  endif
545  else
546  do i = ixoomin2,ixoomax2
547  w(ixomin1:ixomax1, i, ixomin3:ixomax3, iw) = &
548  tmp(ixomin1:ixomax1, ixomin2, ixomin3:ixomax3)
549  end do
550  end if
551  end do
552  if(interp_phy_first_row) then
553  if(boundary_data_primitive) then
554  call phys_to_conserved(ixi^l,ixomin1,ix,ixomin3,ixomax1,ix,ixomax3,w,x)
555  endif
556  endif
557  case (5, 6)
558  if(interp_phy_first_row) then
559  if (ib == 5) then
560  ix = ixomax3+1
561  else
562  ix = ixomin3-1
563  end if
564  if(boundary_data_primitive) then
565  call phys_to_primitive(ixi^l,ixomin1,ixomax1,ixomin2,ixomax2,ix,ix,w,x)
566  endif
567  endif
568  if(bc_phy_first_row)then
569  if (ib == 5) then
570  ixoomax3=ixoomax3+1
571  else
572  ixoomin3=ixoomin3-1
573  endif
574  if(boundary_data_primitive) then
575  if (ib == 5) then
576  ixoomin3=ixoomax3
577  else
578  ixoomax3=ixoomin3
579  endif
580  call phys_to_primitive(ixi^l,ixoo^l,w,x)
581  if (ib == 5) then
582  ixoomin3=ixomin3 ! to be used later in to_conserved
583  else
584  ixoomax3=ixomax3
585  endif
586  endif
587  endif
588  do iw = 1, nwfluxbc
589  n_bc = bc_data_ix(iw, ib)
590  if (n_bc == -1) cycle
591 
592  tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) = bc_data_get_3d(n_bc, &
593  x(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3, 1), &
594  x(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3, 2), qt)
595 
596  if(interp_phy_first_row) then
597 
599  ! Approximate boundary value by linear interpolation to first ghost
600  ! cell, rest of ghost cells contains the same value
601  do i = 0, ixoomax3-ixoomin3
602  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
603  2 * tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) - &
604  w(ixomin1:ixomax1, ixomin2:ixomax2, ix, iw)
605  end do
606  else
607  if (ib==5) then
608  do i = 0, ixoomax3-ixoomin3
609  if (i==0) then
610  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
611  4 * tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) - &
612  3 * w(ixomin1:ixomax1, ixomin2:ixomax2, ix, iw)
613  elseif (i==1)then
614  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
615  2 * tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) - &
616  w(ixomin1:ixomax1, ixomin2:ixomax2, ix, iw)
617  else
618  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
619  tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3)
620  endif
621 
622  end do
623  else
624  do i = 0, ixoomax3-ixoomin3
625  if (i==ixoomax3-ixoomin3) then
626  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
627  4 * tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) - &
628  3 * w(ixomin1:ixomax1, ixomin2:ixomax2, ix, iw)
629  elseif (i==ixoomax3-ixoomin3-1)then
630  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
631  2 * tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3) - &
632  w(ixomin1:ixomax1, ixomin2:ixomax2, ix, iw)
633  else
634  w(ixomin1:ixomax1, ixomin2:ixomax2, ixoomin3+i, iw) = &
635  tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3)
636  endif
637 
638  end do
639  endif
640 
641  endif
642  else
643  do i = ixoomin3,ixoomax3
644  w(ixomin1:ixomax1, ixomin2:ixomax2, i, iw) = &
645  tmp(ixomin1:ixomax1, ixomin2:ixomax2, ixomin3)
646  end do
647  end if
648  end do
649  if(interp_phy_first_row) then
650  if(boundary_data_primitive) then
651  call phys_to_conserved(ixi^l,ixomin1,ixomax1,ixomin2,ixomax2,ix,ix,w,x)
652  endif
653  endif
654  case default
655  call mpistop("bc_data_set: unknown iB")
656  end select
657  }
658 
659  if(boundary_data_primitive) then
660  call phys_to_conserved(ixi^l,ixoo^l,w,x)
661  endif
662 
663  end subroutine bc_data_set
664 
665  subroutine read_vtk_structured_points(fname, bc)
666  character(len=*), intent(in) :: fname
667  type(bc_data_t), intent(out) :: bc
668  double precision, allocatable :: tmp_data(:, :, :, :)
669  integer, parameter :: max_variables = 10
670  character(len=40) :: tmp_names(max_variables)
671  character(len=256) :: line
672  character(len=40) :: word, typename
673  integer, parameter :: my_unit = 123
674  integer :: n, n_points_total
675  integer :: n_components
676 
677  open(my_unit, file=trim(fname), status="old", action="read")
678 
679  ! Header, e.g. # vtk DataFile Version 2.0
680  read(my_unit, "(A)") line
681 
682  ! Dataset name
683  read(my_unit, "(A)") line
684 
685  ! ASCII / BINARY
686  read(my_unit, "(A)") line
687 
688  if (line /= "ASCII") then
689  print *, "line: ", trim(line)
690  error stop "read_vtk: not an ASCII file"
691  end if
692 
693  ! DATASET STRUCTURED_POINTS
694  read(my_unit, "(A)") line
695 
696  if (line /= "DATASET STRUCTURED_POINTS") then
697  print *, "line: ", trim(line)
698  error stop "read_vtk must have: DATASET STRUCTURED_POINTS"
699  end if
700 
701  ! DIMENSIONS NX NY NZ
702  read(my_unit, "(A)") line
703  read(line, *) word, bc%n_points
704 
705  if (word /= "DIMENSIONS") then
706  print *, "line: ", trim(line)
707  error stop "read_vtk expects: DIMENSIONS"
708  end if
709 
710  ! SPACING DX DY DZ
711  read(my_unit, *) word, bc%dx
712 
713  if (word /= "SPACING") then
714  print *, "line: ", trim(line)
715  error stop "read_vtk expects: SPACING"
716  end if
717 
718  ! ORIGIN 0 0 0
719  read(my_unit, *) word, bc%origin
720  if (word /= "ORIGIN") then
721  print *, "line: ", trim(line)
722  error stop "read_vtk expects: ORIGIN"
723  end if
724 
725  ! POINT_DATA NPOINTS
726  read(my_unit, *) word, n_points_total
727 
728  if (word /= "POINT_DATA") then
729  print *, "line: ", trim(line)
730  error stop "read_vtk expects: POINT_DATA n_points"
731  end if
732 
733  if (n_points_total /= product(bc%n_points)) &
734  error stop "read_vtk: n_points not equal to NX*NY*NZ"
735 
736  allocate(tmp_data(bc%n_points(1), bc%n_points(2), bc%n_points(3), &
737  max_variables))
738 
739  ! Read all scalar variables
740  do n = 1, max_variables
741 
742  ! SCALARS name type ncomponents
743  read(my_unit, *, end=900) word, tmp_names(n), typename, n_components
744 
745  if (word /= "SCALARS") then
746  print *, "line: ", trim(line)
747  error stop "read_vtk expects: SCALARS name type ncomponents"
748  end if
749 
750  if (n_components /= 1) error stop "read_vtk: ncomponents should be 1"
751 
752  ! LOOKUP_TABLE default
753  read(my_unit, *) word, typename
754 
755  if (word /= "LOOKUP_TABLE") then
756  print *, "line: ", trim(line)
757  error stop "read_vtk expects: LOOKUP_TABLE name"
758  end if
759 
760  ! Read list of data values
761  read(my_unit, *) tmp_data(:, :, :, n)
762  end do
763 
764  ! Done reading variables
765 900 continue
766 
767  close(my_unit)
768 
769  if (n == max_variables + 1) &
770  error stop "read_vtk: increase max_variables"
771 
772  ! Loop index is one higher than number of variables
773  bc%n_variables = n-1
774  bc%values = tmp_data(:, :, :, 1:n-1)
775  bc%names = tmp_names(1:n-1)
776  end subroutine read_vtk_structured_points
777 
778 end module mod_bc_data
Module to set boundary conditions from user data.
Definition: mod_bc_data.t:2
logical, public, protected interp_phy_first_row_same
Definition: mod_bc_data.t:33
subroutine read_vtk_structured_points(fname, bc)
Definition: mod_bc_data.t:666
character(len=std_len), public, protected boundary_data_file_name
data file name
Definition: mod_bc_data.t:31
elemental double precision function, public bc_data_get_2d(n_bc, x1, qt)
Definition: mod_bc_data.t:132
logical, public, protected bc_phy_first_row
Definition: mod_bc_data.t:34
subroutine bc_read_params(files)
Read this module"s parameters from a file.
Definition: mod_bc_data.t:104
logical, public, protected boundary_data_primitive
Definition: mod_bc_data.t:35
elemental double precision function, public bc_data_get_3d(n_bc, x1, x2, qt)
Definition: mod_bc_data.t:120
subroutine, public bc_data_set(qt, ixIL, ixOL, iB, w, x)
Set boundary conditions according to user data.
Definition: mod_bc_data.t:145
subroutine, public bc_data_init()
Definition: mod_bc_data.t:45
integer, dimension(:, :), allocatable, public, protected bc_data_ix
Integer array for indexing lookup tables per variable per direction.
Definition: mod_bc_data.t:28
logical, public, protected bc_data_time_varying
Whether boundary condition data is time varying.
Definition: mod_bc_data.t:25
logical, public, protected interp_phy_first_row
Definition: mod_bc_data.t:32
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: mod_comm_lib.t:208
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer, parameter unitpar
file handle for IO
integer, dimension(:, :), allocatable typeboundary
Array indicating the type of boundary condition per variable and per physical boundary.
integer, parameter ndim
Number of spatial dimensions for grid variables.
integer, parameter bc_data
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
integer, parameter bc_icarus
A Fortran 90 module for creating 1D and 2D lookup tables. These tables can be used to efficiently int...
type(lt2_t) function, public lt2_create_from_data(x_min, x_max, spaced_data)
This function returns a new lookup table from regularly spaced data.
type(lt_t) function, public lt_create_from_data(x_min, x_max, spaced_data)
This function returns a new lookup table from regularly spaced data.
type(lt3_t) function, public lt3_create_from_data(x_min, x_max, spaced_data)
This function returns a new lookup table from regularly spaced data.
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition: mod_physics.t:4
procedure(sub_convert), pointer phys_to_primitive
Definition: mod_physics.t:59
procedure(sub_convert), pointer phys_to_conserved
Definition: mod_physics.t:58