summaryrefslogtreecommitdiff
path: root/src/utilities/hyperplaneLattice2D.hh
blob: 94d101ddfc545efc4785160d9b3449134c446a3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2018 Adrian Kummerlaender
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
*/

#ifndef HYPERPLANE_LATTICE_2D_HH
#define HYPERPLANE_LATTICE_2D_HH

#include "hyperplaneLattice2D.h"

namespace olb {

template <typename T>
int HyperplaneLattice2D<T>::computeMaxLatticeDistance() const
{
  const Cuboid2D<T>&  cuboid = _geometry.getMotherCuboid();
  const Vector<T,2>   origin = cuboid.getOrigin();
  const Vector<int,2> extend = cuboid.getExtend();
  const T             deltaR = cuboid.getDeltaR();

  T maxPhysDistance = T();
  T tmp;
  Vector<T,2> tmpO;
  Vector<T,2> tmpE;

  for(int iDim=0; iDim<2; ++iDim){
  tmpO[iDim] = origin[iDim] - _origin[iDim];
  tmpE[iDim] = origin[iDim] + extend[iDim]*deltaR - _origin[iDim];
  }
  tmp = sqrt(tmpO[0]*tmpO[0] + tmpO[1]*tmpO[1]);
  if (maxPhysDistance < tmp) {
      maxPhysDistance = tmp;
  }
  tmp = sqrt((tmpE[0]*tmpE[0] + tmpO[1]*tmpO[1]));
  if (maxPhysDistance < tmp) {
      maxPhysDistance = tmp;
  }
  tmp = sqrt(tmpO[0]*tmpO[0] + tmpE[1]*tmpE[1]);
  if (maxPhysDistance < tmp) {
      maxPhysDistance = tmp;
  }
  tmp = sqrt(tmpE[0]*tmpE[0] + tmpE[1]*tmpE[1]);
  if (maxPhysDistance < tmp) {
      maxPhysDistance = tmp;
  }

  return int(maxPhysDistance/_h) + 1;
}

template <typename T>
void HyperplaneLattice2D<T>::constructCuboid(int maxLatticeDistance)
{
  int iC;
  int min = -maxLatticeDistance;
  int max = maxLatticeDistance;

  for ( int i = -maxLatticeDistance; i < maxLatticeDistance; ++i ) {
    if ( _geometry.getC(getPhysR(i), iC) ) {
      min = i;
      break;
    }
  }
  for ( int i = maxLatticeDistance; i > -maxLatticeDistance; --i ) {
    if ( _geometry.getC(getPhysR(i), iC) ) {
      max = i;
      break;
    }
  }

  _n = max - min + 1;
  _origin = _origin + double(min)*_u;
}

template <typename T>
void HyperplaneLattice2D<T>::setToResolution(int resolution)
{
  T newH = _n*_h/(T) resolution;
  _n = resolution;
  _h = newH;
  _u.normalize(_h);
}

template<typename T>
HyperplaneLattice2D<T>::HyperplaneLattice2D(
  CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane)
  : _geometry(geometry),
    _hyperplane(hyperplane),
    _origin(hyperplane.origin),
    _u(hyperplane.u),
    _h(geometry.getMinDeltaR())
{
  _u.normalize(_h);

  const int maxLatticeDistance = computeMaxLatticeDistance();
  // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
  constructCuboid(maxLatticeDistance);
}

template<typename T>
HyperplaneLattice2D<T>::HyperplaneLattice2D(
  CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane, int resolution)
  : _geometry(geometry),
    _hyperplane(hyperplane),
    _origin(hyperplane.origin),
    _u(hyperplane.u),
    _h(geometry.getMinDeltaR())
{
  _u.normalize(_h);

  const int maxLatticeDistance = computeMaxLatticeDistance();
  // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
  constructCuboid(maxLatticeDistance);

  if ( resolution > 0 ) {
    setToResolution(resolution);
  }
}

template<typename T>
HyperplaneLattice2D<T>::HyperplaneLattice2D(
  CuboidGeometry2D<T>& geometry, Hyperplane2D<T> hyperplane, T h)
  : _geometry(geometry),
    _hyperplane(hyperplane),
    _origin(hyperplane.origin),
    _u(hyperplane.u),
    _h(h)
{
  if ( util::nearZero(_h) ) {
    _h = _geometry.getMinDeltaR();
  }

  _u.normalize(_h);

  const int maxLatticeDistance = computeMaxLatticeDistance();
  // compute _hyperplane.origin, _nx, _ny so that the cuboid is right inside the geometry
  constructCuboid(maxLatticeDistance);
}

template <typename T>
const Hyperplane2D<T>& HyperplaneLattice2D<T>::getHyperplane() const
{
  return _hyperplane;
}

template <typename T>
Vector<T,2> HyperplaneLattice2D<T>::getPhysR(const int& n) const
{
  return Vector<T,2> {
    _origin[0] + double(n)*_u[0],
    _origin[1] + double(n)*_u[1]
  };
}

template <typename T>
int HyperplaneLattice2D<T>::getN() const
{
  return _n;
}

template <typename T>
T HyperplaneLattice2D<T>::getPhysSpacing() const
{
  return _h;
}

template <typename T>
Vector<T,2> HyperplaneLattice2D<T>::getPhysOrigin() const
{
  return _origin;
}

template <typename T>
Vector<T,2> HyperplaneLattice2D<T>::getVectorU() const
{
  return _u;
}


}

#endif