Skip to content

Commit ad5de56

Browse files
authored
Merge pull request #140 from computationalmodelling/fmm
FMM Code
2 parents b70bea1 + a6a106f commit ad5de56

30 files changed

+10233
-41
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*.pdf
77
*.tmp
88
*.so
9+
*.o
10+
911
local/
1012
*~
1113
*.bak
@@ -51,3 +53,4 @@ test-reports
5153

5254
*.npz
5355
*.npy
56+
fmm.cpp

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
- docker
88

99
before_install:
10-
- docker build -t fidimag -f ./docker/travis/Dockerfile .
10+
- travis_wait 90 docker build -t fidimag -f ./docker/travis/Dockerfile .
1111
- docker run -ti -d --name fidimag fidimag
1212

1313
jobs:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PYTEST = ${PYTHON} -m pytest
88
#####################
99

1010
build:
11-
${PYTHON} setup.py build_ext --inplace
11+
${PYTHON} setup.py build_ext --inplace -j2
1212

1313
clean:
1414
rm -rf ${EXTENSIONS_DIR}/*

bin/install-fftw.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ download_and_install() {
3636
./configure --quiet --enable-shared --enable-openmp --enable-sse2 --enable-avx --prefix=${LIBS_DIR}
3737
echo "Compiling and installing "${1}"."
3838
{
39-
make
39+
make -j2
4040
make install
4141
} > /dev/null
4242
echo "Done."

bin/install-sundials.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ download_and_cmake_install() {
3939

4040
echo "Compiling and installing "${1}"."
4141
{
42-
make
42+
make -j2
4343
make install
4444
} > /dev/null
4545

docker/travis/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:16.04
1+
FROM ubuntu:18.04
22

33
# To build this image `docker build -t fidimag .`
44
# Then you can drop into a live bash shell with `docker run -it fidimag`.

fidimag/atomistic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .exchange import UniformExchange, Exchange
33
from .anisotropy import Anisotropy, CubicAnisotropy
44
from .zeeman import Zeeman, TimeZeeman
5-
from .demag import Demag
5+
from .demag import Demag, DemagFMM
66
from .demag_hexagonal import DemagHexagonal
77
from .hexagonal_mesh import HexagonalMesh
88
from .demag_full import DemagFull

fidimag/atomistic/demag.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import fidimag.extensions.dipolar as clib
22
import numpy as np
33
from .energy import Energy
4+
import numpy as np
5+
import fidimag
6+
from fidimag.atomistic.energy import Energy
7+
import fidimag.extensions.fmm as fmm
8+
import time
9+
import sys
410

511

612
class Demag(Energy):
@@ -41,7 +47,7 @@ def __init__(self, calc_every=0, name='Demag'):
4147

4248
def setup(self, mesh, spin, mu_s, mu_s_inv):
4349
super(Demag, self).setup(mesh, spin, mu_s, mu_s_inv)
44-
50+
4551
# Ryan Pepper 04/04/2019
4652
# We *do not* need to scale by mesh.unit_length**3 here!
4753
# This is because in the base energy class, dx, dy and dz
@@ -94,3 +100,39 @@ def compute_energy(self):
94100
self.energy /= self.scale
95101

96102
return energy / self.scale
103+
104+
105+
class DemagFMM(Energy):
106+
def __init__(self, order, ncrit, theta, name="DemagFMM", type='fmm'):
107+
self.type = type
108+
if self.type == 'fmm':
109+
self._type = 0
110+
elif self.type == 'bh':
111+
self._type = 1
112+
113+
self.name = name
114+
assert order > 0, "Order must be 1 or higher"
115+
assert order < 11, "Order bust be < 11"
116+
self.order = order
117+
assert ncrit >= 2, "ncrit must be greater than 1."
118+
self.ncrit = ncrit
119+
assert theta >= 0.0, "theta must be >= 0.0"
120+
self.theta = theta
121+
122+
def setup(self, mesh, spin, mu_s, mu_s_inv):
123+
super(DemagFMM, self).setup(mesh, spin, mu_s, mu_s_inv)
124+
self.coords = mesh.coordinates * mesh.unit_length
125+
self.m_temp = np.zeros_like(spin)
126+
self.fmm = fmm.FMM(self.n, self.ncrit, self.theta,
127+
self.order,
128+
self.coords,
129+
self.m_temp,
130+
self.mu_s, self._type
131+
)
132+
133+
def compute_field(self, t=0, spin=None):
134+
print('computing field')
135+
self.m_temp[:] = spin if spin is not None else self.spin
136+
self.fmm.compute_field(self.field)
137+
self.field *= -1e-7
138+
return self.field

0 commit comments

Comments
 (0)