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, mpi_grp, natoms, space, pos, vel, tot_forces, iter)
49 type(c_ptr), intent(inout) :: out_coords
50 type(mpi_grp_t), intent(in) :: mpi_grp
51 integer, intent(in) :: natoms
52 class(space_t), intent(in) :: space
53 real(real64), contiguous, intent(in) :: pos(:,:)
54 real(real64), contiguous, intent(in) :: vel(:,:)
55 real(real64), contiguous, intent(in) :: tot_forces(:,:)
56 integer, intent(in) :: iter
57
58 integer :: iatom, idir
59 character(len=50) :: aux
60 real(real64) :: tmp(space%dim)
61
62 if (.not. mpi_grp%is_root()) return ! only first node outputs
63
64 push_sub(td_write_coordinates)
65
66 if (iter == 0) then
67 call td_write_print_header_init(out_coords)
68
69 ! first line: column names
70 call write_iter_header_start(out_coords)
71
72 do iatom = 1, natoms
73 do idir = 1, space%dim
74 write(aux, '(a2,i0,a1,i1,a1)') 'x(', iatom, ',', idir, ')'
75 call write_iter_header(out_coords, aux)
76 end do
77 end do
78 do iatom = 1, natoms
79 do idir = 1, space%dim
80 write(aux, '(a2,i0,a1,i1,a1)') 'v(', iatom, ',', idir,')'
81 call write_iter_header(out_coords, aux)
82 end do
83 end do
84 do iatom = 1, natoms
85 do idir = 1, space%dim
86 write(aux, '(a2,i0,a1,i1,a1)') 'f(', iatom, ',', idir,')'
87 call write_iter_header(out_coords, aux)
88 end do
89 end do
90 call write_iter_nl(out_coords)
91
92 ! second line: units
93 call write_iter_string(out_coords, '#[Iter n.]')
94 call write_iter_header(out_coords, '[' // trim(units_abbrev(units_out%time)) // ']')
95 call write_iter_string(out_coords, &
96 'Positions in ' // trim(units_abbrev(units_out%length)) // &
97 ', Velocities in '// trim(units_abbrev(units_out%velocity)) // &
98 ', Forces in ' // trim(units_abbrev(units_out%force)))
99 call write_iter_nl(out_coords)
100
101 call td_write_print_header_end(out_coords)
102 end if
103
104 call write_iter_start(out_coords)
105
106 do iatom = 1, natoms
107 tmp(1:space%dim) = units_from_atomic(units_out%length, pos(:, iatom))
108 call write_iter_double(out_coords, tmp, space%dim)
109 end do
110 do iatom = 1, natoms
111 tmp(1:space%dim) = units_from_atomic(units_out%velocity, vel(:, iatom))
112 call write_iter_double(out_coords, tmp, space%dim)
113 end do
114 do iatom = 1, natoms
115 tmp(1:space%dim) = units_from_atomic(units_out%force, tot_forces(:, iatom))
116 call write_iter_double(out_coords, tmp, space%dim)
117 end do
118 call write_iter_nl(out_coords)
119
120 pop_sub(td_write_coordinates)
121 end subroutine td_write_coordinates
122
123 ! ---------------------------------------------------------
124 subroutine td_write_sep_coordinates(out_coords, mpi_grp, natoms, space, pos, vel, tot_forces, iter, which)
125 type(c_ptr), intent(inout) :: out_coords
126 type(mpi_grp_t), intent(in) :: mpi_grp
127 integer, intent(in) :: natoms
128 class(space_t), intent(in) :: space
129 real(real64), contiguous, intent(in) :: pos(:,:)
130 real(real64), contiguous, intent(in) :: vel(:,:)
131 real(real64), contiguous, intent(in) :: tot_forces(:,:)
132 integer, intent(in) :: iter
133 integer, intent(in) :: which !1=xyz, 2=velocity, 3=force
134
135 integer, parameter :: COORDINATES=1
136 integer, parameter :: VELOCITIES=2
137 integer, parameter :: FORCES=3
138 integer :: iatom, idir
139 character(len=50) :: aux
140 real(real64) :: tmp(space%dim)
141
142 if (.not. mpi_grp%is_root()) return ! only first node outputs
145
146 if (iter == 0) then
147 call td_write_print_header_init(out_coords)
148
149 ! first line: column names
150 call write_iter_header_start(out_coords)
151
152 do iatom = 1, natoms
153 do idir = 1, space%dim
154 select case (which)
155 case (coordinates)
156 write(aux, '(a2,i0,a1,i1,a1)') 'x(', iatom, ',', idir, ')'
157 case (velocities)
158 write(aux, '(a2,i0,a1,i1,a1)') 'v(', iatom, ',', idir,')'
159 case (forces)
160 write(aux, '(a2,i0,a1,i1,a1)') 'f(', iatom, ',', idir,')'
161 case default
162 assert(.false.)
163 end select
164 call write_iter_header(out_coords, aux)
165 end do
166 end do
167 call write_iter_nl(out_coords)
168
169 ! second line: units
170 call write_iter_string(out_coords, '#[Iter n.]')
171 call write_iter_header(out_coords, '[' // trim(units_abbrev(units_out%time)) // ']')
172 select case (which)
173 case (coordinates)
174 call write_iter_string(out_coords, &
175 'Positions in ' // trim(units_abbrev(units_out%length)))
176 case (velocities)
177 call write_iter_string(out_coords, &
178 'Velocities in ' // trim(units_abbrev(units_out%velocity)))
179 case (forces)
180 call write_iter_string(out_coords, &
181 'Forces in ' // trim(units_abbrev(units_out%force)))
182 end select
183 call write_iter_nl(out_coords)
184
185 call td_write_print_header_end(out_coords)
186 end if
187
188 call write_iter_start(out_coords)
189
190 select case (which)
191 case (coordinates)
192 do iatom = 1, natoms
193 tmp(1:space%dim) = units_from_atomic(units_out%length, pos(:, iatom))
194 call write_iter_double(out_coords, tmp, space%dim)
195 end do
196 case (velocities)
197 do iatom = 1, natoms
198 tmp(1:space%dim) = units_from_atomic(units_out%velocity, vel(:, iatom))
199 call write_iter_double(out_coords, tmp, space%dim)
200 end do
201 case (forces)
202 do iatom = 1, natoms
203 tmp(1:space%dim) = units_from_atomic(units_out%force, tot_forces(:, iatom))
204 call write_iter_double(out_coords, tmp, space%dim)
205 end do
206 end select
207
208 call write_iter_nl(out_coords)
209
211 end subroutine td_write_sep_coordinates
212
214
215!! Local Variables:
216!! mode: f90
217!! coding: utf-8
218!! End:
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
this module contains the low-level part of the output system
Definition: output_low.F90:117
subroutine, public td_write_sep_coordinates(out_coords, mpi_grp, natoms, space, pos, vel, tot_forces, iter, which)
subroutine, public td_write_coordinates(out_coords, mpi_grp, natoms, space, pos, vel, tot_forces, iter)
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