Octopus
td_write_classical.F90
Go to the documentation of this file.
1! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
23 use global_oct_m
26 use io_oct_m
28 use mpi_oct_m
31 use space_oct_m
33 use unit_oct_m
36
37 implicit none
38
39 private
40
41 public :: &
44
45contains
46
47 ! ---------------------------------------------------------
48 subroutine td_write_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter)
49 type(c_ptr), intent(inout) :: out_coords
50 integer, intent(in) :: natoms
51 class(space_t), intent(in) :: space
52 real(real64), intent(in) :: pos(:,:)
53 real(real64), intent(in) :: vel(:,:)
54 real(real64), intent(in) :: tot_forces(:,:)
55 integer, intent(in) :: iter
56
57 integer :: iatom, idir
58 character(len=50) :: aux
59 real(real64) :: tmp(space%dim)
60
61 if (.not. mpi_world%is_root()) return ! only first node outputs
62
63 push_sub(td_write_coordinates)
64
65 if (iter == 0) then
66 call td_write_print_header_init(out_coords)
67
68 ! first line: column names
69 call write_iter_header_start(out_coords)
70
71 do iatom = 1, natoms
72 do idir = 1, space%dim
73 write(aux, '(a2,i0,a1,i1,a1)') 'x(', iatom, ',', idir, ')'
74 call write_iter_header(out_coords, aux)
75 end do
76 end do
77 do iatom = 1, natoms
78 do idir = 1, space%dim
79 write(aux, '(a2,i0,a1,i1,a1)') 'v(', iatom, ',', idir,')'
80 call write_iter_header(out_coords, aux)
81 end do
82 end do
83 do iatom = 1, natoms
84 do idir = 1, space%dim
85 write(aux, '(a2,i0,a1,i1,a1)') 'f(', iatom, ',', idir,')'
86 call write_iter_header(out_coords, aux)
87 end do
88 end do
89 call write_iter_nl(out_coords)
90
91 ! second line: units
92 call write_iter_string(out_coords, '#[Iter n.]')
93 call write_iter_header(out_coords, '[' // trim(units_abbrev(units_out%time)) // ']')
94 call write_iter_string(out_coords, &
95 'Positions in ' // trim(units_abbrev(units_out%length)) // &
96 ', Velocities in '// trim(units_abbrev(units_out%velocity)) // &
97 ', Forces in ' // trim(units_abbrev(units_out%force)))
98 call write_iter_nl(out_coords)
99
100 call td_write_print_header_end(out_coords)
101 end if
102
103 call write_iter_start(out_coords)
104
105 do iatom = 1, natoms
106 tmp(1:space%dim) = units_from_atomic(units_out%length, pos(:, iatom))
107 call write_iter_double(out_coords, tmp, space%dim)
108 end do
109 do iatom = 1, natoms
110 tmp(1:space%dim) = units_from_atomic(units_out%velocity, vel(:, iatom))
111 call write_iter_double(out_coords, tmp, space%dim)
112 end do
113 do iatom = 1, natoms
114 tmp(1:space%dim) = units_from_atomic(units_out%force, tot_forces(:, iatom))
115 call write_iter_double(out_coords, tmp, space%dim)
116 end do
117 call write_iter_nl(out_coords)
118
119 pop_sub(td_write_coordinates)
120 end subroutine td_write_coordinates
121
122 ! ---------------------------------------------------------
123 subroutine td_write_sep_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter, which)
124 type(c_ptr), intent(inout) :: out_coords
125 integer, intent(in) :: natoms
126 class(space_t), intent(in) :: space
127 real(real64), intent(in) :: pos(:,:)
128 real(real64), intent(in) :: vel(:,:)
129 real(real64), intent(in) :: tot_forces(:,:)
130 integer, intent(in) :: iter
131 integer, intent(in) :: which !1=xyz, 2=velocity, 3=force
132
133 integer, parameter :: COORDINATES=1
134 integer, parameter :: VELOCITIES=2
135 integer, parameter :: FORCES=3
136 integer :: iatom, idir
137 character(len=50) :: aux
138 real(real64) :: tmp(space%dim)
139
140 if (.not. mpi_world%is_root()) return ! only first node outputs
141
144 if (iter == 0) then
145 call td_write_print_header_init(out_coords)
146
147 ! first line: column names
148 call write_iter_header_start(out_coords)
149
150 do iatom = 1, natoms
151 do idir = 1, space%dim
152 select case (which)
153 case (coordinates)
154 write(aux, '(a2,i0,a1,i1,a1)') 'x(', iatom, ',', idir, ')'
155 case (velocities)
156 write(aux, '(a2,i0,a1,i1,a1)') 'v(', iatom, ',', idir,')'
157 case (forces)
158 write(aux, '(a2,i0,a1,i1,a1)') 'f(', iatom, ',', idir,')'
159 case default
160 assert(.false.)
161 end select
162 call write_iter_header(out_coords, aux)
163 end do
164 end do
165 call write_iter_nl(out_coords)
166
167 ! second line: units
168 call write_iter_string(out_coords, '#[Iter n.]')
169 call write_iter_header(out_coords, '[' // trim(units_abbrev(units_out%time)) // ']')
170 select case (which)
171 case (coordinates)
172 call write_iter_string(out_coords, &
173 'Positions in ' // trim(units_abbrev(units_out%length)))
174 case (velocities)
175 call write_iter_string(out_coords, &
176 'Velocities in ' // trim(units_abbrev(units_out%velocity)))
177 case (forces)
178 call write_iter_string(out_coords, &
179 'Forces in ' // trim(units_abbrev(units_out%force)))
180 end select
181 call write_iter_nl(out_coords)
182
183 call td_write_print_header_end(out_coords)
184 end if
185
186 call write_iter_start(out_coords)
187
188 select case (which)
189 case (coordinates)
190 do iatom = 1, natoms
191 tmp(1:space%dim) = units_from_atomic(units_out%length, pos(:, iatom))
192 call write_iter_double(out_coords, tmp, space%dim)
193 end do
194 case (velocities)
195 do iatom = 1, natoms
196 tmp(1:space%dim) = units_from_atomic(units_out%velocity, vel(:, iatom))
197 call write_iter_double(out_coords, tmp, space%dim)
198 end do
199 case (forces)
200 do iatom = 1, natoms
201 tmp(1:space%dim) = units_from_atomic(units_out%force, tot_forces(:, iatom))
202 call write_iter_double(out_coords, tmp, space%dim)
203 end do
204 end select
205
206 call write_iter_nl(out_coords)
207
209 end subroutine td_write_sep_coordinates
210
212
213!! Local Variables:
214!! mode: f90
215!! coding: utf-8
216!! End:
217
Writes to the corresponding file and adds one to the iteration. Must be called after write_iter_init(...
Definition: write_iter.F90:163
Definition: io.F90:116
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
this module contains the low-level part of the output system
Definition: output_low.F90:117
subroutine, public td_write_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter)
subroutine, public td_write_sep_coordinates(out_coords, natoms, space, pos, vel, tot_forces, iter, which)
subroutine, public td_write_print_header_init(out)
subroutine, public td_write_print_header_end(out)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
Explicit interfaces to C functions, defined in write_iter_low.cc.
Definition: write_iter.F90:116
subroutine, public write_iter_header(out, string)
Definition: write_iter.F90:249
subroutine, public write_iter_string(out, string)
Definition: write_iter.F90:265