Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
Borrvall_Petersson_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_borrvall_petersson_mapping, only: &
44 device_borrvall_petersson_mapping_apply, &
45 device_borrvall_petersson_mapping_apply_backward
49 use json_utils, only: json_get, json_get_or_default
50 use logger, only: neko_log
51 use continuation_scheduler, only: nekotop_continuation
52 implicit none
53 private
54
80
81 type, public, extends(mapping_t) :: borrvall_petersson_mapping_t
83 real(kind=rp) :: f_min
85 real(kind=rp) :: f_max
87 real(kind=rp) :: q
88
89 contains
91 procedure, pass(this) :: init => borrvall_petersson_mapping_init_from_json
93 procedure, pass(this) :: init_from_attributes => &
94 borrvall_petersson_mapping_init_from_attributes
96 procedure, pass(this) :: free => borrvall_petersson_mapping_free
98 procedure, pass(this) :: forward_mapping => &
99 borrvall_petersson_forward_mapping
101 procedure, pass(this) :: backward_mapping => &
102 borrvall_petersson_backward_mapping
104
105contains
106
108 subroutine borrvall_petersson_mapping_init_from_json(this, json, coef)
109 class(borrvall_petersson_mapping_t), intent(inout) :: this
110 type(json_file), intent(inout) :: json
111 type(coef_t), intent(inout) :: coef
112 real(kind=rp) :: f_min, f_max, q
113
114 call json_get_or_default(json, 'f_min', f_min, 0.0_rp)
115 call nekotop_continuation%json_get_or_register(json, 'f_max', this%f_max, &
116 f_max)
117 call nekotop_continuation%json_get_or_register(json, 'q', this%q, q, 1.0_rp)
118
119 call this%init_base(json, coef, "Borrvall_Petersson_mapping")
120 call this%init_from_attributes(coef, f_min, f_max, q)
121
123
125 subroutine borrvall_petersson_mapping_init_from_attributes(this, coef, &
126 f_min, f_max, q)
127 class(borrvall_petersson_mapping_t), intent(inout) :: this
128 type(coef_t), intent(inout) :: coef
129 real(kind=rp), intent(in) :: f_min, f_max, q
130 character(len=256) :: msg
131
132 this%f_min = f_min
133 this%f_max = f_max
134 this%q = q
135
136 call neko_log%section('Borrvall & Petersson Mapping')
137 write(msg, '(A,F8.4)') ' f_min: ', this%f_min
138 call neko_log%message(msg)
139 write(msg, '(A,F8.4)') ' f_max: ', this%f_max
140 call neko_log%message(msg)
141 write(msg, '(A,F8.4)') ' q: ', this%q
142 call neko_log%message(msg)
143 call neko_log%end_section()
144
145 end subroutine borrvall_petersson_mapping_init_from_attributes
146
148 subroutine borrvall_petersson_mapping_free(this)
149 class(borrvall_petersson_mapping_t), intent(inout) :: this
150
151 call this%free_base()
152
153 end subroutine borrvall_petersson_mapping_free
154
159 subroutine borrvall_petersson_forward_mapping(this, X_out, X_in)
160 class(borrvall_petersson_mapping_t), intent(inout) :: this
161 type(field_t), intent(in) :: X_in
162 type(field_t), intent(inout) :: X_out
163 integer :: n
164
165 ! The moved (unmodified) kernel computes
166 ! arg1 + (arg2 - arg1) * S(x)
167 ! with S(x) = x (q+1) / (x+q). Passing f_max as arg1 and f_min as arg2
168 ! (i.e. SWAPPED with respect to the historic RAMP call) yields the correct
169 ! Borrvall & Petersson assembly
170 ! f(x) = f_max + (f_min - f_max) * S(x).
171 n = x_in%dof%size()
172 if (neko_bcknd_device .eq. 1) then
173 call device_borrvall_petersson_mapping_apply(this%f_max, this%f_min, &
174 this%q, x_out%x_d, x_in%x_d, n)
175 else
176 call borrvall_petersson_mapping_apply_cpu(this%f_max, this%f_min, &
177 this%q, x_out%x, x_in%x, n)
178 end if
179
180 end subroutine borrvall_petersson_forward_mapping
181
182
188 subroutine borrvall_petersson_backward_mapping(this, sens_out, sens_in, X_in)
189 class(borrvall_petersson_mapping_t), intent(inout) :: this
190 type(field_t), intent(in) :: X_in
191 type(field_t), intent(in) :: sens_in
192 type(field_t), intent(inout) :: sens_out
193 integer :: n
194
195 ! Same SWAP of f_min/f_max as the forward mapping. The moved kernel gives
196 ! dx_out/dx_in = (arg2 - arg1) * (q+1) * q / (x+q)**2
197 ! which with arg1 = f_max, arg2 = f_min becomes
198 ! f'(x) = q (q+1) (f_min - f_max) / (x+q)**2.
199 n = x_in%dof%size()
200 if (neko_bcknd_device .eq. 1) then
201 call device_borrvall_petersson_mapping_apply_backward(this%f_max, &
202 this%f_min, this%q, sens_out%x_d, sens_in%x_d, x_in%x_d, n)
203 else
205 this%f_min, this%q, sens_out%x, sens_in%x, x_in%x, n)
206 end if
207
208 end subroutine borrvall_petersson_backward_mapping
209
CPU backend for Borrvall & Petersson mapping operations.
subroutine, public borrvall_petersson_mapping_apply_backward_cpu(f_min, f_max, q, sens_out, sens_in, x_in, n)
Apply Borrvall & Petersson chain rule on CPU.
subroutine, public borrvall_petersson_mapping_apply_cpu(f_min, f_max, q, x_out, x_in, n)
Apply Borrvall & Petersson forward mapping on CPU.
A Borrvall & Petersson mapping of coefficients.
subroutine borrvall_petersson_mapping_init_from_json(this, json, coef)
Constructor from json.
Continuation scheduler for the optimization loop.
Mappings to be applied to a scalar field.
Definition mapping.f90:36
A Borrvall & Petersson mapping of coefficients This is the material interpolation described by Borrva...
Base abstract class for mapping.
Definition mapping.f90:47