Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
adjoint_mixing_scalar_source_term.f90
Go to the documentation of this file.
1
34!
36! this is a such a dumb name
38 use num_types, only : rp
39 use field_list, only : field_list_t
40 use field, only: field_t
41 use registry, only: neko_registry
42 use scratch_registry, only: neko_scratch_registry
43 use json_module, only : json_file
44 use time_state, only: time_state_t
45 use json_utils, only: json_get, json_get_or_default
46 use source_term, only : source_term_t
47 use coefs, only : coef_t
48 use field_math, only: field_add2s2, field_copy, field_cadd
50 use point_zone, only: point_zone_t
51 implicit none
52 private
54
55 ! this will be the adjoint forcing from Casper's objective function
56 ! TODO
57 ! it actually isn't this. Infact, his is a surface integral on the outlet
58 ! Which means we get strange BC's in our adjoint problem.
59 ! This source term would be if we had a certain volume that we wanted more
60 ! mixed
61 ! the forcing is of the form:
62 ! \f$ \phi - \phi_ref \f$
63 ! ie, difference between it and the average.
64 type, public, extends(source_term_t) :: adjoint_mixing_scalar_source_term_t
66 type(field_t), pointer :: s => null()
68 real(kind=rp) :: obj_scale
70 real(kind=rp) :: phi_ref
72 class(point_zone_t), pointer :: mask => null()
74 logical :: if_mask
76 real(kind=rp) :: mask_volume
77 contains
79 procedure, pass(this) :: init => &
80 adjoint_mixing_scalar_source_term_init_from_json
82 procedure, pass(this) :: init_from_components => &
83 adjoint_mixing_scalar_source_term_init_from_components
85 procedure, pass(this) :: free => adjoint_mixing_scalar_source_term_free
87 procedure, pass(this) :: compute_ => &
88 adjoint_mixing_scalar_source_term_compute
90
91contains
94 class(source_term_t), allocatable, intent(inout) :: obj
97
104 subroutine adjoint_mixing_scalar_source_term_init_from_json(this, &
105 json, fields, coef, variable_name)
106 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
107 type(json_file), intent(inout) :: json
108 type(field_list_t), intent(in), target :: fields
109 type(coef_t), intent(in), target :: coef
110 character(len=*), intent(in) :: variable_name
111
112
113 end subroutine adjoint_mixing_scalar_source_term_init_from_json
114
126 subroutine adjoint_mixing_scalar_source_term_init_from_components(this, &
127 f_s, s, obj_scale, phi_ref, mask, if_mask, coef, start_time, end_time)
128 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
129 type(field_t), pointer, intent(in) :: f_s
130 type(field_t), intent(in), target :: s
131 real(kind=rp), intent(in) :: obj_scale
132 real(kind=rp), intent(in) :: phi_ref
133 class(point_zone_t), intent(in), target :: mask
134 logical, intent(in) :: if_mask
135 type(coef_t), intent(in) :: coef
136 real(kind=rp), intent(in) :: start_time
137 real(kind=rp), intent(in) :: end_time
138
139 type(field_list_t) :: fields
140
141 call this%free()
142
143 ! this is copying the fluid source term init
144 ! We package the fields for the source term to operate on in a field list.
145 call fields%init(1)
146 call fields%assign(1, f_s)
147
148 call this%init_base(fields, coef, start_time, end_time)
149 call fields%free()
150
151 ! point everything in the correct places
152 this%s => s
153 this%obj_scale = obj_scale
154 this%phi_ref = phi_ref
155 this%if_mask = if_mask
156
157 if (this%if_mask) then
158 this%mask => mask
159 this%mask_volume = compute_masked_volume(this%mask, coef)
160 else
161 this%mask_volume = coef%volume
162 end if
163
164 end subroutine adjoint_mixing_scalar_source_term_init_from_components
165
167 subroutine adjoint_mixing_scalar_source_term_free(this)
168 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
169
170 call this%free_base()
171 nullify(this%s)
172 nullify(this%mask)
173
174 end subroutine adjoint_mixing_scalar_source_term_free
175
179 subroutine adjoint_mixing_scalar_source_term_compute(this, time)
180 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
181 type(time_state_t), intent(in) :: time
182 type(field_t), pointer :: fs
183 type(field_t), pointer :: work
184 integer :: temp_indices(1)
185
186
187 fs => this%fields%get(1)
188
189 call neko_scratch_registry%request_field(work, temp_indices(1), .false.)
190 ! \phi
191 call field_copy(work, this%s)
192 ! \phi - \phi_ref
193 call field_cadd(work, -this%phi_ref)
194 ! mask
195 if (this%if_mask) then
196 call mask_exterior_const(work, this%mask, 0.0_rp)
197 end if
198
199 ! append to RHS with scaling and mask volume
200 call field_add2s2(fs, work, this%obj_scale / this%mask_volume)
201 call neko_scratch_registry%relinquish_field(temp_indices)
202
203
204 end subroutine adjoint_mixing_scalar_source_term_compute
205
Implements the adjoint_mixing_scalar_source_term type.
subroutine, public adjoint_mixing_scalar_source_term_allocate(obj)
Allocator for the adjoint mixing scalar source term.
Some common Masking operations we may need.
Definition mask_ops.f90:36
real(kind=rp) function, public compute_masked_volume(mask, coef)
Compute the volume of the domain contained within the mask.
Definition mask_ops.f90:182