Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
design.f90
1! Copyright (c) 2024-2025, 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
34module design
35 use json_module, only: json_file
36 use simulation_m, only: simulation_t
37 use num_types, only: rp
38 use vector, only: vector_t
39 use utils, only: neko_error
40 use point_zone, only: point_zone_t
41 use comm, only: neko_comm
42 use mpi_f08, only: mpi_allreduce, mpi_integer, mpi_sum
43 implicit none
44 private
45
52 type, abstract :: design_t
53 private
55 character(len=:), allocatable :: name
56
58 integer :: n = 0
60 integer :: n_global = 0
61
62 contains
63
64 ! ----------------------------------------------------------------------- !
65 ! Interfaces
66
77 procedure, pass(this) :: init_from_json_sim => design_init_from_json_sim
78
87 procedure, pass(this) :: init_from_json => design_init_from_json
88
90 procedure(design_free), public, pass(this), deferred :: free
91
93 procedure(design_get_values), public, pass(this), deferred :: get_values
95 generic :: get_x => design_get_x
96 generic :: x => design_get_x_i
98 generic :: get_y => design_get_y
99 generic :: y => design_get_y_i
101 generic :: get_z => design_get_z
102 generic :: z => design_get_z_i
103
105 procedure(design_update_design), public, pass(this), deferred :: &
106 update_design
107
109 procedure(design_map_forward), public, pass(this), deferred :: &
110 map_forward
112 procedure(design_map_backward), public, pass(this), deferred :: &
113 map_backward
115 procedure(design_write), public, pass(this), deferred :: write
116
117 ! ----------------------------------------------------------------------- !
118 ! Methods
119
121 procedure, pass(this) :: init_base => design_init_base
123 procedure, pass(this) :: free_base => design_free_base
125 procedure, public, pass(this) :: size => design_size
127 procedure, public, pass(this) :: size_global => design_size_global
128
130 procedure, pass(this) :: design_get_x
132 procedure, pass(this) :: design_get_x_i
134 procedure, pass(this) :: design_get_y
136 procedure, pass(this) :: design_get_y_i
138 procedure, pass(this) :: design_get_z
140 procedure, pass(this) :: design_get_z_i
141 end type design_t
142
143 ! ========================================================================== !
144 ! Interface for the factory function
145
156 module subroutine design_factory(object, parameters, simulation)
157 class(design_t), allocatable, intent(inout) :: object
158 type(json_file), intent(inout) :: parameters
159 type(simulation_t), intent(inout), optional :: simulation
160 end subroutine design_factory
161 end interface design_factory
162
163
164 ! ========================================================================== !
165 ! Public interface for the deferred methods
166
167 abstract interface
168 subroutine design_free(this)
169 import design_t
170 class(design_t), intent(inout) :: this
171 end subroutine design_free
172
173 subroutine design_get_values(this, values)
174 import design_t, vector_t
175 class(design_t), intent(in) :: this
176 type(vector_t), intent(inout) :: values
177 end subroutine design_get_values
178
179 subroutine design_update_design(this, values)
180 import design_t, vector_t
181 class(design_t), intent(inout) :: this
182 type(vector_t), intent(inout) :: values
183 end subroutine design_update_design
184
185 subroutine design_map_forward(this)
186 import design_t
187 class(design_t), intent(inout) :: this
188 end subroutine design_map_forward
189
190 subroutine design_map_backward(this, sensitivity)
191 import design_t, vector_t
192 class(design_t), intent(inout) :: this
193 type(vector_t), intent(in) :: sensitivity
194 end subroutine design_map_backward
195
196 subroutine design_write(this, idx)
197 import design_t
198 class(design_t), intent(inout) :: this
199 integer, intent(in) :: idx
200 end subroutine design_write
201 end interface
202
203 public :: design_t, design_factory
204contains
205
209 subroutine design_init_from_json(this, parameters)
210 class(design_t), intent(inout) :: this
211 type(json_file), intent(inout) :: parameters
212
213 call neko_error("Design type does not support initialization " // &
214 "without simulation")
215 end subroutine design_init_from_json
216
221 subroutine design_init_from_json_sim(this, parameters, simulation)
222 class(design_t), intent(inout) :: this
223 type(json_file), intent(inout) :: parameters
224 type(simulation_t), intent(inout) :: simulation
225
226 call neko_error("Design type does not support initialization " // &
227 "with simulation")
228 end subroutine design_init_from_json_sim
229
234 subroutine design_init_base(this, name, n)
235 class(design_t), intent(inout) :: this
236 character(len=*), intent(in) :: name
237 integer, intent(in) :: n
238 integer :: ierr
239
240 this%name = name
241 this%n = n
242 call mpi_allreduce(n, this%n_global, 1, mpi_integer, mpi_sum, &
243 neko_comm, ierr)
244 end subroutine design_init_base
245
248 subroutine design_free_base(this)
249 class(design_t), intent(inout) :: this
250 this%name = ""
251 this%n = 0
252 this%n_global = 0
253 end subroutine design_free_base
254
258 pure function design_size(this) result(n)
259 class(design_t), intent(in) :: this
260 integer :: n
261 n = this%n
262 end function design_size
263
265 pure function design_size_global(this) result(n)
266 class(design_t), intent(in) :: this
267 integer :: n
268 n = this%n_global
269 end function design_size_global
270
271 subroutine design_get_x(this, x)
272 class(design_t), intent(in) :: this
273 type(vector_t), intent(inout) :: x
274 call neko_error("Design type does not support x retrieval")
275 end subroutine design_get_x
276
277 function design_get_x_i(this, i) result(x_i)
278 class(design_t), intent(in) :: this
279 integer, intent(in) :: i
280 real(kind=rp) :: x_i
281 x_i = -huge(x_i)
282 call neko_error("Design type does not support x retrieval")
283 end function design_get_x_i
284
285 subroutine design_get_y(this, y)
286 class(design_t), intent(in) :: this
287 type(vector_t), intent(inout) :: y
288 call neko_error("Design type does not support y retrieval")
289 end subroutine design_get_y
290
291 function design_get_y_i(this, i) result(y_i)
292 class(design_t), intent(in) :: this
293 integer, intent(in) :: i
294 real(kind=rp) :: y_i
295 y_i = -huge(y_i)
296 call neko_error("Design type does not support y retrieval")
297 end function design_get_y_i
298
299 subroutine design_get_z(this, z)
300 class(design_t), intent(in) :: this
301 type(vector_t), intent(inout) :: z
302 call neko_error("Design type does not support z retrieval")
303 end subroutine design_get_z
304
305 function design_get_z_i(this, i) result(z_i)
306 class(design_t), intent(in) :: this
307 integer, intent(in) :: i
308 real(kind=rp) :: z_i
309 z_i = -huge(z_i)
310 call neko_error("Design type does not support z retrieval")
311 end function design_get_z_i
312
313end module design
Factory function for the design object.
Definition design.f90:155
Implements the design_t.
Definition design.f90:34
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:52