MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 Lawrence Livermore National Laboratory. Under 00005 the terms of Contract B545069 with the University of Wisconsin -- 00006 Madison, Lawrence Livermore National Laboratory retains certain 00007 rights in this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 (2006) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 #ifndef MSQ_OFEVALUATOR_HPP 00028 #define MSQ_OFEVALUATOR_HPP 00029 00030 /** \file OFEvaluator.hpp 00031 * \brief 00032 * \author Jason Kraftcheck 00033 */ 00034 00035 #include <vector> 00036 00037 #include "Vector3D.hpp" 00038 #include "ObjectiveFunction.hpp" 00039 00040 namespace MBMesquite 00041 { 00042 00043 class MsqError; 00044 class Mesh; 00045 class MeshDomain; 00046 class PatchData; 00047 class MsqHessian; 00048 class PatchSet; 00049 00050 /**\brief Evaluate objective function 00051 * 00052 * This class handles the details of the differences between 00053 * Nash and block coordinate descent methods for evaluation 00054 * of the objective function, such that solvers need only 00055 * interact with this interface and need not be aware of the 00056 * Nash vs. BCD details. 00057 */ 00058 class MESQUITE_EXPORT OFEvaluator 00059 { 00060 public: 00061 /**\brief Constructor 00062 *\param of The objective function (may be NULL for Laplacian-type solvers) 00063 *\param Nash True for Nash-type solutions, false for 00064 * block coordinate descent. 00065 */ 00066 OFEvaluator( ObjectiveFunction* of ); 00067 00068 void initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err ); 00069 00070 /**\brief Initialize OFEvaluator 00071 * 00072 * For a Nash-type algorithm, this method will initialize 00073 * some member variables. For a block coordinate descent 00074 * solution, this method will calculate an initial value 00075 * of the objective function for the mesh. 00076 * 00077 *\param mesh The active mesh 00078 */ 00079 bool initialize( MeshDomainAssoc* mesh_and_domain, const Settings* settings, PatchSet* patches, MsqError& err ); 00080 00081 /**\brief Update accumulated values for changes to vertex positions 00082 * in a patch. 00083 * 00084 * For a block coordinate descent solution, this method calculates 00085 * the updated global objective function value for any modifications 00086 * to the passed patch, as made by the solver. The change to 00087 * the current patch state is considered relative to that of the 00088 * previous patch passed to any of the update methods, except when 00089 * the reset() method has been called by the solver to indicate 00090 * that a new inner iteration is starting. 00091 * 00092 * For a Nash-type solution, this method simply returns the evaluation 00093 * of the objective funtion for the local patch. The behavior is identical 00094 * to calling the evaluate() method. 00095 * 00096 *\param pd The mesh patch 00097 *\param value Output, the value of the objective function. 00098 */ 00099 bool update( PatchData& pd, double& value, MsqError& err ); 00100 00101 /**\brief Update accumulated values for changes to vertex positions 00102 * in a patch. 00103 * 00104 * For a block coordinate descent solution, this method calculates 00105 * the updated global objective function value for any modifications 00106 * to the passed patch, as made by the solver. The change to 00107 * the current patch state is considered relative to that of the 00108 * previous patch passed to any of the update methods, except when 00109 * the reset() method has been called by the solver to indicate 00110 * that a new inner iteration is starting. 00111 * 00112 * For a Nash-type solution, this method simply returns the evaluation 00113 * of the objective funtion for the local patch. The behavior is identical 00114 * to calling the evaluate() method. 00115 * 00116 *\param pd The mesh patch 00117 *\param value Output, the value of the objective function. 00118 *\param grad Output, the gradient of the objective function 00119 * with respect to each FREE vertex in the patch. 00120 */ 00121 bool update( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqError& err ); 00122 00123 /**\brief Update accumulated values for changes to vertex positions 00124 * in a patch. 00125 * 00126 * For a block coordinate descent solution, this method calculates 00127 * the updated global objective function value for any modifications 00128 * to the passed patch, as made by the solver. The change to 00129 * the current patch state is considered relative to that of the 00130 * previous patch passed to any of the update methods, except when 00131 * the reset() method has been called by the solver to indicate 00132 * that a new inner iteration is starting. 00133 * 00134 * For a Nash-type solution, this method simply returns the evaluation 00135 * of the objective funtion for the local patch. The behavior is identical 00136 * to calling the evaluate() method. 00137 * 00138 *\param pd The mesh patch 00139 *\param value Output, the value of the objective function. 00140 *\param grad Output, the gradient of the objective function 00141 * with respect to each FREE vertex in the patch. 00142 *\param Hessian_diag_blocks Output, 3x3 submatrices along diagonal of 00143 * Hessian of objective function 00144 */ 00145 bool update( PatchData& pd, 00146 double& value, 00147 std::vector< Vector3D >& grad, 00148 std::vector< SymMatrix3D >& Hessian_diag_blocks, 00149 MsqError& err ); 00150 00151 /**\brief Update accumulated values for changes to vertex positions 00152 * in a patch. 00153 * 00154 * For a block coordinate descent solution, this method calculates 00155 * the updated global objective function value for any modifications 00156 * to the passed patch, as made by the solver. The change to 00157 * the current patch state is considered relative to that of the 00158 * previous patch passed to any of the update methods, except when 00159 * the reset() method has been called by the solver to indicate 00160 * that a new inner iteration is starting. 00161 * 00162 * For a Nash-type solution, this method simply returns the evaluation 00163 * of the objective funtion for the local patch. The behavior is identical 00164 * to calling the evaluate() method. 00165 * 00166 *\param pd The mesh patch 00167 *\param value Output, the value of the objective function. 00168 *\param grad Output, the gradient of the objective function 00169 * with respect to each FREE vertex in the patch. 00170 *\param Hessian Output, the Hessian of the objective function. 00171 */ 00172 bool update( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqHessian& Hessian, MsqError& err ); 00173 00174 /**\brief Check if doing Nash game algorithm.*/ 00175 bool is_nash_game() const 00176 { 00177 return !doBCD; 00178 } 00179 00180 /**\brief Do Nash game algorithm.*/ 00181 void do_nash_game() 00182 { 00183 doBCD = false; 00184 } 00185 00186 /**\brief Check if doing block coordinate descent algorithm */ 00187 bool is_block_coordinate_descent() const 00188 { 00189 return doBCD; 00190 } 00191 00192 /**\brief Do block coordinate descent algorithm.*/ 00193 void do_block_coordinate_descent() 00194 { 00195 doBCD = true; 00196 } 00197 00198 /**\brief Evaluate the objective function without changing any 00199 * accumulated values. 00200 * 00201 * Evaluate the objective function for the specified patch 00202 * (or for the change to the specified patch for BCD). This 00203 * method does not change any internal state or accumulated 00204 * values. It is provided for FeasibleNewton and other solvers 00205 * that need to obtain an OF value for some intermediate or 00206 * temporary set of vertex positions. 00207 * 00208 *\param pd The mesh patch 00209 *\param value Output, the value of the objective function. 00210 */ 00211 bool evaluate( PatchData& pd, double& value, MsqError& err ) const; 00212 00213 /**\brief Evaluate the objective function without changing any 00214 * accumulated values. 00215 * 00216 * Evaluate the objective function for the specified patch 00217 * (or for the change to the specified patch for BCD). This 00218 * method does not change any internal state or accumulated 00219 * values. It is provided for FeasibleNewton and other solvers 00220 * that need to obtain an OF value for some intermediate or 00221 * temporary set of vertex positions. 00222 * 00223 *\param pd The mesh patch 00224 *\param value Output, the value of the objective function. 00225 *\param grad Output, the gradient of the objective function 00226 * with respect to each FREE vertex in the patch. 00227 */ 00228 bool evaluate( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqError& err ) const; 00229 00230 /**\brief Evaluate the objective function without changing any 00231 * accumulated values. 00232 * 00233 * Evaluate the objective function for the specified patch 00234 * (or for the change to the specified patch for BCD). This 00235 * method does not change any internal state or accumulated 00236 * values. It is provided for FeasibleNewton and other solvers 00237 * that need to obtain an OF value for some intermediate or 00238 * temporary set of vertex positions. 00239 * 00240 *\param pd The mesh patch 00241 *\param value Output, the value of the objective function. 00242 *\param grad Output, the gradient of the objective function 00243 * with respect to each FREE vertex in the patch. 00244 *\param Hessian_diag_blocks Output, 3x3 submatrices along diagonal of 00245 * Hessian of objective function 00246 */ 00247 bool evaluate( PatchData& pd, 00248 double& value, 00249 std::vector< Vector3D >& grad, 00250 std::vector< SymMatrix3D >& Hessian_diag_blocks, 00251 MsqError& err ) const; 00252 00253 /**\brief Evaluate the objective function without changing any 00254 * accumulated values. 00255 * 00256 * Evaluate the objective function for the specified patch 00257 * (or for the change to the specified patch for BCD). This 00258 * method does not change any internal state or accumulated 00259 * values. It is provided for FeasibleNewton and other solvers 00260 * that need to obtain an OF value for some intermediate or 00261 * temporary set of vertex positions. 00262 * 00263 *\param pd The mesh patch 00264 *\param value Output, the value of the objective function. 00265 *\param grad Output, the gradient of the objective function 00266 * with respect to each FREE vertex in the patch. 00267 *\param Hessian Output, the Hessian of the objective function. 00268 */ 00269 bool evaluate( PatchData& pd, 00270 double& value, 00271 std::vector< Vector3D >& grad, 00272 MsqHessian& Hessian, 00273 MsqError& err ) const; 00274 00275 /**\brief Reset for next inner iteration 00276 * 00277 * The control code for the vertex mover is responsible for 00278 * calling this method before the beginning of each inner 00279 * solver iteration so the necessary internal state can be 00280 * updated for the correct behavior of the first call to 00281 * the update() method for block coordinate descent algorithms. 00282 */ 00283 bool reset(); 00284 00285 /**\brief Get ObjectiveFunction pointer */ 00286 inline ObjectiveFunction* get_objective_function() const 00287 { 00288 return this->OF; 00289 } 00290 00291 /**\brief Check if we have an objective function */ 00292 inline bool have_objective_function() const 00293 { 00294 return 0 != get_objective_function(); 00295 } 00296 00297 private: 00298 /**\brief Disallow copying*/ 00299 OFEvaluator( const OFEvaluator& ); 00300 00301 /**\brief Disallow assignment*/ 00302 OFEvaluator& operator=( const OFEvaluator& ); 00303 00304 /** The ObjectiveFunction to evaluate */ 00305 ObjectiveFunction* const OF; 00306 00307 /** Nash or BCD */ 00308 bool doBCD; 00309 00310 /** Nash vs. BCD and state of BCD data */ 00311 ObjectiveFunction::EvalType tempType, firstType, updateType, currUpdateType; 00312 }; 00313 00314 } // namespace MBMesquite 00315 00316 #endif