Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
objective.f90
Go to the documentation of this file.
1
34
38 use simulation_m, only: simulation_t
39 use design, only: design_t
40 use num_types, only: rp
41 use point_zone_registry, only: neko_point_zone_registry
42 use json_module, only: json_file
43 implicit none
44 private
45
47
52 type, abstract, extends(base_functional_t) :: objective_t
54 real(kind=rp) :: weight = 1.0_rp
55
56 contains
57
59 procedure, pass(this) :: init_base => objective_init_base
61 procedure, pass(this) :: free_base => objective_free_base
63 procedure, pass(this) :: get_weight => objective_get_weight
65 procedure, pass(this) :: get_log_size => objective_get_log_size
67 procedure, pass(this) :: get_log_headers => objective_get_log_headers
69 procedure, pass(this) :: get_log_values => objective_get_log_values
70
71 end type objective_t
72
75 class(objective_t), allocatable :: objective
76 contains
77 procedure, pass(this) :: free => objective_wrapper_free
78 end type objective_wrapper_t
79
80 ! -------------------------------------------------------------------------- !
81 ! Explicit interfaces
82
90 module subroutine objective_factory(object, json, design, simulation)
91 class(objective_t), allocatable, intent(inout) :: object
92 type(json_file), intent(inout) :: json
93 class(design_t), intent(in) :: design
94 type(simulation_t), target, optional, intent(inout) :: simulation
95 end subroutine objective_factory
96 end interface objective_factory
97
98contains
99
100 ! -------------------------------------------------------------------------- !
101 ! Implementations for the base class
102
111 subroutine objective_init_base(this, name, design_size, weight, mask_name, &
112 start_time, end_time)
113 class(objective_t), intent(inout) :: this
114 character(len=*), intent(in) :: name
115 integer, intent(in) :: design_size
116 real(kind=rp), intent(in) :: weight
117 character(len=*), intent(in), optional :: mask_name
118 real(kind=rp), intent(in), optional :: start_time
119 real(kind=rp), intent(in), optional :: end_time
120
121 call this%free_base()
122
123 this%name = name
124 call this%sensitivity%init(design_size)
125 call this%sensitivity_old%init(design_size)
126
127 this%weight = weight
128
129 if (present(mask_name)) then
130 if (mask_name .ne. "") then
131 this%has_mask = .true.
132 this%mask => neko_point_zone_registry%get_point_zone(mask_name)
133 end if
134 end if
135
136 if (present(start_time)) then
137 this%start_time = start_time
138 else
139 this%start_time = 0.0_rp
140 end if
141
142 if (present(end_time)) then
143 this%end_time = end_time
144 else
145 this%end_time = huge(0.0_rp)
146 end if
147
148 end subroutine objective_init_base
149
151 subroutine objective_free_base(this)
152 class(objective_t), target, intent(inout) :: this
153
154 this%name = ""
155 this%weight = 1.0_rp
156
157 this%value = 0.0_rp
158 this%value_old = 0.0_rp
159 this%start_time = 0.0_rp
160 this%end_time = huge(0.0_rp)
161 call this%sensitivity%free()
162 call this%sensitivity_old%free()
163
164 this%has_mask = .false.
165 if (associated(this%mask)) nullify(this%mask)
166
167 end subroutine objective_free_base
168
172 function objective_get_log_size(this) result(n)
173 class(objective_t), intent(in) :: this
174 integer :: n
175
176 n = 2
177 end function objective_get_log_size
178
182 subroutine objective_get_log_headers(this, headers)
183 class(objective_t), intent(in) :: this
184 character(len=*), intent(out) :: headers(:)
185 character(len=64) :: prefix
186
187 if (size(headers) .lt. 1) return
188 prefix = trim(this%name)
189 headers(1) = prefix
190 if (size(headers) .lt. 2) return
191 headers(2) = trim(prefix) // '.weight'
192 end subroutine objective_get_log_headers
193
197 subroutine objective_get_log_values(this, values)
198 class(objective_t), intent(in) :: this
199 real(kind=rp), intent(out) :: values(:)
200
201 if (size(values) .lt. 1) return
202 values(1) = this%value
203 if (size(values) .lt. 2) return
204 values(2) = this%weight
205 end subroutine objective_get_log_values
206
207 ! -------------------------------------------------------------------------- !
208 ! Implementations for the wrapper
209
211 subroutine objective_wrapper_free(this)
212 class(objective_wrapper_t), intent(inout) :: this
213 if (allocated(this%objective)) then
214 call this%objective%free()
215 deallocate(this%objective)
216 end if
217 end subroutine objective_wrapper_free
218
220 pure function objective_get_weight(this) result(w)
221 class(objective_t), intent(in) :: this
222 real(kind=rp) :: w
223 w = this%weight
224 end function objective_get_weight
225
226end module objective
227
Factory function Allocates and initializes an objective function object.
Definition objective.f90:89
Defines the abstract the base_functional_t type.
Implements the design_t.
Definition design.f90:36
Implements the objective_t type.
Definition objective.f90:36
Implements the steady_problem_t type.
An abstract design type.
Definition design.f90:53
The abstract objective type.
Definition objective.f90:52
Wrapper for objectives for use in lists.
Definition objective.f90:74