Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
span.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
47 #ifndef SPAN_H_
48 #define SPAN_H_
49 
50 #include "../general/util.h"
51 #include "../config.h"
52 #include "geometry.h"
53 #include "../storage/stream.h"
54 #include "../storage/stream_vector.h"
55 
56 namespace mui {
57 
58 template<class CONFIG>
59 class span {
60 protected:
61  using container = std::vector<geometry::any_shape<CONFIG> >;
63 public:
64  span() {}
65 
67  parts.push_back(s);
68  return *this;
69  }
71  auto i = parts.begin();
72  while( i != parts.end() ) {
73  if ( !i->collide(s) ) i = parts.erase(i);
74  else ++i;
75  }
76  }
77  void reset() { parts.clear(); }
78 
79  bool collide( const geometry::any_shape<CONFIG>& other ) const {
80  for( const auto& my: parts )
81  if( mui::geometry::collide(my,other) ) return true;
82  return false;
83  }
84  bool collide( const span& other ) const {
85  for( const auto& r: other.parts )
86  if( this->collide(r) ) return true;
87  return false;
88  }
89 
91  if( parts.empty() ) return geometry::box<CONFIG>();
92  geometry::box<CONFIG> bx = parts.front().bbox();
93  for( std::size_t i=1; i<parts.size(); ++i ) bx = mui::geometry::bbox(bx,parts[i]);
94  return bx;
95  }
96 
97  void serialize( ostream& stream ) const {
98  stream << parts;
99  }
100  void deserialize( istream& stream ){
101  stream >> parts;
102  }
103 };
104 
105 template<typename CONFIG>
106 ostream& operator<< ( ostream& stream, const span<CONFIG>& data )
107 {
108  data.serialize(stream);
109  return stream;
110 }
111 
112 template<typename CONFIG>
114 {
115  data.deserialize(stream);
116  return stream;
117 }
118 
119 template<typename CONFIG>
120 bool collide( const span<CONFIG>& lhs, const span<CONFIG>& rhs )
121 {
122  return lhs.collide(rhs);
123 }
124 
125 template<typename CONFIG>
126 bool collide( const geometry::any_shape<CONFIG>& lhs, const span<CONFIG>& rhs )
127 {
128  return rhs.collide(lhs);
129 }
130 template<typename CONFIG>
131 bool collide( const span<CONFIG>& lhs, const geometry::any_shape<CONFIG>& rhs )
132 {
133  return lhs.collide(rhs);
134 }
135 
136 }
137 
138 #endif /* SPAN_H_ */
Definition: geometry.h:92
Definition: geometry.h:188
Definition: stream.h:61
Definition: stream.h:67
Definition: span.h:59
span()
Definition: span.h:64
geometry::box< CONFIG > bbox() const
Definition: span.h:90
void deserialize(istream &stream)
Definition: span.h:100
std::vector< geometry::any_shape< CONFIG > > container
Definition: span.h:61
container parts
Definition: span.h:62
span operator||(const geometry::any_shape< CONFIG > &s)
Definition: span.h:66
bool collide(const geometry::any_shape< CONFIG > &other) const
Definition: span.h:79
bool collide(const span &other) const
Definition: span.h:84
void serialize(ostream &stream) const
Definition: span.h:97
void reset()
Definition: span.h:77
void operator&&(const geometry::any_shape< CONFIG > &s)
Definition: span.h:70
Base classes for creating geometries, primarily used by spatial interpolation methods and for definin...
bool collide(const shape< CONFIG > &lhs, const shape< CONFIG > &rhs)
Definition: geometry.h:301
Definition: comm.h:54
istream & operator>>(istream &stream, smalluint &sml)
Definition: comm_tcp.h:103
ostream & operator<<(ostream &stream, const smalluint &sml)
Definition: comm_tcp.h:127
bool collide(const span< CONFIG > &lhs, const span< CONFIG > &rhs)
Definition: span.h:120