diff --git a/code/code_gen/post.py b/code/code_gen/post.py index ecb271f..526757c 100644 --- a/code/code_gen/post.py +++ b/code/code_gen/post.py @@ -235,41 +235,50 @@ real*8, allocatable, dimension(:,:,:) :: {field_name}_export_array fmt_init=''' ! init -! call MPI_INFO_CREATE({field_name}_info, mpi_err) -! call MPI_FILE_OPEN(MPI_COMM_TASK,{field_name}_fname,MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err) -! allocate({field_name}_export_array({1}), stat=ierr) ; {field_name}_export_array = 0. +call MPI_INFO_CREATE({field_name}_info, mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'{field_name}-export.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. ''' fmt_final=''' ! finalize -! call MPI_FILE_CLOSE({field_name}_fh, mpi_err) -! call MPI_INFO_FREE({field_name}_info, mpi_err) -! deallocate({field_name}_export_array) +call MPI_FILE_CLOSE({field_name}_fh, mpi_err) +call MPI_INFO_FREE({field_name}_info, mpi_err) +deallocate({field_name}_export_array) ''' fmt_calc=''' ! copy to array for export ! do k = 1, nzp ! do j = 1, nyp -! do i = {}, {} -! {}(i,j,k) = {}(i,j,k) +! do i = {x_start}, {x_end} +! {field_name}_export_array(i,j,k) = {work_array}(i,j,k) ! end do ! end do ! end do -! after calculate -! count = {x1-x0+1} * ny * nz -! offset = time_count * count -! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_buffer, count, MPI_REAL8, mpi_status, mpi_err) +! write to file +! count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) +! offset = {itime} * count +! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) ''' def __init__ (self, name, attr, parent): self.name = name self.attr = attr self.parent = parent - self.x0 = attr["x0"] - self.x1 = attr["x1"] - self.xslice = "{}:{},ny,nz".format(self.x0, self.x1) + # self.xslice = "{}:{},ny,nz".format(self.x0, self.x1) + + self.params = dict(attr) + + self.params.setdefault("xs", 1) + self.params.setdefault("xe", "nxp") + self.params.setdefault("ys", 1) + self.params.setdefault("ye", "nyp") + self.params.setdefault("zs", 1) + self.params.setdefault("ze", "nzp") + + self.params.setdefault("field_name", self.name) def code (self): @@ -277,13 +286,13 @@ real*8, allocatable, dimension(:,:,:) :: {field_name}_export_array return FieldExporter.fmt_calc # real_array_loop.format((self.array, rhs), self.comment) def code_decl (self): - return FieldExporter.fmt_decl.format(field_name=self.name) + return FieldExporter.fmt_decl.format(**self.params) def code_alloc (self): - return FieldExporter.fmt_init # real_array_alloc.format(self.name, self.shape) + return FieldExporter.fmt_init.format(**self.params) def code_free (self): - return FieldExporter.fmt_final # real_array_free.format(self.name) + return FieldExporter.fmt_final.format(**self.params) diff --git a/code/code_gen/terms.input b/code/code_gen/terms.input index 4daf6ee..277294e 100644 --- a/code/code_gen/terms.input +++ b/code/code_gen/terms.input @@ -10,6 +10,6 @@ nx = - ddx(c) / fsd ny = - ddy(c) / fsd nz = - ddz(c) / fsd -divn (export=true, x0=128, x1=320) = ddx(nx) + ddy(ny) + ddz(nz) +divn (export=true, xs=176, xe=400) = ddx(nx) + ddy(ny) + ddz(nz) avg { c, fsd, divn } diff --git a/code/m_terms.f90 b/code/m_terms.f90 index 9fdb607..05a6c8d 100644 --- a/code/m_terms.f90 +++ b/code/m_terms.f90 @@ -41,9 +41,9 @@ allocate(avg_fsd(nxp), stat=ierr) ; avg_fsd = 0. allocate(avg_divn(nxp), stat=ierr) ; avg_divn = 0. ! init -! call MPI_INFO_CREATE({field_name}_info, mpi_err) -! call MPI_FILE_OPEN(MPI_COMM_TASK,{field_name}_fname,MPI_MODE_WRONLY+MPI_MODE_CREATE,{field_name}_info,{field_name}_fh,mpi_err) -! allocate({field_name}_export_array({1}), stat=ierr) ; {field_name}_export_array = 0. +call MPI_INFO_CREATE(divn_info, mpi_err) +call MPI_FILE_OPEN(MPI_COMM_TASK,'divn-export.dat',MPI_MODE_WRONLY+MPI_MODE_CREATE,divn_info,divn_fh,mpi_err) +allocate(divn_export_array(176:400,1:nyp,1:nzp), stat=ierr) ; divn_export_array = 0. allocate(xyzbuffer0(nxp,nyp,nzp), stat=ierr) ; xyzbuffer0 = 0. allocate(xyzbuffer1(nxp,nyp,nzp), stat=ierr) ; xyzbuffer1 = 0. @@ -61,9 +61,9 @@ deallocate(avg_fsd) deallocate(avg_divn) ! finalize -! call MPI_FILE_CLOSE({field_name}_fh, mpi_err) -! call MPI_INFO_FREE({field_name}_info, mpi_err) -! deallocate({field_name}_export_array) +call MPI_FILE_CLOSE(divn_fh, mpi_err) +call MPI_INFO_FREE(divn_info, mpi_err) +deallocate(divn_export_array) deallocate(xyzbuffer0) deallocate(xyzbuffer1) @@ -165,16 +165,16 @@ end do ! copy to array for export ! do k = 1, nzp ! do j = 1, nyp -! do i = {}, {} -! {}(i,j,k) = {}(i,j,k) +! do i = {x_start}, {x_end} +! {field_name}_export_array(i,j,k) = {work_array}(i,j,k) ! end do ! end do ! end do -! after calculate -! count = {x1-x0+1} * ny * nz -! offset = time_count * count -! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_buffer, count, MPI_REAL8, mpi_status, mpi_err) +! write to file +! count = ({xe} - {xs} + 1) * ({ye} - {ys} + 1) * ({ze} - {zs} + 1) +! offset = {itime} * count +! call MPI_FILE_WRITE_AT({field_name}_fh, offset, {field_name}_export_array, count, MPI_REAL8, mpi_status, mpi_err) do k = 1, nzp