37 use neko_config,
only: neko_bcknd_device
38 use num_types,
only: rp
41 use field,
only: field_t
42 use field_list,
only: field_list_t
43 use json_utils,
only: json_get, json_extract_item, json_get_or_default
44 use json_module,
only: json_file
45 use coefs,
only: coef_t
46 use user_intf,
only: user_t
47 use field_math,
only: field_rzero, field_copy
49 use device_math,
only: device_col2
50 use scratch_registry,
only: neko_scratch_registry
51 use utils,
only: neko_warning
52 use vector,
only:vector_t
54 use gather_scatter,
only : gs_op_add
70 type(coef_t),
pointer :: coef
76 procedure, pass(this) :: free => mapping_handler_free
78 generic :: apply_forward => mapping_handler_apply_forward_field, &
79 mapping_handler_apply_forward_vector
80 procedure, pass(this) :: mapping_handler_apply_forward_field
81 procedure, pass(this) :: mapping_handler_apply_forward_vector
84 generic :: apply_backward => mapping_handler_apply_backward_field, &
85 mapping_handler_apply_backward_vector
86 procedure, pass(this) :: mapping_handler_apply_backward_field
87 procedure, pass(this) :: mapping_handler_apply_backward_vector
89 generic :: add => add_mapping, add_json_mappings
91 procedure, pass(this) :: add_mapping => &
92 mapping_handler_add_mapping
94 procedure, pass(this) :: add_json_mappings => &
95 mapping_handler_add_json_mappings
97 procedure, pass(this) :: make_cts => mapping_handler_make_cts
105 type(coef_t),
target,
intent(in) :: coef
115 subroutine mapping_handler_free(this)
119 if (
allocated(this%mapping_cascade))
then
120 do i = 1,
size(this%mapping_cascade)
121 call this%mapping_cascade(i)%free()
123 deallocate(this%mapping_cascade)
126 end subroutine mapping_handler_free
132 subroutine mapping_handler_apply_forward_field(this, X_out, X_in)
134 type(field_t),
intent(in) :: X_in
135 type(field_t),
intent(inout) :: X_out
137 type(field_t),
pointer :: tmp_fld_in, tmp_fld_out
138 integer :: temp_indices(2)
140 call neko_scratch_registry%request_field(tmp_fld_in, temp_indices(1), &
142 call neko_scratch_registry%request_field(tmp_fld_out, temp_indices(2), &
147 call field_copy(tmp_fld_out, x_in)
150 call this%make_cts(tmp_fld_out)
153 if (
allocated(this%mapping_cascade))
then
154 do i = 1,
size(this%mapping_cascade)
156 call field_copy(tmp_fld_in, tmp_fld_out)
158 call this%mapping_cascade(i)%mapping%apply_forward(tmp_fld_out, &
166 call field_copy(x_out, tmp_fld_out)
169 call neko_scratch_registry%relinquish_field(temp_indices)
171 end subroutine mapping_handler_apply_forward_field
177 subroutine mapping_handler_apply_forward_vector(this, X_out, X_in)
179 type(vector_t),
intent(in) :: X_in
180 type(vector_t),
intent(inout) :: X_out
181 type(field_t),
pointer :: tmp_fld_in, tmp_fld_out
182 integer :: temp_indices(2)
184 call neko_scratch_registry%request_field(tmp_fld_in, temp_indices(1), &
186 call neko_scratch_registry%request_field(tmp_fld_out, temp_indices(2), &
190 call mapping_handler_apply_forward_field(this, tmp_fld_out, tmp_fld_in)
194 call neko_scratch_registry%relinquish_field(temp_indices)
196 end subroutine mapping_handler_apply_forward_vector
204 subroutine mapping_handler_apply_backward_field(this, sens_out, sens_in)
206 type(field_t),
intent(inout) :: sens_out
207 type(field_t),
intent(in) :: sens_in
209 type(field_t),
pointer :: tmp_fld_in, tmp_fld_out
210 integer :: temp_indices(2)
212 call neko_scratch_registry%request_field(tmp_fld_in, temp_indices(1), &
214 call neko_scratch_registry%request_field(tmp_fld_out, temp_indices(2), &
219 call field_copy(tmp_fld_out, sens_in)
222 call this%make_cts(tmp_fld_out)
225 if (
allocated(this%mapping_cascade))
then
226 do i =
size(this%mapping_cascade), 1, -1
228 call field_copy(tmp_fld_in, tmp_fld_out)
233 call this%mapping_cascade(i)%mapping%apply_backward(tmp_fld_out, &
241 if (neko_bcknd_device .eq. 1)
then
242 call device_col2(tmp_fld_out%x_d, this%coef%B_d, tmp_fld_out%size())
244 call col2(tmp_fld_out%x, this%coef%B, tmp_fld_out%size())
248 call field_copy(sens_out, tmp_fld_out)
251 call neko_scratch_registry%relinquish_field(temp_indices)
254 end subroutine mapping_handler_apply_backward_field
262 subroutine mapping_handler_apply_backward_vector(this, X_out, X_in)
264 type(vector_t),
intent(in) :: X_in
265 type(vector_t),
intent(inout) :: X_out
266 type(field_t),
pointer :: tmp_fld_in, tmp_fld_out
267 integer :: temp_indices(2)
269 call neko_scratch_registry%request_field(tmp_fld_in, temp_indices(1), &
271 call neko_scratch_registry%request_field(tmp_fld_out, temp_indices(2), &
275 call mapping_handler_apply_backward_field(this, tmp_fld_out, tmp_fld_in)
279 call neko_scratch_registry%relinquish_field(temp_indices)
281 end subroutine mapping_handler_apply_backward_vector
284 subroutine mapping_handler_add_json_mappings(this, json, name)
286 type(json_file),
intent(inout) :: json
287 character(len=*),
intent(in) :: name
292 type(json_file) :: mapping_subdict
293 integer :: n_mappings, i, i0
295 if (json%valid_path(name))
then
297 call json%info(name, n_children = n_mappings)
299 if (
allocated(this%mapping_cascade))
then
300 i0 =
size(this%mapping_cascade)
301 call move_alloc(this%mapping_cascade, temp)
302 allocate(this%mapping_cascade(i0 + n_mappings))
303 if (
allocated(temp))
then
305 call move_alloc(temp(i)%mapping, &
306 this%mapping_cascade(i)%mapping)
311 allocate(this%mapping_cascade(n_mappings))
316 call json_extract_item(json, name, i, mapping_subdict)
318 mapping_subdict, this%coef)
322 call neko_warning(
"No mappings selected")
325 end subroutine mapping_handler_add_json_mappings
330 subroutine mapping_handler_add_mapping(this, mapping)
335 integer :: n_mappings, i
337 if (
allocated(this%mapping_cascade))
then
338 n_mappings =
size(this%mapping_cascade)
343 call move_alloc(this%mapping_cascade, temp)
344 allocate(this%mapping_cascade(n_mappings + 1))
346 if (
allocated(temp))
then
348 call move_alloc(temp(i)%mapping, this%mapping_cascade(i)%mapping)
352 this%mapping_cascade(n_mappings + 1)%mapping =
mapping
354 end subroutine mapping_handler_add_mapping
360 subroutine mapping_handler_make_cts(this, fld)
362 type(field_t),
intent(inout) :: fld
364 call this%coef%gs_h%op(fld, gs_op_add)
365 if (neko_bcknd_device .eq. 1)
then
366 call device_col2(fld%x_d, this%coef%mult_d, fld%size())
368 call col2(fld%x, this%coef%mult, fld%size())
371 end subroutine mapping_handler_make_cts
mapping factory. Both constructs and initializes the object.
Implements the mapping_handler_t type.
subroutine mapping_handler_init_base(this, coef)
Constructor.
Mappings to be applied to a scalar field.
Contains extensions to the neko library required to run the topology optimization code.
subroutine, public field_to_vector(vector, field)
Field to vector.
subroutine, public vector_to_field(field, vector)
Vector to field.
Base abstract class for mapping.
A helper type that is needed to have an array of polymorphic objects.
Abstract class for handling mapping_cascade.