1 /* *****************************************************************
2     MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4     Copyright 2006 Lawrence Livermore National Laboratory.  Under
5     the terms of Contract B545069 with the University of Wisconsin --
6     Madison, Lawrence Livermore National Laboratory retains certain
7     rights in this software.
8 
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU Lesser General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13 
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17     Lesser General Public License for more details.
18 
19     You should have received a copy of the GNU Lesser General Public License
20     (lgpl.txt) along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 
23     (2006) kraftche@cae.wisc.edu
24 
25   ***************************************************************** */
26 
27 
28 /** \file ScalarAddQualityMetric.cpp
29  *  \brief
30  *  \author Jason Kraftcheck
31  */
32 
33 #include "Mesquite.hpp"
34 #include "ScalarAddQualityMetric.hpp"
35 #include "Vector3D.hpp"
36 #include "Matrix3D.hpp"
37 #include "MsqError.hpp"
38 #include <sstream>
39 
40 namespace MBMesquite {
41 
get_name() const42 std::string ScalarAddQualityMetric::get_name() const
43 {
44   std::ostringstream str;
45   str << mMetric->get_name() << "+" << mOffset;
46   return str.str();
47 }
48 
get_evaluations(PatchData & pd,std::vector<size_t> & handles,bool free_vertices_only,MsqError & err)49 void ScalarAddQualityMetric::get_evaluations( PatchData& pd,
50                                               std::vector<size_t>& handles,
51                                               bool free_vertices_only,
52                                               MsqError& err )
53 {
54   mMetric->get_evaluations( pd, handles, free_vertices_only, err );
55   MSQ_CHKERR(err);
56 }
57 
evaluate(PatchData & pd,size_t handle,double & value,MsqError & err)58 bool ScalarAddQualityMetric::evaluate( PatchData& pd, size_t handle, double& value, MsqError& err )
59 {
60   bool rval = mMetric->evaluate( pd, handle, value, err );
61   value += mOffset;
62   return rval;
63 }
64 
evaluate_with_indices(PatchData & pd,size_t handle,double & value,std::vector<size_t> & indices,MsqError & err)65 bool ScalarAddQualityMetric::evaluate_with_indices( PatchData& pd,
66                                                     size_t handle,
67                                                     double& value,
68                                                     std::vector<size_t>& indices,
69                                                     MsqError& err )
70 {
71   bool rval = mMetric->evaluate_with_indices( pd, handle, value, indices, err );
72   value += mOffset;
73   return !MSQ_CHKERR(err) && rval;
74 }
75 
evaluate_with_gradient(PatchData & pd,size_t handle,double & value,std::vector<size_t> & indices,std::vector<Vector3D> & gradient,MsqError & err)76 bool ScalarAddQualityMetric::evaluate_with_gradient( PatchData& pd,
77                                                    size_t handle,
78                                                    double& value,
79                                                    std::vector<size_t>& indices,
80                                                    std::vector<Vector3D>& gradient,
81                                                    MsqError& err )
82 {
83   bool rval = mMetric->evaluate_with_gradient( pd, handle, value, indices, gradient, err );
84   value += mOffset;
85   return !MSQ_CHKERR(err) && rval;
86 }
87 
88 
evaluate_with_Hessian(PatchData & pd,size_t handle,double & value,std::vector<size_t> & indices,std::vector<Vector3D> & gradient,std::vector<Matrix3D> & Hessian,MsqError & err)89 bool ScalarAddQualityMetric::evaluate_with_Hessian( PatchData& pd,
90                                                   size_t handle,
91                                                   double& value,
92                                                   std::vector<size_t>& indices,
93                                                   std::vector<Vector3D>& gradient,
94                                                   std::vector<Matrix3D>& Hessian,
95                                                   MsqError& err )
96 {
97   bool rval = mMetric->evaluate_with_Hessian( pd, handle, value, indices, gradient, Hessian, err );
98   value += mOffset;
99   return !MSQ_CHKERR(err) && rval;
100 }
101 
102 
103 } // namespace MBMesquite
104