Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/LPtoPTemplate.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government 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  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25 
26  ***************************************************************** */
27 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 -*-
28 
37 #ifndef LPtoPTemplate_hpp
38 #define LPtoPTemplate_hpp
39 
40 #include "Mesquite.hpp"
41 #include "MsqError.hpp"
42 #include "ObjectiveFunction.hpp"
43 
44 namespace Mesquite
45 {
66  class PatchData;
67  class MsqMeshEntity;
69  {
70  public:
72  virtual ~LPtoPTemplate();
73  virtual bool concrete_evaluate(PatchData &patch, double &fval,
74  MsqError &err);
85  void set_dividing_by_n(bool d_bool){dividingByN=d_bool;}
86 
87  protected:
88  virtual bool compute_analytical_gradient(PatchData &patch,
89  Vector3D *const &grad,
90  double &OF_val,
91  MsqError &err,
92  size_t array_size);
93 
94  virtual bool compute_analytical_hessian(PatchData &patch,
95  MsqHessian &hessian,
96  Vector3D *const &grad,
97  double &OF_val,
98  MsqError &err);
99 
100  private:
101  double compute_function(double metric_values[], size_t total_num,
102  MsqError &err);
104  short pVal;
108  };
109 
110  inline double LPtoPTemplate::compute_function(double metric_values[],
111  size_t total_num,
112  MsqError &err)
113  {
114  double scale_factor=1.0;
115  //if scaling, divide by total_num
116  if(dividingByN){
117  if(total_num<=0) {
119  return 0.0;
120  }
121  scale_factor/=total_num;
122  }
123  size_t ind=0;
124  short jnd=0;
125  double temp_value=1;
126  double total_value=0;
127  for(ind=0;ind<total_num;++ind){
128  temp_value=1;
129  for(jnd=0;jnd<pVal;++jnd){
130  temp_value*=metric_values[ind];
131  }
132  total_value+=(scale_factor*temp_value);
133  }
134  return total_value;
135  }
136 
137 }//namespace
138 
139 #endif // LPtoPTemplate_hpp
140 
virtual bool compute_analytical_hessian(PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err)
short pVal
The metric value entries are raised to the pVal power.
double compute_function(double metric_values[], size_t total_num, MsqError &err)
Calculates the L_p objective function raised to the pth power. That is, sums the p_th powers of (the ...
Used to hold the error state and return it to the application.
Base class for concrete quality metrics.
virtual bool concrete_evaluate(PatchData &patch, double &fval, MsqError &err)
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
Vector3D is the object that effeciently stores the objective function Hessian each entry is a Matrix3...
invalid function argument passed
Definition: patch.h:74
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
LPtoPTemplate(QualityMetric *, short, MsqError &)
virtual bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric...
bool dividingByN
dividingByN is true if we are dividing the objective function by the number of metric values...