Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
SIMP_mapping.f90
1! Copyright (c) 2023, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33!
36 use num_types, only: rp
37 use mapping, only: mapping_t
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
47 use continuation_scheduler, only: nekotop_continuation
48 implicit none
49 private
50
54
55 type, public, extends(mapping_t) :: simp_mapping_t
57 real(kind=rp) :: f_min
59 real(kind=rp) :: f_max
61 real(kind=rp) :: p
62
63 contains
65 procedure, pass(this) :: init => simp_mapping_init_from_json
67 procedure, pass(this) :: init_from_attributes => &
68 simp_mapping_init_from_attributes
70 procedure, pass(this) :: free => simp_mapping_free
72 procedure, pass(this) :: forward_mapping => simp_forward_mapping
74 procedure, pass(this) :: backward_mapping => simp_backward_mapping
75 end type simp_mapping_t
76
77contains
78
80 subroutine simp_mapping_init_from_json(this, json, coef)
81 class(simp_mapping_t), intent(inout) :: this
82 type(json_file), intent(inout) :: json
83 type(coef_t), intent(inout) :: coef
84 real(kind=rp) :: f_min, f_max, p
85
86 call json_get_or_default(json, 'f_min', f_min, 0.0_rp)
87 call nekotop_continuation%json_get_or_register(json, 'f_max', this%f_max, &
88 f_max)
89 call nekotop_continuation%json_get_or_register(json, 'p', this%p, p, 1.0_rp)
90
91 call this%init_base(json, coef, "SIMP_mapping")
92 call this%init_from_attributes(coef, f_min, f_max, p)
93
94 end subroutine simp_mapping_init_from_json
95
97 subroutine simp_mapping_init_from_attributes(this, coef, f_min, f_max, p)
98 class(simp_mapping_t), intent(inout) :: this
99 type(coef_t), intent(inout) :: coef
100 real(kind=rp), intent(in) :: f_min, f_max, p
101
102 this%f_min = f_min
103 this%f_max = f_max
104 this%p = p
105
106 end subroutine simp_mapping_init_from_attributes
107
109 subroutine simp_mapping_free(this)
110 class(simp_mapping_t), intent(inout) :: this
111
112 call this%free_base()
113
114 end subroutine simp_mapping_free
115
120 subroutine simp_forward_mapping(this, X_out, X_in)
121 class(simp_mapping_t), intent(inout) :: this
122 type(field_t), intent(in) :: X_in
123 type(field_t), intent(inout) :: X_out
124 integer :: n
125
126 n = x_in%dof%size()
127 if (neko_bcknd_device .eq. 1) then
128 call device_simp_mapping_apply(this%f_min, this%f_max, this%p, &
129 x_out%x_d, x_in%x_d, n)
130 else
131 call simp_mapping_apply_cpu(this%f_min, this%f_max, this%p, &
132 x_out%x, x_in%x, n)
133 end if
134
135 end subroutine simp_forward_mapping
136
137
143 subroutine simp_backward_mapping(this, sens_out, sens_in, X_in)
144 class(simp_mapping_t), intent(inout) :: this
145 type(field_t), intent(in) :: X_in
146 type(field_t), intent(in) :: sens_in
147 type(field_t), intent(inout) :: sens_out
148 integer :: n
149
150 n = x_in%dof%size()
151 if (neko_bcknd_device .eq. 1) then
152 call device_simp_mapping_apply_backward(this%f_min, this%f_max, this%p, &
153 sens_out%x_d, sens_in%x_d, x_in%x_d, n)
154 else
155 call simp_mapping_apply_backward_cpu(this%f_min, this%f_max, this%p, &
156 sens_out%x, sens_in%x, x_in%x, n)
157 end if
158
159 end subroutine simp_backward_mapping
160
161end module simp_mapping
Continuation scheduler for the optimization loop.
Mappings to be applied to a scalar field.
Definition mapping.f90:36
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.
Definition mapping.f90:46
A SIMP mapping of coefficients.