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 implicit none
54 private
55
83
84 type, public, extends(mapping_t) :: ramp_mapping_t
86 real(kind=rp) :: f_min
88 real(kind=rp) :: f_max
90 real(kind=rp) :: q
93 logical :: convex_up
94
95 contains
97 procedure, pass(this) :: init => ramp_mapping_init_from_json
99 procedure, pass(this) :: init_from_attributes => &
100 ramp_mapping_init_from_attributes
102 procedure, pass(this) :: free => ramp_mapping_free
104 procedure, pass(this) :: forward_mapping => ramp_forward_mapping
106 procedure, pass(this) :: backward_mapping => ramp_backward_mapping
107 end type ramp_mapping_t
108
109contains
110
112 subroutine ramp_mapping_init_from_json(this, json, coef)
113 class(ramp_mapping_t), intent(inout) :: this
114 type(json_file), intent(inout) :: json
115 type(coef_t), intent(inout) :: coef
116 real(kind=rp) :: f_min, f_max, q
117 logical :: convex_up
118
119 call json_get_or_default(json, 'f_min', f_min, 0.0_rp)
120 call json_get(json, 'f_max', f_max)
121 call json_get_or_default(json, 'q', q, 1.0_rp)
122 call json_get_or_default(json, 'convex_up', convex_up, .false.)
123
124 call this%init_base(json, coef)
125 call this%init_from_attributes(coef, f_min, f_max, q, &
126 convex_up)
127
128 end subroutine ramp_mapping_init_from_json
129
131 subroutine ramp_mapping_init_from_attributes(this, coef, f_min, f_max, q, &
132 convex_up)
133 class(ramp_mapping_t), intent(inout) :: this
134 type(coef_t), intent(inout) :: coef
135 real(kind=rp), intent(in) :: f_min, f_max, q
136 logical, intent(in) :: convex_up
137 character(len=256) :: msg
138
139 this%f_min = f_min
140 this%f_max = f_max
141 this%q = q
142 this%convex_up = convex_up
143
144 call neko_log%section('RAMP Mapping')
145 write(msg, '(A,F8.4)') ' f_min: ', this%f_min
146 call neko_log%message(msg)
147 write(msg, '(A,F8.4)') ' f_max: ', this%f_max
148 call neko_log%message(msg)
149 write(msg, '(A,F8.4)') ' q: ', this%q
150 call neko_log%message(msg)
151 if (this%convex_up .eqv. .true.) then
152 call neko_log%message(' convexity: up (Borrvall & Peterson)')
153 else
154 call neko_log%message(' convexity: down (standard RAMP)')
155 end if
156 call neko_log%end_section()
157
158 end subroutine ramp_mapping_init_from_attributes
159
161 subroutine ramp_mapping_free(this)
162 class(ramp_mapping_t), intent(inout) :: this
163
164 call this%free_base()
165
166 end subroutine ramp_mapping_free
167
172 subroutine ramp_forward_mapping(this, X_out, X_in)
173 class(ramp_mapping_t), intent(inout) :: this
174 type(field_t), intent(in) :: X_in
175 type(field_t), intent(inout) :: X_out
176
177 if (this%convex_up .eqv. .true.) then
178 call convex_up_ramp_mapping_apply(this%f_min, this%f_max, &
179 this%q, x_out, x_in)
180 else
181 call convex_down_ramp_mapping_apply(this%f_min, this%f_max, &
182 this%q, x_out, x_in)
183 end if
184
185 end subroutine ramp_forward_mapping
186
187
193 subroutine ramp_backward_mapping(this, sens_out, sens_in, X_in)
194 class(ramp_mapping_t), intent(inout) :: this
195 type(field_t), intent(in) :: X_in
196 type(field_t), intent(in) :: sens_in
197 type(field_t), intent(inout) :: sens_out
198
199 if (this%convex_up .eqv. .true.) then
200 call convex_up_ramp_mapping_apply_backward(this%f_min, this%f_max, &
201 this%q, sens_out, sens_in, x_in)
202 else
203 call convex_down_ramp_mapping_apply_backward(this%f_min, this%f_max, &
204 this%q, sens_out, sens_in, x_in)
205 end if
206
207 end subroutine ramp_backward_mapping
208
215 subroutine convex_down_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
216 real(kind=rp), intent(in) :: q, f_min, f_max
217 type(field_t), intent(in) :: x_in
218 type(field_t), intent(inout) :: X_out
219 integer :: n
220
221 ! x_out = f_min + (f_max - f_min) * x_in / (1 + q * (1 - x_in) )
222
223 n = x_in%dof%size()
224 if (neko_bcknd_device .eq. 1) then
225 call device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
226 x_out%x_d, x_in%x_d, n)
227 else
228 call convex_down_ramp_mapping_apply_cpu(f_min, f_max, q, &
229 x_out%x, x_in%x, n)
230 end if
231
232 end subroutine convex_down_ramp_mapping_apply
233
234
242 subroutine convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
243 sens_out, sens_in, X_in)
244 real(kind=rp), intent(in) :: f_min, f_max, q
245 type(field_t), intent(in) :: x_in
246 type(field_t), intent(in) :: sens_in
247 type(field_t), intent(inout) :: sens_out
248 integer :: n
249
250 ! df/dx_in = df/dx_out * dx_out/dx_in
251
252 ! dx_out/dx_in = (f_min - f_max) * (q + 1) / (1 - q*(x - 1))**2
253
254 n = x_in%dof%size()
255
256 if (neko_bcknd_device .eq. 1) then
257 call device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
258 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
259 else
260 call convex_down_ramp_mapping_apply_backward_cpu(f_min, f_max, q, &
261 sens_out%x, sens_in%x, x_in%x, n)
262 end if
263
264 end subroutine convex_down_ramp_mapping_apply_backward
265
272 subroutine convex_up_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
273 real(kind=rp), intent(in) :: f_min, f_max, q
274 type(field_t), intent(in) :: x_in
275 type(field_t), intent(inout) :: X_out
276 integer :: n
277
278 ! x_out = f_min + (f_max - f_min) * x_in * (q + 1) / (x_in + q)
279
280 n = x_in%dof%size()
281
282 if (neko_bcknd_device .eq. 1) then
283 call device_convex_up_ramp_mapping_apply(f_min, f_max, q, &
284 x_out%x_d, x_in%x_d, n)
285 else
286 call convex_up_ramp_mapping_apply_cpu(f_min, f_max, q, &
287 x_out%x, x_in%x, n)
288 end if
289
290
291 end subroutine convex_up_ramp_mapping_apply
292
293
301 subroutine convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
302 sens_out, sens_in, X_in)
303 real(kind=rp), intent(in) :: f_min, f_max, q
304 type(field_t), intent(in) :: x_in
305 type(field_t), intent(in) :: sens_in
306 type(field_t), intent(inout) :: sens_out
307 integer :: n
308
309 ! df/dx_in = df/dx_out * dx_out/dx_in
310
311 ! dx_out/dx_in = (f_min - f_max) * (q + 1) * q / (q + x)**2
312
313 n = x_in%dof%size()
314
315 if (neko_bcknd_device .eq. 1) then
316 call device_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
317 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
318 else
319 call convex_up_ramp_mapping_apply_backward_cpu(f_min, f_max, q, &
320 sens_out%x, sens_in%x, x_in%x, n)
321 end if
322
323 end subroutine convex_up_ramp_mapping_apply_backward
324end module ramp_mapping
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....