DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_EntitySet.cpp
1 //---------------------------------------------------------------------------//
2 /*
3  Copyright (c) 2012, Stuart R. Slattery
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are
8  met:
9 
10  *: Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  *: Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 
17  *: Neither the name of the University of Wisconsin - Madison nor the
18  names of its contributors may be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 //---------------------------------------------------------------------------//
39 //---------------------------------------------------------------------------//
40 
41 #include "DTK_EntitySet.hpp"
42 #include "DTK_BasicEntityPredicates.hpp"
43 #include "DTK_DBC.hpp"
44 
45 #include <Teuchos_CommHelpers.hpp>
46 
47 namespace DataTransferKit
48 {
49 //---------------------------------------------------------------------------//
50 // Constructor.
51 EntitySet::EntitySet() { /* ... */}
52 
53 //---------------------------------------------------------------------------//
54 // Destructor.
55 EntitySet::~EntitySet() { /* ... */}
56 
57 //---------------------------------------------------------------------------//
58 // Get the local bounding box of entities of the set. Default implementation
59 // gathers the bounding boxes of local entities.
60 void EntitySet::localBoundingBox( Teuchos::Tuple<double, 6> &bounds ) const
61 {
62  LocalEntityPredicate local_predicate( communicator()->getRank() );
63  PredicateFunction select_func = local_predicate.getFunction();
64  double max = std::numeric_limits<double>::max();
65  bounds = Teuchos::tuple( max, max, max, -max, -max, -max );
66  EntityIterator entity_begin;
67  EntityIterator entity_end;
68  EntityIterator entity_it;
69  EntityIterator dim_it;
70  Teuchos::Tuple<double, 6> entity_bounds;
71  for ( int i = 0; i < 4; ++i )
72  {
73  dim_it = this->entityIterator( i, select_func );
74  entity_begin = dim_it.begin();
75  entity_end = dim_it.end();
76  for ( entity_it = entity_begin; entity_it != entity_end; ++entity_it )
77  {
78  entity_it->boundingBox( entity_bounds );
79  for ( int n = 0; n < 3; ++n )
80  {
81  bounds[n] = std::min( bounds[n], entity_bounds[n] );
82  bounds[n + 3] = std::max( bounds[n + 3], entity_bounds[n + 3] );
83  }
84  }
85  }
86 }
87 
88 //---------------------------------------------------------------------------//
89 // Get the global bounding box of entities of the set. Default implementation
90 // performs a parallel reduction using the local bounding boxes.
91 void EntitySet::globalBoundingBox( Teuchos::Tuple<double, 6> &bounds ) const
92 {
93  double max = std::numeric_limits<double>::max();
94  bounds = Teuchos::tuple( max, max, max, max, max, max );
95 
96  Teuchos::Tuple<double, 6> local_bounds;
97  this->localBoundingBox( local_bounds );
98  local_bounds[3] *= -1;
99  local_bounds[4] *= -1;
100  local_bounds[5] *= -1;
101 
102  Teuchos::reduceAll( *( this->communicator() ), Teuchos::REDUCE_MIN, 6,
103  &local_bounds[0], &bounds[0] );
104 
105  bounds[3] *= -1;
106  bounds[4] *= -1;
107  bounds[5] *= -1;
108 }
109 
110 //---------------------------------------------------------------------------//
111 // Provide a one line description of the object.
112 std::string EntitySet::description() const
113 {
114  return std::string( "DataTransferKit::EntitySet" );
115 }
116 
117 //---------------------------------------------------------------------------//
118 // Provide a verbose description of the object.
119 void EntitySet::describe( Teuchos::FancyOStream &out,
120  const Teuchos::EVerbosityLevel /*verb_level*/ ) const
121 {
122  EntityIterator d0_it = entityIterator( 0 );
123  EntityIterator d1_it = entityIterator( 1 );
124  EntityIterator d2_it;
125  if ( this->physicalDimension() >= 2 )
126  d2_it = entityIterator( 2 );
127  EntityIterator d3_it;
128  if ( this->physicalDimension() == 3 )
129  d3_it = entityIterator( 3 );
130 
131  Teuchos::Tuple<double, 6> local_box;
132  localBoundingBox( local_box );
133 
134  out << description() << std::endl
135  << "Dimension: " << physicalDimension() << std::endl
136  << "Num 0-D entities: " << d0_it.size() << std::endl
137  << "Num 1-D entities: " << d1_it.size() << std::endl
138  << "Num 2-D entities: " << d2_it.size() << std::endl
139  << "Num 3-D entities: " << d3_it.size() << std::endl
140  << "Local bounding box: " << local_box << std::endl;
141 }
142 
143 //---------------------------------------------------------------------------//
144 
145 } // end namespace DataTransferKit
146 
147 //---------------------------------------------------------------------------//
148 // end DTK_EntitySet.cpp
149 //---------------------------------------------------------------------------//
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verb_level=Teuchos::Describable::verbLevel_default) const override
Provide a verbose description of the object.
void boundingBox(Teuchos::Tuple< double, 6 > &bounds) const
Return the Cartesian bounding box around an entity.
Definition: DTK_Entity.cpp:114
Entity iterator interface.
virtual Teuchos::RCP< const Teuchos::Comm< int > > communicator() const =0
Parallel functions.
virtual EntityIterator entityIterator(const int topological_dimension, const PredicateFunction &predicate=selectAll) const =0
Get an iterator of the given entity type that satisfies the given predicate.
virtual int physicalDimension() const =0
Geometric data functions.
Assertions and Design-by-Contract for error handling.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Definition: DTK_Types.hpp:64
virtual void globalBoundingBox(Teuchos::Tuple< double, 6 > &bounds) const
Get the global bounding box of entities of the set.
virtual void localBoundingBox(Teuchos::Tuple< double, 6 > &bounds) const
Get the local bounding box of entities of the set.
virtual std::string description() const override
Teuchos::Describable interface.
DTK_BasicEntitySet.cpp.
virtual ~EntitySet()
Destructor.