Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
base_functional.f90
Go to the documentation of this file.
1
34
37 use design, only: design_t
38 use json_module, only: json_file
39 use json_utils, only: json_get
40 use num_types, only: rp
41 use point_zone, only: point_zone_t
42 use simulation_m, only: simulation_t
43 use vector, only: vector_t
44 use utils, only: neko_error
45 use vector_math, only: vector_copy, vector_add2s1
46 implicit none
47 private
48
59 type, abstract, public :: base_functional_t
60
62 real(kind=rp) :: value = 0.0_rp
64 real(kind=rp) :: value_old = 0.0_rp
66 type(vector_t) :: sensitivity
68 type(vector_t) :: sensitivity_old
70 character(len=25) :: name = ""
72 logical :: has_mask = .false.
74 class(point_zone_t), pointer :: mask => null()
75
76 contains
77
78 ! ----------------------------------------------------------------------- !
79 ! Derived class interfaces
80
82 generic :: init => init_json, init_json_sim
83
85 procedure, pass(this) :: init_json => functional_init_json
87 procedure, pass(this) :: init_json_sim => functional_init_json_sim
89 procedure(functional_free), pass(this), deferred :: free
90
92 procedure(functional_update_value), pass(this), deferred :: update_value
94 procedure(functional_update_sensitivity), pass(this), deferred :: &
95 update_sensitivity
96
98 procedure, pass(this) :: get_value => functional_get_value
100 procedure, pass(this) :: get_sensitivity => functional_get_sensitivity
102 procedure, pass(this) :: reset_value => functional_reset_value
104 procedure, pass(this) :: reset_sensitivity => functional_reset_sensitivity
106 procedure, pass(this) :: accumulate_value => functional_accumulate_value
108 procedure, pass(this) :: accumulate_sensitivity => &
109 functional_accumulate_sensitivity
110
111 end type base_functional_t
112
113 ! -------------------------------------------------------------------------- !
114 ! Interface specifications for the derived types, these are the constructors
115 ! for the different types of objective functions.
116
117 abstract interface
118
120 subroutine functional_free(this)
121 import base_functional_t
122 class(base_functional_t), intent(inout) :: this
123 end subroutine functional_free
124
126 subroutine functional_update_value(this, design)
128 class(base_functional_t), intent(inout) :: this
129 class(design_t), intent(in) :: design
130 end subroutine functional_update_value
131
133 subroutine functional_update_sensitivity(this, design)
135 class(base_functional_t), intent(inout) :: this
136 class(design_t), intent(in) :: design
137 end subroutine functional_update_sensitivity
138
139 end interface
140
141contains
142
144 subroutine functional_init_json(this, json, design)
145 class(base_functional_t), intent(inout) :: this
146 type(json_file), intent(inout) :: json
147 class(design_t), intent(in) :: design
148 character(len=:), allocatable :: type
149
150 call json_get(json, 'type', type)
151 call neko_error("Functional type: '" // type // &
152 "' does not support initialization without simulation")
153 end subroutine functional_init_json
154
156 subroutine functional_init_json_sim(this, json, design, simulation)
157 class(base_functional_t), intent(inout) :: this
158 type(json_file), intent(inout) :: json
159 class(design_t), intent(in) :: design
160 type(simulation_t), target, intent(inout) :: simulation
161 character(len=:), allocatable :: type
162
163 call json_get(json, 'type', type)
164 call neko_error("Functional type: '" // type // &
165 "' does not support initialization with simulation")
166 end subroutine functional_init_json_sim
167
168
170 function functional_get_value(this) result(v)
171 class(base_functional_t), intent(in) :: this
172 real(kind=rp) :: v
173
174 v = this%value
175 end function functional_get_value
176
178 subroutine functional_get_sensitivity(this, sensitivity)
179 class(base_functional_t), intent(in) :: this
180 type(vector_t), intent(inout) :: sensitivity
181
182 sensitivity = this%sensitivity
183 end subroutine functional_get_sensitivity
184
186 subroutine functional_reset_value(this)
187 class(base_functional_t), intent(inout) :: this
188
189 this%value = 0.0_rp
190 end subroutine functional_reset_value
191
193 subroutine functional_reset_sensitivity(this)
194 class(base_functional_t), intent(inout) :: this
195
196 this%sensitivity = 0.0_rp
197 end subroutine functional_reset_sensitivity
198
200 subroutine functional_accumulate_value(this, design, dt)
201 class(base_functional_t), intent(inout) :: this
202 class(design_t), intent(in) :: design
203 real(kind=rp), intent(in) :: dt
204
205 this%value_old = this%value
206 call this%update_value(design)
207
208 ! could potentially use higher order trapezoidal/Simpson etc, but this
209 ! should suffice
210 this%value = this%value_old + this%value * dt
211 end subroutine functional_accumulate_value
212
214 subroutine functional_accumulate_sensitivity(this, design, dt)
215 class(base_functional_t), intent(inout) :: this
216 class(design_t), intent(in) :: design
217 real(kind=rp), intent(in) :: dt
218
219 call vector_copy(this%sensitivity_old, this%sensitivity)
220 call this%update_sensitivity(design)
221
222 ! could potentially use higher order trapezoidal/Simpson etc, but this
223 ! should suffice
224 call vector_add2s1(this%sensitivity, this%sensitivity_old, dt)
225 end subroutine functional_accumulate_sensitivity
226end module base_functional
Defines the abstract the base_functional_t type.
Implements the design_t.
Definition design.f90:36
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:54