Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
mapping.f90
Go to the documentation of this file.
1
34!
36module mapping
37 use num_types, only: rp
38 use json_module, only: json_file
39 use coefs, only: coef_t
40 use field, only: field_t
41 use field_math, only: field_copy
42 implicit none
43 private
44
46 type, abstract, public :: mapping_t
48 type(coef_t), pointer :: coef => null()
50 type(field_t) :: x_in
52 character(len=80) :: fld_name = ""
53
54 contains
56 procedure, pass(this) :: init_base => mapping_init_base
58 procedure, pass(this) :: free_base => mapping_free_base
60 procedure, pass(this) :: apply_forward => mapping_apply_forward_wrapper
62 procedure, pass(this) :: apply_backward => mapping_apply_backward_wrapper
64 procedure(mapping_init), pass(this), deferred :: init
66 procedure(mapping_free), pass(this), deferred :: free
68 procedure(mapping_forward_mapping), pass(this), deferred :: forward_mapping
70 procedure(mapping_backward_mapping), pass(this), deferred :: &
71 backward_mapping
72 end type mapping_t
73
75 type, public :: mapping_wrapper_t
77 class(mapping_t), allocatable :: mapping
78 contains
80 procedure, pass(this) :: free => mapping_wrapper_free
81 end type mapping_wrapper_t
82
83 abstract interface
84
88 subroutine mapping_init(this, json, coef)
89 import mapping_t, json_file, coef_t
90 class(mapping_t), intent(inout) :: this
91 type(json_file), intent(inout) :: json
92 type(coef_t), intent(inout) :: coef
93 end subroutine mapping_init
94 end interface
95
96 abstract interface
97
98 subroutine mapping_free(this)
99 import mapping_t
100 class(mapping_t), intent(inout) :: this
101 end subroutine mapping_free
102 end interface
103
104 abstract interface
105
109 subroutine mapping_forward_mapping(this, X_out, X_in)
110 import mapping_t, field_t
111 class(mapping_t), intent(inout) :: this
112 type(field_t), intent(in) :: X_in
113 type(field_t), intent(inout) :: X_out
114 end subroutine mapping_forward_mapping
115 end interface
116
117 abstract interface
118
127 subroutine mapping_backward_mapping(this, sens_out, sens_in, X_in)
128 import mapping_t, field_t
129 class(mapping_t), intent(inout) :: this
130 type(field_t), intent(in) :: sens_in
131 type(field_t), intent(in) :: X_in
132 type(field_t), intent(inout) :: sens_out
133 end subroutine mapping_backward_mapping
134 end interface
135
141 module subroutine mapping_factory(object, json, coef)
142 class(mapping_t), allocatable, intent(inout) :: object
143 type(json_file), intent(inout) :: json
144 type(coef_t), intent(inout) :: coef
145 end subroutine mapping_factory
146 end interface mapping_factory
147
148 public :: mapping_factory
149contains
150
152 subroutine mapping_init_base(this, json, coef, fld_name)
153 class(mapping_t), intent(inout) :: this
154 type(json_file), intent(inout) :: json
155 character(len=*), intent(in) :: fld_name
156 type(coef_t), intent(inout), target :: coef
157
158 this%coef => coef
159 this%fld_name = fld_name
160 ! The mapping handler will take care of naming this field
161 call this%X_in%init(coef%dof)
162
163 end subroutine mapping_init_base
164
166 subroutine mapping_free_base(this)
167 class(mapping_t), intent(inout) :: this
168
169 call this%X_in%free()
170 nullify(this%coef)
171
172 end subroutine mapping_free_base
173
175 subroutine mapping_wrapper_free(this)
176 class(mapping_wrapper_t), intent(inout) :: this
177
178 if (allocated(this%mapping)) then
179 call this%mapping%free()
180 deallocate(this%mapping)
181 end if
182 end subroutine mapping_wrapper_free
183
188 subroutine mapping_apply_forward_wrapper(this, X_out, X_in)
189 class(mapping_t), intent(inout) :: this
190 type(field_t), intent(inout) :: X_out
191 type(field_t), intent(in) :: X_in
192
193 call field_copy(this%X_in, x_in)
194 call this%forward_mapping(x_out, this%X_in)
195
196 end subroutine mapping_apply_forward_wrapper
197
206 subroutine mapping_apply_backward_wrapper(this, sens_out, sens_in)
207 class(mapping_t), intent(inout) :: this
208 type(field_t), intent(inout) :: sens_out
209 type(field_t), intent(in) :: sens_in
210 ! @todo
211 ! hmmmm, it would be silly to call mapping backward without mapping forward
212 ! but at least this%X_in is certainly initialized.
213 ! but it won't contain the correct information unless a map forward has
214 ! occured.
215 call this%backward_mapping(sens_out, sens_in, this%X_in)
216
217 end subroutine mapping_apply_backward_wrapper
218
219end module mapping
mapping factory. Both constructs and initializes the object.
Definition mapping.f90:140
The common constructor using a JSON dictionary.
Definition mapping.f90:88
Mappings to be applied to a scalar field.
Definition mapping.f90:36
Base abstract class for mapping.
Definition mapping.f90:46
A helper type that is needed to have an array of polymorphic objects.
Definition mapping.f90:75