Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
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!
35module mapping
36 use num_types, only: rp
37 use json_module, only: json_file
38 use coefs, only: coef_t
39 use field, only: field_t
40 use field_math, only: field_copy
41 implicit none
42 private
43
45 type, abstract, public :: mapping_t
47 type(coef_t), pointer :: coef => null()
49 type(field_t) :: x_in
50
51 contains
53 procedure, pass(this) :: init_base => mapping_init_base
55 procedure, pass(this) :: free_base => mapping_free_base
57 procedure, pass(this) :: apply_forward => mapping_apply_forward_wrapper
59 procedure, pass(this) :: apply_backward => mapping_apply_backward_wrapper
61 procedure(mapping_init), pass(this), deferred :: init
63 procedure(mapping_free), pass(this), deferred :: free
65 procedure(mapping_forward_mapping), pass(this), deferred :: forward_mapping
67 procedure(mapping_backward_mapping), pass(this), deferred :: &
68 backward_mapping
69 end type mapping_t
70
72 type, public :: mapping_wrapper_t
74 class(mapping_t), allocatable :: mapping
75 contains
77 procedure, pass(this) :: free => mapping_wrapper_free
78 end type mapping_wrapper_t
79
80 abstract interface
81
85 subroutine mapping_init(this, json, coef)
86 import mapping_t, json_file, coef_t
87 class(mapping_t), intent(inout) :: this
88 type(json_file), intent(inout) :: json
89 type(coef_t), intent(inout) :: coef
90 end subroutine mapping_init
91 end interface
92
93 abstract interface
94
95 subroutine mapping_free(this)
96 import mapping_t
97 class(mapping_t), intent(inout) :: this
98 end subroutine mapping_free
99 end interface
100
101 abstract interface
102
106 subroutine mapping_forward_mapping(this, X_out, X_in)
107 import mapping_t, field_t
108 class(mapping_t), intent(inout) :: this
109 type(field_t), intent(in) :: X_in
110 type(field_t), intent(inout) :: X_out
111 end subroutine mapping_forward_mapping
112 end interface
113
114 abstract interface
115
124 subroutine mapping_backward_mapping(this, sens_out, sens_in, X_in)
125 import mapping_t, field_t
126 class(mapping_t), intent(inout) :: this
127 type(field_t), intent(in) :: sens_in
128 type(field_t), intent(in) :: X_in
129 type(field_t), intent(inout) :: sens_out
130 end subroutine mapping_backward_mapping
131 end interface
132
138 module subroutine mapping_factory(object, json, coef)
139 class(mapping_t), allocatable, intent(inout) :: object
140 type(json_file), intent(inout) :: json
141 type(coef_t), intent(inout) :: coef
142 end subroutine mapping_factory
143 end interface mapping_factory
144
145 public :: mapping_factory
146contains
147
149 subroutine mapping_init_base(this, json, coef)
150 class(mapping_t), intent(inout) :: this
151 type(json_file), intent(inout) :: json
152 type(coef_t), intent(inout), target :: coef
153
154 this%coef => coef
155 call this%X_in%init(coef%dof)
156
157 end subroutine mapping_init_base
158
160 subroutine mapping_free_base(this)
161 class(mapping_t), intent(inout) :: this
162
163 call this%X_in%free()
164 nullify(this%coef)
165
166 end subroutine mapping_free_base
167
169 subroutine mapping_wrapper_free(this)
170 class(mapping_wrapper_t), intent(inout) :: this
171
172 if (allocated(this%mapping)) then
173 call this%mapping%free()
174 deallocate(this%mapping)
175 end if
176 end subroutine mapping_wrapper_free
177
182 subroutine mapping_apply_forward_wrapper(this, X_out, X_in)
183 class(mapping_t), intent(inout) :: this
184 type(field_t), intent(inout) :: X_out
185 type(field_t), intent(in) :: X_in
186
187 call field_copy(this%X_in, x_in)
188 call this%forward_mapping(x_out, this%X_in)
189
190 end subroutine mapping_apply_forward_wrapper
191
200 subroutine mapping_apply_backward_wrapper(this, sens_out, sens_in)
201 class(mapping_t), intent(inout) :: this
202 type(field_t), intent(inout) :: sens_out
203 type(field_t), intent(in) :: sens_in
204 ! @todo
205 ! hmmmm, it would be silly to call mapping backward without mapping forward
206 ! but at least this%X_in is certainly initialized.
207 ! but it won't contain the correct information unless a map forward has
208 ! occured.
209 call this%backward_mapping(sens_out, sens_in, this%X_in)
210
211 end subroutine mapping_apply_backward_wrapper
212
213end module mapping
mapping factory. Both constructs and initializes the object.
Definition mapping.f90:137
The common constructor using a JSON dictionary.
Definition mapping.f90:85
Mappings to be applied to a scalar field.
Definition mapping.f90:35
Base abstract class for mapping.
Definition mapping.f90:45
A helper type that is needed to have an array of polymorphic objects.
Definition mapping.f90:72