-
Notifications
You must be signed in to change notification settings - Fork 0
/
mumaterial_test.f90
181 lines (148 loc) · 5.35 KB
/
mumaterial_test.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
PROGRAM MUMATERIAL_TEST
USE MUMATERIAL_MOD
IMPLICIT NONE
INCLUDE "mpif.h"
INTEGER :: istat, size, rank, comm
CHARACTER(LEN=256) :: filename
DOUBLE PRECISION, DIMENSION(:), allocatable :: x, y, z, Hx, Hy, Hz, offset
INTEGER :: i_int
DOUBLE PRECISION :: Bx, By, Bz
INTEGER :: start, finish, rate
integer, parameter :: arg_len = 256
INTEGER :: i, numargs
CHARACTER*(arg_len) :: arg1
CHARACTER*(arg_len), allocatable, dimension(:) :: args
rank = 0
DO i_int = 1,6
DO i = 1,i_int-1
WRITE(6,*) i_int,i
CALL FLUSH(6)
END DO
DO i = i_int+1,6
WRITE(6,*) i_int,i
CALL FLUSH(6)
END DO
END DO
!-----------------------------------------------------------------------
! Handle Input Arguments
!-----------------------------------------------------------------------
numargs = 0
i = 0
arg1 = ''
! First Handle the input arguments
CALL GETCARG(1, arg1, numargs)
ALLOCATE(args(numargs))
! Cycle through Arguments
i = 1
DO WHILE (i <= numargs)
call GETCARG(i, args(i), numargs)
select case (args(i))
case ("-mumat")
i = i + 1
CALL GETCARG(i, filename, numargs)
END SELECT
i = i + 1
END DO
DEALLOCATE(args)
CALL MPI_INIT(istat)
comm = MPI_COMM_WORLD
CALL MPI_COMM_SIZE(comm, size, istat)
CALL MPI_COMM_RANK(comm, rank, istat)
CALL MUMATERIAL_SETVERB(.FALSE.)
IF (rank .eq. 0) THEN
CALL SYSTEM_CLOCK(count_rate=rate)
CALL SYSTEM_CLOCK(start)
CALL MUMATERIAL_SETVERB(.TRUE.)
END IF
!filename = 'sphere_mu.dat'
allocate(offset(3))
offset = [0.0, 0.0, 0.0]
CALL MUMATERIAL_LOAD(TRIM(filename),istat, comm)
! if (istat/=0) EXIT(2) ! probably need to stop the program in this case?
IF (rank .eq. 0) THEN
CALL MUMATERIAL_INFO(6)
END IF
CALL MUMATERIAL_SETD(1.0d-5, 1000, 0.7d0, 0.75d0, -1, comm) ! only set if values need to be changed
CALL MUMATERIAL_INIT_NEW(BEXTERNAL, comm, offset)
IF (rank .eq. 0) THEN
CALL SYSTEM_CLOCK(finish)
WRITE(*,*) "Time to finish loading: ", real(finish-start)/real(rate)
END IF
CALL gen_grid(x, y, z)
! CALL MUMATERIAL_GETB(5.d0, 5.d0, 501.d0, Bx, By, Bz, BEXTERNAL)
! WRITE(*,*) "H:", Bx / (16 * atan(1.d0) * 1.d-7), By / (16 * atan(1.d0) * 1.d-7), Bz / (16 * atan(1.d0) * 1.d-7)
CALL MUMATERIAL_OUTPUT('./', x, y, z, BEXTERNAL, comm)
CALL MUMATERIAL_FREE()
IF (rank .eq. 0) THEN
CALL SYSTEM_CLOCK(finish)
WRITE(*,*) "Time to finish: ", real(finish-start)/real(rate)
END IF
CALL MPI_FINALIZE(istat)
CONTAINS
SUBROUTINE BEXTERNAL(x,y,z,bx,by,bz)
IMPLICIT NONE
DOUBLE PRECISION, INTENT(IN) :: x,y,z
DOUBLE PRECISION, INTENT(OUT) :: bx,by,bz
DOUBLE PRECISION :: theta, phi, mag
! python easy axis from spherical coordinate transformations
theta = 0.0
phi = 0.0
mag = 1.0!16 * atan(1.d0) * 1.0E-7
bx = mag*sin(theta)*cos(phi)
by = mag*sin(theta)*sin(phi)
bz = mag*cos(theta)
!bx = 1.0; by = 0.0; bz = 0.0
RETURN
END SUBROUTINE BEXTERNAL
subroutine gen_grid(x, y, z)
implicit none
DOUBLE PRECISION, dimension(:), allocatable, intent(out) :: x, y, z
integer, dimension(3) :: num_points
integer :: n_temp, i, j, k, n_points
DOUBLE PRECISION :: r, theta, phi, pi
DOUBLE PRECISION, dimension(3) :: min, max
pi = 4.0 * atan(1.0)
min = [5.0, 0.0, 0.0]
max = [1000.d0, pi, 2.0*pi]
num_points = [300, 5, 1]![200, 5, 1]
! min = [-10.0, -10.0, -10.0]
! max = [10.0, 10.0, 10.0]
! num_points = [300, 300, 300]
n_temp = 1
n_points = num_points(1)*num_points(2)*num_points(3)
allocate(x(n_points))
allocate(y(n_points))
allocate(z(n_points))
do i = 1, num_points(1)
do j = 1, num_points(2)
do k = 1, num_points(3)
if (num_points(1) .gt. 1) then
r = min(1) + 1.0*(i-1)*(max(1)-min(1))/(num_points(1)-1)
x(n_temp) = min(1) + 1.0*(i-1)*(max(1)-min(1))/(num_points(1)-1)
else
r = min(1)
x(n_temp) = min(1)
end if
if (num_points(2) .gt. 1) then
theta = min(2) + 1.0*(j-1)*(max(2)-min(2))/(num_points(2)-1)
y(n_temp) = min(2) + 1.0*(j-1)*(max(2)-min(2))/(num_points(2)-1)
else
theta = min(2)
y(n_temp) = min(2)
end if
if (num_points(3) .gt. 1) then
phi = min(3) + 1.0*(k-1)*(max(3)-min(3))/(num_points(3))
z(n_temp) = min(3) + 1.0*(k-1)*(max(3)-min(3))/(num_points(3)-1)
else
phi = min(3)
z(n_temp) = min(3)
end if
x(n_temp) = r*sin(theta)*cos(phi)
y(n_temp) = r*sin(theta)*sin(phi)
z(n_temp) = r*cos(theta)
n_temp = n_temp + 1
enddo
enddo
enddo
end subroutine gen_grid
END PROGRAM MUMATERIAL_TEST