예제 #1
0
파일: test_fimport.py 프로젝트: pv/fimport
def test_run():
    old_path = list(sys.path)
    tmpdir = tempfile.mkdtemp()
    try:
        sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))

        import fimport
        fimport.install(reload_support=True,
                        build_dir=os.path.join(tmpdir, "_fbld"))

        sys.path.insert(0, tmpdir)

        test_f90 = os.path.join(tmpdir, 'fimport_test_123.f90')
        test_inc = os.path.join(tmpdir, 'fimport_test_123.inc')
        test_fbld = os.path.join(tmpdir, 'fimport_test_123.fbld')
        test_fdep = os.path.join(tmpdir, 'fimport_test_123.fdep')

        with open(test_f90, 'wb') as f:
            f.write(b"subroutine ham(a)\n"
                    b"double precision, intent(out) :: a\n"
                    b"include 'fimport_test_123.inc'\n"
                    b"end subroutine\n"
                    b"subroutine spam(a)\n"
                    b"double precision, intent(out) :: a\n"
                    b"a = 9.99d0\n"
                    b"end subroutine\n")

        with open(test_inc, 'wb') as f:
            f.write(b"a = 3.14d0\n")

        with open(test_fbld, 'wb') as f:
            f.write(b"from numpy.distutils.core import Extension\n"
                    b"def make_ext(modname, ffilename):\n"
                    b"    return Extension(name=modname, sources=[ffilename],\n"
                    b"                     f2py_options=['only:', 'ham', ':'])")

        with open(test_fdep, 'wb') as f:
            f.write(b"fimport_test_123.inc")

        # import!
        import fimport_test_123
        assert_equal(fimport_test_123.ham(), 3.14)
        assert_true('spam' not in dir(fimport_test_123))

        # sleep over timestamp granularity
        time.sleep(1.01)

        # rewrite and reload
        with open(test_inc, 'wb') as f:
            f.write(b"a = 1.23d0\n")

        newmod = imp.reload(fimport_test_123)
        assert_equal(newmod.ham(), 1.23)
        if sys.version_info[0] >= 3:
            raise AssertionError("Reloading doesn't work currently on Python 3")
        else:
            assert_equal(fimport_test_123.ham(), 1.23)
    finally:
        sys.path = old_path
        shutil.rmtree(tmpdir)
예제 #2
0
from __future__ import print_function
import scikits.bvp_solver
import numpy as np
from math import pi, sqrt, sin, cos
import fimport
fimport.install(reload_support=True)
import equations
import sys

# # # # # # # # # # # # #
# Function definitions. #
# # # # # # # # # # # # #


# Function to load previous solutions to be used as initial guesses.
def load(sol_dir, phase, T, alpha_1, alpha_2, alpha_3, alpha_4, h, h_angle, i):
    return scikits.bvp_solver.Solution.load(
        sol_dir +
        'Phase_difference_%.2f/T_%.2f/Rashba_%.2f_%.2f_%.2f_%.2f/h_%.2f_angle_%.2f/Solution-i-%i.sol'
        % (phase, T, alpha_1, alpha_2, alpha_3, alpha_4, h, h_angle, i))


# Function used to solve the problem.
def solve(runge_kutta, tolerance, initial_guess):
    return scikits.bvp_solver.solve(bvp_problem=problem_definition,
                                    method=runge_kutta,
                                    tolerance=tolerance,
                                    solution_guess=initial_guess)


# # # # # # # # # # # # # # #
예제 #3
0
from __future__ import print_function
import scikits.bvp_solver
import numpy as np
from cmath import pi, sqrt, exp
import fimport
fimport.install(reload_support=True)
import equations_real_time, g_bcs
import sys

# # # # # # # # # # # # #
# Function definitions. #
# # # # # # # # # # # # #

# Range function for floats.
def frange(start, end=None, inc=None):
    "A range function, that does accept floats"

    if end == None:
        end = start + 0.0
        start = 0.0
    else: start += 0.0 # force it to be a float

    if inc == None:
        inc = 1.0

    count = int((end - start) / inc)
    if start + count * inc != end + inc:
        count += 1

    L = [None,] * count
    for i in xrange(count):