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
109 subroutine objective_init_base(this, name, design_size, weight, mask_name)
110 class(objective_t), intent(inout) :: this
111 character(len=*), intent(in) :: name
112 integer, intent(in) :: design_size
113 real(kind=rp), intent(in) :: weight
114 character(len=*), intent(in), optional :: mask_name
115
116 call this%free_base()
117
118 this%name = name
119 call this%sensitivity%init(design_size)
120 call this%sensitivity_old%init(design_size)
121
122 this%weight = weight
123
124 if (present(mask_name)) then
125 if (mask_name .ne. "") then
126 this%has_mask = .true.
127 this%mask => neko_point_zone_registry%get_point_zone(mask_name)
128 end if
129 end if
130
131 end subroutine objective_init_base
132
134 subroutine objective_free_base(this)
135 class(objective_t), target, intent(inout) :: this
136
137 this%name = ""
138 this%weight = 1.0_rp
139
140 this%value = 0.0_rp
141 this%value_old = 0.0_rp
142 call this%sensitivity%free()
143 call this%sensitivity_old%free()
144
145 this%has_mask = .false.
146 if (associated(this%mask)) nullify(this%mask)
147
148 end subroutine objective_free_base
149
153 function objective_get_log_size(this) result(n)
154 class(objective_t), intent(in) :: this
155 integer :: n
156
157 n = 2
158 end function objective_get_log_size
159
163 subroutine objective_get_log_headers(this, headers)
164 class(objective_t), intent(in) :: this
165 character(len=*), intent(out) :: headers(:)
166 character(len=64) :: prefix
167
168 if (size(headers) .lt. 1) return
169 prefix = trim(this%name)
170 headers(1) = prefix
171 if (size(headers) .lt. 2) return
172 headers(2) = trim(prefix) // '.weight'
173 end subroutine objective_get_log_headers
174
178 subroutine objective_get_log_values(this, values)
179 class(objective_t), intent(in) :: this
180 real(kind=rp), intent(out) :: values(:)
181
182 if (size(values) .lt. 1) return
183 values(1) = this%value
184 if (size(values) .lt. 2) return
185 values(2) = this%weight
186 end subroutine objective_get_log_values
187
188 ! -------------------------------------------------------------------------- !
189 ! Implementations for the wrapper
190
192 subroutine objective_wrapper_free(this)
193 class(objective_wrapper_t), intent(inout) :: this
194 if (allocated(this%objective)) then
195 call this%objective%free()
196 deallocate(this%objective)
197 end if
198 end subroutine objective_wrapper_free
199
201 pure function objective_get_weight(this) result(w)
202 class(objective_t), intent(in) :: this
203 real(kind=rp) :: w
204 w = this%weight
205 end function objective_get_weight
206
207end module objective
208
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:54
The abstract objective type.
Definition objective.f90:52
Wrapper for objectives for use in lists.
Definition objective.f90:74