Memosa-FVM  0.2
MPM Class Reference

#include <MPM_Particles.h>

Collaboration diagram for MPM:

Public Types

typedef Vector< double, 3 > VecD3
 
typedef Array< VecD3VecD3Array
 

Public Member Functions

 MPM (string fileName)
 
 MPM ()
 
 ~MPM ()
 
const StorageSitegetParticles () const
 
const StorageSitegetParticles (int num_particles)
 
const shared_ptr< Array< VecD3 > > & getCoordinates ()
 
const shared_ptr< Array< VecD3 > > & getVelocities ()
 
const shared_ptr< Array
< double > > & 
getTemperatures ()
 
const shared_ptr< Array< int > > & getTypes ()
 
void setCoordinates (const shared_ptr< ArrayBase > x)
 
void setVelocities (const shared_ptr< ArrayBase > v)
 
void setTypes (const shared_ptr< ArrayBase > type)
 
void setTemperatures (const shared_ptr< ArrayBase > t)
 
void setandwriteParticles (const char *file)
 
const shared_ptr< Array< VecD3 > > readVelocities (const char *file)
 
const shared_ptr< Array< VecD3 > > readCoordinates (const char *file)
 
const shared_ptr< Array< int > > readTypes (const char *file)
 
const shared_ptr< Array< double > > readTemperatures (const char *file)
 
void Init (const shared_ptr< Array< VecD3 > > coordinates, const shared_ptr< Array< VecD3 > > velocities, const shared_ptr< Array< int > > types, const shared_ptr< Array< double > > temperatures)
 
void Impl (string fileName)
 

Protected Attributes

StorageSite _particles
 
shared_ptr< Array< VecD3 > > _coordinates
 
shared_ptr< Array< VecD3 > > _velocities
 
shared_ptr< Array< int > > _types
 
shared_ptr< Array< double > > _temperatures
 

Detailed Description

Definition at line 15 of file MPM_Particles.h.

Member Typedef Documentation

typedef Vector<double,3> MPM::VecD3

Definition at line 24 of file MPM_Particles.h.

Definition at line 25 of file MPM_Particles.h.

Constructor & Destructor Documentation

MPM::MPM ( string  fileName)

Definition at line 15 of file MPM_Particles.cpp.

References Init(), readCoordinates(), readTemperatures(), readTypes(), and readVelocities().

15  :
16  _particles(0),
17  _coordinates(),
18  _velocities(),
19  _types(),
21 {
22  char* file;
23  file = &fileName[0];
24 
25  // MPM::setandwriteParticles(file);
26  //get coordinate
27  const shared_ptr<VecD3Array> MPM_Coordinates = MPM::readCoordinates(file);
28 
29  //get velocity
30  const shared_ptr<VecD3Array> MPM_Velocities = MPM::readVelocities(file);
31 
32  //get type
33  const shared_ptr<Array<int> > MPM_Types = MPM::readTypes(file);
34 
35  //get temperature
36  const shared_ptr<Array<double> > MPM_Temperatures = MPM::readTemperatures(file);
37  //store all the information in MPM class
38  MPM::Init(MPM_Coordinates, MPM_Velocities, MPM_Types, MPM_Temperatures);}
void Init(const shared_ptr< Array< VecD3 > > coordinates, const shared_ptr< Array< VecD3 > > velocities, const shared_ptr< Array< int > > types, const shared_ptr< Array< double > > temperatures)
const shared_ptr< Array< double > > readTemperatures(const char *file)
const shared_ptr< Array< VecD3 > > readCoordinates(const char *file)
shared_ptr< Array< int > > _types
Definition: MPM_Particles.h:74
shared_ptr< Array< double > > _temperatures
Definition: MPM_Particles.h:75
shared_ptr< Array< VecD3 > > _velocities
Definition: MPM_Particles.h:73
StorageSite _particles
Definition: MPM_Particles.h:71
const shared_ptr< Array< VecD3 > > readVelocities(const char *file)
const shared_ptr< Array< int > > readTypes(const char *file)
shared_ptr< Array< VecD3 > > _coordinates
Definition: MPM_Particles.h:72
MPM::MPM ( )

Definition at line 40 of file MPM_Particles.cpp.

40  :
41  _particles(0),
42  _coordinates(),
43  _velocities(),
44  _types(),
46 {}
shared_ptr< Array< int > > _types
Definition: MPM_Particles.h:74
shared_ptr< Array< double > > _temperatures
Definition: MPM_Particles.h:75
shared_ptr< Array< VecD3 > > _velocities
Definition: MPM_Particles.h:73
StorageSite _particles
Definition: MPM_Particles.h:71
shared_ptr< Array< VecD3 > > _coordinates
Definition: MPM_Particles.h:72
MPM::~MPM ( )

Definition at line 49 of file MPM_Particles.cpp.

49 { }

Member Function Documentation

const shared_ptr<Array<VecD3> >& MPM::getCoordinates ( )
inline

Definition at line 33 of file MPM_Particles.h.

References _coordinates.

Referenced by CellMark_Impl().

33 {return _coordinates;}
shared_ptr< Array< VecD3 > > _coordinates
Definition: MPM_Particles.h:72
const StorageSite& MPM::getParticles ( ) const
inline

Definition at line 27 of file MPM_Particles.h.

References _particles.

Referenced by CellMark_Impl().

27 {return _particles;}
StorageSite _particles
Definition: MPM_Particles.h:71
const StorageSite& MPM::getParticles ( int  num_particles)
inline

Definition at line 29 of file MPM_Particles.h.

References _particles, and StorageSite::setCount().

29  {
30  _particles.setCount( num_particles);
31  return _particles;}
void setCount(const int selfCount, const int nGhost=0)
Definition: StorageSite.h:42
StorageSite _particles
Definition: MPM_Particles.h:71
const shared_ptr<Array<double> >& MPM::getTemperatures ( )
inline

Definition at line 37 of file MPM_Particles.h.

References _temperatures.

37 {return _temperatures;}
shared_ptr< Array< double > > _temperatures
Definition: MPM_Particles.h:75
const shared_ptr<Array<int> >& MPM::getTypes ( )
inline

Definition at line 39 of file MPM_Particles.h.

References _types.

Referenced by CellMark_Impl().

39 {return _types;}
shared_ptr< Array< int > > _types
Definition: MPM_Particles.h:74
const shared_ptr<Array<VecD3> >& MPM::getVelocities ( )
inline

Definition at line 35 of file MPM_Particles.h.

References _velocities.

Referenced by CellMark_Impl().

35 {return _velocities;}
shared_ptr< Array< VecD3 > > _velocities
Definition: MPM_Particles.h:73
void MPM::Impl ( string  fileName)
void MPM::Init ( const shared_ptr< Array< VecD3 > >  coordinates,
const shared_ptr< Array< VecD3 > >  velocities,
const shared_ptr< Array< int > >  types,
const shared_ptr< Array< double > >  temperatures 
)

Definition at line 371 of file MPM_Particles.cpp.

References _particles, setCoordinates(), StorageSite::setCount(), setTemperatures(), setTypes(), and setVelocities().

Referenced by MPM().

375 {
376 
377  const int n = (*coordinates).getLength(); //number of particles
378  _particles.setCount(n);
379 
380  MPM::setCoordinates(coordinates);
381  MPM::setVelocities(velocities);
382  MPM::setTypes(types);
383  MPM::setTemperatures(temperatures);
384 
385 }
void setCount(const int selfCount, const int nGhost=0)
Definition: StorageSite.h:42
StorageSite _particles
Definition: MPM_Particles.h:71
void setTemperatures(const shared_ptr< ArrayBase > t)
Definition: MPM_Particles.h:51
void setCoordinates(const shared_ptr< ArrayBase > x)
Definition: MPM_Particles.h:42
void setTypes(const shared_ptr< ArrayBase > type)
Definition: MPM_Particles.h:48
void setVelocities(const shared_ptr< ArrayBase > v)
Definition: MPM_Particles.h:45
const shared_ptr< Array< VecD3 > > MPM::readCoordinates ( const char *  file)

Definition at line 261 of file MPM_Particles.cpp.

Referenced by MPM().

263 {
264  FILE *fp;
265  int nMPM;
266  double x=0, y=0, z=0;
267 
268  fp=fopen(file,"r");
269  fscanf(fp,"%i\n",&nMPM);
270  cout<<"number of particles is"<<nMPM<<endl;
271 
272  shared_ptr<Array<VecD3> > MPM_Points ( new Array<VecD3> (nMPM));
273  //read in coordinate
274  for(int i=0; i<nMPM; i++){
275  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
276  (*MPM_Points)[i][0]=x;
277  (*MPM_Points)[i][1]=y;
278  (*MPM_Points)[i][2]=z;
279  }
280  fclose(fp);
281  return (MPM_Points);
282 }
Definition: Array.h:14
const shared_ptr< Array< double > > MPM::readTemperatures ( const char *  file)

Definition at line 338 of file MPM_Particles.cpp.

Referenced by MPM().

340 {
341  FILE *fp;
342  int nMPM;
343  double x=0, y=0, z=0;
344  int t=0;
345  double temperature=0.0;
346  fp=fopen(file,"r");
347  fscanf(fp,"%i\n",&nMPM);
348 
349  shared_ptr<Array<double> > MPM_Points ( new Array<double> (nMPM));
350  //read in cooridnate and skip
351  for(int i=0; i<nMPM; i++){
352  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
353  }
354  //read in velocity and skip
355  for(int i=0; i<nMPM; i++){
356  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
357  }
358  //read in type
359  for(int i=0; i<nMPM; i++){
360  fscanf(fp,"%i\n", & t);
361  }
362  //read in temperature
363  for(int i=0; i<nMPM; i++){
364  fscanf(fp,"%lf\n", & temperature);
365  (*MPM_Points)[i]=temperature;
366  }
367  fclose(fp);
368  return (MPM_Points);
369 }
const shared_ptr< Array< int > > MPM::readTypes ( const char *  file)

Definition at line 311 of file MPM_Particles.cpp.

Referenced by MPM().

313 {
314  FILE *fp;
315  int nMPM;
316  double x=0, y=0, z=0;
317  int t=0;
318  fp=fopen(file,"r");
319  fscanf(fp,"%i\n",&nMPM);
320 
321  shared_ptr<Array<int> > MPM_Points ( new Array<int> (nMPM));
322  //read in cooridnate and skip
323  for(int i=0; i<nMPM; i++){
324  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
325  }
326  //read in velocity and skip
327  for(int i=0; i<nMPM; i++){
328  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
329  }
330  //read in type
331  for(int i=0; i<nMPM; i++){
332  fscanf(fp,"%i\n", & t);
333  (*MPM_Points)[i]=t;
334  }
335  fclose(fp);
336  return (MPM_Points);
337 }
const shared_ptr< Array< VecD3 > > MPM::readVelocities ( const char *  file)

Definition at line 284 of file MPM_Particles.cpp.

Referenced by MPM().

286 {
287  FILE *fp;
288  int nMPM;
289  double vx=0, vy=0, vz=0;
290  double x=0, y=0, z=0;
291  fp=fopen(file,"r");
292  fscanf(fp,"%i\n",&nMPM);
293 
294  shared_ptr<Array<VecD3> > MPM_Points ( new Array<VecD3> (nMPM));
295  //read in cooridnate and skip
296  for(int i=0; i<nMPM; i++){
297  fscanf(fp,"%lf\t%lf\t%lf\n", &x, &y, &z);
298  }
299  //read in velocity
300  for(int i=0; i<nMPM; i++){
301  fscanf(fp,"%lf\t%lf\t%lf\n", &vx, &vy, &vz);
302  (*MPM_Points)[i][0]=vx;
303  (*MPM_Points)[i][1]=vy;
304  (*MPM_Points)[i][2]=vz;
305  }
306  fclose(fp);
307  return (MPM_Points);
308 }
Definition: Array.h:14
void MPM::setandwriteParticles ( const char *  file)

Definition at line 52 of file MPM_Particles.cpp.

References mag(), and sin().

53 {
54 
55  FILE *fp;
56 
57  VecD3 center;
58  center[0]=0.0;
59  center[1]=0.0;
60  center[2]=0.0;
61 
62  int count=0;
63 
64 #if 0
65  //set up particle cartesian coordinate
66  VecD3 temp;
67 
68  const double innerSide = 1.0;
69  const double midSide = 3.0;
70  const double outerSide = 4.2;
71 
72  int nX=20, nY=20, nZ=1;
73 
74  double gapX=outerSide/(nX), gapY=outerSide/(nY), gapZ=0;
75  const int nMPM = (nX+1)*(nY+1)*nZ;
76  Array<VecD3> solidPoint(nMPM);
77  Array<VecD3> solidVelocity(nMPM);
78  Array<int> type(nMPM);
79  Array<double> solidTemperature(nMPM);
80  for(int i=0; i<=nX; i++){
81  for(int j=0; j<=nY; j++){
82  for(int k=0; k<nZ; k++){
83  temp[0]=i*gapX-outerSide/2.;
84  temp[1]=j*gapY-outerSide/2.;
85  temp[2]=k*gapZ;
86  //inner square
87  if( temp[0]>=(-innerSide/2.) && temp[0]<=(innerSide/2.) && temp[1]>=(-innerSide/2.) && temp[1]<=(innerSide/2.))
88  {
89  //surface particles
90  type[count] = 0;
91  if( temp[0]> (innerSide/2.0-gapX) || temp[0]<(-innerSide/2.0+gapX))
92  type[count]=1;
93  if( temp[1]> (innerSide/2.0-gapY) || temp[1]<(-innerSide/2.0+gapY))
94  type[count]=1;
95  //rotate
96  double alfa = atan(1.);
97  solidPoint[count][0]=temp[0]*cos(alfa)-temp[1]*sin(alfa);
98  solidPoint[count][1]=temp[1]*cos(alfa)+temp[0]*sin(alfa);
99  solidPoint[count][2]=temp[2];
100 
101  count+=1;
102  }
103 
104  //outer square
105  if( !(temp[0]>(-midSide/2.) && temp[0]<(midSide/2.) && temp[1]>(-midSide/2.) && temp[1]<(midSide/2.)))
106  {
107  type[count] = 0;
108  //surface particles
109 
110  if( temp[0]< (midSide/2.0+gapX) && temp[0]>(midSide/2.0-gapX) && temp[1]<(midSide/2.0+gapY) && temp[1]>(-midSide/2.0-gapY))
111  type[count]=1;
112  if( temp[0]> (-midSide/2.0-gapX) && temp[0]<(-midSide/2.0+gapX) && temp[1]<(midSide/2.0+gapY) && temp[1]>(-midSide/2.0-gapY))
113  type[count]=1;
114  if( temp[1]< (midSide/2.0+gapY) && temp[1]>(midSide/2.0-gapY) && temp[0]<(midSide/2.0+gapX) && temp[0]>(-midSide/2.0-gapX))
115  type[count]=1;
116  if( temp[1]> (-midSide/2.0-gapY) && temp[1]<(-midSide/2.0+gapY) && temp[0]<(midSide/2.0+gapX) && temp[0]>(-midSide/2.0-gapX))
117  type[count]=1;
118 
119  double alfa = atan(1);
120  solidPoint[count][0]=temp[0]*cos(alfa)-temp[1]*sin(alfa);
121  solidPoint[count][1]=temp[1]*cos(alfa)+temp[0]*sin(alfa);
122  solidPoint[count][2]=temp[2];
123  count+=1;
124  }
125 
126  }
127  }
128  }
129 
130 
131 #endif
132 
133 #if 0
134  int nX=81, nY=400, nZ=1;
135  double radius1=0., radius2=0.2;
136  double gapR=(radius2-radius1)/(nX-1), gapAngle=2*3.1415926/nY, gapZ=1.0/nZ;
137 
138  const int nMPM = nX*nY*nZ;
139  Array<VecD3> solidPoint(nMPM);
140  Array<VecD3> solidVelocity(nMPM);
141  Array<int> type(nMPM);
142  Array<double> solidTemperature(nMPM);
143 
144 
145  //polar coordinate
146  for(int i=0; i<nX; i++){
147  for(int j=0; j<nY; j++){
148  for(int k=0; k<nZ; k++){
149  solidPoint[count][0]=(radius1+i*gapR)*(cos(j*gapAngle))+center[0];
150  solidPoint[count][1]=(radius1+i*gapR)*(sin(j*gapAngle))+center[1];
151  solidPoint[count][2]=k*gapZ+center[2];
152 
153  if(i!=(nX-1)) type[count] = 0; //internal particles
154  if(i==(nX-1)){
155  type[count] = 1; //surface particles
156  }
157  count+=1;
158  }
159  }
160  }
161 
162  /*
163  radius1=0.9, radius2=1.5;
164  gapR=(radius2-radius1)/nX, gapAngle=2*3.1415926/nY, gapZ=1.0/nZ;
165 
166  //polar coordinate
167  for(int i=0; i<nX; i++){
168  for(int j=0; j<nY; j++){
169  for(int k=0; k<nZ; k++){
170  solidPoint[count][0]=(radius1+i*gapR)*(cos(j*gapAngle))+center[0];
171  solidPoint[count][1]=(radius1+i*gapR)*(sin(j*gapAngle))+center[1];
172  solidPoint[count][2]=k*gapZ+center[2];
173 
174  if(i!=0) type[count] = 0; //internal particles
175  if(i==0){
176  type[count] = 1; //surface particles
177  }
178  count+=1;
179  }
180  }
181  }
182  */
183 #endif
184 #if 1
185  int nX=21, nY=300, nZ=400;
186  const double pi = atan(1.0)*4.0;
187  double radius1=0., radius2=10;
188  double gapR=(radius2-radius1)/(nX-1), gapAlfa=pi/nY, gapBeta=2*pi/nZ;
189  const int nMPM = nX*nY*nZ;
190  Array<VecD3> solidPoint(nMPM);
191  Array<VecD3> solidVelocity(nMPM);
192  Array<int> type(nMPM);
193  Array<double> solidTemperature(nMPM);
194  //polar coordinate
195  for(int i=0; i<nX; i++){
196  for(int j=0; j<nY; j++){
197  for(int k=0; k<nZ; k++){
198  solidPoint[count][0]=(radius1+i*gapR)*sin(j*gapAlfa)*(cos(k*gapBeta))+center[0];
199  solidPoint[count][1]=(radius1+i*gapR)*sin(j*gapAlfa)*(sin(k*gapBeta))+center[1];
200  solidPoint[count][2]=(radius1+i*gapR)*cos(j*gapAlfa)+center[2];
201 
202  type[count] = 0; //internal particles
203  if(i==nX-1){
204  type[count] = 1; //surface particles
205  }
206  count+=1;
207  }
208  }
209  }
210 
211 #endif
212  //set up particle velocity
213 #if 1
214  for(int p=0; p<count; p++){
215  solidVelocity[p][0]=0.0;
216  solidVelocity[p][1]=0.0;
217  solidVelocity[p][2]=0.0;
218  }
219 #endif
220 
221 #if 0
222  //set up rotating cylinder velcity
223  const double angV = 1;
224  for (int p=0; p<count; p++){
225  double r = mag(solidPoint[p]-center);
226  double angle = atan2(solidPoint[p][1]-center[1],solidPoint[p][0]-center[0]);
227  solidVelocity[p][0] = -angV*r*sin(angle);
228  solidVelocity[p][1] = angV*r*cos(angle);
229  solidVelocity[p][2] = 0.0;
230  }
231 #endif
232 
233  //set up temperature
234  const double InitT=300.0;
235  for (int p=0; p<count; p++){
236  solidTemperature[p]=InitT;
237  }
238 
239 
240  cout<<"count of particles is "<<count<<endl;
241  //write out coordinate and velocity and particle type into file
242  fp=fopen(file,"w");
243  fprintf(fp,"%i\n",count);
244  for(int p=0; p<count; p++){
245  fprintf(fp, "%e\t%e\t%e\n", solidPoint[p][0],solidPoint[p][1],solidPoint[p][2]);
246  }
247  for(int p=0; p<count; p++){
248  fprintf(fp, "%e\t%e\t%e\n", solidVelocity[p][0],solidVelocity[p][1],solidVelocity[p][2]);
249  }
250  for(int p=0; p<count; p++){
251  fprintf(fp, "%i\n", type[p]);
252  }
253  for(int p=0; p<count; p++){
254  fprintf(fp, "%f\n", solidTemperature[p]);
255  }
256  fclose(fp);
257 
258 }
T mag(const Vector< T, 3 > &a)
Definition: Vector.h:260
Tangent sin(const Tangent &a)
Definition: Tangent.h:307
Definition: Array.h:14
void MPM::setCoordinates ( const shared_ptr< ArrayBase x)
inline

Definition at line 42 of file MPM_Particles.h.

References _coordinates.

Referenced by Init().

43  {_coordinates = dynamic_pointer_cast< Array<VecD3> > ( x );}
Definition: Array.h:14
shared_ptr< Array< VecD3 > > _coordinates
Definition: MPM_Particles.h:72
void MPM::setTemperatures ( const shared_ptr< ArrayBase t)
inline

Definition at line 51 of file MPM_Particles.h.

References _temperatures.

Referenced by Init().

52  {_temperatures = dynamic_pointer_cast< Array<double> > (t);}
shared_ptr< Array< double > > _temperatures
Definition: MPM_Particles.h:75
void MPM::setTypes ( const shared_ptr< ArrayBase type)
inline

Definition at line 48 of file MPM_Particles.h.

References _types.

Referenced by Init().

49  {_types = dynamic_pointer_cast< Array<int> > (type);}
shared_ptr< Array< int > > _types
Definition: MPM_Particles.h:74
void MPM::setVelocities ( const shared_ptr< ArrayBase v)
inline

Definition at line 45 of file MPM_Particles.h.

References _velocities.

Referenced by Init().

46  {_velocities = dynamic_pointer_cast< Array<VecD3> > (v);}
shared_ptr< Array< VecD3 > > _velocities
Definition: MPM_Particles.h:73
Definition: Array.h:14

Member Data Documentation

shared_ptr<Array<VecD3> > MPM::_coordinates
protected

Definition at line 72 of file MPM_Particles.h.

Referenced by getCoordinates(), and setCoordinates().

StorageSite MPM::_particles
protected

Definition at line 71 of file MPM_Particles.h.

Referenced by getParticles(), and Init().

shared_ptr<Array<double> > MPM::_temperatures
protected

Definition at line 75 of file MPM_Particles.h.

Referenced by getTemperatures(), and setTemperatures().

shared_ptr<Array<int> > MPM::_types
protected

Definition at line 74 of file MPM_Particles.h.

Referenced by getTypes(), and setTypes().

shared_ptr<Array<VecD3> > MPM::_velocities
protected

Definition at line 73 of file MPM_Particles.h.

Referenced by getVelocities(), and setVelocities().


The documentation for this class was generated from the following files: