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/dev/setup.py | #!/usr/bin/env python
# 2015-04-24, Created by H Fuchs <[email protected]>
# This does nothing more than installing the already-created
# finmag-tree.
from distutils.core import setup
setup(name = 'Finmag',
version = '1.0',
description = 'Finmag',
author = 'Hans Fangohr et al',
author_em... | 1,208 | 29.225 | 60 | py |
finmag | finmag-master/dev/sandbox/sumatra_template/main.py | import os
import sys
from sumatra.parameters import build_parameters
# The following line is important because Sumatra creates a parameter file
# 'on the fly' and passes its name to the script, so we should *not* use a
# hard-coded filename here.
paramsfile = sys.argv[1]
parameters = build_parameters(paramsfile)
# I ... | 1,194 | 31.297297 | 74 | py |
finmag | finmag-master/dev/sandbox/periodic/1d_pbc.py | import dolfin as df
import numpy as np
df.parameters.reorder_dofs_serial = False
#from finmag.energies.exchange import Exchange
#from finmag.util.consts import mu0
mu0=np.pi*4e-7
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
class PeriodicBoundary1(df.SubDomain):
def __init__(self, mes... | 2,492 | 20.491379 | 87 | py |
finmag | finmag-master/dev/sandbox/periodic/2d_pbc.py | import dolfin as df
import numpy as np
df.parameters.reorder_dofs_serial = False
#from finmag.energies.exchange import Exchange
#from finmag.util.consts import mu0
mu0=np.pi*4e-7
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
class PeriodicBoundary2D(df.SubDomain):
def inside(self, x, ... | 2,237 | 20.314286 | 87 | py |
finmag | finmag-master/dev/sandbox/periodic/demag/energy.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 1,831 | 21.9 | 76 | py |
finmag | finmag-master/dev/sandbox/periodic/demag/1d_test/demag_pbc_1d_ringdown.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 2,294 | 19.491071 | 76 | py |
finmag | finmag-master/dev/sandbox/periodic/demag/1d_test/demag_pbc_1d.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 2,009 | 22.103448 | 76 | py |
finmag | finmag-master/dev/sandbox/periodic/demag/1d_test/test_belement.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
mesh = df.BoxMesh(-5, -5, -5, 5, 5, 5, 5, 5, 5)
from finmag.native.treecode_bem import compute_solid_angle_single
from finmag.native.treecode_bem import compute_boundary_element
from finmag.native.llg impo... | 1,731 | 22.726027 | 65 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/show_indexsummationwarning_demo.py | """
Anisotropy Energy
Energy computed with two different, mathematically equivalent forms. The second
one produces the warning
Calling FFC just-in-time (JIT) compiler, this may take some time.
Summation index does not appear exactly twice: ?
when it is compiled.
"""
import dolfin as df
mesh = df.UnitCubeMe... | 803 | 23.363636 | 79 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/mixedspacestest.py | import dolfin as df
#Test wether we can combine DG0 and CG1 expressions. Background:
#
#To allow M to vary as a function of space, we would like to write
#M = Ms*m where
#
# Ms is a DG0 space (with values on the centre of the cells) and
# m the normalised magnetisation vector defined on the nodes of the mesh.
#
# Seem... | 724 | 24.892857 | 73 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/assemble_array.py | from dolfin import *
mesh = UnitCubeMesh(30,30,30)
V = FunctionSpace(mesh, "CG", 1)
v = TestFunction(V)
F = Function(V)
b = v*dx
L = assemble(b)
print \
"""
In this test case, F is a dolfin.Function, and L is computed as
\tL = assemble(v*dx),
where v is a dolfin.TestFunction. Say we want to divide F by L.
It we si... | 717 | 17.410256 | 63 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/linear_algebra_timings.py | __author__ = "Anders Logg <[email protected]>"
__date__ = "2012-01-20"
__copyright__ = "Copyright (C) 2012 Anders Logg"
__license__ = "GNU LGPL version 3 or any later version"
# Last changed: 2012-01-20
from dolfin import *
import pylab
# Mesh sizes to check
mesh_sizes = [2, 3, 4, 6, 8, 11, 16, 23, 32, 45, 64, 91]
# ... | 2,595 | 25.489796 | 72 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/project-interpolate.py | from dolfin import *
# Compare the project and interpolate methods for
# a small mesh size. Would assume that both
# methods give the same result in this
# simple case.
# Mesh and functionspace
L = 10e-9 #10 nm
n = 5
mesh = BoxMesh(0,0,0,L,L,L,n,n,n)
V = VectorFunctionSpace(mesh, "CG", 1)
# Initial magnetisati... | 923 | 27.875 | 78 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/eigenvalues.py | #based on https://answers.launchpad.net/dolfin/+question/199058
from dolfin import *
import math
mesh = UnitSquareMesh(30,30)
lv = [c.volume() for c in cells(mesh)]
print "ratio of max and min volume: ", max(lv)/min(lv)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(... | 1,122 | 21.019608 | 82 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/dofs/dofmaptool.py | from dolfin import *
from fenicstools import DofMapPlotter
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, 'CG', 1)
if rank == 0:
dmp = DofMapPlotter(V)
print("""Pressing C, E, v with mouse hovering over cells 0 and 1 and d with mouse over... | 664 | 46.5 | 403 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/dofs/mesh_coordinates_and_function_values_via_dofmap.py | #!/usr/bin/env python
# This is a slightly adapted example from the FEniCS Q&A forum [1].
# It creates a 2D vector field 'v' on a 2D mesh (e.g. representing
# velocity of a flow) and then extracts these values out again and
# displays them in the form
#
# (x_i, y_i) --> (vx_i, vy_i)
#
# It also plots the field val... | 2,626 | 28.188889 | 88 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/dofs/dofmap_cell_dofs.py | # Example motivated by dolfin mailing list (questions 221862):
# http://answers.launchpad.net/dolfin/+question/221862 -- see last reply from Hake
# The entry on the list is not actually very
# informative, but the snippet below seems to show the key idea.
#
# I am gathering this here, to push forward the whole dofmap... | 1,738 | 30.053571 | 121 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/instant/test_norm.py | from dolfin import *
import numpy as np
import os
def test_norm():
header_file = open("Foo/Foo.h", "r")
code = header_file.read()
header_file.close()
foo_module = compile_extension_module(
code=code, source_directory="Foo", sources=["Foo.cpp", "Bar.cpp"],
include_dirs=[".", os.path.absp... | 1,039 | 29.588235 | 74 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/instant/simple.py | import dolfin as df
mesh = df.UnitIntervalMesh(1)
V = df.VectorFunctionSpace(mesh, "CG", 1, dim=3)
f = df.Function(V)
f.assign(df.Expression(("1", "2", "3")))
print f.vector().array()
| 186 | 19.777778 | 48 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/instant/norm_test.py | from dolfin import *
import instant
cpp_code = """
void dabla(dolfin::Vector& a, dolfin::Vector& b, double c, double d) {
for (unsigned int i=0; i < a.size(); i++) {
b.setitem(i, d*a[i] + c);
}
}
"""
include_dirs, flags, libs, libdirs = instant.header_and_libs_from_pkgconfig("dolfin")
headers= ["do... | 1,047 | 25.871795 | 125 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/instant/dolfin_test_foo.py |
"This demo program demonstrates how to include additional C++ code in DOLFIN."
# Copyright (C) 2013 Kent-Andre Mardal, Mikael Mortensen, Johan Hake
#
# This file is part of DOLFIN.
#
# DOLFIN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as publi... | 1,274 | 30.097561 | 78 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/local-arrays/parallel-with-coord.py | """
Script to investigate the ordering process for Dolphin
meshes with periodic boundary conditions.
Want to assert that a local process contains the full
vector for each node and that they are not distributed.
"""
print "Hello World"
import dolfin as df
import numpy as np
# Explicit - do not reorder
df.parameters.r... | 2,777 | 34.615385 | 95 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/local-arrays/parallel-with-rank.py |
print "Hello World"
import dolfin as df
mpi_world = df.mpi_comm_world()
rank = df.MPI.rank(mpi_world)
size = df.MPI.size(mpi_world)
me_str = "{}/{}".format(rank, size)
print("I am " + me_str)
#df.parameters.reorder_dofs_serial = False
nx = ny = 1
mesh = df.RectangleMesh(0, 0, 1, 1, nx, ny)
V = df.VectorFunctionSpace... | 526 | 26.736842 | 84 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/local-arrays/parallel-with-coord-and-map.py | """
Script to investigate the ordering process for Dolphin
meshes with periodic boundary conditions.
Want to assert that a local process contains the full
vector for each node and that they are not distributed.
"""
print "Hello World"
import dolfin as df
import numpy as np
#df.parameters.reorder_dofs_serial = False
... | 3,092 | 32.258065 | 122 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/local-arrays/parallel.py | from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
print("Hello World from {}/{}".format(rank, size))
import dolfin as df
#df.parameters.reorder_dofs_serial = False
nx = ny = 10
mesh = df.RectangleMesh(df.Point(0, 0), df.Point(1, 1), nx, ny)
V = df.VectorFunctionSpace(mesh, '... | 568 | 28.947368 | 88 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/writing_and_reading_meshes/write_mesh.py | from dolfin import *
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
print "This is process {}/{}".format(rank, size)
from common import mesh
F = HDF5File('meshfile_{:02d}.h5'.format(size), 'w')
F.write(mesh, 'mymesh')
print "Process {}/{} has written the mesh.".format(ran... | 329 | 21 | 62 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/writing_and_reading_meshes/common.py | from dolfin import *
nx = 2
ny = 2
nz = 2
mesh = UnitCubeMesh(nx, ny, nz)
| 76 | 8.625 | 31 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/writing_and_reading_meshes/read_mesh.py | import sys
from dolfin import *
from mpi4py import MPI
try:
meshfilename = sys.argv[1]
except IndexError:
print "Error: expecting meshfilename as first argument."
sys.exit(0)
G = HDF5File(meshfilename, 'r')
mesh2 = Mesh()
G.read(mesh2, 'mymesh')
from common import mesh
def sort_nested(lst, level=1):
... | 1,825 | 28.934426 | 90 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/writing_and_reading_meshes/read_mesh_serial.py | import sys
from dolfin import *
try:
meshfilename = sys.argv[1]
except IndexError:
print "Error: expecting meshfilename as first argument."
sys.exit(0)
G = HDF5File(meshfilename, 'r')
mesh2 = Mesh()
G.read(mesh2, 'mymesh')
from common import mesh
def sort_nested(lst, level=1):
"""
Sort a list of... | 1,461 | 25.107143 | 60 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/writing_and_reading_meshes/write_mesh_serial.py | from dolfin import *
from common import mesh
F = HDF5File('meshfile_serial.h5', 'w')
F.write(mesh, 'mymesh')
| 110 | 17.5 | 39 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/exercises/cells_distribution.py | #!/usr/bin/env python
"""
A short example to show how the nodes are distributed on processes
without the knowledge of the data details. To run this script,
mpirun -n 8 python cells_distribution.py
"""
import dolfin as df
mpi_world = df.mpi_comm_world()
rank = df.MPI.rank(mpi_world)
size = df.MPI.size(mpi_w... | 1,196 | 23.9375 | 80 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/exercises/map_dof_rank.py | """
Visuale distribution of degrees of freedom.
Invoke with
`mpirun -np N python map_dof_rank.py`
to run with N processes. Creates a `color_map.pvd` file which you can open with
paraview. When the --plot option is set, it will also display plots to screen.
"""
import argparse
import dolfin as df
from mpi4py imp... | 1,577 | 26.684211 | 97 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/parallel/computing_the_maximum_value_of_a_dolfin_vector/compute_max_of_vector.py | #!/usr/bin/env python
import dolfin as df
# Define a non-constant function with unique entries.
mesh = df.IntervalMesh(100, 0, 10)
V = df.FunctionSpace(mesh, 'CG', 1)
f = df.interpolate(df.Expression('x[0]'), V, degree=1)
rank = df.cpp.common.MPI.rank(df.mpi_comm_world())
size = df.cpp.common.MPI.size(df.mpi_comm_wo... | 635 | 34.333333 | 98 | py |
finmag | finmag-master/dev/sandbox/basics-dolfin/map/example.py | import numpy as np
def v2d_xxx_from_xyz(v2d):
"""
Return the vertex to dof map in the form
v2d_xxx = [x0, x1, x2 , ... y0, y1, y2, ..., z0, z1, z2, ... ]
using the vertex to dof map in the form (we are assuming this)
v2d = [x0, y0, z0, x1 , y1, z1, x2, y2, z2, ... ]
"""
# C... | 4,558 | 27.49375 | 90 | py |
finmag | finmag-master/dev/sandbox/treecode_bem/setup.py | from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
import os
#python setup.py build_ext --inplace
#NFFT_DIR = os.path.expanduser('~/nfft-3.2.0')
ext_modules = [
Extension("fastsum_lib",
sources = ['fast_sum.c','fast_sum_lib... | 602 | 22.192308 | 58 | py |
finmag | finmag-master/dev/sandbox/treecode_bem/fastdemag.py | import logging
import dolfin as df
import numpy as np
import finmag
import finmag.util.solver_benchmark as bench
import finmag.energies.demag.solver_base as sb
from finmag.util.timings import timings, mtimed
import time
from fastsum_lib import FastSum
from fastsum_lib import compute_solid_angle_single
from fastsum_... | 5,815 | 31.49162 | 88 | py |
finmag | finmag-master/dev/sandbox/benchmarks/updating_expression_simple.py | import time
import math
import dolfin as df
import numpy as np
"""
This script works with dolfin 1.0.1.
In dolfin 1.1.0, the ordering of degrees of freedom does not correspond
to geometrical structures such as vertices anymore. This has to be
investigated further. For now, the re-ordering can be turned off using
the... | 2,015 | 28.217391 | 115 | py |
finmag | finmag-master/dev/sandbox/benchmarks/simple_timer.py | import time
class SimpleTimer():
"""
A simple timer which can be used as a context manager.
Usage example:
benchmark = SimpleTimer()
with benchmark:
do_stuff()
print benchmark.elapsed
A SimpleTimer instance can be reused.
"""
def __init__(self):
s... | 546 | 19.259259 | 58 | py |
finmag | finmag-master/dev/sandbox/benchmarks/test_method_efficiency.py | import dolfin as df
import time
from finmag.energies.anisotropy import UniaxialAnisotropy as ani
from finmag.energies.exchange import Exchange as exch
import numpy as np
def efficiency_test(method, n, field='exchange'):
"""
Test the efficiency of different methods
implemented in the different energy classe... | 4,546 | 27.597484 | 83 | py |
finmag | finmag-master/dev/sandbox/benchmarks/vector_initialisation.py | #!/usr/bin/python
import numpy as np
import dolfin as df
import timeit
df.parameters.reorder_dofs_serial = False # for dolfin 1.1.0
# Define a rectangular mesh and a vector-function space on it
n1 = 100
n2 = 40
n3 = 25
print "Initialising mesh and function space..."
mesh = df.UnitCubeMesh(n1, n2, n3)
S3 = df.Vecto... | 1,835 | 31.785714 | 126 | py |
finmag | finmag-master/dev/sandbox/benchmarks/demag_tolerances.py | import dolfin as df
from finmag.energies.demag.fk_demag import FKDemag
from finmag.util.meshes import sphere
from simple_timer import SimpleTimer
# nmag, dict ksp_tolerances in Simulation class constructor
# apparently gets passed to petsc http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetTolerance... | 1,713 | 38.860465 | 119 | py |
finmag | finmag-master/dev/sandbox/benchmarks/updating_expression.py | import numpy as np
import dolfin as df
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from math import sin
from simple_timer import SimpleTimer
benchmark = SimpleTimer()
"""
The goal is to compute the values of f(r, t) = sin(x) * sin(t) on a mesh for
different points in time. The cost of upda... | 4,038 | 31.312 | 88 | py |
finmag | finmag-master/dev/sandbox/cross_product/llg_example.py | import dolfin as df
import time
mesh = df.UnitSquareMesh(200, 200)
print mesh
S1 = df.FunctionSpace(mesh, 'CG', 1)
S3 = df.VectorFunctionSpace(mesh, 'CG', 1, 3)
u = df.TrialFunction(S3)
v = df.TestFunction(S3)
m = df.Function(S3) # magnetisation
Heff = df.Function(S3) # effective field
Ms = df.Function(S1) # satur... | 1,400 | 28.1875 | 107 | py |
finmag | finmag-master/dev/sandbox/cross_product/benchmark.py | """
An example code that computes the cross product of two dolfin functions.
This should be replaced in the parts of the code where dmdt is computed.
"""
import dolfin as df
import time
mesh = df.IntervalMesh(1000, 0, 1)
S3 = df.VectorFunctionSpace(mesh, 'CG', 1, 3)
a = df.Function(S3)
b = df.Function(S3)
a.assign(df... | 852 | 26.516129 | 146 | py |
finmag | finmag-master/dev/sandbox/cross_product/using_cpp.py | import time
import dolfin as df
from finmag.physics.equation import Equation
mesh = df.UnitSquareMesh(200, 200)
S1 = df.FunctionSpace(mesh, "CG", 1)
S3 = df.VectorFunctionSpace(mesh, "CG", 1, dim=3)
alpha = df.Function(S1)
m = df.Function(S3)
H = df.Function(S3)
dmdt = df.Function(S3)
alpha.assign(df.Constant(1))
m.... | 625 | 19.866667 | 52 | py |
finmag | finmag-master/dev/sandbox/cross_product/fem_cross.py | import time
import dolfin as df
mesh = df.UnitIntervalMesh(5)
V = df.VectorFunctionSpace(mesh, "CG", 1, dim=3)
u = df.TrialFunction(V)
v = df.TestFunction(V)
f = df.Function(V)
g = df.Function(V)
fxg = df.Function(V)
f.assign(df.Constant((1, 0, 0)))
g.assign(df.Constant((0, 1, 0)))
# FINITE ELEMENT METHOD
# but dP ... | 1,143 | 20.584906 | 59 | py |
finmag | finmag-master/dev/sandbox/cross_product/cross_product.py | """
An example code that computes the cross product of two dolfin functions.
This should be replaced in the parts of the code where dmdt is computed.
"""
import dolfin as df
from distutils.version import LooseVersion
if LooseVersion(df.__version__) < LooseVersion('1.5.0'):
raise RuntimeError("This script requires ... | 1,009 | 31.580645 | 154 | py |
finmag | finmag-master/dev/sandbox/gpu/cupstest.py | from dolfin import *
from time import time
import math, random
#from finmag.util.meshes import from_geofile
def run_test():
solver = KrylovSolver("cg", "jacobi")
mesh = Box(0,0,0,30,30,100,10,10,30)
#mesh = Mesh(convert_mesh("bar.geo"))
#mesh = UnitCubeMesh(32,32,32)
V = FunctionSpace(mesh, "CG", ... | 952 | 24.078947 | 50 | py |
finmag | finmag-master/dev/sandbox/gpu/finmag_backends.py | import os, time
import dolfin as df
from finmag.util.timings import default_timer
from finmag import Simulation
from finmag.energies import Exchange, Demag
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
# Run the nmag2 example on PETSc and PETScCUSP and compare timings
def run_finmag():
# Setup
setupstart... | 1,491 | 30.744681 | 81 | py |
finmag | finmag-master/dev/sandbox/bulkdmi_direct/run.py | import os
import logging
import pylab as p
import numpy as np
import dolfin as df
df.parameters.reorder_dofs_serial = False
from dolfin import *
from finmag import Simulation as Sim
from finmag.field import Field
from finmag.energies import Exchange, Demag, DMI
from finmag.util.meshes import from_geofile, mesh_volum... | 1,611 | 19.666667 | 94 | py |
finmag | finmag-master/dev/sandbox/numpy/sundials_ode.py | import os
import numpy as np
from finmag.native import sundials
def call_back(t, y):
return y**2-y**3
class Test_Sundials(object):
def __init__(self, call_back, x0):
self.sim = call_back
self.x0 = x0
self.x = x0.copy()
self.ode_count = 0
... | 1,599 | 22.880597 | 72 | py |
finmag | finmag-master/dev/sandbox/numpy/test_ode.py | import os
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
from sundials_ode import Test_Sundials
from sundials_ode import call_back
def plot_data(ts,ys):
fig=plt.figure()
plt.plot(ts, ys, '.-')
#plt.legend()
plt.grid()
fig.savefig(... | 645 | 13.355556 | 47 | py |
finmag | finmag-master/dev/sandbox/numpy/test_weiwei_bug.py | import numpy as np
"""
h2 = h - np.dot(h,t)*t + sf*t
self.Heff[i][:] = h2[:]
where h, t are 1d numpy arrays, and sf is a double number, if I change the code to,
h2 = np.dot(h,t)*t
h3 = h - h2 + sf*t
self.Heff[i][:] = h3[:]
does anyone know why h2 = h - np.dot(h,t)*t + sf*t is not safe? Weiwei
"""
def test_d... | 745 | 17.65 | 83 | py |
finmag | finmag-master/dev/sandbox/baryakhter/example.py | import dolfin as df
import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import time
from baryakhtar import LLB
from finmag.energies import Zeeman
from finmag.energies import Demag
from exchange import Exchange
from finmag import Simulation as Sim
import finmag.energies as fe
#... | 3,340 | 19.496933 | 58 | py |
finmag | finmag-master/dev/sandbox/baryakhter/compare_fd_fem_laplace.py | from dolfin import *
import numpy as np
def Laplace_FD_2d(mesh,u_e,gridm,gridn):
data=mesh.coordinates()
m,n=data.shape
assert((gridm+1)*(gridn+1)==m)
x=data[:,0]
y=data[:,1]
x=x.reshape((gridm+1,gridn+1),order='F')
y=y.reshape((gridm+1,gridn+1),order='F')
u=u_e.vector().array().reshap... | 2,272 | 26.059524 | 70 | py |
finmag | finmag-master/dev/sandbox/baryakhter/exchange.py | import dolfin as df
import numpy as np
import logging
from finmag.util.consts import mu0
from aeon import timer
from finmag.native import llg as native_llg
logger=logging.getLogger('finmag')
class Exchange(object):
def __init__(self, C, chi=1, in_jacobian=True):
self.C = C
self.chi = chi
... | 1,895 | 26.478261 | 86 | py |
finmag | finmag-master/dev/sandbox/baryakhter/simple_demag.py | import logging
import numpy as np
import dolfin as df
from finmag.util import helpers
logger = logging.getLogger('finmag')
class SimpleDemag(object):
"""
Demagnetising field for thin films in the i-direction.
Hj = Hk = 0 and Hi = - Mi.
"""
def __init__(self, Ms, Nx=0, Ny=0.5, Nz=0.5, in_jacobian... | 1,636 | 26.283333 | 88 | py |
finmag | finmag-master/dev/sandbox/baryakhter/baryakhtar_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.energies import Zeeman
from finmag.energies import Demag
from sandbox.baryakhter.baryakhtar import LLB
from sandbox.baryakhter.exchange import Exchange
MODULE_DIR = os.path.dirname(os.pa... | 1,765 | 23.527778 | 79 | py |
finmag | finmag-master/dev/sandbox/baryakhter/baryakhtar_example.py | import dolfin as df
import numpy as np
import scipy.integrate.ode as scipy_ode
import matplotlib.pyplot as plt
import time
from finmag.drivers.llg_integrator import llg_integrator
from llb import LLB
from finmag.energies import Zeeman
from test_exchange import BaryakhtarExchange
def cross_times(a,b):
assert(... | 4,070 | 22.668605 | 70 | py |
finmag | finmag-master/dev/sandbox/baryakhter/baryakhtar.py | import logging
import numpy as np
import dolfin as df
from finmag.util import helpers
import finmag.util.consts as consts
from finmag.util.fileio import Tablewriter
from finmag.native import sundials
from finmag.native import llg as native_llg
from finmag.util.timings import default_timer
from finmag.energies import... | 10,120 | 31.543408 | 105 | py |
finmag | finmag-master/dev/sandbox/baryakhter/__init__.py | 0 | 0 | 0 | py | |
finmag | finmag-master/dev/sandbox/baryakhter/llb.py | import logging
import numpy as np
import scipy
import dolfin as df
import finmag.util.helpers as h
import finmag.util.consts as consts
from finmag.native import llg as native_llg
from finmag.util.timings import mtimed, default_timer
#default settings for logger 'finmag' set in __init__.py
#getting access to logger ... | 14,236 | 31.065315 | 144 | py |
finmag | finmag-master/dev/sandbox/baryakhter/anisotropy.py | import dolfin as df
import logging
from finmag.util.timings import mtimed
from finmag.util.consts import mu0
logger = logging.getLogger('finmag')
class UniaxialAnisotropy(object):
def __init__(self, K1, axis):
self.K1=K1
self.axis = df.Constant(axis)
@mtimed
def setup(self, S3, M, Ms0, unit_length... | 1,355 | 24.584906 | 84 | py |
finmag | finmag-master/dev/sandbox/new_energy_classes/test_zeeman.py | import dolfin as df
import numpy as np
from finmag.util.consts import mu0
from finmag import sim_with, Field
np.set_printoptions(precision=2)
def generate_random_vectors(num=10, length=1.0):
v = np.random.random_sample((num, 3))
v_norms = np.linalg.norm(v, axis=1)
return length * v / v_norms[:, np.newaxi... | 6,130 | 36.384146 | 107 | py |
finmag | finmag-master/dev/sandbox/airbox/test_airbox.py | import os
import dolfin as df
import matplotlib.pyplot as plt
from finmag.util.meshes import from_geofile, plot_mesh_regions
from finmag.util.helpers import piecewise_on_subdomains
from finmag import sim_with
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
def test_two_regions_with_same_Ms():
"""
Def... | 2,138 | 35.87931 | 76 | py |
finmag | finmag-master/dev/sandbox/energy_density/run_nmag.py | import nmag
from nmag import SI
mat_Py = nmag.MagMaterial(name="Py",
Ms=SI(0.86e6,"A/m"),
exchange_coupling=SI(13.0e-12, "J/m"),
llg_damping=0.5)
sim = nmag.Simulation("bar")
sim.load_mesh("coarse_bar.nmesh.h5",
[("Py", mat_P... | 944 | 25.25 | 82 | py |
finmag | finmag-master/dev/sandbox/energy_density/extract_oommf.py | import os
import numpy as np
from finmag.util.oommf.ovf import OVFFile
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
EPSILON = 1e-15
bar_size = (30e-9, 30e-9, 100e-9)
bar_x_mid = bar_size[0]/2; bar_y_mid = bar_size[1]/2; bar_z_mid = bar_size[2]/2;
def extract_line_across_scalar_field(ovf_filename, txt_file... | 1,505 | 39.702703 | 107 | py |
finmag | finmag-master/dev/sandbox/energy_density/run_finmag.py | import numpy as np
import pylab as p
from dolfin import Mesh
from finmag.sim.llg import LLG
from finmag.drivers.llg_integrator import llg_integrator
# Create mesh
mu = 1e-9
mesh = Mesh("coarse_bar.xml.gz")
#mesh = Mesh("bar.xml.gz")
# Setup LLG
llg = LLG(mesh, unit_length=mu)
llg.Ms = 0.86e6
llg.A = 13.0e-12
llg.alph... | 1,788 | 26.523077 | 84 | py |
finmag | finmag-master/dev/sandbox/energy_density/anisotropy/finmag_anisotropy.py | import numpy as np
import dolfin as df
from finmag.sim.anisotropy import UniaxialAnisotropy
TOL = 1e-15
def test_anisotropy_energy_density():
"""
Written in sperical coordinates, the equation for the
anisotropy energy density reads
E/V = K*sin^2(theta),
where theta is the angle between the m... | 1,482 | 28.66 | 63 | py |
finmag | finmag-master/dev/sandbox/energy_density/anisotropy/nmag_anisotropy.py | import numpy as np
import nmag
from nmag import SI
import nmeshlib.unidmesher as unidmesher
mesh_unit = SI(1e-9, "m") # mesh unit (1 nm)
layers = [(0.0, 1.0)] # the mesh
discretization = 0.2 # discretization
def m0(r):
"""Initial magnetisation 45 degrees between x- and z-axis."""
return [1/np.s... | 897 | 27.967742 | 97 | py |
finmag | finmag-master/dev/sandbox/xdmf_and_hdf5/parallel-xdmf-mesh-and-vector/output.py |
from dolfin import *
mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, 'CG', 1)
u = interpolate(Expression('x[0]'), V)
f = File('mesh.xdmf')
f << mesh
print("mesh we have written: {}".format(mesh.coordinates().shape))
del f
fu = File('u.xdmf')
fu << u
print("u we have written: {}".format(u.vector().array().shap... | 334 | 14.227273 | 66 | py |
finmag | finmag-master/dev/sandbox/xdmf_and_hdf5/parallel-xdmf-mesh-and-vector/input.py |
from dolfin import *
mesh2 = Mesh("mesh.xdmf")
print("Mesh we have read: {}".format(mesh2.coordinates().shape))
print("Can't read back from xdmf file, see\nhttps://answers.launchpad.net/dolfin/+question/222230 ")
#V2 = FunctionSpace(mesh2, 'CG', 1)
#u2 = Function(V2, 'u.xdmf')
#u << f
#print "vector we have read: {... | 365 | 25.142857 | 100 | py |
finmag | finmag-master/dev/sandbox/xdmf_and_hdf5/parallel-hdf5-mesh-and-vector/output.py | from dolfin import *
mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, 'CG', 1)
u = interpolate(Expression('x[0]'), V)
f = HDF5File(mesh.mpi_comm(), 'u.h5', 'w') # works
f.write(mesh, 'mesh')
print "mesh we have written: {}".format(mesh.coordinates().shape)
f.write(u, 'u')
print "vector we have written: {}".for... | 358 | 21.4375 | 67 | py |
finmag | finmag-master/dev/sandbox/xdmf_and_hdf5/parallel-hdf5-mesh-and-vector/input.py | from dolfin import *
mesh2 = Mesh()
f2 = HDF5File(mesh2.mpi_comm(), 'u.h5', 'r')
# The 3rd parameter in df.HDF5File.read is use_partition_from_file.
# When dolfin runs in parallel the mesh is divided/partitioned and
# each process has a one partition. When a mesh is saved in parallel
# the details of how the mesh i... | 777 | 34.363636 | 68 | py |
finmag | finmag-master/dev/sandbox/bugs/erratic_spins_and_increasing_energy/energy.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 1,675 | 21.052632 | 76 | py |
finmag | finmag-master/dev/sandbox/bugs/energy/exchange/energy.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 1,523 | 20.166667 | 76 | py |
finmag | finmag-master/dev/sandbox/bugs/energy/demag/energy.py | import numpy as np
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman, UniaxialAnisotropy
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
from finmag.util.f... | 1,858 | 19.428571 | 76 | py |
finmag | finmag-master/dev/sandbox/bugs/too-many-open-files/many-simulation-objects.py | import os
import psutil # sudo apt-get install python-psutils
import dolfin as df
import finmag
# get handle to this process
p = psutil.Process(os.getpid())
def openfiles():
return p.get_open_files()
def openfilescount():
return len(openfiles())
def create_finmag_sim_object(name):
mesh = df.UnitInter... | 801 | 20.675676 | 75 | py |
finmag | finmag-master/dev/sandbox/bugs/too-many-open-files/counting-simulations-prototype.py | class Simulation(object):
max_instance_counter = 0
instances = {}
def __init__(self):
self.id = Simulation.max_instance_counter
Simulation.max_instance_counter += 1
assert self.id not in Simulation.instances.keys()
Simulation.instances[self.id] = self
def __str__(self)... | 2,562 | 27.797753 | 77 | py |
finmag | finmag-master/dev/sandbox/parallel_dolfin_integration/array_integrator_parallel.py | # This script attempts to solve an unphysical Temperature (T)-based dolfin
# problem within an array-based integrator. It initialises a gaussian, and
# decays all values independently.
#
# Written for dolfin 1.6.0.
#
# Run with mpirun -n 2 python array_intergrator_parallel.py.
import dolfin as df
import dolfinh5tools
... | 6,663 | 32.656566 | 93 | py |
finmag | finmag-master/dev/sandbox/parallel_dolfin_integration/load_array_integrator_parallel_data.py | import matplotlib.pyplot as plt
from dolfinh5tools import openh5
hFile = openh5("array_integrator_parallel", mode="r")
plt.plot(hFile.read(t=0, field_name="T").vector().array())
plt.plot(hFile.read(t=1, field_name="T").vector().array())
plt.show()
| 249 | 30.25 | 58 | py |
finmag | finmag-master/dev/sandbox/parallel_dolfin_integration/integrators.py | # This library includes some functions for integrating arrays.
def euler(Tn, dTndt, tStep):
"""
Performs Euler integration to obtain T_{n+1}.
Arguments:
Tn: Array-like representing Temperature at time t_n.
dTndt: Array-like representing dT/dt at time t_n.
tStep: Float determining the ... | 416 | 26.8 | 62 | py |
finmag | finmag-master/dev/sandbox/hysteresis/hysteresis_example.py | import dolfin as df
from numpy import linspace
from math import cos, sin, pi
from finmag import sim_with
from finmag.util.meshes import ellipsoid
r1 = 30.0
r2 = 10.0
r3 = 10.0
maxh = 3.0
Ms = 1e6 # A/m
A = 13.0e-12 # J/m
alpha = 1.0 # large damping for quick convergence
H = 1e6 # external fi... | 817 | 30.461538 | 159 | py |
finmag | finmag-master/dev/sandbox/hysteresis/hysteresis_loop_example.py | import matplotlib
matplotlib.use('Agg')
from numpy import array
from finmag import sim_with
from finmag.util.meshes import ellipsoid
import matplotlib.pyplot as plt
import sys
import logging
logger = logging.getLogger("finmag")
# This example essentially reproduces Example 2.3 in the nmag manual;
# see: http://nmag.s... | 1,534 | 30.326531 | 191 | py |
finmag | finmag-master/dev/sandbox/timeintegration/macrospin_ode_jac.py | from dolfin import *
from scipy.integrate import ode
from numpy import linspace
from values import c, M0
set_log_level(21)
m = 1e-5
mesh = Box(0,m,0,m,0,m,1,1,1)
# Functions
V = VectorFunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
# Parameters
alpha = 0.5
gamma = 2.211e5
p = Constant(gamma/(1... | 1,149 | 16.96875 | 70 | py |
finmag | finmag-master/dev/sandbox/timeintegration/macrospin_odeint_nojac.py | from dolfin import *
from scipy.integrate import odeint
from numpy import linspace
from values import c, M0
set_log_level(21)
m = 1e-5
mesh = Box(0,m,0,m,0,m,1,1,1)
# Functions
V = VectorFunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
# Parameters
alpha = 0.5
gamma = 2.211e5
p = Constant(gamma... | 971 | 17.692308 | 61 | py |
finmag | finmag-master/dev/sandbox/timeintegration/timings.py | import commands, time, sys
files = ['macrospin_odeint_nojac', 'macrospin_odeint_jac', 'macrospin_ode_nojac', 'macrospin_ode_jac']
names = ['odeint', 'odeint with jacobian', 'ode', 'ode with jacobian']
for nr, f in enumerate(files):
cmd = 'python %s.py' % (f)
# Run all scripts once before timing starts, to av... | 754 | 31.826087 | 102 | py |
finmag | finmag-master/dev/sandbox/timeintegration/macrospin_odeint_jac.py | from dolfin import *
from scipy.integrate import odeint
from numpy import linspace
from values import c, M0
set_log_level(21)
m = 1e-5
mesh = Box(0,m,0,m,0,m,1,1,1)
# Functions
V = VectorFunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
# Parameters
alpha = 0.5
gamma = 2.211e5
p = Constant(gamma... | 1,050 | 17.438596 | 58 | py |
finmag | finmag-master/dev/sandbox/timeintegration/conflicting_ode_odeint_exchange.py | from dolfin import *
from finmag.sim.exchange import Exchange
from numpy import linspace
from scipy.integrate import odeint, ode
set_log_level(21)
# FIXME: Figure out of this extreme inconsistency between ode and odeint
# FIXME: Make odeint convert when using jacobian
# FIXME: Make odeint convert when adding applied ... | 2,558 | 23.141509 | 77 | py |
finmag | finmag-master/dev/sandbox/timeintegration/values.py | from dolfin import *
def c():
return 1e8
def M0():
Ms = 1e8
return Ms, Constant((0.8*Ms, -0.1*Ms*2, 0.1*Ms*0))
| 126 | 11.7 | 54 | py |
finmag | finmag-master/dev/sandbox/timeintegration/macrospin_ode_nojac.py | from dolfin import *
from scipy.integrate import ode
from numpy import linspace
from values import c, M0
set_log_level(21)
m = 1e-5
mesh = Box(0,m,0,m,0,m,1,1,1)
# Functions
V = VectorFunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
# Parameters
alpha = 0.5
gamma = 2.211e5
p = Constant(gamma/(1... | 1,066 | 17.084746 | 68 | py |
finmag | finmag-master/dev/sandbox/timeintegration/jacobian_test/reduced_problem.py | from dolfin import *
import finmag.util.consts as consts
# Mesh and functionspace
L = 10e-9 # 10 nm
mesh = Box(0,0,0,L,L,L,4,4,4)
V = VectorFunctionSpace(mesh, 'CG', 1)
# Parameters
alpha = 0.02
gamma = consts.gamma
# Initial magnetisation
m0_tuple = (("1",
"5 * pow(cos(pi * (x[0] * pow(10, 9) - 11) / ... | 1,066 | 23.813953 | 76 | py |
finmag | finmag-master/dev/sandbox/timeintegration/jacobian_test/applied_exchange_anisotropy.py | from dolfin import *
import numpy as np
import finmag.util.consts as consts
# Mesh and functionspace
x0 = 0; x1 = 15e-9; nx = 30;
y0 = -4.5e-9; y1 = 4.5e-9; ny = 18;
z0 = -0.1e-9; z1 = 0.1e-9; nz = 1;
mesh = Box(x0, y0, z0, x1, y1, z1, nx, ny, nz)
V = VectorFunctionSpace(mesh, 'Lagrange', 1, dim=3)
# Parameters
Ms =... | 1,422 | 23.534483 | 88 | py |
finmag | finmag-master/dev/sandbox/timeintegration/c-dolfin-compare/dolfin-spinwave2.py | from dolfin import *
import instant
from finmag.energies import Exchange
from scipy.integrate import ode
import finmag.util.helpers as h
import finmag.util.consts as consts
import os
import numpy as np
set_log_level(21)
def m_average(y, V, vol):
m = Function(V)
m.vector()[:] = y
mx = assemble(dot(m, Cons... | 2,980 | 24.698276 | 77 | py |
finmag | finmag-master/dev/sandbox/timeintegration/c-dolfin-compare/c-spinwave.py | from dolfin import *
import instant
from finmag.energies import Exchange
from scipy.integrate import ode
import finmag.util.helpers as h
import finmag.util.consts as consts
import os
import numpy as np
def m_average(y, V, vol):
m = Function(V)
m.vector()[:] = y
mx = assemble(dot(m, Constant([1,0,0])) * dx... | 3,167 | 26.076923 | 77 | py |
finmag | finmag-master/dev/sandbox/timeintegration/c-dolfin-compare/dolfin-spinwave.py | from dolfin import *
import instant
from finmag.energies import Exchange
from scipy.integrate import ode
import finmag.util.helpers as h
import os
import numpy as np
set_log_level(21)
def m_average(y, V, vol):
m = Function(V)
m.vector()[:] = y
mx = assemble(dot(m, Constant([1,0,0])) * dx)
my = assemb... | 3,294 | 24.944882 | 77 | py |
finmag | finmag-master/dev/sandbox/timeintegration/c-dolfin-compare/dolfin-spinwave3.py | from dolfin import *
import instant
from finmag.energies import Exchange
from scipy.integrate import ode
import finmag.util.helpers as h
import finmag.util.consts as consts
import os
import numpy as np
parameters["linear_algebra_backend"] = "PETSc"
parameters["form_compiler"]["cpp_optimize"] = True
ffc_options = {"opt... | 3,171 | 25.881356 | 82 | py |
finmag | finmag-master/dev/sandbox/skyrmions/sw_analysis.py | import numpy as np
import pylab as plt
import matplotlib.cm as cm
file_name = 'output.npz'
threshold = 3000
def find_max(a, threshold=0.5):
index = []
for i in range(1,len(a)-1):
if a[i-1] < a[i] > a[i+1] and a[i]>threshold:
index.append(i)
return index
#load the file with tsim, mx, my... | 3,258 | 27.094828 | 85 | py |
finmag | finmag-master/dev/sandbox/skyrmions/sw_dmi.py | import dolfin as df
import numpy as np
import pylab as plt
from finmag.energies import Exchange, Zeeman, DMI
from finmag import Simulation as Sim
from math import pi
def plot_excitation(tsinc, Hsinc):
"""Plot the external excitation signal both in time and frequency domain."""
#time domain
plt.subplot(211)... | 3,733 | 27.075188 | 80 | py |
finmag | finmag-master/dev/sandbox/skyrmions/skyrmion_dispersion.py | import numpy as np
import dolfin as df
from finmag import Simulation
from finmag.energies import Exchange, DMI, Demag, Zeeman
from finmag.energies.zeeman import TimeZeemanPython
import matplotlib.pyplot as plt
Rx = 5445
Ry = 60
Nx = 2178
Ny = 24
mesh = df.RectangleMesh(0,0,Rx,Ry,Nx,Ny)
def m_init_fun(pos):
retur... | 3,783 | 20.622857 | 77 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.