70 simulation, max_iterations, tolerance)
72 type(json_file),
intent(inout) :: parameters
74 class(
design_t),
intent(in) :: design
76 integer,
intent(in) :: max_iterations
77 real(kind=rp),
intent(in) :: tolerance
79 character(len=1024) :: optimization_header
80 character(len=1024) :: problem_header
83 type(json_file) :: solver_parameters
86 call this%logger%init(
'optimization_data.csv')
89 problem_header =
problem%get_log_header()
90 optimization_header =
'iter, ' // trim(problem_header) // &
91 ', KKTmax, KKTnorm2, scaling factor'
92 call this%logger%set_header(trim(optimization_header))
96 if (pe_rank .eq. 0)
then
97 print *,
"Initializing mma_optimizer with steady_state_problem_t."
101 call this%mma%init(x%x,
design%size(),
problem%get_n_constraints(), &
102 solver_parameters, this%scale, this%auto_scale)
105 max_iterations, tolerance)
127 class(
problem_t),
intent(inout) :: problem
128 class(
design_t),
intent(inout) :: design
133 integer :: iter, ierr, nglobal, n
134 real(kind=rp) :: scaling_factor
136 real(kind=rp) :: objective_value
137 type(vector_t) :: all_objectives
138 type(vector_t) :: constraint_value
139 type(vector_t) :: objective_sensitivities
140 type(matrix_t) :: constraint_sensitivities
142 type(vector_t) :: log_data
146 call mpi_allreduce(n, nglobal, 1, mpi_integer, mpi_sum, neko_comm, ierr)
149 scaling_factor = 1.0_rp
150 if (pe_rank .eq. 0)
then
151 print *,
"max_iterations for the optimization loop = ", &
161 call problem%get_objective_value(objective_value)
162 call problem%get_constraint_values(constraint_value)
163 call problem%get_objective_sensitivities(objective_sensitivities)
164 call problem%get_constraint_sensitivities(constraint_sensitivities)
165 call problem%get_all_objective_values(all_objectives)
169 all_objectives, constraint_value, 0.0_rp, 0.0_rp, scaling_factor, &
171 call this%logger%write(log_data)
176 do iter = 1, this%max_iterations
177 if (this%mma%get_residumax() .lt. this%tolerance)
exit
180 if (this%auto_scale .eqv. .true.)
then
181 scaling_factor = abs(this%scale/constraint_value%x(1))
183 scaling_factor = abs(this%scale)
189 call this%mma%update(iter, x%x, objective_sensitivities, &
190 scaling_factor * constraint_value, &
191 scaling_factor * constraint_sensitivities)
193 call design%update_design(x)
201 call problem%get_objective_value(objective_value)
202 call problem%get_constraint_values(constraint_value)
203 call problem%get_objective_sensitivities(objective_sensitivities)
204 call problem%get_constraint_sensitivities(constraint_sensitivities)
205 call problem%get_all_objective_values(all_objectives)
207 call this%mma%KKT(x%x, objective_sensitivities, &
208 constraint_value, constraint_sensitivities)
212 all_objectives, constraint_value, this%mma%get_residumax(), &
213 this%mma%get_residunorm(), scaling_factor, &
215 call this%logger%write(log_data)
223 if (pe_rank .eq. 0)
then
224 print *,
"MMA Optimization completed after", iter-1,
"iterations."
227 call constraint_value%free()
228 call objective_sensitivities%free()
229 call constraint_sensitivities%free()
243 all_objectives, constraint_value, residumax, residunorm, &
244 scaling_factor, n, m)
245 type(vector_t),
intent(out) :: log_data
246 integer,
intent(in) :: iter
247 real(kind=rp),
intent(in) ::objective_value
248 type(vector_t),
intent(in) :: all_objectives
249 type(vector_t),
intent(in) :: constraint_value
250 real(kind=rp),
intent(in) :: residumax, residunorm, scaling_factor
251 integer,
intent(in) :: n, m
252 integer :: i_tmp1, i_tmp2
256 call log_data%init(5 + n + m)
259 log_data%x(1) = real(iter, kind=rp)
262 log_data%x(2) = objective_value
266 i_tmp2 = i_tmp1 + n - 1
267 log_data%x(i_tmp1 : i_tmp2) = all_objectives%x
271 i_tmp2 = i_tmp1 + m - 1
272 log_data%x(i_tmp1 : i_tmp2) = constraint_value%x
275 log_data%x(i_tmp2 + 1) = residumax
276 log_data%x(i_tmp2 + 2) = residunorm
277 log_data%x(i_tmp2 + 3) = scaling_factor
subroutine mma_logger_assemble_data(log_data, iter, objective_value, all_objectives, constraint_value, residumax, residunorm, scaling_factor, n, m)