DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_CloudDomain_impl.hpp
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 #ifndef DTK_CLOUDDOMAIN_IMPL_HPP
42 #define DTK_CLOUDDOMAIN_IMPL_HPP
43 
44 #include "DTK_CloudDomain.hpp"
45 #include "DTK_DBC.hpp"
46 
47 namespace DataTransferKit
48 {
49 //---------------------------------------------------------------------------//
53 template <int DIM>
55 {
56  Teuchos::Array<double> zero( 2 * DIM, 0.0 );
57  std::copy( zero.begin(), zero.end(), d_bounds );
58 }
59 
60 //---------------------------------------------------------------------------//
66 template <int DIM>
67 CloudDomain<DIM>::CloudDomain( const double bounds[2 * DIM] )
68 {
69  std::copy( bounds, bounds + 2 * DIM, d_bounds );
70 }
71 
72 //---------------------------------------------------------------------------//
76 template <>
77 void CloudDomain<1>::expand( const double radius )
78 {
79  DTK_CHECK( radius >= 0.0 );
80  d_bounds[0] -= radius;
81  d_bounds[1] += radius;
82 }
83 
84 //---------------------------------------------------------------------------//
88 template <>
89 void CloudDomain<2>::expand( const double radius )
90 {
91  DTK_CHECK( radius >= 0.0 );
92  d_bounds[0] -= radius;
93  d_bounds[1] += radius;
94  d_bounds[2] -= radius;
95  d_bounds[3] += radius;
96 }
97 
98 //---------------------------------------------------------------------------//
102 template <>
103 void CloudDomain<3>::expand( const double radius )
104 {
105  DTK_CHECK( radius >= 0.0 );
106  d_bounds[0] -= radius;
107  d_bounds[1] += radius;
108  d_bounds[2] -= radius;
109  d_bounds[3] += radius;
110  d_bounds[4] -= radius;
111  d_bounds[5] += radius;
112 }
113 
114 //---------------------------------------------------------------------------//
123 template <>
125  const Teuchos::ArrayView<const double> &coords ) const
126 {
127  DTK_REQUIRE( coords.size() == 1 );
128  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
129 
130  return ( coords[0] >= d_bounds[0] && coords[0] <= d_bounds[1] ) ? true
131  : false;
132 }
133 
134 //---------------------------------------------------------------------------//
143 template <>
145  const Teuchos::ArrayView<const double> &coords ) const
146 {
147  DTK_REQUIRE( coords.size() == 2 );
148  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
149  DTK_CHECK( d_bounds[2] <= d_bounds[3] );
150 
151  return ( coords[0] >= d_bounds[0] && coords[0] <= d_bounds[1] &&
152  coords[1] >= d_bounds[2] && coords[1] <= d_bounds[3] )
153  ? true
154  : false;
155 }
156 
157 //---------------------------------------------------------------------------//
166 template <>
168  const Teuchos::ArrayView<const double> &coords ) const
169 {
170  DTK_REQUIRE( coords.size() == 3 );
171  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
172  DTK_CHECK( d_bounds[2] <= d_bounds[3] );
173  DTK_CHECK( d_bounds[4] <= d_bounds[5] );
174 
175  return ( coords[0] >= d_bounds[0] && coords[0] <= d_bounds[1] &&
176  coords[1] >= d_bounds[2] && coords[1] <= d_bounds[3] &&
177  coords[2] >= d_bounds[4] && coords[2] <= d_bounds[5] )
178  ? true
179  : false;
180 }
181 
182 //---------------------------------------------------------------------------//
190 template <>
192 {
193  Teuchos::ArrayView<const double> bounds = domain.bounds();
194 
195  return !( ( d_bounds[0] > bounds[1] || d_bounds[1] < bounds[0] ) );
196 }
197 
198 //---------------------------------------------------------------------------//
206 template <>
208 {
209  Teuchos::ArrayView<const double> bounds = domain.bounds();
210 
211  return !( ( d_bounds[0] > bounds[1] || d_bounds[1] < bounds[0] ) ||
212  ( d_bounds[2] > bounds[3] || d_bounds[3] < bounds[2] ) );
213 }
214 
215 //---------------------------------------------------------------------------//
223 template <>
225 {
226  Teuchos::ArrayView<const double> bounds = domain.bounds();
227 
228  return !( ( d_bounds[0] > bounds[1] || d_bounds[1] < bounds[0] ) ||
229  ( d_bounds[2] > bounds[3] || d_bounds[3] < bounds[2] ) ||
230  ( d_bounds[4] > bounds[5] || d_bounds[5] < bounds[4] ) );
231 }
232 
233 //---------------------------------------------------------------------------//
237 template <>
238 Teuchos::Array<double> CloudDomain<1>::center() const
239 {
240  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
241  return Teuchos::Array<double>( 1, ( d_bounds[1] + d_bounds[0] ) / 2.0 );
242 }
243 
244 //---------------------------------------------------------------------------//
248 template <>
249 Teuchos::Array<double> CloudDomain<2>::center() const
250 {
251  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
252  DTK_CHECK( d_bounds[2] <= d_bounds[3] );
253 
254  Teuchos::Array<double> center( 2 );
255  center[0] = ( d_bounds[1] + d_bounds[0] ) / 2.0;
256  center[1] = ( d_bounds[3] + d_bounds[2] ) / 2.0;
257  return center;
258 }
259 
260 //---------------------------------------------------------------------------//
264 template <>
265 Teuchos::Array<double> CloudDomain<3>::center() const
266 {
267  DTK_CHECK( d_bounds[0] <= d_bounds[1] );
268  DTK_CHECK( d_bounds[2] <= d_bounds[3] );
269  DTK_CHECK( d_bounds[4] <= d_bounds[5] );
270 
271  Teuchos::Array<double> center( 3 );
272  center[0] = ( d_bounds[1] + d_bounds[0] ) / 2.0;
273  center[1] = ( d_bounds[3] + d_bounds[2] ) / 2.0;
274  center[2] = ( d_bounds[5] + d_bounds[4] ) / 2.0;
275  return center;
276 }
277 
278 //---------------------------------------------------------------------------//
279 
280 } // end namespace DataTransferKit
281 
282 #endif // end DTK_CLOUDDOMAIN_IMPL_HPP
283 
284 //---------------------------------------------------------------------------//
285 // end DTK_CloudDomain.cpp
286 //---------------------------------------------------------------------------//
CloudDomain()
Default constructor.
Assertions and Design-by-Contract for error handling.
Axis-aligned Cartesian cloud domain container.
DTK_BasicEntitySet.cpp.
Cloud domain declaration.