40 use num_types,
only: rp
41 use point_zone_registry,
only: neko_point_zone_registry
42 use json_module,
only: json_file
54 real(kind=rp) :: weight = 1.0_rp
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
75 class(objective_t),
allocatable :: objective
77 procedure, pass(this) :: free => objective_wrapper_free
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
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
121 call this%free_base()
124 call this%sensitivity%init(design_size)
128 if (
present(mask_name))
then
129 if (mask_name .ne.
"")
then
130 this%has_mask = .true.
131 this%mask => neko_point_zone_registry%get_point_zone(mask_name)
135 if (
present(start_time))
then
136 this%start_time = start_time
138 this%start_time = 0.0_rp
141 if (
present(end_time))
then
142 this%end_time = end_time
144 this%end_time = huge(0.0_rp)
147 end subroutine objective_init_base
150 subroutine objective_free_base(this)
151 class(objective_t),
target,
intent(inout) :: this
157 this%value_weight = 0.0_rp
158 this%sensitivity_weight = 0.0_rp
159 this%start_time = 0.0_rp
160 this%end_time = huge(0.0_rp)
161 call this%sensitivity%free()
163 this%has_mask = .false.
164 if (
associated(this%mask))
nullify(this%mask)
166 end subroutine objective_free_base
171 function objective_get_log_size(this)
result(n)
172 class(objective_t),
intent(in) :: this
176 end function objective_get_log_size
181 subroutine objective_get_log_headers(this, headers)
182 class(objective_t),
intent(in) :: this
183 character(len=*),
intent(out) :: headers(:)
184 character(len=64) :: prefix
186 if (
size(headers) .lt. 1)
return
187 prefix = trim(this%name)
189 if (
size(headers) .lt. 2)
return
190 headers(2) = trim(prefix) //
'.weight'
191 end subroutine objective_get_log_headers
196 subroutine objective_get_log_values(this, values)
197 class(objective_t),
intent(in) :: this
198 real(kind=rp),
intent(out) :: values(:)
200 if (
size(values) .lt. 1)
return
201 values(1) = this%value
202 if (
size(values) .lt. 2)
return
203 values(2) = this%weight
204 end subroutine objective_get_log_values
210 subroutine objective_wrapper_free(this)
211 class(objective_wrapper_t),
intent(inout) :: this
212 if (
allocated(this%objective))
then
213 call this%objective%free()
214 deallocate(this%objective)
216 end subroutine objective_wrapper_free
219 pure function objective_get_weight(this)
result(w)
220 class(objective_t),
intent(in) :: this
223 end function objective_get_weight
Factory function Allocates and initializes an objective function object.
Defines the abstract the base_functional_t type.
Implements the objective_t type.
Implements the steady_problem_t type.
The base functional type.
The abstract objective type.
Wrapper for objectives for use in lists.