MOAB: Mesh Oriented datABase  (version 5.4.1)
CompositeOFScalarAdd.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government 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     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 /*!
00028   \file    CompositeOFScalarAdd.cpp
00029   \brief
00030 
00031   This Objective Function combines two Objective Functions by addition
00032   \author Michael Brewer
00033   \date   2002-06-24
00034 */
00035 #include <cmath>
00036 #include "CompositeOFScalarAdd.hpp"
00037 #include "PatchData.hpp"
00038 #include "MsqTimer.hpp"
00039 using namespace MBMesquite;
00040 
00041 /*!
00042 Sets the QualityMetric pointer to the metric associated with Obj1.
00043 The new ObjectiveFunction's negateFlag is also the
00044 same as that of Obj1.  This objective function defaults to the analytical
00045 gradient which essentially just calls Obj1's gradient function.
00046   \param alp (double)
00047   \param Obj1 (ObjectiveFunction*)
00048  */
00049 CompositeOFScalarAdd::CompositeOFScalarAdd( double alp, ObjectiveFunction* Obj1, bool delete_OF )
00050     : deleteObjFunc( delete_OF )
00051 {
00052     objFunc = Obj1;
00053     mAlpha  = alp;
00054 }
00055 
00056 // Michael:  need to clean up here
00057 CompositeOFScalarAdd::~CompositeOFScalarAdd()
00058 {
00059     if( deleteObjFunc ) delete objFunc;
00060 }
00061 
00062 ObjectiveFunction* CompositeOFScalarAdd::clone() const
00063 {
00064     return new CompositeOFScalarAdd( mAlpha, objFunc->clone(), true );
00065 }
00066 
00067 void CompositeOFScalarAdd::clear()
00068 {
00069     objFunc->clear();
00070 }
00071 
00072 void CompositeOFScalarAdd::initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, MsqError& err )
00073 {
00074     objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
00075 }
00076 
00077 bool CompositeOFScalarAdd::initialize_block_coordinate_descent( MeshDomainAssoc* mesh_and_domain,
00078                                                                 const Settings* settings,
00079                                                                 PatchSet* user_set,
00080                                                                 MsqError& err )
00081 {
00082     bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err );
00083     return !MSQ_CHKERR( err ) && rval;
00084 }
00085 
00086 bool CompositeOFScalarAdd::evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err )
00087 {
00088     bool ok = objFunc->evaluate( type, pd, value_out, free, err );
00089     value_out += mAlpha;
00090     return !MSQ_CHKERR( err ) && ok;
00091 }
00092 
00093 bool CompositeOFScalarAdd::evaluate_with_gradient( EvalType type,
00094                                                    PatchData& pd,
00095                                                    double& value_out,
00096                                                    std::vector< Vector3D >& grad_out,
00097                                                    MsqError& err )
00098 {
00099     bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err );
00100     value_out += mAlpha;
00101     return !MSQ_CHKERR( err ) && ok;
00102 }
00103 
00104 bool CompositeOFScalarAdd::evaluate_with_Hessian_diagonal( EvalType type,
00105                                                            PatchData& pd,
00106                                                            double& value_out,
00107                                                            std::vector< Vector3D >& grad_out,
00108                                                            std::vector< SymMatrix3D >& diag_out,
00109                                                            MsqError& err )
00110 {
00111     bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err );
00112     value_out += mAlpha;
00113     return !MSQ_CHKERR( err ) && ok;
00114 }
00115 
00116 bool CompositeOFScalarAdd::evaluate_with_Hessian( EvalType type,
00117                                                   PatchData& pd,
00118                                                   double& value_out,
00119                                                   std::vector< Vector3D >& grad_out,
00120                                                   MsqHessian& Hessian_out,
00121                                                   MsqError& err )
00122 {
00123     bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err );
00124     value_out += mAlpha;
00125     return !MSQ_CHKERR( err ) && ok;
00126 }
00127 
00128 int CompositeOFScalarAdd::min_patch_layers() const
00129 {
00130     return objFunc->min_patch_layers();
00131 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines