MOAB: Mesh Oriented datABase  (version 5.4.1)
ObjectiveFunctionTemplate.cpp
Go to the documentation of this file.
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) [email protected]
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,
00049                                                   const Settings* settings,
00050                                                   MsqError& err )
00051 {
00052     qualityMetric->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
00053 }
00054 
00055 bool ObjectiveFunctionTemplate::initialize_block_coordinate_descent( MeshDomainAssoc* mesh_and_domain,
00056                                                                      const Settings* settings,
00057                                                                      PatchSet*,
00058                                                                      MsqError& err )
00059 {
00060     std::unique_ptr< PatchSet > patch_set;
00061     switch( get_quality_metric()->get_metric_type() )
00062     {
00063         case QualityMetric::VERTEX_BASED:
00064             patch_set = std::unique_ptr< PatchSet >( new VertexPatches( 1, false ) );
00065             break;
00066         case QualityMetric::ELEMENT_BASED:
00067             patch_set = std::unique_ptr< PatchSet >( new ElementPatches );
00068             break;
00069         default:
00070             MSQ_SETERR( err )
00071             ( "Cannot initialize for BCD for unknown metric type", MsqError::INVALID_STATE );
00072             return false;
00073     }
00074 
00075     Mesh* mesh         = mesh_and_domain->get_mesh();
00076     MeshDomain* domain = mesh_and_domain->get_domain();
00077 
00078     clear();
00079     patch_set->set_mesh( mesh );
00080     PatchIterator patches( patch_set.get() );
00081 
00082     PatchData pd;
00083     pd.set_mesh( mesh );
00084     pd.set_domain( domain );
00085     if( settings ) pd.attach_settings( settings );
00086 
00087     bool result = true;
00088     while( patches.get_next_patch( pd, err ) && !MSQ_CHKERR( err ) )
00089     {
00090         double value;
00091         bool b = evaluate( ObjectiveFunction::ACCUMULATE, pd, value, false, err );
00092         MSQ_ERRZERO( err );
00093         result = result && b;
00094     }
00095     return result;
00096 }
00097 
00098 int ObjectiveFunctionTemplate::min_patch_layers() const
00099 {
00100     if( !get_quality_metric() )
00101         return 0;
00102     else if( get_quality_metric()->get_metric_type() == QualityMetric::VERTEX_BASED )
00103         return 2;
00104     else
00105         return 1;
00106 }
00107 
00108 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines