Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
simulation_component_fctry.f90
Go to the documentation of this file.
1! Copyright (c) 2024, 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!
35submodule(simulation_component) simulation_component_fctry
39 use user_stats, only : user_stats_t
40 use lambda2, only : lambda2_t
41 use probes, only : probes_t
42 use les_simcomp, only : les_simcomp_t
45 use curl_simcomp, only : curl_t
52 implicit none
53
54 ! List of all possible types created by the factory routine
55 character(len=20) :: SIMCOMPS_KNOWN_TYPES(14) = [character(len=20) :: &
56 "lambda2", &
57 "probes", &
58 "les_model", &
59 "field_writer", &
60 "fluid_stats", &
61 "scalar_stats", &
62 "grad", &
63 "div", &
64 "curl", &
65 "derivative", &
66 "weak_grad", &
67 "force_torque", &
68 "user_stats", &
69 "spectral_error"]
70
71contains
72
77 module subroutine simulation_component_factory(object, json, case)
78 class(simulation_component_t), allocatable, intent(inout) :: object
79 type(json_file), intent(inout) :: json
80 class(case_t), intent(inout), target :: case
81 character(len=:), allocatable :: type_name
82 character(len=:), allocatable :: type_string
83 logical :: is_user
84
85 ! Check if this is a user-defined component
86 call json_get_or_default(json, "is_user", is_user, .false.)
87 if (is_user) return
88
89 ! Get the type name
90 call json_get(json, "type", type_name)
91
92 ! Allocate
93 call simulation_component_allocator(object, type_name)
94
95 ! Initialize
96 call object%init(json, case)
97
98 end subroutine simulation_component_factory
99
103 module subroutine simulation_component_allocator(object, type_name)
104 class(simulation_component_t), allocatable, intent(inout) :: object
105 character(len=*), intent(in):: type_name
106 integer :: i
107
108 if (allocated(object)) then
109 call object%free()
110 deallocate(object)
111 end if
112
113 select case (trim(type_name))
114 case ("lambda2")
115 allocate(lambda2_t::object)
116 case ("probes")
117 allocate(probes_t::object)
118 case ("les_model")
119 allocate(les_simcomp_t::object)
120 case ("field_writer")
121 allocate(field_writer_t::object)
122 case ("weak_grad")
123 allocate(weak_gradient_t::object)
124 case ("grad")
125 allocate(gradient_t::object)
126 case ("derivative")
127 allocate(derivative_t::object)
128 case ("curl")
129 allocate(curl_t::object)
130 case ("div")
131 allocate(divergence_t::object)
132 case ("force_torque")
133 allocate(force_torque_t::object)
134 case ("fluid_stats")
135 allocate(fluid_stats_simcomp_t::object)
136 case ("scalar_stats")
137 allocate(scalar_stats_simcomp_t::object)
138 case ("user_stats")
139 allocate(user_stats_t::object)
140 case ("spectral_error")
141 allocate(spectral_error_t::object)
142 case default
143 do i = 1, simcomp_registry_size
144 if (trim(type_name) == &
145 trim(simcomp_registry(i)%type_name)) then
146 call simcomp_registry(i)%allocator(object)
147 return
148 end if
149 end do
150 call neko_type_error("simulation component", trim(type_name), &
151 simcomps_known_types)
152 end select
153
154 end subroutine simulation_component_allocator
155
161 module subroutine register_simulation_component(type_name, allocator)
162 character(len=*), intent(in) :: type_name
163 procedure(simulation_component_allocate), pointer, intent(in) :: allocator
164 type(allocator_entry), allocatable :: temp(:)
165 integer :: i
166
167 do i = 1, size(simcomps_known_types)
168 if (trim(type_name) .eq. trim(simcomps_known_types(i))) then
169 call neko_type_registration_error("simulation component", type_name, &
170 .true.)
171 end if
172 end do
173
174 do i = 1, simcomp_registry_size
175 if (trim(type_name) .eq. &
176 trim(simcomp_registry(i)%type_name)) then
177 call neko_type_registration_error("simulation component", type_name, &
178 .false.)
179 end if
180 end do
181
182 ! Expand registry
183 if (simcomp_registry_size == 0) then
184 allocate(simcomp_registry(1))
185 else
186 allocate(temp(simcomp_registry_size + 1))
187 temp(1:simcomp_registry_size) = simcomp_registry
188 call move_alloc(temp, simcomp_registry)
189 end if
190
191 simcomp_registry_size = simcomp_registry_size + 1
192 simcomp_registry(simcomp_registry_size)%type_name = type_name
193 simcomp_registry(simcomp_registry_size)%allocator => allocator
194 end subroutine register_simulation_component
195
196end submodule simulation_component_fctry
Defines a simulation case.
Definition case.f90:34
Implements the curl_t type.
Implements the derivative_t type.
Implements the divergence_t type.
Implements the field_writer_t type.
Implements the fluid_stats_simcomp_t type.
Implements the force_torque_t type.
Implements the gradient_t type.
A simulation component that computes lambda2 The values are stored in the field registry under the na...
Definition lambda2.f90:37
Implements the les_simcomp_t type.
Implements probes.
Definition probes.F90:37
Implements the scalar_stats_simcomp_t type.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
Implements type spectral_error_t.
Implements the user_stats_t type.
Utilities.
Definition utils.f90:35
character(:) function, allocatable, public concat_string_array(array, sep, prepend)
Concatenate an array of strings into one string with array items separated by spaces.
Definition utils.f90:356
subroutine, public neko_type_registration_error(base_type, wrong_type, known)
Definition utils.f90:328
subroutine, public neko_type_error(base_type, wrong_type, known_types)
Reports an error allocating a type for a particular base pointer class.
Definition utils.f90:313
Implements the weak_gradient_t type.
A simulation component that computes the curl of a vector field. Added to the field registry as curl_...
A simulation component that computes a derivative of a field. Wraps the duxyz operator.
A simulation component that computes the divergence of a vector field. Added to the field registry as...
A simulation component that writes a 3d field to a file.
A simulation component that computes the velocity and pressure statistics up to 4th order....
A simulation component that computes the force and torque on a given boundary zone.
A simulation component that computes the gradient of a field. Wraps the gradient operator.
A simulation component that drives the computation of the SGS viscosity.
A simulation component that computes the scalar statistics for the skewness, kurtosis,...
Provides tools to calculate the spectral error indicator.
A simulation component that computes the averages of fields in the registry.
A simulation component that computes the weak gradient of a field. Wraps the opgradient operator.