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 use registry, only: neko_registry
43 implicit none
44 private
45
47 type, abstract, public :: mapping_t
49 type(coef_t), pointer :: coef => null()
51 type(field_t), pointer :: x_in => null()
53 character(len=80) :: fld_name = ""
54
55 contains
57 procedure, pass(this) :: init_base => mapping_init_base
59 procedure, pass(this) :: free_base => mapping_free_base
61 procedure, pass(this) :: apply_forward => mapping_apply_forward_wrapper
63 procedure, pass(this) :: apply_backward => mapping_apply_backward_wrapper
65 procedure(mapping_init), pass(this), deferred :: init
67 procedure(mapping_free), pass(this), deferred :: free
69 procedure(mapping_forward_mapping), pass(this), deferred :: forward_mapping
71 procedure(mapping_backward_mapping), pass(this), deferred :: &
72 backward_mapping
73 end type mapping_t
74
76 type, public :: mapping_wrapper_t
78 class(mapping_t), allocatable :: mapping
79 contains
81 procedure, pass(this) :: free => mapping_wrapper_free
82 end type mapping_wrapper_t
83
84 abstract interface
85
89 subroutine mapping_init(this, json, coef)
90 import mapping_t, json_file, coef_t
91 class(mapping_t), intent(inout) :: this
92 type(json_file), intent(inout) :: json
93 type(coef_t), intent(inout) :: coef
94 end subroutine mapping_init
95 end interface
96
97 abstract interface
98
99 subroutine mapping_free(this)
100 import mapping_t
101 class(mapping_t), intent(inout) :: this
102 end subroutine mapping_free
103 end interface
104
105 abstract interface
106
110 subroutine mapping_forward_mapping(this, X_out, X_in)
111 import mapping_t, field_t
112 class(mapping_t), intent(inout) :: this
113 type(field_t), intent(in) :: X_in
114 type(field_t), intent(inout) :: X_out
115 end subroutine mapping_forward_mapping
116 end interface
117
118 abstract interface
119
128 subroutine mapping_backward_mapping(this, sens_out, sens_in, X_in)
129 import mapping_t, field_t
130 class(mapping_t), intent(inout) :: this
131 type(field_t), intent(in) :: sens_in
132 type(field_t), intent(in) :: X_in
133 type(field_t), intent(inout) :: sens_out
134 end subroutine mapping_backward_mapping
135 end interface
136
142 module subroutine mapping_factory(object, json, coef)
143 class(mapping_t), allocatable, intent(inout) :: object
144 type(json_file), intent(inout) :: json
145 type(coef_t), intent(inout) :: coef
146 end subroutine mapping_factory
147 end interface mapping_factory
148
149 public :: mapping_factory
150contains
151
153 subroutine mapping_init_base(this, json, coef, fld_name)
154 class(mapping_t), intent(inout) :: this
155 type(json_file), intent(inout) :: json
156 character(len=*), intent(in) :: fld_name
157 type(coef_t), intent(inout), target :: coef
158
159 this%coef => coef
160 this%fld_name = fld_name
161 ! The mapping handler will take care of naming this field
162 call neko_registry%add_field(coef%dof, this%fld_name)
163 this%X_in => neko_registry%get_field(this%fld_name)
164
165 end subroutine mapping_init_base
166
168 subroutine mapping_free_base(this)
169 class(mapping_t), intent(inout) :: this
170
171 nullify(this%X_in)
172 nullify(this%coef)
173
174 end subroutine mapping_free_base
175
177 subroutine mapping_wrapper_free(this)
178 class(mapping_wrapper_t), intent(inout) :: this
179
180 if (allocated(this%mapping)) then
181 call this%mapping%free()
182 deallocate(this%mapping)
183 end if
184 end subroutine mapping_wrapper_free
185
190 subroutine mapping_apply_forward_wrapper(this, X_out, X_in)
191 class(mapping_t), intent(inout) :: this
192 type(field_t), intent(inout) :: X_out
193 type(field_t), intent(in) :: X_in
194
195 call field_copy(this%X_in, x_in)
196 call this%forward_mapping(x_out, this%X_in)
197
198 end subroutine mapping_apply_forward_wrapper
199
208 subroutine mapping_apply_backward_wrapper(this, sens_out, sens_in)
209 class(mapping_t), intent(inout) :: this
210 type(field_t), intent(inout) :: sens_out
211 type(field_t), intent(in) :: sens_in
212 ! @todo
213 ! hmmmm, it would be silly to call mapping backward without mapping forward
214 ! but at least this%X_in is certainly initialized.
215 ! but it won't contain the correct information unless a map forward has
216 ! occured.
217 call this%backward_mapping(sens_out, sens_in, this%X_in)
218
219 end subroutine mapping_apply_backward_wrapper
220
221end module mapping
mapping factory. Both constructs and initializes the object.
Definition mapping.f90:141
The common constructor using a JSON dictionary.
Definition mapping.f90:89
Mappings to be applied to a scalar field.
Definition mapping.f90:36
Base abstract class for mapping.
Definition mapping.f90:47
A helper type that is needed to have an array of polymorphic objects.
Definition mapping.f90:76