示例#1
0
文件: core.py 项目: meawoppl/ndsolver
    def setup_dof_cache_faster(self, s_filename):
        from tables import openFile
        self.dbprint("BIG MODE! Setting up DOF Cache")
        # Should only be run by cpu 0!
        if self.myID != 0: 
            raise RuntimeError("Only thread 0 should setup dof cache!")

        # Open the file to copy S from
        self.dbprint("Opening h5 file to read solid")
        source_h5 = openFile(s_filename)
        S = source_h5.root.geometry.S[:]
        self.dbprint("Success!", 3)
        shape = S.shape
        ndim = len(shape)

        # Write Memory Maps
        self.dbprint("Writing memmap files.")
        shape_map = memmap("shape.mem",    dtype="int64", mode='w+', shape=tuple([ndim]))
        s_memmap  =  memmap("S.mem",       dtype="int64", mode='w+', shape=shape)
        p_memmap  =  memmap("P.mem",       dtype="int64", mode='w+', shape=shape)
        v_memmaps = [memmap("V%i.mem" % x, dtype="int64", mode='w+', shape=shape) for x in range(ndim)]

        self.dbprint("Assigning Values.")

        # Assign the shape
        shape_map[:] = array(shape).astype(int64)[:]
        self.dbprint("Shape Done.")
        
        # Assign S
        s_memmap[:] = S[:].astype(int64)
        self.dbprint("S Done.")

        # Assign P's
        p_memmap[:] = ndim_eq.p_dof(S).astype(int64)
        self.dbprint("P Done.")

        # Assign V's
        for axis, v_mmap in enumerate(v_memmaps):
            v_mmap[:] = ndim_eq.velocity_dof(S, axis).astype(int64)
        self.dbprint("VS Done.")
        self.dbprint("Loaded Maps . . .  Flushing.")
        # Flush All to disk.
        shape_map.flush()
        s_memmap.flush()
        p_memmap.flush()
        [v_mmap.flush() for v_mmap in v_memmaps]

        source_h5.close()
        self.dbprint("\tDone Constructing memory mapped files.")
示例#2
0
文件: core.py 项目: meawoppl/ndsolver
    def __init__(self, solid_or_filename, dP, sol_method = "default", printing = False, dbcallback = None ):
        # Log the starting time
        self.start_time = time.time()

	# Set debugging flag
        self.printlevel = printing
        self.dbcallback = dbcallback

        # Trilinos setup and iteration requires very different programmatic flow . . . 
        self.using_trilinos = ( sol_method == "trilinos")

        # Trilinos communicator between threads . . .
        if self.using_trilinos:
            # Epetra Imported Here and all vectors defined
            from PyTrilinos import Epetra 
            self.Comm = Epetra.PyComm()    
            self.myID = self.Comm.MyPID()
            self.cpuCount = self.Comm.NumProc()
            self.dbprint("Trilinos Inititated: %s" % gethostname())
        else:
            # Only one thread
            self.myID = 0
            self.cpuCount = 1

        self.dbprint("Solver Instantiated", level = 2)
        
        # Default direction of pressure drop
        self.dP = dP

        # I left this in here so you can manually 
        # disable Biot number based acceleration if desired
        self.useBi = True  

        if sol_method == "default":
            self.method = "spsolve"
        else:
            self.method = sol_method

        # Iteration count
        self.I = 0

        ################################################################
        # Solver Internal Stuff ## Degree of Freedom Grids and Numbers #
        ################################################################
        
        # the ndarray of solid
        if hasattr(solid_or_filename, "shape"):
            self.S = solid_or_filename
            self.shape = self.S.shape
            self.ndim  = len(self.S.shape)

            # Pressure (cell centered)
            # Get the P degrees of freedom
            self.P_dof_grid = ndim_eq.p_dof( self.S )

            # Velocities (face centered)
            self.vel_dof_grids = ndim_eq.velocity_dofs( self.S )
            self.bigMode = False

        elif type(solid_or_filename) == str:
            if self.myID == 0:
                self.setup_dof_cache_faster(solid_or_filename)
            
            self.sync()
            self.dbprint("Waiting for cached file to flush to disk.")
            time.sleep(1)
            self.sync()

            self.import_dof_cache()
            self.bigMode = True

        self.P_dof_num  = self.P_dof_grid.max() + 1
        self.vel_dof_nums  = [int(grid.max() + 1) for grid in self.vel_dof_grids]
        self.sync("DOF Config Completion Sync")

        self.la_is_setup = False
        self.bc_is_setup = False