diff --git a/sources/mesh.F90 b/sources/mesh.F90 index fb4d570..1f5bbcd 100644 --- a/sources/mesh.F90 +++ b/sources/mesh.F90 @@ -43,27 +43,36 @@ module mesh integer , save :: imi, ims, img, imu, ima, imp, imr #endif /* PROFILE */ -! file handler for the mesh statistics +! the handler of the mesh statistics file ! integer, save :: funit = 11 -! flag indicating that the block structure or distribution has changed +! the size of the common workspace +! + integer, save :: nwork = 0 + +! the flag indicating that the workspace is in use +! + logical, save :: work_in_use = .false. + +! the flag indicating that the block structure or distribution has changed ! logical, save :: changed = .true. -! dimensions of the temporary array used in the block prolongation +! the dimensions of the temporary array used in the block prolongation ! integer, dimension(3), save :: pm = 1 -! by default everything is private +! the common workspace to use for local arrays ! + real(kind=8), dimension(:), allocatable, target :: work + private -! declare public subroutines -! public :: initialize_mesh, finalize_mesh public :: generate_mesh, update_mesh public :: redistribute_blocks, store_mesh_stats + public :: work, work_in_use !- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! @@ -91,8 +100,12 @@ module mesh ! subroutine initialize_mesh(nrun, status) - use coordinates, only : ni => ncells, ng => nghosts, toplev - use mpitools , only : master, nprocs + use coordinates , only : nn => bcells, ni => ncells, ng => nghosts + use coordinates , only : toplev + use equations , only : nf + use iso_fortran_env, only : error_unit + use mpitools , only : master, nprocs + use parameters , only : get_parameter implicit none @@ -102,6 +115,8 @@ module mesh character(len=64) :: fn integer :: l, n + character(len=*), parameter :: loc = 'MESH::initialize_mesh()' + !------------------------------------------------------------------------------- ! #ifdef PROFILE @@ -158,10 +173,24 @@ module mesh end if ! master -! prepare dimensions of the prolongation array +! prepare the dimensions of the prolongation array ! pm(1:NDIMS) = 2 * (ni + ng) +! get the requested size of the workspace +! + call get_parameter('workspace_size', nwork) + nwork = max(nwork, (2 * NDIMS + 1) * nf * nn**NDIMS) + +! allocate the workspace +! + allocate(work(nwork), stat=status) + + if (status /= 0) then + write(error_unit,"('[',a,']: ',a)") trim(loc) & + , "Cannot allocate the common workspace!" + end if + #ifdef PROFILE call stop_timer(imi) #endif /* PROFILE */ @@ -201,6 +230,8 @@ module mesh if (master) close(funit) + if (allocated(work)) deallocate(work) + #ifdef PROFILE call stop_timer(imi) #endif /* PROFILE */