Ejemplo n.º 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
Ejemplo n.º 2
0
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)
print(ml_provider)


from examples.problems.constant import Constant
from examples.problems.lambda_u import LambdaU
# problem = Constant()
problem = LambdaU(lmbda=complex(-1.0, -1.0))
print(problem)


from pypint.communicators import ForwardSendingMessaging
comm = ForwardSendingMessaging()


from pypint.solvers.ml_sdc import MlSdc
mlsdc = 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)


mlsdc.init(problem=problem, ml_provider=ml_provider)

from pypint.solvers.cores import ExplicitMlSdcCore, ImplicitMlSdcCore, SemiImplicitMlSdcCore
mlsdc.run(SemiImplicitMlSdcCore, dt=1.0)

print("RHS Evaluations: %d" % problem.rhs_evaluations)