DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_CylinderGeometryImpl.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 <cmath>
42 
44 #include "DTK_DBC.hpp"
45 
46 namespace DataTransferKit
47 {
48 //---------------------------------------------------------------------------//
53  : d_global_id( dtk_invalid_entity_id )
54  , d_owner_rank( -1 )
55  , d_block_id( 0 )
56  , d_length( 0.0 )
57  , d_radius( 0.0 )
58  , d_centroid_x( 0.0 )
59  , d_centroid_y( 0.0 )
60  , d_centroid_z( 0.0 )
61 { /* ... */
62 }
63 
64 //---------------------------------------------------------------------------//
79  const EntityId global_id, const int owner_rank, const int block_id,
80  const double length, const double radius, const double centroid_x,
81  const double centroid_y, const double centroid_z )
82  : d_global_id( global_id )
83  , d_owner_rank( owner_rank )
84  , d_block_id( block_id )
85  , d_length( length )
86  , d_radius( radius )
87  , d_centroid_x( centroid_x )
88  , d_centroid_y( centroid_y )
89  , d_centroid_z( centroid_z )
90 {
91  DTK_REQUIRE( 0.0 <= d_length );
92  DTK_REQUIRE( 0.0 <= d_radius );
93 }
94 
95 //---------------------------------------------------------------------------//
96 // Get the unique global identifier for the entity.
97 EntityId CylinderGeometryImpl::id() const { return d_global_id; }
98 
99 //---------------------------------------------------------------------------//
100 // Get the parallel rank that owns the entity.
101 int CylinderGeometryImpl::ownerRank() const { return d_owner_rank; }
102 
103 //---------------------------------------------------------------------------//
104 // Return the topological dimension of the entity.
106 
107 //---------------------------------------------------------------------------//
108 // Return the physical dimension of the entity.
110 
111 //---------------------------------------------------------------------------//
118  Teuchos::Tuple<double, 6> &bounds ) const
119 {
120  bounds =
121  Teuchos::tuple( d_centroid_x - d_radius, d_centroid_y - d_radius,
122  d_centroid_z - d_length / 2, d_centroid_x + d_radius,
123  d_centroid_y + d_radius, d_centroid_z + d_length / 2 );
124 }
125 
126 //---------------------------------------------------------------------------//
127 // Determine if an entity is in the block with the given id.
128 bool CylinderGeometryImpl::inBlock( const int block_id ) const
129 {
130  return ( block_id == d_block_id );
131 }
132 
133 //---------------------------------------------------------------------------//
134 // Determine if an entity is on the boundary with the given id.
135 bool CylinderGeometryImpl::onBoundary( const int boundary_id ) const
136 {
137  return false;
138 }
139 
140 //---------------------------------------------------------------------------//
142  Teuchos::FancyOStream &out,
143  const Teuchos::EVerbosityLevel /*verb_level*/ ) const
144 {
145  out << "---" << std::endl;
146  out << description() << std::endl;
147  out << "Id: " << id() << std::endl;
148  out << "Owner rank: " << ownerRank() << std::endl;
149  out << "Block id: " << d_block_id << std::endl;
150  out << "Length: " << d_length << std::endl;
151  out << "Radius: " << d_radius << std::endl;
152  out << "Centroid (x,y,z): " << d_centroid_x << " " << d_centroid_y << " "
153  << d_centroid_z << std::endl;
154 }
155 
156 //---------------------------------------------------------------------------//
163 {
164  double zero = 0.0;
165  double pi = 2.0 * std::acos( zero );
166  return pi * d_radius * d_radius * d_length;
167 }
168 
169 //---------------------------------------------------------------------------//
176  const Teuchos::ArrayView<double> &centroid ) const
177 {
178  centroid[0] = d_centroid_x;
179  centroid[1] = d_centroid_y;
180  centroid[2] = d_centroid_z;
181 }
182 
183 //---------------------------------------------------------------------------//
188  const Teuchos::ArrayView<const double> &point,
189  const Teuchos::ArrayView<double> &reference_point ) const
190 {
191  reference_point.assign( point );
192  return true;
193 }
194 
195 //---------------------------------------------------------------------------//
201  const double tolerance,
202  const Teuchos::ArrayView<const double> &reference_point ) const
203 {
204  DTK_REQUIRE( reference_point.size() == 3 );
205 
206  double x_dist = d_centroid_x - reference_point[0];
207  double y_dist = d_centroid_y - reference_point[1];
208  double r = std::sqrt( x_dist * x_dist + y_dist * y_dist );
209  double rad_tol = d_radius * tolerance;
210  double half_length_tol = d_length / 2 + d_length * tolerance;
211 
212  return ( ( r <= d_radius + rad_tol ) &&
213  ( reference_point[2] >= d_centroid_z - half_length_tol ) &&
214  ( reference_point[2] <= d_centroid_z + half_length_tol ) );
215 }
216 
217 //---------------------------------------------------------------------------//
222  const Teuchos::ArrayView<const double> &reference_point,
223  const Teuchos::ArrayView<double> &point ) const
224 {
225  point.assign( reference_point );
226 }
227 
228 //---------------------------------------------------------------------------//
229 
230 } // end namespace DataTransferKit
231 
232 //---------------------------------------------------------------------------//
233 // end DTK_CylinderGeometryImpl.cpp
234 //---------------------------------------------------------------------------//
static const EntityId dtk_invalid_entity_id
Invalid entity id.
Definition: DTK_Types.hpp:53
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.
double radius() const
Get the radius of the cylinder.
double length() const
Get the length of the cylinder.
CylinderGeometry implementation.
EntityId id() const override
EntityImpl interface.
std::string description() const override
Provide a one line description of the object.
bool inBlock(const int block_id) const override
Determine if an entity is in the block with the given id.
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.
Assertions and Design-by-Contract for error handling.
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 ownerRank() const override
Get the parallel rank that owns the entity.
unsigned long int EntityId
Entity id type.
Definition: DTK_Types.hpp:50
bool onBoundary(const int boundary_id) const override
Determine if an entity is on the boundary with the given id.
void centroid(const Teuchos::ArrayView< double > &centroid) const override
Get the centroid of the box.
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.
void boundingBox(Teuchos::Tuple< double, 6 > &bounds) const override
Compute the bounding box around the box.
int topologicalDimension() const override
Return the topological dimension of the entity.
DTK_BasicEntitySet.cpp.
int physicalDimension() const override
Return the physical dimension of the entity.