diff --git a/code/code_gen/post.py b/code/code_gen/post.py index 6d38021..fdd3aa5 100644 --- a/code/code_gen/post.py +++ b/code/code_gen/post.py @@ -349,13 +349,22 @@ integer(kind=MPI_INTEGER_KIND) :: {field_name}_info ! - buffer real*8, allocatable, dimension(:,:,:) :: {field_name}_export_array +integer, allocatable, dimension(:) :: {field_name}_xpts ''' fmt_init=''' ! init call MPI_INFO_CREATE({field_name}_info, mpi_err) call MPI_FILE_OPEN(MPI_COMM_TASK,'export-{field_name}.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err) -allocate({field_name}_export_array({xs}:{xe},{ys}:{ye},{zs}:{ze}), stat=ierr) ; {field_name}_export_array = 0. +allocate({field_name}_export_array(1:{len_xpts},{ys}:{ye},{zs}:{ze}), stat=ierr) ; {field_name}_export_array = 0. +allocate({field_name}_xpts(1:{len_xpts}), stat=ierr) +{xpts_init} +''' + + fmt_xpts_init=''' +do i = {xs}, {xe} +{field_name}_xpts(i-{xs}+1) = i +end do ''' fmt_final=''' @@ -363,20 +372,21 @@ allocate({field_name}_export_array({xs}:{xe},{ys}:{ye},{zs}:{ze}), stat=ierr) ; call MPI_FILE_CLOSE({field_name}_fh, mpi_err) call MPI_INFO_FREE({field_name}_info, mpi_err) deallocate({field_name}_export_array) +deallocate({field_name}_xpts) ''' fmt_calc=''' ! copy to array for export do k = {zs}, {ze} do j = {ys}, {ye} -do i = {xs}, {xe} -{field_name}_export_array(i,j,k) = {work_array}(i,j,k) +do i = 1, {len_xpts} +{field_name}_export_array(i,j,k) = {work_array}({field_name}_xpts(i),j,k) end do end do end do ! write to file -count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) +count = ({len_xpts}) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) offset = export_offset(fidx) * count * 8 call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) ''' @@ -398,6 +408,22 @@ call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count self.params.setdefault("field_name", self.name) + self.params.setdefault("len_xpts", "({xe} - {xs} + 1)".format(**self.params)) + self.params.setdefault("xpts_init", FieldExporter.fmt_xpts_init.format(**self.params)) + + try: + # Sampling at listed x coordinates + fmt_xpts_init_list = "{field_name}_xpts = (/ {list_xpts} /)" + + import sys + raw_xpts = self.params["xpts"] + int_xpts = map(int, raw_xpts.split()) + len_xpts = len(int_xpts) + self.params["len_xpts"] = len_xpts + self.params["list_xpts"] = ",".join(map(str, int_xpts)) + self.params["xpts_init"] = fmt_xpts_init_list.format(**self.params) + except KeyError: + pass def code (self): diff --git a/code/code_gen/resources/m_template.py b/code/code_gen/resources/m_template.py index 18745d9..3d2ef83 100644 --- a/code/code_gen/resources/m_template.py +++ b/code/code_gen/resources/m_template.py @@ -14,6 +14,7 @@ contains subroutine m_{0[module_name]}_init integer :: ierr +integer :: i, j, k {0[module_init]} diff --git a/code/termspecs/termspec.pdf-sampling-ic1 b/code/termspecs/termspec.pdf-sampling-ic1 index 3258355..5f5f849 100644 --- a/code/termspecs/termspec.pdf-sampling-ic1 +++ b/code/termspecs/termspec.pdf-sampling-ic1 @@ -5,7 +5,7 @@ # field_name (arg_name=arg (, pair)* ) = expression -c (export=true, xs=176, xe=400) = 1.0 - y +c (export=true, xs=176, xe=400, xpts="200 220 240 260 280 300") = 1.0 - y fsd (export=true, xs=176, xe=400) = sqrt (sqr(ddx(c)) + sqr(ddy(c)) + sqr(ddz(c)))