31 const double tol = 1.e-10;
35 std::pair<util::Point, util::Point> box = {
util::Point(),
41 for (
size_t i=0; i<2; i++)
42 for (
size_t j=0; j<2; j++)
43 for (
size_t k=0; k<2; k++) {
45 auto p =
util::Point(
double(i),
double(j),
double(k));
47 for (
auto q : corner_pts) {
52 errExit(std::format(
"Error: Can not find corner point {}\n", p.printStr()));
56 errExit(
"Error: getCenter()\n");
62 errExit(
"Error: triangleArea()\n");
67 std::vector<double> x = {1., 0., 0.};
68 std::vector<double> y_check = {1./std::sqrt(2.), -1./std::sqrt(2.), 0.};
71 errExit(
"Error: rotateCW2D()\n");
74 errExit(
"Error: rotateCW2D()\n");
76 y_check = {1./std::sqrt(2.), 1./std::sqrt(2.), 0.};
79 errExit(
"Error: rotateACW2D()\n");
88 if (y_check.dist(y) > tol)
89 errExit(std::format(
"Error: rotate(). y_check = {}, y = {}\n", y_check.printStr(), y.printStr()));
94 if (y_check.dist(y) > tol)
95 errExit(std::format(
"Error: rotate(). y_check = {}, y = {}\n", y_check.printStr(), y.printStr()));
102 if (std::abs(M_PI*0.25 -
util::angle(x1, x2)) > tol)
106 if (std::abs(M_PI*0.5 -
util::angle(x1, x2)) > tol)
118 const std::vector<double> Ks = {2.16e7, 1.0e4, 1.0e5,
119 159.2e9, 216000.0, 2.0e9, 1.23e9};
120 const std::vector<double> hs = {6.0e-4, 2.0e-4, 4.0e-4,
121 3.0e-3, 3.2e-4, 1.25e-3, 3.75e-3};
123 size_t n_checked = 0;
128 for (
int p : {4, 5}) {
129 const double expected =
134 "normalContactStiffness({}, {}, {}, {}) = {:.20g}, expected "
135 "{:.20g}: the replaced expression gave a different value\n",
136 K1, K2, h, p, got, expected));
144 const double expected = (18. / (M_PI * std::pow(h, 5))) * K1;
148 "selfContactStiffness({}, {}) = {:.20g}, expected {:.20g}: the "
149 "order of operations differs from the one in BaseParticle\n",
150 K1, h, got, expected));
158 errExit(std::format(
"harmonicMean({0}, {0}) != {0}\n", K));
164 }
catch (
const std::exception &) {
168 errExit(
"normalContactStiffness accepted a zero horizon\n");
170 std::cout << std::format(
171 "testContactStiffness: {} values equal to the replaced expressions\n",
void errExit(std::string msg)
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
std::vector< std::pair< util::Point, util::Point > > getEdges(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
double triangleArea(const util::Point &x1, const util::Point &x2, const util::Point &x3)
Compute area of triangle.
void testContactStiffness()
Checks the contact-stiffness helpers are bit-for-bit what the expressions they replaced produced.
void testUtilMethods()
Test methods
T l2Dist(const std::vector< T > &x1, const std::vector< T > &x2)
Computes l2 distance between two vectors.
double selfContactStiffness(const double &K, const double &horizon, int horizonPower=5)
Contact stiffness for a body against itself.
double normalContactStiffness(const double &K1, const double &K2, const double &horizon, int horizonPower=5)
Silling normal contact stiffness from two bulk moduli and the horizon.
double angle(util::Point a, util::Point b)
Computes angle between two vectors.
std::vector< double > rotateACW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in anti-clockwise direction.
std::vector< double > rotateCW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in clockwise direction.
double harmonicMean(const double &m1, const double &m2)
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.
A structure to represent 3d vectors.