BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Optimizer.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_OPTIMIZER_HPP
13#define BELFEM_CL_OPTIMIZER_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "cl_Objective.hpp"
18#include "en_Opt_Algorithm.hpp"
19#include "en_Opt_Status.hpp"
20
21namespace belfem
22{
23 namespace opt
24 {
25//------------------------------------------------------------------------------
26
39 {
40 // objective to be minimized or maximized
41 Objective & mObjective;
42
43 // algorithm used for this optimizer
44 Algorithm mAlgorithm;
45
46 // lower / upper bounds on the design variables. Set together via
47 // set_bounds(); both left empty means an unbounded problem.
48 Vector< real > mLowerBounds;
49 Vector< real > mUpperBounds;
50
51 // relative tolerance on the objective value
52 real mFtolRel = 1.0e-8;
53
54 // relative tolerance on the design vector
55 real mXtolRel = 1.0e-8;
56
57 // maximum number of objective evaluations
58 uint mMaxEval = 1000;
59
60 // if true, the objective is maximized instead of minimized
61 bool mMaximize = false;
62
63 // detailed diagnostic from the solver library for the most recent
64 // optimize() call; empty when no detail was reported
65 string mErrmsg;
66
67//------------------------------------------------------------------------------
68 public:
69//------------------------------------------------------------------------------
70
71 Optimizer( Objective & aObjective, const Algorithm aAlgorithm );
72
73//------------------------------------------------------------------------------
74
75 ~Optimizer() = default;
76
77//------------------------------------------------------------------------------
78
87 void
89 const Vector< real > & aLowerBounds,
90 const Vector< real > & aUpperBounds );
91
92//------------------------------------------------------------------------------
93
105 Status
106 optimize( Vector< real > & aX, real & aValue );
107
108//------------------------------------------------------------------------------
109
116 inline const string &
117 errmsg() const;
118
119//------------------------------------------------------------------------------
120
124 inline real &
125 ftol_rel();
126
127//------------------------------------------------------------------------------
128
132 inline real &
133 xtol_rel();
134
135//------------------------------------------------------------------------------
136
140 inline uint &
141 max_eval();
142
143//------------------------------------------------------------------------------
144
148 inline bool &
149 maximize();
150
151//------------------------------------------------------------------------------
152
156 inline const Algorithm &
157 algorithm() const;
158
159//------------------------------------------------------------------------------
160 };
161
162//------------------------------------------------------------------------------
163
164 inline real &
166 {
167 return mFtolRel;
168 }
169
170//------------------------------------------------------------------------------
171
172 inline real &
174 {
175 return mXtolRel;
176 }
177
178//------------------------------------------------------------------------------
179
180 inline uint &
182 {
183 return mMaxEval;
184 }
185
186//------------------------------------------------------------------------------
187
188 inline bool &
190 {
191 return mMaximize;
192 }
193
194//------------------------------------------------------------------------------
195
196 inline const Algorithm &
198 {
199 return mAlgorithm;
200 }
201
202//------------------------------------------------------------------------------
203
204 inline const string &
206 {
207 return mErrmsg;
208 }
209
210//------------------------------------------------------------------------------
211 }
212}
213#endif //BELFEM_CL_OPTIMIZER_HPP
an object that defines a scalar objective function to be optimized.
Definition cl_Objective.hpp:32
real & ftol_rel()
relative tolerance on the objective value ( ftol_rel )
Definition cl_Optimizer.hpp:165
bool & maximize()
flag selecting maximization ( true ) over minimization ( false )
Definition cl_Optimizer.hpp:189
real & xtol_rel()
relative tolerance on the design vector ( xtol_rel )
Definition cl_Optimizer.hpp:173
const string & errmsg() const
detailed diagnostic from the solver for the most recent optimize() call ( e.g.
Definition cl_Optimizer.hpp:205
const Algorithm & algorithm() const
the algorithm used by this optimizer
Definition cl_Optimizer.hpp:197
Status optimize(Vector< real > &aX, real &aValue)
run the optimization, starting from and writing back into aX.
Definition cl_Optimizer.cpp:306
void set_bounds(const Vector< real > &aLowerBounds, const Vector< real > &aUpperBounds)
set the lower and upper bounds of the design variables.
Definition cl_Optimizer.cpp:36
uint & max_eval()
maximum number of objective evaluations; 0 means unlimited
Definition cl_Optimizer.hpp:181
Optimizer(Objective &aObjective, const Algorithm aAlgorithm)
Definition cl_Optimizer.cpp:27
Definition cl_Objective.hpp:21
Algorithm
optimization algorithm selector.
Definition en_Opt_Algorithm.hpp:28
Status
outcome of an optimization run.
Definition en_Opt_Status.hpp:27
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
double real
Definition typedefs.hpp:36