Пример #1
0
def run_problem(real, imag, max_iter, num_steps, num_nodes, criteria, task, num_tasks, n_procs, starttime):
    _width = len(str(num_tasks))
    _percent = float(task) / float(num_tasks) * 100
    _diff_time = time.time() - starttime
    _time_epsilon = 0.1
    if task > n_procs \
            and ((_diff_time > 8.0 and
                  ((_diff_time % 10.0) < _time_epsilon) or ((10.0 - (_diff_time % 10.0)) < _time_epsilon))
                 or (num_tasks % 2 == 0 and _percent % 4 == 0)
                 or (num_tasks % 2 != 0 and _percent % 4 == 0)):
        print("[ {:6.2f}%] Starting task {:{width}d} of {:{width}d}: \\lambda = {: .3f}{:+.3f}i"
              .format(_percent, task, num_tasks, real, imag, width=_width))

    base_integrator = SdcIntegrator()
    base_integrator.init(num_nodes=num_nodes)

    intermediate_integrator = SdcIntegrator()
    intermediate_integrator.init(num_nodes=(2 * num_nodes - 1))

    # fine_integrator = SdcIntegrator()
    # fine_integrator.init(num_nodes=(num_nodes + 4))

    transitioner1 = TimeTransitionProvider(fine_nodes=intermediate_integrator.nodes, coarse_nodes=base_integrator.nodes)
    # transitioner2 = TimeTransitionProvider(fine_nodes=fine_integrator.nodes, coarse_nodes=intermediate_integrator.nodes)

    ml_provider = MultiTimeLevelProvider()
    # ml_provider.add_coarse_level(fine_integrator)
    ml_provider.add_coarse_level(intermediate_integrator)
    ml_provider.add_coarse_level(base_integrator)
    ml_provider.add_level_transition(transitioner1, 0, 1)
    # ml_provider.add_level_transition(transitioner2, 1, 2)

    problem = LambdaU(lmbda=complex(real, imag))
    check = ThresholdCheck(min_threshold=1e-12, max_threshold=max_iter,
                           conditions=('residual', 'iterations'))

    comm = ForwardSendingMessaging()
    solver = MlSdc(communicator=comm)
    comm.link_solvers(previous=comm, next=comm)
    comm.write_buffer(tag=(ml_provider.num_levels - 1), value=problem.initial_value, time_point=problem.time_start)

    solver.init(problem=problem, ml_provider=ml_provider, threshold=check)
    try:
        solution = solver.run(SemiImplicitMlSdcCore, dt=(problem.time_end - problem.time_start))
        return int(solution[-1].used_iterations)
        # print("####======> %s -> %s" % (solution[-1].error(-1)[-1].value, linalg.norm(solution[-1].error(-1)[-1].value)))
        # return two_norm(solution[-1].error(-1)[-1].value)
    except RuntimeError:
        return max_iter + 1
Пример #2
0
class SdcIntegratorTest(NumpyAwareTestCase):
    def setUp(self):
        self._test_obj = SdcIntegrator()

    def test_s_and_q_matrix_computation_default_interval(self):
        self._test_obj.init(num_nodes=3)
        computed_smat = self._test_obj._smat
        expected_smat = numpy.array(
            [
                [0.416666666666667, 0.666666666666667, -0.0833333333333335],
                [-0.0833333333333333, 0.666666666666667, 0.416666666666667]
            ]
        )
        self.assertNumpyArrayAlmostEqual(computed_smat, expected_smat, delta=1e-8)

    def test_q_matrix_computation_default_interval(self):
        self._test_obj.init(num_nodes=3)
        computed_qmat = self._test_obj._qmat
        expected_qmat = numpy.array(
            [
                [0.0, 0.0, 0.0],
                [0.416666666666667, 0.666666666666667, -0.0833333333333335],
                [float(1.0/3.0), float(4.0/3.0), float(1.0/3.0)]
            ]
        )
        self.assertNumpyArrayAlmostEqual(computed_qmat, expected_qmat, delta=1e-8)

    def test_s_matrix_computation_0_to_1_interval(self):
        self._test_obj.init(num_nodes=3, interval=numpy.array([0.0, 1.0]))
        computed_smat = self._test_obj._smat
        expected_smat = numpy.array(
            [
                [0.208333333333333, 0.333333333333334, -0.0416666666666667],
                [-0.0416666666666667, 0.333333333333333, 0.208333333333333]
            ]
        )
        self.assertNumpyArrayAlmostEqual(computed_smat, expected_smat, delta=1e-8)

    def test_q_matrix_computation_0_to_1_interval(self):
        self._test_obj.init(num_nodes=3, interval=numpy.array([0.0, 1.0]))
        computed_qmat = self._test_obj._qmat
        expected_qmat = numpy.array(
            [
                [0.0, 0.0, 0.0],
                [0.208333333333333, 0.333333333333334, -0.0416666666666667],
                [0.166666666666667, 0.666666666666667, 0.1666666666666667]
            ]
        )
        self.assertNumpyArrayAlmostEqual(computed_qmat, expected_qmat, delta=1e-8)
Пример #3
0
# coding: utf-8
from warnings import simplefilter
simplefilter('always')

from pypint.multi_level_providers.multi_time_level_provider import MultiTimeLevelProvider
from pypint.multi_level_providers.level_transition_providers.time_transition_provider import TimeTransitionProvider
from pypint.integrators.sdc_integrator import SdcIntegrator

base_integrator = SdcIntegrator()
base_integrator.init(num_nodes=3)
# print(base_integrator)

intermediate_integrator = SdcIntegrator()
intermediate_integrator.init(num_nodes=5)
# print(intermediate_integrator)

# fine_integrator = SdcIntegrator()
# fine_integrator.init(num_nodes=7)
# print(fine_integrator)

transitioner1 = TimeTransitionProvider(fine_nodes=intermediate_integrator.nodes, coarse_nodes=base_integrator.nodes)
# print(transitioner1)
# transitioner2 = TimeTransitionProvider(fine_nodes=fine_integrator.nodes, coarse_nodes=intermediate_integrator.nodes)
# print(transitioner2)

ml_provider = MultiTimeLevelProvider()
# ml_provider.add_coarse_level(fine_integrator)
ml_provider.add_coarse_level(intermediate_integrator)
ml_provider.add_coarse_level(base_integrator)
ml_provider.add_level_transition(transitioner1, 0, 1)
# ml_provider.add_level_transition(transitioner2, 1, 2)
Пример #4
0
# base_mg_level.arr[:] = 0.0
# base_mg_level.res[:] = 0.0
# base_mg_level.rhs[:] = 0.0
# base_mg_level.pad()

# problem.fill_rhs(fine_mg_level)

LOG.info(SEPARATOR_LVL2)
LOG.info("%sSetting Up MLSDC Solver" % VERBOSITY_LVL1)
from pypint.multi_level_providers.multi_time_level_provider import MultiTimeLevelProvider
from pypint.multi_level_providers.level_transition_providers.time_transition_provider import TimeTransitionProvider
from pypint.integrators.sdc_integrator import SdcIntegrator

base_mlsdc_level = SdcIntegrator()
base_mlsdc_level.init(num_nodes=5)

fine_mlsdc_level = SdcIntegrator()
fine_mlsdc_level.init(num_nodes=7)

transitioner = TimeTransitionProvider(fine_nodes=fine_mlsdc_level.nodes, coarse_nodes=base_mlsdc_level.nodes)

ml_provider = MultiTimeLevelProvider()
ml_provider.add_coarse_level(fine_mlsdc_level)
ml_provider.add_coarse_level(base_mlsdc_level)
ml_provider.add_level_transition(transitioner, 0, 1)

from pypint.communicators import ForwardSendingMessaging
comm = ForwardSendingMessaging()

from pypint.solvers.ml_sdc import MlSdc