def definalize(self): if self.finalized: self._finalized = False else: LOG.warning("This Solution is not finalized.")
def __init__(self, *args, **kwargs): """ Parameters ---------- rhs_function_wrt_space : :py:class:`callable` function returning the space-dependent values for the right hand side as used by the space solver boundaries : :py:class:`None` or :py:class:`list` of :py:class:`str` *(optional)* defaults to ``periodic`` for each dimension boundary_functions : :py:class:`None` or :py:class:`list` of :py:class:`callable` *(optional)* functions defined on the boundaries of the geometry geometry : :py:class:`None` or :py:class:`numpy.ndarray` *(optional)* specifying the dimension and extend of the geometry """ assert_is_instance(self, IProblem, message="This Mixin is only valid for IProblems.", checking_obj=self) assert_named_argument('rhs_function_wrt_space', kwargs, descriptor="RHS for space solver", checking_obj=self) assert_is_callable(kwargs['rhs_function_wrt_space'], descriptor="RHS for space solver", checking_obj=self) self._rhs_function_wrt_space = kwargs['rhs_function_wrt_space'] # check if boundary conditions are specified if kwargs.get('boundaries') is None: self._boundaries = ['periodic'] * len(self.spacial_dim) elif isinstance(kwargs['boundaries'], str) \ and kwargs['boundaries'] in MultigridProblemMixin.valid_boundary_conditions: self._boundaries = [kwargs['boundaries']] * len(self.spacial_dim) elif isinstance(kwargs['boundaries'], list): check = 0 for bc in kwargs['boundaries']: if bc in MultigridProblemMixin.valid_boundary_conditions: check += 1 if check == len(self.spacial_dim) * 2: self._boundaries = kwargs['boundaries'] else: LOG.warning('Boundary specifications are not valid, will use periodic boundaries for each dimension.') self._boundaries = ['periodic'] * len(self.spacial_dim) else: LOG.warning('Boundary specifications are not valid, will use periodic boundaries for each dimension') self._boundaries = ['periodic'] * len(self.spacial_dim) # assign according to the boundary conditions the right functions if kwargs.get('boundary_functions') is None: self._boundary_functions = [None] * len(self.spacial_dim) else: assert_is_instance(kwargs['boundary_functions'], list, descriptor="Boundary Functions", checking_obj=self) check = 0 assert_condition(len(kwargs['boundary_functions']) == len(self.spacial_dim), ValueError, message="Not enough boundary functions given.", checking_obj=self) for ftpls in kwargs['boundary_functions']: if ftpls is 'dirichlet': assert_is_instance(ftpls, list, message="Dirichlet function list not available", checking_obj=self) assert_condition(len(ftpls) == 2, ValueError, message="Wrong number of functions", checking_obj=self) assert_is_callable(ftpls[0], "Not a function", self) assert_is_callable(ftpls[1], "Not a function", self) check += 1 self._boundary_functions = kwargs['boundary_functions'] # construct or save the geometry if kwargs.get('geometry') is None: self._geometry = np.asarray([[0, 1]] * len(self.spacial_dim)) else: assert_is_instance(kwargs['geometry'], np.ndarray, descriptor="Geometry", checking_obj=self) assert_condition(len(kwargs["geometry"].shape) == 2, ValueError, message="Numpy array has the wrong dimensions", checking_obj=self) assert_condition(kwargs['geometry'].shape[0] == len(self.spacial_dim) and kwargs['geometry'].shape[1] == 2, ValueError, message="Numpy array has a wrong shape", checking_obj=self) self._geometry = kwargs['geometry'] self._rhs_space_operators = {} self._implicit_solve_method = kwargs.get('implicit_solve_method', 'direct') self._mg_core = None # the Space tensor which is actually used self._act_space_tensor = None self._act_grid_distances = None # the points actually used self._act_npoints = None