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
115
116 subroutine adjoint_mixing_scalar_source_term_init_from_components(this, &
117 f_s, s, obj_scale, phi_ref, mask, if_mask, coef)
118 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
119 type(field_t), pointer, intent(in) :: f_s
120 real(kind=rp), intent(in) :: phi_ref
121 type(field_t), intent(in), target :: s
122 class(point_zone_t), intent(in), target :: mask
123 type(field_list_t) :: fields
124 type(coef_t) :: coef
125 real(kind=rp) :: start_time
126 real(kind=rp) :: end_time
127 real(kind=rp) :: obj_scale
128
129 logical :: if_mask
130
131 start_time = 0.0_rp
132 end_time = 100000000.0_rp
133
134
135 call this%free()
136
137 ! this is copying the fluid source term init
138 ! We package the fields for the source term to operate on in a field list.
139 call fields%init(1)
140 call fields%assign(1, f_s)
141
142 call this%init_base(fields, coef, start_time, end_time)
143
144 ! point everything in the correct places
145 this%s => s
146 this%obj_scale = obj_scale
147 this%phi_ref = phi_ref
148 this%if_mask = if_mask
149
150 if (this%if_mask) then
151 this%mask => mask
152 this%mask_volume = compute_masked_volume(this%mask, coef)
153 else
154 this%mask_volume = coef%volume
155 end if
156
157 end subroutine adjoint_mixing_scalar_source_term_init_from_components
158
160 subroutine adjoint_mixing_scalar_source_term_free(this)
161 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
162
163 call this%free_base()
164 nullify(this%s)
165 nullify(this%mask)
166
167 end subroutine adjoint_mixing_scalar_source_term_free
168
172 subroutine adjoint_mixing_scalar_source_term_compute(this, time)
173 class(adjoint_mixing_scalar_source_term_t), intent(inout) :: this
174 type(time_state_t), intent(in) :: time
175 type(field_t), pointer :: fs
176 type(field_t), pointer :: work
177 integer :: temp_indices(1)
178
179
180 fs => this%fields%get(1)
181
182 call neko_scratch_registry%request_field(work, temp_indices(1), .false.)
183 ! \phi
184 call field_copy(work, this%s)
185 ! \phi - \phi_ref
186 call field_cadd(work, -this%phi_ref)
187 ! mask
188 if (this%if_mask) then
189 call mask_exterior_const(work, this%mask, 0.0_rp)
190 end if
191
192 ! append to RHS with scaling and mask volume
193 call field_add2s2(fs, work, this%obj_scale / this%mask_volume)
194 call neko_scratch_registry%relinquish_field(temp_indices)
195
196
197 end subroutine adjoint_mixing_scalar_source_term_compute
198
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