MOAB: Mesh Oriented datABase  (version 5.4.0)
ScdElementData.cpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in 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  */
00015 
00016 #include "ScdElementData.hpp"
00017 #include "ScdVertexData.hpp"
00018 #include "moab/Interface.hpp"
00019 #include "moab/ReadUtilIface.hpp"
00020 #include "moab/CN.hpp"
00021 #include "Internals.hpp"
00022 #include <cassert>
00023 
00024 namespace moab
00025 {
00026 
00027 EntityID ScdElementData::calc_num_entities( EntityHandle start_handle,
00028                                             int irange,
00029                                             int jrange,
00030                                             int krange,
00031                                             int* is_periodic )
00032 {
00033     size_t result = 1;
00034     auto dim      = CN::Dimension( TYPE_FROM_HANDLE( start_handle ) );
00035     switch( dim )
00036     {
00037         case 3:
00038             result *= krange;
00039             // fall through
00040         case 2:
00041             result *= ( is_periodic && is_periodic[1] ? ( jrange + 1 ) : jrange );
00042             // fall through
00043         case 1:
00044             result *= ( is_periodic && is_periodic[0] ? ( irange + 1 ) : irange );
00045             break;
00046         default:
00047             result = 0;
00048             assert( false );
00049             break;
00050     }
00051     return result;
00052 }
00053 
00054 ScdElementData::ScdElementData( EntityHandle shandle,
00055                                 const int imin,
00056                                 const int jmin,
00057                                 const int kmin,
00058                                 const int imax,
00059                                 const int jmax,
00060                                 const int kmax,
00061                                 int* is_p )
00062     : SequenceData( 0,
00063                     shandle,
00064                     shandle + calc_num_entities( shandle, imax - imin, jmax - jmin, kmax - kmin, is_p ) - 1 )
00065 {
00066     // need to have meaningful parameters
00067     assert( imax >= imin && jmax >= jmin && kmax >= kmin );
00068 
00069     isPeriodic[0] = ( is_p ? is_p[0] : 0 );
00070     isPeriodic[1] = ( is_p ? is_p[1] : 0 );
00071 
00072     boxParams[0] = HomCoord( imin, jmin, kmin );
00073     boxParams[1] = HomCoord( imax, jmax, kmax );
00074     boxParams[2] = HomCoord( 1, 1, 1 );
00075 
00076     // assign and compute parameter stuff
00077     dIJK[0]   = boxParams[1][0] - boxParams[0][0] + 1;
00078     dIJK[1]   = boxParams[1][1] - boxParams[0][1] + 1;
00079     dIJK[2]   = boxParams[1][2] - boxParams[0][2] + 1;
00080     dIJKm1[0] = dIJK[0] - ( isPeriodic[0] ? 0 : 1 );
00081     dIJKm1[1] = dIJK[1] - ( isPeriodic[1] ? 0 : 1 );
00082     dIJKm1[2] = dIJK[2] - 1;
00083 }
00084 
00085 ScdElementData::~ScdElementData() {}
00086 
00087 bool ScdElementData::boundary_complete() const
00088 {
00089     // test the bounding vertex sequences to see if they fully define the
00090     // vertex parameter space for this rectangular block of elements
00091 
00092     int p;
00093     std::vector< VertexDataRef > minlist, maxlist;
00094 
00095     // pseudo code:
00096     // for each vertex sequence v:
00097     for( std::vector< VertexDataRef >::const_iterator vseq = vertexSeqRefs.begin(); vseq != vertexSeqRefs.end();
00098          ++vseq )
00099     {
00100         //   test min corner mincorner:
00101         bool mincorner = true;
00102         //   for each p = (i-1,j,k), (i,j-1,k), (i,j,k-1):
00103         for( p = 0; p < 3; p++ )
00104         {
00105 
00106             //     for each vsequence v' != v:
00107             for( std::vector< VertexDataRef >::const_iterator othervseq = vertexSeqRefs.begin();
00108                  othervseq != vertexSeqRefs.end(); ++othervseq )
00109             {
00110                 if( othervseq == vseq ) continue;
00111                 //       if v.min-p contained in v'
00112                 if( ( *othervseq ).contains( ( *vseq ).minmax[0] - HomCoord::unitv[p] ) )
00113                 {
00114                     //         mincorner = false
00115                     mincorner = false;
00116                     break;
00117                 }
00118             }
00119             if( !mincorner ) break;
00120         }
00121 
00122         bool maxcorner = true;
00123         //   for each p = (i-1,j,k), (i,j-1,k), (i,j,k-1):
00124         for( p = 0; p < 3; p++ )
00125         {
00126 
00127             //     for each vsequence v' != v:
00128             for( std::vector< VertexDataRef >::const_iterator othervseq = vertexSeqRefs.begin();
00129                  othervseq != vertexSeqRefs.end(); ++othervseq )
00130             {
00131                 if( othervseq == vseq ) continue;
00132                 //       if v.max+p contained in v'
00133                 if( ( *othervseq ).contains( ( *vseq ).minmax[1] + HomCoord::unitv[p] ) )
00134                 {
00135                     //         maxcorner = false
00136                     maxcorner = false;
00137                     break;
00138                 }
00139             }
00140             if( !maxcorner ) break;
00141         }
00142 
00143         //   if mincorner add to min corner list minlist
00144         if( mincorner ) minlist.push_back( *vseq );
00145         //   if maxcorner add to max corner list maxlist
00146         if( maxcorner ) maxlist.push_back( *vseq );
00147     }
00148 
00149     //
00150     // if minlist.size = 1 & maxlist.size = 1 & minlist[0] = esequence.min &
00151     //         maxlist[0] = esequence.max+(1,1,1)
00152     if( minlist.size() == 1 && maxlist.size() == 1 && minlist[0].minmax[0] == boxParams[0] &&
00153         maxlist[0].minmax[1] == boxParams[1] )
00154         //   complete
00155         return true;
00156     // else
00157 
00158     return false;
00159 }
00160 
00161 SequenceData* ScdElementData::subset( EntityHandle /*start*/,
00162                                       EntityHandle /*end*/,
00163                                       const int* /*sequence_data_sizes*/,
00164                                       const int* /*tag_data_sizes*/ ) const
00165 {
00166     return 0;
00167 }
00168 
00169 unsigned long ScdElementData::get_memory_use() const
00170 {
00171     return sizeof( *this ) + vertexSeqRefs.capacity() * sizeof( VertexDataRef );
00172 }
00173 
00174 }  // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines