MOAB: Mesh Oriented datABase  (version 5.2.1)
Sample.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2007 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     (2009) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 /** \file Sample.hpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_SAMPLE_HPP
00033 #define MSQ_SAMPLE_HPP
00034 
00035 #include "Mesquite.hpp"
00036 #include <iosfwd>
00037 #include <cstddef>  // for size_t
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 //! Define a logical location within an element at which the
00043 //! element will be "sampled" for the purpose of evaluating a
00044 //! quality metric.  For example, specify a location at which
00045 //! to calculate the Jacobian of the mapping function and
00046 //! use it to evaluate a TMP quality metric.
00047 //!
00048 //! Logical sample points are currently limited to corners, mid-sides
00049 //! (region elements have both face and edge "sides") and mid-element.
00050 struct MESQUITE_EXPORT Sample
00051 {
00052     //!\brief The "dimension" of the sub-entity.
00053     //!
00054     //! Possible values are [0-3]:
00055     //! - 0 : sample at the location of a corner vertex
00056     //! - 1 : sample at the center of an edge
00057     //! - 2 : sample at the center of a surface element or the center
00058     //!       of one face of a volume element
00059     //! - 3 : sample at the center of a volume element
00060     unsigned short dimension;
00061 
00062     //!\brief Canonical number in ITAPS ordering for element corners/sides.
00063     //!
00064     //! The dimension specifies which set of sub-entities that the sample
00065     //! my be on.  The number specifies which entity within that subset.
00066     //! For example, if dimension == 1 then the sample point is at the
00067     //! center of one of the element edges.  The number then specifies
00068     //! which edge of the element, where edges are ordered according to
00069     //! the ITAPS ordering.
00070     //!
00071     //! For mid-region or mid-face of a surface element, the number
00072     //! should be zero.
00073     unsigned short number;
00074 
00075     //! Constants used for a packed (minimum number of bits) representation
00076     //! of a sample.
00077     enum
00078     {
00079         /** Number of bits used to store the dimension of an element 'side' */
00080         SIDE_DIMENSION_BITS = 2,
00081         /** Number of bits used to store the index of an element 'side' of a specific dimension */
00082         SIDE_NUMBER_BITS   = 4,
00083         NUMBER_PACKED_BITS = SIDE_DIMENSION_BITS + SIDE_NUMBER_BITS,
00084         /** Number of distinct side dimension values that will fit
00085          *  in a sample value (one greater than the largest dimension) */
00086         NUM_SAMPLE_SIDE_DIM = 1u << SIDE_DIMENSION_BITS,
00087         /** Number of distinct side index values that will fit
00088          *  in a sample value (one greater than the largest side number) */
00089         NUM_SAMPLE_SIDE_NUM = 1u << SIDE_NUMBER_BITS,
00090         /** Mask to remove side dimension bits from sample number */
00091         SIDE_NUMBER_MASK = NUM_SAMPLE_SIDE_NUM - 1,
00092         /** Mask to remove side dimension bits from sample number */
00093         SIDE_DIMENSON_MASK = NUM_SAMPLE_SIDE_DIM - 1
00094     };
00095 
00096     //! Return packed representation of this sample.
00097     inline size_t pack() const
00098     {
00099         return ( ( (size_t)dimension ) << SIDE_NUMBER_BITS ) | number;
00100     }
00101     //! Set this sample to the values encoded in a packed sample representation.
00102     inline void unpack( size_t packed )
00103     {
00104         dimension = ( packed >> SIDE_NUMBER_BITS ) & SIDE_DIMENSON_MASK;
00105         number    = packed & SIDE_NUMBER_MASK;
00106     }
00107     //! Initialization constructor
00108     Sample( unsigned dim, unsigned num ) : dimension( dim ), number( num ) {}
00109     //! Initialize from packed representation
00110     explicit Sample( size_t packed )
00111     {
00112         unpack( packed );
00113     }
00114     //! Default constructor must be explicitly included if we provide other constructors
00115     //! Do nothing (don't waste time initilazing to zero or something, I'd rather
00116     //! be able to catch the use of uninitialized values using a memory checker
00117     //! anyway if I make such a mistake.)
00118     Sample() {}
00119 
00120     bool operator==( const Sample& other ) const
00121     {
00122         return pack() == other.pack();
00123     }
00124     bool operator!=( const Sample& other ) const
00125     {
00126         return pack() != other.pack();
00127     }
00128     bool operator<( const Sample& other ) const
00129     {
00130         return pack() < other.pack();
00131     }
00132     bool operator>( const Sample& other ) const
00133     {
00134         return pack() > other.pack();
00135     }
00136     bool operator<=( const Sample& other ) const
00137     {
00138         return pack() <= other.pack();
00139     }
00140     bool operator>=( const Sample& other ) const
00141     {
00142         return pack() >= other.pack();
00143     }
00144 };
00145 
00146 std::ostream& operator<<( std::ostream& str, Sample s );
00147 
00148 }  // namespace MBMesquite
00149 
00150 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines