Ejemplo n.º 1
0
 def setUp(self):
     # Domain
     nx = ny = nz = 10
     mesh = fenics.RectangleMesh(fenics.Point(-2, -2), fenics.Point(2, 2),
                                 nx, ny)
     # function spaces
     displacement_element = fenics.VectorElement("Lagrange",
                                                 mesh.ufl_cell(), 1)
     concentration_element = fenics.FiniteElement("Lagrange",
                                                  mesh.ufl_cell(), 1)
     element = fenics.MixedElement(
         [displacement_element, concentration_element])
     subspace_names = {0: 'displacement', 1: 'concentration'}
     functionspace = FunctionSpace(mesh)
     functionspace.init_function_space(element, subspace_names)
     # build a 'solution' function
     u_0_conc_expr = fenics.Expression(
         'sqrt(pow(x[0]-x0,2)+pow(x[1]-y0,2)) < 0.1 ? (1.0) : (0.0)',
         degree=1,
         x0=0.25,
         y0=0.5)
     u_0_disp_expr = fenics.Constant((0.0, 0.0))
     self.U = functionspace.project_over_space(function_expr={
         0: u_0_disp_expr,
         1: u_0_conc_expr
     })
     self.tsd = TimeSeriesData(functionspace=functionspace, name='solution')
Ejemplo n.º 2
0
 def setUp(self):
     # Domain
     nx = ny = nz = 10
     self.mesh = fenics.RectangleMesh(fenics.Point(-2, -2),
                                      fenics.Point(2, 2), nx, ny)
     # function spaces
     self.displacement_element = fenics.VectorElement(
         "Lagrange", self.mesh.ufl_cell(), 1)
     self.concentration_element = fenics.FiniteElement(
         "Lagrange", self.mesh.ufl_cell(), 1)
     self.element = fenics.MixedElement(
         [self.displacement_element, self.concentration_element])
     subspace_names = {0: 'displacement', 1: 'concentration'}
     self.functionspace = FunctionSpace(self.mesh)
     self.functionspace.init_function_space(self.element, subspace_names)
     # subdomains
     label_funspace = fenics.FunctionSpace(self.mesh, "DG", 1)
     label_expr = fenics.Expression('(x[0]>=0) ? (1.0) : (2.0)', degree=1)
     labels = fenics.project(label_expr, label_funspace)
     self.labels = labels
     self.tissue_id_name_map = {0: 'outside', 1: 'tissue', 2: 'tumor'}
     self.parameter = {'outside': 0.0, 'tissue': 1.0, 'tumor': 0.1}
     self.boundary = Boundary()
     boundary_dict = {
         'boundary_1': self.boundary,
         'boundary_2': self.boundary
     }
     self.boundary_dict = boundary_dict
     self.subdomains = SubDomains(self.mesh)
     self.subdomains.setup_subdomains(label_function=self.labels)
     self.subdomains.setup_boundaries(tissue_map=self.tissue_id_name_map,
                                      boundary_fct_dict=self.boundary_dict)
     self.subdomains.setup_measures()
     # parameter instance
     self.params = Parameters(self.functionspace, self.subdomains)
Ejemplo n.º 3
0
    def test_project_over_subspace(self):
        from glimslib import fenics_local as fenics
        nx = ny = nz = 10
        mesh = fenics.RectangleMesh(fenics.Point(-2, -2), fenics.Point(2, 2),
                                    nx, ny)
        E1 = fenics.FiniteElement("Lagrange", mesh.ufl_cell(), 1)
        V1 = fenics.FunctionSpace(mesh, E1)
        E2 = fenics.VectorElement("Lagrange", mesh.ufl_cell(), 1)
        V2 = fenics.FunctionSpace(mesh, E2)
        expr_1 = fenics.Expression(
            ('exp(-a*pow(x[0]-x0, 2) - a*pow(x[1]-y0, 2))'),
            degree=1,
            a=1,
            x0=0.0,
            y0=0.0)
        expr_2 = fenics.Expression(('x[0]', 'x[1]'), degree=1)
        self.subspaces.set_functionspaces([V1, V2])
        f_1 = self.subspaces.project_over_subspace(expr_1, 0)
        if fenics.is_version("<2018.1.x"):
            self.assertEqual(type(f_1), fenics.functions.Function)
        else:
            self.assertEqual(type(f_1), fenics.function.function.Function)

        f_2 = self.subspaces.project_over_subspace(expr_2, 0)
        self.assertEqual(f_2, None)
        f_1 = self.subspaces.project_over_subspace(expr_1, 1)
        self.assertEqual(f_1, None)
        f_2 = self.subspaces.project_over_subspace(expr_2, 1)
        if fenics.is_version("<2018.1.x"):
            self.assertEqual(type(f_2), fenics.functions.Function)
        else:
            self.assertEqual(type(f_2), fenics.function.function.Function)
Ejemplo n.º 4
0
 def _setup_functionspace(self):
     displacement_element = fenics.VectorElement("Lagrange",
                                                 self.mesh.ufl_cell(), 1)
     concentration_element = fenics.FiniteElement("Lagrange",
                                                  self.mesh.ufl_cell(), 1)
     element = fenics.MixedElement(
         [displacement_element, concentration_element])
     subspace_names = {0: 'displacement', 1: 'concentration'}
     self.functionspace.init_function_space(element, subspace_names)
Ejemplo n.º 5
0
 def _setup_functionspace(self):
     """
     This is a test_cases implementation that needs to be overwritten.
     Any implementation of this function must initialize self.functionspace.
     """
     # Element definitions
     displacement_element = fenics.VectorElement("Lagrange",
                                                 self.mesh.ufl_cell(), 1)
     concentration_element = fenics.FiniteElement("Lagrange",
                                                  self.mesh.ufl_cell(), 1)
     element = fenics.MixedElement(
         [displacement_element, concentration_element])
     subspace_names = {0: 'displacement', 1: 'concentration'}
     # Initialisation of self.functionspace
     self.functionspace.init_function_space(element, subspace_names)
Ejemplo n.º 6
0
 def setUp(self):
     # Domain
     nx = ny = nz = 10
     self.nx, self.ny = nx, ny
     self.mesh = fenics.RectangleMesh(fenics.Point(-2, -2), fenics.Point(2, 2), nx, ny)
     # function spaces
     self.displacement_element = fenics.VectorElement("Lagrange", self.mesh.ufl_cell(), 1)
     self.concentration_element = fenics.FiniteElement("Lagrange", self.mesh.ufl_cell(), 1)
     self.element = fenics.MixedElement([self.displacement_element, self.concentration_element])
     subspace_names = {0: 'displacement', 1: 'concentration'}
     self.functionspace = FunctionSpace(self.mesh)
     self.functionspace.init_function_space(self.element, subspace_names)
     # define 'solution' with concentration=1 everywhere
     self.conc_expr =  fenics.Constant(1.0)
     self.conc = self.functionspace.project_over_space(self.conc_expr, subspace_name='concentration')
     # subdomains
     label_funspace = fenics.FunctionSpace(self.mesh, "DG", 1)
     label_expr = fenics.Expression('(x[0]>=0) ? (1.0) : (2.0)', degree=1)
     labels = fenics.project(label_expr, label_funspace)
     self.labels = labels
     self.tissue_id_name_map = {0: 'outside',
                                1: 'tissue',
                                2: 'tumor'}
     self.parameter = {'outside': 0.0,
                       'tissue': 1.0,
                       'tumor': 0.1}
     self.boundary_pos = BoundaryPos()
     self.boundary_neg = BoundaryNeg()
     boundary_dict = {'boundary_pos': self.boundary_pos,
                      'boundary_neg': self.boundary_neg}
     self.boundary_dict = boundary_dict
     self.subdomains = SubDomains(self.mesh)
     self.subdomains.setup_subdomains(label_function=self.labels)
     self.subdomains.setup_boundaries(tissue_map=self.tissue_id_name_map,
                                      boundary_fct_dict=self.boundary_dict)
     self.subdomains.setup_measures()
     # BCs
     self.bcs = BoundaryConditions(self.functionspace, self.subdomains)
     self.dirichlet_bcs = {'clamped_0': {'bc_value': fenics.Constant((0.0, 0.0)),
                                       'boundary': BoundaryPos(),
                                       'subspace_id': 0},
                           'clamped_1': {'bc_value': fenics.Constant((0.0, 0.0)),
                                         'subdomain_boundary': 'tissue_tumor',
                                         'subspace_id': 0},
                           'clamped_pos': {'bc_value': fenics.Constant((0.0, 0.0)),
                                         'named_boundary': 'boundary_pos',
                                         'subspace_id': 0},
                           'clamped_neg': {'bc_value': fenics.Constant((0.0, 0.0)),
                                         'named_boundary': 'boundary_neg',
                                         'subspace_id': 0}
                           }
     self.von_neuman_bcs = {
                            'flux_boundary_pos': {'bc_value': fenics.Constant(1.0),
                                        'named_boundary': 'boundary_pos',
                                        'subspace_id': 1},
                             'flux_boundary_neg': {'bc_value': fenics.Constant(-5.0),
                                                   'named_boundary': 'boundary_neg',
                                                   'subspace_id': 1}
                            # 'no_flux_domain_boundary': {'bc_value': fenics.Constant(1.0),
                            #               'subdomain_boundary': 'tissue_tumor',
                            #               'subspace_id': 1},
                           }
Ejemplo n.º 7
0
 def setUp(self):
     nx = ny = nz = 5
     self.mesh = fenics.RectangleMesh(fenics.Point(-2, -2), fenics.Point(2, 2), nx, ny)
     self.displacement_element = fenics.VectorElement("Lagrange", self.mesh.ufl_cell(), 1)
     self.concentration_element = fenics.FiniteElement("Lagrange", self.mesh.ufl_cell(), 1)
     self.element = fenics.MixedElement([self.displacement_element, self.concentration_element])