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
43 use vector,
only: vector_t
44 use utils,
only: neko_error
45 use vector_math,
only: vector_copy, vector_add2s1
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()
82 generic :: init => init_json, init_json_sim
85 procedure, pass(this) :: init_json => functional_init_json
87 procedure, pass(this) :: init_json_sim => functional_init_json_sim
92 procedure(functional_update_value), pass(this),
deferred :: update_value
94 procedure(functional_update_sensitivity), pass(this),
deferred :: &
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
122 class(base_functional_t),
intent(inout) :: this
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
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
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
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
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
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
170 function functional_get_value(this)
result(v)
171 class(base_functional_t),
intent(in) :: this
175 end function functional_get_value
178 subroutine functional_get_sensitivity(this, sensitivity)
179 class(base_functional_t),
intent(in) :: this
180 type(vector_t),
intent(inout) :: sensitivity
182 sensitivity = this%sensitivity
183 end subroutine functional_get_sensitivity
186 subroutine functional_reset_value(this)
187 class(base_functional_t),
intent(inout) :: this
190 end subroutine functional_reset_value
193 subroutine functional_reset_sensitivity(this)
194 class(base_functional_t),
intent(inout) :: this
196 this%sensitivity = 0.0_rp
197 end subroutine functional_reset_sensitivity
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
205 this%value_old = this%value
206 call this%update_value(
design)
210 this%value = this%value_old + this%value * dt
211 end subroutine functional_accumulate_value
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
219 call vector_copy(this%sensitivity_old, this%sensitivity)
220 call this%update_sensitivity(
design)
224 call vector_add2s1(this%sensitivity, this%sensitivity_old, dt)
225 end subroutine functional_accumulate_sensitivity
Defines the abstract the base_functional_t type.
Implements the steady_problem_t type.
The base functional type.