Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
RAMP_mapping.f90
Go to the documentation of this file.
1
34!
37 use num_types, only: rp
38 use mapping, only: mapping_t
39 use json_module, only: json_file
40 use field, only: field_t
41 use coefs, only: coef_t
42 use neko_config, only: neko_bcknd_device
43 use device_ramp_mapping, only: device_convex_down_ramp_mapping_apply, &
44 device_convex_down_ramp_mapping_apply_backward, &
45 device_convex_up_ramp_mapping_apply, &
46 device_convex_up_ramp_mapping_apply_backward
51 use json_utils, only: json_get, json_get_or_default
52 use logger, only: neko_log
53 use continuation_scheduler, only: nekotop_continuation
54 implicit none
55 private
56
84
85 type, public, extends(mapping_t) :: ramp_mapping_t
87 real(kind=rp) :: f_min
89 real(kind=rp) :: f_max
91 real(kind=rp) :: q
94 logical :: convex_up
95
96 contains
98 procedure, pass(this) :: init => ramp_mapping_init_from_json
100 procedure, pass(this) :: init_from_attributes => &
101 ramp_mapping_init_from_attributes
103 procedure, pass(this) :: free => ramp_mapping_free
105 procedure, pass(this) :: forward_mapping => ramp_forward_mapping
107 procedure, pass(this) :: backward_mapping => ramp_backward_mapping
108 end type ramp_mapping_t
109
110contains
111
113 subroutine ramp_mapping_init_from_json(this, json, coef)
114 class(ramp_mapping_t), intent(inout) :: this
115 type(json_file), intent(inout) :: json
116 type(coef_t), intent(inout) :: coef
117 real(kind=rp) :: f_min, f_max, q
118 logical :: convex_up
119
120 call json_get_or_default(json, 'f_min', f_min, 0.0_rp)
121 call nekotop_continuation%json_get_or_register(json, 'f_max', this%f_max, &
122 f_max)
123 call nekotop_continuation%json_get_or_register(json, 'q', this%q, q, 1.0_rp)
124 call json_get_or_default(json, 'convex_up', convex_up, .false.)
125
126 call this%init_base(json, coef, "RAMP_mapping")
127 call this%init_from_attributes(coef, f_min, f_max, q, &
128 convex_up)
129
130 end subroutine ramp_mapping_init_from_json
131
133 subroutine ramp_mapping_init_from_attributes(this, coef, f_min, f_max, q, &
134 convex_up)
135 class(ramp_mapping_t), intent(inout) :: this
136 type(coef_t), intent(inout) :: coef
137 real(kind=rp), intent(in) :: f_min, f_max, q
138 logical, intent(in) :: convex_up
139 character(len=256) :: msg
140
141 this%f_min = f_min
142 this%f_max = f_max
143 this%q = q
144 this%convex_up = convex_up
145
146 call neko_log%section('RAMP Mapping')
147 write(msg, '(A,F8.4)') ' f_min: ', this%f_min
148 call neko_log%message(msg)
149 write(msg, '(A,F8.4)') ' f_max: ', this%f_max
150 call neko_log%message(msg)
151 write(msg, '(A,F8.4)') ' q: ', this%q
152 call neko_log%message(msg)
153 if (this%convex_up .eqv. .true.) then
154 call neko_log%message(' convexity: up (Borrvall & Peterson)')
155 else
156 call neko_log%message(' convexity: down (standard RAMP)')
157 end if
158 call neko_log%end_section()
159
160 end subroutine ramp_mapping_init_from_attributes
161
163 subroutine ramp_mapping_free(this)
164 class(ramp_mapping_t), intent(inout) :: this
165
166 call this%free_base()
167
168 end subroutine ramp_mapping_free
169
174 subroutine ramp_forward_mapping(this, X_out, X_in)
175 class(ramp_mapping_t), intent(inout) :: this
176 type(field_t), intent(in) :: X_in
177 type(field_t), intent(inout) :: X_out
178
179 if (this%convex_up .eqv. .true.) then
180 call convex_up_ramp_mapping_apply(this%f_min, this%f_max, &
181 this%q, x_out, x_in)
182 else
183 call convex_down_ramp_mapping_apply(this%f_min, this%f_max, &
184 this%q, x_out, x_in)
185 end if
186
187 end subroutine ramp_forward_mapping
188
189
195 subroutine ramp_backward_mapping(this, sens_out, sens_in, X_in)
196 class(ramp_mapping_t), intent(inout) :: this
197 type(field_t), intent(in) :: X_in
198 type(field_t), intent(in) :: sens_in
199 type(field_t), intent(inout) :: sens_out
200
201 if (this%convex_up .eqv. .true.) then
202 call convex_up_ramp_mapping_apply_backward(this%f_min, this%f_max, &
203 this%q, sens_out, sens_in, x_in)
204 else
205 call convex_down_ramp_mapping_apply_backward(this%f_min, this%f_max, &
206 this%q, sens_out, sens_in, x_in)
207 end if
208
209 end subroutine ramp_backward_mapping
210
217 subroutine convex_down_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
218 real(kind=rp), intent(in) :: q, f_min, f_max
219 type(field_t), intent(in) :: x_in
220 type(field_t), intent(inout) :: X_out
221 integer :: n
222
223 ! x_out = f_min + (f_max - f_min) * x_in / (1 + q * (1 - x_in) )
224
225 n = x_in%dof%size()
226 if (neko_bcknd_device .eq. 1) then
227 call device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
228 x_out%x_d, x_in%x_d, n)
229 else
230 call convex_down_ramp_mapping_apply_cpu(f_min, f_max, q, &
231 x_out%x, x_in%x, n)
232 end if
233
234 end subroutine convex_down_ramp_mapping_apply
235
236
244 subroutine convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
245 sens_out, sens_in, X_in)
246 real(kind=rp), intent(in) :: f_min, f_max, q
247 type(field_t), intent(in) :: x_in
248 type(field_t), intent(in) :: sens_in
249 type(field_t), intent(inout) :: sens_out
250 integer :: n
251
252 ! df/dx_in = df/dx_out * dx_out/dx_in
253
254 ! dx_out/dx_in = (f_min - f_max) * (q + 1) / (1 - q*(x - 1))**2
255
256 n = x_in%dof%size()
257
258 if (neko_bcknd_device .eq. 1) then
259 call device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
260 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
261 else
262 call convex_down_ramp_mapping_apply_backward_cpu(f_min, f_max, q, &
263 sens_out%x, sens_in%x, x_in%x, n)
264 end if
265
266 end subroutine convex_down_ramp_mapping_apply_backward
267
274 subroutine convex_up_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
275 real(kind=rp), intent(in) :: f_min, f_max, q
276 type(field_t), intent(in) :: x_in
277 type(field_t), intent(inout) :: X_out
278 integer :: n
279
280 ! x_out = f_min + (f_max - f_min) * x_in * (q + 1) / (x_in + q)
281
282 n = x_in%dof%size()
283
284 if (neko_bcknd_device .eq. 1) then
285 call device_convex_up_ramp_mapping_apply(f_min, f_max, q, &
286 x_out%x_d, x_in%x_d, n)
287 else
288 call convex_up_ramp_mapping_apply_cpu(f_min, f_max, q, &
289 x_out%x, x_in%x, n)
290 end if
291
292
293 end subroutine convex_up_ramp_mapping_apply
294
295
303 subroutine convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
304 sens_out, sens_in, X_in)
305 real(kind=rp), intent(in) :: f_min, f_max, q
306 type(field_t), intent(in) :: x_in
307 type(field_t), intent(in) :: sens_in
308 type(field_t), intent(inout) :: sens_out
309 integer :: n
310
311 ! df/dx_in = df/dx_out * dx_out/dx_in
312
313 ! dx_out/dx_in = (f_min - f_max) * (q + 1) * q / (q + x)**2
314
315 n = x_in%dof%size()
316
317 if (neko_bcknd_device .eq. 1) then
318 call device_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
319 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
320 else
321 call convex_up_ramp_mapping_apply_backward_cpu(f_min, f_max, q, &
322 sens_out%x, sens_in%x, x_in%x, n)
323 end if
324
325 end subroutine convex_up_ramp_mapping_apply_backward
326end module ramp_mapping
Continuation scheduler for the optimization loop.
Mappings to be applied to a scalar field.
Definition mapping.f90:36
CPU backend for RAMP mapping operations.
subroutine, public convex_down_ramp_mapping_apply_backward_cpu(f_min, f_max, q, sens_out, sens_in, x_in, n)
Apply convex-down RAMP chain rule on CPU.
subroutine, public convex_up_ramp_mapping_apply_backward_cpu(f_min, f_max, q, sens_out, sens_in, x_in, n)
Apply convex-up RAMP chain rule on CPU.
subroutine, public convex_up_ramp_mapping_apply_cpu(f_min, f_max, q, x_out, x_in, n)
Apply convex-up RAMP forward mapping on CPU.
subroutine, public convex_down_ramp_mapping_apply_cpu(f_min, f_max, q, x_out, x_in, n)
Apply convex-down RAMP forward mapping on CPU.
A RAMP mapping of coefficients.
subroutine ramp_mapping_init_from_json(this, json, coef)
Constructor from json.
Base abstract class for mapping.
Definition mapping.f90:46
A RAMP mapping of coefficients This is the standard RAMP described in https://doi....