def __init__(self, fun, n, name="material_parameters"): """ Initialize Mixed parameter. This will instanciate a function in a dolfin.MixedFunctionSpace consiting of `n` subspaces of the same type as `fun`. This is of course easy for the case when `fun` is a normal dolfin function, but in the case of a `RegionalParameter` it is not that straight forward. This class handles this case as well. :param fun: The type of you want to make a du :type fun: (:py:class:`dolfin.Function`) :param int n: number of subspaces :param str name: Name of the function .. todo:: Implement support for MixedParameter with different types of subspaces, e.g [RegionalParamter, R_0, CG_1] """ msg = "Please provide a dolin function as argument to MixedParameter" assert isinstance(fun, (dolfin.Function, Function, RegionalParameter)), msg if isinstance(fun, RegionalParameter): raise NotImplementedError # We can just make a usual mixed function space # with n copies of the original one V = fun.function_space() W = dolfin.MixedFunctionSpace([V] * n) Function.__init__(self, W, name=name) # Create a function assigner self.function_assigner = [ FunctionAssigner(W.sub(i), V) for i in range(n) ] # Store the original function space self.basespace = V if isinstance(fun, RegionalParameter): self._meshfunction = fun._meshfunction
def __init__(self, meshfunction): # assert isinstance( # meshfunction, dolfin.MeshFunctionSizet # ), "Invalid meshfunction for regional gamma" mesh = meshfunction.mesh() # FIXME self._values = set(numpy_mpi.gather_broadcast(meshfunction.array())) self._nvalues = len(self._values) V = dolfin.VectorFunctionSpace(mesh, "R", 0, dim=self._nvalues) Function.__init__(self, V) self._meshfunction = meshfunction # Functionspace for the indicator functions self._proj_space = dolfin.FunctionSpace(mesh, "DG", 0) # Make indicator functions self._ind_functions = [] for v in self._values: self._ind_functions.append(self._make_indicator_function(v))