MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XYZ.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 
26 #include "XYZ.h"
27 #include "Particles/BaseParticle.h"
28 #include "DPMBase.h"
29 
30 using namespace CGCoordinates;
31 
32 void XYZ::writeNames(std::ostream& os)
33 {
34  os << "x y z ";
35 }
36 
40 void XYZ::write(std::ostream& os) const
41 {
42  os << p_ << ' ';
43 }
44 
54 {
55  return 1.0;
56 }
57 
62 {
63  p_ = p;
64 }
65 
74 {
75  return Vec3D::getLengthSquared(p_ - p);
76 }
77 
84 {
85  return sqrt(p.X * p.X + p.Y * p.Y + p.Z * p.Z);
86 }
87 
94 Mdouble XYZ::getINormal(const BaseInteraction& c, const Vec3D& normal) const
95 {
96  return Vec3D::dot(c.getI()->getPosition() - p_, c.getNormal());
97 }
98 Mdouble XYZ::getPNormal(const BaseInteraction& c, const Vec3D& normal) const
105 {
106  return Vec3D::dot(c.getP()->getPosition() - p_, c.getNormal());
107 }
108 Mdouble XYZ::getCNormal(const BaseInteraction& c, const Vec3D& normal) const
115 {
116  return Vec3D::dot(c.getContactPoint() - p_, c.getNormal());
117 }
118 
127 {
128  return Vec3D::getLengthSquared(c.getP()->getPosition() - p_) - mathsFunc::square(pNormal);
129 }
130 
139 {
140  //Wolfram alpha: erf(c/(sqrt(2) w))-(sqrt(2/pi) c e^(-c^2/(2 w^2)))/w
141  Mdouble prefactor = 1.0 / (constants::sqrt_2 * constants::sqrt_pi * width);
142  Mdouble cw = cutoff / width;
143  return mathsFunc::cubic(prefactor) / (
144  erf(cw / constants::sqrt_2)
146  );
147 }
148 
158 {
159  Mdouble widthSqrt2 = width * constants::sqrt_2;
160  Mdouble a = -cutoff;
161  Mdouble b = cutoff + distance;
162  //full 2D prefactor
163  Mdouble prefactor = 1.0 / (constants::sqrt_2 * constants::sqrt_pi * width);
164  prefactor = mathsFunc::square(prefactor) / (1.0 - exp(-0.5 * mathsFunc::square(cutoff / width)));
165  return prefactor * 0.5 / (
166  +erf(b / widthSqrt2) * b
167  + widthSqrt2 / constants::sqrt_pi * exp(-mathsFunc::square(b / widthSqrt2))
168  - erf(a / widthSqrt2) * a
169  - widthSqrt2 / constants::sqrt_pi * exp(-mathsFunc::square(a / widthSqrt2))
170  );
171 }
172 
180 void XYZ::normalisePolynomialCoefficients(std::vector<Mdouble>& coefficients, Mdouble cutoff)
181 {
182  Mdouble volume = 0.0;
183  for (std::size_t i = 0; i < coefficients.size(); i++)
184  volume += coefficients[i] / static_cast<Mdouble>(i + 3);
185  volume *= 4.0 * constants::pi * mathsFunc::cubic(cutoff);
186  for (double& coefficient : coefficients)
187  coefficient /= volume;
188 }
189 
190 const unsigned XYZ::countVariables()
191 {
192  return 3;
193 }
194 
195 std::string XYZ::getName()
196 {
197  return "XYZ";
198 }
199 
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: XYZ.cc:94
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Mdouble X
the vector components
Definition: Vector.h:65
void write(std::ostream &os) const
Writes the coordinates in human-readable form to an ostream.
Definition: XYZ.cc:40
static Mdouble getGaussIntegralPrefactor(Mdouble distance, Mdouble width, Mdouble cutoff)
Computes the prefactor of the Gauss line integral, which is dependent on the number of non-averaged d...
Definition: XYZ.cc:157
double Mdouble
Definition: GeneralDefine.h:34
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:84
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
const Mdouble sqrt_pi
Definition: ExtendedMath.h:46
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: XYZ.cc:114
const Vec3D & getContactPoint() const
Gets constant reference to contact point (vector).
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle)...
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
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: XYZ.cc:180
T cubic(const T val)
calculates the cube of a number
Definition: ExtendedMath.h:113
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:184
Stores information about interactions between two interactable objects; often particles but could be ...
static std::string getName()
Definition: XYZ.cc:195
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
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: XYZ.cc:73
static void writeNames(std::ostream &os)
Writes the coordinate names in human-readable form to an ostream.
Definition: XYZ.cc:32
const Mdouble pi
Definition: ExtendedMath.h:45
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: XYZ.cc:104
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: XYZ.cc:53
#define UNUSED
Definition: GeneralDefine.h:39
const Mdouble sqrt_2
Definition: ExtendedMath.h:48
void setXYZ(Vec3D p)
Returns the position of the current CGPoint, in the non-averaged directions.
Definition: XYZ.cc:61
Mdouble Y
Definition: Vector.h:65
static Mdouble getGaussPrefactor(Mdouble width, Mdouble cutoff)
Computes the prefactor of the Gauss CGFunction, which is dependent on the number of non-averaged dime...
Definition: XYZ.cc:138
Definition: Vector.h:49
T square(const T val)
squares a number
Definition: ExtendedMath.h:104
Mdouble getTangentialSquared(const BaseInteraction &c, Mdouble pNormal) const
For the Interaction between particles/walls P and I, this function returns the square of the minimum ...
Definition: XYZ.cc:126
Mdouble Z
Definition: Vector.h:65
static Mdouble getLength(const Vec3D &p)
Returns the length of the input vector in the non-averaged directions.
Definition: XYZ.cc:83
static const unsigned countVariables()
Definition: XYZ.cc:190