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 vector, only: vector_t
38 use utils, only: neko_error
39 use comm, only: neko_comm
40 use mpi_f08, only: mpi_allreduce, mpi_integer, mpi_sum
41 implicit none
42 private
43
50 type, abstract :: design_t
51 private
52
54 integer :: n = 0
56 integer :: n_global = 0
57
58 contains
59
60 ! ----------------------------------------------------------------------- !
61 ! Interfaces
62
73 procedure, pass(this) :: init_from_json_sim => design_init_from_json_sim
74
83 procedure, pass(this) :: init_from_json => design_init_from_json
84
86 procedure(design_free), public, pass(this), deferred :: free
87
89 procedure(design_get_values), public, pass(this), deferred :: get_values
91 procedure, public, pass(this) :: get_x => design_get_x
93 procedure, public, pass(this) :: get_y => design_get_y
95 procedure, public, pass(this) :: get_z => design_get_z
96
98 procedure(design_update_design), public, pass(this), deferred :: &
99 update_design
100
102 procedure(design_map_forward), public, pass(this), deferred :: &
103 map_forward
105 procedure(design_map_backward), public, pass(this), deferred :: &
106 map_backward
108 procedure(design_write), public, pass(this), deferred :: write
109
110 ! ----------------------------------------------------------------------- !
111 ! Methods
112
114 procedure, pass(this) :: init_base => design_init_base
116 procedure, pass(this) :: free_base => design_free_base
118 procedure, public, pass(this) :: size => design_size
120 procedure, public, pass(this) :: size_global => design_size_global
121
122 end type design_t
123
124 ! ========================================================================== !
125 ! Interface for the factory function
126
137 module subroutine design_factory(object, parameters, simulation)
138 class(design_t), allocatable, intent(inout) :: object
139 type(json_file), intent(inout) :: parameters
140 type(simulation_t), intent(inout), optional :: simulation
141 end subroutine design_factory
142 end interface design_factory
143
144
145 ! ========================================================================== !
146 ! Public interface for the deferred methods
147
148 abstract interface
149 subroutine design_free(this)
150 import design_t
151 class(design_t), intent(inout) :: this
152 end subroutine design_free
153
154 function design_get_values(this) result(values)
155 import design_t, vector_t
156 class(design_t), intent(in) :: this
157 type(vector_t) :: values
158 end function design_get_values
159
160 subroutine design_update_design(this, values)
161 import design_t, vector_t
162 class(design_t), intent(inout) :: this
163 type(vector_t), intent(inout) :: values
164 end subroutine design_update_design
165
166 subroutine design_map_forward(this)
167 import design_t
168 class(design_t), intent(inout) :: this
169 end subroutine design_map_forward
170
171 subroutine design_map_backward(this, sensitivity)
172 import design_t, vector_t
173 class(design_t), intent(inout) :: this
174 type(vector_t), intent(in) :: sensitivity
175 end subroutine design_map_backward
176
177 subroutine design_write(this, idx)
178 import design_t
179 class(design_t), intent(inout) :: this
180 integer, intent(in) :: idx
181 end subroutine design_write
182 end interface
183
184 public :: design_t, design_factory
185contains
186
190 subroutine design_init_from_json(this, parameters)
191 class(design_t), intent(inout) :: this
192 type(json_file), intent(inout) :: parameters
193
194 call neko_error("Design type does not support initialization " // &
195 "without simulation")
196 end subroutine design_init_from_json
197
202 subroutine design_init_from_json_sim(this, parameters, simulation)
203 class(design_t), intent(inout) :: this
204 type(json_file), intent(inout) :: parameters
205 type(simulation_t), intent(inout) :: simulation
206
207 call neko_error("Design type does not support initialization " // &
208 "with simulation")
209 end subroutine design_init_from_json_sim
210
214 subroutine design_init_base(this, n)
215 class(design_t), intent(inout) :: this
216 integer, intent(in) :: n
217 integer :: ierr
218
219 this%n = n
220 call mpi_allreduce(n, this%n_global, 1, mpi_integer, mpi_sum, &
221 neko_comm, ierr)
222 end subroutine design_init_base
223
226 subroutine design_free_base(this)
227 class(design_t), intent(inout) :: this
228 this%n = 0
229 end subroutine design_free_base
230
234 pure function design_size(this) result(n)
235 class(design_t), intent(in) :: this
236 integer :: n
237 n = this%n
238 end function design_size
239
241 pure function design_size_global(this) result(n)
242 class(design_t), intent(in) :: this
243 integer :: n
244 n = this%n_global
245 end function design_size_global
246
247 function design_get_x(this) result(values)
248 class(design_t), intent(in) :: this
249 type(vector_t) :: values
250 call neko_error("Design type does not support x retrieval")
251 end function design_get_x
252
253 function design_get_y(this) result(values)
254 class(design_t), intent(in) :: this
255 type(vector_t) :: values
256 call neko_error("Design type does not support y retrieval")
257 end function design_get_y
258
259 function design_get_z(this) result(values)
260 class(design_t), intent(in) :: this
261 type(vector_t) :: values
262 call neko_error("Design type does not support z retrieval")
263 end function design_get_z
264
265end module design
Factory function for the design object.
Definition design.f90:136
Implements the design_t.
Definition design.f90:34
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:50