MOAB: Mesh Oriented datABase
(version 5.3.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to 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 ObjectiveFunctionTemplate.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "ObjectiveFunctionTemplate.hpp" 00034 #include "QualityMetric.hpp" 00035 #include "MsqError.hpp" 00036 #include "MsqHessian.hpp" 00037 #include "PatchData.hpp" 00038 #include "ElementPatches.hpp" 00039 #include "VertexPatches.hpp" 00040 #include "PatchIterator.hpp" 00041 #include <memory> 00042 00043 namespace MBMesquite 00044 { 00045 00046 ObjectiveFunctionTemplate::~ObjectiveFunctionTemplate() {} 00047 00048 void ObjectiveFunctionTemplate::initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings, 00049 MsqError& err ) 00050 { 00051 qualityMetric->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err ); 00052 } 00053 00054 bool ObjectiveFunctionTemplate::initialize_block_coordinate_descent( MeshDomainAssoc* mesh_and_domain, 00055 const Settings* settings, PatchSet*, 00056 MsqError& err ) 00057 { 00058 std::unique_ptr< PatchSet > patch_set; 00059 switch( get_quality_metric()->get_metric_type() ) 00060 { 00061 case QualityMetric::VERTEX_BASED: 00062 patch_set = std::unique_ptr< PatchSet >( new VertexPatches( 1, false ) ); 00063 break; 00064 case QualityMetric::ELEMENT_BASED: 00065 patch_set = std::unique_ptr< PatchSet >( new ElementPatches ); 00066 break; 00067 default: 00068 MSQ_SETERR( err ) 00069 ( "Cannot initialize for BCD for unknown metric type", MsqError::INVALID_STATE ); 00070 return false; 00071 } 00072 00073 Mesh* mesh = mesh_and_domain->get_mesh(); 00074 MeshDomain* domain = mesh_and_domain->get_domain(); 00075 00076 clear(); 00077 patch_set->set_mesh( mesh ); 00078 PatchIterator patches( patch_set.get() ); 00079 00080 PatchData pd; 00081 pd.set_mesh( mesh ); 00082 pd.set_domain( domain ); 00083 if( settings ) pd.attach_settings( settings ); 00084 00085 bool result = true; 00086 while( patches.get_next_patch( pd, err ) && !MSQ_CHKERR( err ) ) 00087 { 00088 double value; 00089 bool b = evaluate( ObjectiveFunction::ACCUMULATE, pd, value, false, err ); 00090 MSQ_ERRZERO( err ); 00091 result = result && b; 00092 } 00093 return result; 00094 } 00095 00096 int ObjectiveFunctionTemplate::min_patch_layers() const 00097 { 00098 if( !get_quality_metric() ) 00099 return 0; 00100 else if( get_quality_metric()->get_metric_type() == QualityMetric::VERTEX_BASED ) 00101 return 2; 00102 else 00103 return 1; 00104 } 00105 00106 } // namespace MBMesquite