source: trunk/src/run_ape.F90 @ 608

Revision 608, 9.0 KB checked in by micael, 21 months ago (diff)
  • Renamed some constants to have a more consistent naming scheme.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1!! Copyright (C) 2004-2011 M. Oliveira, F. Nogueira
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16!! 02111-1307, USA.
17!!
18!! $Id$
19
20#include "global.h"
21
22module run_ape_m
23  use global_m
24  use oct_parser_m
25  use utilities_m
26  use messages_m
27  use units_m
28  use output_m
29  use wave_equations_integrator_m
30  use eigensolver_m
31  use atom_m
32  use numerical_tests_m
33  implicit none
34
35
36                    !---Global Variables---!
37
38  !The stack
39  integer :: stack(100) = 0
40  integer :: n_inst     = 0
41
42  !Modes
43  integer, parameter :: AE         = 1,  &
44                        PP_GEN     = 2,  &
45                        PP_TEST    = 4,  &
46                        PP_CONVERT = 8,  &
47                        NUM_TESTS  = 16, &
48                        XC_EVAL    = 32
49
50  !Instructions
51  integer, parameter :: ATOM_AE_CREATE  = 1,  &
52                        ATOM_AE_SAVE    = 2,  &
53                        ATOM_AE_LOAD    = 3,  &
54                        ATOM_AE_XC_EVAL = 4,  &
55                        ATOM_AE_END     = 5,  &
56                        ATOM_PS_CREATE  = 11, &
57                        ATOM_PS_SAVE    = 12, &
58                        ATOM_PS_LOAD    = 13, &
59                        ATOM_PS_TEST    = 14, &
60                        ATOM_PS_END     = 15, &
61                        ATOM_KB_END     = 16, &
62                        NUMERICAL_TESTS = 30, &
63                        LEAVE           = 100
64
65
66                    !---Public/Private Statements---!
67
68  private
69  public :: run, AE, PP_GEN, PP_TEST, NUM_TESTS, XC_EVAL
70
71
72contains
73
74  subroutine run()
75    !-----------------------------------------------------------------------!
76    ! This subroutine reads the run mode and puts the corresponding tasks   !
77    ! in a stack. It then performs all the tasks that are in the stack by   !
78    ! calling the appropriate subroutines.                                  !
79    !                                                                       !
80    !-----------------------------------------------------------------------!
81    integer             :: calcmode, mode_test, inst, message_length
82    type(integrator_t)  :: integrator_sp, integrator_dp
83    type(eigensolver_t) :: eigensolver
84    type(atom_t)        :: ae_atom, ps_atom, kb_atom
85
86    call push_sub("run")
87
88    !Read calculation mode
89    call oct_parse_int('CalculationMode', AE + PP_GEN, calcmode)
90
91    !Write what the code is going to do and check the input
92    message(1) = "Calculation Type:"
93    message_length = 1
94    mode_test = calcmode
95    if (iand(calcmode, AE) /= 0) then
96      message_length = message_length + 1
97      message(message_length) = "  Atomic Calculation"
98      mode_test = mode_test - iand(AE, calcmode)
99    end if
100    if (iand(calcmode, PP_GEN) /= 0) then
101      message_length = message_length + 1
102      message(message_length) = "  PseudoPotential Generation"
103      mode_test = mode_test - iand(PP_GEN, calcmode)
104    end if
105    if (iand(calcmode, PP_TEST) /= 0) then
106      message_length = message_length + 1
107      message(message_length) = "  PseudoPotential Test"
108      mode_test = mode_test - iand(PP_TEST, calcmode)
109    end if
110    if (iand(calcmode, PP_CONVERT) /= 0) then
111      message_length = message_length + 1
112      message(message_length) = "  PseudoPotential File Conversion"
113      mode_test = mode_test - iand(PP_CONVERT, calcmode)
114    end if
115    if (iand(calcmode, NUM_TESTS) /= 0) then
116      message_length = message_length + 1
117      message(message_length) = "  Numerical Tests"
118      mode_test = mode_test - iand(NUM_TESTS, calcmode)
119    end if
120    if (iand(calcmode, XC_EVAL) /= 0) then
121      message_length = message_length + 1
122      message(message_length) = "  Exchange-Correlation Evaluation"
123      mode_test = mode_test - iand(XC_EVAL, calcmode)
124    end if
125    if (mode_test /= 0) then
126      write(message(1), '(A,I2,A)') "Input: '", calcmode, "' is not a valid CalculationMode"
127      call write_fatal(1)
128    else
129      call write_info(message_length)
130    end if
131
132    !Initialize stack
133    !Remember this is a stack: first in last out!
134    call push(LEAVE) !Last thing to do is always to exit
135
136    !Are we going to convert the pseudopotential data?
137    if (iand(calcmode, PP_CONVERT) /= 0) then
138      call push(ATOM_PS_END)
139      call push(ATOM_PS_LOAD)
140    end if
141
142    !Are we going to test the pseudopotentials?
143    if (iand(calcmode, PP_TEST) /= 0) then
144      call push(ATOM_PS_END)
145      call push(ATOM_PS_TEST)
146      call push(ATOM_PS_LOAD)
147    end if
148
149    !Are we going to do a pseudopotential generation?
150    if (iand(calcmode, PP_GEN) /= 0) then
151      call push(ATOM_AE_END)
152      call push(ATOM_PS_END)
153      call push(ATOM_KB_END)
154      call push(ATOM_PS_SAVE)
155      call push(ATOM_PS_CREATE)
156      call push(ATOM_AE_LOAD)
157    end if
158
159    !Are we going to do an all-electron calculation?
160    if (iand(calcmode, AE) /= 0) then
161      call push(ATOM_AE_END)
162      call push(ATOM_AE_SAVE)
163      call push(ATOM_AE_CREATE)
164    end if
165
166    !Are we going to perform numerical tests?
167    if (iand(calcmode, NUM_TESTS) /= 0) then
168      call push(NUMERICAL_TESTS)
169    end if
170
171    !Are we going to evaluate the xc potential and energy?
172    if (iand(calcmode, XC_EVAL) /= 0) then
173      call push(ATOM_AE_END)
174      call push(ATOM_AE_XC_EVAL)
175      call push(ATOM_AE_LOAD)
176    end if
177
178    !Initialize things needed for all modes
179    call units_init()
180    call wave_equations_integrator_init(integrator_sp, integrator_dp)
181    call eigensolver_init(eigensolver)
182
183    !Main loop: do everything that is in the stack
184    do
185      call pop(inst)
186      select case (inst)
187      case (ATOM_AE_CREATE)
188        message(1) = ""
189        message(2) = ""
190        message(3) = str_center("-- All Electron Calculation --", 70)
191        call write_info(3)
192
193        call output_init("ae")
194        call atom_null(ae_atom)
195        call atom_create_ae(ae_atom, integrator_sp, integrator_dp, eigensolver)
196        call atom_output(ae_atom, "ae")
197        call output_end("ae")
198
199      case (ATOM_AE_SAVE)
200        call atom_save(ae_atom, "ae")
201
202      case (ATOM_AE_LOAD)
203        call atom_null(ae_atom)
204        call atom_load(ae_atom, "ae")
205
206      case (ATOM_AE_XC_EVAL)
207        message(1) = ""
208        message(2) = ""
209        message(3) = str_center("-- Exchage-Correlation Evaluation --", 70)
210        call output_init("xc")
211        call atom_xc_eval(ae_atom)
212        call output_end("xc")
213
214      case (ATOM_AE_END)
215        call atom_end(ae_atom)
216
217      case (ATOM_PS_CREATE)
218        message(1) = ""
219        message(2) = ""
220        message(3) = str_center("-- Pseudopotential Generation --", 70)
221        call write_info(3)
222
223        call output_init("pp")
224        call output_init("kb")
225        call atom_null(ps_atom)
226        call atom_null(kb_atom)
227        call atom_create_ps(ae_atom, ps_atom, kb_atom, integrator_sp, &
228                            integrator_dp, eigensolver)
229        call atom_output(ps_atom, "pp")
230        call atom_output(kb_atom, "kb")
231        call output_end("pp")
232        call output_end("kb")
233
234      case (ATOM_PS_SAVE)
235        call atom_save(ps_atom, "pp")
236
237      case (ATOM_PS_LOAD)
238        call atom_null(ps_atom)
239        call atom_load(ps_atom, "pp")
240
241      case (ATOM_PS_TEST)
242        message(1) = ""
243        message(2) = ""
244        message(3) = str_center("-- Pseudopotential Testing --", 70)
245        call write_info(3)
246
247        call output_init("tests")
248        call atom_test(ps_atom, integrator_sp, integrator_dp, eigensolver)
249        call output_end("tests")
250      case (ATOM_PS_END)
251        call atom_end(ps_atom)
252      case (NUMERICAL_TESTS)
253        message(1) = ""
254        message(2) = ""
255        message(3) = str_center("-- Numerical Tests --", 70)
256        call output_init("nt")
257        call numerical_tests_run()
258        call output_end("nt")
259      case (LEAVE)
260        exit
261      end select
262    end do
263
264    !End things needed for all modes
265    call wave_equations_integrator_end(integrator_sp, integrator_dp)
266    call eigensolver_end(eigensolver)
267
268    call pop_sub()
269  contains
270
271    subroutine push(inst)
272      integer, intent(in) :: inst
273
274      if (n_inst == 100) then
275        message(1) = "Too many instructions in stack"
276        call write_fatal(1)
277      end if
278      n_inst = n_inst + 1
279      stack(n_inst) = inst
280
281    end subroutine push
282
283    subroutine pop(inst)
284      integer, intent(out) :: inst
285
286      if (n_inst == 0) then
287        message(1) = "Not enough instructions in stack"
288        call write_fatal(1)
289      end if
290      inst = stack(n_inst)
291      stack(n_inst) = 0
292      n_inst = n_inst - 1
293
294    end subroutine pop
295
296  end subroutine run
297
298end module run_ape_m
Note: See TracBrowser for help on using the repository browser.