From 472865bb69b94fdbc304dd36f74a9a0458e0cce8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 23 Jun 2010 15:57:49 +0200 Subject: [PATCH] Started to work on grid partitioning --- eplf.config | 1 + scripts/eplf_edit.py | 128 +++++++++++++++++++++++++++----------- src/compute.irp.f | 2 +- src/ezfio_interface.irp.f | 1 + src/grid.irp.f | 86 ++++++++++++------------- src/main.irp.f | 18 +++--- 6 files changed, 144 insertions(+), 92 deletions(-) diff --git a/eplf.config b/eplf.config index b34853c..920c11c 100644 --- a/eplf.config +++ b/eplf.config @@ -63,4 +63,5 @@ compute density logical density_grad logical density_lapl logical + elf_partition logical diff --git a/scripts/eplf_edit.py b/scripts/eplf_edit.py index ee44a7f..da32b93 100755 --- a/scripts/eplf_edit.py +++ b/scripts/eplf_edit.py @@ -14,6 +14,39 @@ import tempfile editor = os.getenv("EDITOR",default="vi") +## Data cleaning +################## + +class Cleaner(object): + def __init__(self,inp,name): + self.dir = inp.name + self.name = name.lower() + self.inp = inp + def action(self): + raise TypeError + def clean(self): + print "Removing "+self.name + self.action() + +class GridDataCleaner(Cleaner): + def action(self): + os.system("rm -f %s/grid_data/%s.gz"%(self.dir,self.name) ) + +class AllCleaner(Cleaner): + def action(self): + os.system("rm -rf %s/grid"%(self.dir) ) + os.system("rm -rf %s/grid_data"%(self.dir) ) + +def clear(x,inp): + d = { "all": AllCleaner, + } + if x in d.keys(): + type = d[x] + else: + type = GridDataCleaner + + type(inp,x.replace("_"," ")).clean() + ## Data editing ############### @@ -70,29 +103,29 @@ class GridEditor(Editor): self.opposite = self.inp.opposite self.step_size = self.inp.step_size self.point_num = self.inp.point_num - if self.origin is None: - self.origin = [ 0., 0., 0. ] - for l in xrange(3): - self.origin[l] = self.inp.nucl_coord[l][1] - for i in self.inp.nucl_coord[l]: - self.origin[l] = min(self.origin[l],i) - self.origin[l] -= 4. - if self.opposite is None: - self.opposite = [ 0., 0., 0. ] - for l in xrange(3): - self.opposite[l] = self.inp.nucl_coord[l][1] - for i in self.inp.nucl_coord[l]: - self.opposite[l] = max(self.opposite[l],i) - self.opposite[l] += 4. - if self.step_size is None: - self.step_size = [ 0., 0., 0. ] - for l in xrange(3): - self.step_size[l] = (self.opposite[l] - self.origin[l])/float(self.point_num[l]) +# if self.origin is None: +# self.origin = [ 0., 0., 0. ] +# for l in xrange(3): +# self.origin[l] = self.inp.nucl_coord[l][1] +# for i in self.inp.nucl_coord[l]: +# self.origin[l] = min(self.origin[l],i) +# self.origin[l] -= 4. +# if self.opposite is None: +# self.opposite = [ 0., 0., 0. ] +# for l in xrange(3): +# self.opposite[l] = self.inp.nucl_coord[l][1] +# for i in self.inp.nucl_coord[l]: +# self.opposite[l] = max(self.opposite[l],i) +# self.opposite[l] += 4. +# if self.step_size is None: +# self.step_size = [ 0., 0., 0. ] +# for l in xrange(3): +# self.step_size[l] = (self.opposite[l] - self.origin[l])/float(self.point_num[l]) - self.inp.point_num = self.point_num - self.inp.origin = self.origin - self.inp.opposite = self.opposite - self.inp.step_size = self.step_size +# self.inp.point_num = self.point_num +# self.inp.origin = self.origin +# self.inp.opposite = self.opposite +# self.inp.step_size = self.step_size edit_temp_file(self.inp,self.write_grid_file,self.read_grid_file) def write_grid_file(self,file,inp): @@ -101,33 +134,49 @@ class GridEditor(Editor): print >>file, "###########################" print >>file, "" print >>file, "# Number of points along x, y, z" - print >>file, "%d %d %d"%tuple(self.point_num) + if self.point_num is None: + print >>file, "Default" + else: + print >>file, "%d %d %d"%tuple(self.point_num) print >>file, "" print >>file, "# Coordinates of the origin (x,y,z)" - print >>file, "%f %f %f"%tuple(self.origin) + if self.origin is None: + print >>file, "Default" + else: + print >>file, "%f %f %f"%tuple(self.origin) print >>file, "" print >>file, "# Coordinates of the opposite point (x,y,z)" - print >>file, "%f %f %f"%tuple(self.opposite) + if self.opposite is None: + print >>file, "Default" + else: + print >>file, "%f %f %f"%tuple(self.opposite) print >>file, "" print >>file, "# Step sizes (x,y,z)" - print >>file, "%f %f %f"%tuple(self.step_size) + if self.step_size is None: + print >>file, "Default" + else: + print >>file, "%f %f %f"%tuple(self.step_size) def read_grid_file(self,file,inp): lines = file.readlines() lines = filter(lambda x: len(x.strip())>0,lines) lines = filter(lambda x: not x.startswith("#"),lines) - buffer = lines.pop(0).split() - self.inp.point_num = map(int,buffer) + buffer = lines.pop(0).lower().split() + if buffer[0] != "default": + self.inp.point_num = map(int,buffer) - buffer = lines.pop(0).split() - self.inp.origin = map(float,buffer) + buffer = lines.pop(0).lower().split() + if buffer[0] != "default": + self.inp.origin = map(float,buffer) - buffer = lines.pop(0).split() - self.inp.opposite = map(float,buffer) + buffer = lines.pop(0).lower().split() + if buffer[0] != "default": + self.inp.opposite = map(float,buffer) - buffer = lines.pop(0).split() - self.inp.step_size = self.step_size + buffer = lines.pop(0).lower().split() + if buffer[0] != "default": + self.inp.step_size = self.step_size @@ -150,9 +199,15 @@ def write_main_file(file,inp): print >>file, '# edit(geometry)' print >>file, '# edit(grid_parameters)' print >>file, "" + compute = filter(lambda x: x.startswith("compute"),rw_data) + print >>file, "# Clear" + print >>file, "# --------------------\n" + print >>file, '# clear(all)' + for p in compute: + print >>file, '# clear(%s)'%(p[8:]) + print >>file, "" print >>file, "# Computation" print >>file, "# --------------------\n" - compute = filter(lambda x: x.startswith("compute"),rw_data) compute = filter(lambda x: not x.endswith("_grad"),compute) compute = filter(lambda x: not x.endswith("_lapl"),compute) for p in compute: @@ -177,7 +232,8 @@ def read_main_file(file,inp): line = line.replace("(x) ","=True inp.compute_") buffer = line.split() line = ' '.join([buffer[1].lower(),buffer[0]]) - elif line.startswith("edit"): + elif line.startswith("edit") \ + or line.startswith("clear"): line = line.replace("(","('").replace(")","',inp)").lower() exec line diff --git a/src/compute.irp.f b/src/compute.irp.f index 49a4267..0d23769 100644 --- a/src/compute.irp.f +++ b/src/compute.irp.f @@ -19,5 +19,5 @@ SUBST [ X ] density;; density_grad;; density_lapl;; - + elf_partition;; END_TEMPLATE diff --git a/src/ezfio_interface.irp.f b/src/ezfio_interface.irp.f index d4b8e5c..02adf26 100644 --- a/src/ezfio_interface.irp.f +++ b/src/ezfio_interface.irp.f @@ -30,6 +30,7 @@ data = [ \ ("compute_density" , "logical" , "" ), ("compute_density_grad" , "logical" , "" ), ("compute_density_lapl" , "logical" , "" ), +("compute_elf_partition" , "logical" , "" ), ("grid_data_eplf" , "real" , "(grid_x_num,grid_y_num,grid_z_num)" ), ("grid_data_eplf_grad" , "real" , "(grid_x_num,grid_y_num,grid_z_num,4)" ), ("grid_data_eplf_lapl" , "real" , "(grid_x_num,grid_y_num,grid_z_num)" ), diff --git a/src/grid.irp.f b/src/grid.irp.f index 5970d69..af5f31a 100644 --- a/src/grid.irp.f +++ b/src/grid.irp.f @@ -81,6 +81,13 @@ BEGIN_PROVIDER [ real, grid_$X, (grid_x_num,grid_y_num,grid_z_num) ] integer :: ix, iy, iz integer :: ibegin, iend + real, parameter :: UNDEFINED=123456789.123456789 + + grid_$X(1,1,1) = UNDEFINED + call get_grid_data_$X(grid_$X) + if (grid_$X(1,1,1) /= UNDEFINED) then + return + endif do iz=1,grid_z_num do iy=1,grid_y_num @@ -114,60 +121,27 @@ BEGIN_PROVIDER [ real, grid_$X, (grid_x_num,grid_y_num,grid_z_num) ] enddo IRP_IF MPI -! integer :: dim, ierr -! do iz=1,grid_z_num -! real :: buffer(grid_x_num*grid_y_num+1) -! icount = 0 -! do iy=1,grid_y_num -! do ix=1,grid_x_num -! buffer(icount+ix) = grid_$X(ix,iy,iz) -! enddo -! icount = icount + grid_x_num -! enddo -! dim = grid_x_num * grid_y_num -! call MPI_REDUCE(buffer,grid_$X(1,1,iz),dim,mpi_real, & -! mpi_sum,0,MPI_COMM_WORLD,ierr) -! if (ierr /= MPI_SUCCESS) then -! call abrt(irp_here,'Unable to fetch buffer') -! endif -! call barrier -! enddo - -! integer :: dim, ierr -! real :: buffer(grid_x_num*grid_y_num*grid_z_num) -! icount = 0 -! do iz=1,grid_z_num -! do iy=1,grid_y_num -! do ix=1,grid_x_num -! buffer(icount+ix) = grid_$X(ix,iy,iz) -! enddo -! icount = icount + grid_x_num -! enddo -! enddo -! dim = grid_x_num * grid_y_num * grid_y_num -! call MPI_REDUCE(buffer,grid_$X,dim,mpi_real, & -! mpi_sum,0,MPI_COMM_WORLD,ierr) -! if (ierr /= MPI_SUCCESS) then -! call abrt(irp_here,'Unable to fetch buffer') -! endif - integer :: dim, ierr - dim = grid_x_num do iz=1,grid_z_num - real :: buffer(grid_x_num) + real :: buffer(grid_x_num*grid_y_num+1) + icount = 0 do iy=1,grid_y_num do ix=1,grid_x_num - buffer(ix) = grid_$X(ix,iy,iz) + buffer(icount+ix) = grid_$X(ix,iy,iz) enddo - call MPI_REDUCE(buffer,grid_$X(1,iy,iz),dim,mpi_real, & - mpi_sum,0,MPI_COMM_WORLD,ierr) - if (ierr /= MPI_SUCCESS) then - call abrt(irp_here,'Unable to fetch buffer') - endif - call barrier + icount = icount + grid_x_num enddo + dim = grid_x_num * grid_y_num + call MPI_REDUCE(buffer,grid_$X(1,1,iz),dim,mpi_real, & + mpi_sum,0,MPI_COMM_WORLD,ierr) + if (ierr /= MPI_SUCCESS) then + call abrt(irp_here,'Unable to fetch buffer') + endif + call barrier enddo + IRP_ENDIF + call set_grid_data_$X(grid_$X) END_PROVIDER @@ -188,6 +162,13 @@ END_PROVIDER integer :: ix, iy, iz, it integer :: ibegin, iend + real, parameter :: UNDEFINED=123456789.123456789 + + grid_$X_lapl(1,1,1) = UNDEFINED + call get_grid_data_$X_lapl(grid_$X) + if (grid_$X_lapl(1,1,1) /= UNDEFINED) then + return + endif do iz=1,grid_z_num do iy=1,grid_y_num @@ -256,6 +237,8 @@ END_PROVIDER enddo enddo IRP_ENDIF + call set_grid_data_$X_grad(grid_$X_grad) + call set_grid_data_$X_lapl(grid_$X_lapl) END_PROVIDER @@ -265,3 +248,14 @@ SUBST [ X ] density;; END_TEMPLATE + +IRP_IF caca +BEGIN_PROVIDER [ integer, grid_partition_$X, (grid_x_num,grid_y_num,grid_z_num) ] + implicit none + BEGIN_DOC +! Create the topological partition of $X + END_DOC + +END_PROVIDER +IRP_ENDIF + diff --git a/src/main.irp.f b/src/main.irp.f index b38f416..c31ad0c 100644 --- a/src/main.irp.f +++ b/src/main.irp.f @@ -3,34 +3,34 @@ program eplf provide mpi_rank if (comp_eplf) then - call set_grid_data_eplf(grid_eplf) + PROVIDE grid_eplf FREE grid_eplf endif if (comp_eplf_grad.or.comp_eplf_lapl) then - call set_grid_data_eplf_grad(grid_eplf_grad) - call set_grid_data_eplf_lapl(grid_eplf_lapl) + PROVIDE grid_eplf_grad + PROVIDE grid_eplf_lapl FREE grid_eplf_grad FREE grid_eplf_lapl endif if (comp_elf) then - call set_grid_data_elf(grid_elf) + PROVIDE grid_elf FREE grid_elf endif if (comp_elf_grad.or.comp_elf_lapl) then - call set_grid_data_elf_grad(grid_elf_grad) - call set_grid_data_elf_lapl(grid_elf_lapl) + PROVIDE grid_elf_grad + PROVIDE grid_elf_lapl FREE grid_elf_grad FREE grid_elf_lapl endif if (comp_density) then - call set_grid_data_density(grid_density) + PROVIDE grid_density FREE grid_density endif if (comp_density_grad.or.comp_density_lapl) then - call set_grid_data_density_grad(grid_density_grad) - call set_grid_data_density_lapl(grid_density_lapl) + PROVIDE grid_density_grad + PROVIDE grid_density_lapl FREE grid_density_grad FREE grid_density_lapl endif