37 use num_types,
only: rp
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
47 use json_utils,
only: json_get, json_get_or_default
81 real(kind=rp) :: f_min
83 real(kind=rp) :: f_max
94 procedure, pass(this) :: init_from_attributes => &
95 ramp_mapping_init_from_attributes
97 procedure, pass(this) :: free => ramp_mapping_free
99 procedure, pass(this) :: forward_mapping => ramp_forward_mapping
101 procedure, pass(this) :: backward_mapping => ramp_backward_mapping
109 type(json_file),
intent(inout) :: json
110 type(coef_t),
intent(inout) :: coef
111 real(kind=rp) :: f_min, f_max, q
114 call json_get_or_default(json,
'f_min', f_min, 0.0_rp)
115 call json_get(json,
'f_max', f_max)
116 call json_get_or_default(json,
'q', q, 1.0_rp)
117 call json_get_or_default(json,
'convex_up', convex_up, .false.)
119 call this%init_base(json, coef)
120 call this%init_from_attributes(coef, f_min, f_max, q, &
126 subroutine ramp_mapping_init_from_attributes(this, coef, f_min, f_max, q, &
129 type(coef_t),
intent(inout) :: coef
130 real(kind=rp),
intent(in) :: f_min, f_max, q
131 logical,
intent(in) :: convex_up
136 this%convex_up = convex_up
138 end subroutine ramp_mapping_init_from_attributes
141 subroutine ramp_mapping_free(this)
144 call this%free_base()
146 end subroutine ramp_mapping_free
152 subroutine ramp_forward_mapping(this, X_out, X_in)
154 type(field_t),
intent(in) :: X_in
155 type(field_t),
intent(inout) :: X_out
157 if (this%convex_up .eqv. .true.)
then
158 call convex_up_ramp_mapping_apply(this%f_min, this%f_max, &
161 call convex_down_ramp_mapping_apply(this%f_min, this%f_max, &
165 end subroutine ramp_forward_mapping
173 subroutine ramp_backward_mapping(this, sens_out, sens_in, X_in)
175 type(field_t),
intent(in) :: X_in
176 type(field_t),
intent(in) :: sens_in
177 type(field_t),
intent(inout) :: sens_out
179 if (this%convex_up .eqv. .true.)
then
180 call convex_up_ramp_mapping_apply_backward(this%f_min, this%f_max, &
181 this%q, sens_out, sens_in, x_in)
183 call convex_down_ramp_mapping_apply_backward(this%f_min, this%f_max, &
184 this%q, sens_out, sens_in, x_in)
187 end subroutine ramp_backward_mapping
195 subroutine convex_down_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
196 real(kind=rp),
intent(in) :: q, f_min, f_max
197 type(field_t),
intent(in) :: x_in
198 type(field_t),
intent(inout) :: X_out
204 if (neko_bcknd_device .eq. 1)
then
205 call device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
206 x_out%x_d, x_in%x_d, n)
209 x_out%x(i,1,1,1) = f_min + (f_max - f_min) * &
210 x_in%x(i,1,1,1) / (1.0_rp + q * (1.0_rp - x_in%x(i,1,1,1) ) )
214 end subroutine convex_down_ramp_mapping_apply
224 subroutine convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
225 sens_out, sens_in, X_in)
226 real(kind=rp),
intent(in) :: f_min, f_max, q
227 type(field_t),
intent(in) :: x_in
228 type(field_t),
intent(in) :: sens_in
229 type(field_t),
intent(inout) :: sens_out
238 if (neko_bcknd_device .eq. 1)
then
239 call device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
240 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
243 sens_out%x(i,1,1,1) = (f_max - f_min) * (q + 1.0_rp) / &
244 ((1.0_rp - q * (x_in%x(i,1,1,1) - 1.0_rp))**2) * &
249 end subroutine convex_down_ramp_mapping_apply_backward
257 subroutine convex_up_ramp_mapping_apply(f_min, f_max, q, X_out, X_in)
258 real(kind=rp),
intent(in) :: f_min, f_max, q
259 type(field_t),
intent(in) :: x_in
260 type(field_t),
intent(inout) :: X_out
267 if (neko_bcknd_device .eq. 1)
then
268 call device_convex_up_ramp_mapping_apply(f_min, f_max, q, &
269 x_out%x_d, x_in%x_d, n)
272 x_out%x(i,1,1,1) = f_min + (f_max - f_min) * &
273 x_in%x(i,1,1,1) * (1.0_rp + q ) / (x_in%x(i,1,1,1) + q)
278 end subroutine convex_up_ramp_mapping_apply
288 subroutine convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
289 sens_out, sens_in, X_in)
290 real(kind=rp),
intent(in) :: f_min, f_max, q
291 type(field_t),
intent(in) :: x_in
292 type(field_t),
intent(in) :: sens_in
293 type(field_t),
intent(inout) :: sens_out
302 if (neko_bcknd_device .eq. 1)
then
303 call device_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
304 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
307 sens_out%x(i,1,1,1) = (f_max - f_min) * (q + 1.0_rp) * q / &
308 ( (x_in%x(i,1,1,1) + q)**2) * &
313 end subroutine convex_up_ramp_mapping_apply_backward
Mappings to be applied to a scalar field.
A RAMP mapping of coefficients.
subroutine ramp_mapping_init_from_json(this, json, coef)
Constructor from json.
Base abstract class for mapping.
A RAMP mapping of coefficients This is the standard RAMP described in https://doi....