37 use num_types,
only: rp
38 use field_math,
only: field_copy, field_cmult, field_cadd
40 use num_types,
only: rp
41 use json_module,
only: json_file
42 use field,
only: field_t
43 use coefs,
only: coef_t
44 use json_utils,
only: json_get, json_get_or_default
51 real(kind=rp) :: f_min
53 real(kind=rp) :: f_max
59 procedure, pass(this) :: init_from_attributes => &
60 linear_mapping_init_from_attributes
62 procedure, pass(this) :: free => linear_mapping_free
64 procedure, pass(this) :: forward_mapping => linear_forward_mapping
66 procedure, pass(this) :: backward_mapping => &
67 linear_backward_mapping
75 type(json_file),
intent(inout) :: json
76 type(coef_t),
intent(inout) :: coef
77 real(kind=rp) :: f_min, f_max
79 call json_get_or_default(json,
'f_min', f_min, 0.0_rp)
80 call json_get(json,
'f_max', f_max)
82 call this%init_base(json, coef)
83 call linear_mapping_init_from_attributes(this, coef, f_min, f_max)
88 subroutine linear_mapping_init_from_attributes(this, coef, f_min, f_max)
90 type(coef_t),
intent(inout) :: coef
91 real(kind=rp),
intent(in) :: f_min, f_max
96 end subroutine linear_mapping_init_from_attributes
99 subroutine linear_mapping_free(this)
102 call this%free_base()
104 end subroutine linear_mapping_free
110 subroutine linear_forward_mapping(this, X_out, X_in)
112 type(field_t),
intent(in) :: X_in
113 type(field_t),
intent(inout) :: X_out
116 call field_copy(x_out, x_in)
117 call field_cmult(x_out, this%f_max - this%f_min)
118 call field_cadd(x_out, this%f_min)
120 end subroutine linear_forward_mapping
128 subroutine linear_backward_mapping(this, sens_out, sens_in, X_in)
130 type(field_t),
intent(in) :: X_in
131 type(field_t),
intent(in) :: sens_in
132 type(field_t),
intent(inout) :: sens_out
138 call field_copy(sens_out, sens_in)
139 call field_cmult(sens_out, this%f_max - this%f_min)
141 end subroutine linear_backward_mapping
A linear mapping of coefficients.
subroutine linear_mapping_init_from_json(this, json, coef)
Constructor from json.
Mappings to be applied to a scalar field.
A linear mapping of coefficients $f(x) = f_{min} + (f_{max} - f_{min}) x$.
Base abstract class for mapping.