inflowFromPeriodic.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #include "scr/Chute.h"
6 
7 class inflowFromPeriodic : public Chute
8 {
9 public:
11  //load particles and chute setup into periodic chute
12  setName("../../H20A22L0.5M0.5");
13  load_restart_data();
14  setRestarted(false);
15 
16  // adds new species
18 
19  // creates bottom outside periodic chute of species 1
20  set_Nmax(get_N()*12.);
21  int N=get_N();
22  for (int j=0; j<5; j++) {
23  for (int i=0; i<N; i++) {
24  if (Particles[i].is_fixed()) {
25  Particles.push_back(Particles[i]);
26  Particles.back().indSpecies=1;
27  Particles.back().Position.X+=20*j;
28  }
29  }
30  }
31 
32  Chute SlowBottom;
33  SlowBottom.setName("../../H20A22L0.75M0.5");
34  SlowBottom.load_restart_data();
35  for (int j=5; j<10; j++) {
36  for (int i=0; i<SlowBottom.get_N(); i++) {
37  if (SlowBottom.getObjects()[i].is_fixed()) {
38  Particles.push_back(SlowBottom.getObjects()[i]);
39  Particles.back().indSpecies=1;
40  Particles.back().Position.X+=20*j;
41  }
42  }
43  }
44  setXMax(10*getXMax());
45 
46  Walls.resize(0);
47  }
48 
49  inflowFromPeriodic(string restart_file) {
50  //load particles and chute setup into periodic chute
51  setName(restart_file.c_str());
52  load_restart_data();
53  setName("restarted");
54  set_HGRID_num_buckets_to_power();
55  }
56 
57  //Do not add or remove particles
58  void actionsBeforeTimeStep() override {cleanChute();};
59 
60  void cleanChute() {
61  //clean outflow every 100 time steps
62  static int count = 0, maxcount = 100;
63  if (count>maxcount)
64  {
65  count = 0;
66  // delete all outflowing particles
67  for (unsigned int i=0;i<Particles.size();)
68  {
69  if (Particles[i].Position.Z<getZMin()-10)//||Particles[i].Position.Z+Particles[i].Radius<zmin)
70  {
71  #ifdef DEBUG_OUTPUT_FULL
72  cout << "erased:" << Particles[i] << endl;
73  #endif
74  removeParticle(i);
75  }
76  else i++;
77  }
78  } else count++;
79  }
80 
81  //Do not add bottom
82  void setupInitialConditions() override {}
83 
85  {
86  Particles[i].Velocity += Particles[i].Force*Particles[i].get_invmass()*0.5*getTimeStep();
87  Particles[i].Position += Particles[i].Velocity*getTimeStep();
88  if (speciesHandler.getObject(0)->mu)
89  {
90  Particles[i].AngularVelocity += Particles[i].Torque*Particles[i].get_invinertia()*0.5*getTimeStep();
91  Particles[i].Angle += Particles[i].AngularVelocity*getTimeStep();
92  }
93 
94  // This shifts particles that moved through periodic walls
95  if (Particles[i].indSpecies==0 && WallsPeriodic[0].distance(Particles[i])<0) {
96  if (Particles[i].Position.X>18 && Particles[i].Position.X<22) {
97  if (get_Nmax()<=get_N()) set_Nmax(get_Nmax()+10000);
98  Particles.push_back(Particles[i]);
99  Particles.back().indSpecies=1;
100  }
101  WallsPeriodic[0].shift_position(Particles[i].Position);
102  }
103  if (WallsPeriodic[1].distance(Particles[i])<0)
104  WallsPeriodic[1].shift_position(Particles[i].Position);
105  }
106 
107  //~ void computeExternalForces(int CI) {
108  //~ MD::computeExternalForces(CI);
109  //limit force
110  //~ if (Particles[CI].indSpecies==1 && Particles[CI].Position.X<40) {
111  //~ Particles[CI].Force *= max(0.,(Particles[CI].Position.X-22.)/18.);
112  //~ if (std::max(0.,(Particles[CI].Position.X-22.)/18.))
113  //~ cout << max(0.,(Particles[CI].Position.X-22.)/18.) << endl;
114  //~ }
115  //~ }
116 
117  void printTime() {
118  int counter=0;
119  for (int i=0; i<get_N(); i++)
120  if (Particles[i].indSpecies==0) counter++;
121 
122  cout << "t=" << setprecision(3) << left << setw(6) << getTime()
123  << ", Nmax=" << setprecision(3) << left << setw(6) << get_Nmax()
124  << ", counter=" << setprecision(3) << left << setw(6) << counter << endl;
125  }
126 
127  void add_forces(int PI, int PJreal) {
128  // Add and subtract this force to the force acting on particles i, j
129  if (Particles[PI ].indSpecies!=Particles[PJreal].indSpecies) {
130  if (Particles[PI ].indSpecies==0) {
131  if (Particles[PI ].Position.X>18) {
132  Particles[PJreal].Force-=force;
133  }
134  } else {
135  if (Particles[PJreal].Position.X>18) {
136  Particles[PI ].Force+=force;
137  }
138  }
139  } else {
140  Particles[PI ].Force+=force;
141  Particles[PJreal].Force-=force;
142  }
143  }
144 
145  int Check_and_Duplicate_Periodic_Particle(int i, int nWallPeriodic)
146  {
147  int C=0; //Number of particles created
148  if (nWallPeriodic==0 && Particles[i].indSpecies==0 && WallsPeriodic[0].distance(Particles[i])<Particles[i].Radius+get_radius_of_largest_particle())
149  {
150  CParticle F0=Particles[i];
151  WallsPeriodic[0].shift_position(F0.Position);
152 
153  //If Particle is double shifted, get correct original particle
154  int From=i;
155  while(Particles[From].get_periodicFromParticle()!=-1)
156  From=Particles[From].get_periodicFromParticle();
157  F0.set_periodicFromParticle(From);
158 
159  Particles.push_back(F0);
160  HGridInsertParticleToHgrid(Particles[get_N()-1]);
161  C++;
162 
163  //Check for double shifted particles
164  C+=Check_and_Duplicate_Periodic_Particle(get_N()-1, 0+1);
165  }
166  for (int k=max(1,nWallPeriodic); k<get_NWallPeriodic(); k++) { //Loop over all still posible walls
168  if (WallsPeriodic[k].distance(Particles[i])<Particles[i].Radius+get_radius_of_largest_particle())
169  {
170  CParticle F0=Particles[i];
171  WallsPeriodic[k].shift_position(F0.Position);
172 
173  //If Particle is double shifted, get correct original particle
174  int From=i;
175  while(Particles[From].get_periodicFromParticle()!=-1)
176  From=Particles[From].get_periodicFromParticle();
177  F0.set_periodicFromParticle(From);
178 
179  Particles.push_back(F0);
180  HGridInsertParticleToHgrid(Particles[get_N()-1]);
181  C++;
182 
183  //Check for double shifted particles
185  }
186  }
187  return(C);
188  }
189 
191  {
192 
193  stringstream file_name;
194  ofstream script_file;
195  file_name << problem_name.str() <<".disp";
196  script_file.open((file_name.str()).c_str());
197 
199  script_file << "#!/bin/bash" << endl;
200  script_file << "x=$(echo $0 | cut -c2-)" << endl;
201  script_file << "file=$PWD$x" << endl;
202  script_file << "dirname=`dirname \"$file\"`" << endl;
203  script_file << "cd $dirname" << endl;
204 
205  double scale;
206  int format;
207 
208  int width=1700-140, height=1000-140;
209  int ratio=getSystemDimensions()<3?(getXMax()-getXMin())/(getYMax()-getYMin()):(getXMax()-getXMin())/(getZMax()-getZMin());
210  if (ratio>width/height) height=width/ratio;
211  else width=height*ratio;
212 
213  if (getSystemDimensions()<3)
214  { // dim = 1 or 2
215  format = 8;
216  if (getXBallsScale()<0)
217  {
218  scale = 1.0 / max( getYMax()-getYMin(), getXMax()-getXMin() );
219  }
220  else
221  {
222  scale=getXBallsScale();
223  }
224  }
225  else
226  { //dim==3
227  format = 14;
228  if (getXBallsScale()<0)
229  {
230  scale = width/480/(getXMax()-getXMin());
231  }
232 
233  else
234  {
235  scale=getXBallsScale();
236  }
237 
238  }
239 
240  script_file << "../xballs -format " << format
241  << " -f " << data_filename.str() << ((get_options_data()==2)?"'.0000":"")
242  << " -s " << scale
243  << " -w " << width+140
244  << " -h " << height+140
245  << " -cmode " << getXBallsColourMode()
246  << " -cmax -scala 4 -sort "
248  << " $*";
249  if (getXBallsVectorScale()>-1)
250  {
251  script_file << " -vscale " << getXBallsVectorScale();
252  }
253  script_file.close();
254 
255  //This line changes teh file permision and give the owener (i.e. you) read, write and excute permission to the file.
256  chmod((file_name.str().c_str()),S_IRWXU);
257 
258  }
259 
260 
261  //~ void outputXBallsData()
262  //~ {
263  //~ format=14;
264  //~ // This outputs the location of walls and how many particles there are to file this is required by the xballs plotting
265  //~ int counter=0;
266  //~ for (unsigned int i = 0;i<Particles.size();i++) if (Particles[i].indSpecies==0) counter++;
267  //~ if (format!=14) // dim = 1 or 2
268  //~ data_file << Particles.size()-counter << " " <<t << " "
269  //~ << xmin << " " << ymin << " "
270  //~ << xmax << " " << ymax << " " << endl;
271  //~ else //dim==3
272  //~ data_file << Particles.size()-counter << " " <<t << " "
273  //~ << xmin << " " << ymin << " " << zmin << " "
274  //~ << xmax << " " << ymax << " " << zmax << " " << endl;
275  //~ // This outputs the particle data
276  //~ for (unsigned int i = 0;i<Particles.size();i++) {
277  //~ if (Particles[i].indSpecies==1) outputXBallsDataParticle(i);
278  //~ }
279  //~ }
280 
281 };
int i
Definition: BiCGSTAB_step_by_step.cpp:9
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:360
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:621
Creates chutes with different bottoms. Inherits from Mercury3D (-> MercuryBase -> DPMBase).
Definition: Chute.h:44
int getXBallsColourMode() const
Get the xballs colour mode (CMode).
Definition: DPMBase.cc:1301
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin.
Definition: DPMBase.h:603
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax.
Definition: DPMBase.h:610
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
double getXBallsVectorScale() const
Returns the scale of vectors used in xballs.
Definition: DPMBase.cc:1321
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin.
Definition: DPMBase.h:616
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:400
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1241
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:799
std::string getXBallsAdditionalArguments() const
Returns the additional arguments for xballs.
Definition: DPMBase.cc:1346
void setRestarted(bool newRestartedFlag)
Allows to set the flag stating if the simulation is to be restarted or not.
Definition: DPMBase.cc:1492
void setXMax(Mdouble newXMax)
Sets the value of XMax, the upper bound of the problem domain in the x-direction.
Definition: DPMBase.cc:1156
double getXBallsScale() const
Returns the scale of the view in xballs.
Definition: DPMBase.cc:1363
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax.
Definition: DPMBase.h:622
unsigned int getSystemDimensions() const
Returns the system dimensionality.
Definition: DPMBase.cc:1421
Mdouble getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax.
Definition: DPMBase.h:634
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin.
Definition: DPMBase.h:628
Definition: inflowFromPeriodic.h:8
int Check_and_Duplicate_Periodic_Particle(int i, int nWallPeriodic)
Definition: inflowFromPeriodic.h:145
void integrateBeforeForceComputation(int i)
Definition: inflowFromPeriodic.h:84
void add_forces(int PI, int PJreal)
Definition: inflowFromPeriodic.h:127
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: inflowFromPeriodic.h:82
void actionsBeforeTimeStep() override
A virtual function which allows to define operations to be executed before the new time step.
Definition: inflowFromPeriodic.h:58
inflowFromPeriodic()
Definition: inflowFromPeriodic.h:10
void writeXBallsScript()
Definition: inflowFromPeriodic.h:190
void cleanChute()
Definition: inflowFromPeriodic.h:60
inflowFromPeriodic(string restart_file)
Definition: inflowFromPeriodic.h:49
void printTime()
Definition: inflowFromPeriodic.h:117
Definition: matrices.h:74
@ N
Definition: constructor.cpp:22
#define max(a, b)
Definition: datatypes.h:23
char char char int int * k
Definition: level2_impl.h:374
double Radius
Radius of the pipe.
Definition: pipe.cc:55
double height(const double &x)
Height of domain.
Definition: simple_spine_channel.cc:429
string file_name
Definition: Particles2023AnalysisHung.py:321
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:217
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2