MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Box.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "Box.h"
26 #include "Math/Vector.h"
27 #include "Panel.h"
28 #include "Sphere.h"
29 
30 Box::Box(int maxLevel, int nTerms) : maxLevel_(maxLevel), p_(nTerms)
31 {
32  for (int iL = 0; iL <= maxLevel; iL++)
33  {
34  std::vector<Panel*>* boxLevel = new std::vector<Panel*>;
35  levels_.push_back(*boxLevel);
36  }
37 }
38 
39 void Box::addPanel(int level, Panel* panel)
40 {
41  levels_[level].push_back(panel);
42 }
43 
45 {
46  std::cout << "============================" << std::endl;
47  std::cout << "Starting the upward pass." << std::endl;
48  // Perform a multipole expansion about the centre of all panels located on the finest mesh
49  std::cout << "Computing multipole expansion on finest level." << std::endl;
50  for (Panel* panel : levels_[maxLevel_])
51  {
52  panel->computeMultipoleExpansion();
53  }
54 
55  // Perform an upward pass, each level combine the previous level multipole expansions by shifting them to the centre of the current panel
56  for (int iL = maxLevel_ - 1; iL >= 0; iL--)
57  {
58  std::cout << "Shifting multipole expansions on level " << iL << "." << std::endl;
59  for (Panel* panel : levels_[iL])
60  {
61  panel->translateMultipoleExpansion();
62  }
63  }
64  std::cout << "Finished upward pass." << std::endl;
65 
66 }
67 
69 {
70  std::cout << "============================" << std::endl;
71  std::cout << "Starting the downward pass." << std::endl;
72 
73  //Set the first part of the local expansion to zero: everything is in the interaction list or closer
74  NumericalVector<std::complex<Mdouble>> localExpansionCoefficients;
75  for (Panel* panel : levels_[1])
76  {
77  panel->setLocalExpansionZero();
78  }
79 
80  // Compute all local expansions for intermediate levels
81  for (int iL = 1; iL < maxLevel_; iL++)
82  {
83  std::cout << "Computing nearby Local Expansions on level " << iL << "." << std::endl;
84  for (Panel* panel : levels_[iL])
85  {
86  panel->computePartialLocalExpansion();
87  panel->computeLocalExpansion();
88 
89  }
90 
91  std::cout << "Translating local expansions to children" << std::endl;
92  for (Panel* panel : levels_[iL])
93  {
94  panel->translateLocalExpansion();
95  }
96  }
97 
98  // Compute local expansions for the remaining interaction list on the finest level
99  std::cout << "Computing nearby local expansions on finest level " << std::endl;
100  for (Panel* panel : levels_[maxLevel_])
101  {
102  panel->computePartialLocalExpansion();
103  panel->computeLocalExpansion();
104  }
105 
106  std::cout << "Finished downward pass." << std::endl;
107 }
108 
109 void Box::computeFlow(int k)
110 {
111  //***************************************
112  //* Initialise spheres *
113  //***************************************
114 
115  // The first step is to add dipoles with correct location and strengths in the domain
116  // All dipoles in the domain are now expanded into multipoles
117  std::cout << "Initialising spheres" << std::endl;
118  upwardPass();
119  downwardPass();
120 
121  //For all panels on the finest level
122  for (Panel* panel : levels_[maxLevel_])
123  {
124  //For all dipoles on the finest level
125  for (Dipole* iD : panel->getDipoles())
126  {
127  // Add a multipole in the domain
128  //Multipole* multipole = new Multipole(iD->getP, iD->getSquaredFactorials, iD->getLocation());
129  //panel->multipoles_.push_back(multipole);
130 
131  // Construct a sphere
132  //Sphere* sphere = new Sphere(panel, iD->getLocation(), iD, multipole);
133 
134  // Add the sphere to the list of spheres and to the panel list
135  //spheres_.push_back(sphere);
136  //spheres_.push_back(sphere);
137  }
138  }
139 
140  //***********************************
141  //* Compue Mirror Multipoles *
142  //***********************************
143 
144 
145  // Compute k order mirrors
146  for (int i = 1; k <= i; i++)
147  {
148  //For all panels on the finest level
149  for (Panel* panel : levels_[maxLevel_])
150  {
151  // For all spheres: add a new multipole to the centre of a sphere to compensate
152  for (Sphere* sphere : panel->getSpheres())
153  {
154  std::vector<std::complex<Mdouble>> localExpansionAroundSphere;
155  Vec3D sphereCentre = sphere->getLocation();
156 
157  // Compute panel local expansion around sphere
158  //localExpansionAroundSphere = panel->localExpansionAroundCentre_->translateLocalExpansion(sphereCentre);
159 
160  // Compute other sphere local expansion around sphere
161  for (Sphere* sphereOther: spheres_)
162  {
163  if (sphereOther != sphere)
164  {
165  // todo: implement this shizzle
166  //localExpansionAroundSphere += sphereOther->multipole_->convertMultipoleToLocal(sphereCentre);
167  }
168  }
169  // Compute multipole
170  size_t nTerms = (p_ + 1) * (p_ + 1);
171  NumericalVector<std::complex<Mdouble>> multipoleExpansionCoefficients(nTerms);
172  for (int n = 0; n <= p_; n++)
173  {
174  for (int m = -n; m <= n; m++)
175  {
176  int location = n * n + (m + n);
177  //multipoleExpansionCoefficients[location] = localExpansionAroundSphere[0]*n/(n+1)*std::pow(sphere->getRadius,2n+1);
178  }
179  }
180  //sphere->multipole_->setExpansionCoefficients(multipoleExpansionCoefficients);
181  }
182  }
183 
184  //Perform and upward and downward pass to compute the new coefficients
185  upwardPass();
186  downwardPass();
187  }
188 
189 
190 }
191 
192 
193 
194 
195 
196 
197 
198 
Definition: Panel.h:42
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Definition: Dipole.h:34
void computeFlow(int k)
Definition: Box.cc:109
void upwardPass()
Definition: Box.cc:44
int maxLevel_
Definition: Box.h:61
int p_
Definition: Box.h:62
void addPanel(int level, Panel *panel)
Definition: Box.cc:39
Box(int maxLevel, int nTerms)
Definition: Box.cc:30
std::vector< std::vector< Panel * > > levels_
Definition: Box.h:63
Definition: Sphere.h:34
std::vector< Sphere * > spheres_
Definition: Box.h:64
Definition: Vector.h:49
void downwardPass()
Definition: Box.cc:68