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 implicit none
48 private
49
53
54 type, public, extends(mapping_t) :: simp_mapping_t
56 real(kind=rp) :: f_min
58 real(kind=rp) :: f_max
60 real(kind=rp) :: p
61
62 contains
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
74 end type simp_mapping_t
75
76contains
77
79 subroutine simp_mapping_init_from_json(this, json, coef)
80 class(simp_mapping_t), intent(inout) :: this
81 type(json_file), intent(inout) :: json
82 type(coef_t), intent(inout) :: coef
83 real(kind=rp) :: f_min, f_max, p
84
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)
88
89 call this%init_base(json, coef)
90 call this%init_from_attributes(coef, f_min, f_max, p)
91
92 end subroutine simp_mapping_init_from_json
93
95 subroutine simp_mapping_init_from_attributes(this, coef, f_min, f_max, p)
96 class(simp_mapping_t), intent(inout) :: this
97 type(coef_t), intent(inout) :: coef
98 real(kind=rp), intent(in) :: f_min, f_max, p
99
100 this%f_min = f_min
101 this%f_max = f_max
102 this%p = p
103
104 end subroutine simp_mapping_init_from_attributes
105
107 subroutine simp_mapping_free(this)
108 class(simp_mapping_t), intent(inout) :: this
109
110 call this%free_base()
111
112 end subroutine simp_mapping_free
113
118 subroutine simp_forward_mapping(this, X_out, X_in)
119 class(simp_mapping_t), intent(inout) :: this
120 type(field_t), intent(in) :: X_in
121 type(field_t), intent(inout) :: X_out
122 integer :: n
123
124 n = x_in%dof%size()
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)
128 else
129 call simp_mapping_apply_cpu(this%f_min, this%f_max, this%p, &
130 x_out%x, x_in%x, n)
131 end if
132
133 end subroutine simp_forward_mapping
134
135
141 subroutine simp_backward_mapping(this, sens_out, sens_in, X_in)
142 class(simp_mapping_t), intent(inout) :: this
143 type(field_t), intent(in) :: X_in
144 type(field_t), intent(in) :: sens_in
145 type(field_t), intent(inout) :: sens_out
146 integer :: n
147
148 n = x_in%dof%size()
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)
152 else
153 call simp_mapping_apply_backward_cpu(this%f_min, this%f_max, this%p, &
154 sens_out%x, sens_in%x, x_in%x, n)
155 end if
156
157 end subroutine simp_backward_mapping
158
159end module simp_mapping
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.