PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
testParticleLib.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include "testParticleLib.h"
13#include "util/point.h"
14#include "util/matrix.h"
15#include <bitset>
16#include <fstream>
17#include <iostream>
18
20
21 bool test_result = true;
22
23 // test translation
24 double scale = 1.0;
25 double theta = 0.;
26 auto xt = util::Point(1., 1., 0.);
27 auto t1 = particle::ParticleTransform(xt, util::Point(0., 0., 1.), theta, scale);
28
29 auto xold = util::Point(0., 0., 0.);
30 auto xnew = t1.apply(xold);
31 auto xnew_check = util::Point( xold.d_x + 1., xold.d_y + 1., xold.d_z);
32
33 std::cout << "xold = (" << xold.d_x << ", " << xold.d_y << ", " << xold.d_z
34 << "), xnew = (" << xnew.d_x << ", " << xnew.d_y << ", " << xnew.d_z
35 << "), distance = " << xnew_check.dist(xnew) << "\n";
36 if (xnew_check.dist(xnew) > 1.0E-8) {
37 std::cout << "Error\n";
38 test_result = false;
39 }
40
41 // test rotation
42 scale = 1.0;
43 theta = M_PI / 6;
44 xt = util::Point(0., 0., 0.);
45 auto t2 =
46 particle::ParticleTransform(xt, util::Point(0., 0., 1.), theta, scale);
47 xold = util::Point(0.5, 0.2, 0.);
48 xnew = t2.apply(xold);
49 xnew_check = util::Point(
50 xold.d_x * std::cos(theta) - xold.d_y * std::sin(theta),
51 xold.d_x * std::sin(theta) + xold.d_y * std::cos(theta), 0.);
52
53 std::cout << "xold = (" << xold.d_x << ", " << xold.d_y << ", " << xold.d_z
54 << "), xnew = (" << xnew.d_x << ", " << xnew.d_y << ", " << xnew.d_z
55 << "), distance = " << xnew_check.dist(xnew) << "\n";
56 if (xnew_check.dist(xnew) > 1.0E-8) {
57 std::cout << "Error\n";
58 test_result = false;
59 }
60
61 // test scale and rotation
62 scale = 0.5;
63 theta = M_PI / 3;
64 xt = util::Point(0., 0., 0.);
65 auto t3 =
66 particle::ParticleTransform(xt, util::Point(0., 0., 1.), theta,
67 scale);
68 xold = util::Point(0.2, 0.4, 0.);
69 xnew = t3.apply(xold);
70 xnew_check = util::Point(
71 scale * xold.d_x * std::cos(theta) - scale * xold.d_y * std::sin(theta),
72 scale * xold.d_x * std::sin(theta) + scale * xold.d_y * std::cos(theta), 0.);
73
74 std::cout << "xold = (" << xold.d_x << ", " << xold.d_y << ", " << xold.d_z
75 << "), xnew = (" << xnew.d_x << ", " << xnew.d_y << ", " << xnew.d_z
76 << "), distance = " << xnew_check.dist(xnew) << "\n";
77 if (xnew_check.dist(xnew) > 1.0E-8) {
78 std::cout << "Error\n";
79 test_result = false;
80 }
81}
void testTransform()
Perform test on Fracture class and check if bitwise functions are working correctly.
A struct that stores transformation parameters and provides method to transform the particle....
A structure to represent 3d vectors.
Definition point.h:30