MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseCluster.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 "BaseCluster.h"
27 
32  logger(DEBUG, "BaseCluster::BaseCluster() finished");
33 }
34 
39  logger(DEBUG, "BaseCluster::BaseClusterr() finished");
40 }
41 
42 /*
43  * ----------------------------------------------------------------------
44  * FUNCTIONS: setters and getters
45  * ----------------------------------------------------------------------
46  */
47 
53  return position_;
54 }
55 
61  position_ = p;
62 }
63 
64 
70 }
71 
77  if (cTOTS < 45 && cTOTS > 0)
78  logger(WARN, "collisionTimeOverTimeStep = % is too small: consider setting it greater or equal than 50.", cTOTS);
79  else if (cTOTS <= 0)
80  logger(ERROR, "collisionTimeOverTimeStep = % must be grater than zero.", cTOTS);
82 }
83 
89  return radiusParticle_;
90 }
91 
98  if (rP <= 0)
99  logger(ERROR, "radiusParticle must be greater than zero. radiusParticle = %", rP);
100  else {
101  radiusParticle_ = rP;
102  setRadiusParticle_ = true;
103  }
104 }
105 
111 }
112 
118  if (sDP < 1)
119  logger(ERROR, "sizeDispersityParticle must be greater or equal than 1. sizeDispersityParticle = %", sDP);
120  else sizeDispersityParticle_ = sDP;
121 }
122 
127  return nParticles_;
128 }
129 
135  if (nP < 0)
136  logger(ERROR, "nParticles must be grater than zero. nParticles = %", nP);
137  else {
138  nParticles_ = nP;
139  setNumberOfParticles_ = true;
140  }
141 }
142 
150  if (rCR <= 0)
151  logger(ERROR,
152  "relativeClusterRadius is smaller than 0. relativeClusterRadius = %",
153  rCR);
154  else
155  radiusCluster_ = rCR;
156 
157  setRadiusCluster_ = true;
158 }
159 
168  else
169  return solidFraction_;
170 }
171 
175 unsigned int BaseCluster::getClusterId() const {
176  return idCluster_;
177 }
178 
183 void BaseCluster::setClusterId(unsigned int iC) {
184  if (iC < 0)
185  logger(WARN, "idCluster = % is less than zero.", iC);
186  idCluster_ = iC;
187 }
188 
194 }
195 
201  if (vDM < 0 || vDM > 1)
202  logger(ERROR, "velocityDampingModulus must be grater than zero and less than 1. velocityDampingModulus = %", vDM);
204 }
205 
211 }
212 
218  if (gL <= 0)
219  logger(ERROR, "nInternalStructurePoints_ must be grater than zero. nInternalStructurePoints_ = %", gL);
221 }
222 
227  return energyRatioTolerance_;
228 }
229 
235  if (eRT <= 0)
236  logger(ERROR, "energyRatioTolerance must be grater than zero. energyRatioTolerance = %", eRT);
237  energyRatioTolerance_ = eRT;
238 }
239 
244  return particleSpecies_;
245 }
246 
251  particleSpecies_ = pS;
252 }
253 
258  return clusterVelocity_;
259 }
260 
265  clusterVelocity_ = v;
266 }
267 
272  return isCdatOutputOn_;
273 }
274 
278 void BaseCluster::doCdatOutput(bool iCOO) {
279  isCdatOutputOn_ = iCOO;
280 }
281 
286  return isOverlOutputOn_;
287 }
288 
292 void BaseCluster::doOverlOutput(bool iOOO) {
293  isOverlOutputOn_ = iOOO;
294 }
295 
300  return isAmatOutputOn_;
301 }
302 
306 void BaseCluster::doAmatOutput(bool iAOO) {
307  isAmatOutputOn_ = iAOO;
308 }
309 
314  return isIntStrucOutputOn_;
315 }
316 
321  isIntStrucOutputOn_ = iISOO;
322 }
323 
328  return isVtkOutputOn_;
329 }
330 
334 void BaseCluster::doVtkOutput(bool iVOO) {
335  isVtkOutputOn_ = iVOO;
336 }
337 
342  return isRestartOutputOn_;
343 }
344 
349  isRestartOutputOn_ = r;
350 }
351 
356  return isFStatOutputOn_;
357 }
358 
363  isFStatOutputOn_ = fS;
364 }
365 
370  return isEneOutputOn_;
371 }
372 
377  isEneOutputOn_ = e;
378 }
379 
384  return meanClusterRadius_;
385 }
386 
391  return meanRelativeOverlap_;
392 }
393 
394 /*
395  * ----------------------------------------------------------------------
396  * FUNCTIONS: overridden mercury3D functions
397  * ----------------------------------------------------------------------
398  */
399 
426 {
427  logger(VERBOSE, "CREATING CLUSTER");
428 
429  if (particleHandler.getSize()>0){
430  logger(WARN, "ParticleHandler was not empty");
432  }
433 
434  if (speciesHandler.getSize()>0){
435  logger(WARN, "speciesHandler was not empty");
437  }
438  // Defining cluster parameters starting from the user input.
439  // In order to use this class the user has to set exactly 2 values among radiusParticle,
440  // radiusCluster and numberOfParticles.
442  logger(ERROR, "Please set exactly two values among radiusParticle, radiusCluster and numberOfParticles."
443  " radiusParticle = %, radiusCluster = %, numberOfParticles = %.",
445 
446  // If the user sets the cluster radius and the radius of a single particle,
447  // the number of particles has to be computed:
450  logger(VERBOSE, "clusterRadius is small compared to the radius of a single particle:"
451  " consider setting clusterRadius >= 2 * radiusParticle."
452  "clusterRadius = %, radiusParticle = %.", radiusCluster_, radiusParticle_);
453  // relative cluster radius
455  // mass fraction of the cluster in the limit of phi = 0.
456  Mdouble eps0 = 0.58;
457  // The number of particles (N) per cluster given the relative cluster radius (hatR) and penetration depth max (phi)
458  // can be computed as: N = ( hatR / (1 - eps0*phi) )^3 * eps0.
459  // It is very important to notice that this formula is accurate only if sliding friction is set to 0.5 and relative
460  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
461 
462  nParticles_ =
463  round (std::pow( hatR / (1.0 - eps0 * particleSpecies_->getPenetrationDepthMax() ), 3) * eps0);
464  logger(VERBOSE, "Number of particles: %.\n", nParticles_);
465  }
466 
467  // If the user sets the cluster radius and the number of particles,
468  // the radius of a single particle has to be computed:
470  // mass fraction of the cluster in the limit of phi = 0.
471  Mdouble eps0 = 0.58;
472  // The radius of a single particle (r) composig the cluster given the cluster radius (R), penetration depth max (phi)
473  // and the number of particles (N) can be obtained as: r = R / ( cbrt(N/eps0) * (1-eps0*phi) ).
474  // It is very important to notice that this formula is accurate only if sliding friction is set to 0.5 and relative
475  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
476  radiusParticle_ = radiusCluster_ / (cbrt(nParticles_/eps0) * (1-eps0*particleSpecies_->getPenetrationDepthMax()));
477 
478  logger(VERBOSE, "radius particle: %.\n", radiusParticle_);
479  }
480 
481  logger(VERBOSE, "SETTING RADII");
482  setRadii();
483 
484  logger(VERBOSE, "SETTING SPECIES");
485  setSpecies();
486 
487  logger(VERBOSE, "SETTING DOMAIN LIMITS");
488  setDomainLimits();
489 
490  logger(VERBOSE, "COMPUTING TIME STEP");
492 
493  logger(VERBOSE, "PARTICLE INSERTION");
494  insertParticles();
495 
496  logger(VERBOSE, "Number of particles: %.", particleHandler.getSize());
497 
498  t0_ = getTime();
499 
500  // \details deltaStar
501  Mdouble deltaStar = particleSpecies_->getPenetrationDepthMax() * particleSpecies_->getUnloadingStiffnessMax()
502  / (particleSpecies_->getUnloadingStiffnessMax() - particleSpecies_->getLoadingStiffness());
503 
504  /*
505  * \brief maximum force modulus applied on particles (this value is then multiplied by the relative distance from
506  * force center d, which is d = D/r).
507  * It is the force necessary to get a overlap of deltaStar (computed above this description).
508  * If constant restitution is true then it is also multiplied by the mass of the biggest particle,
509  * or if MERCURY_USE_MPI it is the biggest possible mass computed taking into account particle dispersity,
510  * i.e. the mass of a particle having radius
511  * r = radiusParticle_ * 2 * sizeDispersityParticle_ / (1 + sizeDispersityParticle_).
512  * (In order to get the right value of loading stiffness it should be multiplied by the mass of the smallest
513  * particle; multiplying it for the biggest mass here, instead, is for safety).
514  */
515 
516 #ifdef MERCURY_USE_MPI
518  particleSpecies_->getLoadingStiffness()
519  * (particleSpecies_->getConstantRestitution() ?
521  :
522  1);
523 #else
525  particleSpecies_->getLoadingStiffness()
526  * (particleSpecies_->getConstantRestitution() ?
528  :
529  1);
530 #endif
531 
532  /*
533  * \details
534  * The time needed for a particle to cover a distance of x is sqrt(2 * x * m / F), when a constant force F is applied.
535  * In order to hit another particle, a single particle has to travel a distance of about boxSize/4 (boxSize is the domain length).
536  * As a value for x it is used boxSize_ (instead of boxSize_/4 as a safety factor).
537  * As a value for F it is used maximumForceModulus/50 which is half of maximumForceModulus/25 (in this way it is calculated
538  * a measure of the time needed with a force which linearly increases from 0 to maximumForceModulus/25, again dividing for 25
539  * is done for safety). As a value for m it is used the mass of the biggest particle, or if MERCURY_USE_MPI it is
540  * the mass computed taking into account size dispersity, so the mass
541  * of a particle having radius r = radiusParticle_ * 2 * sizeDispersityParticle_ / (1 + sizeDispersityParticle_), for safety.
542  * The factor 5* outside the sqrt is another safety factor empirically determined: with this values the computation is fast
543  * and the obtained results are very similar to the ones obtained if longer times would be set.
544  * All this safety factors are needed because this is not the exact value of time needed but a measure of it: the problem
545  * indeed is quite complicated given that particles can also rearrange during compression and so they will eventually
546  * move in a non radial direction and for this reason they will need more time to settle.
547  */
548 #ifdef MERCURY_USE_MPI
552 #else
555 #endif
556 
557  //\details Maximum possible time duration of dissipation (i.e. duration of dissipation if energy ration tollerance not reached).
558  dissipationDuration_ = forceTuningDuration_/2;
559 
560  // Compression + Decompression + Dissipation = 2 * Compression + Dissipation
561  clusterTimeMax_ = 2 * forceTuningDuration_ + dissipationDuration_;
563 
564  fileOutputTimeInterval_ = forceTuningDuration_ / 100;
565 
567 
569 
570  forceDampingModulus_ = 0.95;
571 
573 
574  setXBallsAdditionalArguments("-v0 -p 10");
575 
577 
579 
581 
582  fStatFile.setFileType(isFStatOutputOn() ? FileType::ONE_FILE : FileType::NO_FILE);
583 
584  eneFile.setFileType(isEneOutputOn() ? FileType::ONE_FILE : FileType::NO_FILE);
585 
586  // Name setting
587  std::ostringstream name;
588  name << "Cluster_ID_" << idCluster_;
589  setName(name.str());
590 
591  if (isCdatOutputOn()) {
592  logger(VERBOSE, "CREATING .cdat FILE\n");
593  makeCdatFile();
594  }
595 
596  if (isOverlOutputOn()) {
597  logger(VERBOSE, "CREATING .overl FILE\n");
598  makeOverlFile();
599  }
600 
601  logger(VERBOSE, "ACTIVATING CENTRAL FORCES\n");
602 
603  /*
604  * \details
605  * Stage defines in which phase of the calculation the program is:
606  * stage = 1: compressing particles and increasing force
607  * stage = 2: releasing force
608  * stage = 3: waiting for the system to be static.
609  */
610  stage_ = 1;
611 }
612 
622 {
624 
626  writeToCdatFile();
627 
630 
631  /*
632  * \brief If stage == 1 force is linearly increased and velocities are damped for a time T = forceTuningDuration.
633  * If t > T, stage is set to 2.
634  */
635  if (stage_ == 1)
636  {
637  if (getTime() - t0_ < forceTuningDuration_)
638  {
639  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
640  increaseForce();
641 
642  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
643  dampVelocities();
644 
646  }
647  else
648  {
649  logger(VERBOSE, "DECREASING CENTRAL FORCE");
650 
651  t0_ = getTime();
652  stage_++;
653  }
654  }
655 
656  /*
657  * \brief If stage == 2 force is linearly decreased and velocities are damped for a time duration of T = forceTuningDuration.
658  * If t > T, stage is set to 3.
659  */
660  if (stage_ == 2)
661  {
662  if (getTime() - t0_ < forceTuningDuration_)
663  {
664  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
665  decreaseForce();
666 
667  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
668  dampVelocities();
669 
671  }
672  else
673  {
674  logger(VERBOSE, "DISSIPATING ENERGY");
675 
676  t0_ = getTime();
679  stage_++;
680  }
681  }
682 
683  /*
684  * \details If stage == 3 force is exponentially decreased and velocities are damped for a time duration of T = dissipationDuration_.
685  * If t>T or if the energy ratio is below the minimum threshold calculation is concluded and a few last operation are computed.
686  * They are:
687  * -timeMax is set to getTime(), in order to stop the calculation,
688  * -stage is set to 4 (if the energy threshold is not reached stage will remain 3 (because the simulation is stopped by the previous
689  * definition of timeMax): if this happens the user gets a warning, see actionsAfterSolve()).
690  * If MERCURY_USE_MPI this process lasts for a time T = dissipationDuration_ - getTimeStep().
691  */
692  if (stage_ == 3)
693  {
694  // \brief Now force is damped and not decreased.
695  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
696  dampForce();
697 
698  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
699  dampVelocities();
700 
702 #ifdef MERCURY_USE_MPI
704 #else
707 #endif
708  {
709  printTime();
710  logger(VERBOSE, "ENERGY DISSIPATED\n");
711 
712  // stage++ now is a flag used to understand if the dissipation procedure has been completed.
713  stage_++;
714 
715  setTimeMax(getTime());
716  }
717  }
718 
719 }
720 
734 {
735 
737 
738  if ( isCdatOutputOn() )
739  writeToCdatFile();
740 
741  if ( isOverlOutputOn() )
743 
744  if (stage_ == 3)
745  logger(WARN, "Dissipation process not completed: final energyRatioTollerance_ = %."
746  "Try to increase energyRatioTollerance_ or decreasing velocityDampingModulus.",
748 
749  if (isAmatOutputOn())
750  {
751  logger(VERBOSE, "CREATING ADJACENCY MATRIX FILE\n");
753  makeAmatFile();
754  writeAmatFile();
755  }
756 
757  if (isIntStrucOutputOn())
758  {
759  logger(VERBOSE, "COMPUTING INTERNAL STRUCTURE FILE\n");
761  }
762 
763  if(isOverlOutputOn())
764  {
765  logger(VERBOSE, "COMPUTING GNUPLOT FILE\n");
766  makeGnuplotFile();
767  }
768 
769 
770  /*
771  * \brief with this loop all particles are moved so that center of mass == position_ and their velocity is set.
772  */
773  for (auto i = particleHandler.begin(); i != particleHandler.end(); ++i){
774  (*i)->setPosition( (*i)->getPosition() + position_ - centerOfMass_ );
775  (*i)->setVelocity( clusterVelocity_ );
776  }
777 
778  logger(VERBOSE, "CLUSTER CREATED.\n");
779 
780  if (isCdatOutputOn())
781  cdatFile_.close();
782 
783  if (isOverlOutputOn())
784  overlFile_.close();
785 }
786 
791 void BaseCluster::write(std::ostream& os, bool writeAllParticles) const
792 {
793  writeAllParticles = true;
794  MercuryBase::write(os, writeAllParticles);
795 
796  os <<
797  "position " << position_ << " " <<
798  "stage " << stage_ << " " <<
799  "t0 " << t0_
800  << std::endl <<
801  "idCluster " << idCluster_ << " " <<
802  "nParticles " << nParticles_ << " " <<
803  "radiusParticle " << radiusParticle_ << " " <<
804  "massParticle " << massParticle_ << " " <<
805  "sizeDispersityParticle " << sizeDispersityParticle_ << " " <<
806  "totalParticleVolume " << totalParticleVolume_
807  << std::endl <<
808  "maximumForceModulus " << maximumForceModulus_ << " " <<
809  "forceTuningInterval " << forceTuningInterval_ << " " <<
810  "forceTuningDuration " << forceTuningDuration_ << " " <<
811  "velocityDampingInterval " << velocityDampingInterval_ << " " <<
812  "velocityDampingModulus " << velocityDampingModulus_ << " " <<
813  "energyRatioTolerance " << energyRatioTolerance_ << " " <<
814  "forceDampingModulus " << forceDampingModulus_ << " " <<
815  "forceModulus " << forceModulus_
816  << std::endl <<
817  "isCdatOutputON " << isCdatOutputOn_ << " " <<
818  "isOverlOutputOn " << isOverlOutputOn_ << " " <<
819  "isAmatOutputOn " << isAmatOutputOn_ << " " <<
820  "isIntStrucOutputOn " << isIntStrucOutputOn_
821  << std::endl;
822  if( isIntStrucOutputOn() )
823  os << "nInternalStructurePoints " << nInternalStructurePoints_ << std::endl;
824 
825  os << "isRestartOutputOn " << isRestartOutputOn_ << " " << //This is obviously on because otherwise restart
826  // process would not take place.
827  //For now it is saved but could eventually be removed.
828  "isFStatOutputOn " << isFStatOutputOn_ << " " <<
829  "isEneOutputOn " << isEneOutputOn_ << std::endl;
830 }
831 
836 void BaseCluster::read(std::istream& is, ReadOptions opt)
837 {
838  MercuryBase::read(is);
839 
840  std::stringstream line;
841  std::string dummy;
842 
844  line >> dummy >> position_
845  >> dummy >> stage_
846  >> dummy >> t0_;
848  line >> dummy >> idCluster_
849  >> dummy >> nParticles_
850  >> dummy >> radiusParticle_
851  >> dummy >> massParticle_
852  >> dummy >> sizeDispersityParticle_
853  >> dummy >> totalParticleVolume_;
855  line >> dummy >> maximumForceModulus_
856  >> dummy >> forceTuningInterval_
857  >> dummy >> forceTuningDuration_
858  >> dummy >> velocityDampingInterval_
859  >> dummy >> velocityDampingModulus_
860  >> dummy >> energyRatioTolerance_
861  >> dummy >> forceDampingModulus_
862  >> dummy >> forceModulus_;
864  line >> dummy >> isCdatOutputOn_
865  >> dummy >> isOverlOutputOn_
866  >> dummy >> isAmatOutputOn_
867  >> dummy >> isIntStrucOutputOn_;
868  if(isIntStrucOutputOn() )
869  {
871  line >> dummy >> nInternalStructurePoints_;
872  }
873  line >> dummy >> isRestartOutputOn_
874  >> dummy >> isFStatOutputOn_
875  >> dummy >> isEneOutputOn_;
876 }
877 
883 {
884  readRestartFile();
885 
887 
889 
891 
893 
895 
896  setXBallsAdditionalArguments("-v0 -p 10");
897 
899 
901 
903 
905 
907 
908  if (isCdatOutputOn())
909  {
910  std::ostringstream cdatName;
911  cdatName << getName() << ".cdat";
912  cdatFile_.open(cdatName.str(), std::ios::app);
913  }
914 
915  if (isOverlOutputOn())
916  {
917  std::ostringstream overlName;
918  overlName << getName() << ".overl";
919  overlFile_.open(overlName.str(), std::ios::app);
920  }
921 
922  logger(VERBOSE, "CALCULATION RESTARTED\n");
923 }
924 
943 {
944  std::ostringstream printTime;
945  switch (stage_)
946  {
947  case 1: printTime << "Compression progress: " << std::setw(3) << int( ceil( 100 * (getTime() - t0_) / forceTuningDuration_ ) ) << "%, ";
948  break;
949 
950  case 2: printTime << "Decompression progress: " << std::setw(3) << int( ceil( 100 * (getTime() - t0_) / forceTuningDuration_ ) )<< "%, ";
951  break;
952 
953  case 3: printTime << "Dissipating energy: ";
954  break;
955 
956  default: printTime << "Final values: ";
957  break;
958  }
959  printTime <<
960  "E_ratio = " << std::scientific << std::setprecision(2) << std::setw(8) << getKineticEnergy()/getElasticEnergy() <<
961  ", cN = " << std::fixed << std::setw(5) << meanCoordinationNumber_ << ", rMean = " << std::scientific << meanClusterRadius_ <<
962  ", mF = " << std::fixed << std::setprecision(3) << solidFraction_ << ", Force Modulus = " << std::scientific << forceModulus_ <<
963  ", dMin = " << std::fixed << std::setw(7) << std::setprecision(5) << minRelativeOverlap_ << ", dMean = " << std::setw(7) << meanRelativeOverlap_ <<
964  ", dMax = " << maxRelativeOverlap_ << ", centerOfMass = " << std::scientific << std::setprecision(5) << std::setw(13) << centerOfMass_.X
965  << std::setw(14) << centerOfMass_.Y << std::setw(14) << centerOfMass_.Z <<
966  " nParticles: " << particleHandler.getSize();
967  logger(VERBOSE, printTime.str());
968 }
969 
970 
971 
972 /*
973  * ----------------------------------------------------------------------
974  * FUNCTIONS: functions inside setupInitialConditions
975  * ----------------------------------------------------------------------
976  */
977 
982 {
985  for (int i = 0; i < nParticles_; ++i)
986  {
987  // This is the actual radius of the i-th particle
989  // Computing totalParticleVolume (this is done because this value is needed before particle insertion).
990  totalParticleVolume_ += 4.0*constants::pi*pow(radii_[i],3.0)/3.0;
991  //computing the smallest radius (needed in computeTimeStep(), which is needed before particle insertion)
993  }
994 }
995 
1001 {
1002  if (particleSpecies_ == nullptr)
1003  logger(ERROR, "Species not set.");
1004 
1006  /*
1007  * \brief mass of the particle which has radius radiusParticle if constantRestitution(false) or
1008  * radiusParticle_*2/(1+sizeDispersityParticle_) otherwise.
1009  * It is set now and used various time in the code (for example for stiffnesses, collision time
1010  * and restitution coefficient below).
1011  */
1012  massParticle_ = particleSpecies_ -> getConstantRestitution()?
1013  speciesHandler.getObject(0) -> getMassFromRadius(radiusParticle_*2/(1+sizeDispersityParticle_))
1014  :
1015  speciesHandler.getObject(0) -> getMassFromRadius(radiusParticle_);
1016 
1017  std::ostringstream printSpecies;
1018  /*
1019  * If constantRestitution(true) loading, unloading, and cohesion stiffness are multiplied by the mass of a particle
1020  * whose radius is radiusParticle_*2/(1+sizeDispersityParticle_),
1021  * which is the mass that should be used to compute collision time.
1022  */
1023  printSpecies << "loadingStiffness: " << std::scientific << particleSpecies_ -> getLoadingStiffness()
1024  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1025  << "unloadingStiffnessMax: " << particleSpecies_ -> getUnloadingStiffnessMax()
1026  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1027  << "cohesionStiffness: " << particleSpecies_ -> getCohesionStiffness()
1028  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1029  << "restitutionCoefficient: " << std::fixed << particleSpecies_ -> getRestitutionCoefficient(massParticle_) << std::endl
1030  << "collisionTime: " << std::scientific << std::setprecision(3) << particleSpecies_ -> getCollisionTime(massParticle_) << std::endl;
1031  logger(VERBOSE, printSpecies.str());
1032 }
1033 
1042 {
1043  Mdouble initialSolidFraction = 0.1;
1044  boxSize_ = cbrt(totalParticleVolume_/initialSolidFraction);
1045  std::ostringstream printDomainLimits;
1046  printDomainLimits << "Cubic size " << boxSize_ << std::endl;
1047  logger(VERBOSE, printDomainLimits.str());
1048 
1049  setDomain(-0.5*boxSize_*Vec3D(1,1,1) + position_, 0.5*boxSize_*Vec3D(1,1,1) + position_);
1050 }
1051 
1057 {
1058  // if constantRestitution(true) mass for collision time will be automatically set to 1, otherwise the smallest particle's mass will be used
1060 
1061  // printing values of timeStep and ratio between collisionTime and timeStep
1062  std::ostringstream printTimeStep;
1063  printTimeStep << "timeStep: " << std::setprecision(4) << getTimeStep() << std::endl
1064  << "cT/tS, at least: " << std::fixed << std::setprecision(1)
1066  << std::endl;
1067  logger(VERBOSE, printTimeStep.str());
1068 }
1069 
1070 
1075 {
1076  int nParticlesInserted = 0;
1077 
1078  while (nParticlesInserted < nParticles_)
1079  {
1080  /* nParticleInserted corresponds to the index of the particle which is being inserted:
1081  * for example if no particle has been inserted yet nParticlesInserted=0 which is the
1082  * index of the first particle, and so on. For this reason this variable is the input
1083  * for particleInsertionSuccessful.
1084  */
1085  if (particleInsertionSuccessful(nParticlesInserted))
1086  {
1087  nParticlesInserted++;
1088  }
1089  else
1090  {
1091  logger(ERROR, "Cannot insert all particles, try to decrase the value of initialSolidFraction in "
1092  "BaseCluster::setDomainLimits();\n"
1093  "Inserted %/% particles.", nParticlesInserted, nParticles_);
1094  }
1095  }
1096  logger(VERBOSE, "PARTICLE INSERTION TERMINATED SUCCESSFULLY\n");
1097 }
1098 
1134 {
1135  std::ostringstream cdatName;
1136  cdatName << getName() << ".cdat";
1137 
1138  cdatFile_.open(cdatName.str(), std::ios::out);
1139 
1140  cdatFile_ << "CLUSTER DATA AND INFORMATION" << std::endl << std::endl;
1141  cdatFile_ << "position: " << position_ << std::endl;
1142  cdatFile_ << "collisionTimeOverTimeStep: " << getCollisionTimeOverTimeStep() << std::endl;
1143  cdatFile_ << "radiusParticle: " << std:: scientific << std::setprecision(2) << getRadiusParticle() << std::endl;
1144  cdatFile_ << "sizeDispersityParticle: " << std::defaultfloat << getSizeDispersityParticle() << std::endl;
1145  cdatFile_ << "densityParticle: " << std:: scientific << particleSpecies_ -> getDensity() << std::endl;
1146  cdatFile_ << "nParticles: " << std::defaultfloat << getNumberOfParticles() << std::endl;
1147  cdatFile_ << "idCluster: " << getClusterId() << std::endl;
1148  cdatFile_ << "slidingFrictionCoeff: " << particleSpecies_ -> getSlidingFrictionCoefficient() << std::endl;
1149  cdatFile_ << "rollingFrictionCoeff: " << particleSpecies_ -> getRollingFrictionCoefficient() << std::endl;
1150  cdatFile_ << "torsionFrictionCoeff: " << particleSpecies_ -> getTorsionFrictionCoefficient() << std::endl;
1151  // If constantRestitution(true) loading, unloading, and cohesion stiffness are multiplied by the mass of a particle (massParticle_) whose radius is radiusParticle_*2/(1+sizeDispersityParticle_),
1152  // which is the mass that should be used to compute collision time.
1153  cdatFile_ << "loadingStiffness: " << std::scientific << particleSpecies_ -> getLoadingStiffness()
1154  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1155  cdatFile_ << "unloadingStiffnessMax: " << particleSpecies_ -> getUnloadingStiffnessMax()
1156  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1157  cdatFile_ << "cohesionStiffness: " << particleSpecies_ -> getCohesionStiffness()
1158  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1159  cdatFile_ << "restitutionCoefficient: " << particleSpecies_ -> getRestitutionCoefficient(massParticle_) << std::endl;
1160  cdatFile_ << "collisionTime: " << std::scientific << std::setprecision(3) << particleSpecies_ -> getCollisionTime(massParticle_) << std::endl;
1162  cdatFile_ << "nInternalStructurePoints: " << getNumberOfInternalStructurePoints() << std::endl;
1163  cdatFile_ << "energyRatioTolerance: " << getEnergyRatioTolerance() << std::endl;
1164  cdatFile_ << "velocityDampingModulus: " << std::defaultfloat << getVelocityDampingModulus() << std::endl << std::endl;
1165 
1166  cdatFile_ << "progress" << std::setw(16) << "ElastEne" << std::setw(23) << "Ekin/ElastEne" << std::setw(18) << "coord_number" << std::setw(14) << "meanRadius"
1167  << std::setw(19) << "solidFraction" << std::setw(16) << "forceModulus" << std::setw(22) << "AveFOnOverl" << std::setw(15) << "dMin" << std::setw(17) << "dMean"
1168  << std::setw(14) << "dMax" << std::setw(24) << "Mass Centre" << std::endl;
1169 }
1170 
1177 {
1178  std::ostringstream overlName;
1179  overlName << getName() << ".overl";
1180 
1181  overlFile_.open(overlName.str(), std::ios::out);
1182  overlFile_ << "Overlap Vs Normal Force" << std::endl;
1183 }
1184 
1196 
1197  int insertionFailCounter = 0;
1198  Mdouble rad, theta, phi;
1199  Vec3D particlePosition;
1200  SphericalParticle p0;
1201 
1202  // setup of particle properties and initial conditions (besides position)
1203  p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
1204  p0.setRadius(radii_[n]);
1206  p0.setGroupId(idCluster_);
1207 
1208  while (insertionFailCounter < 1000)
1209  {
1210  theta = constants::pi * random.getRandomNumber(0, 2.0);
1211  phi = acos(random.getRandomNumber(-1.0, 1.0));
1212  rad = p0.getRadius() + cbrt( random.getRandomNumber( 0, 1 ) ) * ( 0.5 * boxSize_ - 2.01 * p0.getRadius() );
1213 
1214  particlePosition.X = position_.X + rad * sin(phi) * cos(theta);
1215  particlePosition.Y = position_.Y + rad * sin(phi) * sin(theta);
1216  particlePosition.Z = position_.Z + rad * cos(phi);
1217 
1218  p0.setPosition(particlePosition);
1219 
1221  {
1223  return true;
1224  }
1225 
1226  insertionFailCounter++;
1227  }
1228 
1229  return false;
1230 }
1231 
1232 
1233 
1234 /*
1235  * ----------------------------------------------------------------------
1236  * FUNCTIONS: functions inside actionsAfterTimeStep
1237  * ----------------------------------------------------------------------
1238  */
1239 
1253 {
1254  // resetting counters and variables
1255  Mdouble solidVolumeInsideRadius = 0;
1256  Vec3D localMin;
1257  Vec3D localMax;
1258  localMin.setZero();
1259  localMax.setZero();
1261  //\brief vector in which it is saved the relative position of a particle from the center of mass
1262  Vec3D distanceFromCenterOfMass;
1263  //\brief distance from the center of mass of the furthest particle
1264  Mdouble furthestParticleDistance = 0;
1265  // number of particles whose distance d from the center of mass is d > furthestParticleDistance - radiusParticle_
1266  int counter = 0;
1267  Mdouble relativeOverlap = 0;
1268 
1269  meanClusterRadius_ = 0.0;
1271  maxRelativeOverlap_ = 0.0;
1272  meanRelativeOverlap_ = 0.0;
1274 
1275  // loops over each particle to compute mean coordination number and center of mass.
1276  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1277 
1278  meanCoordinationNumber_ += ((*p)->getInteractions()).size();
1279 
1280  centerOfMass_ += ((*p)->getVolume()) * ((*p)->getPosition());
1281  }
1282 
1285 
1286 
1287  // loops over each particle to compute the furthest particle from the center of mass.
1288  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1289 
1290  distanceFromCenterOfMass = (*p)->getPosition() - centerOfMass_;
1291 
1292  if (distanceFromCenterOfMass.getLength() > furthestParticleDistance)
1293  furthestParticleDistance = distanceFromCenterOfMass.getLength();
1294 
1295  }
1296 
1297  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1298 
1299  distanceFromCenterOfMass = (*p)->getPosition() - centerOfMass_;
1300 
1301  if (distanceFromCenterOfMass.getLength() > furthestParticleDistance - radiusParticle_) {
1302  meanClusterRadius_ += distanceFromCenterOfMass.getLength();
1303  counter++;
1304  }
1305 
1306  }
1307 
1308  meanClusterRadius_ /= counter;
1310 
1311 
1312  /*
1313  * \details This is the radius used to compute solid fraction: it is smaller than the meanClusterRadius.
1314  */
1316 
1317  /*
1318  * \details With a for cycle the volume of the particles inside radiusForSolidFraction is computed and after this the value of solid
1319  * fraction is calculated. This value is less precise as the maximum penetration depth increases and more precise as the
1320  * number of particle increases.
1321  */
1322  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1323  {
1324  distanceFromCenterOfMass = (*p) -> getPosition() - centerOfMass_;
1325 
1326  if( distanceFromCenterOfMass.getLength() < radiusForSolidFraction_ )
1327  solidVolumeInsideRadius += (*p) -> getVolume();
1328  }
1329 
1330  solidFraction_ = 3 * solidVolumeInsideRadius / ( 4 * constants::pi * pow(radiusForSolidFraction_, 3) );
1331 
1332  // loops over every interaction to compute mean force acting on interaction, maximum, mean and minimum relative particle overlap.
1333  for (std::vector<BaseInteraction*>::const_iterator i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1334  {
1335 
1336  /*
1337  * \details the relative overlap is computed as an average of the relative overlap on the two particles.
1338  * rO = ( O/R1 + O/R2 ) / 2.
1339  */
1340  relativeOverlap = ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getP() -> getIndex()) -> getRadius()) +
1341  ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getI() -> getIndex()) -> getRadius());
1342  relativeOverlap /= 2;
1343  meanRelativeOverlap_ += relativeOverlap;
1344  if (relativeOverlap > maxRelativeOverlap_)
1345  maxRelativeOverlap_ = relativeOverlap;
1346 
1347  if (relativeOverlap < minRelativeOverlap_)
1348  minRelativeOverlap_ = relativeOverlap;
1349  }
1351 }
1352 
1368 {
1369  switch (stage_)
1370  {
1371  case 1:
1372  cdatFile_ << "C, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1373  break;
1374 
1375  case 2:
1376  cdatFile_ << "D, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1377  break;
1378 
1379  case 3:
1380  cdatFile_ << "D-energy: ";
1381  break;
1382 
1383  default:
1384  cdatFile_ << "Final v: ";
1385  }
1386 
1387  cdatFile_ <<
1388  std::scientific <<
1389  std::setprecision(2)<<
1390  std::setw(14) <<
1391  getElasticEnergy() <<
1392  std::setw(18) <<
1394  std::fixed <<
1395  std::setprecision(2) <<
1396  std::setw(15) <<
1398  std::scientific <<
1399  std::setw(20) <<
1401  std::fixed <<
1402  std::setprecision(2) <<
1403  std::setw(13) <<
1404  solidFraction_ <<
1405  std::scientific <<
1406  std::setprecision(3) <<
1407  std::setw(24) <<
1408  forceModulus_ <<
1409  std::setw(22) <<
1410  std::fixed <<
1411  std::setprecision(5) <<
1412  std::setw(18) <<
1414  std::setw(16) <<
1416  std::setw(15) <<
1418  std::scientific <<
1419  std::setprecision(2) <<
1420  std::setw(19) <<
1421  centerOfMass_.X <<
1422  std::setw(12) <<
1423  centerOfMass_.Y <<
1424  std::setw(12) <<
1425  centerOfMass_.Z <<
1426  " " <<
1427  std::endl;
1428 }
1429 
1435 {
1436  //\brief force acting on overlap.
1437  Mdouble forceOnOverlap = 0;
1438  Mdouble relativeOverlap = 0;
1439  switch (stage_)
1440  {
1441  case 1:
1442  overlFile_ << "C, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1443  break;
1444 
1445  case 2:
1446  overlFile_ << "D, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1447  break;
1448 
1449  case 3:
1450  overlFile_ << "D energy: ";
1451  break;
1452 
1453  default:
1454  overlFile_ << "Final v: ";
1455  }
1456 
1457  for (std::vector<BaseInteraction*>::const_iterator i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1458  {
1459  forceOnOverlap = ((*i) -> getForce()).getLength();
1460  relativeOverlap = ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getP() -> getIndex()) -> getRadius()) +
1461  ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getI() -> getIndex()) -> getRadius());
1462  relativeOverlap = relativeOverlap / 2;
1463  overlFile_ << std::setprecision(2) << std::scientific << std::setw(18) << forceOnOverlap
1464  << std::defaultfloat << std::fixed << std::setprecision(4) << std::setw(9) << relativeOverlap;
1465  }
1466 
1467  overlFile_ << " " << std::endl;
1468 }
1469 
1478 {
1479  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1480  {
1481  //\brief distance from the center of forces (which is position_).
1482  Vec3D distanceFromForceCenter = (*p) -> getPosition() - position_;
1483 
1484  //\brief norm of distanceFromForceCenter vector
1485  Mdouble norm = distanceFromForceCenter.getLength();
1486 
1487  (*p) -> addForce( -forceModulus_ * distanceFromForceCenter * (2*radiusParticle_ + norm) / (2*radiusParticle_*norm) );
1488 
1489  }
1490 }
1491 
1497 {
1499 }
1500 
1506 {
1507  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1508  {
1509  (*p) -> setVelocity(velocityDampingModulus_*( (*p) -> getVelocity() ));
1510  }
1511 }
1512 
1519 {
1521 }
1522 
1527 {
1529 }
1530 
1537 {
1538  for (int i = 0; i < particleHandler.getSize(); i++)
1539  {
1540  std::vector<int> temporaryRowVector;
1541  temporaryRowVector.reserve(particleHandler.getSize());
1542 
1543  for (int j = 0; j < particleHandler.getSize(); j++)
1544  temporaryRowVector.push_back(0);
1545 
1546  adjacencyMatrix_.push_back(temporaryRowVector);
1547  }
1548 
1549  for (auto i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1550  {
1551  adjacencyMatrix_[(*i) -> getP() -> getIndex()][(*i) -> getI() -> getIndex()] = 1;
1552  adjacencyMatrix_[(*i) -> getI() -> getIndex()][(*i) -> getP() -> getIndex()] = 1;
1553  }
1554 }
1555 
1560 {
1561  std::ostringstream amatName;
1562  amatName << getName() << ".amat";
1563 
1564  amatFile_.open(amatName.str(), std::ios::out);
1565  amatFile_ << "ADJACENCY MATRIX" << std::endl << std::endl;
1566 }
1567 
1574 {
1575  for(int i=0; i < particleHandler.getSize(); i++)
1576  {
1577  for(int j=0; j < particleHandler.getSize(); j++)
1578  {
1579  amatFile_ << adjacencyMatrix_[i][j] << " ";
1580  }
1581  amatFile_ << std::endl;
1582  }
1584  amatFile_ << std::endl;
1585  amatFile_ << "THE TOTAL NUMBER OF INTRACLUSTER BONDS IS: " << nIntraClusterBonds_ << std::endl;
1586  amatFile_ << "THE MEAN COORDINATION NUMBER IS: " << meanCoordinationNumber_ << std::endl;
1587 
1588  amatFile_.close();
1589 }
1590 
1600 {
1601 
1602 
1603 
1604  Vec3D mcPoint;
1605  SphericalParticle p0;
1606  Mdouble fictitiousGridPointRadiusRatio = 1.0e-5;
1608  p0.setRadius(radiusParticle_*fictitiousGridPointRadiusRatio);
1609  p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
1610  int nMonteCarloSamplingPoints = nInternalStructurePoints_;
1611  Mdouble nPointsInsideComponentsForMCTest = 0;
1612 
1614 
1615  for (int i = 0; i < nMonteCarloSamplingPoints; ++i)
1616  {
1617 
1618  Mdouble theta = constants::pi * random.getRandomNumber(0, 2.0);
1619  Mdouble phi = acos(random.getRandomNumber(-1.0, 1.0));
1620  Mdouble rad = radiusForSolidFraction_*cbrt( random.getRandomNumber( 0, 1 ) );
1621 
1622  mcPoint.X = rad * sin(phi) * cos(theta);
1623  mcPoint.Y = rad * sin(phi) * sin(theta);
1624  mcPoint.Z = rad * cos(phi);
1625  mcPoint += centerOfMass_;
1626 
1627  p0.setPosition(mcPoint);
1628 
1629  if (!checkParticleForInteraction(p0)) // collision -> the counter goes to the mass fraction
1630  {
1631  nPointsInsideComponentsForMCTest++;
1632  intStructFile_ << std::scientific << std::setprecision(5) << std::setw(12) << mcPoint.X
1633  << std::setw(13) << mcPoint.Y << std::setw(13) << mcPoint.Z << std::setw(6) << 0 << std::endl;
1634  }
1635 
1636  }
1637 
1638  // Solid fraction (accordance between theoretical values and penetration depth max).
1639  // It is very important to notice that this value is accurate only if sliding friction is set to 0.5 and relative
1640  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
1641  solidFractionIntStruct_ = nPointsInsideComponentsForMCTest/nMonteCarloSamplingPoints;
1642  Mdouble theoVal = 0.58 + 3*pow(0.58,2)*particleSpecies_->getPenetrationDepthMax();
1643  Mdouble diff = fabs(theoVal-solidFractionIntStruct_);
1644  Mdouble accordance = (theoVal - diff)/theoVal;
1645  // Solid fraction (accordance between theoretical values and average overlap).
1646  // It is very important to notice that this value is accurate only if sliding friction is set to 0.5 and relative
1647  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
1648  solidFractionIntStruct_ = nPointsInsideComponentsForMCTest/nMonteCarloSamplingPoints;
1649  Mdouble theoValAvOverl = 0.58 + 3*pow(0.58,2)*meanRelativeOverlap_;
1650  Mdouble diffAvOverl = fabs(theoValAvOverl-solidFractionIntStruct_);
1651  Mdouble accordanceAvOverl = (theoValAvOverl - diffAvOverl)/theoValAvOverl;
1652 
1653  intStructFile_ << "n_points_inside_boundary: " << std::scientific << nMonteCarloSamplingPoints << std::endl;
1654  intStructFile_ << "n_points_inside_components: " << nPointsInsideComponentsForMCTest << std::endl;
1655  intStructFile_ << "solidFractionIntStruct_: " << std::fixed << std::setprecision(6) << solidFractionIntStruct_
1656  << ", accordance with theoretical values: " << 100*accordance << "%." << std::endl
1657  << "Accordance with average overlap: " << 100*accordanceAvOverl << "%." << std::endl
1658  << "It is very important to notice that this formula is accurate only if sliding friction" << std::endl
1659  << "is set to 0.5 and relative tangential stiffness is set to 0.3 while creating the cluster." << std::endl
1660  << "Different values do not guarantee accuracy." << std::endl << std::endl;
1661 
1662  /*
1663  * computeInternalStructure output is set to VERBOSE in order not to have too much output. If the user needs it,
1664  * it is enough to set it to INFO.
1665  */
1666 
1667  std::ostringstream printResults;
1668  printResults << "n_points_inside_boundary: " << std::scientific << nMonteCarloSamplingPoints << std::endl;
1669  printResults << "n_points_inside_components: " << nPointsInsideComponentsForMCTest << std::endl;
1670  printResults << "solidFractionIntStruct_: " << std::fixed << std::setprecision(6) << solidFractionIntStruct_
1671  << ", accordance with theoretical values: " << 100*accordance << "%." << std::endl
1672  << "Accordance with average overlap: " << 100*accordanceAvOverl << "%." << std::endl
1673  << "It is very important to notice that this formula is accurate only if sliding friction" << std::endl
1674  << "is set to 0.5 and relative tangential stiffness is set to 0.3 while creating the cluster." << std::endl
1675  << "Different values do not guarantee accuracy." << std::endl << std::endl;
1676  logger(VERBOSE, printResults.str());
1677 }
1678 
1686 {
1687  std::ostringstream gnuplotname;
1688  gnuplotname << getName() << ".gnuplot";
1689 
1690  gnuplotFile_.open(gnuplotname.str(), std::ios::out);
1691  gnuplotFile_ << "set terminal jpeg" << std::endl;
1692  gnuplotFile_ << "set output \"" << getName() << "_overlaps" << ".jpeg\"" << std::endl;
1693  std::string titleLine=R"(set title "Overlap Vs Force")";// font ",14"
1694  std::string xLabel=R"(set xlabel "Overlap")";
1695  std::string yLabel=R"(set ylabel "Force")";
1696  gnuplotFile_ << titleLine << std::endl;
1697  gnuplotFile_ << xLabel << std::endl;
1698  gnuplotFile_ << yLabel << std::endl;
1699  gnuplotFile_ << "set grid" << std::endl;
1700  gnuplotFile_ << "plot ";
1701  for (int i = 0; i < interactionHandler.getSize(); ++i)
1702  {
1703  gnuplotFile_ << "\"" << getName() << ".overl" << "\"" << " using " << 2*i+4 << ":" << 2*i+3 << " title \"\" with lines lt 1 dashtype 2, ";
1704  }
1705 
1706  gnuplotFile_.close();
1707 
1708 }
1709 
1717 {
1718  std::ostringstream intStructName;
1719  intStructName << getName() << ".struct";
1720 
1721  intStructFile_.open(intStructName.str(), std::ios::out);
1722  intStructFile_ << "Number of Montecarlo points: " << nInternalStructurePoints_ << std::endl;
1723 }
std::vector< std::vector< int > > adjacencyMatrix_
Definition: BaseCluster.h:560
Vec3D getPosition() const
This returns the value of position_, which is the position in which the cluster will be inserted...
Definition: BaseCluster.cc:52
void setSpecies()
Sets species of particles.
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
void computeInternalStructure()
This computes the internal structure of the cluster.
void setCollisionTimeOverTimeStep(Mdouble cTOTS)
This sets the collisionTimeOverTimeStep number (which is the ratio between collision time and time st...
Definition: BaseCluster.cc:76
Mdouble minRelativeOverlap_
Definition: BaseCluster.h:568
Mdouble getCollisionTimeOverTimeStep() const
This returns the value of the ratio between collision time and time step.
Definition: BaseCluster.cc:68
Mdouble X
the vector components
Definition: Vector.h:65
void makeDataAnalysis()
This functions computes some important cluster information needed by the program. ...
bool isEneOutputOn() const
This returns the bool variable that defines whether the cluster ene output is written or not...
Definition: BaseCluster.cc:369
Mdouble t0_
Definition: BaseCluster.h:598
void writeToCdatFile()
This writes on the cluster data output file.
A basic particle.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
LinearPlasticViscoelasticFrictionSpecies * particleSpecies_
Definition: BaseCluster.h:513
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:840
void setNumberOfInternalStructurePoints(int gL)
This sets the value of the number of particles used to compute the internal structure.
Definition: BaseCluster.cc:217
LinearPlasticViscoelasticFrictionSpecies * getParticleSpecies() const
This returns the species of the particle.
Definition: BaseCluster.cc:243
void actionsAfterSolve() override
Overrides DPMBase actionsAfterSolve(): in this cluster data file and cluster overlap file are closed ...
Definition: BaseCluster.cc:733
void createAdjacencyMatrix()
This calculates the adjacency matrix of the cluster.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
bool isCdatOutputOn_
Definition: BaseCluster.h:518
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
void doOverlOutput(bool iOOO)
This sets the bool variable that defines whether the cluster overlap output will be written or not...
Definition: BaseCluster.cc:292
Mdouble velocityDampingInterval_
Definition: BaseCluster.h:610
void doIntStrucOutput(bool iISOO)
This sets the bool variable that defines whether the cluster internal structure output will be writte...
Definition: BaseCluster.cc:320
void doAmatOutput(bool iAOO)
This sets the bool variable that defines whether the cluster adjacency matrix output will be written ...
Definition: BaseCluster.cc:306
unsigned int getClusterId() const
This returns the value of the cluster ID.
Definition: BaseCluster.cc:175
void doEneOutput(bool isEneOutputOn)
This sets the bool variable that defines whether the cluster ene output will be written or not...
Definition: BaseCluster.cc:376
void insertParticles()
Inserts particles inside the domain.
Mdouble radiusParticle_
Definition: BaseCluster.h:481
void setParticlesWriteVTK(bool writeParticlesVTK)
Sets whether particles are written in a VTK file.
Definition: DPMBase.cc:904
void writeToOverlFile()
This writes on the cluster overlap output file.
void decreaseForce()
This linearly decreases values of forceModulus (stage = 2).
bool isVtkOutputOn_
Definition: BaseCluster.h:526
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Mdouble meanRelativeOverlap_
Definition: BaseCluster.h:566
Vec3D clusterVelocity_
Definition: BaseCluster.h:499
void setRadii()
Sets all radii according to particleRadius and sizeDispersityParticle.
Definition: BaseCluster.cc:981
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
void setSizeDispersityParticle(Mdouble sDP)
This sets the value of particles' dispersity in size.
Definition: BaseCluster.cc:117
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: DPMBase.cc:389
Mdouble boxSize_
Definition: BaseCluster.h:554
bool isVtkOutputOn() const
This returns the bool variable that defines whether the cluster vtk output is written or not...
Definition: BaseCluster.cc:327
void setZero()
Sets all elements to zero.
Definition: Vector.cc:43
void dampForce()
This damps values of forceModulus (stage = 3).
bool setNumberOfParticles_
Definition: BaseCluster.h:489
bool isIntStrucOutputOn_
Definition: BaseCluster.h:524
Mdouble maxRelativeOverlap_
Definition: BaseCluster.h:564
bool isIntStrucOutputOn() const
This returns the bool variable that defines whether the cluster internal structure output is written ...
Definition: BaseCluster.cc:313
int getNumberOfInternalStructurePoints() const
This returns the value of the number of particles used to compute internal structure.
Definition: BaseCluster.cc:209
void setSpecies(const ParticleSpecies *species)
Mdouble dissipationDuration_
Definition: BaseCluster.h:615
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
Mdouble getMassFromRadius(Mdouble radius) const
bool particleInsertionSuccessful(int n)
This function tries to insert the n-th particle (returns true if it manage to do that). It is inside insertParticles().
Mdouble getMeanClusterRadius()
this returns meanClusterRadius (radius of an ideal perfectly spherical cluster, there's no setter)...
Definition: BaseCluster.cc:383
bool isAmatOutputOn() const
This returns the bool variable that defines whether the cluster adjacency matrix output is written or...
Definition: BaseCluster.cc:299
std::ofstream gnuplotFile_
Definition: BaseCluster.h:578
void increaseForce()
This linearly increases the value of forceModulus (stage = 1).
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
void doCdatOutput(bool iCOO)
This sets the bool variable that defines whether the cluster data output will be written or not...
Definition: BaseCluster.cc:278
void makeAmatFile()
This creates the adjacency matrix file.
const Mdouble inf
Definition: GeneralDefine.h:44
bool isOverlOutputOn_
Definition: BaseCluster.h:520
bool isCdatOutputOn() const
This returns the bool variable that defines whether the cluster data output (which is NOT the mercury...
Definition: BaseCluster.cc:271
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
std::ofstream overlFile_
Definition: BaseCluster.h:576
void read(std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
Overrides DPMBase read(): in this all variables needed by the program for restarting are read...
Definition: BaseCluster.cc:836
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
Mdouble getSizeDispersityParticle() const
This returns the value of particles' dispersity in size.
Definition: BaseCluster.cc:109
Mdouble radiusCluster_
Definition: BaseCluster.h:495
bool isFStatOutputOn_
Definition: BaseCluster.h:530
void setVelocity(Vec3D v)
This sets the value of velocity after creation.
Definition: BaseCluster.cc:264
bool checkParticleForInteraction(const BaseParticle &P) final
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:588
Mdouble meanCoordinationNumber_
Definition: BaseCluster.h:562
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1059
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:1490
void setDomainLimits()
Sets domain limits.
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1370
Mdouble clusterTimeMax_
Definition: BaseCluster.h:600
file will not be created/read
void makeCdatFile()
Creates the cluster data output file.
Mdouble maximumForceModulus_
Definition: BaseCluster.h:604
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44
bool setRadiusParticle_
Definition: BaseCluster.h:483
void write(std::ostream &os, bool writeAllParticles=true) const override
Writes the MercuryBase to an output stream, for example a restart file.
Definition: MercuryBase.cc:146
Mdouble fileOutputTimeInterval_
Definition: BaseCluster.h:584
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1375
void write(std::ostream &os, bool writeAllParticles) const override
Overrides DPMBase write(): in this all variables needed by the program for restarting are written...
Definition: BaseCluster.cc:791
std::ofstream intStructFile_
Definition: BaseCluster.h:582
Mdouble getFinalMassFraction()
This gets the final value obtained for the mass fraction;.
Definition: BaseCluster.cc:165
unsigned int idCluster_
Definition: BaseCluster.h:493
Mdouble getMass() const
Returns the particle's mass.
Definition: BaseParticle.h:322
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
Definition: Helpers.cc:424
const Mdouble pi
Definition: ExtendedMath.h:45
std::ofstream amatFile_
Definition: BaseCluster.h:580
void actionsOnRestart() override
Overrides DPMBase actionsOnRestart(): in this all variables needed by the program for restarting are ...
Definition: BaseCluster.cc:882
void setVelocityDampingModulus(Mdouble vDM)
This sets the value of the velocity damping modulus.
Definition: BaseCluster.cc:200
void makeOverlFile()
Creates the cluster overlap output file.
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
all data will be written into/ read from a single file called name_
void makeGnuplotFile()
This creates the gnuplot file needed for printing force vs overlaps values.
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
void doVtkOutput(bool iVOO)
This sets the bool variable that defines whether the cluster vtk output will be written or not...
Definition: BaseCluster.cc:334
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
Definition: DPMBase.cc:1504
void printTime() const override
Overrides DPMBase printTime(): this way variables of interest are shown.
Definition: BaseCluster.cc:942
void doFStatOutput(bool isfStatOutputOn)
This sets the bool variable that defines whether the cluster fStat output will be written or not...
Definition: BaseCluster.cc:362
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:398
Mdouble collisionTimeOverTimeStep_
Definition: BaseCluster.h:475
Mdouble solidFraction_
Definition: BaseCluster.h:590
Mdouble energyRatioTolerance_
Definition: BaseCluster.h:477
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
Mdouble radiusForSolidFraction_
Definition: BaseCluster.h:588
void writeAmatFile()
This writes on the adjacency matrix file.
Vec3D position_
Definition: BaseCluster.h:471
Mdouble forceDampingModulus_
Definition: BaseCluster.h:617
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Mdouble getAverageOverlap()
this returns the average overlap.
Definition: BaseCluster.cc:390
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Mdouble sizeDispersityParticle_
Definition: BaseCluster.h:485
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1359
Mdouble forceModulus_
Definition: BaseCluster.h:606
Mdouble totalParticleVolume_
Definition: BaseCluster.h:550
void setXBallsAdditionalArguments(std::string newXBArgs)
Set the additional arguments for xballs.
Definition: DPMBase.cc:1307
std::ofstream cdatFile_
Definition: BaseCluster.h:574
bool isAmatOutputOn_
Definition: BaseCluster.h:522
Mdouble Y
Definition: Vector.h:65
~BaseCluster() final
Default destructor.
Definition: BaseCluster.cc:38
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:216
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:1324
Vec3D getVelocity()
This gets the value of velocity after creation.
Definition: BaseCluster.cc:257
Mdouble solidFractionIntStruct_
Definition: BaseCluster.h:592
void setGroupId(unsigned groupId)
Definition: BaseObject.h:131
bool isEneOutputOn_
Definition: BaseCluster.h:532
void dampVelocities()
This damps values of each particle velocity (stage = 1, stage = 2, stage = 3).
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Mdouble round(const Mdouble value, unsigned precision)
Definition: Helpers.cc:600
Mdouble massParticle_
Definition: BaseCluster.h:548
void setNumberOfParticles(int nP)
This sets the value of the number of particles in the cluster.
Definition: BaseCluster.cc:134
Vec3D centerOfMass_
Definition: BaseCluster.h:556
Mdouble smallestRadius_
Definition: BaseCluster.h:546
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:412
void applyCentralForce()
This applies force on each particle.
Mdouble meanClusterRadius_
Definition: BaseCluster.h:501
bool isRestartOutputOn() const
This returns the bool variable that defines whether the cluster restart output is written or not...
Definition: BaseCluster.cc:341
Mdouble velocityDampingModulus_
Definition: BaseCluster.h:505
Mdouble getEnergyRatioTolerance() const
This returns the value of the value of the energy ratio threshold under which the process can be cons...
Definition: BaseCluster.cc:226
Mdouble forceTuningDuration_
Definition: BaseCluster.h:612
void makeIntenalStructureFile()
This creates the file needed for writing down datas from computeInternalStructure().
void setParticleSpecies(LinearPlasticViscoelasticFrictionSpecies *particleSpecies)
This sets the species of the particle.
Definition: BaseCluster.cc:250
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1195
Mdouble getRadiusParticle() const
This returns the value of particles' radius if there's no dispersity in size. In case of dispersity !...
Definition: BaseCluster.cc:88
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: DPMBase.h:1380
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1385
int nInternalStructurePoints_
Definition: BaseCluster.h:509
void setEnergyRatioTolerance(Mdouble eRT)
This sets the value of the value of the energy ratio threshold under which the process can be conside...
Definition: BaseCluster.cc:234
Contains material and contact force properties.
Definition: Interaction.h:42
void doRestartOutput(bool isRestartOutputOn)
This sets the bool variable that defines whether the cluster restart output will be written or not...
Definition: BaseCluster.cc:348
Definition: Vector.h:49
void setRadiusParticle(Mdouble rP)
This sets the value of particles' radius if there's no dispersity in size.
Definition: BaseCluster.cc:97
void actionsAfterTimeStep() override
Overrides DPMBase actionsAfterTimeStep(): in this compression and decompression are computed...
Definition: BaseCluster.cc:621
int nIntraClusterBonds_
Definition: BaseCluster.h:570
void calculateTimeStep()
Calculates the time step.
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1211
Mdouble getVelocityDampingModulus() const
This returns the value of the velocity damping modulus.
Definition: BaseCluster.cc:192
bool isFStatOutputOn() const
This returns the bool variable that defines whether the cluster fStat output is written or not...
Definition: BaseCluster.cc:355
void read(std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
Reads the MercuryBase from an input stream, for example a restart file.
Definition: MercuryBase.cc:104
bool isRestartOutputOn_
Definition: BaseCluster.h:528
Mdouble Z
Definition: Vector.h:65
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition: DPMBase.cc:2896
void setupInitialConditions() override
Overrides DPMBase setupInitialConditions(): in this initial conditions for the problem are set...
Definition: BaseCluster.cc:425
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
Mdouble forceTuningInterval_
Definition: BaseCluster.h:608
bool isOverlOutputOn() const
This returns the bool variable that defines whether the cluster overlap output is written or not...
Definition: BaseCluster.cc:285
void setPosition(Vec3D p)
This sets the value of position_, which is the position in which the cluster will be inserted...
Definition: BaseCluster.cc:60
void setClusterId(unsigned int iC)
This sets the value of the cluster ID.
Definition: BaseCluster.cc:183
BaseCluster()
Default constructor.
Definition: BaseCluster.cc:31
int getNumberOfParticles() const
This returns the value of the number of particles in the cluster.
Definition: BaseCluster.cc:126
ReadOptions
Definition: DPMBase.h:240
bool setRadiusCluster_
Definition: BaseCluster.h:497
void setRadiusCluster(Mdouble rCR)
This sets the desired value of the cluster radius (there is no getter of this value, but there is a getter of the actual mean cluster radius obtained, getMeanClusterRadius)
Definition: BaseCluster.cc:149
std::vector< Mdouble > radii_
Definition: BaseCluster.h:544