36 use num_types,
only: rp
38 use json_module,
only: json_file
39 use field,
only: field_t
40 use coefs,
only: coef_t
41 use neko_config,
only: neko_bcknd_device
42 use device_ramp_mapping,
only: device_convex_down_ramp_mapping_apply, &
43 device_convex_down_ramp_mapping_apply_backward, &
44 device_convex_up_ramp_mapping_apply, &
45 device_convex_up_ramp_mapping_apply_backward
46 use json_utils,
only: json_get, json_get_or_default
80 real(kind=rp) :: f_min
82 real(kind=rp) :: f_max
91 procedure, pass(this) :: init => ramp_mapping_init_from_json
93 procedure, pass(this) :: init_from_attributes => &
94 ramp_mapping_init_from_attributes
96 procedure, pass(this) :: free => ramp_mapping_free
98 procedure, pass(this) :: forward_mapping => ramp_forward_mapping
100 procedure, pass(this) :: backward_mapping => ramp_backward_mapping
106 subroutine ramp_mapping_init_from_json(this, json, coef)
108 type(json_file),
intent(inout) :: json
109 type(coef_t),
intent(inout) :: coef
110 real(kind=rp) :: f_min, f_max, q
113 call json_get_or_default(json,
'f_min', f_min, 0.0_rp)
114 call json_get(json,
'f_max', f_max)
115 call json_get_or_default(json,
'q', q, 1.0_rp)
116 call json_get_or_default(json,
'convex_up', convex_up, .false.)
118 call this%init_base(json, coef)
119 call this%init_from_attributes(coef, f_min, f_max, q, &
122 end subroutine ramp_mapping_init_from_json
125 subroutine ramp_mapping_init_from_attributes(this, coef, f_min, f_max, q, &
128 type(coef_t),
intent(inout) :: coef
129 real(kind=rp),
intent(in) :: f_min, f_max, q
130 logical,
intent(in) :: convex_up
135 this%convex_up = convex_up
137 end subroutine ramp_mapping_init_from_attributes
140 subroutine ramp_mapping_free(this)
143 call this%free_base()
145 end subroutine ramp_mapping_free
151 subroutine ramp_forward_mapping(this, X_out, X_in)
153 type(field_t),
intent(in) :: X_in
154 type(field_t),
intent(inout) :: X_out
156 if (this%convex_up .eqv. .true.)
then
157 call convex_up_ramp_mapping_apply(this%f_min, this%f_max, &
160 call convex_down_ramp_mapping_apply(this%f_min, this%f_max, &
164 end subroutine ramp_forward_mapping
172 subroutine ramp_backward_mapping(this, sens_out, sens_in, X_in)
174 type(field_t),
intent(in) :: X_in
175 type(field_t),
intent(in) :: sens_in
176 type(field_t),
intent(inout) :: sens_out
178 if (this%convex_up .eqv. .true.)
then
179 call convex_up_ramp_mapping_apply_backward(this%f_min, this%f_max, &
180 this%q, sens_out, sens_in, x_in)
182 call convex_down_ramp_mapping_apply_backward(this%f_min, this%f_max, &
183 this%q, sens_out, sens_in, x_in)
186 end subroutine ramp_backward_mapping
194 subroutine convex_down_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
195 real(kind=rp),
intent(in) :: q, f_min, f_max
196 type(field_t),
intent(in) :: x_in
197 type(field_t),
intent(inout) :: X_out
203 if (neko_bcknd_device .eq. 1)
then
204 call device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
205 x_out%x_d, x_in%x_d, n)
208 x_out%x(i,1,1,1) = f_min + (f_max - f_min) * &
209 x_in%x(i,1,1,1) / (1.0_rp + q * (1.0_rp - x_in%x(i,1,1,1) ) )
213 end subroutine convex_down_ramp_mapping_apply
223 subroutine convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
224 sens_out, sens_in, X_in)
225 real(kind=rp),
intent(in) :: f_min, f_max, q
226 type(field_t),
intent(in) :: x_in
227 type(field_t),
intent(in) :: sens_in
228 type(field_t),
intent(inout) :: sens_out
237 if (neko_bcknd_device .eq. 1)
then
238 call device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
239 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
242 sens_out%x(i,1,1,1) = (f_max - f_min) * (q + 1.0_rp) / &
243 ((1.0_rp - q * (x_in%x(i,1,1,1) - 1.0_rp))**2) * &
248 end subroutine convex_down_ramp_mapping_apply_backward
256 subroutine convex_up_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
257 real(kind=rp),
intent(in) :: f_min, f_max, q
258 type(field_t),
intent(in) :: x_in
259 type(field_t),
intent(inout) :: X_out
266 if (neko_bcknd_device .eq. 1)
then
267 call device_convex_up_ramp_mapping_apply(f_min, f_max, q, &
268 x_out%x_d, x_in%x_d, n)
271 x_out%x(i,1,1,1) = f_min + (f_max - f_min) * &
272 x_in%x(i,1,1,1) * (1.0_rp + q ) / (x_in%x(i,1,1,1) + q)
277 end subroutine convex_up_ramp_mapping_apply
287 subroutine convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
288 sens_out, sens_in, X_in)
289 real(kind=rp),
intent(in) :: f_min, f_max, q
290 type(field_t),
intent(in) :: x_in
291 type(field_t),
intent(in) :: sens_in
292 type(field_t),
intent(inout) :: sens_out
301 if (neko_bcknd_device .eq. 1)
then
302 call device_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
303 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
306 sens_out%x(i,1,1,1) = (f_max - f_min) * (q + 1.0_rp) / &
307 ( (x_in%x(i,1,1,1) + q)**2) * &
312 end subroutine convex_up_ramp_mapping_apply_backward
Mappings to be applied to a scalar field.
A RAMP mapping of coefficients.
Base abstract class for mapping.
A RAMP mapping of coefficients This is the standard RAMP described in https://doi....