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