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_simp_mapping,
only: device_simp_mapping_apply, &
43 device_simp_mapping_apply_backward
46 use json_utils,
only: json_get, json_get_or_default
56 real(kind=rp) :: f_min
58 real(kind=rp) :: f_max
64 procedure, pass(this) :: init => simp_mapping_init_from_json
66 procedure, pass(this) :: init_from_attributes => &
67 simp_mapping_init_from_attributes
69 procedure, pass(this) :: free => simp_mapping_free
71 procedure, pass(this) :: forward_mapping => simp_forward_mapping
73 procedure, pass(this) :: backward_mapping => simp_backward_mapping
79 subroutine simp_mapping_init_from_json(this, json, coef)
81 type(json_file),
intent(inout) :: json
82 type(coef_t),
intent(inout) :: coef
83 real(kind=rp) :: f_min, f_max, p
85 call json_get_or_default(json,
'f_min', f_min, 0.0_rp)
86 call json_get(json,
'f_max', f_max)
87 call json_get_or_default(json,
'p', p, 1.0_rp)
89 call this%init_base(json, coef)
90 call this%init_from_attributes(coef, f_min, f_max, p)
92 end subroutine simp_mapping_init_from_json
95 subroutine simp_mapping_init_from_attributes(this, coef, f_min, f_max, p)
97 type(coef_t),
intent(inout) :: coef
98 real(kind=rp),
intent(in) :: f_min, f_max, p
104 end subroutine simp_mapping_init_from_attributes
107 subroutine simp_mapping_free(this)
110 call this%free_base()
112 end subroutine simp_mapping_free
118 subroutine simp_forward_mapping(this, X_out, X_in)
120 type(field_t),
intent(in) :: X_in
121 type(field_t),
intent(inout) :: X_out
125 if (neko_bcknd_device .eq. 1)
then
126 call device_simp_mapping_apply(this%f_min, this%f_max, this%p, &
127 x_out%x_d, x_in%x_d, n)
133 end subroutine simp_forward_mapping
141 subroutine simp_backward_mapping(this, sens_out, sens_in, X_in)
143 type(field_t),
intent(in) :: X_in
144 type(field_t),
intent(in) :: sens_in
145 type(field_t),
intent(inout) :: sens_out
149 if (neko_bcknd_device .eq. 1)
then
150 call device_simp_mapping_apply_backward(this%f_min, this%f_max, this%p, &
151 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
154 sens_out%x, sens_in%x, x_in%x, n)
157 end subroutine simp_backward_mapping
Mappings to be applied to a scalar field.
CPU backend for SIMP mapping operations.
subroutine, public simp_mapping_apply_backward_cpu(f_min, f_max, p, sens_out, sens_in, x_in, n)
Apply SIMP chain rule on CPU.
subroutine, public simp_mapping_apply_cpu(f_min, f_max, p, x_out, x_in, n)
Apply SIMP forward mapping on CPU.
A SIMP mapping of coefficients.
Base abstract class for mapping.
A SIMP mapping of coefficients.