Skip to content

Commit d0ac9fb

Browse files
Clang formatted C extensions. Updated integrators test
1 parent eeb9eba commit d0ac9fb

23 files changed

+1407
-1543
lines changed

fidimag/common/dipolar/demag.c

Lines changed: 414 additions & 441 deletions
Large diffs are not rendered by default.

fidimag/common/dipolar/demag_oommf.c

Lines changed: 257 additions & 269 deletions
Large diffs are not rendered by default.

fidimag/common/dipolar/demagcoef.h

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* This file demag_oommf.h is taken from the OOMMF project (oommf/app/oxs/ext/demagcoef.h
22
downloaded from http://math.nist.gov/oommf/dist/oommf12a5rc_20120928.tar.gz)
3-
with slightly modifications (change OC_REALWIDE to double)
3+
with slightly modifications (change OC_REALWIDE to double)
44
and distributed under this license shown below. */
55

6-
/* License
6+
/* License
77
88
OOMMF - Object Oriented MicroMagnetic Framework
99
@@ -39,10 +39,6 @@ to copyright protection within the United States.
3939
4040
*/
4141

42-
43-
44-
45-
4642
/* FILE: demagcoef.h -*-Mode: c++-*-
4743
*
4844
* Demag coefficients.
@@ -73,106 +69,98 @@ to copyright protection within the United States.
7369
*
7470
*/
7571

72+
#include <math.h>
7673

77-
double Newell_f(double x,double y,double z);
78-
double Newell_g(double x,double y,double z);
74+
double Newell_f(double x, double y, double z);
75+
double Newell_g(double x, double y, double z);
7976

8077
double
8178
CalculateSDA00(double x, double y, double z,
82-
double dx,double dy,double dz);
79+
double dx, double dy, double dz);
8380

8481
inline double
8582
CalculateSDA11(double x, double y, double z,
86-
double dx,double dy,double dz)
87-
{ return CalculateSDA00(y,x,z,dy,dx,dz); }
83+
double dx, double dy, double dz) { return CalculateSDA00(y, x, z, dy, dx, dz); }
8884

8985
inline double
9086
CalculateSDA22(double x, double y, double z,
91-
double dx,double dy,double dz)
92-
{ return CalculateSDA00(z,y,x,dz,dy,dx); }
93-
87+
double dx, double dy, double dz) { return CalculateSDA00(z, y, x, dz, dy, dx); }
9488

9589
double
9690
CalculateSDA01(double x, double y, double z,
97-
double dx,double dy,double dz);
91+
double dx, double dy, double dz);
9892

9993
inline double
10094
CalculateSDA02(double x, double y, double z,
101-
double dx,double dy,double dz)
102-
{ return CalculateSDA01(x,z,y,dx,dz,dy); }
95+
double dx, double dy, double dz) { return CalculateSDA01(x, z, y, dx, dz, dy); }
10396

10497
inline double
10598
CalculateSDA12(double x, double y, double z,
106-
double dx,double dy,double dz)
107-
{ return CalculateSDA01(y,z,x,dy,dz,dx); }
99+
double dx, double dy, double dz) { return CalculateSDA01(y, z, x, dy, dz, dx); }
108100

109-
110-
double SelfDemagNx(double xsize,double ysize,double zsize);
111-
double SelfDemagNy(double xsize,double ysize,double zsize);
112-
double SelfDemagNz(double xsize,double ysize,double zsize);
101+
double SelfDemagNx(double xsize, double ysize, double zsize);
102+
double SelfDemagNy(double xsize, double ysize, double zsize);
103+
double SelfDemagNz(double xsize, double ysize, double zsize);
113104

114105
double DemagNxxAsymptotic(double x, double y, double z,
115-
double dx,double dy,double dz);
106+
double dx, double dy, double dz);
116107

117108
double DemagNxyAsymptotic(double x, double y, double z,
118-
double dx,double dy,double dz);
109+
double dx, double dy, double dz);
119110

120111
double DemagNyyAsymptotic(double x, double y, double z,
121-
double dx,double dy,double dz);
112+
double dx, double dy, double dz);
122113

123114
double DemagNzzAsymptotic(double x, double y, double z,
124-
double dx,double dy,double dz);
115+
double dx, double dy, double dz);
125116

126117
double DemagNxzAsymptotic(double x, double y, double z,
127-
double dx,double dy,double dz);
118+
double dx, double dy, double dz);
128119

129120
double DemagNyzAsymptotic(double x, double y, double z,
130-
double dx,double dy,double dz);
131-
132-
121+
double dx, double dy, double dz);
133122

134123
////////////////////////////////////////////////////////////////////////////
135124
// Routines to do accurate summation
136125

137-
static int AS_Compare(const void* px,const void* py)
138-
{
126+
static int AS_Compare(const void *px, const void *py) {
139127
// Comparison based on absolute values
140-
double x=fabs(*((const double *)px));
141-
double y=fabs(*((const double *)py));
142-
if(x<y) return 1;
143-
if(x>y) return -1;
128+
double x = fabs(*((const double *)px));
129+
double y = fabs(*((const double *)py));
130+
if (x < y)
131+
return 1;
132+
if (x > y)
133+
return -1;
144134
return 0;
145135
}
146136

147-
148-
static double
149-
AccurateSum(int n,double *arr)
150-
{
137+
static double
138+
AccurateSum(int n, double *arr) {
151139
// Order by decreasing magnitude
152-
qsort(arr,n,sizeof(double),AS_Compare);
140+
qsort(arr, n, sizeof(double), AS_Compare);
153141

154142
// Add up using doubly compensated summation. If necessary, mark
155143
// variables these "volatile" to protect against problems arising
156144
// from extra precision. Also, don't expect the compiler to respect
157145
// order with respect to parentheses at high levels of optimization,
158146
// i.e., write "u=x; u-=(y-corr)" as opposed to "u=x-(y-corr)".
159147

160-
double sum,corr,y,u,t,v,z,x,tmp;
161-
162-
sum=arr[0]; corr=0;
163-
for(int i=1;i<n;i++) {
164-
x=arr[i];
165-
y=corr+x;
166-
tmp=y-corr;
167-
u=x-tmp;
168-
t=y+sum;
169-
tmp=t-sum;
170-
v=y-tmp;
171-
z=u+v;
172-
sum=t+z;
173-
tmp=sum-t;
174-
corr=z-tmp;
148+
double sum, corr, y, u, t, v, z, x, tmp;
149+
150+
sum = arr[0];
151+
corr = 0;
152+
for (int i = 1; i < n; i++) {
153+
x = arr[i];
154+
y = corr + x;
155+
tmp = y - corr;
156+
u = x - tmp;
157+
t = y + sum;
158+
tmp = t - sum;
159+
v = y - tmp;
160+
z = u + v;
161+
sum = t + z;
162+
tmp = sum - t;
163+
corr = z - tmp;
175164
}
176165
return sum;
177166
}
178-

fidimag/common/dipolar/dipolar.h

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1-
#include<math.h>
2-
#include<complex.h>
3-
#include<fftw3.h>
4-
//#include<omp.h>
1+
#include <complex.h>
2+
#include <fftw3.h>
3+
#include <math.h>
4+
// #include<omp.h>
55

66
#define WIDE_PI 3.1415926535897932384626433832795L
77

8-
inline double cross_x(double a0, double a1, double a2, double b0, double b1, double b2) { return a1*b2 - a2*b1; }
9-
inline double cross_y(double a0, double a1, double a2, double b0, double b1, double b2) { return a2*b0 - a0*b2; }
10-
inline double cross_z(double a0, double a1, double a2, double b0, double b1, double b2) { return a0*b1 - a1*b0; }
11-
8+
inline double cross_x(double a0, double a1, double a2, double b0, double b1, double b2) { return a1 * b2 - a2 * b1; }
9+
inline double cross_y(double a0, double a1, double a2, double b0, double b1, double b2) { return a2 * b0 - a0 * b2; }
10+
inline double cross_z(double a0, double a1, double a2, double b0, double b1, double b2) { return a0 * b1 - a1 * b0; }
1211

1312
enum Type_Nij {
14-
Tensor_xx, Tensor_yy, Tensor_zz, Tensor_xy, Tensor_xz, Tensor_yz
13+
Tensor_xx,
14+
Tensor_yy,
15+
Tensor_zz,
16+
Tensor_xy,
17+
Tensor_xz,
18+
Tensor_yz
1519
};
1620

1721
//==========================================
18-
//used for demag
22+
// used for demag
1923

2024
typedef struct {
21-
int nx;
22-
int ny;
23-
int nz;
24-
double dx;
25-
double dy;
26-
double dz;
27-
int lenx;
28-
int leny;
29-
int lenz;
30-
31-
int total_length;
32-
33-
//TODO: free tensors after obtaining NXX to save memory?
34-
double *tensor_xx;
35-
double *tensor_yy;
36-
double *tensor_zz;
37-
double *tensor_xy;
38-
double *tensor_xz;
39-
double *tensor_yz;
40-
41-
//TODO: (1)using double, (2)using small size
42-
fftw_complex *Nxx; //Nxx, Nxy .. are pure real now.
43-
fftw_complex *Nyy;
44-
fftw_complex *Nzz;
45-
fftw_complex *Nxy;
46-
fftw_complex *Nxz;
47-
fftw_complex *Nyz;
48-
49-
fftw_complex *Mx;
50-
fftw_complex *My;
51-
fftw_complex *Mz;
52-
fftw_complex *Hx;
53-
fftw_complex *Hy;
54-
fftw_complex *Hz;
55-
56-
double *mx;
57-
double *my;
58-
double *mz;
59-
double *hx;
60-
double *hy;
61-
double *hz;
62-
63-
//we need three plans
64-
fftw_plan tensor_plan;
65-
fftw_plan m_plan;
66-
fftw_plan h_plan;
25+
int nx;
26+
int ny;
27+
int nz;
28+
double dx;
29+
double dy;
30+
double dz;
31+
int lenx;
32+
int leny;
33+
int lenz;
34+
35+
int total_length;
36+
37+
// TODO: free tensors after obtaining NXX to save memory?
38+
double *tensor_xx;
39+
double *tensor_yy;
40+
double *tensor_zz;
41+
double *tensor_xy;
42+
double *tensor_xz;
43+
double *tensor_yz;
44+
45+
// TODO: (1)using double, (2)using small size
46+
fftw_complex *Nxx; // Nxx, Nxy .. are pure real now.
47+
fftw_complex *Nyy;
48+
fftw_complex *Nzz;
49+
fftw_complex *Nxy;
50+
fftw_complex *Nxz;
51+
fftw_complex *Nyz;
52+
53+
fftw_complex *Mx;
54+
fftw_complex *My;
55+
fftw_complex *Mz;
56+
fftw_complex *Hx;
57+
fftw_complex *Hy;
58+
fftw_complex *Hz;
59+
60+
double *mx;
61+
double *my;
62+
double *mz;
63+
double *hx;
64+
double *hy;
65+
double *hz;
66+
67+
// we need three plans
68+
fftw_plan tensor_plan;
69+
fftw_plan m_plan;
70+
fftw_plan h_plan;
6771

6872
} fft_demag_plan;
6973

7074
fft_demag_plan *create_plan(void);
7175
void finalize_plan(fft_demag_plan *restrict plan);
7276
void init_plan(fft_demag_plan *plan, double dx, double dy,
73-
double dz, int nx, int ny, int nz);
74-
void compute_dipolar_tensors(fft_demag_plan *restrict plan);
77+
double dz, int nx, int ny, int nz);
78+
void compute_dipolar_tensors(fft_demag_plan *restrict plan);
7579
void compute_demag_tensors(fft_demag_plan *restrict plan);
7680
void create_fftw_plan(fft_demag_plan *restrict plan);
7781

@@ -82,36 +86,33 @@ void compute_fields(fft_demag_plan *restrict plan, double *restrict spin, double
8286
void exact_compute(fft_demag_plan *restrict plan, double *restrict spin, double *mu_s, double *restrict field);
8387
double compute_demag_energy(fft_demag_plan *restrict plan, double *restrict spin, double *restrict mu_s, double *restrict field, double *restrict energy);
8488

85-
86-
8789
//=========================================================
8890
//=========================================================
89-
//used for sode
91+
// used for sode
9092
typedef struct {
91-
int nxyz;
93+
int nxyz;
9294

93-
double dt;
94-
double T;
95-
double gamma;
96-
double *mu_s;
97-
double coeff;
98-
double Q;
95+
double dt;
96+
double T;
97+
double gamma;
98+
double *mu_s;
99+
double coeff;
100+
double Q;
99101

100-
double theta;
101-
double theta1;
102-
double theta2;
102+
double theta;
103+
double theta1;
104+
double theta2;
103105

104-
double *dm1;
105-
double *dm2;
106-
double *eta;
106+
double *dm1;
107+
double *dm2;
108+
double *eta;
107109

108110
} ode_solver;
109111

110112
void init_solver(ode_solver *s, double k_B, double theta, int nxyz, double dt, double gamma);
111113
ode_solver *create_ode_plan(void);
112114
void finalize_ode_plan(ode_solver *plan);
113115
void run_step1(ode_solver *s, double *m, double *h, double *m_pred, double *T,
114-
double *alpha, double *mu_s_inv, int *pins);
116+
double *alpha, double *mu_s_inv, int *pins);
115117
void run_step2(ode_solver *s, double *m_pred, double *h, double *m, double *T,
116-
double *alpha, double *mu_s_inv, int *pins);
117-
118+
double *alpha, double *mu_s_inv, int *pins);

0 commit comments

Comments
 (0)