MOAB: Mesh Oriented datABase  (version 5.4.1)
OFEvaluator.cpp
Go to the documentation of this file.
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 /** \file OFEvaluator.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "OFEvaluator.hpp"
00033 #include "MsqError.hpp"
00034 #include "ObjectiveFunction.hpp"
00035 
00036 namespace MBMesquite
00037 {
00038 
00039 OFEvaluator::OFEvaluator( ObjectiveFunction* of ) : OF( of ), doBCD( false ) {}
00040 
00041 bool OFEvaluator::initialize( MeshDomainAssoc* mesh_and_domain,
00042                               const Settings* settings,
00043                               PatchSet* user_set,
00044                               MsqError& err )
00045 {
00046     if( doBCD )
00047     {
00048         tempType   = ObjectiveFunction::TEMPORARY;
00049         firstType  = ObjectiveFunction::SAVE;
00050         updateType = ObjectiveFunction::UPDATE;
00051     }
00052     else
00053     {
00054         tempType = firstType = updateType = ObjectiveFunction::CALCULATE;
00055     }
00056     reset();
00057 
00058     if( !doBCD )  // Nash
00059         return true;
00060 
00061     if( !have_objective_function() )
00062     {
00063         MSQ_SETERR( err )
00064         ( "Cannot perform block coordinate descent algorithm"
00065           " without an ObjectiveFunction",
00066           MsqError::INVALID_STATE );
00067         return false;
00068     }
00069 
00070     bool result =
00071         get_objective_function()->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err );
00072     return !MSQ_CHKERR( err ) && result;
00073 }
00074 
00075 void OFEvaluator::initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err )
00076 {
00077     if( get_objective_function() ) get_objective_function()->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
00078 }
00079 
00080 bool OFEvaluator::reset()
00081 {
00082     currUpdateType = firstType;
00083     return true;
00084 }
00085 
00086 bool OFEvaluator::update( PatchData& pd, double& value, MsqError& err )
00087 {
00088     if( !have_objective_function() )
00089     {
00090         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00091         return false;
00092     }
00093     bool b         = get_objective_function()->evaluate( currUpdateType, pd, value, OF_FREE_EVALS_ONLY, err );
00094     currUpdateType = updateType;
00095     return !MSQ_CHKERR( err ) && b;
00096 }
00097 
00098 bool OFEvaluator::update( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqError& err )
00099 {
00100     if( !have_objective_function() )
00101     {
00102         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00103         return false;
00104     }
00105     bool b         = get_objective_function()->evaluate_with_gradient( currUpdateType, pd, value, grad, err );
00106     currUpdateType = updateType;
00107     return !MSQ_CHKERR( err ) && b;
00108 }
00109 
00110 bool OFEvaluator::update( PatchData& pd,
00111                           double& value,
00112                           std::vector< Vector3D >& grad,
00113                           std::vector< SymMatrix3D >& hess_diag,
00114                           MsqError& err )
00115 {
00116     if( !have_objective_function() )
00117     {
00118         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00119         return false;
00120     }
00121     bool b =
00122         get_objective_function()->evaluate_with_Hessian_diagonal( currUpdateType, pd, value, grad, hess_diag, err );
00123     currUpdateType = updateType;
00124     return !MSQ_CHKERR( err ) && b;
00125 }
00126 
00127 bool OFEvaluator::update( PatchData& pd,
00128                           double& value,
00129                           std::vector< Vector3D >& grad,
00130                           MsqHessian& Hessian,
00131                           MsqError& err )
00132 {
00133     if( !have_objective_function() )
00134     {
00135         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00136         return false;
00137     }
00138     bool b         = get_objective_function()->evaluate_with_Hessian( currUpdateType, pd, value, grad, Hessian, err );
00139     currUpdateType = updateType;
00140     return !MSQ_CHKERR( err ) && b;
00141 }
00142 
00143 bool OFEvaluator::evaluate( PatchData& pd, double& value, MsqError& err ) const
00144 {
00145     if( !have_objective_function() )
00146     {
00147         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00148         return false;
00149     }
00150     bool b = get_objective_function()->evaluate( tempType, pd, value, OF_FREE_EVALS_ONLY, err );
00151     return !MSQ_CHKERR( err ) && b;
00152 }
00153 
00154 bool OFEvaluator::evaluate( PatchData& pd, double& value, std::vector< Vector3D >& grad, MsqError& err ) const
00155 {
00156     if( !have_objective_function() )
00157     {
00158         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00159         return false;
00160     }
00161     bool b = get_objective_function()->evaluate_with_gradient( tempType, pd, value, grad, err );
00162     return !MSQ_CHKERR( err ) && b;
00163 }
00164 
00165 bool OFEvaluator::evaluate( PatchData& pd,
00166                             double& value,
00167                             std::vector< Vector3D >& grad,
00168                             std::vector< SymMatrix3D >& hess_diag,
00169                             MsqError& err ) const
00170 {
00171     if( !have_objective_function() )
00172     {
00173         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00174         return false;
00175     }
00176     bool b = get_objective_function()->evaluate_with_Hessian_diagonal( tempType, pd, value, grad, hess_diag, err );
00177     return !MSQ_CHKERR( err ) && b;
00178 }
00179 
00180 bool OFEvaluator::evaluate( PatchData& pd,
00181                             double& value,
00182                             std::vector< Vector3D >& grad,
00183                             MsqHessian& Hessian,
00184                             MsqError& err ) const
00185 {
00186     if( !have_objective_function() )
00187     {
00188         MSQ_SETERR( err )( "No ObjectiveFunction", MsqError::INVALID_STATE );
00189         return false;
00190     }
00191     bool b = get_objective_function()->evaluate_with_Hessian( tempType, pd, value, grad, Hessian, err );
00192     return !MSQ_CHKERR( err ) && b;
00193 }
00194 
00195 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines