MOAB: Mesh Oriented datABase
(version 5.3.1)
|
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 diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov, 00024 pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov 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, PatchSet* user_set, 00079 MsqError& err ) 00080 { 00081 bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err ); 00082 return !MSQ_CHKERR( err ) && rval; 00083 } 00084 00085 bool CompositeOFScalarAdd::evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ) 00086 { 00087 bool ok = objFunc->evaluate( type, pd, value_out, free, err ); 00088 value_out += mAlpha; 00089 return !MSQ_CHKERR( err ) && ok; 00090 } 00091 00092 bool CompositeOFScalarAdd::evaluate_with_gradient( EvalType type, PatchData& pd, double& value_out, 00093 std::vector< Vector3D >& grad_out, MsqError& err ) 00094 { 00095 bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err ); 00096 value_out += mAlpha; 00097 return !MSQ_CHKERR( err ) && ok; 00098 } 00099 00100 bool CompositeOFScalarAdd::evaluate_with_Hessian_diagonal( EvalType type, PatchData& pd, double& value_out, 00101 std::vector< Vector3D >& grad_out, 00102 std::vector< SymMatrix3D >& diag_out, MsqError& err ) 00103 { 00104 bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err ); 00105 value_out += mAlpha; 00106 return !MSQ_CHKERR( err ) && ok; 00107 } 00108 00109 bool CompositeOFScalarAdd::evaluate_with_Hessian( EvalType type, PatchData& pd, double& value_out, 00110 std::vector< Vector3D >& grad_out, MsqHessian& Hessian_out, 00111 MsqError& err ) 00112 { 00113 bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err ); 00114 value_out += mAlpha; 00115 return !MSQ_CHKERR( err ) && ok; 00116 } 00117 00118 int CompositeOFScalarAdd::min_patch_layers() const 00119 { 00120 return objFunc->min_patch_layers(); 00121 }