MOAB: Mesh Oriented datABase
(version 5.3.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) kraftche@cae.wisc.edu 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, double& value, std::vector< Vector3D >& grad, 00146 std::vector< SymMatrix3D >& Hessian_diag_blocks, MsqError& err ); 00147 00148 /**\brief Update accumulated values for changes to vertex positions 00149 * in a patch. 00150 * 00151 * For a block coordinate descent solution, this method calculates 00152 * the updated global objective function value for any modifications 00153 * to the passed patch, as made by the solver. The change to 00154 * the current patch state is considered relative to that of the 00155 * previous patch passed to any of the update methods, except when 00156 * the reset() method has been called by the solver to indicate 00157 * that a new inner iteration is starting. 00158 * 00159 * For a Nash-type solution, this method simply returns the evaluation 00160 * of the objective funtion for the local patch. The behavior is identical 00161 * to calling the evaluate() method. 00162 * 00163 *\param pd The mesh patch 00164 *\param value Output, the value of the objective function. 00165 *\param grad Output, the gradient of the objective function 00166 * with respect to each FREE vertex in the patch. 00167 *\param Hessian Output, the Hessian of the objective function. 00168 */ 00169 bool update( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqHessian& Hessian, MsqError& err ); 00170 00171 /**\brief Check if doing Nash game algorithm.*/ 00172 bool is_nash_game() const 00173 { 00174 return !doBCD; 00175 } 00176 00177 /**\brief Do Nash game algorithm.*/ 00178 void do_nash_game() 00179 { 00180 doBCD = false; 00181 } 00182 00183 /**\brief Check if doing block coordinate descent algorithm */ 00184 bool is_block_coordinate_descent() const 00185 { 00186 return doBCD; 00187 } 00188 00189 /**\brief Do block coordinate descent algorithm.*/ 00190 void do_block_coordinate_descent() 00191 { 00192 doBCD = true; 00193 } 00194 00195 /**\brief Evaluate the objective function without changing any 00196 * accumulated values. 00197 * 00198 * Evaluate the objective function for the specified patch 00199 * (or for the change to the specified patch for BCD). This 00200 * method does not change any internal state or accumulated 00201 * values. It is provided for FeasibleNewton and other solvers 00202 * that need to obtain an OF value for some intermediate or 00203 * temporary set of vertex positions. 00204 * 00205 *\param pd The mesh patch 00206 *\param value Output, the value of the objective function. 00207 */ 00208 bool evaluate( PatchData& pd, double& value, MsqError& err ) const; 00209 00210 /**\brief Evaluate the objective function without changing any 00211 * accumulated values. 00212 * 00213 * Evaluate the objective function for the specified patch 00214 * (or for the change to the specified patch for BCD). This 00215 * method does not change any internal state or accumulated 00216 * values. It is provided for FeasibleNewton and other solvers 00217 * that need to obtain an OF value for some intermediate or 00218 * temporary set of vertex positions. 00219 * 00220 *\param pd The mesh patch 00221 *\param value Output, the value of the objective function. 00222 *\param grad Output, the gradient of the objective function 00223 * with respect to each FREE vertex in the patch. 00224 */ 00225 bool evaluate( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqError& err ) const; 00226 00227 /**\brief Evaluate the objective function without changing any 00228 * accumulated values. 00229 * 00230 * Evaluate the objective function for the specified patch 00231 * (or for the change to the specified patch for BCD). This 00232 * method does not change any internal state or accumulated 00233 * values. It is provided for FeasibleNewton and other solvers 00234 * that need to obtain an OF value for some intermediate or 00235 * temporary set of vertex positions. 00236 * 00237 *\param pd The mesh patch 00238 *\param value Output, the value of the objective function. 00239 *\param grad Output, the gradient of the objective function 00240 * with respect to each FREE vertex in the patch. 00241 *\param Hessian_diag_blocks Output, 3x3 submatrices along diagonal of 00242 * Hessian of objective function 00243 */ 00244 bool evaluate( PatchData& pd, double& value, std::vector< Vector3D >& grad, 00245 std::vector< SymMatrix3D >& Hessian_diag_blocks, MsqError& err ) const; 00246 00247 /**\brief Evaluate the objective function without changing any 00248 * accumulated values. 00249 * 00250 * Evaluate the objective function for the specified patch 00251 * (or for the change to the specified patch for BCD). This 00252 * method does not change any internal state or accumulated 00253 * values. It is provided for FeasibleNewton and other solvers 00254 * that need to obtain an OF value for some intermediate or 00255 * temporary set of vertex positions. 00256 * 00257 *\param pd The mesh patch 00258 *\param value Output, the value of the objective function. 00259 *\param grad Output, the gradient of the objective function 00260 * with respect to each FREE vertex in the patch. 00261 *\param Hessian Output, the Hessian of the objective function. 00262 */ 00263 bool evaluate( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqHessian& Hessian, 00264 MsqError& err ) const; 00265 00266 /**\brief Reset for next inner iteration 00267 * 00268 * The control code for the vertex mover is responsible for 00269 * calling this method before the beginning of each inner 00270 * solver iteration so the necessary internal state can be 00271 * updated for the correct behavior of the first call to 00272 * the update() method for block coordinate descent algorithms. 00273 */ 00274 bool reset(); 00275 00276 /**\brief Get ObjectiveFunction pointer */ 00277 inline ObjectiveFunction* get_objective_function() const 00278 { 00279 return this->OF; 00280 } 00281 00282 /**\brief Check if we have an objective function */ 00283 inline bool have_objective_function() const 00284 { 00285 return 0 != get_objective_function(); 00286 } 00287 00288 private: 00289 /**\brief Disallow copying*/ 00290 OFEvaluator( const OFEvaluator& ); 00291 00292 /**\brief Disallow assignment*/ 00293 OFEvaluator& operator=( const OFEvaluator& ); 00294 00295 /** The ObjectiveFunction to evaluate */ 00296 ObjectiveFunction* const OF; 00297 00298 /** Nash or BCD */ 00299 bool doBCD; 00300 00301 /** Nash vs. BCD and state of BCD data */ 00302 ObjectiveFunction::EvalType tempType, firstType, updateType, currUpdateType; 00303 }; 00304 00305 } // namespace MBMesquite 00306 00307 #endif