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
47 use json_utils, only: json_get, json_get_or_default
48 use logger, only: neko_log
49 use utils, only: neko_error
50 use continuation_scheduler, only: nekotop_continuation
51 implicit none
52 private
53
72
73 type, public, extends(mapping_t) :: ramp_mapping_t
75 real(kind=rp) :: f_min
77 real(kind=rp) :: f_max
79 real(kind=rp) :: q
80
81 contains
83 procedure, pass(this) :: init => ramp_mapping_init_from_json
85 procedure, pass(this) :: init_from_attributes => &
86 ramp_mapping_init_from_attributes
88 procedure, pass(this) :: free => ramp_mapping_free
90 procedure, pass(this) :: forward_mapping => ramp_forward_mapping
92 procedure, pass(this) :: backward_mapping => ramp_backward_mapping
93 end type ramp_mapping_t
94
95contains
96
98 subroutine ramp_mapping_init_from_json(this, json, coef)
99 class(ramp_mapping_t), intent(inout) :: this
100 type(json_file), intent(inout) :: json
101 type(coef_t), intent(inout) :: coef
102 real(kind=rp) :: f_min, f_max, q
103
104 ! The 'convex_up' option has been removed. Fail loud rather than silently
105 ! reinterpreting old case files.
106 if (json%valid_path('convex_up')) then
107 call neko_error("RAMP mapping's 'convex_up' option has been " // &
108 "removed -- plain RAMP is now always the down/increasing form " // &
109 "(x=0:fluid, x=1:solid). For the x=0:solid/x=1:fluid form, " // &
110 "use type 'Borrvall_Petersson' instead.")
111 end if
112
113 call json_get_or_default(json, 'f_min', f_min, 0.0_rp)
114 call nekotop_continuation%json_get_or_register(json, 'f_max', this%f_max, &
115 f_max)
116 call nekotop_continuation%json_get_or_register(json, 'q', this%q, q, 1.0_rp)
117
118 call this%init_base(json, coef, "RAMP_mapping")
119 call this%init_from_attributes(coef, f_min, f_max, q)
120
121 end subroutine ramp_mapping_init_from_json
122
124 subroutine ramp_mapping_init_from_attributes(this, coef, f_min, f_max, q)
125 class(ramp_mapping_t), intent(inout) :: this
126 type(coef_t), intent(inout) :: coef
127 real(kind=rp), intent(in) :: f_min, f_max, q
128 character(len=256) :: msg
129
130 this%f_min = f_min
131 this%f_max = f_max
132 this%q = q
133
134 call neko_log%section('RAMP Mapping')
135 write(msg, '(A,F8.4)') ' f_min: ', this%f_min
136 call neko_log%message(msg)
137 write(msg, '(A,F8.4)') ' f_max: ', this%f_max
138 call neko_log%message(msg)
139 write(msg, '(A,F8.4)') ' q: ', this%q
140 call neko_log%message(msg)
141 call neko_log%end_section()
142
143 end subroutine ramp_mapping_init_from_attributes
144
146 subroutine ramp_mapping_free(this)
147 class(ramp_mapping_t), intent(inout) :: this
148
149 call this%free_base()
150
151 end subroutine ramp_mapping_free
152
157 subroutine ramp_forward_mapping(this, X_out, X_in)
158 class(ramp_mapping_t), intent(inout) :: this
159 type(field_t), intent(in) :: X_in
160 type(field_t), intent(inout) :: X_out
161
162 call convex_down_ramp_mapping_apply(this%f_min, this%f_max, &
163 this%q, x_out, x_in)
164
165 end subroutine ramp_forward_mapping
166
167
173 subroutine ramp_backward_mapping(this, sens_out, sens_in, X_in)
174 class(ramp_mapping_t), intent(inout) :: this
175 type(field_t), intent(in) :: X_in
176 type(field_t), intent(in) :: sens_in
177 type(field_t), intent(inout) :: sens_out
178
179 call convex_down_ramp_mapping_apply_backward(this%f_min, this%f_max, &
180 this%q, sens_out, sens_in, x_in)
181
182 end subroutine ramp_backward_mapping
183
190 subroutine convex_down_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
191 real(kind=rp), intent(in) :: q, f_min, f_max
192 type(field_t), intent(in) :: x_in
193 type(field_t), intent(inout) :: X_out
194 integer :: n
195
196 ! x_out = f_min + (f_max - f_min) * x_in / (1 + q * (1 - x_in) )
197
198 n = x_in%dof%size()
199 if (neko_bcknd_device .eq. 1) then
200 call device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
201 x_out%x_d, x_in%x_d, n)
202 else
203 call convex_down_ramp_mapping_apply_cpu(f_min, f_max, q, &
204 x_out%x, x_in%x, n)
205 end if
206
207 end subroutine convex_down_ramp_mapping_apply
208
209
217 subroutine convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
218 sens_out, sens_in, X_in)
219 real(kind=rp), intent(in) :: f_min, f_max, q
220 type(field_t), intent(in) :: x_in
221 type(field_t), intent(in) :: sens_in
222 type(field_t), intent(inout) :: sens_out
223 integer :: n
224
225 ! df/dx_in = df/dx_out * dx_out/dx_in
226
227 ! dx_out/dx_in = (f_max - f_min) * (q + 1) / (1 - q*(x - 1))**2
228
229 n = x_in%dof%size()
230
231 if (neko_bcknd_device .eq. 1) then
232 call device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
233 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
234 else
235 call convex_down_ramp_mapping_apply_backward_cpu(f_min, f_max, q, &
236 sens_out%x, sens_in%x, x_in%x, n)
237 end if
238
239 end subroutine convex_down_ramp_mapping_apply_backward
240
241end 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_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:47
A RAMP mapping of coefficients This is the standard RAMP described in https://doi....