Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
problem.f90
Go to the documentation of this file.
1
34
41module problem
42 use num_types, only: rp, dp
43 use design, only: design_t
47 use vector, only: vector_t
48 use matrix, only: matrix_t
49 use device, only: host_to_device, device_to_host
50 use json_module, only: json_file
51 use json_utils, only: json_extract_item, json_get, json_get_or_default
52 use simulation_m, only: simulation_t
53 use logger, only: neko_log
54 use math, only: copy
55 use time_state, only: time_state_t
56 use vector_math, only: vector_add2, vector_cfill
57 use time_step_controller, only: time_step_controller_t
60 use simulation, only: simulation_init, simulation_step, simulation_finalize
61 use mpi_f08, only: mpi_wtime
62 use profiler, only: profiler_start_region, profiler_end_region
63 use utils, only: neko_error
64 implicit none
65 private
66
68 type, public :: problem_t
69 private
70
72 integer :: n_design = 0
74 integer :: n_objectives = 0
76 integer :: n_constraints = 0
77
79 class(objective_wrapper_t), allocatable, dimension(:) :: objective_list
81 class(constraint_wrapper_t), allocatable, dimension(:) :: constraint_list
82 contains
83
84 ! ----------------------------------------------------------------------- !
85 ! Interfaces
86
88 procedure, pass(this), public :: init => problem_init
90 procedure, pass(this), public :: free => problem_free
91
95 procedure, pass(this), public :: compute => problem_compute
96
100 procedure, pass(this), public :: compute_sensitivity => &
101 problem_compute_sensitivity
104 procedure, pass(this), public :: run_forward_unsteady => &
105 problem_run_forward_unsteady
108 procedure, pass(this), public :: run_backward_unsteady => &
109 problem_run_backward_unsteady
110 ! ----------------------------------------------------------------------- !
111 ! Base class methods
112
114 procedure, pass(this), public :: read_objectives => problem_read_objectives
116 procedure, pass(this), public :: read_constraints => &
117 problem_read_constraints
118
119 ! ----------------------------------------------------------------------- !
120 ! Actual methods
121
123 procedure, pass(this), public :: write => problem_write
125 procedure, pass(this), public :: get_log_values => problem_get_log_values
126
128 procedure, pass(this), public :: add_objective => problem_add_objective
130 procedure, pass(this), public :: add_constraint => problem_add_constraint
131
132 ! ----------------------------------------------------------------------- !
133 ! Internal Updater methods
134
136 procedure, pass(this) :: update_objectives => &
137 problem_update_objectives
139 procedure, pass(this) :: update_constraints => &
140 problem_update_constraints
142 procedure, pass(this) :: update_objective_sensitivities => &
143 problem_update_objective_sensitivities
145 procedure, pass(this) :: update_constraint_sensitivities => &
146 problem_update_constraint_sensitivities
147
149 procedure, pass(this) :: reset_objectives => &
150 problem_reset_objectives
152 procedure, pass(this) :: reset_constraints => &
153 problem_reset_constraints
155 procedure, pass(this) :: reset_objective_sensitivities => &
156 problem_reset_objective_sensitivities
158 procedure, pass(this) :: reset_constraint_sensitivities => &
159 problem_reset_constraint_sensitivities
160
162 procedure, pass(this) :: accumulate_objectives => &
163 problem_accumulate_objectives
165 procedure, pass(this) :: accumulate_constraints => &
166 problem_accumulate_constraints
168 procedure, pass(this) :: accumulate_objective_sensitivities => &
169 problem_accumulate_objective_sensitivities
171 procedure, pass(this) :: accumulate_constraint_sensitivities => &
172 problem_accumulate_constraint_sensitivities
173
174 ! ----------------------------------------------------------------------- !
175 ! Public Getters
176
178 procedure, pass(this), public :: get_objective_value => &
179 problem_get_objective_value
181 procedure, pass(this), public :: get_all_objective_values => &
182 problem_get_all_objective_values
184 procedure, pass(this), public :: get_constraint_values => &
185 problem_get_constraint_values
187 procedure, pass(this), public :: get_objective_sensitivities => &
188 problem_get_objective_sensitivities
190 procedure, pass(this), public :: get_constraint_sensitivities => &
191 problem_get_constraint_sensitivities
192
194 procedure, pass(this) :: get_n_objectives => problem_get_num_objectives
196 procedure, pass(this) :: get_n_constraints => problem_get_num_constraints
197
199 procedure, pass(this) :: get_log_header => problem_get_log_header
201 procedure, pass(this) :: get_log_size => problem_get_log_size
202
203 end type problem_t
204
205contains
206
207 ! ========================================================================== !
208 ! Base class methods
209
211 subroutine problem_init(this, parameters, design, simulation)
212 class(problem_t), intent(inout) :: this
213 type(json_file), intent(inout) :: parameters
214 class(design_t), intent(in) :: design
215 type(simulation_t), optional, intent(inout) :: simulation
216
217 call this%free()
218
219 this%n_design = design%size()
220
221 ! Read the objectives and constraints
222 call this%read_objectives(parameters, design, simulation)
223 call this%read_constraints(parameters, design, simulation)
224
225 end subroutine problem_init
226
228 subroutine problem_free(this)
229 class(problem_t), intent(inout) :: this
230 integer :: i
231
232 this%n_design = 0
233 this%n_objectives = 0
234 this%n_constraints = 0
235
236 ! Free the objective list
237 if (allocated(this%objective_list)) then
238 do i = 1, size(this%objective_list)
239 call this%objective_list(i)%free()
240 end do
241 deallocate(this%objective_list)
242 end if
243
244 ! Free the constraint list
245 if (allocated(this%constraint_list)) then
246 do i = 1, size(this%constraint_list)
247 call this%constraint_list(i)%free()
248 end do
249 deallocate(this%constraint_list)
250 end if
251 end subroutine problem_free
252
254 subroutine problem_write(this, idx)
255 class(problem_t), intent(inout) :: this
256 integer, intent(in) :: idx
257
258 end subroutine problem_write
259
264 subroutine problem_get_log_values(this, values, include_constraints)
265 class(problem_t), intent(in) :: this
266 real(kind=rp), intent(out) :: values(:)
267 logical, intent(in), optional :: include_constraints
268 integer :: i, n, offset
269 real(kind=rp) :: objective_value
270 real(kind=rp), allocatable :: tmp(:)
271 logical :: do_constraints
272
273 if (present(include_constraints)) then
274 do_constraints = include_constraints
275 else
276 do_constraints = .true.
277 end if
278
279 call this%get_objective_value(objective_value)
280 values = 0.0_rp
281 values(1) = objective_value
282
283 offset = 2
284 do i = 1, this%n_objectives
285 n = this%objective_list(i)%objective%get_log_size()
286 if (n .gt. 0) then
287 allocate(tmp(n))
288 call this%objective_list(i)%objective%get_log_values(tmp)
289 values(offset:offset + n - 1) = tmp
290 offset = offset + n
291 deallocate(tmp)
292 end if
293 end do
294
295 if (do_constraints) then
296 do i = 1, this%n_constraints
297 n = this%constraint_list(i)%constraint%get_log_size()
298 if (n .gt. 0) then
299 allocate(tmp(n))
300 call this%constraint_list(i)%constraint%get_log_values(tmp)
301 values(offset:offset + n - 1) = tmp
302 offset = offset + n
303 deallocate(tmp)
304 end if
305 end do
306 end if
307 end subroutine problem_get_log_values
308
309 ! ========================================================================== !
310 ! Handling constraints and objectives
311
313 subroutine problem_read_objectives(this, parameters, design, simulation)
314 class(problem_t), intent(inout) :: this
315 type(json_file), intent(inout) :: parameters
316 class(design_t), intent(in) :: design
317 type(simulation_t), optional, intent(inout) :: simulation
318 class(objective_t), allocatable :: objective
319
320 ! A single objective term as its own json_file.
321 character(len=:), allocatable :: path, type
322 type(json_file) :: objective_json
323 integer :: n_objectives, i
324 logical :: dealias
325
326 call neko_log%section("Reading objectives")
327
328 ! Get the number of objectives.
329 path = "optimization.objectives"
330 if (parameters%valid_path(path)) then
331 call parameters%info(path, n_children = n_objectives)
332
333 ! Grab a single parameters entry and create a constraint from it.
334 do i = 1, n_objectives
335 call json_extract_item(parameters, path, i, objective_json)
336 call json_get(objective_json, "type", type)
337 call neko_log%message(type)
338
339 call objective_factory(objective, objective_json, design, simulation)
340 call this%add_objective(objective)
341 end do
342 end if
343
344 if (present(simulation)) then
345 if (allocated(objective)) deallocate(objective)
347 select type (alo => objective)
349 call json_get_or_default(parameters, &
350 "adjoint_fluid.dealias_sensitivity", dealias, .true.)
351 call alo%init_from_attributes(design, simulation, weight = 1.0_rp, &
352 name = "Augmented Lagrangian", mask_name = "", &
353 dealias = dealias)
354 end select
355 call this%add_objective(objective)
356 end if
357
358 call neko_log%end_section()
359
360 end subroutine problem_read_objectives
361
363 subroutine problem_read_constraints(this, parameters, design, simulation)
364 class(problem_t), intent(inout) :: this
365 type(json_file), intent(inout) :: parameters
366 class(design_t), intent(in) :: design
367 class(constraint_t), allocatable :: constraint
368 type(simulation_t), optional, intent(inout) :: simulation
369
370 ! A single constraint term as its own json_file.
371 character(len=:), allocatable :: path, type
372 type(json_file) :: constraint_json
373 integer :: n_constraints, i
374
375 call neko_log%section("Reading constraints")
376
377 ! Get the number of constraints.
378 path = "optimization.constraints"
379
380 if (parameters%valid_path(path)) then
381 call parameters%info(path, n_children = n_constraints)
382
383 ! Grab a single parameters entry and create a constraint from it.
384 do i = 1, n_constraints
385 call json_extract_item(parameters, path, i, constraint_json)
386 call json_get(constraint_json, "type", type)
387 call neko_log%message(type)
388
389 call constraint_factory(constraint, constraint_json, design, &
390 simulation)
391 call this%add_constraint(constraint)
392 end do
393 end if
394
395 call neko_log%end_section()
396
397 end subroutine problem_read_constraints
398
400 subroutine problem_add_objective(this, objective)
401 class(problem_t), intent(inout) :: this
402 class(objective_t), allocatable, intent(inout) :: objective
403 class(objective_wrapper_t), allocatable, dimension(:) :: temp_list
404 integer :: i, n
405
406 n = 0
407 if (allocated(this%objective_list)) then
408 n = size(this%objective_list)
409 call move_alloc(this%objective_list, temp_list)
410 allocate(this%objective_list(n + 1))
411 if (allocated(temp_list)) then
412 do i = 1, n
413 call move_alloc(temp_list(i)%objective, &
414 this%objective_list(i)%objective)
415 end do
416 end if
417 else
418 allocate(this%objective_list(1))
419 end if
420
421 call move_alloc(objective, this%objective_list(n + 1)%objective)
422 this%n_objectives = n + 1
423 end subroutine problem_add_objective
424
426 subroutine problem_add_constraint(this, constraint)
427 class(problem_t), intent(inout) :: this
428 class(constraint_t), allocatable, intent(inout) :: constraint
429 class(constraint_wrapper_t), allocatable, dimension(:) :: temp_list
430 integer :: i, n
431
432 n = 0
433 if (allocated(this%constraint_list)) then
434 n = size(this%constraint_list)
435 call move_alloc(this%constraint_list, temp_list)
436 allocate(this%constraint_list(n + 1))
437 if (allocated(temp_list)) then
438 do i = 1, n
439 call move_alloc(temp_list(i)%constraint, &
440 this%constraint_list(i)%constraint)
441 end do
442 end if
443 else
444 allocate(this%constraint_list(1))
445 end if
446
447 call move_alloc(constraint, this%constraint_list(n + 1)%constraint)
448 this%n_constraints = n + 1
449 end subroutine problem_add_constraint
450
451 ! ========================================================================== !
452 ! Problem part computation
453
455 subroutine problem_compute(this, design, simulation)
456 class(problem_t), intent(inout) :: this
457 class(design_t), intent(inout) :: design
458 class(simulation_t), optional, intent(inout) :: simulation
459
460 if (present(simulation)) then
461 call simulation%reset()
462 if (simulation%unsteady) then
463 ! Objective value accumulated
464 call this%run_forward_unsteady(simulation, design)
465 else
466 call simulation%run_forward()
467 ! Compute objective value on steady field
468 call this%update_objectives(design)
469 end if
470 else
471 call this%update_objectives(design)
472 end if
473
474 call this%update_constraints(design)
475
476 end subroutine problem_compute
477
479 subroutine problem_compute_sensitivity(this, design, simulation)
480 class(problem_t), intent(inout) :: this
481 class(design_t), intent(inout) :: design
482 class(simulation_t), optional, intent(inout) :: simulation
483
484 type(vector_t) :: objective_sensitivity
485
486 if (present(simulation)) then
487 if (simulation%unsteady) then
488 ! Objective sensitivity accumulated
489 call this%run_backward_unsteady(simulation, design)
490 else
491 call simulation%run_backward()
492 ! Compute sensitivity on steady field
493 call this%update_objective_sensitivities(design)
494 end if
495 else
496 call this%update_objective_sensitivities(design)
497 end if
498
499 call this%update_constraint_sensitivities(design)
500
501 call objective_sensitivity%init(this%n_design)
502 call this%get_objective_sensitivities(objective_sensitivity)
503
504 call design%map_backward(objective_sensitivity)
505
506 call objective_sensitivity%free()
507 end subroutine problem_compute_sensitivity
508
510 subroutine problem_run_forward_unsteady(this, simulation, design)
511 class(problem_t), intent(inout) :: this
512 class(simulation_t), intent(inout) :: simulation
513 class(design_t), intent(inout) :: design
514 type(time_step_controller_t) :: dt_controller
515 real(kind=dp) :: loop_start
516
517 call dt_controller%init(simulation%neko_case%params)
518
519 call simulation%reset()
520 call simulation_init(simulation%neko_case, dt_controller)
521
522 ! Reset the objective value to zero
523 call this%reset_objectives()
524
525 if (.not. allocated(simulation%state_recover)) then
526 call neko_error("State recovery not initialized.")
527 end if
528
529 call profiler_start_region("Forward simulation")
530 loop_start = mpi_wtime()
531 simulation%n_timesteps = 0
532 do while (simulation%neko_case%time%t .lt. &
533 simulation%neko_case%time%end_time)
534 simulation%n_timesteps = simulation%n_timesteps + 1
535 ! step forward
536 call simulation_step(simulation%neko_case, dt_controller, loop_start)
537 ! accumulate objective value
538 call this%accumulate_objectives(design, simulation%neko_case%time)
539 ! save a checkpoint
540 call simulation%state_recover%save()
541 end do
542 call profiler_end_region("Forward simulation")
543
544 call simulation_finalize(simulation%neko_case)
545
546 end subroutine problem_run_forward_unsteady
547
549 subroutine problem_run_backward_unsteady(this, simulation, design)
550 class(problem_t), intent(inout) :: this
551 class(simulation_t), intent(inout) :: simulation
552 class(design_t), intent(inout) :: design
553 type(time_step_controller_t) :: dt_controller
554 real(kind=dp) :: loop_start
555 real(kind=rp) :: cfl
556 real(kind=rp) :: total_time
557 integer :: i
558 type(time_state_t) :: accumulation_time
559
560 call dt_controller%init(simulation%neko_case%params)
561
562 call simulation_adjoint_init(simulation%adjoint_case, dt_controller)
563
564 ! Reset the sensitivity value to zero
565 call this%reset_objective_sensitivities()
566
567 cfl = simulation%adjoint_case%fluid_adj%compute_cfl( &
568 simulation%adjoint_case%time%dt)
569 loop_start = mpi_wtime()
570
571 if (.not. allocated(simulation%state_recover)) then
572 call neko_error("State recovery not initialized.")
573 end if
574
575 ! Total time of the forward simulation
576 total_time = simulation%n_timesteps * simulation%adjoint_case%time%dt
577
578 call profiler_start_region("Adjoint simulation")
579
580 do i = simulation%n_timesteps, 1, -1
581 ! restore primal field
582 call simulation%state_recover%restore(i)
583 ! accumulate objective sensitivity
584 accumulation_time = simulation%adjoint_case%time
585 accumulation_time%t = total_time - simulation%adjoint_case%time%t
586 call this%accumulate_objective_sensitivities(design, accumulation_time)
587 ! step the adjoint backwards
588 call simulation_adjoint_step(simulation%adjoint_case, dt_controller, &
589 cfl, loop_start, total_time)
590 end do
591
592 call profiler_end_region("Adjoint simulation")
593
594 call simulation_adjoint_finalize(simulation%adjoint_case)
595
596 end subroutine problem_run_backward_unsteady
597
598 ! ========================================================================== !
599 ! Update the objectives and constraints
600
607 subroutine problem_update_objectives(this, design)
608 class(problem_t), intent(inout) :: this
609 class(design_t), intent(in) :: design
610 integer :: i
611
612 do i = 1, this%n_objectives
613 call this%objective_list(i)%objective%update_value(design)
614 end do
615 end subroutine problem_update_objectives
616
623 subroutine problem_update_constraints(this, design)
624 class(problem_t), intent(inout) :: this
625 class(design_t), intent(in) :: design
626 integer :: i
627
628 do i = 1, this%n_constraints
629 call this%constraint_list(i)%constraint%update_value(design)
630 end do
631 end subroutine problem_update_constraints
632
639 subroutine problem_update_objective_sensitivities(this, design)
640 class(problem_t), intent(inout) :: this
641 class(design_t), intent(in) :: design
642 integer :: i
643
644 do i = 1, this%n_objectives
645 call this%objective_list(i)%objective%update_sensitivity(design)
646 end do
647 end subroutine problem_update_objective_sensitivities
648
655 subroutine problem_update_constraint_sensitivities(this, design)
656 class(problem_t), intent(inout) :: this
657 class(design_t), intent(in) :: design
658 integer :: i
659
660 do i = 1, this%n_constraints
661 call this%constraint_list(i)%constraint%update_sensitivity(design)
662 end do
663 end subroutine problem_update_constraint_sensitivities
664
665 ! ========================================================================== !
666 ! Reset the objectives and constraints
667
672 subroutine problem_reset_objectives(this)
673 class(problem_t), intent(inout) :: this
674 integer :: i
675
676 do i = 1, this%n_objectives
677 call this%objective_list(i)%objective%reset_value()
678 end do
679 end subroutine problem_reset_objectives
680
685 subroutine problem_reset_constraints(this)
686 class(problem_t), intent(inout) :: this
687 integer :: i
688
689 do i = 1, this%n_constraints
690 call this%constraint_list(i)%constraint%reset_value()
691 end do
692 end subroutine problem_reset_constraints
693
698 subroutine problem_reset_objective_sensitivities(this)
699 class(problem_t), intent(inout) :: this
700 integer :: i
701
702 do i = 1, this%n_objectives
703 call this%objective_list(i)%objective%reset_sensitivity()
704 end do
705 end subroutine problem_reset_objective_sensitivities
706
711 subroutine problem_reset_constraint_sensitivities(this)
712 class(problem_t), intent(inout) :: this
713 integer :: i
714
715 do i = 1, this%n_constraints
716 call this%constraint_list(i)%constraint%reset_sensitivity()
717 end do
718 end subroutine problem_reset_constraint_sensitivities
719
720 ! ========================================================================== !
721 ! Accumulate the objectives and constraints
722
729 subroutine problem_accumulate_objectives(this, design, time)
730 class(problem_t), intent(inout) :: this
731 class(design_t), intent(in) :: design
732 type(time_state_t), intent(in) :: time
733 integer :: i
734
735 do i = 1, this%n_objectives
736 call this%objective_list(i)%objective%accumulate_value(design, time)
737 end do
738 end subroutine problem_accumulate_objectives
739
746 subroutine problem_accumulate_constraints(this, design, time)
747 class(problem_t), intent(inout) :: this
748 class(design_t), intent(in) :: design
749 type(time_state_t), intent(in) :: time
750 integer :: i
751
752 do i = 1, this%n_constraints
753 call this%constraint_list(i)%constraint%accumulate_value(design, time)
754 end do
755 end subroutine problem_accumulate_constraints
756
763 subroutine problem_accumulate_objective_sensitivities(this, design, time)
764 class(problem_t), intent(inout) :: this
765 class(design_t), intent(in) :: design
766 type(time_state_t), intent(in) :: time
767 integer :: i
768
769 do i = 1, this%n_objectives
770 call this%objective_list(i)%objective%accumulate_sensitivity(design, &
771 time)
772 end do
773 end subroutine problem_accumulate_objective_sensitivities
774
781 subroutine problem_accumulate_constraint_sensitivities(this, design, time)
782 class(problem_t), intent(inout) :: this
783 class(design_t), intent(in) :: design
784 type(time_state_t), intent(in) :: time
785 integer :: i
786
787 do i = 1, this%n_constraints
788 call this%constraint_list(i)%constraint%accumulate_sensitivity(design, &
789 time)
790 end do
791 end subroutine problem_accumulate_constraint_sensitivities
792
793 ! ========================================================================== !
794 ! Problem part getters
795
802 subroutine problem_get_objective_value(this, objective_value)
803 class(problem_t), intent(in) :: this
804 real(kind=rp), intent(out) :: objective_value
805 integer :: i
806
807 objective_value = 0.0_rp
808 do i = 1, this%n_objectives
809 objective_value = objective_value + &
810 this%objective_list(i)%objective%get_weight() * &
811 this%objective_list(i)%objective%get_value()
812 end do
813
814 end subroutine problem_get_objective_value
815
822 subroutine problem_get_all_objective_values(this, all_objective_values)
823 class(problem_t), intent(in) :: this
824 type(vector_t), intent(inout) :: all_objective_values
825 integer :: i
826
827 do i = 1, this%n_objectives
828 all_objective_values%x(i) = this%objective_list(i)%objective%value
829 end do
830
831 call all_objective_values%copy_from(host_to_device, sync = .true.)
832
833 end subroutine problem_get_all_objective_values
834
841 subroutine problem_get_constraint_values(this, constraint_value)
842 class(problem_t), intent(in) :: this
843 type(vector_t), intent(inout) :: constraint_value
844 integer :: i
845
846 do i = 1, this%n_constraints
847 constraint_value%x(i) = this%constraint_list(i)%constraint%value
848 end do
849
850 call constraint_value%copy_from(host_to_device, sync = .true.)
851
852 end subroutine problem_get_constraint_values
853
860 subroutine problem_get_objective_sensitivities(this, sensitivity)
861 class(problem_t), intent(in) :: this
862 type(vector_t), intent(inout) :: sensitivity
863 integer :: i
864
865 call vector_cfill(sensitivity, 0.0_rp)
866 do i = 1, this%n_objectives
867 call vector_add2(sensitivity, &
868 this%objective_list(i)%objective%sensitivity)
869 end do
870
871 end subroutine problem_get_objective_sensitivities
872
879 subroutine problem_get_constraint_sensitivities(this, sensitivity)
880 class(problem_t), intent(inout) :: this
881 type(matrix_t), target, intent(inout) :: sensitivity
882 real(kind=rp), pointer :: row(:)
883 integer :: i
884
885 ! Copy all constraint sensitivities to host, sync on last one
886 do i = 1, this%n_constraints
887 call this%constraint_list(i)%constraint%sensitivity%copy_from( &
888 device_to_host, sync = i .eq. this%n_constraints)
889 end do
890
891 do i = 1, this%n_constraints
892 row(1:this%n_design) => sensitivity%x(i, :)
893
894 call copy(row, this%constraint_list(i)%constraint%sensitivity%x, &
895 this%n_design)
896 end do
897
898 call sensitivity%copy_from(host_to_device, sync = .true.)
899
900 end subroutine problem_get_constraint_sensitivities
901
902 ! ========================================================================== !
903 ! Simple getters
904
906 pure function problem_get_num_objectives(this) result(n)
907 class(problem_t), intent(in) :: this
908 integer :: n
909
910 n = this%n_objectives
911 end function problem_get_num_objectives
912
914 pure function problem_get_num_constraints(this) result(n)
915 class(problem_t), intent(in) :: this
916 integer :: n
917
918 n = this%n_constraints
919 end function problem_get_num_constraints
920
925 function problem_get_log_header(this, include_constraints) result(buff)
926 class(problem_t), intent(in) :: this
927 logical, intent(in), optional :: include_constraints
928 character(len=4096) :: buff
929 character(len=128) :: mini_buff
930 character(len=128), allocatable :: headers(:)
931 integer :: i, j, n
932 logical :: do_constraints
933
934 buff = "Total objective function"
935 if (present(include_constraints)) then
936 do_constraints = include_constraints
937 else
938 do_constraints = .true.
939 end if
940
941 do i = 1, this%get_n_objectives()
942 n = this%objective_list(i)%objective%get_log_size()
943 if (n .gt. 0) then
944 allocate(headers(n))
945 call this%objective_list(i)%objective%get_log_headers(headers)
946 do j = 1, n
947 mini_buff = ""
948 write(mini_buff, '(", ", A)') trim(headers(j))
949 buff = trim(buff) // trim(mini_buff)
950 end do
951 deallocate(headers)
952 end if
953 end do
954
955 if (do_constraints) then
956 do i = 1, this%get_n_constraints()
957 n = this%constraint_list(i)%constraint%get_log_size()
958 if (n .gt. 0) then
959 allocate(headers(n))
960 call this%constraint_list(i)%constraint%get_log_headers(headers)
961 do j = 1, n
962 mini_buff = ""
963 write(mini_buff, '(", ", A)') trim(headers(j))
964 buff = trim(buff) // trim(mini_buff)
965 end do
966 deallocate(headers)
967 end if
968 end do
969 end if
970
971 end function problem_get_log_header
972
977 function problem_get_log_size(this, include_constraints) result(n)
978 class(problem_t), intent(in) :: this
979 logical, intent(in), optional :: include_constraints
980 integer :: n, i
981 logical :: do_constraints
982
983 n = 1
984 if (present(include_constraints)) then
985 do_constraints = include_constraints
986 else
987 do_constraints = .true.
988 end if
989 do i = 1, this%get_n_objectives()
990 n = n + this%objective_list(i)%objective%get_log_size()
991 end do
992
993 if (do_constraints) then
994 do i = 1, this%get_n_constraints()
995 n = n + this%constraint_list(i)%constraint%get_log_size()
996 end do
997 end if
998
999 end function problem_get_log_size
1000end module problem
Factory function Allocates and initializes an constraint function object.
Factory function Allocates and initializes an objective function object.
Definition objective.f90:89
Implements the augmented_lagrangian_objective_t type.
Implements the constraint_t type.
Implements the design_t.
Definition design.f90:36
Implements the objective_t type.
Definition objective.f90:36
Module for handling the optimization problem.
Definition problem.f90:41
subroutine problem_init(this, parameters, design, simulation)
The constructor for the base problem.
Definition problem.f90:212
Adjoint simulation driver.
subroutine, public simulation_adjoint_init(c, dt_controller)
Initialise a simulation_adjoint of a case.
subroutine, public simulation_adjoint_step(c, dt_controller, cfl, tstep_loop_start_time, final_time)
Compute a single time-step of an adjoint case.
subroutine, public simulation_adjoint_finalize(c)
Finalize a simulation of a case.
Implements the steady_problem_t type.
An objective function implementing our augmented lagrangian sensitivity contribution.
The abstract constraint type.
Wrapper for constraints for use in lists.
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
The abstract problem type.
Definition problem.f90:68