42 use json_module,
only: json_file
46 use num_types,
only: rp
47 use logger,
only: neko_log
48 use profiler,
only: profiler_start_region, profiler_end_region
58 integer,
public :: max_iterations
60 real(kind=rp),
public :: tolerance
67 procedure, pass(this),
public :: run => optimizer_run
69 procedure(optimizer_initialize), pass(this),
public,
deferred :: &
72 procedure(optimizer_step), pass(this),
public,
deferred :: step
74 procedure(optimizer_free), pass(this),
public,
deferred :: free
77 procedure(optimizer_validate), pass(this),
public,
deferred :: validate
79 procedure(optimizer_write), pass(this),
public,
deferred :: write
82 procedure, pass(this) :: init_base => optimizer_init_base
84 procedure, pass(this) :: free_base => optimizer_free_base
96 class(optimizer_t),
intent(inout) :: this
97 type(json_file),
intent(inout) :: parameters
98 class(problem_t),
intent(inout) :: problem
99 class(design_t),
intent(in) :: design
100 type(simulation_t),
optional,
intent(in) :: simulation
106 subroutine optimizer_initialize(this, problem, design, simulation)
108 class(optimizer_t),
intent(inout) :: this
109 class(problem_t),
intent(inout) :: problem
110 class(design_t),
intent(inout) :: design
111 type(simulation_t),
optional,
intent(inout) :: simulation
112 end subroutine optimizer_initialize
115 logical function optimizer_step(this, iter, problem, design, simulation)
117 integer,
intent(in) :: iter
118 class(optimizer_t),
intent(inout) :: this
119 class(problem_t),
intent(inout) :: problem
120 class(design_t),
intent(inout) :: design
121 type(simulation_t),
optional,
intent(inout) :: simulation
122 end function optimizer_step
125 subroutine optimizer_write(this, iter, problem)
127 class(optimizer_t),
intent(inout) :: this
128 integer,
intent(in) :: iter
129 class(problem_t),
intent(in) :: problem
130 end subroutine optimizer_write
133 subroutine optimizer_free(this)
135 class(optimizer_t),
intent(inout) :: this
136 end subroutine optimizer_free
139 subroutine optimizer_validate(this, problem, design)
141 class(optimizer_t),
intent(inout) :: this
142 class(problem_t),
intent(in) :: problem
143 class(design_t),
intent(in) :: design
144 end subroutine optimizer_validate
157 module subroutine optimizer_factory(object, parameters,
problem,
design, &
159 class(optimizer_t),
allocatable,
intent(inout) :: object
160 type(json_file),
intent(inout) :: parameters
161 class(problem_t),
intent(inout) :: problem
162 class(design_t),
intent(in) :: design
163 type(simulation_t),
optional,
intent(in) :: simulation
164 end subroutine optimizer_factory
165 end interface optimizer_factory
167 public :: optimizer_t, optimizer_factory
178 subroutine optimizer_init_base(this, max_iterations, tolerance)
179 class(optimizer_t),
intent(inout) :: this
180 integer,
intent(in) :: max_iterations
181 real(kind=rp),
intent(in) :: tolerance
183 this%max_iterations = max_iterations
184 this%tolerance = tolerance
186 end subroutine optimizer_init_base
190 subroutine optimizer_free_base(this)
191 class(optimizer_t),
intent(inout) :: this
192 end subroutine optimizer_free_base
205 subroutine optimizer_run(this, problem, design, simulation)
206 class(optimizer_t),
intent(inout) :: this
207 class(problem_t),
intent(inout) :: problem
208 class(design_t),
intent(inout) :: design
209 type(simulation_t),
optional,
intent(inout) :: simulation
211 character(len=256) :: msg
219 call neko_log%section(
'Optimization Loop')
223 do while (iter .le. this%max_iterations .and. .not. converged)
225 call profiler_start_region(
'Optimizer iteration')
227 call profiler_end_region(
'Optimizer iteration')
236 call neko_log%end_section()
241 if (.not. converged)
then
242 write(msg,
'(A,I0,A)')
'Optimizer did not converge in ', &
243 this%max_iterations,
' iterations.'
244 call neko_log%warning(msg)
246 write(msg,
'(A,I0,A)')
'Optimizer converged after ', iter, &
248 call neko_log%message(msg)
251 end subroutine optimizer_run
Factory function for the optimizer.
Interface for optimizer initialization.
Module for handling the optimization problem.
Implements the steady_problem_t type.
Abstract optimizer class.
The abstract problem type.