FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
readtemp.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2019 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
5 module mreadtemp
6 
7  private
9 
10 contains
11 
13  subroutine read_temperature_result(hecMESH, nstep, sstep, rtype, interval, factor, ctime, temp, temp_bak)
14  use m_fstr
15  type(hecmwst_local_mesh), intent(in) :: hecmesh
16  integer(kind=kint), intent(in) :: nstep
17  integer(kind=kint), intent(in) :: sstep
18  integer(kind=kint), intent(in) :: rtype
19  integer(kind=kint), intent(in) :: interval
20  real(kind=kreal), intent(in) :: factor
21  real(kind=kreal), intent(in) :: ctime
22  real(kind=kreal), pointer :: temp(:)
23  real(kind=kreal), pointer :: temp_bak(:)
24  if( rtype == 1 ) then
25  call read_temperature_result_by_step(hecmesh, nstep, sstep, interval, factor, temp, temp_bak)
26  elseif( rtype == 2 ) then
27  call read_temperature_result_by_time(hecmesh, nstep, sstep, ctime, temp)
28  endif
29  write(idbg,*) ' Read temperature from result file : OK'
30  end subroutine read_temperature_result
31 
32  subroutine read_temperature_result_by_step(hecMESH, nstep, sstep, interval, factor, temp, temp_bak)
33  use hecmw_result
34  use m_fstr
35  type(hecmwst_local_mesh), intent(in) :: hecmesh
36  integer(kind=kint), intent(in) :: nstep
37  integer(kind=kint), intent(in) :: sstep
38  integer(kind=kint), intent(in) :: interval
39  real(kind=kreal), intent(in) :: factor
40  real(kind=kreal), pointer :: temp(:)
41  real(kind=kreal), pointer :: temp_bak(:)
42  type(hecmwst_result_data) :: result
43  character(len=HECMW_NAME_LEN) :: name_id
44  integer(kind=kint) :: i, k0, kt, nstep_active, tstep
45  real(kind=kreal) :: w
46 
47  real(kind=kreal), pointer :: temp0(:,:)
48 
49  allocate(temp0(2,size(temp)), stat=i)
50  if( i /= 0 ) then
51  write(*,*) 'Allocation error: temp0'
52  call hecmw_abort(hecmw_comm_get_comm())
53  endif
54 
55  nstep_active = (nstep-sstep)/interval + 1
56  kt = floor(factor*dble(nstep_active)-1.d-10)
57  w = factor*dble(nstep_active)-dble(kt)
58 
59  do k0=1,2
60  tstep = sstep+(kt+k0-2)*interval
61  if( tstep == 0 ) then
62  do i=1, hecmesh%n_node
63  temp0(k0,i) = temp_bak(i)
64  enddo
65  cycle
66  end if
67 
68  call hecmw_nullify_result_data( result )
69  name_id = 'fstrTEMP'
70  call hecmw_result_read_by_name(hecmesh, name_id, tstep, result)
71 
72  if (result%nn_component /= 1 .or. result%nn_dof(1) /= 1) then
73  write(*,*) ' Read temperature result failed; not heat analysis result'
74  endif
75 
76  do i=1, hecmesh%n_node
77  temp0(k0,i) = result%node_val_item(i)
78  enddo
79 
80  call hecmw_result_free(result)
81  enddo
82 
83  do i=1, hecmesh%n_node
84  temp(i) = (1.d0-w)*temp0(1,i)+w*temp0(2,i)
85  enddo
86 
87  deallocate(temp0)
88  end subroutine read_temperature_result_by_step
89 
91  subroutine read_temperature_result_by_time(hecMESH, nstep, sstep, ctime, temp)
92  use hecmw_result
93  use m_fstr
94  type(hecmwst_local_mesh), intent(in) :: hecmesh
95  integer(kind=kint), intent(in) :: nstep
96  integer(kind=kint), intent(in) :: sstep
97  real(kind=kreal), intent(in) :: ctime
98  real(kind=kreal), pointer :: temp(:)
99 
100  logical, save :: flg_first_call = .true.
101  logical, save :: flg_constant = .false.
102  logical, save :: flg_finished = .false.
103  integer(kind=kint), save :: tstep1, tstep2
104  real(kind=kreal), save :: ttime1, ttime2
105 
106  integer(kind=kint) :: ierr, i
107  real(kind=kreal) :: w
108  logical :: flg_read1, flg_read2
109  real(kind=kreal), allocatable :: temp0(:,:)
110 
111  allocate(temp0(2,size(temp)), stat=ierr)
112  if( ierr /= 0 ) then
113  write(*,*) 'Allocation error: temp0'
114  call hecmw_abort(hecmw_comm_get_comm())
115  endif
116  flg_read1 = .false.
117  flg_read2 = .false.
118  ! read first 2 results at first call
119  if (flg_first_call) then
120  call read_next_result(hecmesh, nstep, sstep, tstep1, ttime1, temp0(1,:), ierr)
121  ! if no more result; error: no result file
122  if (ierr /= 0) then
123  write(*,*) ' Read temperature result failed; no result file'
124  call hecmw_abort(hecmw_comm_get_comm())
125  endif
126  flg_read1 = .true.
127  call read_next_result(hecmesh, nstep, tstep1+1, tstep2, ttime2, temp0(2,:), ierr)
128  ! if no more result (only 1 result exists); assume temperature is constant
129  if (ierr /= 0) flg_constant = .true.
130  flg_read2 = .true.
131  flg_first_call = .false.
132  endif
133  ! when temperature is assumed constant
134  if (flg_constant) then
135  if (.not. flg_read1) call read_result_at(hecmesh, tstep1, ttime1, temp0(1,:))
136  do i=1, hecmesh%n_node
137  temp(i) = temp0(1,i)
138  enddo
139  return
140  endif
141  ! when ctime is out-of-range (left side)
142  if (ctime <= ttime1) then
143  if (.not. flg_read1) call read_result_at(hecmesh, tstep1, ttime1, temp0(1,:))
144  do i=1, hecmesh%n_node
145  temp(i) = temp0(1,i)
146  enddo
147  return
148  endif
149  ! proceed until ctime is within [ttime1, ttime2]
150  do while (ttime2 < ctime)
151  tstep1 = tstep2
152  ttime1 = ttime2
153  if (flg_read2) then
154  do i=1, hecmesh%n_node
155  temp0(1,i) = temp0(2,i)
156  enddo
157  flg_read1 = .true.
158  endif
159  flg_read2 = .false.
160  call read_next_result(hecmesh, nstep, tstep1+1, tstep2, ttime2, temp0(2,:), ierr)
161  ! if no more result; finished reading (ctime is out-of-range)
162  if (ierr /= 0) then
163  flg_finished = .true.
164  exit
165  endif
166  flg_read2 = .true.
167  enddo
168  ! when ctime is out-of-range (right side)
169  if (flg_finished) then
170  if (.not. flg_read1) call read_result_at(hecmesh, tstep1, ttime1, temp0(1,:))
171  do i=1, hecmesh%n_node
172  temp(i) = temp0(1,i)
173  enddo
174  return
175  endif
176  ! now, ttime1 <= ctime <= ttime2
177  if (.not. flg_read1) call read_result_at(hecmesh, tstep1, ttime1, temp0(1,:))
178  if (.not. flg_read2) call read_result_at(hecmesh, tstep2, ttime2, temp0(2,:))
179  w = (ctime - ttime1) / (ttime2 - ttime1)
180  do i=1, hecmesh%n_node
181  temp(i) = (1-w)*temp0(1,i) + w*temp0(2,i)
182  enddo
183  !write(IDBG,'(a,f10.2,a,i0,a,f10.2,a,i0,a,f10.2,a)') &
184  ! ' Interpolated temp at',ctime,' from step ',tstep1,' (time',ttime1,') and step ',tstep2,' (time',ttime2,')'
185  return
186  end subroutine read_temperature_result_by_time
187 
188  subroutine read_result_at(hecMESH, tstep, ttime, temp)
189  use m_fstr
190  use hecmw_result
191  implicit none
192  type(hecmwst_local_mesh), intent(in) :: hecmesh
193  integer(kind=kint), intent(in) :: tstep
194  real(kind=kreal), intent(out) :: ttime
195  real(kind=kreal), intent(out) :: temp(:)
196  type(hecmwst_result_data) :: result
197  character(len=HECMW_NAME_LEN) :: name_id
198  integer(kind=kint) :: i
199  call hecmw_nullify_result_data( result )
200  name_id = 'fstrTEMP'
201  call hecmw_result_read_by_name(hecmesh, name_id, tstep, result)
202  if (result%nn_component /= 1 .or. result%nn_dof(1) /= 1) then
203  write(*,*) ' Read temperature result failed; not heat analysis result'
204  endif
205  ttime = result%global_val_item(1)
206  do i=1, hecmesh%n_node
207  temp(i) = result%node_val_item(i)
208  enddo
209  call hecmw_result_free(result)
210  end subroutine read_result_at
211 
212  subroutine read_next_result(hecMESH, nstep, sstep, tstep, ttime, temp, ierr)
213  use m_fstr
214  use hecmw_result
215  implicit none
216  type(hecmwst_local_mesh), intent(in) :: hecMESH
217  integer(kind=kint), intent(in) :: nstep
218  integer(kind=kint), intent(in) :: sstep
219  integer(kind=kint), intent(out) :: tstep
220  real(kind=kreal), intent(out) :: ttime
221  real(kind=kreal), intent(out) :: temp(:)
222  integer(kind=kint), intent(out) :: ierr
223  character(len=HECMW_NAME_LEN) :: name_ID
224  integer(kind=kint) :: istep
225  name_id = 'fstrTEMP'
226  tstep = -1
227  do istep = sstep, nstep
228  call hecmw_result_checkfile_by_name(name_id, istep, ierr)
229  if (ierr == 0) then
230  tstep = istep
231  exit
232  endif
233  enddo
234  if (tstep < 0) then
235  ierr = 1
236  return
237  endif
238  call read_result_at(hecmesh, tstep, ttime, temp)
239  end subroutine read_next_result
240 
241 end module mreadtemp
I/O and Utility.
subroutine, public hecmw_result_checkfile_by_name(name_ID, i_step, ierr)
subroutine, public hecmw_result_read_by_name(hecMESH, name_ID, i_step, result)
subroutine, public hecmw_nullify_result_data(P)
subroutine, public hecmw_result_free(result_data)
This module defines common data and basic structures for analysis.
Definition: m_fstr.F90:15
integer(kind=kint), parameter idbg
Definition: m_fstr.F90:113
subroutine read_next_result(hecMESH, nstep, sstep, tstep, ttime, temp, ierr)
Definition: readtemp.f90:213
subroutine read_temperature_result_by_step(hecMESH, nstep, sstep, interval, factor, temp, temp_bak)
Definition: readtemp.f90:33
subroutine read_temperature_result_by_time(hecMESH, nstep, sstep, ctime, temp)
Read in temperature distribution from external file.
Definition: readtemp.f90:92
subroutine read_result_at(hecMESH, tstep, ttime, temp)
Definition: readtemp.f90:189
subroutine, public read_temperature_result(hecMESH, nstep, sstep, rtype, interval, factor, ctime, temp, temp_bak)
Read in temperature distribution from external file.
Definition: readtemp.f90:14