Globals Library 1.0
Loading...
Searching...
No Matches
modTimeOutputs.f90
Go to the documentation of this file.
2
3 use globals
4
5 implicit none
6
7 private
8
9 !> @brief Data structure containing values of a variable
10 !> possibly depending on time (e.g., forcing function)
11 !> @details This data structure can be used, for example, for
12 !> storing the values of a forcing function. Each colum of
13 !> `tdout::tdactual` represent the value of the forcing function
14 !> in a different point of the domain. All the values are
15 !> associated to a specific time value.
16 type, public :: tdout
17 !> Logical flag to check if object is initialized
18 logical :: built
19 !> Dimension of real data array
20 integer :: dimdata
21 !> Number of data arrays
22 integer :: ndata
23 !> Dimension (`::dimdata`,`::ndata`)
24 real(kind=double), allocatable :: tdactual(:, :)
25 !> Time associated to data stored in `::tdactual`
26 real(kind=double) :: time
27 !> `.true.` if data doeas not depend on time
28 !> `.false.` if data depends on time
29 logical :: steadytd
30 !> `.true.` if steady state data has already
31 !> been written `.false.` otherwise
32 logical :: steadytd_written = .false.
33 contains
34 !> Static constructor for `timeoutputs::tdout`
35 procedure, public, pass :: init => init_td
36 !> Static destructor for `timeoutputs::tdout`
37 procedure, public, pass :: kill => kill_td
38 !> Info procedure for `timeoutputs::tdout`
39 procedure, public, pass :: info => info_td
40 !> Writing procedure for `timeoutputs::tdout`
41 procedure, public, pass :: write2dat => write_td
42 !> Write variable `::time`
43 procedure, public, pass :: write_end_time
44 !> Compute number of data arrays (columns of
45 !> `tdout::tdactual`) having non-zero norm
46 procedure, public, pass :: eval_ninput
47 end type tdout
48
49contains
50
51 !>-------------------------------------------------------------
52 !> @brief Static constructor for `timeoutputs::tdout`
53 !> @details Initialize variables `tdout::dimdata` and `tdout::ndata`
54 !> and allocate variable `tdout::tdactual`. Set `tdout::built = .true.`
55 !> and `tdout::steadytd = .false.`
56 !>
57 !> @param[in] stderr: unit number for error message
58 !> @param[in] dimdata: value to be assigned to `tdout::dimdata`
59 !> @param[in] ndata: value to be assigned to `tdout::ndata`
60 !<-------------------------------------------------------------------
61 subroutine init_td(this, stderr, dimdata, Ndata)
62 implicit none
63 class(tdout), intent(out) :: this
64 integer, intent(in) :: stderr
65 integer, intent(in) :: dimdata
66 integer, intent(in) :: Ndata
67 ! local vars
68 integer :: res
69 logical :: rc
70
71 this%built = .true.
72
73 this%dimdata = dimdata
74 this%ndata = ndata
75
76 allocate (this%TDactual(dimdata, ndata), stat=res)
77 if (res .ne. 0) rc = ioerr(stderr, err_alloc, 'read_TD', &
78 ' type TDOut member TDactual (array)', res)
79 this%TDactual = zero
80
81 this%steadyTD = .false.
82
83 end subroutine init_td
84
85 !>-------------------------------------------------------------
86 !> @brief Static destructor for `timeoutputs::tdout`
87 !> @details Deallocate array `tdout::tdactual` and set
88 !> `tdout::built = .false.`
89 !>
90 !> @param[in] lun: unit number for error message
91 !<-----------------------------------------------------------
92 subroutine kill_td(this, lun)
93 implicit none
94 class(tdout), intent(inout) :: this
95 integer, intent(in) :: lun
96 ! local vars
97 integer :: res
98 logical :: rc
99
100 this%built = .false.
101 deallocate (this%TDactual, stat=res)
102 if (res .ne. 0) rc = ioerr(lun, err_dealloc, 'kill_TD', &
103 'type TDOut var TDactual')
104
105 end subroutine kill_td
106
107 !>-------------------------------------------------------------
108 !> @brief Info procedure for `timeoutputs::tdout`
109 !> @details Write non-zero content of variable `tdout::tdactual`
110 !>
111 !> @param[in] lun: unit number for output message
112 !> @param[in] nsample: number of first non zero columns of
113 !> `tdout::tdactual` to print
114 !<-------------------------------------------------------------
115 subroutine info_td(this, lun, nsample)
116 implicit none
117 class(tdout), intent(in) :: this
118 integer, intent(in) :: lun
119 integer, intent(in) :: nsample
120 ! local vars
121 integer :: i, j, k
122 real(kind=double) :: dnrm2
123
124 write (lun, *) ' '
125 write (lun, *) ' Info: TDOut structure definition:'
126 write (lun, *) 'dimension data', this%dimdata
127 write (lun, *) 'ndata ', this%ndata
128
129 if (this%steadyTD) write (lun, *) ' Steady state'
130 if (.not. this%steadyTD) write (lun, *) ' Not in steady state'
131
132 write (lun, *) ' Actual val '
133 i = 0
134 j = 0
135 do while ((i .lt. this%ndata) .and. (j .lt. nsample))
136 i = i + 1
137 if (dnrm2(this%dimdata, this%TDactual(:, i), 1) .ne. zero) then
138 j = j + 1
139 write (lun, '(5(i5,e11.3))') i, (this%TDactual(k, i), k=1, this%dimdata)
140 end if
141 end do
142
143 end subroutine info_td
144
145 !>-------------------------------------------------------------
146 !> @brief Write non-zero content of `tdout::tdactual` for
147 !> non steady state data
148 !> @details If `tdout::steadytd_written = .false.` this
149 !> procedure writes the columns of `tdout::tdactual`
150 !> having non-zero norm, otherwise it does nothin.
151 !> Then, if `tdout::steadytd = .true.`
152 !> set `tdout::steadytd_written = .true.`.
153 !>
154 !> @param[in] lun: unit number for output
155 !<-------------------------------------------------------------
156 subroutine write_td(this, lun)
157 implicit none
158 class(tdout), intent(inout) :: this
159 integer, intent(in) :: lun
160 !local
161 integer :: i, k, ninput
162 real(kind=double) :: dnrm2
163
164 !> if the steady steady is already written
165 !> do nothing
166 if (.not. this%steadyTD_written) then
167 ninput = this%eval_ninput()
168 write (lun, '(a4,1pe15.6)') 'time', this%time
169 write (lun, *) ninput
170 do i = 1, this%NData
171 if (dnrm2(this%dimdata, this%TDactual(:, i), 1) > small) then
172 write (lun, *) i, (this%TDactual(k, i), k=1, this%dimdata)
173 end if
174 end do
175 !> if the steady steady is reached
176 !> write closing sequence and change the flag
177 if (this%steadyTD) then
178 write (lun, '(a4,1pe15.6)') 'time', huge
179 this%steadyTD_written = .true.
180 end if
181 end if
182
183 end subroutine write_td
184
185 !>-------------------------------------------------------------
186 !> @brief Write variable `tdout::time`
187 !>
188 !> @param[in] lun: unit number for output message
189 !<-------------------------------------------------------------
190 subroutine write_end_time(this, lun)
191 implicit none
192 class(tdout), intent(inout) :: this
193 integer, intent(in) :: lun
194
195 write (lun, '(a4,1pe15.6)') 'time', this%time
196
197 end subroutine write_end_time
198
199 !>-------------------------------------------------------------
200 !> @brief Compute number of data arrays (columns of
201 !> `tdout::tdactual`) having non-zero norm
202 !>
203 !> @return (integer) number of data arrays (columns of
204 !> `tdout::tdactual`) having non-zero norm
205 !<-------------------------------------------------------------
206 function eval_ninput(this) result(ninput)
207 implicit none
208 class(tdout), intent(in) :: this
209 integer :: ninput
210 !local
211 integer :: i
212 real(kind=double) :: dnrm2
213
214 ninput = 0
215
216 do i = 1, this%NData
217 if (dnrm2(this%dimdata, this%TDactual(:, i), 1) > small) then
218 ninput = ninput + 1
219 end if
220 end do
221
222 end function eval_ninput
223
224end module timeoutputs
integer, parameter err_alloc
Error allocation failed.
integer, parameter err_dealloc
Error deallocation failed.
logical function ioerr(lun, errno, call_proc, add_msg, add_int)
Handle and write alert I/O warnings and errors.
subroutine kill_td(this, lun)
Static destructor for timeoutputs::tdout.
subroutine init_td(this, stderr, dimdata, ndata)
Static constructor for timeoutputs::tdout.
subroutine info_td(this, lun, nsample)
Info procedure for timeoutputs::tdout.
integer function eval_ninput(this)
Compute number of data arrays (columns of tdout::tdactual) having non-zero norm.
subroutine write_end_time(this, lun)
Write variable tdout::time.
subroutine write_td(this, lun)
Write non-zero content of tdout::tdactual for non steady state data.
Data structure containing values of a variable possibly depending on time (e.g., forcing function).