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 time_state, only : time_state_t
45 use logger, only : neko_log, neko_log_debug
47 use registry, only : neko_registry
48 use device
49 implicit none
50 private
51
53
55 character(len=20), allocatable :: field_names(:)
56
58 real(kind=rp) :: start_time
59
61 type(data_streamer_t) :: dstream
62
63 contains
65 procedure, pass(this) :: init => data_streamer_simcomp_init_from_json
67 procedure, pass(this) :: init_from_components => &
70 procedure, pass(this) :: free => data_streamer_simcomp_free
72 procedure, pass(this) :: compute_ => data_streamer_simcomp_compute
74
75contains
76
78 subroutine data_streamer_simcomp_init_from_json(this, json, case)
79 class(data_streamer_simcomp_t), intent(inout), target :: this
80 type(json_file), intent(inout) :: json
81 class(case_t), intent(inout), target :: case
82 character(len=20), allocatable :: which_fields(:)
83 character(len=:), allocatable :: name
84 real(kind=rp) :: start_time
85 logical :: stream_mesh
86
87 call json_get_or_default(json, "name", name, "data_streamer_simcomp")
88 call json_get(json, 'fields', which_fields)
89
90 call json_get_or_lookup_or_default(json, 'start_time', start_time, &
91 -1.0_rp)
92
93 call json_get_or_default(json, 'stream_mesh', stream_mesh, .false.)
94
95 call this%init_base(json, case)
96 call this%init_from_components(name, which_fields, start_time, stream_mesh)
97
99
105 which_fields, start_time, stream_mesh)
106 class(data_streamer_simcomp_t), intent(inout) :: this
107 character(len=*), intent(in) :: name
108 character(len=20), intent(in) :: which_fields(:)
109 real(kind=rp), intent(in) :: start_time
110 logical, intent(in) :: stream_mesh
111 type(field_t), pointer :: f
112
113 this%name = name
114 this%field_names = which_fields
115 this%start_time = start_time
116
117 call this%dstream%init(this%case%fluid%c_Xh)
118
119 if (stream_mesh) then
120 ! Stream the mesh coordinates of the first field in which_fields. We
121 ! assume that all fields share the same mesh. We don't use the dofmap
122 ! in case%fluid in case the fields we are streaming are masked.
123 f => neko_registry%get_field_by_name(which_fields(1))
124 call neko_log%message("Using field " // trim(f%name) // &
125 " for streaming mesh", lvl = neko_log_debug)
126 call neko_log%message("Streaming mesh: x-coordinates", &
127 lvl = neko_log_debug)
128 call this%dstream%stream(f%dof%x)
129 call neko_log%message("Streaming mesh: y-coordinates", &
130 lvl = neko_log_debug)
131 call this%dstream%stream(f%dof%y)
132 call neko_log%message("Streaming mesh: z-coordinates", &
133 lvl = neko_log_debug)
134 call this%dstream%stream(f%dof%z)
135 end if
136
138
141 class(data_streamer_simcomp_t), intent(inout) :: this
142 call this%free_base()
143
144 if (allocated(this%field_names)) deallocate(this%field_names)
145 this%start_time = -1.0_rp
146 call this%dstream%free()
147
148 end subroutine data_streamer_simcomp_free
149
152 subroutine data_streamer_simcomp_compute(this, time)
153 class(data_streamer_simcomp_t), intent(inout) :: this
154 type(time_state_t), intent(in) :: time
155
156 integer :: i
157 type(field_t), pointer :: f
158
159 if (time%t .ge. this%start_time) then
160 do i = 1, size(this%field_names)
161
162 ! Sync from GPU to CPU
163 f => neko_registry%get_field_by_name(this%field_names(i))
164 call f%copy_from(device_to_host, .true.)
165
166 call neko_log%message("Streaming field: " // this%field_names(i))
167
168 ! Stream the field
169 call this%dstream%stream(f%x)
170 end do
171 end if
172
173 end subroutine data_streamer_simcomp_compute
174
175end 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
A simulation component that streams data using ADIOS2.
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.
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.