MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HGridOptimiser.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 
26 #ifndef HGRIDOPTIMIZER_H
27 #define HGRIDOPTIMIZER_H
28 
29 #include <vector>
30 #include "MercuryBase.h"
31 
37 {
38 public:
42  void initialise(const MercuryBase& problem, unsigned int numberOfCells, int verbosity);
43 
47  void initialisePolyFunc(double omega, std::vector<double>& coeff, unsigned int numberOfCells, int verbosity);
48 
52  unsigned int radius2Cell(double r);
53 
57  unsigned int radius2IntCell(double r);
58 
62  double intCell2Min(unsigned int i);
63 
67  double intCell2Max(unsigned int i);
68 
72  double cell2Min(unsigned int i);
73 
77  double cell2Max(unsigned int i);
78 
82  double pdfIntCell(double start, double end, unsigned int i, int p);
83 
87  double pdfInt(double start, double end, int power);
88 
92  double diffPdfInt(double x, int power);
93 
97  double expectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h);
98 
102  double diffHExpectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h);
103 
107  double expectedCellsIntegralCellDenominator(double start, double end, unsigned int i);
108 
112  double expectedCellsIntegral(double start, double end, int p, double h);
113 
117  double diffStartExpectedCellsIntegral(double start, double end, int p, double h);
118 
122  double diffEndExpectedCellsIntegral(double start, double end, int p, double h);
123 
127  double diffHExpectedCellsIntegral(double start, double end, int p, double h);
128 
132  double calculateWork(std::vector<double>& hGridCellSizes, HGridMethod method, int verbosity);
133 
137  void calculateDiffWork(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, HGridMethod method, int verbosity);
138 
142  void calcDfDx(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, HGridMethod method, int verbosity);
143 
147  double checkLimit(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, int verbosity);
148 
152  void applyStep(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, double stepsize, int verbosity);
153 
157  double goldenSectionSearch(std::vector<double>& startHGridCellSizes, std::vector<double>& searchDirection, double min, double cur, double max, HGridMethod method, int verbosity);
158 
162  void getOptimalDistribution(std::vector<double>& hGridCellSizes, unsigned int numberOfLevels, HGridMethod method, int verbosity);
163 
167  void histNumberParticlesPerCell(std::vector<double>& hGridCellSizes);
168 
169 private:
173  unsigned int numCells_;
178  double rMin_;
183  double rMax_;
184 
191  double length_;
202  unsigned int dimension_;
203 
204  //Something with cells. Still have to find out which property the double represents.
205  //Could be the number of particles in that cell (see initialise), but then
206  //you'd expect an unsigned int and not a double.
207  std::vector<double> cellN_;
208  std::vector<double> intCellN;
209 };
210 
211 #endif
212 
double goldenSectionSearch(std::vector< double > &startHGridCellSizes, std::vector< double > &searchDirection, double min, double cur, double max, HGridMethod method, int verbosity)
void getOptimalDistribution(std::vector< double > &hGridCellSizes, unsigned int numberOfLevels, HGridMethod method, int verbosity)
double diffPdfInt(double x, int power)
diff(int(f(r)*r^power*dr,r=s..e)/int(f(r)*dr,r=0..omega),e)=f(e)*e^power/int(f(r)*dr,r=0..omega)
double cell2Min(unsigned int i)
Computes the left bound of the cell with given ordinal number.
void initialisePolyFunc(double omega, std::vector< double > &coeff, unsigned int numberOfCells, int verbosity)
double calculateWork(std::vector< double > &hGridCellSizes, HGridMethod method, int verbosity)
The amount of work that has to be done to run a simulation using the HGrid, in steps.
double length_
The weighted length of the domain.
double diffStartExpectedCellsIntegral(double start, double end, int p, double h)
double intCell2Min(unsigned int i)
double cell2Max(unsigned int i)
Computes the right bound of the cell with given ordinal number.
double intCell2Max(unsigned int i)
void initialise(const MercuryBase &problem, unsigned int numberOfCells, int verbosity)
HGridMethod
Enum class that indicates how particles in different levels (cross level checking) of the HGrid are c...
Definition: MercuryBase.h:45
double expectedCellsIntegral(double start, double end, int p, double h)
This function calculates: int((2*r/h+2)^d f(r) dr,r=s..e)/int(f(r) dr,r=s..e)+ Used to calculated the...
void calculateDiffWork(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, HGridMethod method, int verbosity)
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:127
void histNumberParticlesPerCell(std::vector< double > &hGridCellSizes)
double diffHExpectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h)
void calcDfDx(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, HGridMethod method, int verbosity)
double rMax_
Radius of the largest particle, "rounded" to the smallest double that is larger than the radius of ea...
double expectedCellsIntegralCellDenominator(double start, double end, unsigned int i)
double checkLimit(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, int verbosity)
std::vector< double > cellN_
void applyStep(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, double stepsize, int verbosity)
double rMin_
Radius of the smallest particle, "rounded" to the largest double that is smaller than the radius of e...
std::vector< double > intCellN
unsigned int dimension_
The dimension of the system, usually 3, sometimes 2 or 1.
double cellCheckOverContactCheckRatio_
The ratio of the time required for a single geometric contact detection over the time required to ret...
double diffHExpectedCellsIntegral(double start, double end, int p, double h)
unsigned int radius2Cell(double r)
Assigns a BaseParticle of given radius to a certain cell.
double pdfIntCell(double start, double end, unsigned int i, int p)
double pdfInt(double start, double end, int power)
This function calculates: int(f(r)*r^power*dr,r=start..end)/int(f(r)*dr,r=0..omega) with r=a*r+b...
double expectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h)
unsigned int numCells_
Number of cells, usually called levels in the HGrid.
double diffEndExpectedCellsIntegral(double start, double end, int p, double h)
unsigned int radius2IntCell(double r)