MOAB: Mesh Oriented datABase
(version 5.2.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 CompositeOFScalarMultiply.cpp 00029 \brief 00030 00031 This Objective Function combines two Objective Functions by mulitplication 00032 \author Michael Brewer 00033 \date 2002-01-23 00034 */ 00035 #include <math.h> 00036 #include "CompositeOFScalarMultiply.hpp" 00037 #include "MsqTimer.hpp" 00038 #include "MsqError.hpp" 00039 #include "MsqDebug.hpp" 00040 #include "MsqHessian.hpp" 00041 00042 namespace MBMesquite 00043 { 00044 00045 /*! 00046 Sets the QualityMetric pointer to the metric associated with Obj. 00047 However, if alp is less than zero, the new 00048 ObjectiveFunction's negateFlag is the opposite of Obj's. This objective 00049 function defaults to the analytical gradient. 00050 \param alp (double) 00051 \param Obj (ObjectiveFunction*) 00052 */ 00053 CompositeOFScalarMultiply::CompositeOFScalarMultiply( double alp, ObjectiveFunction* Obj, bool delete_of ) 00054 : deleteObjFunc( delete_of ) 00055 { 00056 objFunc = Obj; 00057 mAlpha = alp; 00058 } 00059 00060 // Michael: need to clean up here 00061 CompositeOFScalarMultiply::~CompositeOFScalarMultiply() 00062 { 00063 if( deleteObjFunc ) delete objFunc; 00064 } 00065 00066 ObjectiveFunction* CompositeOFScalarMultiply::clone() const 00067 { 00068 return new CompositeOFScalarMultiply( mAlpha, objFunc->clone(), true ); 00069 } 00070 00071 void CompositeOFScalarMultiply::clear() 00072 { 00073 objFunc->clear(); 00074 } 00075 00076 void CompositeOFScalarMultiply::initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, 00077 MsqError& err ) 00078 { 00079 objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err ); 00080 } 00081 00082 bool CompositeOFScalarMultiply::initialize_block_coordinate_descent( MeshDomainAssoc* mesh_and_domain, 00083 const Settings* settings, PatchSet* user_set, 00084 MsqError& err ) 00085 { 00086 bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err ); 00087 return !MSQ_CHKERR( err ) && rval; 00088 } 00089 00090 bool CompositeOFScalarMultiply::evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ) 00091 { 00092 bool ok = objFunc->evaluate( type, pd, value_out, free, err ); 00093 value_out *= mAlpha; 00094 return !MSQ_CHKERR( err ) && ok; 00095 } 00096 00097 bool CompositeOFScalarMultiply::evaluate_with_gradient( EvalType type, PatchData& pd, double& value_out, 00098 std::vector< Vector3D >& grad_out, MsqError& err ) 00099 { 00100 bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err ); 00101 value_out *= mAlpha; 00102 for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) 00103 *i *= mAlpha; 00104 return !MSQ_CHKERR( err ) && ok; 00105 } 00106 00107 bool CompositeOFScalarMultiply::evaluate_with_Hessian_diagonal( EvalType type, PatchData& pd, double& value_out, 00108 std::vector< Vector3D >& grad_out, 00109 std::vector< SymMatrix3D >& diag_out, 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 for( size_t i = 0; i < pd.num_free_vertices(); ++i ) 00114 { 00115 grad_out[i] *= mAlpha; 00116 diag_out[i] *= mAlpha; 00117 } 00118 return !MSQ_CHKERR( err ) && ok; 00119 } 00120 00121 bool CompositeOFScalarMultiply::evaluate_with_Hessian( EvalType type, PatchData& pd, double& value_out, 00122 std::vector< Vector3D >& grad_out, MsqHessian& Hessian_out, 00123 MsqError& err ) 00124 { 00125 bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err ); 00126 value_out *= mAlpha; 00127 for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) 00128 *i *= mAlpha; 00129 Hessian_out.scale( mAlpha ); 00130 return !MSQ_CHKERR( err ) && ok; 00131 } 00132 00133 int CompositeOFScalarMultiply::min_patch_layers() const 00134 { 00135 return objFunc->min_patch_layers(); 00136 } 00137 00138 } // namespace MBMesquite