def setUp(self):
        # Domain
        nx = ny = nz = 10
        self.mesh = fenics.RectangleMesh(fenics.Point(-2, -2),
                                         fenics.Point(2, 2), nx, ny)
        self.sim = TumorGrowth(self.mesh)
        label_funspace = fenics.FunctionSpace(self.mesh, "DG", 1)
        label_expr = fenics.Expression('(x[0]>=0.5) ? (1.0) : (2.0)', degree=1)
        self.labels = fenics.project(label_expr, label_funspace)
        self.tissue_map = {0: 'outside', 1: 'tissue', 2: 'tumor'}
        boundary = Boundary()
        self.boundary_dict = {'boundary_1': boundary, 'boundary_2': boundary}
        self.dirichlet_bcs = {
            'clamped_0': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary': Boundary(),
                'subspace_id': 0
            },
            'clamped_1': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary_id': 0,
                'subspace_id': 0
            },
            'clamped_2': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary_name': 'boundary_1',
                'subspace_id': 0
            }
        }
        self.von_neuman_bcs = {
            'no_flux': {
                'bc_value': fenics.Constant(0.0),
                'boundary_id': 0,
                'subspace_id': 1
            },
            'no_flux_2': {
                'bc_value': fenics.Constant(0.0),
                'boundary_name': 'boundary_1',
                'subspace_id': 1
            },
        }
        self.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)
        self.u_0_disp_expr = fenics.Constant((0.0, 0.0))

        self.youngmod = {'outside': 10E6, 'tissue': 1, 'tumor': 1000}
        self.poisson = {'outside': 0.4, 'tissue': 0.4, 'tumor': 0.49}
        self.diffusion = {'outside': 0.0, 'tissue': 1.0, 'tumor': 0.1}
        self.prolif = {'outside': 0.0, 'tissue': 0.1, 'tumor': 1.0}
        self.coupling = {'outside': 0.0, 'tissue': 0.0, 'tumor': 0.5}
u_0_disp_expr = fenics.Constant((0.0, 0.0))

# model parameters
youngmod = {'outside': 10E6, 'A': 0.001, 'B': 0.001}
poisson = {'outside': 0.49, 'A': 0.40, 'B': 0.10}
diffusion = {'outside': 0.0, 'A': 0.1, 'B': 0.0}
prolif = {'outside': 0.0, 'A': 0.1, 'B': 0.0}
coupling = {'outside': 0.0, 'A': 0.2, 'B': 0.0}

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 5
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters(label_function=labels,
                            domain_names=tissue_map,
                            boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

ivs = {0: u_0_disp_expr, 1: u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                           diffusion=diffusion,
                           coupling=coupling,
                           proliferation=prolif,
                           E=youngmod,
                           poisson=poisson,
                           sim_time=sim_time,
Esempio n. 3
0
u_0_conc_expr = 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)
u_0_disp_expr = fenics.Expression(('0', '0'), degree=1)

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 10
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters(boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

ivs = {0: u_0_disp_expr, 1: u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                           diffusion=0.1,
                           coupling=1,
                           proliferation=0.1,
                           E=0.001,
                           poisson=0.4,
                           sim_time=sim_time,
                           sim_time_step=sim_time_step)
u_0_disp_expr = fenics.Constant((0.0, 0.0))

# model parameters
youngmod = {'outside': 10E6, 'A': 0.001, 'B': 0.001}
poisson = {'outside': 0.49, 'A': 0.40, 'B': 0.10}
diffusion = {'outside': 0.0, 'A': 0.1, 'B': 0.0}
prolif = {'outside': 0.0, 'A': 0.1, 'B': 0.0}
coupling = {'outside': 0.0, 'A': 0.2, 'B': 0.0}

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 10
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters(label_function=labels,
                            domain_names=tissue_map,
                            boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

ivs = {0: u_0_disp_expr, 1: u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                           diffusion=diffusion,
                           coupling=coupling,
                           proliferation=prolif,
                           E=youngmod,
                           poisson=poisson,
                           sim_time=sim_time,
Esempio n. 5
0
    a=0.5,
    x0=118,
    y0=-109,
    z0=72)
# u_0_conc_expr = fenics.Expression('sqrt(pow(x[0]-x0,2)+pow(x[1]-y0,2)+pow(x[2]-z0,2)) < 15 ? (1.0) : (0.0)',
#                                 degree=1, x0=118, y0=-109, z0=72)

u_0_disp_expr = fenics.Expression(('0.0', '0.0', '0.0'), degree=1)

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 5
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.projection_parameters = {'solver_type': 'cg', 'preconditioner_type': 'amg'}

sim.setup_global_parameters(subdomains=subdomains,
                            domain_names=tissue_id_name_map,
                            boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

youngmod = {
    'WM': 3000E-6,
    'GM': 3000E-6,
    'CSF': 1000E-6,
    'Ventricles': 1000E-6
}
                 }

# Initial Values
# 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.0, y0=0.0)
u_0_conc_expr = 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)

u_0_disp_expr = fenics.Constant((0.0, 0.0))

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 20
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters( boundaries=boundary_dict,
                             dirichlet_bcs=dirichlet_bcs,
                             von_neumann_bcs=von_neuman_bcs   )

ivs = {0:u_0_disp_expr, 1:u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                            diffusion=0.1,
                            coupling=1,
                            proliferation=0.1,
                            E=0.001,
                            poisson=0.45,
                            sim_time=sim_time, sim_time_step=sim_time_step)

# ==============================================================================
    a=0.5,
    x0=118,
    y0=-109,
    z0=72)
# u_0_conc_expr = fenics.Expression('sqrt(pow(x[0]-x0,2)+pow(x[1]-y0,2)+pow(x[2]-z0,2)) < 15 ? (1.0) : (0.0)',
#                                 degree=1, x0=118, y0=-109, z0=72)

u_0_disp_expr = fenics.Expression(('0.0', '0.0', '0.0'), degree=1)

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 50
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.projection_parameters = {'solver_type': 'cg', 'preconditioner_type': 'amg'}

sim.setup_global_parameters(subdomains=subdomains,
                            domain_names=tissue_id_name_map,
                            boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

youngmod = {
    'WM': 3000E-6,
    'GM': 3000E-6,
    'CSF': 1000E-6,
    'Ventricles': 1000E-6
}
prolif = {
    'outside': 0.0,
    'CSF': 0.0,
    'WM': rho_WM,
    'GM': rho_GM,
    'Ventricles': 0.0
}

coupling = 0.1

# ==============================================================================
# TumorGrowth
# ==============================================================================

sim_TG = TumorGrowth(mesh)

sim_TG.setup_global_parameters(label_function=labelfunction,
                               domain_names=tissue_id_name_map,
                               boundaries=boundary_dict,
                               dirichlet_bcs=dirichlet_bcs,
                               von_neumann_bcs=von_neuman_bcs)

sim_TG.setup_model_parameters(iv_expression=ivs,
                              diffusion=diffusion,
                              coupling=coupling,
                              proliferation=prolif,
                              E=youngmod,
                              poisson=poisson,
                              sim_time=sim_time,
                              sim_time_step=sim_time_step)
Esempio n. 9
0
u_0_conc_expr = 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)

u_0_disp_expr = fenics.Constant((0.0, 0.0))

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 5
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters(boundaries=boundary_dict,
                            dirichlet_bcs=dirichlet_bcs,
                            von_neumann_bcs=von_neuman_bcs)

ivs = {0: u_0_disp_expr, 1: u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                           diffusion=0.1,
                           coupling=1,
                           proliferation=0.1,
                           E=0.001,
                           poisson=0.45,
                           sim_time=sim_time,
                           sim_time_step=sim_time_step)
                 }

# Initial Values
# 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.0, y0=0.0)
u_0_conc_expr = 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)

u_0_disp_expr = fenics.Constant((0.0, 0.0))

# ==============================================================================
# Class instantiation & Setup
# ==============================================================================
sim_time = 20
sim_time_step = 1

sim = TumorGrowth(mesh)

sim.setup_global_parameters( boundaries=boundary_dict,
                             dirichlet_bcs=dirichlet_bcs,
                             von_neumann_bcs=von_neuman_bcs   )

ivs = {0:u_0_disp_expr, 1:u_0_conc_expr}
sim.setup_model_parameters(iv_expression=ivs,
                            diffusion=0.1,
                            coupling=1,
                            proliferation=0.1,
                            E=0.001,
                            poisson=0.45,
                            sim_time=sim_time, sim_time_step=sim_time_step)

# ==============================================================================
class TestBaseImplementation(TestCase):
    def setUp(self):
        # Domain
        nx = ny = nz = 10
        self.mesh = fenics.RectangleMesh(fenics.Point(-2, -2),
                                         fenics.Point(2, 2), nx, ny)
        self.sim = TumorGrowth(self.mesh)
        label_funspace = fenics.FunctionSpace(self.mesh, "DG", 1)
        label_expr = fenics.Expression('(x[0]>=0.5) ? (1.0) : (2.0)', degree=1)
        self.labels = fenics.project(label_expr, label_funspace)
        self.tissue_map = {0: 'outside', 1: 'tissue', 2: 'tumor'}
        boundary = Boundary()
        self.boundary_dict = {'boundary_1': boundary, 'boundary_2': boundary}
        self.dirichlet_bcs = {
            'clamped_0': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary': Boundary(),
                'subspace_id': 0
            },
            'clamped_1': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary_id': 0,
                'subspace_id': 0
            },
            'clamped_2': {
                'bc_value': fenics.Constant((0.0, 0.0)),
                'boundary_name': 'boundary_1',
                'subspace_id': 0
            }
        }
        self.von_neuman_bcs = {
            'no_flux': {
                'bc_value': fenics.Constant(0.0),
                'boundary_id': 0,
                'subspace_id': 1
            },
            'no_flux_2': {
                'bc_value': fenics.Constant(0.0),
                'boundary_name': 'boundary_1',
                'subspace_id': 1
            },
        }
        self.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)
        self.u_0_disp_expr = fenics.Constant((0.0, 0.0))

        self.youngmod = {'outside': 10E6, 'tissue': 1, 'tumor': 1000}
        self.poisson = {'outside': 0.4, 'tissue': 0.4, 'tumor': 0.49}
        self.diffusion = {'outside': 0.0, 'tissue': 1.0, 'tumor': 0.1}
        self.prolif = {'outside': 0.0, 'tissue': 0.1, 'tumor': 1.0}
        self.coupling = {'outside': 0.0, 'tissue': 0.0, 'tumor': 0.5}

    def test_setup_global_parameters(self):
        # subdomains from labels
        self.sim.setup_global_parameters(label_function=self.labels,
                                         domain_names=self.tissue_map,
                                         boundaries=self.boundary_dict,
                                         dirichlet_bcs=self.dirichlet_bcs,
                                         von_neumann_bcs=self.von_neuman_bcs)
        # subdomains
        self.assertTrue(hasattr(self.sim, 'subdomains'))
        self.assertTrue(hasattr(self.sim.subdomains, 'subdomain_boundaries'))
        # functionspaces
        self.assertTrue(hasattr(self.sim.functionspace, 'element'))
        self.assertTrue(hasattr(self.sim.functionspace, 'subspaces'))
        # boundary conditions
        self.assertTrue(hasattr(self.sim.bcs, 'dirichlet_bcs'))
        self.assertEqual(len(self.sim.bcs.dirichlet_bcs), 3)
        self.assertTrue(hasattr(self.sim.bcs, 'von_neumann_bcs'))
        self.assertEqual(len(self.sim.bcs.von_neumann_bcs), 2)

    def test_setup_model_parameters(self):
        self.sim.setup_global_parameters(label_function=self.labels,
                                         domain_names=self.tissue_map,
                                         boundaries=self.boundary_dict,
                                         dirichlet_bcs=self.dirichlet_bcs,
                                         von_neumann_bcs=self.von_neuman_bcs)
        ivs = {0: self.u_0_disp_expr, 1: self.u_0_conc_expr}
        self.sim.setup_model_parameters(iv_expression=ivs,
                                        diffusion=1,
                                        coupling=1,
                                        proliferation=1,
                                        E=self.params,
                                        poisson=self.params,
                                        otherparam=1,
                                        sim_time=10,
                                        sim_time_step=1)
        self.assertTrue(self.sim.params.get_iv(0), self.u_0_disp_expr)
        self.assertTrue(hasattr(self.sim.params, 'E'))
        self.assertFalse(hasattr(self.sim.params, 'otherparam'))