repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
finmag
finmag-master/examples/nmag_example_2/__init__.py
0
0
0
py
finmag
finmag-master/examples/nmag_example_2/callgraph.py
#!/usr/bin/env python try: from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph import Grouper from pycallgraph.output import GraphvizOutput except ImportError: print "You need to install pycallgraph (for instance with `pip i...
911
26.636364
90
py
finmag
finmag-master/examples/nmag_example_2/test_nmag_example_2.py
import os import pytest import subprocess as sp import numpy as np import run_finmag from finmag.util.fileio import Tablereader MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) @pytest.mark.slow def test_against_nmag(): cwd_backup = os.getcwd() os.chdir(MODULE_DIR) try: cmd = ['make', 'cl...
1,218
27.348837
68
py
finmag
finmag-master/examples/spatially-varying-anisotropy/run.py
""" Demonstrating spatially varying anisotropy. Example with anisotropy vectors as follows: ----------------------------------- --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> ----------------------------------- ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | ...
2,709
29.111111
97
py
finmag
finmag-master/examples/precession/run.py
import os import numpy as np import dolfin as df import matplotlib.pyplot as plt from finmag import Simulation from finmag.energies import Demag, Exchange MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) IMAGE = os.path.join(MODULE_DIR, 'precession.png') ts = np.linspace(0, 3e-10) def run_simulation(do_preces...
1,201
28.317073
82
py
finmag
finmag-master/examples/exchange_1D/1d_plot.py
import numpy import finmag.util.helpers as helpers from mayavi import mlab """ Visualise the final configuration of the magnetisation. """ x = numpy.genfromtxt("1d_coord.txt") y = numpy.zeros(len(x)) z = numpy.zeros(len(x)) Ms = numpy.genfromtxt("1d_M.txt") Mx, My, Mz = helpers.components(Ms[-1]) figure = mlab.fig...
474
18
55
py
finmag
finmag-master/examples/exchange_1D/1d_anim.py
import numpy import finmag.util.helpers as helpers from mayavi import mlab """ Visualise the evolution of the vector field M over time. """ x = numpy.genfromtxt("1d_coord.txt") y = numpy.zeros(len(x)) z = numpy.zeros(len(x)) Ms = numpy.genfromtxt("1d_M.txt") u, v, w = helpers.components(Ms[0]) figure = mlab.figure...
769
20.388889
56
py
finmag
finmag-master/examples/exchange_1D/run_visual.py
""" Attempt to visualise some dynimacs using python's visual module. Visualisation probably okay, but some convergence problem in the time integration means this does not look smooth at all, and is very slow. """ import dolfin import numpy from scipy.integrate import odeint from finmag.physics.llg import LLG """ Co...
1,412
24.232143
97
py
finmag
finmag-master/examples/exchange_1D/1d_angles.py
import numpy import pylab from finmag.util.helpers import vectors, norm, angle # Load the data which dolfin has created and odeint has integrated. Ms = numpy.genfromtxt("1d_M.txt") # Each entry in ys is M for a particular moment in time. # Each M is all the x-values of M on the mesh, followed by the y and z-values. ...
994
25.184211
78
py
finmag
finmag-master/examples/exchange_1D/1d_dynamics.py
import numpy import pylab from finmag.util.helpers import norm, angle, components, \ vectors, rows_to_columns # Load the data which dolfin has created and odeint has integrated. Ms = numpy.genfromtxt("1d_M.txt") # Each entry in ys is M for a particular moment in time. # Each M is all the x-values of M on the...
838
30.074074
78
py
finmag
finmag-master/examples/exchange_1D/1d_run.py
import dolfin import numpy from scipy.integrate import odeint from finmag.physics.llg import LLG from finmag.energies import Exchange """ Compute the behaviour of a one-dimensional strip of magnetic material, with exchange interaction. """ A = 1.3e-11 Ms = 8.6e5 length = 20e-9 # in meters simplexes = 10 mesh = dolf...
1,018
22.159091
70
py
finmag
finmag-master/examples/macrospin/test_macrospin.py
import dolfin import os import py import numpy import pytest from finmag import Simulation from finmag.energies import Zeeman from finmag.util.macrospin import make_analytic_solution MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) """ The analytical solution of the LLG equation for a constant applied field, b...
4,033
29.330827
89
py
finmag
finmag-master/examples/macrospin/test_macrospin_alpha_rtol.py
import py import os import dolfin import numpy import logging import matplotlib.pyplot as plt from finmag import Simulation from finmag.energies import Zeeman from test_macrospin import make_analytic_solution from scipy.integrate import odeint log = logging.getLogger(name='finmag') log.setLevel(logging.WARNING) """ W...
3,160
37.54878
110
py
finmag
finmag-master/examples/demag/run_nmag.py
import os import nmag, sys from nmag import SI try: meshfile = sys.argv[1] datafile = sys.argv[2] except IndexError: print 'Usage: nmsim %s meshfile outputdatafile' % sys.argv[0] sys.exit(1) #create simulation object sim = nmag.Simulation() # define magnetic material Py = nmag.MagMaterial(name = 'Py', ...
1,149
22.469388
74
py
finmag
finmag-master/examples/demag/test_field.py
import os import dolfin as df from numpy import average from finmag.energies import Demag from finmag.field import Field from finmag.util.meshes import from_geofile TOL = 1e-3 MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) Ms = 1e6 def test_field(): """ Test the demag field. H_demag should be eq...
1,648
27.929825
80
py
finmag
finmag-master/examples/demag/short_nmag_comp_tests2.py
##import io import os import sys import time import subprocess import numpy as np import dolfin as df from finmag.field import Field from finmag.util.meshes import from_geofile from finmag.energies import Demag from finmag.energies.demag.solver_gcr import FemBemGCRSolver import pylab as p import finmag.energies.demag.s...
12,237
32.165312
149
py
finmag
finmag-master/examples/demag/test_energy.py
import os import py import pytest import logging import dolfin as df from numpy import pi, sqrt from finmag.energies import Demag from finmag.field import Field from finmag.util.meshes import from_geofile from finmag.util.consts import mu0 log = logging.getLogger("finmag") MODULE_DIR = os.path.dirname(os.path.abspath(...
1,339
25.8
81
py
finmag
finmag-master/examples/varying_alpha/run.py
import dolfin as df from finmag.physics.llg import LLG x0 = 0; x1 = 100e-9; xn = 50; y0 = 0; y1 = 10e-9; yn = 5; nanowire = df.RectangleMesh(df.Point(x0, y0), df.Point(x1, y1), xn, yn, "left/right") S1 = df.FunctionSpace(nanowire, "Lagrange", 1) S3 = df.VectorFunctionSpace(nanowire, "Lagrange", 1, dim=3) llg = LLG(S1...
687
28.913043
89
py
finmag
finmag-master/examples/cubic_anisotropy/sim.py
import math import numpy as np from finmag import Simulation from finmag.energies import CubicAnisotropy, Demag, Exchange, Zeeman from finmag.util.consts import flux_density_to_field_strength from finmag.util.meshes import cylinder ps = 1e-12 # Mesh mesh = cylinder(r=10, h=2.5, maxh=3.0, filename='disk') unit_length...
1,560
25.016667
68
py
finmag
finmag-master/examples/cubic_anisotropy/nmag_original.py
import os, sys, math from nsim.netgen import netgen_mesh_from_string from nmag.common import SI, degrees_per_ns, Tesla, mu0, at, every from nmag.nmag5 import Simulation, MagMaterial, cubic_anisotropy from nsim.model import Value ps = SI(1e-12, "s"); nm = SI(1e-9, "m") # Useful definitions t...
2,157
13.882759
133
py
finmag
finmag-master/examples/cubic_anisotropy/hysteresis.py
import numpy as np import dolfin as df from finmag import Simulation from finmag.energies import Exchange, CubicAnisotropy from finmag.util.consts import mu0 mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(1, 1, 40), 1, 1, 40) Ms = 876626 # A/m A = 1.46e-11 # J/m K1 = -8608726 K2 = -13744132 K3 = 1100269 u1 = (0, -...
1,144
28.358974
111
py
finmag
finmag-master/examples/boost_python/demo2_classdef/demo2.py
import demo2_module c = demo2_module.console() c.print_line("Hello World - demo2") c.print_line()
102
10.444444
35
py
finmag
finmag-master/examples/boost_python/demo3_numpy/demo3_exceptions.py
import numpy as np import sys import traceback import demo3_module a = np.array([[1, 2], [3, 4]], dtype=float) print "Providing a vector instead of a matrix as an argument\n" try: demo3_module.trace(a[0]) raise Exception("An exception has not been raised") except: traceback.print_exception(*sys.exc_info(...
531
23.181818
63
py
finmag
finmag-master/examples/boost_python/demo3_numpy/demo3.py
import numpy as np import demo3_module a = np.array([[1, 2], [3, 4]], dtype=float) print "Trace of a:", demo3_module.trace(a)
128
17.428571
43
py
finmag
finmag-master/examples/boost_python/demo4_dolfin/demo4.py
import dolfin as df import demo4_module mesh = df.UnitCubeMesh(5, 5, 5) print "Number of vertices:", demo4_module.get_num_vertices(mesh)
138
22.166667
64
py
finmag
finmag-master/examples/boost_python/demo4_dolfin/demo4_swig_objects.py
import dolfin as df mesh = df.UnitCubeMesh(5,5,5) print "mesh = ", mesh, ", type(mesh) =", type(mesh) print "mesh.this = ", mesh.this, ", type(mesh.this) =", type(mesh.this)
176
24.285714
71
py
finmag
finmag-master/examples/boost_python/petsc/demo5.py
import dolfin as df import demo5_module mesh = df.UnitCubeMesh(5, 5, 5) print "Number of vertices:", demo5_module.get_num_vertices(mesh) V = df.FunctionSpace(mesh, 'Lagrange', 1) expr = df.Expression('sin(x[0])', degree=1) M = df.interpolate(expr, V) print 'vector length',demo5_module.get_vector_local_size(M.vector...
324
24
68
py
finmag
finmag-master/examples/boost_python/demo1_helloworld/demo1.py
import demo1_module demo1_module.print_line("Hello World!")
61
14.5
39
py
finmag
finmag-master/src/setup-native.py
#!/usr/bin/env python # Run native_compiler.make_modules() as part of the distribution # process. # See # http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder # for info on this addition before the import line, which works for modules in # arbitrary directories (here, "finmag/util") import ...
606
29.35
138
py
finmag
finmag-master/src/print_tarball_name.py
import os import sys from finmag.util.helpers import binary_tarball_name try: revision = sys.argv[1] suffix = sys.argv[2] destdir = sys.argv[3] except IndexError: print "Usage: print_tarball_name REVISION SUFFIX DESTDIR" sys.exit(0) name = binary_tarball_name(repo=os.curdir, revision=revision, suf...
368
22.0625
76
py
finmag
finmag-master/src/setup-cython.py
# build script for compiled version of finmag # change this as needed libincludedir = "." import sys import os from distutils.core import setup from distutils.extension import Extension # we'd better have Cython installed, or it's a no-go try: from Cython.Distutils import build_ext except: print "You don't ...
3,236
33.43617
109
py
finmag
finmag-master/src/distcp.py
import os import shutil import argparse directories_to_ignore = ['build', '__pycache__'] def cp_file(sourcedir, filename, targetdir): # The only relevant case is if we have a .so file for a given .py, # then don't copy .py if the .so file is __init__.py, we need to # copy an empty __init__.py # Crea...
4,398
34.192
85
py
finmag
finmag-master/src/finmag/field.py
""" Representation of scalar and vector fields, as well as operations on them backed by a dolfin function. This module exists because things like per-node operations or exporting of field values to convenient formats are awkward to do in dolfin currently. Additionally, some things are non-trivial to get right, especia...
29,357
38.406711
126
py
finmag
finmag-master/src/finmag/field_test.py
import dolfin as df import numpy as np import functools import pytest import os from field import Field, associated_scalar_space class TestField(object): def setup(self): self.create_meshes() self.define_tolerances() # All created function spaces are CG (Lagrange) # with degree=1 ...
74,170
46.637123
177
py
finmag
finmag-master/src/finmag/setup2.py
# build script for compiled version of finmag # change this as needed libincludedir = "." import sys import os from distutils.core import setup from distutils.extension import Extension # we'd better have Cython installed, or it's a no-go try: from Cython.Distutils import build_ext except: print "You don't ...
1,728
25.6
89
py
finmag
finmag-master/src/finmag/init.py
# FinMag - a thin layer on top of FEniCS to enable micromagnetic multi-physics simulations # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] from __future__ import division import logging logger = logging.getLogger("finmag") # no need to propagate up to root handler,...
5,083
37.80916
90
py
finmag
finmag-master/src/finmag/__init__.py
# FinMag # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] # from init import * from __version__ import __version__ # dolfin 1.1.0 re-orders the degrees of freedom # to speed up some iterative algorithms. However, # this means that the ordering doesn't correspond # t...
554
28.210526
49
py
finmag
finmag-master/src/finmag/distcp.py
#files_to_ignore = ['llg.py'] directories_to_ignore = ['build'] directories_for_straight_copy_only = ['native'] import os import shutil import argparse def cp_file(sourcedir, filename, targetdir): # only relevant case is if we have a .so file for a given .py, then don't copy .py # if the .so file is __init_...
2,146
31.530303
86
py
finmag
finmag-master/src/finmag/field_setters_test.py
""" Ensure that field values can be set using a wide range of types and make sure we don't assign a new dolfin function, but only overwrite the values of the existing function. """ import dolfin as df import numpy as np import pytest from .field import Field EPSILON = 1e-14 @pytest.fixture def setup(): mesh = d...
4,917
29.171779
94
py
finmag
finmag-master/src/finmag/scheduler/timeevent.py
from finmag.scheduler.event import Event EPSILON = 1e-15 # Time precision, used to compare two time values. def same_time(t0, t1): """ This function compares time values and returns True or False to denote comparison. """ return (t0 is not None) and (t1 is not None) and abs(t0 - t1) < EPSILON ...
3,027
34.209302
79
py
finmag
finmag-master/src/finmag/scheduler/event.py
# Event states are as follows: # EV_ACTIVE: Event intends to trigger eventually if integration continues. # EV_DONE: Event does not intent to trigger again. Should be removed by the # scheduler. # EV_REQUESTS_STOP_INTEGRATION: Event wishes the scheduler to stop the # integration. This does n...
2,435
37.0625
79
py
finmag
finmag-master/src/finmag/scheduler/scheduler.py
import atexit import logging import functools from numbers import Number from datetime import datetime, timedelta from finmag.scheduler.derivedevents import SingleTimeEvent, RepeatingTimeEvent from finmag.scheduler.timeevent import same_time from finmag.scheduler.event import EV_DONE, EV_REQUESTS_STOP_INTEGRATION # Thi...
9,526
34.681648
136
py
finmag
finmag-master/src/finmag/scheduler/scheduler_test.py
import pytest from timeevent import TimeEvent from derivedevents import SingleTimeEvent, RepeatingTimeEvent from scheduler import Scheduler class Counter(object): cnt_every = 0 cnt_at = 0 def inc_every(self): self.cnt_every += 1 def inc_at(self): self.cnt_at += 1 def reset(self)...
7,883
23.184049
79
py
finmag
finmag-master/src/finmag/scheduler/__init__.py
# This file is needed just os that python recognises # the contents as a module, but we're not actually # exposing any names here.
131
32
52
py
finmag
finmag-master/src/finmag/scheduler/derivedevents.py
import logging from finmag.scheduler.timeevent import TimeEvent, same_time, EPSILON # Import the possible states of events. from finmag.scheduler.event import EV_ACTIVE, EV_DONE from finmag.scheduler.event import EV_REQUESTS_STOP_INTEGRATION log = logging.getLogger(name="finmag") class SingleTimeEvent(TimeEvent): ...
3,767
32.945946
79
py
finmag
finmag-master/src/finmag/physics/effective_field.py
import logging import numpy as np from finmag.field import Field from finmag.util.helpers import vector_valued_function from finmag.energies import TimeZeeman from finmag.physics.errors import UnknownInteraction logger = logging.getLogger(name="finmag") class EffectiveField(object): def __init__(self, m, Ms, un...
5,424
30.911765
76
py
finmag
finmag-master/src/finmag/physics/errors.py
class UnknownInteraction(KeyError): def __init__(self, unknown_interaction, known_interactions): self.unknown = unknown_interaction self.known = known_interactions super(UnknownInteraction, self).__init__() def __str__(self): message = ("Couldn't find interaction with name {}. ...
434
35.25
76
py
finmag
finmag-master/src/finmag/physics/neb_cartesian_modified.py
import os import numpy as np import dolfin as df # import inspect from aeon import timer # import finmag.util.consts as consts # from finmag.util import helpers # from finmag.physics.effective_field import EffectiveField from finmag.util.vtk_saver import VTKSaver from finmag import Simulation # from finmag.field impo...
22,197
34.5168
117
py
finmag
finmag-master/src/finmag/physics/physics.py
""" Derives physical quantities from the primary simulation state. """ import logging import numpy as np import dolfin as df import finmag.util.consts as consts from finmag.field import Field from effective_field import EffectiveField from equation import Equation logger = logging.getLogger(name="finmag") class Phy...
6,484
34.054054
195
py
finmag
finmag-master/src/finmag/physics/neb_cartesian.py
import os import dolfin as df import numpy as np # import inspect from aeon import timer # import finmag.util.consts as consts # from finmag.util import helpers # from finmag.physics.effective_field import EffectiveField from finmag.util.vtk_saver import VTKSaver from finmag import Simulation # from finmag.field impor...
21,007
33.839138
94
py
finmag
finmag-master/src/finmag/physics/llg.py
import logging import numpy as np import dolfin as df import finmag.util.consts as consts from aeon import timer from finmag.field import Field from finmag.physics.effective_field import EffectiveField from finmag.native import llg as native_llg from finmag.util import helpers from finmag.util.meshes import nodal_volum...
21,056
36.137566
195
py
finmag
finmag-master/src/finmag/physics/llg_stt.py
import dolfin as df import numpy as np import inspect from aeon import timer import finmag.util.consts as consts from finmag.field import Field from finmag.util import helpers from finmag.physics.effective_field import EffectiveField from finmag.util.meshes import nodal_volume from finmag.native import llg as native_l...
9,776
30.236422
112
py
finmag
finmag-master/src/finmag/physics/equation.py
""" This module solves the LLG equation or one of its many variants. Using native code tied in by instant, it allows to specify parameters and the terms of the equation that are to be used and then solves for dm/dt. No effective field computation, no saving of magnetisation to file or whatever, just straight up solvi...
5,606
37.9375
102
py
finmag
finmag-master/src/finmag/physics/__init__.py
0
0
0
py
finmag
finmag-master/src/finmag/physics/neb.py
import os import dolfin as df import numpy as np import inspect from aeon import timer import finmag.util.consts as consts from finmag.util import helpers from finmag.physics.effective_field import EffectiveField from finmag.util.vtk_saver import VTKSaver from finmag import Simulation # from finmag.field import Field ...
30,649
31.263158
104
py
finmag
finmag-master/src/finmag/physics/tests/test_effective_field.py
import numpy as np import dolfin as df import pytest import os from finmag.example import barmini def test_effective_field_compute_returns_copy(tmpdir): """ Regression test to ensure that the value returned by EffectiveField.compute() does not change as a simulation progresses. This used to happen sin...
733
27.230769
70
py
finmag
finmag-master/src/finmag/physics/tests/test_terms.py
import pytest from os import path import dolfin as df import finmag.physics.equation as eqn @pytest.fixture def terms_module(): MODULE_DIR = path.dirname(path.abspath(__file__)) SOURCE_DIR = path.join(MODULE_DIR, "..", "native") with open(path.join(SOURCE_DIR, "terms.h"), "r") as header: code = he...
1,460
30.76087
101
py
finmag
finmag-master/src/finmag/physics/tests/test_equation.py
import pytest import numpy as np import dolfin as df from finmag.physics.equation import Equation @pytest.fixture def setup(): mesh = df.UnitIntervalMesh(3) V = df.FunctionSpace(mesh, "CG", 1) alpha = df.Function(V) alpha.assign(df.Constant(1)) W = df.VectorFunctionSpace(mesh, "CG", 1, dim=3) ...
4,598
32.086331
86
py
finmag
finmag-master/src/finmag/physics/tests/neb/microspin.py
import os import dolfin as df import numpy as np import matplotlib as mpl mpl.use("Agg") import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.colors import colorConverter from matplotlib.collections import PolyCollection, LineCollection from finmag import Simulation as Sim from fin...
1,477
22.09375
73
py
finmag
finmag-master/src/finmag/physics/tests/neb/neb_test.py
import os import dolfin as df import numpy as np import matplotlib as mpl mpl.use("Agg") import matplotlib.pyplot as plt from finmag import Simulation as Sim from finmag.energies import Exchange, UniaxialAnisotropy MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) def test_compute_dm(): from finmag.physi...
1,245
20.482759
68
py
finmag
finmag-master/src/finmag/physics/llb/sllg.py
import time import numpy as np import dolfin as df import finmag.util.consts as consts import finmag.native.llb as native_llb from finmag.field import Field from finmag.util import helpers from finmag.physics.effective_field import EffectiveField from finmag.util.meshes import mesh_volume, nodal_volume from finmag.uti...
9,355
28.514196
107
py
finmag
finmag-master/src/finmag/physics/llb/exchange.py
import logging import dolfin as df from aeon import timer from finmag.energies.energy_base import EnergyBase from finmag.util.consts import mu0 from finmag.physics.llb.material import Material logger = logging.getLogger('finmag') class ExchangeStd(EnergyBase): """ Compute the exchange field for LLB case. ...
4,723
25.840909
82
py
finmag
finmag-master/src/finmag/physics/llb/llb_test.py
import os import pytest import dolfin as df import numpy as np import matplotlib as mpl mpl.use("Agg") import matplotlib.pyplot as plt from finmag.physics.llb.llb import LLB from finmag.physics.llb.exchange import Exchange from finmag.energies import Zeeman from finmag.energies import Demag from finmag.physics.llb.mate...
4,687
22.44
76
py
finmag
finmag-master/src/finmag/physics/llb/material.py
import logging import numpy as np import dolfin as df import finmag.util.consts as consts import finmag.native.llb as native_llb from finmag.util import helpers from finmag.field import Field logger = logging.getLogger(name='finmag') class Material(object): """ The aim to define this class is to collect mat...
6,255
32.816216
106
py
finmag
finmag-master/src/finmag/physics/llb/__init__.py
# FinMag - a thin layer on top of FEniCS to enable micromagnetic multi-physics simulations # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] # # AUTHOR(S) OF THIS FILE: Dmitri Chernyshenko ([email protected])
270
32.875
90
py
finmag
finmag-master/src/finmag/physics/llb/llb.py
import dolfin as df import numpy as np import inspect from aeon import timer from finmag.native import sundials import finmag.native.llb as native_llb from finmag.energies import Zeeman from finmag.energies import Demag from finmag.physics.llb.exchange import Exchange from finmag.physics.llb.material import Material fr...
13,787
30.124153
93
py
finmag
finmag-master/src/finmag/physics/llb/anisotropy.py
import dolfin as df import logging from aeon import timer from finmag.energies.energy_base import EnergyBase from material import Material logger = logging.getLogger('finmag') class LLBAnisotropy(EnergyBase): """ Compute the anisotropy field for LLB case H = -(m_x e_x + m_y e_y)/chi_perp ==> E...
2,072
23.104651
77
py
finmag
finmag-master/src/finmag/physics/llb/sllg_test.py
import os import dolfin as df import numpy as np import matplotlib as mpl mpl.use("Agg") import matplotlib.pyplot as plt from finmag.physics.llb.sllg import SLLG from finmag.energies import Zeeman from finmag.energies import Demag MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) def plot_random_number(): ...
1,150
22.979167
76
py
finmag
finmag-master/src/finmag/physics/llb/tests/__init__.py
# FinMag - a thin layer on top of FEniCS to enable micromagnetic multi-physics simulations # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] # # AUTHOR(S) OF THIS FILE: Dmitri Chernyshenko ([email protected])
270
32.875
90
py
finmag
finmag-master/src/finmag/drivers/llg_integrator.py
import logging from finmag.field import Field from finmag.drivers.sundials_integrator import SundialsIntegrator from finmag.drivers.scipy_integrator import ScipyIntegrator log = logging.getLogger(name='finmag') def llg_integrator(llg, m0, backend="sundials", **kwargs): # XXX TODO: Passing the tablewriter argumen...
1,284
41.833333
93
py
finmag
finmag-master/src/finmag/drivers/sundials_integrator.py
import logging from finmag.native import sundials EPSILON = 1e-15 log = logging.getLogger(name='finmag') class SundialsIntegrator(object): """ Sundials time integrator. We always start integration from t = 0. Attributes: cur_t The time up to which integration has been carried out. ""...
7,695
38.875648
101
py
finmag
finmag-master/src/finmag/drivers/__init__.py
0
0
0
py
finmag
finmag-master/src/finmag/drivers/scipy_integrator.py
import logging import numpy as np from scipy.integrate import ode EPSILON = 1e-15 log = logging.getLogger(name="finmag") class ScipyIntegrator(object): def __init__(self, llg, m0, reltol=1e-6, abstol=1e-6, nsteps=10000, method="bdf", tablewriter=None, **kwargs): self.m_field = m0 self.solve_for =...
1,359
31.380952
114
py
finmag
finmag-master/src/finmag/drivers/tests/test_integrator_raises_exception_on_exceed_maxsteps.py
import os import pytest import finmag steps = 10 def test_can_change_maxsteps(): sim = finmag.example.barmini() sim.create_integrator() sim.integrator.max_steps = steps assert sim.integrator.max_steps == steps def test_time_run_until(): sim = finmag.example.barmini() sim.create_integrator()...
1,301
24.529412
70
py
finmag
finmag-master/src/finmag/drivers/tests/test_relaxation.py
import os import numpy as np import dolfin as df import matplotlib.pyplot as plt from finmag import Simulation from finmag.energies import Zeeman, Exchange, Demag from finmag.util.consts import ONE_DEGREE_PER_NS MODULE_DIR = os.path.abspath(os.path.dirname(__file__)) def test_easy_relaxation(do_plot=False): """ ...
2,025
30.65625
154
py
finmag
finmag-master/src/finmag/drivers/tests/test_scipy.py
import dolfin as df from finmag import Simulation def _test_scipy_advance_time(): mesh = df.UnitIntervalMesh(10) sim = Simulation(mesh, Ms=1, unit_length=1e-9, integrator_backend="scipy") sim.set_m((1, 0, 0)) sim.advance_time(1e-12) sim.advance_time(2e-12) sim.advance_time(2e-12) sim.advan...
723
25.814815
78
py
finmag
finmag-master/src/finmag/drivers/tests/sundials_nsteps_test.py
import finmag import os def test_integrator_get_set_max_steps(tmpdir): """ Tests setting and getting of nsteps """ os.chdir(str(tmpdir)) sim = finmag.example.barmini() sim.run_until(0) # create integrator object steps = sim.integrator.max_steps assert steps != 42 # would be an odd d...
1,747
28.133333
76
py
finmag
finmag-master/src/finmag/drivers/tests/test_relax_two_times.py
import dolfin as df from finmag import Simulation from finmag.energies import Zeeman def test_relax_two_times(): """ Test whether we can call the relax method on Sim two times in a row. """ mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(10, 10, 10), 2, 2, 2) Ms = 0.86e6 sim = Simulation(mesh,...
656
22.464286
72
py
finmag
finmag-master/src/finmag/drivers/tests/test_integrators.py
# FinMag - a thin layer on top of FEniCS to enable micromagnetic multi-physics simulations # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] # # AUTHOR(S) OF THIS FILE: Dmitri Chernyshenko ([email protected]) import unittest from finmag.tests.jacobean.domain...
1,632
31.019608
96
py
finmag
finmag-master/src/finmag/drivers/tests/sundials_reinit_test.py
# FinMag - a thin layer on top of FEniCS to enable micromagnetic multi-physics simulations # Copyright (C) 2012 University of Southampton # Do not distribute # # CONTACT: [email protected] # # AUTHOR(S) OF THIS FILE: Hans Fangohr (copied template from Dmitri for # integrator tests) """The purpose of this file is ...
4,324
33.055118
90
py
finmag
finmag-master/src/finmag/energies/test_energies_in_regions.py
from __future__ import division import numpy as np import dolfin as df import pytest import os import finmag from finmag.field import Field #from finmag.energies import Zeeman, TimeZeeman, DiscreteTimeZeeman, OscillatingZeeman from finmag.energies import Zeeman #from finmag.util.consts import mu0 from finmag.util.meshe...
4,938
34.278571
89
py
finmag
finmag-master/src/finmag/energies/energy_base.py
import logging import dolfin as df import numpy as np from aeon import timer from finmag.util.meshes import nodal_volume from finmag.util import helpers from finmag.util.consts import mu0 from finmag.field import Field logger = logging.getLogger('finmag') class EnergyBase(object): """ Computes a field for a...
9,254
34.190114
81
py
finmag
finmag-master/src/finmag/energies/cubic_anisotropy.py
import logging import numpy as np import dolfin as df from aeon import timer from finmag.field import Field from energy_base import EnergyBase from finmag.util import helpers from finmag.util.consts import mu0 from finmag.native import llg as native_llg logger = logging.getLogger('finmag') class CubicAnisotropy(Ener...
4,052
33.347458
102
py
finmag
finmag-master/src/finmag/energies/exchange.py
import logging import dolfin as df from aeon import timer from energy_base import EnergyBase from finmag.field import Field logger = logging.getLogger('finmag') class Exchange(EnergyBase): """ Compute the exchange field. .. math:: E_{\\text{exch}} = \\int_\\Omega A (\\nabla M)^2 dx *Argu...
2,933
26.942857
76
py
finmag
finmag-master/src/finmag/energies/anisotropy_test.py
import pytest import textwrap import dolfin as df import numpy as np from finmag.field import Field from finmag.energies import UniaxialAnisotropy from finmag.util.consts import mu0 TOLERANCE = 1e-12 @pytest.fixture(scope="module") def fixt(): """ Create an UniaxialAnisotropy object that will be re-used duri...
4,795
32.538462
93
py
finmag
finmag-master/src/finmag/energies/dw_fixed_energy.py
import os import textwrap import dolfin as df import numpy as np from demag import Demag class FixedEnergyDW(object): def __init__(self, left=(1, 0, 0), right=(-1, 0, 0), repeat_time=5, name='FixedEnergyDW'): self.left = left self.right = right self.repeat_time = repeat_time self....
5,152
33.817568
96
py
finmag
finmag-master/src/finmag/energies/cubic_anisotropy_test.py
import dolfin as df import numpy as np from finmag.field import Field from finmag.energies import CubicAnisotropy from finmag.util.meshes import mesh_volume import pytest unit_length = 1e-9 Ms = 876626 # A/m K1 = -8608726 K2 = -13744132 K3 = 1100269 u1 = (0, -0.7071, 0.7071) u2 = (0, 0.7071, 0.7071) u3 = (-1, 0, 0)...
1,514
27.584906
86
py
finmag
finmag-master/src/finmag/energies/dmi_test.py
import pytest import numpy as np import dolfin as df from math import pi from finmag.energies import DMI, Exchange from finmag import Simulation from finmag.field import Field from finmag.util.helpers import vector_valued_function from finmag.util.pbc2d import PeriodicBoundary2D def test_dmi_uses_unit_length_2dmesh()...
3,797
29.878049
86
py
finmag
finmag-master/src/finmag/energies/exchange_test.py
import pytest import numpy as np import dolfin as df from finmag.energies import Exchange from finmag.field import Field from math import sqrt, pi from finmag.util.consts import mu0 from finmag.util.pbc2d import PeriodicBoundary2D @pytest.fixture def fixt(): """ Create an Exchange object that will be re-used d...
6,795
29.475336
84
py
finmag
finmag-master/src/finmag/energies/init.py
import logging from demag import Demag, Demag2D, MacroGeometry from energy_base import EnergyBase from exchange import Exchange from anisotropy import UniaxialAnisotropy from cubic_anisotropy import CubicAnisotropy from zeeman import Zeeman, TimeZeeman, DiscreteTimeZeeman, OscillatingZeeman, TimeZeemanPython from dmi i...
466
34.923077
94
py
finmag
finmag-master/src/finmag/energies/zeeman_test.py
from __future__ import division import numpy as np import dolfin as df import pytest import os import finmag import logging from finmag.field import Field from finmag import sim_with from finmag.energies import Zeeman, TimeZeeman, DiscreteTimeZeeman, OscillatingZeeman from finmag.util.consts import mu0 from finmag.util...
15,728
33.953333
97
py
finmag
finmag-master/src/finmag/energies/dmi.py
import logging import dolfin as df from aeon import timer from finmag.field import Field from energy_base import EnergyBase from finmag.util.helpers import times_curl logger = logging.getLogger('finmag') class DMI(EnergyBase): """ Compute the Dzyaloshinskii-Moriya Interaction (DMI) field. .. math:: ...
5,280
29.703488
101
py
finmag
finmag-master/src/finmag/energies/random_thermal.py
import numpy as np import dolfin as df from finmag.util.consts import mu0, k_B from finmag.util.meshes import mesh_volume class RandomThermal(object): """ Thermal field from Simone, E. Martínez, L. López-Díaz, L. Torres and C.J. García-Cervera. Minimizing cell size dependence in micromagnetics simu...
1,736
28.948276
99
py
finmag
finmag-master/src/finmag/energies/thin_film_demag.py
import logging import numpy as np import dolfin as df logger = logging.getLogger('finmag') class ThinFilmDemag(object): """ Demagnetising field for thin films in the i-direction. Hj = Hk = 0 and Hi = - Mi. """ def __init__(self, direction="z", field_strength=None, in_jacobian=False, name='Thin...
1,491
30.083333
100
py
finmag
finmag-master/src/finmag/energies/magnetostatic_field_test.py
import numpy as np from finmag.util.consts import mu0 from finmag.energies.magnetostatic_field import MagnetostaticField def test_magnetostatic_field_for_uniformly_magnetised_sphere(): """ Our favourite test when it comes to demag! """ Ms = 1 m = np.array((1, 0, 0)) Nxx = Nyy = Nzz = 1.0 / 3....
1,372
32.487805
106
py
finmag
finmag-master/src/finmag/energies/__init__.py
from init import *
19
9
18
py
finmag
finmag-master/src/finmag/energies/magnetostatic_field.py
import numpy as np from finmag.util.consts import mu0 EPS = 1e-15 class MagnetostaticField(object): """ Magnetostatic field for uniform magnetisation. The magnetostatic energy density for a uniform magnetisation can be written as: .. math:: U_{\\text{ms}} = \\frac{1}{2} \\...
2,238
29.671233
89
py
finmag
finmag-master/src/finmag/energies/thin_film_demag_test.py
import pytest import numpy as np import dolfin as df from finmag import Simulation as Sim from finmag.energies import ThinFilmDemag, Demag Ms = 8.6e5 def test_interaction_accepts_name(): """ Check that the interaction accepts a 'name' argument and has a 'name' attribute. """ demag = ThinFilmDemag() ...
2,383
31.657534
91
py
finmag
finmag-master/src/finmag/energies/anisotropy.py
import logging import dolfin as df import numpy as np from aeon import timer from energy_base import EnergyBase from finmag.field import Field from finmag.util import helpers from finmag.util.consts import mu0 from finmag.native import llg as native_llg from finmag.field import Field logger = logging.getLogger('finmag...
4,846
30.888158
100
py
finmag
finmag-master/src/finmag/energies/zeeman.py
import logging import dolfin as df import numpy as np from finmag.field import Field from finmag.util.consts import mu0 from finmag.util.meshes import nodal_volume from finmag.util import helpers from math import pi, cos log = logging.getLogger("finmag") class Zeeman(object): def __init__(self, H, name='Zeeman'...
15,581
37.474074
276
py