Discrete Element Methods (Alpha)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DEMGrain.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 06/16/2016 02:11:21 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2016, University of Utah
  15. * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
  16. */
  17. #include "DEMGrain.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. std::ostream &operator << (std::ostream &stream, const DEMGrain &ob) {
  21. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  22. return stream;
  23. }
  24. // ==================== LIFECYCLE =======================
  25. //--------------------------------------------------------------------------------------
  26. // Class: DEMGrain
  27. // Method: DEMGrain
  28. // Description: constructor (protected)
  29. //--------------------------------------------------------------------------------------
  30. DEMGrain::DEMGrain ( ) : DEMParticle( ) {
  31. } // ----- end of method DEMGrain::DEMGrain (constructor) -----
  32. //--------------------------------------------------------------------------------------
  33. // Class: DEMGrain
  34. // Method: DEMGrain
  35. // Description: DeSerializing constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. DEMGrain::DEMGrain (const YAML::Node& node) : DEMParticle(node) {
  38. Points = node["Points"].as<Vector3Xr>( );
  39. } // ----- end of method DEMGrain::DEMGrain (constructor) -----
  40. //--------------------------------------------------------------------------------------
  41. // Class: DEMGrain
  42. // Method: NewSP()
  43. // Description: public constructor returing a shared_ptr
  44. //--------------------------------------------------------------------------------------
  45. std::shared_ptr< DEMGrain > DEMGrain::NewSP() {
  46. std::shared_ptr< DEMGrain > sp(new DEMGrain( ), LemmaObjectDeleter() );
  47. return sp;
  48. }
  49. //--------------------------------------------------------------------------------------
  50. // Class: DEMGrain
  51. // Method: ~DEMGrain
  52. // Description: destructor (protected)
  53. //--------------------------------------------------------------------------------------
  54. DEMGrain::~DEMGrain () {
  55. } // ----- end of method DEMGrain::~DEMGrain (destructor) -----
  56. //--------------------------------------------------------------------------------------
  57. // Class: DEMGrain
  58. // Method: Serialize
  59. //--------------------------------------------------------------------------------------
  60. YAML::Node DEMGrain::Serialize ( ) const {
  61. YAML::Node node = DEMParticle::Serialize();
  62. node.SetTag( GetName() );
  63. // FILL IN CLASS SPECIFICS HERE
  64. node["Points"] = Points;
  65. return node;
  66. } // ----- end of method DEMGrain::Serialize -----
  67. //--------------------------------------------------------------------------------------
  68. // Class: DEMGrain
  69. // Method: DeSerialize
  70. //--------------------------------------------------------------------------------------
  71. std::shared_ptr<DEMGrain> DEMGrain::DeSerialize ( const YAML::Node& node ) {
  72. if (node.Tag() != "DEMGrain" ) {
  73. throw DeSerializeTypeMismatch( "DEMGrain", node.Tag());
  74. }
  75. std::shared_ptr< DEMGrain > Object(new DEMGrain(node), LemmaObjectDeleter() );
  76. return Object ;
  77. } // ----- end of method DEMGrain::DeSerialize -----
  78. //--------------------------------------------------------------------------------------
  79. // Class: DEMGrain
  80. // Method: RandomPointBuild
  81. //--------------------------------------------------------------------------------------
  82. void DEMGrain::RandomPointCloud ( const int& npoints, const Real& sigma ) {
  83. Points.resize( Eigen::NoChange, npoints );
  84. std::mt19937 eng(time(NULL));
  85. std::normal_distribution<Real> normalx(GetCentreMass(0), sigma);
  86. std::normal_distribution<Real> normaly(GetCentreMass(1), sigma);
  87. std::normal_distribution<Real> normalz(GetCentreMass(2), sigma);
  88. std::cout.precision(12);
  89. for(int i=0; i < npoints; ++i) {
  90. Points(0, i) = normalx(eng);
  91. Points(1, i) = normaly(eng);
  92. Points(2, i) = normalz(eng);
  93. }
  94. ConvexHull();
  95. return ;
  96. } // ----- end of method DEMGrain::RandomPoints -----
  97. //--------------------------------------------------------------------------------------
  98. // Class: DEMGrain
  99. // Method: ConvexHull
  100. //--------------------------------------------------------------------------------------
  101. void DEMGrain::ConvexHull ( ) {
  102. //for ( auto point : Points.rowwise() ) {
  103. // Brute force algorithm (O(n^3))
  104. for (int icol=0; icol<Points.cols(); ++icol) {
  105. std::cout << Points.col(icol) << std::endl;
  106. }
  107. return ;
  108. } // ----- end of method DEMGrain::ConvexHull -----
  109. } // ---- end of namespace Lemma ----
  110. /* vim: set tabstop=4 expandtab: */
  111. /* vim: set filetype=cpp: */