Skip to content

Commit dddc72d

Browse files
committed
Merge branch 'master' of github.com:computationalmodelling/fidimag
2 parents 37da1ab + 09b5501 commit dddc72d

File tree

15 files changed

+758
-2032
lines changed

15 files changed

+758
-2032
lines changed

bin/install-scikit-odes.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# This script installs the python bindings to SUNDIALS called scikit ODES.
5+
# It requires SUNDIALS 2.6.2 to be installed.
6+
7+
echo "Installing dependencies."
8+
sudo apt-get install python-dev
9+
sudo pip install scipy numpy cython enum34
10+
11+
HERE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
12+
FIDIMAG_DIR="$(dirname "$HERE_DIR")"
13+
LIBS_DIR=${FIDIMAG_DIR}/local
14+
15+
echo "Downloading ODES to "${LIBS_DIR}"."
16+
mkdir -p ${LIBS_DIR}
17+
cd ${LIBS_DIR}
18+
19+
git clone git://github.com/bmcage/odes.git odes
20+
cd odes
21+
22+
# Paths to SUNDIALS are hardcoded in odes/scikits/odes/sundials/setup.py.
23+
# The README recommends to edit that file if you want to change the paths...
24+
25+
sed -i \
26+
"s|LIB_DIRS_SUNDIALS = \[base_path\,|LIB_DIRS_SUNDIALS = [base_path, '${LIBS_DIR}\/lib',|g" \
27+
scikits/odes/sundials/setup.py
28+
29+
python setup.py build
30+
sudo python setup.py install
31+
32+
cd ${HERE_DIR}

bin/install-sundials.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# This script installs any SUNDIALS version starting with version 2.6.0
5+
# when SUNDIALS moved to a CMake-based installation. Will install locally.
6+
# It may need environment variables to work, like `export CC=gcc` in ARCHER.
7+
8+
SUNDIALS=sundials-2.6.2
9+
10+
# Make sure CMake is installed, since SUNDIALS requires it.
11+
which cmake > /dev/null
12+
if [ $? -eq 0 ]
13+
then
14+
echo "Found CMake."
15+
else
16+
echo "CMake required to build SUNDIALS. Installing."
17+
sudo apt-get install cmake
18+
fi
19+
20+
HERE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
21+
FIDIMAG_DIR="$(dirname "$HERE_DIR")"
22+
LIBS_DIR=${FIDIMAG_DIR}/local
23+
24+
echo "Will install SUNDIALS to "${LIBS_DIR}" using CC="${CC}"."
25+
mkdir -p ${LIBS_DIR}
26+
cd ${LIBS_DIR}
27+
28+
download_and_cmake_install() {
29+
# $1 name of the package
30+
# $2 URL where ${1}.tar.gz can be obtained
31+
# $3 configure options
32+
if [ ! -e ${1}.tar.gz ]; then
33+
echo "Downloading "${1}"."
34+
wget -q ${2}/${1}.tar.gz
35+
fi;
36+
37+
if [ ! -e ${1} ]; then
38+
tar -xzf ${1}.tar.gz
39+
40+
echo "Configuring "${1}"."
41+
mkdir ${1}_build
42+
cd ${1}_build
43+
cmake ${3} ../${1}
44+
45+
echo "Compiling and installing "${1}"."
46+
{
47+
make
48+
make install
49+
} > /dev/null
50+
51+
echo "Cleaning up."
52+
cd ..
53+
rm -rf ${1}
54+
rm -rf ${1}_build
55+
56+
cd ${HERE_DIR}
57+
echo "Done."
58+
fi;
59+
}
60+
61+
download_and_cmake_install \
62+
${SUNDIALS} \
63+
http://computation.llnl.gov/projects/sundials-suite-nonlinear-differential-algebraic-equation-solvers/download \
64+
"-DBUILD_STATIC_LIBS=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="${LIBS_DIR}" -DEXAMPLES_ENABLE=OFF -DLAPACK_ENABLE=ON -DOPENMP_ENABLE=ON"

doc/ipynb/1d_domain_wall.ipynb

Lines changed: 231 additions & 709 deletions
Large diffs are not rendered by default.

doc/ipynb/tutorial-basics.ipynb

Lines changed: 219 additions & 1019 deletions
Large diffs are not rendered by default.

fidimag/atomistic/lib/clib.h

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,41 +79,10 @@ void compute_guiding_center(double *spin, int nx, int ny, int nz, double *res);
7979
void compute_px_py_c(double *spin, int nx, int ny, int nz,
8080
double *px, double *py);
8181

82+
//======================================================================
8283

83-
//=========================================================
84-
//=========================================================
85-
//used for sode
86-
typedef struct {
87-
int n;
84+
void llg_rhs_dw_c(double *m, double *h, double *dm, double *T, double *alpha,
85+
double *mu_s_inv, int *pins, double *eta, int n, double gamma, double dt);
8886

89-
double dt;
90-
double T;
91-
double gamma;
92-
double *mu_s;
93-
double coeff;
94-
double Q;
95-
96-
double theta;
97-
double theta1;
98-
double theta2;
99-
100-
double *dm1;
101-
double *dm2;
102-
double *eta;
103-
104-
} ode_solver;
105-
106-
void init_solver(ode_solver *s, double k_B, double theta,
107-
int n, double dt, double gamma);
108-
109-
ode_solver *create_ode_plan(void);
110-
111-
void finalize_ode_plan(ode_solver *plan);
112-
113-
void run_step1(ode_solver *s, double *m, double *h, double *m_pred, double *T,
114-
double *alpha, double *mu_s_inv, int *pins);
115-
116-
void run_step2(ode_solver *s, double *m_pred, double *h, double *m, double *T,
117-
double *alpha, double *mu_s_inv, int *pins);
11887

11988
#endif

fidimag/atomistic/lib/clib.pyx

Lines changed: 19 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ np.import_array()
44

55

66
cdef extern from "clib.h":
7-
8-
void gauss_random_vec_with_init(double *x, int n)
7+
void initial_random(int seed)
8+
void gauss_random_vec(double *x, int n)
99

1010
double skyrmion_number(double *spin, double *charge,
1111
int nx, int ny, int nz, int *ngbs)
@@ -70,32 +70,7 @@ cdef extern from "clib.h":
7070
double *alpha, int *pins, double *a_J, double beta, double gamma, int n)
7171

7272
# used for sllg
73-
ctypedef struct ode_solver:
74-
pass
75-
76-
ode_solver *create_ode_plan()
77-
78-
void init_solver(ode_solver *s, double k_B, double theta,
79-
int n, double dt, double gamma)
80-
81-
void finalize_ode_plan(ode_solver *plan)
82-
83-
void run_step1(ode_solver *s, double *m, double *h,
84-
double *m_pred, double *T, double *alpha,
85-
double *mu_s_inv, int *pins)
86-
87-
void run_step2(ode_solver *s, double *m_pred,
88-
double *h, double *m, double *T,
89-
double *alpha, double *mu_s_inv, int *pins)
90-
91-
def random_number(np.ndarray[double, ndim=1, mode="c"] v):
92-
cdef int n = len(v)
93-
94-
95-
print n
96-
97-
gauss_random_vec_with_init(&v[0], n)
98-
73+
void llg_rhs_dw_c(double *m, double *h, double *dm, double *T, double *alpha, double *mu_s_inv, int *pins, double *eta, int n, double gamma, double dt)
9974

10075

10176
def compute_skyrmion_number(np.ndarray[double, ndim=1, mode="c"] spin,
@@ -273,87 +248,22 @@ def normalise_spin(np.ndarray[double, ndim=1, mode="c"] spin, n):
273248
normalise(&spin[0], n)
274249

275250

251+
def init_random(seed):
252+
initial_random(seed);
276253

277-
cdef class RK2S(object):
278-
cdef ode_solver * _c_plan
279-
cdef double dt
280-
cdef update_fun
281-
cdef np.ndarray pred_m
282-
cdef np.ndarray field
283-
cdef np.ndarray mu_s_inv
284-
cdef np.ndarray T
285-
cdef np.ndarray alpha
286-
cdef np.ndarray pins
254+
def random_number_array(np.ndarray[double, ndim=1, mode="c"] v):
255+
256+
cdef int n = len(v)
287257

288-
cdef public double t
289-
cdef public int step
290-
cdef public np.ndarray y
258+
gauss_random_vec(&v[0], n)
291259

292-
def __cinit__(self,dt,n,gamma,k_B,theta,
293-
np.ndarray[double, ndim=1, mode="c"] mu_s_inv,
294-
np.ndarray[double, ndim=1, mode="c"] alpha,
295-
np.ndarray[double, ndim=1, mode="c"] spin,
296-
np.ndarray[double, ndim=1, mode="c"] field,
297-
np.ndarray[double, ndim=1, mode="c"] T,
298-
np.ndarray[int, ndim=1, mode="c"] pins,
299-
update_fun):
300-
301-
self.t = 0
302-
self.step = 0
303-
self.dt = dt
304-
305-
self.update_fun = update_fun
306-
self.mu_s_inv = mu_s_inv
307-
self.field = field
308-
self.T = T
309-
self.alpha = alpha
310-
self.pins = pins
311-
self.pred_m = numpy.zeros(3*n,dtype=numpy.float)
312-
self.y = numpy.zeros(3*n,dtype=numpy.float)
313-
314-
315-
self._c_plan = create_ode_plan()
316-
if self._c_plan is NULL:
317-
raise MemoryError()
318-
319-
init_solver(self._c_plan,k_B,theta,n,dt,gamma)
320-
321-
def __dealloc__(self):
322-
if self._c_plan is not NULL:
323-
finalize_ode_plan(self._c_plan)
324-
self._c_plan = NULL
325-
326-
def set_initial_value(self,np.ndarray[double, ndim=1, mode="c"] spin, t):
327-
self.t = t
328-
self.y[:] = spin[:]
329-
330-
def successful(self):
331-
#print self.spin
332-
return True
333-
334-
def run_step(self):
335-
cdef np.ndarray[double, ndim=1, mode="c"] y=self.y
336-
cdef np.ndarray[double, ndim=1, mode="c"] field=self.field
337-
cdef np.ndarray[double, ndim=1, mode="c"] pred_m=self.pred_m
338-
cdef np.ndarray[double, ndim=1, mode="c"] T=self.T
339-
cdef np.ndarray[double, ndim=1, mode="c"] alpha=self.alpha
340-
cdef np.ndarray[double, ndim=1, mode="c"] mu_s_inv=self.mu_s_inv
341-
cdef np.ndarray[int, ndim=1, mode="c"] pins = self.pins
342-
343-
#print "from cython1", self.spin,self.field,self.pred_m
344-
self.update_fun(self.y, self.t)
345-
run_step1(self._c_plan, &y[0], &field[0], &pred_m[0],
346-
&T[0], &alpha[0], &mu_s_inv[0], &pins[0])
347-
348-
self.step += 1
349-
self.t = self.step * self.dt
350-
351-
self.update_fun(self.pred_m, self.t)
352-
run_step2(self._c_plan, &pred_m[0], &field[0],
353-
&y[0], &T[0], &alpha[0], &mu_s_inv[0], &pins[0])
354-
355-
356-
def run_until(self, t):
357-
while (self.t<t):
358-
self.run_step()
359-
return 0
260+
261+
def compute_llg_rhs_dw(np.ndarray[double, ndim=1, mode="c"] dm,
262+
np.ndarray[double, ndim=1, mode="c"] spin,
263+
np.ndarray[double, ndim=1, mode="c"] field,
264+
np.ndarray[double, ndim=1, mode="c"] T,
265+
np.ndarray[double, ndim=1, mode="c"] alpha,
266+
np.ndarray[double, ndim=1, mode="c"] mu_s_inv,
267+
np.ndarray[double, ndim=1, mode="c"] eta,
268+
np.ndarray[int, ndim=1, mode="c"] pin, n, gamma, dt):
269+
llg_rhs_dw_c(&spin[0], &field[0], &dm[0], &T[0], &alpha[0], &mu_s_inv[0], &pin[0], &eta[0], n, gamma, dt)

fidimag/atomistic/lib/llg_random.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static inline unsigned int int_rand(void) {
4343
}
4444

4545
//temporary random generator
46-
void initial_random(void) {
47-
unsigned int seed = (unsigned int) time(NULL);
46+
void initial_random(int seed) {
47+
//unsigned int seed = (unsigned int) time(NULL);
4848

4949
int i;
5050
MT[0] = seed & 0xFFFFFFFFU;
@@ -136,12 +136,4 @@ void gauss_random_vec(double *x, int n) {
136136

137137
}
138138

139-
void gauss_random_vec_with_init(double *x, int n) {
140-
141-
initial_random();
142-
143-
gauss_random_vec(x,n);
144-
145-
}
146-
147139
#endif

0 commit comments

Comments
 (0)