Esempio n. 1
0
        def callback_add_to_solution(q, qbc, ghostlayer_width, size_x, size_y, size_z, position_x, position_y, position_z, currentTime):
            dim = get_dimension( q )

            #TODO 3D: Adjust subdivision_factor to 3D
            # Set up grid information for current patch
            if dim is 2:
                subdivision_factor_x = q.shape[1]
                subdivision_factor_y = q.shape[2]
                unknowns_per_subcell = q.shape[0]
                dim_x = pyclaw.Dimension('x', position_x, position_x + size_x, subdivision_factor_x)
                dim_y = pyclaw.Dimension('y', position_y, position_y + size_y, subdivision_factor_y)

                patch = pyclaw.geometry.Patch((dim_x, dim_y))

            elif dim is 3:
                subdivision_factor_x = q.shape[1]
                subdivision_factor_y = q.shape[2]
                subdivision_factor_z = q.shape[3]
                unknowns_per_subcell = q.shape[0]
                dim_x = pyclaw.Dimension('x', position_x, position_x + size_x, subdivision_factor_x)
                dim_y = pyclaw.Dimension('y', position_y, position_y + size_y, subdivision_factor_y)
                dim_z = pyclaw.Dimension('z', position_z, position_z + size_z, subdivision_factor_z)
                
                patch = pyclaw.geometry.Patch((dim_x, dim_y,dim_z))

            state = pyclaw.State(patch, unknowns_per_subcell)
            state.q[:] = q[:]
            state.t = currentTime
            
            self.gathered_patches.append(patch)
            self.gathered_states.append(state)
Esempio n. 2
0
        def callback_initialization(q, qbc, aux, subdivision_factor_x0, subdivision_factor_x1, subdivision_factor_x2, unknowns_per_subcell, aux_fields_per_subcell, size_x, size_y, size_z, position_x, position_y, position_z):
            import clawpack.pyclaw as pyclaw

            dim = get_dimension(q)
            if dim is 2:
                self.dim_x = pyclaw.Dimension('x',position_x,position_x + size_x,subdivision_factor_x0)
                self.dim_y = pyclaw.Dimension('y',position_y,position_y + size_y,subdivision_factor_x1)
                domain = pyclaw.Domain([self.dim_x,self.dim_y])

            elif dim is 3:
                self.dim_x = pyclaw.Dimension('x',position_x,position_x + size_x,subdivision_factor_x0)
                self.dim_y = pyclaw.Dimension('y',position_y,position_y + size_y,subdivision_factor_x1)
                self.dim_z = pyclaw.Dimension('z',position_z,position_z + size_z,subdivision_factor_x2)
                domain = pyclaw.Domain([self.dim_x,self.dim_y,self.dim_z])

            subgrid_state = pyclaw.State(domain, unknowns_per_subcell, aux_fields_per_subcell)
            subgrid_state.q = q
            if(aux_fields_per_subcell > 0):
              subgrid_state.aux = aux
            subgrid_state.problem_data = self.solution.state.problem_data
            self.q_initialization(subgrid_state)
            if(self.aux_initialization != None and aux_fields_per_subcell > 0):
              self.aux_initialization(subgrid_state)
              
            #Steer refinement
            if not self.refinement_criterion == None:
              return self.refinement_criterion(subgrid_state)
            else:
              return self.initial_minimal_mesh_width
Esempio n. 3
0
    def __init__(self, solver, global_state, q, qbc, aux, position, size, subdivision_factor_x0, subdivision_factor_x1, subdivision_factor_x2, unknowns_per_cell, aux_fields_per_cell, current_time):
        r"""
        Initializes this subgrid solver. It get's all information to prepare a domain and state for a
        single subgrid. 
        
        :Input:
         -  *solver* - (:class:`pyclaw.Solver`) The PyClaw-solver used for advancing this subgrid in time.
         -  *global_state* - (:class:`pyclaw.State`) The global state. This is not the state used for
                            for the actual solving of the timestep on the subgrid.
         -  *q* - The array storing the current solution.
         -  *qbc* - The array storing the solution of the last timestep including the ghostlayer.
         -  *position* - A d-dimensional tuple holding the position of the grid in the computational domain.
                         This measures the continuous real-world position in floats, not the integer position 
                         in terms of cells. 
         -  *size* - A d-dimensional tuple holding the size of the grid in the computational domain. This
                     measures the continuous real-world size in floats, not the size in terms of cells.
         -  *subdivision_factor* - The number of cells in one dimension of this subgrid. At the moment only
                                    square subgrids are allowed, so the total number of cells in the subgrid
                                    (excluding the ghostlayer) is subdivision_factor x subdivision_factor.
         -  *unknowns_per_cell* - The number of equations or unknowns that are stored per cell of the subgrid.
        
        """
        self.solver = solver
        self.dimension = get_dimension(q)

        if self.dimension is 2:
            self.dim_x = pyclaw.Dimension('x',position[0],position[0] + size[0],subdivision_factor_x0)
            self.dim_y = pyclaw.Dimension('y',position[1],position[1] + size[1],subdivision_factor_x1)
            domain = pyclaw.Domain([self.dim_x,self.dim_y])
        elif self.dimension is 3:
            self.dim_x = pyclaw.Dimension('x',position[0],position[0] + size[0],subdivision_factor_x0)
            self.dim_y = pyclaw.Dimension('y',position[1],position[1] + size[1],subdivision_factor_x1)
            self.dim_z = pyclaw.Dimension('z',position[2],position[2] + size[2],subdivision_factor_x2)
            domain = pyclaw.Domain([self.dim_x,self.dim_y,self.dim_z])

        subgrid_state = pyclaw.State(domain, unknowns_per_cell, aux_fields_per_cell)
        subgrid_state.q = q
        subgrid_state.aux = aux
        subgrid_state.problem_data = global_state.problem_data
        self.solution = pyclaw.Solution(subgrid_state, domain)
        self.solution.t = current_time
        
        self.solver.bc_lower[0] = pyclaw.BC.custom
        self.solver.bc_upper[0] = pyclaw.BC.custom
        self.solver.bc_lower[1] = pyclaw.BC.custom
        self.solver.bc_upper[1] = pyclaw.BC.custom
        if self.dimension is 3:
            self.solver.bc_lower[2] = pyclaw.BC.custom
            self.solver.bc_upper[2] = pyclaw.BC.custom
        
        self.qbc = qbc
        self.solver.user_bc_lower = self.user_bc_lower
        self.solver.user_bc_upper = self.user_bc_upper
Esempio n. 4
0
    def setup(self, solution):
        r"""
        Initialize a Solver object. This method loads the library of Peano and prepares the initial mesh.
        
        See :class:`Solver` for full documentation
        """
        dim = get_dimension( solution.q )

        logging.getLogger('peanoclaw').info("Loading Peano-library...")
        self.libpeano = CDLL(self.get_lib_path(dim))
        logging.getLogger('peanoclaw').info("Peano loaded successfully.")
        self.libpeano.pyclaw_peano_new.restype = c_void_p
        self.libpeano.pyclaw_peano_destroy.argtypes = [c_void_p]
        self.libpeano.pyclaw_peano_evolveToTime.argtypes = [c_double, c_void_p, c_void_p, c_void_p]
        
        self.bc_lower = self.solver.bc_lower[:]
        self.bc_upper = self.solver.bc_upper[:]
        self.user_bc_lower = self.solver.user_bc_lower
        self.user_bc_upper = self.solver.user_bc_upper
        
        # Get parameters for Peano
        dimensions = solution.state.grid.dimensions
        subdivision_factor_x0 = solution.state.grid.dimensions[0].num_cells
        subdivision_factor_x1 = solution.state.grid.dimensions[1].num_cells

        if dim is 3:
            subdivision_factor_x2 = solution.state.grid.dimensions[2].num_cells 
        else:
            subdivision_factor_x2 = 0

        number_of_unknowns = solution.state.num_eqn 
        number_of_auxiliar_fields = solution.state.num_aux
        ghostlayer_width = self.num_ghost
        import os, sys
        configuration_file = os.path.join(sys.path[0], 'peanoclaw-config.xml')
        use_dimensional_splitting_optimization = self.solver.dimensional_split
          
        #self.solver.setup(solution)
        self.solution = solution
        
        if dim is 2:
            domain_position_x2 = 0
            domain_size_x2 = 0
        else:
            domain_position_x2 = dimensions[2].lower
            domain_size_x2 = dimensions[2].upper - dimensions[2].lower

        self.libpeano.pyclaw_peano_new.argtypes = [ c_double, #Initial mesh width
                                                    c_double, #Domain position X0
                                                    c_double, #Domain position X1
                                                    c_double, #Domain position X2
                                                    c_double, #Domain size X0
                                                    c_double, #Domain size X1
                                                    c_double, #Domain size X2
                                                    c_int,    #Subdivision factor X0
                                                    c_int,    #Subdivision factor X1
                                                    c_int,    #Subdivision factor X2
                                                    c_int,    #Number of unknowns
                                                    c_int,    #Number of auxiliar fields
                                                    c_int,    #Ghostlayer width
                                                    c_double, #Initial timestep size
                                                    c_char_p, #Config file
                                                    c_bool,   #Use dimensional splitting
                                                    c_void_p, #q Initialization callback
                                                    c_void_p, #Boundary condition callback
                                                    c_void_p] #Solver callback
        self.peano = self.libpeano.pyclaw_peano_new(c_double(self.initial_minimal_mesh_width),
                                                    c_double(dimensions[0].lower),
                                                    c_double(dimensions[1].lower),
                                                    c_double(domain_position_x2),
                                                    c_double(dimensions[0].upper - dimensions[0].lower),
                                                    c_double(dimensions[1].upper - dimensions[1].lower),
                                                    c_double(domain_size_x2),
                                                    subdivision_factor_x0,
                                                    subdivision_factor_x1,
                                                    subdivision_factor_x2,
                                                    number_of_unknowns,
                                                    number_of_auxiliar_fields,
                                                    ghostlayer_width,
                                                    self.solver.dt_initial,
                                                    c_char_p(configuration_file),
                                                    use_dimensional_splitting_optimization,
                                                    self.initialization_callback,
                                                    self.boundary_condition_callback,
                                                    self.solver_callback)
        
        # Set PeanoSolution
        import clawpack.peanoclaw as peanoclaw
        if(isinstance(solution, peanoclaw.Solution)):
            solution.peano = self.peano
            solution.libpeano = self.libpeano
        else:
            logging.getLogger('peanoclaw').warning("Use peanoclaw.Solution instead of pyclaw.Solution together with peanoclaw.Solver to provide plotting functionality.")
        
        #Causes Ctrl+C to quit Peano
        signal.signal(signal.SIGINT, signal.SIG_DFL)