MOAB: Mesh Oriented datABase
(version 5.4.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 <cmath> 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, 00077 const Settings* settings, 00078 MsqError& err ) 00079 { 00080 objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err ); 00081 } 00082 00083 bool CompositeOFScalarMultiply::initialize_block_coordinate_descent( MeshDomainAssoc* mesh_and_domain, 00084 const Settings* settings, 00085 PatchSet* user_set, 00086 MsqError& err ) 00087 { 00088 bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err ); 00089 return !MSQ_CHKERR( err ) && rval; 00090 } 00091 00092 bool CompositeOFScalarMultiply::evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ) 00093 { 00094 bool ok = objFunc->evaluate( type, pd, value_out, free, err ); 00095 value_out *= mAlpha; 00096 return !MSQ_CHKERR( err ) && ok; 00097 } 00098 00099 bool CompositeOFScalarMultiply::evaluate_with_gradient( EvalType type, 00100 PatchData& pd, 00101 double& value_out, 00102 std::vector< Vector3D >& grad_out, 00103 MsqError& err ) 00104 { 00105 bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err ); 00106 value_out *= mAlpha; 00107 for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) 00108 *i *= mAlpha; 00109 return !MSQ_CHKERR( err ) && ok; 00110 } 00111 00112 bool CompositeOFScalarMultiply::evaluate_with_Hessian_diagonal( EvalType type, 00113 PatchData& pd, 00114 double& value_out, 00115 std::vector< Vector3D >& grad_out, 00116 std::vector< SymMatrix3D >& diag_out, 00117 MsqError& err ) 00118 { 00119 bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err ); 00120 value_out *= mAlpha; 00121 for( size_t i = 0; i < pd.num_free_vertices(); ++i ) 00122 { 00123 grad_out[i] *= mAlpha; 00124 diag_out[i] *= mAlpha; 00125 } 00126 return !MSQ_CHKERR( err ) && ok; 00127 } 00128 00129 bool CompositeOFScalarMultiply::evaluate_with_Hessian( EvalType type, 00130 PatchData& pd, 00131 double& value_out, 00132 std::vector< Vector3D >& grad_out, 00133 MsqHessian& Hessian_out, 00134 MsqError& err ) 00135 { 00136 bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err ); 00137 value_out *= mAlpha; 00138 for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) 00139 *i *= mAlpha; 00140 Hessian_out.scale( mAlpha ); 00141 return !MSQ_CHKERR( err ) && ok; 00142 } 00143 00144 int CompositeOFScalarMultiply::min_patch_layers() const 00145 { 00146 return objFunc->min_patch_layers(); 00147 } 00148 00149 } // namespace MBMesquite