MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
R.h
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 #ifndef R_H
26 #define R_H
27 
28 #include <GeneralDefine.h>
29 #include <iostream>
30 #include "Math/Vector.h"
31 #include "Base_X_Y_Z.h"
32 #include <vector>
33 #include <array>
34 #include "Math/ExtendedMath.h"
35 
36 class BaseParticle;
37 
38 class BaseInteraction;
39 
40 class DPMBase;
41 
42 namespace CGCoordinates
43 {
44 
51 class R : public Base_X_Y_Z
52 {
53 public:
54 
58  static void writeNames(std::ostream& os);
59 
63  void write(std::ostream& os) const;
64 
69  static Mdouble getVolumeOfAveragedDimensions(const Vec3D& min, const Vec3D& max);
70 
75  Mdouble getDistanceSquared(const Vec3D& p) const;
76 
80  static Mdouble getLength(const Vec3D& p);
81 
86  void setR(Mdouble r);
87 
88  const Mdouble getR() const
89  { return r_; }
90 
96  Mdouble getINormal(const BaseInteraction& c, const Vec3D& normal) const;
97 
103  Mdouble getPNormal(const BaseInteraction& c, const Vec3D& normal) const;
104 
110  Mdouble getCNormal(const BaseInteraction& c, const Vec3D& normal) const;
111 
116  static void normalisePolynomialCoefficients(std::vector<Mdouble>& coefficients, Mdouble cutoff);
117 
122  Mdouble getWeight() override;
123 
124  static Mdouble getDomainVolume(const Vec3D& min, const Vec3D& max);
125 
126  static bool isResolvedIn(unsigned i) {return i==0?true:false;}
127 
128  static std::string getName();
129 
130 protected:
131 
136 };
137 
142 template<typename T>
143 typename std::enable_if<std::is_base_of<CGCoordinates::R, typename T::CoordinatesType>::value, void>::type
144 spaceEvenly(Vec3D min, Vec3D max, std::vector<std::size_t> nAll, std::vector<T>& points)
145 {
146  //note, the x-coordinate represents the r-coordinate here
147  std::size_t n = nAll[0];
148  Mdouble start = min.X;
149  Mdouble delta = (max.X - start) / n;
150 // Mdouble end = sqrt(mathsFunc::square(std::fmax(-min.X,max.X))+mathsFunc::square(std::fmax(-min.Y,max.Y)));
151 // Mdouble start = 0;
152 // Mdouble delta = (end - start) / n;
153  if (start < 0.0)
154  {
155  if (max.X > 0.0)
156  {
157  start = 0.0;
158  }
159  else
160  {
161  start = -max.X;
162  delta = (-min.X - start) / n;
163  }
164  std::cerr << "Warning: r should be positive, but x-limits are not;"
165  "grid is set within " << start << "<r<" << start + delta * (n + 1) << std::endl;
166  }
167  start += 0.5 * delta;
168  points.resize(n);
169  for (std::size_t i = 0; i < n; i++)
170  {
171  points[i].coordinates.setR(start + delta * i);
172  }
173 }
174 
175 }
176 #endif
static Mdouble getDomainVolume(const Vec3D &min, const Vec3D &max)
Definition: R.cc:123
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:72
Mdouble X
the vector components
Definition: Vector.h:65
Mdouble getINormal(const BaseInteraction &c, const Vec3D &normal) const
For the Interaction between particles/walls P and I, this function returns the dot product between th...
Definition: R.cc:67
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
static std::string getName()
Definition: R.cc:129
Mdouble r_
Definition: R.h:135
static Mdouble getLength(const Vec3D &p)
Returns the length of the input vector in the non-averaged directions.
Definition: R.cc:57
std::enable_if< std::is_base_of< CGCoordinates::O, typename T::CoordinatesType >::value, void >::type spaceEvenly(Vec3D min, Vec3D max, std::vector< std::size_t > nAll, std::vector< T > &points)
Definition: O.h:101
void write(std::ostream &os) const
Writes the coordinates in human-readable form to an ostream.
Definition: R.cc:37
Stores information about interactions between two interactable objects; often particles but could be ...
Mdouble getCNormal(const BaseInteraction &c, const Vec3D &normal) const
For the Interaction between particles/walls P and I, this function returns the dot product between th...
Definition: R.cc:91
Mdouble getWeight() override
Definition: R.cc:118
static bool isResolvedIn(unsigned i)
Definition: R.h:126
Mdouble getPNormal(const BaseInteraction &c, const Vec3D &normal) const
For the Interaction between particles/walls P and I, this function returns the dot product between th...
Definition: R.cc:79
Defines the non-averaged directions on which spatial coarse-graining is applied (the x-direction for ...
Definition: R.h:51
Contains common member functions of the X, Y, and Z classes.
Definition: Base_X_Y_Z.h:48
Mdouble getDistanceSquared(const Vec3D &p) const
Returns the square of the distance between the particle p and the current CGPoint, in the non-averaged directions.
Definition: R.cc:62
static void normalisePolynomialCoefficients(std::vector< Mdouble > &coefficients, Mdouble cutoff)
Normalises the coefficients of Polynomial CGFunction such that the integral over all non-averaged dim...
Definition: R.cc:108
void setR(Mdouble r)
Returns the position of the current CGPoint, in the non-averaged directions.
Definition: R.cc:47
const Mdouble getR() const
Definition: R.h:88
Definition: Vector.h:49
static Mdouble getVolumeOfAveragedDimensions(const Vec3D &min, const Vec3D &max)
returns the factor the CGFunction has to be divided by, due to integrating the variables over the ave...
Definition: R.cc:42
static void writeNames(std::ostream &os)
Writes the coordinate names in human-readable form to an ostream.
Definition: R.cc:32