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/src/finmag/energies/demag/fk_demag_test.py | import time
import pytest
import dolfin as df
import numpy as np
from math import pi
from finmag.energies.demag.fk_demag import FKDemag
from finmag.field import Field
from finmag.util.consts import mu0
from finmag.util.meshes import sphere, box
radius = 1.0
maxh = 0.2
unit_length = 1e-9
volume = 4 * pi * (radius * uni... | 5,117 | 33.348993 | 106 | py |
finmag | finmag-master/src/finmag/energies/demag/fk_demag_pbc.py | """
Computation of the demagnetising field using the Fredkin-Koehler
technique and the infamous magpar method.
Rationale: The previous implementation in FemBemFKSolver (child class
of FemBemDeMagSolver) was kind of a mess. This does the same thing in the same
time with less code. Should be more conducive to further op... | 4,756 | 29.690323 | 97 | py |
finmag | finmag-master/src/finmag/energies/demag/demag_treecode.py | from dolfin import *
import dolfin as df
import numpy as np
from finmag.native.fast_sum_lib import FastSum
_nodes = (
(0.,),
(-0.5773502691896257,
0.5773502691896257),
(-0.7745966692414834,
0.,
0.7745966692414834),
(-0.861136311594053,
-0.3399810435848562,
0.3399810435848562,... | 16,634 | 29.245455 | 94 | py |
finmag | finmag-master/src/finmag/energies/demag/fk_demag_2d.py | import numpy as np
import dolfin as df
from aeon import timer
from finmag.field import Field
from finmag.native.llg import compute_bem_fk
from finmag.util.consts import mu0
from finmag.util.meshes import nodal_volume
from finmag.util import helpers
from fk_demag import FKDemag
class Demag2D(FKDemag):
"""
To ... | 5,565 | 26.554455 | 77 | py |
finmag | finmag-master/src/finmag/energies/demag/benchmark.py | import time
import numpy as np
import dolfin as df
from finmag.energies import Demag
from finmag.field import Field
from finmag.util.meshes import sphere
import matplotlib.pyplot as plt
radius = 5.0
maxhs = [0.2, 0.4, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.95, 1.0]
unit_length = 1e-9
m_0 = (1, 0, 0)
Ms = 1
H_ref = np.array(... | 2,283 | 29.864865 | 68 | py |
finmag | finmag-master/src/finmag/energies/demag/treecode_bem.py | import logging
import numpy as np
import dolfin as df
import distutils
from finmag.field import Field
from finmag.util.consts import mu0
from finmag.util.meshes import nodal_volume
from finmag.native.treecode_bem import FastSum
from finmag.native.treecode_bem import compute_solid_angle_single
from finmag.util import he... | 8,480 | 34.78481 | 120 | py |
finmag | finmag-master/src/finmag/energies/demag/benchmark_fk.py | import time
import pickle
import numpy as np
import dolfin as df
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
from finmag.energies import Demag
from finmag.field import Field
from finmag.native.llg import compute_bem_fk
from finmag.util.meshes import box
now = time.time
create_mesh = lambda... | 3,020 | 31.836957 | 81 | py |
finmag | finmag-master/src/finmag/energies/demag/fk_demag.py | """
Computation of the demagnetising field using the Fredkin-Koehler
technique and the infamous magpar method.
Rationale: The previous implementation in FemBemFKSolver (child class
of FemBemDeMagSolver) was kind of a mess. This does the same thing in the same
time with less code. Should be more conducive to further op... | 15,001 | 36.979747 | 124 | py |
finmag | finmag-master/src/finmag/energies/demag/belement_magpar.py | import instant
def return_bele_magpar():
args = [["n_bvert", "bvert", "in"], ["facv1_n", "facv1", "in"], [
"facv2_n", "facv2", "in"], ["facv3_n", "facv3", "in"], ["matele_n", "matele"]]
return instant.inline_with_numpy(C_CODE, arrays=args)
C_CODE = """
int Bele(int n_bvert,double* bvert,int facv1_n, ... | 6,075 | 30.811518 | 137 | py |
finmag | finmag-master/src/finmag/energies/demag/belement.py | import dolfin as df
import numpy as np
import belement_magpar
import finmag.util.solid_angle_magpar as solid_angle_solver
compute_belement = belement_magpar.return_bele_magpar()
compute_solid_angle = solid_angle_solver.return_csa_magpar()
def GetDet3(x, y, z):
"""
helper function
"""
d = x[0] * y[1] *... | 5,506 | 28.929348 | 89 | py |
finmag | finmag-master/src/finmag/energies/demag/fk_demag_2d_test.py | import dolfin as df
import pytest
from finmag.field import Field
from finmag.energies.demag.fk_demag_2d import Demag2D
def test_create_mesh():
mesh = df.UnitSquareMesh(20, 2)
demag = Demag2D(thickness=0.1)
mesh3 = demag.create_3d_mesh(mesh)
coord1 = mesh.coordinates()
coord2 = mesh3.coordinates... | 1,461 | 21.492308 | 59 | py |
finmag | finmag-master/src/finmag/energies/demag/__init__.py | import logging
from fk_demag import FKDemag
from fk_demag_pbc import MacroGeometry
from fk_demag_2d import Demag2D
from treecode_bem import TreecodeBEM
log = logging.getLogger("finmag")
KNOWN_SOLVERS = {
'FK': FKDemag, 'Treecode': TreecodeBEM}
def Demag(solver='FK', *args, **kwargs):
if not solver in KNOWN_S... | 700 | 32.380952 | 108 | py |
finmag | finmag-master/src/finmag/energies/demag/demag_pbc_test.py | import pytest
import numpy as np
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag
from finmag import MacroGeometry
mesh_1 = df.BoxMesh(df.Point(-10, -10, -10), df.Point(10, 10, 10), 10, 10, 10)
mesh_3 = df.BoxMesh(df.Point(-30, -10, -10), df.Point(30, 10, 10), 30, 10, ... | 2,013 | 25.853333 | 78 | py |
finmag | finmag-master/src/finmag/energies/demag/solver_base.py | import dolfin as df
import numpy as np
from aeon import Timer
from finmag.field import Field
from finmag.util import helpers
import finmag.util.solver_benchmark as bench
# Define default parameters for the fembem solvers
default_parameters = df.Parameters("demag_options")
poisson = df.Parameters("poisson_solver")
pois... | 10,596 | 33.858553 | 118 | py |
finmag | finmag-master/src/finmag/util/visualization_test.py | import finmag
import pytest
import textwrap
import subprocess
import os
import sys
import numpy as np
import dolfin as df
from glob import glob
from finmag.util.visualization import *
from finmag.util.visualization_impl import *
# Skipping this test for now because it still doesn't work on aleph0
# (although it works ... | 5,488 | 36.59589 | 145 | py |
finmag | finmag-master/src/finmag/util/fft_test.py | from __future__ import division
from fft import *
from numpy import sqrt, sin, cos, pi, exp, real, conj
from finmag.util.consts import gamma
import numpy as np
import os
import pytest
import matplotlib.pyplot as plt
import fft_test_helpers
def test_analytical_inverse_DFT(tmpdir, debug=False):
"""
We construct... | 18,029 | 40.639723 | 146 | py |
finmag | finmag-master/src/finmag/util/solver_benchmark.py | # Modified By Gabriel Balaban April 20, 20012
import dolfin
import ufl
import operator
import numpy as np
def solver_parameters(solver_exclude, preconditioner_exclude):
linear_solver_set = ["lu"]
linear_solver_set += [e[0] for e in dolfin.krylov_solver_methods()]
preconditioner_set = [e[0] for e in dolfi... | 6,181 | 37.6375 | 171 | py |
finmag | finmag-master/src/finmag/util/set_function_values.py | """
Gathers all the ways we know about how to set the values of a dolfin function.
"""
import dolfin as df
def from_constant(function, constant):
"""
Set function values using dolfin constant.
"""
function.assign(constant)
def from_expression(function, expression):
"""
Set function val... | 1,300 | 22.654545 | 78 | py |
finmag | finmag-master/src/finmag/util/mesh_templates_test.py | #!/usr/bin/env python
import pytest
import os
import numpy as np
import dolfin as df
from math import pi
from meshes import mesh_volume
from mesh_templates import *
import logging
# loose tolerance for bad approximations (e.g. for a spherical mesh)
TOL1 = 1e-2
TOL2 = 1e-7 # intermediate tolerance (used e.g. for the... | 10,135 | 34.564912 | 109 | py |
finmag | finmag-master/src/finmag/util/pbc_test.py | import dolfin as df
from pbc2d import PeriodicBoundary2D, PeriodicBoundary1D
def test_pbc1d_2dmesh():
mesh = df.UnitSquareMesh(2, 2)
pbc = PeriodicBoundary1D(mesh)
S = df.FunctionSpace(mesh, "Lagrange", 1, constrained_domain=pbc)
expr = df.Expression('cos(x[0])', degree=1)
M = df.interpolate(e... | 2,111 | 24.756098 | 77 | py |
finmag | finmag-master/src/finmag/util/progress_bar.py | import progressbar
from datetime import datetime, timedelta
DISPLAY_DELAY = timedelta(seconds=1)
class ProgressBar(object):
def __init__(self, maximum_value):
self.pb = progressbar.ProgressBar(maxval=maximum_value,
widgets=[progressbar.ETA(), progressbar.Bar('='... | 535 | 30.529412 | 133 | py |
finmag | finmag-master/src/finmag/util/time_counter.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])
from datetime import datetime, timedelta
import m... | 5,889 | 38.797297 | 221 | py |
finmag | finmag-master/src/finmag/util/visualization.py | from __future__ import division
import StringIO
import sh
import numpy as np
import textwrap
import logging
import tempfile
import shutil
import sys
import os
import re
import dolfin as df
import IPython.core.display
from visualization_impl import _axes, find_unused_X_display
from math import sin, cos, pi
logger = log... | 11,824 | 35.16208 | 108 | py |
finmag | finmag-master/src/finmag/util/dmi_helper_test.py | import pytest
import numpy as np
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Zeeman
from dmi_helper import compute_skyrmion_number_2d
def init_skx_down(pos):
x = pos[0]
y = pos[1]
if (x - 50) ** 2 + (y - 50) ** 2 < 15 ** 2:
return (0, 0, -1)
el... | 1,611 | 21.704225 | 71 | py |
finmag | finmag-master/src/finmag/util/run_native_tests.py | if __name__ == "__main__":
import os
import sys
from finmag.util.native_compiler import pipe_output
os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/../../../native")
res = pipe_output("make test")
sys.exit(res)
| 244 | 26.222222 | 77 | py |
finmag | finmag-master/src/finmag/util/fft.py | from __future__ import division
from scipy.interpolate import InterpolatedUnivariateSpline
from finmag.util.helpers import probe
from finmag.util.fileio import Tablereader
from glob import glob
from time import time
import numpy as np
import dolfin as df
import logging
from numpy import sin, cos, pi
logger = logging.g... | 26,961 | 35.484438 | 155 | py |
finmag | finmag-master/src/finmag/util/consts.py | """
A collection of constants we use (in SI units).
"""
from __future__ import division
from math import pi, sqrt
import numbers
mu0 = 4 * pi * 1e-7 # Vs/(Am)
k_B = 1.3806488e-23 # Boltzmann constant in J / K
h_bar = 1.054571726e-34 # reduced Plank constant in Js
e = 1.602176565e-19 # elementary charge in As
# m/... | 1,525 | 22.476923 | 74 | py |
finmag | finmag-master/src/finmag/util/fileio.py | import os
import logging
import types
import numpy as np
from glob import glob
from types import TupleType, StringType
from aeon import timer
logger = logging.getLogger(name='finmag')
class Tablewriter(object):
# It is recommended that the comment symbol should end with a
# space so that there is no danger th... | 16,523 | 36.049327 | 114 | py |
finmag | finmag-master/src/finmag/util/dmi_helper.py | import numpy as np
import dolfin as df
def find_skyrmion_center_2d(fun, point_up=False):
"""
Find the centre the skyrmion, suppose only one skyrmion
and only works for 2d mesh.
`fun` accept a dolfin function.
`point_up` : the core of skyrmion, points up or points down.
"""
V = fun.fu... | 1,714 | 20.987179 | 75 | py |
finmag | finmag-master/src/finmag/util/vtk_saver.py | import os
import re
import glob
import time
import logging
import dolfin as df
log = logging.getLogger("finmag")
class VTKSaver(object):
def __init__(self, filename=None, overwrite=False):
self.filename = filename
self.f = None
self.counter = 0
if filename != None:
se... | 2,171 | 29.591549 | 85 | py |
finmag | finmag-master/src/finmag/util/fft_test_helpers.py | import os
import numpy as np
import matplotlib.pyplot as plt
import subprocess as sp
from numpy import sqrt, sin, cos, pi, exp, real, conj
def create_test_ndt_file(dirname, t_step, t_ini, t_end, omega, alpha, debug=False):
"""
Create a .ndt file with a time series of artificial magnetisation
data for test... | 3,967 | 33.504348 | 136 | py |
finmag | finmag-master/src/finmag/util/versions.py | import os
import re
import sh
import sys
import logging
import finmag
logger = logging.getLogger('finmag')
def get_linux_issue():
try:
f = open("/etc/issue")
except IOError:
logger.error("Can't read /etc/issue -- this is odd?")
raise RuntimeError("Cannot establish linux version")
i... | 6,533 | 30.114286 | 91 | py |
finmag | finmag-master/src/finmag/util/visualization_impl.py | # This file contains the actual implementation of the Paraview-based
# plotting code. Unfortunately, we cannot import this directly into
# Finmag due to an incompatibility between the Python modules
# 'paraview.servermanager' and 'vtk' which can lead to segfaults (see
# comment in visualization.py). Instead, we need to... | 24,132 | 36.242284 | 121 | py |
finmag | finmag-master/src/finmag/util/vtk_saver_test.py | import os
import pytest
import dolfin as df
import numpy as np
from vtk_saver import VTKSaver
from finmag.util.helpers import assert_number_of_files
class TestVTKSaver(object):
def setup_class(self):
"""
Create a dummy field in various formats (numpy arrays and
dolfin function).
"... | 3,619 | 31.321429 | 72 | py |
finmag | finmag-master/src/finmag/util/batch_task.py | import os
import time
import numpy as np
from multiprocessing import Process, Queue, Lock
lock = Lock()
class TaskState(object):
def __init__(self, taskname):
self.taskname = taskname
self.state = {}
self.load()
def load(self):
if not os.path.exists(self.taskname):
... | 4,992 | 25.005208 | 74 | py |
finmag | finmag-master/src/finmag/util/configuration.py | import ConfigParser as configparser
import os
__all__ = ["get_configuration"]
CONFIGURATION_FILES = [
os.path.expanduser("~/.finmagrc"),
os.path.expanduser("~/.finmag/finmagrc")
]
def get_configuration():
_parser = configparser.SafeConfigParser()
_parser.read(CONFIGURATION_FILES)
return _parser
... | 3,749 | 30.779661 | 79 | py |
finmag | finmag-master/src/finmag/util/plot_helpers_test.py | import os
import pytest
from finmag.example import barmini
from finmag.util.plot_helpers import *
@pytest.mark.requires_X_display
def test_plot_ndt_columns_and_plot_dynamics(tmpdir):
"""
Simply check that we can call the command `plot_ndt_columns` with some arguments
"""
os.chdir(str(tmpdir))
sim ... | 856 | 30.740741 | 93 | py |
finmag | finmag-master/src/finmag/util/macrospin.py | import numpy
import numbers
from finmag.util.consts import gamma as gamma_llg
def make_analytic_solution(H, alpha, gamma=gamma_llg):
"""
Returns a function `m(t)` which computes the magnetisation vector
of a macrospin as a function of time, i.e. the typical precession
under the influence of an applied... | 1,413 | 25.185185 | 75 | py |
finmag | finmag-master/src/finmag/util/plot_helpers.py | """
Easy way to plot values of a function R2 -> R in 2D or 3D.
Does not offer much flexibility, but can be helpful for quick visualisation
of data in an ipython notebook for instance.
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
# don't let the pyflakes error "unused import" in the... | 13,058 | 32.570694 | 138 | py |
finmag | finmag-master/src/finmag/util/dispersion.py | import os
import math
import numpy as np
import dolfin as df
import fenicstools as tls
from joblib import Memory
from tempfile import mkdtemp
__all__ = ['points_on_line', 'points_on_axis', 'probe',
'magnetisation_deviation', 'spinwaves', 'dispersion_relation',
'spinwaves_to_vtk']
# important, si... | 4,216 | 29.338129 | 80 | py |
finmag | finmag-master/src/finmag/util/meshes.py | """
This module contains convenience functions to create common types of
meshes. The execution time may be relatively slow (in particular for
fine meshes) because the mesh creation is done externally via Netgen.
Caveat: Netgen only saves the first 5-6 digits (or so) of each
coordinate during the mesh creation process.... | 61,359 | 35.502082 | 159 | py |
finmag | finmag-master/src/finmag/util/meshes_test.py | import dolfin as df
import numpy as np
import pytest
import os
from meshes import *
from mesh_templates import *
from math import sin, cos, pi
import mshr
def test_mesh_size():
"""
Construct a couple of meshes (box, sphere) and check that
the mesh size is reported as expected.
"""
RTOL = 1e-3
... | 8,361 | 35.837004 | 117 | py |
finmag | finmag-master/src/finmag/util/pbc2d.py | import dolfin as df
import numpy as np
class PeriodicBoundary1D(df.SubDomain):
"""
Periodic Boundary condition in in x direction
"""
def __init__(self, mesh):
super(PeriodicBoundary1D, self).__init__()
self.mesh = mesh
self.find_mesh_info()
def inside(self, x, on_bound... | 5,424 | 28.483696 | 97 | py |
finmag | finmag-master/src/finmag/util/nmesh_to_dolfin.py | import re
def convert(nmesh_file, xml_file):
"""
Convert a mesh from nmesh ASCII format to dolfin xml format.
Note that region information is read from nmesh, but then discarded.
You would need to extend the Emitter class to output a second xml file
if you wanted to preserve the region informatio... | 7,063 | 28.556485 | 107 | py |
finmag | finmag-master/src/finmag/util/test_dmi_from_helix.py | import DMI_from_helix as dfh
import numpy as np
import pytest
a = 3.53e-13
ms = 1.56e5
l = 22e-9
d0 = 4 * np.pi * a / l
hDirection = np.array([1., 0., 0.])
h = hDirection * 0.
def test_dmi_from_helix_solution():
# Test the helix length solution with an example that is known to produce a
# certain value.
... | 1,220 | 23.42 | 79 | py |
finmag | finmag-master/src/finmag/util/point_contacts.py | import dolfin as df
def point_contacts(origins, radius, J, debug=False):
"""
Returns a dolfin expression that locates one or more point contacts.
The expression takes the value *J* for coordinates belonging to a point
contact and the value 0 everywhere else. 'Belonging to a point contact'
means t... | 1,284 | 35.714286 | 86 | py |
finmag | finmag-master/src/finmag/util/test_set_function_values.py | import pytest
import numpy as np
import dolfin as df
from finmag.field import Field
from set_function_values import *
EPSILON = 1e-14
@pytest.fixture
def f():
mesh = df.UnitIntervalMesh(1)
V = df.FunctionSpace(mesh, "CG", 1)
f = df.Function(V)
return f
@pytest.fixture
def vf():
mesh = df.UnitIn... | 1,399 | 23.137931 | 68 | py |
finmag | finmag-master/src/finmag/util/mesh_templates.py | #!/usr/bin/env python
import textwrap
import hashlib
from finmag.util.meshes import from_csg
from finmag.util.helpers import vec2str
netgen_primitives = ['plane', 'cylinder', 'sphere',
'ellipticcylinder', 'ellipsoid', 'cone', 'orthobrick', 'polyhedron']
class MeshTemplate(object):
# Intern... | 8,942 | 36.894068 | 130 | py |
finmag | finmag-master/src/finmag/util/solid_angle_magpar.py | import instant
def return_csa_magpar():
args = [["xn", "x", "in"], ["v1n", "v1", "in"],
["v2n", "v2", "in"], ["v3n", "v3", "in"]]
return instant.inline_with_numpy(C_CODE, arrays=args)
C_CODE = """
double SolidAngle(int xn, double *x, int v1n, double *v1, int v2n, double *v2, int v3n, double *v3);... | 3,963 | 32.033333 | 154 | py |
finmag | finmag-master/src/finmag/util/plot.py | import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from collections import Iterable
import numpy as np
def plot_m(sim, component='x', filename=None, figsize=(10, 5),
extent=None, z=0.0, gridpoints=[100, 100], cbar=True, ncbarticks=5,
cmap='RdBu', bgcolor='w', scale_by_Ms=... | 8,257 | 32.433198 | 77 | py |
finmag | finmag-master/src/finmag/util/__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])
from .plot import *
| 291 | 28.2 | 90 | py |
finmag | finmag-master/src/finmag/util/vtk_export.py | import os
import re
import glob
import time
import logging
import dolfin as df
from aeon import timer
log = logging.getLogger(name="finmag")
class VTK(object):
"""
Can save dolfin functions to VTK files and allows for sequential snapshots.
This object can be used in two modes:
1. To save a single ... | 4,264 | 37.080357 | 88 | py |
finmag | finmag-master/src/finmag/util/native_compiler.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])
"""
Automatic compilation of C/C++ extension modu... | 2,858 | 33.035714 | 153 | py |
finmag | finmag-master/src/finmag/util/helpers.py | from __future__ import division
from datetime import datetime
from glob import glob
from contextlib import contextmanager
from finmag.util.fileio import Tablereader
from finmag.util.visualization import render_paraview_scene
from finmag.util.versions import get_version_dolfin
from finmag.util import ansistrm
from threa... | 60,902 | 31.326433 | 149 | py |
finmag | finmag-master/src/finmag/util/length_scales_test.py | import dolfin as df
import numpy as np
import length_scales as ls
from finmag.field import Field
from finmag.util.consts import mu0
class TestLengthScales(object):
def setup(self):
# Create a 3d mesh.
self.mesh3d = df.UnitCubeMesh(11, 10, 10)
# Create a DG scalar function space.
s... | 2,405 | 31.958904 | 79 | py |
finmag | finmag-master/src/finmag/util/helpers_test.py | import numpy as np
import dolfin as df
import tempfile
import logging
import pytest
import os
import re
from finmag.util.helpers import *
from finmag.util.meshes import box, cylinder
from finmag.util.mesh_templates import Sphere
from finmag.util.visualization import render_paraview_scene
from finmag.example import barm... | 25,171 | 34.156425 | 154 | py |
finmag | finmag-master/src/finmag/util/magpar.py | ##import io
import gzip
import numpy as np
import dolfin as df
import os
import logging
import subprocess
from finmag.util.helpers import run_in_tmpdir
logger = logging.getLogger(name='finmag')
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
def gen_magpar_conf(base_name, init_m, Ms=8.6e5, A=13e-12, K1=0,
... | 8,862 | 27.775974 | 90 | py |
finmag | finmag-master/src/finmag/util/fileio_test.py | import numpy as np
import pytest
import os
from glob import glob
from fileio import *
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
def test_Table_writer_and_reader(tmpdir):
os.chdir(str(tmpdir))
import finmag
import dolfin as df
xmin, ymin, zmin = 0, 0, 0 # one corner of cuboid
xma... | 4,952 | 32.241611 | 89 | py |
finmag | finmag-master/src/finmag/util/length_scales.py | import dolfin as df
from finmag.field import Field
from finmag.util.consts import mu0
from numpy import pi
def exchange_length(A, Ms):
"""
Computes the exchange length when the exchange constant A
and the saturation magnetisation Ms are given. Both Ms and A
are Field objects.
"""
dg_functions... | 1,368 | 25.843137 | 73 | py |
finmag | finmag-master/src/finmag/util/DMI_from_helix.py | """
This file contains three functions that use finmag simulations on a 1D mesh
to obtain certain material characteristics. It also contains an example
showing usage of two of the functions.
"""
import dolfin as df
import finmag
import numpy as np
import scipy.optimize
def Find_Helix_Length(D, A, Ms, H=[0, 0, 0],... | 14,784 | 36.813299 | 80 | py |
finmag | finmag-master/src/finmag/util/ansistrm.py | #
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
# got it from
# http://plumberjack.blogspot.co.uk/2010/12/colorizing-logging-output-in-terminals.html
# probably part of logutils as well
#
import ctypes
import logging
import os
level_maps = {
'dark_bg':
{
... | 5,575 | 31.231214 | 95 | py |
finmag | finmag-master/src/finmag/util/oommf/comparison.py | import dolfin as df
import numpy as np
from finmag.field import Field
from finmag.energies import UniaxialAnisotropy, Exchange
from finmag.util.oommf import oommf_uniform_exchange, oommf_uniaxial_anisotropy
def compare_anisotropy(m_gen, Ms, K1, axis, dolfin_mesh, oommf_mesh, dims=3, name=""):
finmag_anis_field = ... | 3,580 | 34.107843 | 86 | py |
finmag | finmag-master/src/finmag/util/oommf/test_mesh.py | import unittest
import numpy as np
from finmag.util.oommf import mesh
class TestIterCoordsInt(unittest.TestCase):
def test_zyx_ordering(self):
m = mesh.Mesh((3, 1, 1), cellsize=(1, 1, 1))
indices = [r for r in m.iter_coords_int()]
expected = [[0, 0, 0], [1, 0, 0], [2, 0, 0]]
asser... | 1,909 | 38.791667 | 79 | py |
finmag | finmag-master/src/finmag/util/oommf/lattice.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: Matteo Franchin
'''
This module provides the Lattice class to describe multi dimensional
rectangul... | 9,631 | 36.046154 | 90 | py |
finmag | finmag-master/src/finmag/util/oommf/ovf.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: Matteo Franchin
"""
Generic library to read/write files using the OOMMF OVF file format.
We suppor... | 30,985 | 32.753813 | 90 | py |
finmag | finmag-master/src/finmag/util/oommf/init.py | from oommf_calculator import calculate_oommf_fields
import numpy as np
from mesh import MeshField
def mesh_spec(mesh):
return """
Specify Oxs_BoxAtlas:atlas {
xrange {%25.18e %25.18e}
yrange {%25.18e %25.18e}
zrange {%25.18e %25.18e}
}
Specify Oxs_RectangularMesh:mesh {
cellsize {%25.18e %25.18e %25.18e}... | 5,002 | 36.901515 | 202 | py |
finmag | finmag-master/src/finmag/util/oommf/__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])
from init import *
| 290 | 28.1 | 90 | py |
finmag | finmag-master/src/finmag/util/oommf/mesh.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 numpy as np
__all__ = ["Mesh", "MeshField... | 5,347 | 35.882759 | 179 | py |
finmag | finmag-master/src/finmag/util/oommf/oommf_calculator.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 os
import re
import hashlib
import tempfil... | 5,409 | 27.324607 | 90 | py |
finmag | finmag-master/src/finmag/util/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: Gabriel Balaban [email protected]
| 256 | 31.125 | 90 | py |
finmag | finmag-master/src/finmag/util/ode/init.py |
import finmag.native.sundials as native_ode
import numpy as np
class cvode(object):
def __init__(self, f):
native_ode.cvode(native_ode.CV_ADAMS, native_ode.CV_FUNCTIONAL)
def scipy_to_cvode_rhs(f):
def cvode_rhs(t, y, ydot):
ydot[:] = f(t, y)
return 0
return cvode_rhs
def sc... | 469 | 17.076923 | 71 | py |
finmag | finmag-master/src/finmag/util/ode/__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])
from init import *
| 289 | 31.222222 | 90 | py |
finmag | finmag-master/src/finmag/util/ode/tests/robertson_ode.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 numpy as np
import scipy.integrate
n_rhs_... | 1,741 | 23.194444 | 90 | py |
finmag | finmag-master/src/finmag/util/ode/tests/test_sundials_stiff_ode.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
import numpy as np
import finmag.... | 3,181 | 39.278481 | 129 | py |
finmag | finmag-master/src/finmag/util/ode/tests/__init__.py | 0 | 0 | 0 | py | |
finmag | finmag-master/src/finmag/util/ode/tests/test_sundials_ode.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
import math
import numpy as np
im... | 3,475 | 33.415842 | 90 | py |
finmag | finmag-master/src/finmag/tests/test_writing_data.py | import finmag
import os
import numpy as np
from finmag.util.fileio import Tablereader
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
reference_file = os.path.join(MODULE_DIR, "barmini_test.ndt.ref")
def test_write_ndt_file(tmpdir):
os.chdir(str(tmpdir))
sim = finmag.example.barmini(name="barmini_te... | 1,293 | 35.971429 | 70 | py |
finmag | finmag-master/src/finmag/tests/test_1d_domain_wall_profile_uniaxial_anisotropy.py | import numpy as np
import dolfin as df
from finmag import Simulation as Sim
from finmag.energies import Exchange, UniaxialAnisotropy
from aeon import timer
import pylab
K1 = 520e3 # J/m^3
A = 30e-12 # J/m
x0 = 252e-9 # m
Ms = 1400e3 # A/m
def Mz_exact(x, x0=x0, A=A, Ms=Ms):
"""Analytical solution.
"""
... | 3,852 | 29.579365 | 86 | py |
finmag | finmag-master/src/finmag/tests/test_cyclic_references_in_sim.py |
def test_cyclic_refs_in_simulation_object_basic():
import finmag
import dolfin as df
mesh = df.UnitIntervalMesh(1)
s = finmag.Simulation(mesh, Ms=1, unit_length=1e-9, name='simple')
refcount = s.shutdown()
# The number 4 is emperical. If it increases, we
# have introduced an extra cyclic r... | 846 | 31.576923 | 87 | py |
finmag | finmag-master/src/finmag/tests/test_effective_field.py | # HF: April 2014: I am just creating this test file. I am not sure
# whether we have no other tests for the effictive fields - maybe
# they are in a different file.
# Testing new 'get_interaction_list' function:
import dolfin
import finmag
def test_get_interaction_list():
# has bar mini example Demag and Excha... | 831 | 26.733333 | 66 | py |
finmag | finmag-master/src/finmag/tests/test_jacobian.py | import pytest
from dolfin import *
from finmag.physics.llg import LLG
from finmag.energies import Exchange
from math import log
@pytest.mark.xfail
def test_this_needs_fixing():
print("The content of the code in `setup()` above needs to be distributed into the other ")
print("test routines here. It used to be ... | 5,293 | 26.148718 | 95 | py |
finmag | finmag-master/src/finmag/tests/test_sim_parallel.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 Zeeman
#df.parameters.reorder_dofs_serial = True
alpha = 0.1
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
def t_test_si... | 1,778 | 25.954545 | 75 | py |
finmag | finmag-master/src/finmag/tests/test_solid_angle.py | import numpy as np
from finmag.util.solid_angle_magpar import return_csa_magpar
from finmag.native import llg as native_llg
# native_llg.compute_solid_angle returns a signed angle, magpar does not.
TOLERANCE = 1e-15
csa = native_llg.compute_solid_angle
csa_magpar = return_csa_magpar()
def test_solid_angle_first_oc... | 3,572 | 32.392523 | 85 | py |
finmag | finmag-master/src/finmag/tests/test_meshes.py | import os
import time
import pytest
import shutil
import tempfile
import textwrap
from finmag.util.meshes import *
from dolfin import Mesh
from math import pi
from StringIO import StringIO
import logging
logger = logging.getLogger("finmag")
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
TOLERANCE = 0.05
# to... | 6,829 | 34.572917 | 99 | py |
finmag | finmag-master/src/finmag/tests/test_exchange_static.py | import numpy as np
import dolfin as df
from finmag import Simulation as Sim
from finmag.energies import Exchange
from finmag.util.helpers import vectors, angle
TOLERANCE = 8e-7
# define the mesh
length = 20e-9 # m
simplexes = 10
mesh = df.IntervalMesh(simplexes, 0, length)
Ms = 8.6e5
A = 1.3e-11
# initial configura... | 2,356 | 27.39759 | 78 | py |
finmag | finmag-master/src/finmag/tests/test_interactions_scale_linearly_with_m.py | #!/usr/bin/env python
import dolfin as df
import numpy as np
from finmag.field import Field
import pytest
from finmag.energies import Exchange, UniaxialAnisotropy, Zeeman, Demag, DMI
np.random.seed(0)
mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(40, 40, 5), 15, 15, 1)
N = mesh.num_vertices()
V = df.VectorFunctionSp... | 3,760 | 39.880435 | 120 | py |
finmag | finmag-master/src/finmag/tests/test_restart_simulation.py | import finmag
import os
def test_restart_same_simulation(tmpdir):
os.chdir(str(tmpdir))
sim = finmag.example.barmini()
sim.run_until(10e-12)
# To be able to restart the simulation from a particular point, we need to
# save the magnetisation at that time before:
sim.save_restart_data()
... | 3,377 | 29.990826 | 138 | py |
finmag | finmag-master/src/finmag/tests/test_dmi.py | import numpy as np
import dolfin as df
from finmag.field import Field
from finmag.energies import DMI
nm = 1e-9
simplexes = 10
length = 20 * nm
mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(length, 3 * nm, 3 * nm), simplexes, 1, 1)
V = df.VectorFunctionSpace(mesh, "Lagrange", 1)
def test_dmi_field():
"""
Sim... | 1,858 | 32.8 | 87 | py |
finmag | finmag-master/src/finmag/tests/test_anis.py | import numpy as np
import dolfin as df
from finmag.util.helpers import stats
from finmag.energies import UniaxialAnisotropy, CubicAnisotropy
from finmag import Simulation
Ms = 8.6e5
K1 = 520e3
mx = 0.8
my = 0.6
mz = 0
mu0 = 4 * np.pi * 1e-7
def test_anisotropy():
mesh = df.IntervalMesh(1, 0, 1)
sim = Simulat... | 1,012 | 20.553191 | 73 | py |
finmag | finmag-master/src/finmag/tests/test_sim_ode.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 Zeeman
alpha = 0.1
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
def test_sim_ode(do_plot=False):
mesh = df.BoxMesh(d... | 1,686 | 25.777778 | 77 | py |
finmag | finmag-master/src/finmag/tests/test_spatially_varying_anisotropy.py | import pytest
import os
import numpy as np
import dolfin as df
import matplotlib.pyplot as plt
from finmag.field import Field
from finmag import Simulation
from finmag.energies import UniaxialAnisotropy
from finmag.util.consts import bloch_parameter
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
#@pytest.mar... | 2,315 | 31.166667 | 79 | py |
finmag | finmag-master/src/finmag/tests/test_unit_length.py | import os
import numpy as np
import dolfin as df
from finmag.field import Field
from finmag.energies import Exchange
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
n = 20
Ms = 8.6e5
A = 1
REL_TOL = 1e-4
def exchange(mesh, unit_length):
S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1)
m = Field(S3, v... | 1,670 | 33.8125 | 120 | py |
finmag | finmag-master/src/finmag/tests/test_spatially_varying_alpha.py | import dolfin as df
import numpy as np
from finmag import Simulation
from finmag.physics.llg import LLG
def test_spatially_varying_alpha_using_Simulation_class():
"""
test that I can change the value of alpha through the property sim.alpha
and that I get an df.Function back.
"""
length = 20
s... | 1,191 | 27.380952 | 76 | py |
finmag | finmag-master/src/finmag/tests/__init__.py | 0 | 0 | 0 | py | |
finmag | finmag-master/src/finmag/tests/test_heun.py | import numpy as np
from finmag.native.llg import StochasticHeunIntegrator
def test_file_builds():
drift = lambda y, t: 2 * y
diffusion = lambda y, t: y + 0.1
integrator = StochasticHeunIntegrator(np.zeros(1), drift, diffusion, 1e-12)
integrator.helloWorld()
| 276 | 26.7 | 79 | py |
finmag | finmag-master/src/finmag/tests/test_applied_field.py | import numpy as np
import dolfin as df
from finmag import Simulation as Sim
from finmag.energies import Zeeman
Ms = 8.6e5
def test_uniform_external_field():
TOLERANCE = 3.5e-10
mesh = df.UnitCubeMesh(2, 2, 2)
sim = Sim(mesh, Ms)
sim.set_m((1, 0, 0))
sim.add(Zeeman((0, Ms, 0)))
sim.alpha = 1.... | 1,603 | 24.870968 | 99 | py |
finmag | finmag-master/src/finmag/tests/test_time.py | import dolfin as df
from finmag import Simulation as Sim
from finmag.energies import Exchange, Demag
epsilon = 1e-16
def test_current_time():
size = 20e-9
simplices = 4
mesh = df.BoxMesh(
df.Point(0, 0, 0),
df.Point(size, size, size),
simplices, simplices, simplices)
Ms = 860... | 764 | 20.857143 | 78 | py |
finmag | finmag-master/src/finmag/tests/test_dmi_terms.py | import pytest
import dolfin as df
mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(1, 1, 1), 10, 10, 10)
V1 = df.VectorFunctionSpace(mesh, "CG", 1)
VT = df.TensorFunctionSpace(mesh, "CG", 1)
Vs = df.FunctionSpace(mesh, "CG", 1)
tf = df.TestFunction(Vs)
#from finmag.energies.dmi import dmi_term3d, dmi_term2d, dmi_term3... | 6,324 | 40.071429 | 87 | py |
finmag | finmag-master/src/finmag/tests/test_solid_angle_invariance.py | import numpy as np
from finmag.native.llg import compute_solid_angle
import scipy.linalg
import scipy.stats
import math
import unittest
# Quaternion multiplicatoin
def quaternion_product(a, b):
return np.array([
a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3],
a[0] * b[1] + a[1] * b[0] + a[... | 3,961 | 36.028037 | 90 | py |
finmag | finmag-master/src/finmag/tests/test_energy_creation_with_variable_Ms.py | import pytest
import dolfin as df
from finmag.field import Field
from finmag.util.helpers import fnormalise
from finmag.energies import Exchange, UniaxialAnisotropy, Zeeman, Demag
Ms = 8.6e5
mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(10e-9, 10e-9, 10e-9), 5, 5, 5)
@pytest.fixture
def fixt(request):
fixt = requ... | 2,004 | 28.485294 | 79 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.