DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_BoxGeometryImpl.cpp
Go to the documentation of this file.
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_BoxGeometryImpl.hpp"
42 #include "DTK_DBC.hpp"
43 
44 namespace DataTransferKit
45 {
46 //---------------------------------------------------------------------------//
51  : d_global_id( dtk_invalid_entity_id )
52  , d_owner_rank( -1 )
53  , d_block_id( 0 )
54  , d_x_min( 0.0 )
55  , d_y_min( 0.0 )
56  , d_z_min( 0.0 )
57  , d_x_max( 0.0 )
58  , d_y_max( 0.0 )
59  , d_z_max( 0.0 )
60 { /* ... */
61 }
62 
63 //---------------------------------------------------------------------------//
80  const int owner_rank, const int block_id,
81  const double x_min, const double y_min,
82  const double z_min, const double x_max,
83  const double y_max, const double z_max )
84  : d_global_id( global_id )
85  , d_owner_rank( owner_rank )
86  , d_block_id( block_id )
87  , d_x_min( x_min )
88  , d_y_min( y_min )
89  , d_z_min( z_min )
90  , d_x_max( x_max )
91  , d_y_max( y_max )
92  , d_z_max( z_max )
93 {
94  DTK_REQUIRE( d_x_min <= d_x_max );
95  DTK_REQUIRE( d_y_min <= d_y_max );
96  DTK_REQUIRE( d_z_min <= d_z_max );
97 }
98 
99 //---------------------------------------------------------------------------//
106  const int owner_rank, const int block_id,
107  const Teuchos::Tuple<double, 6> &bounds )
108  : d_global_id( global_id )
109  , d_owner_rank( owner_rank )
110  , d_block_id( block_id )
111  , d_x_min( bounds[0] )
112  , d_y_min( bounds[1] )
113  , d_z_min( bounds[2] )
114  , d_x_max( bounds[3] )
115  , d_y_max( bounds[4] )
116  , d_z_max( bounds[5] )
117 {
118  DTK_REQUIRE( d_x_min <= d_x_max );
119  DTK_REQUIRE( d_y_min <= d_y_max );
120  DTK_REQUIRE( d_z_min <= d_z_max );
121 }
122 
123 //---------------------------------------------------------------------------//
124 // Get the unique global identifier for the entity.
125 EntityId BoxGeometryImpl::id() const { return d_global_id; }
126 
127 //---------------------------------------------------------------------------//
128 // Get the parallel rank that owns the entity.
129 int BoxGeometryImpl::ownerRank() const { return d_owner_rank; }
130 
131 //---------------------------------------------------------------------------//
132 // Return the topological dimension of the entity.
133 int BoxGeometryImpl::topologicalDimension() const { return 3; }
134 
135 //---------------------------------------------------------------------------//
136 // Return the physical dimension of the entity.
137 int BoxGeometryImpl::physicalDimension() const { return 3; }
138 
139 //---------------------------------------------------------------------------//
145 void BoxGeometryImpl::boundingBox( Teuchos::Tuple<double, 6> &bounds ) const
146 {
147  bounds =
148  Teuchos::tuple( d_x_min, d_y_min, d_z_min, d_x_max, d_y_max, d_z_max );
149 }
150 
151 //---------------------------------------------------------------------------//
152 // Determine if an entity is in the block with the given id.
153 bool BoxGeometryImpl::inBlock( const int block_id ) const
154 {
155  return ( block_id == d_block_id );
156 }
157 
158 //---------------------------------------------------------------------------//
159 // Determine if an entity is on the boundary with the given id.
160 bool BoxGeometryImpl::onBoundary( const int boundary_id ) const
161 {
162  return false;
163 }
164 
165 //---------------------------------------------------------------------------//
167  Teuchos::FancyOStream &out,
168  const Teuchos::EVerbosityLevel /*verb_level*/ ) const
169 {
170  out << "---" << std::endl;
171  out << description() << std::endl;
172  out << "Id: " << id() << std::endl;
173  out << "Owner rank: " << ownerRank() << std::endl;
174  out << "Block id: " << d_block_id << std::endl;
175  out << "(xmin,ymin,zmin,xmax,ymax,zmax): " << d_x_min << " " << d_y_min
176  << " " << d_z_min << " " << d_x_max << " " << d_y_max << " " << d_z_max
177  << std::endl;
178 }
179 
180 //---------------------------------------------------------------------------//
187 {
188  return ( d_x_max - d_x_min ) * ( d_y_max - d_y_min ) *
189  ( d_z_max - d_z_min );
190 }
191 
192 //---------------------------------------------------------------------------//
199  const Teuchos::ArrayView<double> &centroid ) const
200 {
201  centroid[0] = ( d_x_max + d_x_min ) / 2.0;
202  centroid[1] = ( d_y_max + d_y_min ) / 2.0;
203  centroid[2] = ( d_z_max + d_z_min ) / 2.0;
204 }
205 
206 //---------------------------------------------------------------------------//
211  const Teuchos::ArrayView<const double> &point,
212  const Teuchos::ArrayView<double> &reference_point ) const
213 {
214  reference_point.assign( point );
215  return true;
216 }
217 
218 //---------------------------------------------------------------------------//
224  const double tolerance,
225  const Teuchos::ArrayView<const double> &reference_point ) const
226 {
227  DTK_REQUIRE( 3 == reference_point.size() );
228 
229  double x_tol = ( d_x_max - d_x_min ) * tolerance;
230  double y_tol = ( d_y_max - d_y_min ) * tolerance;
231  double z_tol = ( d_z_max - d_z_min ) * tolerance;
232 
233  if ( reference_point[0] >= d_x_min - x_tol &&
234  reference_point[1] >= d_y_min - y_tol &&
235  reference_point[2] >= d_z_min - z_tol &&
236  reference_point[0] <= d_x_max + x_tol &&
237  reference_point[1] <= d_y_max + y_tol &&
238  reference_point[2] <= d_z_max + z_tol )
239  {
240  return true;
241  }
242 
243  return false;
244 }
245 
246 //---------------------------------------------------------------------------//
251  const Teuchos::ArrayView<const double> &reference_point,
252  const Teuchos::ArrayView<double> &point ) const
253 {
254  point.assign( reference_point );
255 }
256 
257 //---------------------------------------------------------------------------//
258 
259 } // end namespace DataTransferKit
260 
261 //---------------------------------------------------------------------------//
262 // end DTK_BoxGeometryImpl.cpp
263 //---------------------------------------------------------------------------//
static const EntityId dtk_invalid_entity_id
Invalid entity id.
Definition: DTK_Types.hpp:53
int ownerRank() const override
Get the parallel rank that owns the entity.
double measure() const override
Compute the measure of the box.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verb_level) const override
Provide a verbose description of the object.
int physicalDimension() const override
Return the physical dimension of the entity.
void boundingBox(Teuchos::Tuple< double, 6 > &bounds) const override
Compute the bounding box around the box.
bool onBoundary(const int boundary_id) const override
Determine if an entity is on the boundary with the given id.
int topologicalDimension() const override
Return the topological dimension of the entity.
bool inBlock(const int block_id) const override
Determine if an entity is in the block with the given id.
Assertions and Design-by-Contract for error handling.
EntityId id() const override
EntityImpl interface.
BoxGeometry implementation.
unsigned long int EntityId
Entity id type.
Definition: DTK_Types.hpp:50
std::string description() const override
Provide a one line description of the object.
void centroid(const Teuchos::ArrayView< double > &centroid) const override
Get the centroid of the box.
bool checkPointInclusion(const double tolerance, const Teuchos::ArrayView< const double > &reference_point) const override
Determine if a reference point is in the parameterized space of an entity.
DTK_BasicEntitySet.cpp.
void mapToPhysicalFrame(const Teuchos::ArrayView< const double > &reference_point, const Teuchos::ArrayView< double > &point) const override
Map a reference point to the physical space of an entity.
bool mapToReferenceFrame(const Teuchos::ArrayView< const double > &point, const Teuchos::ArrayView< double > &reference_point) const override
Map a point to the reference space of an entity. Return the.
BoxGeometryImpl()
Default constructor.