HGridOptimiser.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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,
138  int verbosity);
139 
143  void calcDfDx(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, HGridMethod method, int verbosity);
144 
148  double checkLimit(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, int verbosity);
149 
153  void applyStep(std::vector<double>& hGridCellSizes, std::vector<double>& dfdx, double stepsize, int verbosity);
154 
158  double
159  goldenSectionSearch(std::vector<double>& startHGridCellSizes, std::vector<double>& searchDirection, double min,
160  double cur, double max, HGridMethod method, int verbosity);
161 
165  void getOptimalDistribution(std::vector<double>& hGridCellSizes, unsigned int numberOfLevels, HGridMethod method,
166  int verbosity);
167 
171  void histNumberParticlesPerCell(std::vector<double>& hGridCellSizes);
172 
173 private:
177  unsigned int numCells_;
182  double rMin_;
187  double rMax_;
195  double length_;
206  unsigned int dimension_;
207 
208  //Something with cells. Still have to find out which property the double represents.
209  //Could be the number of particles in that cell (see initialise), but then
210  //you'd expect an unsigned int and not a double.
211  std::vector<double> cellN_;
212  std::vector<double> intCellN;
213 };
214 
215 #endif
216 
HGridMethod
Enum class that indicates how particles in different levels (cross level checking) of the HGrid are c...
Definition: MercuryBase.h:44
Definition: HGridOptimiser.h:37
double pdfInt(double start, double end, int power)
Definition: HGridOptimiser.cc:224
double diffStartExpectedCellsIntegral(double start, double end, int p, double h)
Definition: HGridOptimiser.cc:353
double goldenSectionSearch(std::vector< double > &startHGridCellSizes, std::vector< double > &searchDirection, double min, double cur, double max, HGridMethod method, int verbosity)
Definition: HGridOptimiser.cc:984
unsigned int dimension_
The dimension of the system, usually 3, sometimes 2 or 1.
Definition: HGridOptimiser.h:206
double checkLimit(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, int verbosity)
Definition: HGridOptimiser.cc:902
unsigned int numCells_
Number of cells, usually called levels in the HGrid.
Definition: HGridOptimiser.h:177
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,...
Definition: HGridOptimiser.cc:261
double expectedCellsIntegral(double start, double end, int p, double h)
Definition: HGridOptimiser.cc:323
double diffEndExpectedCellsIntegral(double start, double end, int p, double h)
Definition: HGridOptimiser.cc:394
double expectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h)
Definition: HGridOptimiser.cc:275
double diffHExpectedCellsIntegral(double start, double end, int p, double h)
Definition: HGridOptimiser.cc:434
void calcDfDx(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, HGridMethod method, int verbosity)
Definition: HGridOptimiser.cc:878
double rMax_
Radius of the largest particle, "rounded" to the smallest double that is larger than the radius of ea...
Definition: HGridOptimiser.h:187
void histNumberParticlesPerCell(std::vector< double > &hGridCellSizes)
Definition: HGridOptimiser.cc:1095
std::vector< double > intCellN
Definition: HGridOptimiser.h:212
double diffHExpectedCellsIntegralCellNumerator(double start, double end, unsigned int i, int p, double h)
Definition: HGridOptimiser.cc:290
void initialisePolyFunc(double omega, std::vector< double > &coeff, unsigned int numberOfCells, int verbosity)
Definition: HGridOptimiser.cc:110
double pdfIntCell(double start, double end, unsigned int i, int p)
Definition: HGridOptimiser.cc:213
std::vector< double > cellN_
Definition: HGridOptimiser.h:211
double cell2Min(unsigned int i)
Computes the left bound of the cell with given ordinal number.
Definition: HGridOptimiser.cc:200
void getOptimalDistribution(std::vector< double > &hGridCellSizes, unsigned int numberOfLevels, HGridMethod method, int verbosity)
Definition: HGridOptimiser.cc:1043
double cellCheckOverContactCheckRatio_
The ratio of the time required for a single geometric contact detection over the time required to ret...
Definition: HGridOptimiser.h:202
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.
Definition: HGridOptimiser.cc:728
double cell2Max(unsigned int i)
Computes the right bound of the cell with given ordinal number.
Definition: HGridOptimiser.cc:208
void calculateDiffWork(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, HGridMethod method, int verbosity)
Definition: HGridOptimiser.cc:463
double length_
The weighted length of the domain.
Definition: HGridOptimiser.h:195
double rMin_
Radius of the smallest particle, "rounded" to the largest double that is smaller than the radius of e...
Definition: HGridOptimiser.h:182
void applyStep(std::vector< double > &hGridCellSizes, std::vector< double > &dfdx, double stepsize, int verbosity)
Definition: HGridOptimiser.cc:966
unsigned int radius2Cell(double r)
Assigns a BaseParticle of given radius to a certain cell.
Definition: HGridOptimiser.cc:165
void initialise(const MercuryBase &problem, unsigned int numberOfCells, int verbosity)
Definition: HGridOptimiser.cc:33
double expectedCellsIntegralCellDenominator(double start, double end, unsigned int i)
Definition: HGridOptimiser.cc:312
unsigned int radius2IntCell(double r)
Definition: HGridOptimiser.cc:173
double intCell2Min(unsigned int i)
Definition: HGridOptimiser.cc:181
double intCell2Max(unsigned int i)
Definition: HGridOptimiser.cc:189
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:126
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51