Memosa-FVM  0.2
ContactModel_impl.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #include "Mesh.h"
6 #include "Array.h"
7 #include "Field.h"
8 #include "Vector.h"
9 #include "KSearchTree.h"
10 #include "ContactModel.h"
11 #include "PhysicsConstant.h"
12 
13 
14 
15 
16 template<class T>
17 class ContactModel<T>::Impl
18 {
19 
20  public:
21  typedef Array<T> TArray;
26 
27 
28  Impl(const GeomFields& geomFields,
29  ContactFields& contactFields,
30  const MeshList& meshes) :
31  _meshes(meshes),
32  _geomFields(geomFields),
33  _contactFields(contactFields)
34  { }
35 
36  void init()
37  {}
38 
39  ContactModelConstants<T>& getConstants() {return _constants;}
40 
41  void computeSolidSurfaceForce(const StorageSite& solidFaces, bool perUnitArea)
42  {
43  const int nSolidFaces = solidFaces.getCount();
44 
45  boost::shared_ptr<VectorT3Array>
46  forcePtr( new VectorT3Array(nSolidFaces));
47 
48  VectorT3Array& force = *forcePtr;
49 
50  force.zero();
51 
52  _contactFields.force.addArray(solidFaces,forcePtr);
53 
54  const VectorT3Array& solidFaceCentroid =
55  dynamic_cast<const VectorT3Array&>(_geomFields.coordinate[solidFaces]);
56 
57  //const VectorT3Array& solidFaceArea =
58  // dynamic_cast<const VectorT3Array&>(_geomFields.area[solidFaces]);
59 
60  const TArray& solidFaceAreaMag =
61  dynamic_cast<const TArray&>(_geomFields.areaMag[solidFaces]);
62 
63 
64  vector<NearestCell> solidFacesNearestCell(nSolidFaces);
65 
66 
67  //for each face in solidFaces, find out the nearest neighbor on substrate
68  /*
69  const int numMeshes = _meshes.size();
70  for (int n=0; n<numMeshes; n++)
71  {
72  const Mesh& mesh = *_meshes[n];
73  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
74  {
75  const FaceGroup& fg = *fgPtr;
76  if (fg.id == 5){
77  const StorageSite& faces = fg.site;
78  const VectorT3Array& fluidFaceCoords =
79  dynamic_cast<const VectorT3Array&>(_geomFields.coordinate[faces]);
80 
81  FILE *fp = fopen("./fluidface.dat","w");
82  for (int i=0; i<fg.site.getCount();i++){
83  fprintf(fp, "%i\t%e\t%e\t%e\n", i, fluidFaceCoords[i][0], fluidFaceCoords[i][1], fluidFaceCoords[i][2]);
84  }
85  fclose(fp);
86 
87  KSearchTree searchTree(fluidFaceCoords);
88 
89  Array<int> fluidNeighbors(1);
90 
91  for(int f=0; f<nSolidFaces; f++)
92  {
93  const VectorT3& xf = solidFaceCentroid[f];
94  searchTree.findNeighbors(xf, 1, fluidNeighbors);
95  const int c = fluidNeighbors[0];
96  const VectorT3& xc = fluidFaceCoords[c];
97  const double distanceSquared = mag2(xf-xc);
98  NearestCell& nc = solidFacesNearestCell[f];
99  if ((nc.mesh == 0) || (nc.distanceSquared > distanceSquared))
100  {
101  nc.mesh = &mesh;
102  nc.cell = c;
103  nc.distanceSquared = distanceSquared;
104  }
105  }
106  }
107  }
108  }
109  */
110  //for each face in solidFaces, calculate the contact force based on the nearest distance
111  const double H = 0.23e-20;
112  const double B = 3529e3;
113  const double alpha = 0.1127;
114  const double gamma = 22.69e9;
115  const double alpha01 = 1.6e-9;
116  const double alpha02 = 1.99e-9;
117 
118  const double thickness = _constants["thickness"];
119  const double gap = _constants["gap"];
120 
121  double cloestDistance = 1.;
122  cout << "gap " << gap << " thickness "<< thickness << endl;
123  for(int f=0; f<nSolidFaces; f++) {
124  //const double distance = sqrt(solidFacesNearestCell[f].distanceSquared);
125  const VectorT3& xf = solidFaceCentroid[f];
126  const double distance = gap + thickness*0.5 + xf[2];
127  if (distance < cloestDistance)
128  cloestDistance = distance;
129  //force[f] = -H/(6*PI) * ((1-alpha)/pow(distance,3) + alpha/pow(distance-alpha01,3))
130  // + B*exp(-(distance-alpha02)*gamma);
131  force[f][2] = B*exp(-(distance-alpha02)*gamma);
132 
133  if (!perUnitArea){
134  force[f] *= solidFaceAreaMag[f];
135  }
136  }
137 
138  cout << "cloest distance between beam and substrate " << cloestDistance << endl;
139  /*
140  FILE *fp2 = fopen("./force.dat","w");
141  for(int f=0; f<nSolidFaces; f++) {
142  fprintf(fp2, "%i\t%e\t%e\t%e\n", f, force[f][0],force[f][1],force[f][2]);
143  }
144  fclose(fp2);
145  FILE *fp1 = fopen("./beamCoords.dat","w");
146  for(int f=0; f<nSolidFaces; f++) {
147  fprintf(fp1, "%i\t%e\t%e\t%e\n", f, solidFaceCentroid[f][0], solidFaceCentroid[f][1],solidFaceCentroid[f][2]);
148  }
149  fclose(fp1);
150  */
151  }
152  private:
157 
158 };
159 
160 template<class T>
162  ContactFields& contactFields,
163  const MeshList& meshes) :
164  Model(meshes),
165  _impl(new Impl(geomFields,contactFields,meshes))
166 {
167  logCtor();
168 }
169 
170 
171 template<class T>
173 {
174  logDtor();
175 }
176 
177 template<class T>
178 void
180 {
181  _impl->init();
182 }
183 
184 template<class T>
185 void
187 {
188  return _impl->computeSolidSurfaceForce(particles,false);
189 }
190 
191 template<class T>
192 void
194 {
195  return _impl->computeSolidSurfaceForce(particles,true);
196 }
197 
198 template<class T>
200 ContactModel<T>::getConstants() {return _impl->getConstants();}
201 
202 template<class T>
204 {
205  public:
207  mesh(0),
208  cell(-1),
209  distanceSquared(0) {};
210 
211  const Mesh* mesh;
212  int cell;
214  set<int> neighbors;
215 };
216 
virtual void zero()
Definition: Array.h:281
Vector< T, 3 > VectorT3
Array< VectorT3 > VectorT3Array
ContactModelConstants< T > _constants
const GeomFields & _geomFields
void computeSolidSurfaceForcePerUnitArea(const StorageSite &particles)
void computeSolidSurfaceForce(const StorageSite &solidFaces, bool perUnitArea)
Definition: Mesh.h:49
#define logCtor()
Definition: RLogInterface.h:26
Vector< double, 3 > VectorD3
Array< Vector< double, 3 > > VectorT3Array
Definition: CellMark.cpp:7
Impl(const GeomFields &geomFields, ContactFields &contactFields, const MeshList &meshes)
void computeSolidSurfaceForce(const StorageSite &particles)
ContactModelConstants< T > & getConstants()
const MeshList _meshes
Definition: Model.h:29
Definition: Model.h:13
ContactModelConstants< T > & getConstants()
#define logDtor()
Definition: RLogInterface.h:33
virtual void init()
Definition: Array.h:14
int getCount() const
Definition: StorageSite.h:39
virtual ~ContactModel()
ContactModel(const GeomFields &geomFields, ContactFields &contactFields, const MeshList &meshes)
ContactFields & _contactFields
vector< Mesh * > MeshList
Definition: Mesh.h:439
const MeshList _meshes