MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
R.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 "R.h"
27 #include "Particles/BaseParticle.h"
28 #include "DPMBase.h"
29 
30 using namespace CGCoordinates;
31 
32 void R::writeNames(std::ostream& os)
33 {
34  os << "r ";
35 }
36 
37 void R::write(std::ostream& os) const
38 {
39  os << r_ << ' ';
40 }
41 
43 {
44  return (max.Z - min.Z);//2*constants::pi
45 }
46 
48 {
49  r_ = r;
50 }
51 
58 {
59  return sqrt(p.X * p.X + p.Y * p.Y);
60 }
61 
63 {
64  return mathsFunc::square(getLength(p) - r_);
65 }
66 
67 Mdouble R::getINormal(const BaseInteraction& c, const Vec3D& normal) const
68 {
69  if (Vec3D::dot(c.getContactPoint(), normal) > 0)
70  {
71  return (getLength(c.getI()->getPosition()) - r_);
72  }
73  else
74  {
75  return -(getLength(c.getI()->getPosition()) - r_);
76  }
77 }
78 
79 Mdouble R::getPNormal(const BaseInteraction& c, const Vec3D& normal) const
80 {
81  if (Vec3D::dot(c.getContactPoint(), normal) > 0)
82  {
83  return (getLength(c.getP()->getPosition()) - r_);
84  }
85  else
86  {
87  return -(getLength(c.getP()->getPosition()) - r_);
88  }
89 }
90 
91 Mdouble R::getCNormal(const BaseInteraction& c, const Vec3D& normal) const
92 {
93  if (Vec3D::dot(c.getContactPoint(), normal) > 0)
94  {
95  return (getLength(c.getContactPoint()) - r_);
96  }
97  else
98  {
99  return -(getLength(c.getContactPoint()) - r_);
100  }
101 }
102 
108 void R::normalisePolynomialCoefficients(std::vector<Mdouble>& coefficients, Mdouble cutoff)
109 {
110  Mdouble volume = 0.0;
111  for (std::size_t i = 0; i < coefficients.size(); i++)
112  volume += coefficients[i] / static_cast<Mdouble>(i + 1);
113  volume *= 2.0 * cutoff;
114  for (double& coefficient : coefficients)
115  coefficient /= volume;
116 }
117 
119 {
120  return r_;
121 }
122 
123 Mdouble R::getDomainVolume(const Vec3D& min, const Vec3D& max)
124 {
125  //note, the x-coordinate represents the r-coordinate here
126  return constants::pi * (max.X * max.X - min.X * min.X) * (max.Z - min.Z);
127 }
128 
129 std::string R::getName()
130 {
131  return "R";
132 }
static Mdouble getDomainVolume(const Vec3D &min, const Vec3D &max)
Definition: R.cc:123
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
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
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
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
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
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
const Mdouble pi
Definition: ExtendedMath.h:45
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
Mdouble Y
Definition: Vector.h:65
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
Definition: Vector.h:49
T square(const T val)
squares a number
Definition: ExtendedMath.h: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: R.cc:42
Mdouble Z
Definition: Vector.h:65
static void writeNames(std::ostream &os)
Writes the coordinate names in human-readable form to an ostream.
Definition: R.cc:32