Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
data_streamer_simcomp.F90
Go to the documentation of this file.
1! Copyright (c) 2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33!
36 use num_types, only : rp
37 use json_module, only : json_file
41 use field, only : field_t
42 use case, only : case_t
43 use comm, only : pe_rank
44 use time_state, only : time_state_t
46 use logger, only : neko_log, neko_log_debug
48 use registry, only : neko_registry
49 use device
51 use, intrinsic :: iso_c_binding
52 implicit none
53 private
54
56
58 character(len=NEKO_VARNAME_LEN), allocatable :: field_names(:)
59
61 real(kind=rp) :: start_time
62
64 type(data_streamer_t) :: dstream
65
67 logical :: checked = .false.
68
69 contains
71 procedure, pass(this) :: init => data_streamer_simcomp_init_from_json
73 procedure, pass(this) :: init_from_components => &
76 procedure, pass(this) :: free => data_streamer_simcomp_free
78 procedure, pass(this) :: compute_ => data_streamer_simcomp_compute
80 procedure, pass(this) :: check => data_streamer_simcomp_check
82
83contains
84
90 class(data_streamer_simcomp_t), intent(inout) :: this
91
92 type(field_t), pointer :: f
93 integer :: i, num_elements
94 integer :: dof_size
95
96 if (size(this%field_names) .eq. 0) call neko_error("Empty list of fields")
97
98 f => neko_registry%get_field_by_name(this%field_names(1))
99 num_elements = f%msh%nelv
100 dof_size = f%size()
101
102 ! Loop through all fields and make sure they are "the same".
103 do i = 2, size(this%field_names)
104 f => neko_registry%get_field_by_name(this%field_names(i))
105
106 if (f%msh%nelv .ne. num_elements .or. f%size() .ne. dof_size) then
107 call neko_error("Invalid field :" // trim(f%name) // &
108 "! All streamed fields must have the same size.")
109 end if
110
111 end do
112
113#ifdef HAVE_ADIOS2
114#else
115 call neko_error('Neko has not been configured with ADIOS2 support! ' // &
116 'Use --with-adios2=your/adios2/installation')
117#endif
118
119 this%checked = .true.
120
121 end subroutine data_streamer_simcomp_check
122
124 subroutine data_streamer_simcomp_init_from_json(this, json, case)
125 class(data_streamer_simcomp_t), intent(inout), target :: this
126 type(json_file), intent(inout) :: json
127 class(case_t), intent(inout), target :: case
128 character(len=NEKO_VARNAME_LEN), allocatable :: which_fields(:)
129 character(len=:), allocatable :: name
130 real(kind=rp) :: start_time
131 logical :: stream_mesh
132
133 call json_get_or_default(json, "name", name, "data_streamer_simcomp")
134 call json_get(json, 'fields', which_fields)
135
136 call json_get_or_lookup_or_default(json, 'start_time', start_time, &
137 -1.0_rp)
138
139 call json_get_or_default(json, 'stream_mesh', stream_mesh, .false.)
140
141 call this%init_base(json, case)
142 call this%init_from_components(name, which_fields, start_time, stream_mesh)
143
145
151 which_fields, start_time, stream_mesh)
152 class(data_streamer_simcomp_t), intent(inout) :: this
153 character(len=*), intent(in) :: name
154 character(len=*), intent(in) :: which_fields(:)
155 real(kind=rp), intent(in) :: start_time
156 logical, intent(in) :: stream_mesh
157 type(field_t), pointer :: f
158
159 this%name = name
160 this%field_names = which_fields
161 this%start_time = start_time
162
163 call this%check()
164
165 ! Use the mesh/element information in the first field to initialize the
166 ! streamer. We assume that all fields share the same mesh.
167 f => neko_registry%get_field(which_fields(1))
168 call this%dstream%init(f%msh, f%xh)
169
170 if (stream_mesh) then
171 call neko_log%message("Using field " // trim(f%name) // &
172 " for streaming mesh", lvl = neko_log_debug)
173 call neko_log%message("Streaming mesh: x-coordinates", &
174 lvl = neko_log_debug)
175 call this%dstream%stream(f%dof%x)
176 call neko_log%message("Streaming mesh: y-coordinates", &
177 lvl = neko_log_debug)
178 call this%dstream%stream(f%dof%y)
179 call neko_log%message("Streaming mesh: z-coordinates", &
180 lvl = neko_log_debug)
181 call this%dstream%stream(f%dof%z)
182 end if
183
184 nullify(f)
185
187
190 class(data_streamer_simcomp_t), intent(inout) :: this
191 call this%free_base()
192
193 if (allocated(this%field_names)) deallocate(this%field_names)
194 this%start_time = -1.0_rp
195 call this%dstream%free()
196
197 end subroutine data_streamer_simcomp_free
198
201 subroutine data_streamer_simcomp_compute(this, time)
202 class(data_streamer_simcomp_t), intent(inout) :: this
203 type(time_state_t), intent(in) :: time
204
205 integer :: i
206 type(field_t), pointer :: f
207
208 if (.not. this%checked) call neko_error("Simcomp not checked!")
209
210 if (time%t .ge. this%start_time) then
211 do i = 1, size(this%field_names)
212
213 ! Sync from GPU to CPU
214 f => neko_registry%get_field_by_name(this%field_names(i))
215 call f%copy_from(device_to_host, .true.)
216
217 call neko_log%message("Streaming field: " // this%field_names(i))
218
219 ! Stream the field
220 call this%dstream%stream(f%x)
221 end do
222 end if
223
224 end subroutine data_streamer_simcomp_compute
225
226end module data_streamer_simcomp
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Defines a simulation case.
Definition case.f90:34
Definition comm.F90:1
integer, public pe_rank
MPI rank.
Definition comm.F90:56
A simulation component that streams data using ADIOS2.
subroutine data_streamer_simcomp_check(this)
Checks the validity of the simcomp. Currently, makes sure that:
subroutine data_streamer_simcomp_free(this)
Destructor.
subroutine data_streamer_simcomp_init_from_json(this, json, case)
Constructor from json.
subroutine data_streamer_simcomp_compute(this, time)
Compute the data_streamer_simcomp field.
subroutine data_streamer_simcomp_init_from_components(this, name, which_fields, start_time, stream_mesh)
Common part of constructors.
Implements type data_streamer_t.
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:47
Defines a field.
Definition field.f90:34
Utilities for retrieving parameters from the case files.
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_debug
Debug log level.
Definition log.f90:89
type(log_t), public neko_log
Global log stream.
Definition log.f90:79
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:144
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine compute_(this, time)
Dummy compute function.
Contains the time_based_controller_t type.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_varname_len
Definition utils.f90:42
Provides access to data streaming by interfacing with c++ ADIOS2 subroutines.
Base abstract class for simulation components.
A utility type for determining whether an action should be executed based on the current time value....
A struct that contains all info about the time, expand as needed.