Branch data Line data Source code
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) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file ElemSampleQM.hpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #ifndef MSQ_ELEM_SAMPLE_QM_HPP
33 : : #define MSQ_ELEM_SAMPLE_QM_HPP
34 : :
35 : : #include "Mesquite.hpp"
36 : : #include "QualityMetric.hpp"
37 : : #include "Sample.hpp"
38 : :
39 : : namespace MBMesquite
40 : : {
41 : :
42 : : /**\brief Base type for metrics evaluated at several
43 : : * sample points within each element.
44 : : *
45 : : * This class defines an interface for metrics that are evaluated
46 : : * at multiple sample points within each element. This interface is
47 : : * used by ElemAverageQM and is the base for ElemCornerQM and
48 : : * ElemTargetQM.
49 : : */
50 : 176 : class ElemSampleQM : public QualityMetric
51 : : {
52 : : public:
53 : : MESQUITE_EXPORT virtual ~ElemSampleQM();
54 : :
55 : 28 : MESQUITE_EXPORT virtual MetricType get_metric_type() const
56 : : {
57 : 28 : return ELEMENT_BASED;
58 : : }
59 : :
60 : : /**\brief Get evaluation point handles for a given element
61 : : *
62 : : * Similar to QualityMetric::get_evaluations, this method returns
63 : : * a list of handles corresponding to sample points at which the
64 : : * metric may be evaluated. While QualityMetric::get_evaluations
65 : : * returns sample points for all elements in a PatchData, this
66 : : * method returns only the subset corresponding to a single element.
67 : : */
68 : : MESQUITE_EXPORT virtual void get_element_evaluations( PatchData& pd, size_t elem_index,
69 : : std::vector< size_t >& handles, MsqError& err ) = 0;
70 : :
71 : : /** Misc constants used in defining how element index, side dimension,
72 : : * and side number are packed into a single handle describing a logical
73 : : * location in the patch at which a sample-based metric is to be
74 : : * evaluated.
75 : : */
76 : : #ifndef _WIN32
77 : : enum { /** the number of bits in a handle that are used to store element index */
78 : : ELEM_INDEX_BITS = sizeof( size_t ) * 8 - Sample::NUMBER_PACKED_BITS,
79 : : /** the maximum number of elements in a PatchData without overflowing handle space */
80 : : MAX_ELEM_PER_PATCH = ( (size_t)1 ) << ELEM_INDEX_BITS,
81 : : /** Mask to remove sample bits from handle */
82 : : ELEM_SAMPLE_MASK = MAX_ELEM_PER_PATCH - 1
83 : : };
84 : : #else /* MS Visual C compiler broken for 64-bit enums */
85 : : static const size_t ELEM_INDEX_BITS = sizeof( size_t ) * 8 - Sample::NUMBER_PACKED_BITS;
86 : : static const size_t MAX_ELEM_PER_PATCH = ( (size_t)1 ) << ELEM_INDEX_BITS;
87 : : static const size_t ELEM_SAMPLE_MASK = MAX_ELEM_PER_PATCH - 1;
88 : : #endif
89 : :
90 : 14786862 : inline static size_t handle( Sample sample, size_t index )
91 : : {
92 : 14786862 : return ( sample.pack() << ELEM_INDEX_BITS ) | index;
93 : : }
94 : :
95 : 21247589 : inline static Sample sample( size_t handle )
96 : : {
97 : 21247589 : return Sample( handle >> ELEM_INDEX_BITS );
98 : : }
99 : :
100 : 21247589 : inline static size_t elem( size_t handle )
101 : : {
102 : 21247589 : return handle & ELEM_SAMPLE_MASK;
103 : : }
104 : : };
105 : :
106 : : } // namespace MBMesquite
107 : :
108 : : #endif
|