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, log_size
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
111 procedure, pass(this) :: check_objective_windows => &
112 problem_check_objective_windows
113 ! ----------------------------------------------------------------------- !
114 ! Base class methods
115
117 procedure, pass(this), public :: read_objectives => problem_read_objectives
119 procedure, pass(this), public :: read_constraints => &
120 problem_read_constraints
121
122 ! ----------------------------------------------------------------------- !
123 ! Actual methods
124
126 procedure, pass(this), public :: write => problem_write
128 procedure, pass(this), public :: get_log_values => problem_get_log_values
129
131 procedure, pass(this), public :: add_objective => problem_add_objective
133 procedure, pass(this), public :: add_constraint => problem_add_constraint
134
135 ! ----------------------------------------------------------------------- !
136 ! Internal Updater methods
137
139 procedure, pass(this) :: update_objectives => &
140 problem_update_objectives
142 procedure, pass(this) :: update_constraints => &
143 problem_update_constraints
145 procedure, pass(this) :: update_objective_sensitivities => &
146 problem_update_objective_sensitivities
148 procedure, pass(this) :: update_constraint_sensitivities => &
149 problem_update_constraint_sensitivities
150
152 procedure, pass(this) :: reset_objectives => &
153 problem_reset_objectives
155 procedure, pass(this) :: reset_constraints => &
156 problem_reset_constraints
158 procedure, pass(this) :: reset_objective_sensitivities => &
159 problem_reset_objective_sensitivities
161 procedure, pass(this) :: reset_constraint_sensitivities => &
162 problem_reset_constraint_sensitivities
163
165 procedure, pass(this) :: accumulate_objectives => &
166 problem_accumulate_objectives
168 procedure, pass(this) :: accumulate_constraints => &
169 problem_accumulate_constraints
171 procedure, pass(this) :: accumulate_objective_sensitivities => &
172 problem_accumulate_objective_sensitivities
174 procedure, pass(this) :: accumulate_constraint_sensitivities => &
175 problem_accumulate_constraint_sensitivities
176
177 ! ----------------------------------------------------------------------- !
178 ! Public Getters
179
181 procedure, pass(this), public :: get_objective_value => &
182 problem_get_objective_value
184 procedure, pass(this), public :: get_all_objective_values => &
185 problem_get_all_objective_values
187 procedure, pass(this), public :: get_constraint_values => &
188 problem_get_constraint_values
190 procedure, pass(this), public :: get_objective_sensitivities => &
191 problem_get_objective_sensitivities
193 procedure, pass(this), public :: get_constraint_sensitivities => &
194 problem_get_constraint_sensitivities
195
197 procedure, pass(this) :: get_n_objectives => problem_get_num_objectives
199 procedure, pass(this) :: get_n_constraints => problem_get_num_constraints
200
202 procedure, pass(this) :: get_log_header => problem_get_log_header
204 procedure, pass(this) :: get_log_size => problem_get_log_size
205
206 end type problem_t
207
208contains
209
210 ! ========================================================================== !
211 ! Base class methods
212
214 subroutine problem_init(this, parameters, design, simulation)
215 class(problem_t), intent(inout) :: this
216 type(json_file), intent(inout) :: parameters
217 class(design_t), intent(in) :: design
218 type(simulation_t), optional, intent(inout) :: simulation
219
220 call this%free()
221
222 this%n_design = design%size()
223
224 ! Read the objectives and constraints
225 call this%read_objectives(parameters, design, simulation)
226 call this%read_constraints(parameters, design, simulation)
227
228 end subroutine problem_init
229
231 subroutine problem_free(this)
232 class(problem_t), intent(inout) :: this
233 integer :: i
234
235 this%n_design = 0
236 this%n_objectives = 0
237 this%n_constraints = 0
238
239 ! Free the objective list
240 if (allocated(this%objective_list)) then
241 do i = 1, size(this%objective_list)
242 call this%objective_list(i)%free()
243 end do
244 deallocate(this%objective_list)
245 end if
246
247 ! Free the constraint list
248 if (allocated(this%constraint_list)) then
249 do i = 1, size(this%constraint_list)
250 call this%constraint_list(i)%free()
251 end do
252 deallocate(this%constraint_list)
253 end if
254 end subroutine problem_free
255
257 subroutine problem_write(this, idx)
258 class(problem_t), intent(inout) :: this
259 integer, intent(in) :: idx
260
261 end subroutine problem_write
262
267 subroutine problem_get_log_values(this, values, include_constraints)
268 class(problem_t), intent(in) :: this
269 real(kind=rp), intent(out) :: values(:)
270 logical, intent(in), optional :: include_constraints
271 integer :: i, n, offset
272 real(kind=rp) :: objective_value
273 real(kind=rp), allocatable :: tmp(:)
274 logical :: do_constraints
275
276 if (present(include_constraints)) then
277 do_constraints = include_constraints
278 else
279 do_constraints = .true.
280 end if
281
282 call this%get_objective_value(objective_value)
283 values = 0.0_rp
284 values(1) = objective_value
285
286 offset = 2
287 do i = 1, this%n_objectives
288 n = this%objective_list(i)%objective%get_log_size()
289 if (n .gt. 0) then
290 allocate(tmp(n))
291 call this%objective_list(i)%objective%get_log_values(tmp)
292 values(offset:offset + n - 1) = tmp
293 offset = offset + n
294 deallocate(tmp)
295 end if
296 end do
297
298 if (do_constraints) then
299 do i = 1, this%n_constraints
300 n = this%constraint_list(i)%constraint%get_log_size()
301 if (n .gt. 0) then
302 allocate(tmp(n))
303 call this%constraint_list(i)%constraint%get_log_values(tmp)
304 values(offset:offset + n - 1) = tmp
305 offset = offset + n
306 deallocate(tmp)
307 end if
308 end do
309 end if
310 end subroutine problem_get_log_values
311
312 ! ========================================================================== !
313 ! Handling constraints and objectives
314
316 subroutine problem_read_objectives(this, parameters, design, simulation)
317 class(problem_t), intent(inout) :: this
318 type(json_file), intent(inout) :: parameters
319 class(design_t), intent(in) :: design
320 type(simulation_t), optional, intent(inout) :: simulation
321 class(objective_t), allocatable :: objective
322
323 ! A single objective term as its own json_file.
324 character(len=:), allocatable :: path, type
325 type(json_file) :: objective_json
326 integer :: n_objectives, i
327 logical :: dealias
328
329 call neko_log%section("Reading objectives")
330
331 ! Get the number of objectives.
332 path = "optimization.objectives"
333 if (parameters%valid_path(path)) then
334 call parameters%info(path, n_children = n_objectives)
335
336 ! Grab a single parameters entry and create a constraint from it.
337 do i = 1, n_objectives
338 call json_extract_item(parameters, path, i, objective_json)
339 call json_get(objective_json, "type", type)
340 call neko_log%message(type)
341
342 call objective_factory(objective, objective_json, design, simulation)
343 call this%add_objective(objective)
344 end do
345 end if
346
347 if (present(simulation)) then
348 if (allocated(objective)) deallocate(objective)
350 select type (alo => objective)
352 call json_get_or_default(parameters, &
353 "adjoint_fluid.dealias_sensitivity", dealias, .true.)
354 call alo%init_from_attributes(design, simulation, weight = 1.0_rp, &
355 name = "Augmented Lagrangian", mask_name = "", &
356 dealias = dealias)
357 end select
358 call this%add_objective(objective)
359 end if
360
361 call neko_log%end_section()
362
363 end subroutine problem_read_objectives
364
366 subroutine problem_read_constraints(this, parameters, design, simulation)
367 class(problem_t), intent(inout) :: this
368 type(json_file), intent(inout) :: parameters
369 class(design_t), intent(in) :: design
370 class(constraint_t), allocatable :: constraint
371 type(simulation_t), optional, intent(inout) :: simulation
372
373 ! A single constraint term as its own json_file.
374 character(len=:), allocatable :: path, type
375 type(json_file) :: constraint_json
376 integer :: n_constraints, i
377
378 call neko_log%section("Reading constraints")
379
380 ! Get the number of constraints.
381 path = "optimization.constraints"
382
383 if (parameters%valid_path(path)) then
384 call parameters%info(path, n_children = n_constraints)
385
386 ! Grab a single parameters entry and create a constraint from it.
387 do i = 1, n_constraints
388 call json_extract_item(parameters, path, i, constraint_json)
389 call json_get(constraint_json, "type", type)
390 call neko_log%message(type)
391
392 call constraint_factory(constraint, constraint_json, design, &
393 simulation)
394 call this%add_constraint(constraint)
395 end do
396 end if
397
398 call neko_log%end_section()
399
400 end subroutine problem_read_constraints
401
403 subroutine problem_add_objective(this, objective)
404 class(problem_t), intent(inout) :: this
405 class(objective_t), allocatable, intent(inout) :: objective
406 class(objective_wrapper_t), allocatable, dimension(:) :: temp_list
407 integer :: i, n
408
409 n = 0
410 if (allocated(this%objective_list)) then
411 n = size(this%objective_list)
412 call move_alloc(this%objective_list, temp_list)
413 allocate(this%objective_list(n + 1))
414 if (allocated(temp_list)) then
415 do i = 1, n
416 call move_alloc(temp_list(i)%objective, &
417 this%objective_list(i)%objective)
418 end do
419 end if
420 else
421 allocate(this%objective_list(1))
422 end if
423
424 call move_alloc(objective, this%objective_list(n + 1)%objective)
425 this%n_objectives = n + 1
426 end subroutine problem_add_objective
427
429 subroutine problem_add_constraint(this, constraint)
430 class(problem_t), intent(inout) :: this
431 class(constraint_t), allocatable, intent(inout) :: constraint
432 class(constraint_wrapper_t), allocatable, dimension(:) :: temp_list
433 integer :: i, n
434
435 n = 0
436 if (allocated(this%constraint_list)) then
437 n = size(this%constraint_list)
438 call move_alloc(this%constraint_list, temp_list)
439 allocate(this%constraint_list(n + 1))
440 if (allocated(temp_list)) then
441 do i = 1, n
442 call move_alloc(temp_list(i)%constraint, &
443 this%constraint_list(i)%constraint)
444 end do
445 end if
446 else
447 allocate(this%constraint_list(1))
448 end if
449
450 call move_alloc(constraint, this%constraint_list(n + 1)%constraint)
451 this%n_constraints = n + 1
452 end subroutine problem_add_constraint
453
454 ! ========================================================================== !
455 ! Problem part computation
456
458 subroutine problem_compute(this, design, simulation)
459 class(problem_t), intent(inout) :: this
460 class(design_t), intent(inout) :: design
461 class(simulation_t), optional, intent(inout) :: simulation
462
463 if (present(simulation)) then
464 call simulation%reset()
465 if (simulation%unsteady) then
466 ! Objective value accumulated
467 call this%run_forward_unsteady(simulation, design)
468 else
469 call simulation%run_forward()
470 ! Compute objective value on steady field
471 call this%update_objectives(design)
472 end if
473 else
474 call this%update_objectives(design)
475 end if
476
477 call this%update_constraints(design)
478
479 end subroutine problem_compute
480
482 subroutine problem_compute_sensitivity(this, design, simulation)
483 class(problem_t), intent(inout) :: this
484 class(design_t), intent(inout) :: design
485 class(simulation_t), optional, intent(inout) :: simulation
486
487 type(vector_t) :: objective_sensitivity
488
489 if (present(simulation)) then
490 if (simulation%unsteady) then
491 ! Objective sensitivity accumulated
492 call this%run_backward_unsteady(simulation, design)
493 else
494 call simulation%run_backward()
495 ! Compute sensitivity on steady field
496 call this%update_objective_sensitivities(design)
497 end if
498 else
499 call this%update_objective_sensitivities(design)
500 end if
501
502 call this%update_constraint_sensitivities(design)
503
504 call objective_sensitivity%init(this%n_design)
505 call this%get_objective_sensitivities(objective_sensitivity)
506
507 call design%map_backward(objective_sensitivity)
508
509 call objective_sensitivity%free()
510 end subroutine problem_compute_sensitivity
511
513 subroutine problem_run_forward_unsteady(this, simulation, design)
514 class(problem_t), intent(inout) :: this
515 class(simulation_t), intent(inout) :: simulation
516 class(design_t), intent(inout) :: design
517 type(time_step_controller_t) :: dt_controller
518 real(kind=dp) :: loop_start
519
520 call dt_controller%init(simulation%neko_case%params)
521
522 call simulation%reset()
523 call simulation_init(simulation%neko_case, dt_controller)
524
525 ! Reset the objective value to zero
526 call this%reset_objectives()
527
528 if (.not. allocated(simulation%state_recover)) then
529 call neko_error("State recovery not initialized.")
530 end if
531
532 call profiler_start_region("Forward simulation")
533 loop_start = mpi_wtime()
534 simulation%n_timesteps = 0
535 do while (simulation%neko_case%time%t .lt. &
536 simulation%neko_case%time%end_time)
537 simulation%n_timesteps = simulation%n_timesteps + 1
538 ! step forward
539 call simulation_step(simulation%neko_case, dt_controller, loop_start)
540 ! accumulate objective value
541 call this%accumulate_objectives(design, simulation%neko_case%time)
542 ! save a checkpoint
543 call simulation%state_recover%save()
544 end do
545 call profiler_end_region("Forward simulation")
546
547 call this%check_objective_windows()
548
549 call simulation_finalize(simulation%neko_case)
550
551 end subroutine problem_run_forward_unsteady
552
558 subroutine problem_check_objective_windows(this)
559 class(problem_t), intent(inout) :: this
560 character(len=LOG_SIZE) :: log_buf
561 integer :: i
562
563 do i = 1, this%n_objectives
564 if (this%objective_list(i)%objective%value_weight .gt. 0.0_rp) cycle
565
566 write (log_buf, '(A,A,A)') "Objective '", &
567 trim(this%objective_list(i)%objective%name), &
568 "' was never sampled; its time window misses the run."
569 call neko_log%warning(trim(log_buf))
570 end do
571 end subroutine problem_check_objective_windows
572
574 subroutine problem_run_backward_unsteady(this, simulation, design)
575 class(problem_t), intent(inout) :: this
576 class(simulation_t), intent(inout) :: simulation
577 class(design_t), intent(inout) :: design
578 type(time_step_controller_t) :: dt_controller
579 real(kind=dp) :: loop_start
580 real(kind=rp) :: cfl
581 real(kind=rp) :: total_time
582 integer :: i
583 type(time_state_t) :: accumulation_time
584
585 call dt_controller%init(simulation%neko_case%params)
586
587 call simulation_adjoint_init(simulation%adjoint_case, dt_controller)
588
589 ! Reset the sensitivity value to zero
590 call this%reset_objective_sensitivities()
591
592 cfl = simulation%adjoint_case%fluid_adj%compute_cfl( &
593 simulation%adjoint_case%time%dt)
594 loop_start = mpi_wtime()
595
596 if (.not. allocated(simulation%state_recover)) then
597 call neko_error("State recovery not initialized.")
598 end if
599
600 ! Total time of the forward simulation
601 total_time = simulation%n_timesteps * simulation%adjoint_case%time%dt
602
603 call profiler_start_region("Adjoint simulation")
604
605 do i = simulation%n_timesteps, 1, -1
606 ! restore primal field
607 call simulation%state_recover%restore(i)
608 ! accumulate objective sensitivity
609 accumulation_time = simulation%adjoint_case%time
610 accumulation_time%t = total_time - simulation%adjoint_case%time%t
611 call this%accumulate_objective_sensitivities(design, accumulation_time)
612 ! step the adjoint backwards
613 call simulation_adjoint_step(simulation%adjoint_case, dt_controller, &
614 cfl, loop_start, total_time)
615 end do
616
617 call profiler_end_region("Adjoint simulation")
618
619 call simulation_adjoint_finalize(simulation%adjoint_case)
620
621 end subroutine problem_run_backward_unsteady
622
623 ! ========================================================================== !
624 ! Update the objectives and constraints
625
632 subroutine problem_update_objectives(this, design)
633 class(problem_t), intent(inout) :: this
634 class(design_t), intent(in) :: design
635 integer :: i
636
637 do i = 1, this%n_objectives
638 call this%objective_list(i)%objective%update_value(design)
639 end do
640 end subroutine problem_update_objectives
641
648 subroutine problem_update_constraints(this, design)
649 class(problem_t), intent(inout) :: this
650 class(design_t), intent(in) :: design
651 integer :: i
652
653 do i = 1, this%n_constraints
654 call this%constraint_list(i)%constraint%update_value(design)
655 end do
656 end subroutine problem_update_constraints
657
664 subroutine problem_update_objective_sensitivities(this, design)
665 class(problem_t), intent(inout) :: this
666 class(design_t), intent(in) :: design
667 integer :: i
668
669 do i = 1, this%n_objectives
670 call this%objective_list(i)%objective%update_sensitivity(design)
671 end do
672 end subroutine problem_update_objective_sensitivities
673
680 subroutine problem_update_constraint_sensitivities(this, design)
681 class(problem_t), intent(inout) :: this
682 class(design_t), intent(in) :: design
683 integer :: i
684
685 do i = 1, this%n_constraints
686 call this%constraint_list(i)%constraint%update_sensitivity(design)
687 end do
688 end subroutine problem_update_constraint_sensitivities
689
690 ! ========================================================================== !
691 ! Reset the objectives and constraints
692
697 subroutine problem_reset_objectives(this)
698 class(problem_t), intent(inout) :: this
699 integer :: i
700
701 do i = 1, this%n_objectives
702 call this%objective_list(i)%objective%reset_value()
703 end do
704 end subroutine problem_reset_objectives
705
710 subroutine problem_reset_constraints(this)
711 class(problem_t), intent(inout) :: this
712 integer :: i
713
714 do i = 1, this%n_constraints
715 call this%constraint_list(i)%constraint%reset_value()
716 end do
717 end subroutine problem_reset_constraints
718
723 subroutine problem_reset_objective_sensitivities(this)
724 class(problem_t), intent(inout) :: this
725 integer :: i
726
727 do i = 1, this%n_objectives
728 call this%objective_list(i)%objective%reset_sensitivity()
729 end do
730 end subroutine problem_reset_objective_sensitivities
731
736 subroutine problem_reset_constraint_sensitivities(this)
737 class(problem_t), intent(inout) :: this
738 integer :: i
739
740 do i = 1, this%n_constraints
741 call this%constraint_list(i)%constraint%reset_sensitivity()
742 end do
743 end subroutine problem_reset_constraint_sensitivities
744
745 ! ========================================================================== !
746 ! Accumulate the objectives and constraints
747
754 subroutine problem_accumulate_objectives(this, design, time)
755 class(problem_t), intent(inout) :: this
756 class(design_t), intent(in) :: design
757 type(time_state_t), intent(in) :: time
758 integer :: i
759
760 do i = 1, this%n_objectives
761 call this%objective_list(i)%objective%accumulate_value(design, time)
762 end do
763 end subroutine problem_accumulate_objectives
764
771 subroutine problem_accumulate_constraints(this, design, time)
772 class(problem_t), intent(inout) :: this
773 class(design_t), intent(in) :: design
774 type(time_state_t), intent(in) :: time
775 integer :: i
776
777 do i = 1, this%n_constraints
778 call this%constraint_list(i)%constraint%accumulate_value(design, time)
779 end do
780 end subroutine problem_accumulate_constraints
781
788 subroutine problem_accumulate_objective_sensitivities(this, design, time)
789 class(problem_t), intent(inout) :: this
790 class(design_t), intent(in) :: design
791 type(time_state_t), intent(in) :: time
792 integer :: i
793
794 do i = 1, this%n_objectives
795 call this%objective_list(i)%objective%accumulate_sensitivity(design, &
796 time)
797 end do
798 end subroutine problem_accumulate_objective_sensitivities
799
806 subroutine problem_accumulate_constraint_sensitivities(this, design, time)
807 class(problem_t), intent(inout) :: this
808 class(design_t), intent(in) :: design
809 type(time_state_t), intent(in) :: time
810 integer :: i
811
812 do i = 1, this%n_constraints
813 call this%constraint_list(i)%constraint%accumulate_sensitivity(design, &
814 time)
815 end do
816 end subroutine problem_accumulate_constraint_sensitivities
817
818 ! ========================================================================== !
819 ! Problem part getters
820
827 subroutine problem_get_objective_value(this, objective_value)
828 class(problem_t), intent(in) :: this
829 real(kind=rp), intent(out) :: objective_value
830 integer :: i
831
832 objective_value = 0.0_rp
833 do i = 1, this%n_objectives
834 objective_value = objective_value + &
835 this%objective_list(i)%objective%get_weight() * &
836 this%objective_list(i)%objective%get_value()
837 end do
838
839 end subroutine problem_get_objective_value
840
847 subroutine problem_get_all_objective_values(this, all_objective_values)
848 class(problem_t), intent(in) :: this
849 type(vector_t), intent(inout) :: all_objective_values
850 integer :: i
851
852 do i = 1, this%n_objectives
853 all_objective_values%x(i) = this%objective_list(i)%objective%value
854 end do
855
856 call all_objective_values%copy_from(host_to_device, sync = .true.)
857
858 end subroutine problem_get_all_objective_values
859
866 subroutine problem_get_constraint_values(this, constraint_value)
867 class(problem_t), intent(in) :: this
868 type(vector_t), intent(inout) :: constraint_value
869 integer :: i
870
871 do i = 1, this%n_constraints
872 constraint_value%x(i) = this%constraint_list(i)%constraint%value
873 end do
874
875 call constraint_value%copy_from(host_to_device, sync = .true.)
876
877 end subroutine problem_get_constraint_values
878
885 subroutine problem_get_objective_sensitivities(this, sensitivity)
886 class(problem_t), intent(in) :: this
887 type(vector_t), intent(inout) :: sensitivity
888 integer :: i
889
890 call vector_cfill(sensitivity, 0.0_rp)
891 do i = 1, this%n_objectives
892 call vector_add2(sensitivity, &
893 this%objective_list(i)%objective%sensitivity)
894 end do
895
896 end subroutine problem_get_objective_sensitivities
897
904 subroutine problem_get_constraint_sensitivities(this, sensitivity)
905 class(problem_t), intent(inout) :: this
906 type(matrix_t), target, intent(inout) :: sensitivity
907 real(kind=rp), pointer :: row(:)
908 integer :: i
909
910 ! Copy all constraint sensitivities to host, sync on last one
911 do i = 1, this%n_constraints
912 call this%constraint_list(i)%constraint%sensitivity%copy_from( &
913 device_to_host, sync = i .eq. this%n_constraints)
914 end do
915
916 do i = 1, this%n_constraints
917 row(1:this%n_design) => sensitivity%x(i, :)
918
919 call copy(row, this%constraint_list(i)%constraint%sensitivity%x, &
920 this%n_design)
921 end do
922
923 call sensitivity%copy_from(host_to_device, sync = .true.)
924
925 end subroutine problem_get_constraint_sensitivities
926
927 ! ========================================================================== !
928 ! Simple getters
929
931 pure function problem_get_num_objectives(this) result(n)
932 class(problem_t), intent(in) :: this
933 integer :: n
934
935 n = this%n_objectives
936 end function problem_get_num_objectives
937
939 pure function problem_get_num_constraints(this) result(n)
940 class(problem_t), intent(in) :: this
941 integer :: n
942
943 n = this%n_constraints
944 end function problem_get_num_constraints
945
950 function problem_get_log_header(this, include_constraints) result(buff)
951 class(problem_t), intent(in) :: this
952 logical, intent(in), optional :: include_constraints
953 character(len=4096) :: buff
954 character(len=128) :: mini_buff
955 character(len=128), allocatable :: headers(:)
956 integer :: i, j, n
957 logical :: do_constraints
958
959 buff = "Total objective function"
960 if (present(include_constraints)) then
961 do_constraints = include_constraints
962 else
963 do_constraints = .true.
964 end if
965
966 do i = 1, this%get_n_objectives()
967 n = this%objective_list(i)%objective%get_log_size()
968 if (n .gt. 0) then
969 allocate(headers(n))
970 call this%objective_list(i)%objective%get_log_headers(headers)
971 do j = 1, n
972 mini_buff = ""
973 write(mini_buff, '(", ", A)') trim(headers(j))
974 buff = trim(buff) // trim(mini_buff)
975 end do
976 deallocate(headers)
977 end if
978 end do
979
980 if (do_constraints) then
981 do i = 1, this%get_n_constraints()
982 n = this%constraint_list(i)%constraint%get_log_size()
983 if (n .gt. 0) then
984 allocate(headers(n))
985 call this%constraint_list(i)%constraint%get_log_headers(headers)
986 do j = 1, n
987 mini_buff = ""
988 write(mini_buff, '(", ", A)') trim(headers(j))
989 buff = trim(buff) // trim(mini_buff)
990 end do
991 deallocate(headers)
992 end if
993 end do
994 end if
995
996 end function problem_get_log_header
997
1002 function problem_get_log_size(this, include_constraints) result(n)
1003 class(problem_t), intent(in) :: this
1004 logical, intent(in), optional :: include_constraints
1005 integer :: n, i
1006 logical :: do_constraints
1007
1008 n = 1
1009 if (present(include_constraints)) then
1010 do_constraints = include_constraints
1011 else
1012 do_constraints = .true.
1013 end if
1014 do i = 1, this%get_n_objectives()
1015 n = n + this%objective_list(i)%objective%get_log_size()
1016 end do
1017
1018 if (do_constraints) then
1019 do i = 1, this%get_n_constraints()
1020 n = n + this%constraint_list(i)%constraint%get_log_size()
1021 end do
1022 end if
1023
1024 end function problem_get_log_size
1025end 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:215
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