-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialise.f90
More file actions
175 lines (103 loc) · 4.78 KB
/
initialise.f90
File metadata and controls
175 lines (103 loc) · 4.78 KB
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
module initialise
!------------------------------------------------------------------------------------------!
!------Module to initialise problem by allowing user to select desired N, direction of-----!
!------magnetic moments and whether to run in series or parallel.--------------------------!
!------------------------------------------------------------------------------------------!
use physical_constants
implicit none
contains
!initialisation subroutine
recursive subroutine init(mag_vector, coords, N, sORp)
real(kind=dp), dimension(3), intent(out) :: mag_vector
real(kind=dp), dimension(:), allocatable, intent(out) :: coords
integer, intent(out) :: N
character :: mag_direction
character, intent(out) :: sORp
!If this read statement is uncommented, will be used to read in values for N,
!mag_direction and sORp from bash script rather than them being entered at run time.
!For this must also comment out all other read statements in this module
!read (*,*) N, mag_direction, sORp
!Open a file which can be 3D plotted (e.g. with gnuplot) to
!display the ellipsoid of points (or cube should the dimensions be smaller than the
!ellipsoid radii.
!open(unit=unit1, file="ellipsoid.txt", iostat=istat)
!if(istat/=0) stop "Error opening ellipsoid.txt"
!Section allows user to choose value for N
print *, "-----------------------------------------------------------------"
print *, "Enter a value for N. The total number of dipoles will be", &
" N cubed, such that they form a cube of side N dipoles."
read(*,*) N
!check to make sure N is > 0
if(N<=0)then
print *, "ERROR: N may not be less than or equal to zero."
print *, coords
call init(mag_vector, coords, N, sORp)
else
print *, "N is set to:", N
endif
!Section allows user to choose direction of magnetic dipole moment
print *, "-----------------------------------------------------------------"
print *, "Please choose the direction of the magnetic moment of each", &
" dipole"
print *, "Type 'x', 'y' or 'z' to choose the direction. Or type 'r' to", &
" restart."
read(*,*) mag_direction
if(mag_direction == "x")then
mag_vector = [1.0_dp, 0.0_dp, 0.0_dp]
elseif(mag_direction == "y")then
mag_vector = [0.0_dp, 1.0_dp, 0.0_dp]
elseif(mag_direction == "z")then
mag_vector = [0.0_dp, 0.0_dp, 1.0_dp]
elseif(mag_direction == "r")then
call init(mag_vector, coords, N, sOrp)
else
print *, mag_direction, " is not a valid input."
call init(mag_vector, coords, N, sORp)
endif
print *, "The unit vector for the magnetic moment of each dipole is"
print *, mag_vector
!check to see if coords has already been allocated
!This happens if N was given a not allowed value (<=0)
if(allocated(coords))then
deallocate(coords)
endif
!allocate size of coordinate arrays
allocate(coords(1:N))
!set possible x, y and z coordinates
do i = 1, N
coords(i) = real(i,dp) * l
enddo
!initialise ellipsoid
call ellipsoid(N, l, ellipCent)
print *, "-----------------------------------------------------------------"
print *, "Ellipsoid is centred on the coordinates x = y = z with x,y,z ="
print *, ellipCent
print *, "-----------------------------------------------------------------"
print *, "Select whether to calculate in serial('s') or parallel('p').", &
" Or type 'r' to restart."
read(*,*) sORp
if(sORp == "s")then
print *, "Running in serial."
elseif(sORp == "p")then
print *, "Running in parallel."
elseif(sORp == "r")then
call init(mag_vector, coords, N, sORp)
else
print *, sORp, "is not a valid input."
call init(mag_vector, coords, N, sORp)
endif
endsubroutine init
!Subroutine to create the ellipsoid such that it is centered on the centre of the cube
!of dipoles produced.
subroutine ellipsoid(N, l, center)
real(kind=dp), intent(in) :: l
real(kind=dp) :: halfway
integer, intent(in) :: N
!centre point of ellipsoid, centred on the centre of the cube of dipoles
real(kind=dp), intent(out) :: center
!calculate halfway point between lowest and highest coordinate points
halfway = (N*l) - l
!set central point of the ellipsoid
center = (halfway / 2.0_dp) + l
endsubroutine ellipsoid
endmodule initialise