Changeset 3229

Show
Ignore:
Timestamp:
08/14/09 15:43:49 (8 months ago)
Author:
wd15
Message:

Revamped the parallel module to be a class in tools/init.py. This allows it to be pickled
as module objects cannot be pickled. Introduced a serial module that always has serial info.
The 2D grid meshes now take the parallel or serial objects, which indicate whether the mesh
should be built in a parallel or serial manner. The mesh needs to be able to pickle this
information, hence the needfor a parallel and serial class.

Location:
branches/parallel/fipy
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • branches/parallel/fipy/meshes/cylindricalGrid2D.py

    r2781 r3229  
    3333 ## 
    3434 
     35from fipy.tools import parallel 
    3536 
    36 def CylindricalGrid2D(dr=None, dz=None, nr=None, nz=None, dx=1., dy=1., nx=None, ny=None): 
     37def CylindricalGrid2D(dr=None, dz=None, nr=None, nz=None, dx=1., dy=1., nx=None, ny=None, parallelModule=parallel): 
    3738    from numMesh import cylindricalUniformGrid2D 
    3839    from numMesh import cylindricalGrid2D 
     
    5556     
    5657    if numerix.getShape(dx) == () and numerix.getShape(dy) == (): 
    57         return cylindricalUniformGrid2D.CylindricalUniformGrid2D(dx=dx, dy=dy, nx=nx or 1, ny=ny or 1) 
     58        return cylindricalUniformGrid2D.CylindricalUniformGrid2D(dx=dx, dy=dy, nx=nx or 1, ny=ny or 1, parallelModule=parallelModule) 
    5859    else: 
    59         return cylindricalGrid2D.CylindricalGrid2D(dx=dx, dy=dy, nx=nx, ny=ny) 
     60        return cylindricalGrid2D.CylindricalGrid2D(dx=dx, dy=dy, nx=nx, ny=ny, parallelModule=parallelModule) 
  • branches/parallel/fipy/meshes/numMesh/cylindricalGrid2D.py

    r3156 r3229  
    4343from fipy.meshes.numMesh.grid2D import Grid2D 
    4444from fipy.tools.dimensions.physicalField import PhysicalField 
     45from fipy.tools import parallel 
    4546 
    4647class CylindricalGrid2D(Grid2D): 
     
    4950    first and then vertical faces. 
    5051    """ 
    51     def __init__(self, dx=1., dy=1., nx=None, ny=None, origin=((0.,), (0.,)), overlap=2): 
     52    def __init__(self, dx=1., dy=1., nx=None, ny=None, origin=((0.,), (0.,)), overlap=2, parallelModule=parallel): 
    5253        scale = PhysicalField(value=1, unit=PhysicalField(value=dx).getUnit()) 
    5354        self.origin = PhysicalField(value=origin) 
    5455        self.origin /= scale 
    5556         
    56         Grid2D.__init__(self, dx=dx, dy=dy, nx=nx, ny=ny, overlap=overlap) 
     57        Grid2D.__init__(self, dx=dx, dy=dy, nx=nx, ny=ny, overlap=overlap, parallelModule=parallelModule) 
    5758 
    5859 
  • branches/parallel/fipy/meshes/numMesh/cylindricalUniformGrid2D.py

    r3154 r3229  
    4040from fipy import numerix 
    4141from fipy.meshes.numMesh.uniformGrid2D import UniformGrid2D 
     42from fipy.tools import parallel 
    4243 
    4344class CylindricalUniformGrid2D(UniformGrid2D): 
     
    4647    appropriate for axial symmetry. 
    4748    """ 
    48     def __init__(self, dx=1., dy=1., nx=1, ny=1, origin=((0,),(0,)), overlap=2): 
    49         UniformGrid2D.__init__(self, dx=dx, dy=dy, nx=nx, ny=ny, origin=origin, overlap=overlap) 
     49    def __init__(self, dx=1., dy=1., nx=1, ny=1, origin=((0,),(0,)), overlap=2, parallelModule=parallel): 
     50        UniformGrid2D.__init__(self, dx=dx, dy=dy, nx=nx, ny=ny, origin=origin, overlap=overlap, parallelModule=parallelModule) 
    5051 
    5152    def _getAreaProjections(self): 
  • branches/parallel/fipy/meshes/numMesh/grid1D.py

    r3147 r3229  
    9292         
    9393    def _calcParallelGridInfo(self, nx, overlap): 
    94         from fipy.tools.parallel import procID, Nproc 
     94        from fipy.tools import parallel 
     95        procID = parallel.procID 
     96        Nproc = parallel.Nproc 
    9597         
    9698        overlap = min(overlap, nx) 
  • branches/parallel/fipy/meshes/numMesh/grid2D.py

    r3216 r3229  
    4343from fipy.tools import vector 
    4444from fipy.tools.dimensions.physicalField import PhysicalField 
     45from fipy.tools import parallel 
    4546 
    4647class Grid2D(Mesh2D): 
     
    4950    first and then vertical faces. 
    5051    """ 
    51     def __init__(self, dx=1., dy=1., nx=None, ny=None, overlap=2): 
     52    def __init__(self, dx=1., dy=1., nx=None, ny=None, overlap=2, parallelModule=parallel): 
     53         
    5254        self.args = { 
    5355            'dx': dx,  
     
    5557            'nx': nx,  
    5658            'ny': ny,  
    57             'overlap': overlap 
     59            'overlap': overlap, 
     60            'parallelModule': parallelModule 
    5861        } 
    59      
     62 
    6063        self.dx = PhysicalField(value = dx) 
    6164        scale = PhysicalField(value=1, unit=self.dx.getUnit()) 
     
    7578         self.ny, 
    7679         self.overlap, 
    77          self.offset) = self._calcParallelGridInfo(nx, ny, overlap) 
     80         self.offset) = self._calcParallelGridInfo(nx, ny, overlap, parallelModule) 
    7881 
    7982        if numerix.getShape(self.dx) is not (): 
     
    104107        self.setScale(value = scale) 
    105108 
    106     def _getParallelInfo(self): 
    107         from fipy.tools.parallel import procID, Nproc 
    108         return procID, Nproc 
    109          
    110     def _calcParallelGridInfo(self, nx, ny, overlap): 
    111         procID, Nproc = self._getParallelInfo() 
    112          
     109    def _calcParallelGridInfo(self, nx, ny, overlap, parallelModule): 
     110         
     111        procID = parallelModule.procID 
     112        Nproc = parallelModule.Nproc 
     113 
    113114        overlap = min(overlap, ny) 
    114115        cellsPerNode = max(int(ny / Nproc), overlap) 
  • branches/parallel/fipy/meshes/numMesh/uniformGrid2D.py

    r3216 r3229  
    4343from fipy.tools.dimensions.physicalField import PhysicalField 
    4444from fipy.tools import inline 
     45from fipy.tools import parallel 
    4546 
    4647class UniformGrid2D(Grid2D): 
     
    4950    first and then vertical faces. 
    5051    """ 
    51     def __init__(self, dx=1., dy=1., nx=1, ny=1, origin=((0,),(0,)), overlap=2): 
     52    def __init__(self, dx=1., dy=1., nx=1, ny=1, origin=((0,),(0,)), overlap=2, parallelModule=parallel): 
    5253        self.args = { 
    5354            'dx': dx,  
     
    5657            'ny': ny,  
    5758            'origin': origin, 
    58             'overlap': overlap 
     59            'overlap': overlap, 
     60            'parallelModule': parallelModule 
    5961        } 
    60      
     62 
    6163        self.dim = 2 
    6264         
     
    7880         self.ny, 
    7981         self.overlap, 
    80          self.offset) = self._calcParallelGridInfo(nx, ny, overlap) 
     82         self.offset) = self._calcParallelGridInfo(nx, ny, overlap, parallelModule) 
    8183         
    8284        self.origin = PhysicalField(value = origin) 
     
    115117        return self.__class__(dx = self.dx, nx = self.nx,  
    116118                              dy = self.dy, ny = self.ny,  
    117                               origin = self.origin + vector) 
     119                              origin = self.origin + vector, 
     120                              parallelModule=self.args['parallelModule']) 
    118121 
    119122    def __mul__(self, factor): 
  • branches/parallel/fipy/models/levelSet/electroChem/gapFillMesh.py

    r3216 r3229  
    9595         
    9696        ## Build the fine region mesh. 
    97         from fipy.meshes.numMesh.serialUniformGrid2D import SerialUniformGrid2D 
    98         self.fineMesh = SerialUniformGrid2D(nx = nx, ny = ny, dx = cellSize, dy = cellSize) 
     97        from fipy.tools import serial 
     98        self.fineMesh = Grid2D(nx = nx, ny = ny, dx = cellSize, dy = cellSize, parallelModule=serial) 
    9999 
    100100        ## Build the transition mesh and displace. 
     
    103103        ## Build the boundary layer mesh. 
    104104 
    105         boundaryLayerMesh = SerialUniformGrid2D(dx = actualDomainWidth, 
    106                                                 dy = actualDomainWidth, 
    107                                                 nx = 1, 
    108                                                 ny = numberOfBoundaryLayerCells) + ((0,), (self.actualFineRegionHeight + transitionRegionHeight,)) 
    109  
    110  
     105        boundaryLayerMesh = Grid2D(dx = actualDomainWidth, 
     106                                   dy = actualDomainWidth, 
     107                                   nx = 1, 
     108                                   ny = numberOfBoundaryLayerCells, 
     109                                   parallelModule=serial) + ((0,), (self.actualFineRegionHeight + transitionRegionHeight,),) 
     110                                                                                     
    111111        ## Add the meshes together. 
    112112        mesh = self.fineMesh._concatenate(transitionMesh, self.epsilon) 
  • branches/parallel/fipy/terms/diffusionTerm.py

    r3130 r3229  
    364364           >>> from fipy.meshes.grid1D import Grid1D 
    365365           >>> from fipy.tools.pysparseMatrix import _PysparseMatrix as SparseMatrix 
    366            >>> from fipy.tools.parallel import procID 
     366           >>> from fipy.tools import parallel 
     367           >>> procID = parallel.procID 
    367368           >>> mesh = Grid1D(dx = 1., nx = 2) 
    368369           >>> term = DiffusionTerm(coeff = (1,)) 
  • branches/parallel/fipy/tools/__init__.py

    r3113 r3229  
     1class Parallel: 
     2    try: 
     3 
     4        try: 
     5            import scipy 
     6        except: 
     7            pass 
     8 
     9        from PyTrilinos import Epetra 
     10 
     11        procID = Epetra.PyComm().MyPID() 
     12        Nproc = Epetra.PyComm().NumProc() 
     13    except ImportError: 
     14        procID = 0 
     15        Nproc = 1 
     16 
     17class Serial: 
     18    procID = 0 
     19    Nproc = 1 
     20 
     21parallel = Parallel() 
     22serial = Serial() 
    123import dump 
    224import numerix 
    3 import parallel 
    425import vector 
    526from dimensions.physicalField import PhysicalField 
    627from numerix import * 
    7