예제 #1
0
 def test_limit_conductivity_true(self):
     """
     Test that the problem does inherit from ConductivityLimiterMixin
     if limit_conductivity is true.
     """
     klass = problem.create_problem_class(limit_conductivity=True)
     self.assertTrue(issubclass(klass, ConductivityLimiterMixin))
예제 #2
0
 def test_limit_flux_true(self):
     """
     Test that the problem does inherit from FluxLimiterMixin if
     limit_flux is true.
     """
     klass = problem.create_problem_class(limit_flux=True)
     self.assertTrue(issubclass(klass, FluxLimiterMixin))
예제 #3
0
 def test_limit_conductivity_false(self):
     """
     Test that the problem does not inherit from ConductivityLimiterMixin
     if limit_conductivity is false.
     """
     klass = problem.create_problem_class(limit_conductivity=False)
     self.assertFalse(issubclass(klass, ConductivityLimiterMixin))
예제 #4
0
 def test_constant_ionisation_true(self):
     """
     Test that the problem does inherit from ConstantIonisationSHCMixin if
     constant_ionisation is true.
     """
     klass = problem.create_problem_class(constant_ionisation=True)
     self.assertTrue(issubclass(klass, ConstantIonisationSHCMixin))
예제 #5
0
 def test_limit_flux_false(self):
     """
     Test that the problem does not inherit from FluxLimiterMixin if
     limit_flux is false.
     """
     klass = problem.create_problem_class(limit_flux=False)
     self.assertFalse(issubclass(klass, FluxLimiterMixin))
예제 #6
0
 def test_sh_conductivity_true(self):
     """
     Test that the problem does inherit from SpitzerHarmMixin if
     sh_conductivity is true.
     """
     klass = problem.create_problem_class(sh_conductivity=True)
     self.assertTrue(issubclass(klass, SpitzerHarmMixin))
예제 #7
0
 def test_constant_ionisation_false(self):
     """
     Test that the problem does inherits from NonConstantIonisationSHCMixin
     if constant_ionisation is false.
     """
     klass = problem.create_problem_class(constant_ionisation=False)
     self.assertTrue(issubclass(klass, NonConstantIonisationSHCMixin))
예제 #8
0
 def test_sh_conductivity_false(self):
     """
     Test that the problem does not inherit from SpitzerHarmMixin if
     sh_conductivity is false.
     """
     klass = problem.create_problem_class(sh_conductivity=False)
     self.assertFalse(issubclass(klass, SpitzerHarmMixin))
예제 #9
0
 def test_time_dep_true(self):
     """
     Test that the problem does inherit from TimeMixin if time_dep is
     true.
     """
     klass = problem.create_problem_class(time_dep=True)
     self.assertTrue(issubclass(klass, TimeMixin))
예제 #10
0
 def test_time_dep_false(self):
     """
     Test that the problem does not inherit from TimeMixin if time_dep is
     false.
     """
     klass = problem.create_problem_class(time_dep=False)
     self.assertFalse(issubclass(klass, TimeMixin))
예제 #11
0
 def test_is_problem(self):
     """
     Test that the returned class is a subclass of Problem.
     """
     klass = problem.create_problem_class()
     self.assertTrue(issubclass(klass, problem.Problem))
     self.assertTrue(issubclass(klass, BoundaryMixin))
예제 #12
0
 def test_mix(self):
     """
     Test that a mix of settings has all the required functionality.
     """
     klass = problem.create_problem_class(time_dep=True,
                                          sh_conductivity=True,
                                          constant_ionisation=False,
                                          limit_flux=False,
                                          limit_conductivity=True)
     self.assertTrue(issubclass(klass, TimeMixin))
     self.assertTrue(issubclass(klass, SpitzerHarmMixin))
     self.assertTrue(issubclass(klass, NonConstantIonisationSHCMixin))
     self.assertFalse(issubclass(klass, FluxLimiterMixin))
     self.assertTrue(issubclass(klass, ConductivityLimiterMixin))
예제 #13
0
"""
Tests for the solver.py file.
"""
import os
import unittest
from tempfile import TemporaryDirectory

import numpy as np
from firedrake import (Constant, FunctionSpace, SpatialCoordinate,
                       UnitCubeMesh, UnitIntervalMesh, pi, sin)

from TTiP.core.problem import create_problem_class
from TTiP.core.solver import Solver

SimpleSteadyState = create_problem_class(time_dep=False,
                                         sh_conductivity=False,
                                         limit_flux=False,
                                         limit_conductivity=False)
SimpleTimeDep = create_problem_class(time_dep=True,
                                     sh_conductivity=False,
                                     limit_flux=False,
                                     limit_conductivity=False)


# pylint: disable=protected-access
class TestSolve(unittest.TestCase):
    """
    Tests for the solve method.
    """
    def setUp(self):
        """
        Setup the mesh and function space.
예제 #14
0
def run(config_file, debug=False):
    """
    Run the solve on the given problem definition config file.

    Args:
        config_file (string): The path to the config file to run.
        debug (bool, optional): Print debug output. Defaults to False.
    """
    # pylint: disable=too-many-locals
    logger = setup_logger(debug=debug)

    logger.info('Running TTiP on %s', config_file)
    config = Config(config_file)

    logger.info('Setting up the problem.')
    start_time = time.time()
    logger.debug('Building mesh..')
    # Setup mesh and function space
    mesh, V = config.get_mesh()

    # Get parameters
    params = config.get_parameters()
    constant_ionisation = 'ionisation' in params

    logger.debug('Setting timescales..')
    # Set up timescale
    steps, dt, max_t = config.get_time()
    time_dep = (steps is not None or dt is not None or max_t is not None)

    limit_conductivity, limit_flux = config.get_physics_settings()

    ProblemClass = create_problem_class(
        time_dep=time_dep,
        sh_conductivity=True,
        constant_ionisation=constant_ionisation,
        limit_flux=limit_flux,
        limit_conductivity=limit_conductivity)

    problem = ProblemClass(mesh, V)

    if time_dep:
        problem.set_timescale(steps=steps, dt=dt, max_t=max_t)

    # Set up parameters
    ignored = []
    for name, value in params.items():
        try:
            problem.set_function(name, value)
        except AttributeError:
            ignored.append(name)

    if ignored:
        logger.info('Ignoring unnecesary parameters: %s', ', '.join(ignored))

    logger.debug('Building sources..')
    # Set up source
    source = config.get_sources()
    problem.set_function('S', source)

    logger.debug('Building boundary conditions..')
    # Set up boundary conditions
    bcs = config.get_boundary_conds()
    for bc in bcs:
        problem.add_boundary(**bc)
    if not bcs:
        problem.set_no_boundary()

    logger.debug('Building initial value..')
    # Set up initial value
    initial_val = config.get_initial_val()
    problem.T.assign(initial_val)

    logger.info('Problem set up (%.1fs)', time.time() - start_time)
    logger.info('Running the solve.')
    start_time = time.time()

    # Solve
    file_path, method, params = config.get_solver_params()
    try:
        problem.set_method(method, **params)
    except AttributeError:
        pass

    solver = Solver(problem)
    solver.solve(file_path=file_path)
    logger.info('Success (%.1fs) - Results are stored in: %s',
                time.time() - start_time, file_path)