CFDEMcoupling  2.4
 All Classes
dataExchangeModel.H
1 /*---------------------------------------------------------------------------*\
2  CFDEMcoupling - Open Source CFD-DEM coupling
3 
4  CFDEMcoupling is part of the CFDEMproject
5  www.cfdem.com
6  Christoph Goniva, christoph.goniva@cfdem.com
7  Copyright 2009-2012 JKU Linz
8  Copyright 2012- DCS Computing GmbH, Linz
9 -------------------------------------------------------------------------------
10 License
11  This file is part of CFDEMcoupling.
12 
13  CFDEMcoupling is free software; you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by the
15  Free Software Foundation; either version 3 of the License, or (at your
16  option) any later version.
17 
18  CFDEMcoupling is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with CFDEMcoupling; if not, write to the Free Software Foundation,
25  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 
27 Description
28  This code is designed to realize coupled CFD-DEM simulations using LIGGGHTS
29  and OpenFOAM(R). Note: this code is not part of OpenFOAM(R) (see DISCLAIMER).
30 
31 Class
32  dataExchangeModel
33 
34 SourceFiles
35  dataExchangeModel.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef dataExchangeModel_H
40 #define dataExchangeModel_H
41 
42 #include "fvCFD.H"
43 #include "cfdemCloud.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class dataExchangeModel Declaration
51 \*---------------------------------------------------------------------------*/
52 
54 {
55 
56 protected:
57 
58  // Protected data
59  const dictionary& dict_;
60 
61  cfdemCloud& particleCloud_;
62 
63  int maxNumberOfParticles_;
64 
65  mutable int couplingStep_;
66 
67  scalar DEMts_;
68 
69  int couplingInterval_;
70 
71  // Protected member functions
72 
73 public:
74 
75  //- Runtime type information
76  TypeName("dataExchangeModel");
77 
78  // Declare runtime constructor selection table
79 
80  declareRunTimeSelectionTable
81  (
82  autoPtr,
84  dictionary,
85  (
86  const dictionary& dict,
87  cfdemCloud& sm
88  ),
89  (dict,sm)
90  );
91 
92 
93  // Constructors
94 
95  //- Construct from components
97  (
98  const dictionary& dict,
99  cfdemCloud& sm
100  );
101 
102 
103  // Destructor
104 
105  virtual ~dataExchangeModel();
106 
107 
108  // Selector
109 
110  static autoPtr<dataExchangeModel> New
111  (
112  const dictionary& dict,
113  cfdemCloud& sm
114  );
115 
116 
117  // Member Function
118  void setNumberOfParticles(int) const;
119 
120  inline const int& maxNumberOfParticles() const {return maxNumberOfParticles_;};
121 
122  template <typename T>
123  void getData
124  (
125  word name,
126  word type,
127  T ** const& field
128  ) const { getData(name,type,field,couplingStep_-1); }
129 
130  virtual void getData
131  (
132  word name,
133  word type,
134  double ** const& field,
135  label step
136  ) const = 0;
137 
138  virtual void getData
139  (
140  word name,
141  word type,
142  int ** const& field,
143  label step
144  ) const=0;
145 
146  virtual void giveData
147  (
148  word name,
149  word type,
150  double ** const& field,
151  const char* datatype="double"
152  ) const = 0;
153 
154  //====
155  // double **
156  virtual void allocateArray(double**&, double, int, int) const;
157  virtual void allocateArray(double**&, double, int, const char* ="nparticles") const;
158  virtual void destroy(double**,int) const;
159 
160  //====
161  // int **
162  virtual void allocateArray(int**&, int, int, int) const;
163  virtual void allocateArray(int**&, int, int, const char* ="nparticles") const;
164  virtual void destroy(int**,int) const;
165  //====
166 
167  //====
168  // int *
169  virtual void allocateArray(int*&, int, int) const;
170  virtual void destroy(int*) const;
171  //====
172 
173  //====
174  // double *
175  virtual void allocateArray(double*&, double, int) const;
176  virtual void destroy(double*) const;
177  //====
178 
179  virtual bool couple(int) const;
180 
181  virtual scalar timeStepFraction() const;
182 
183  inline int couplingStep() const {return couplingStep_;};
184 
185  inline const scalar& DEMts() const {return DEMts_;};
186 
187  inline int couplingInterval() const {return couplingInterval_;};
188 
189  inline scalar couplingTime() const {return couplingInterval_*DEMts_;};
190 
191  inline scalar TSstart() const { return particleCloud_.mesh().time().startTime().value()
192  + (couplingStep_-1) * couplingTime();};
193 
194  inline scalar TSend() const {return particleCloud_.mesh().time().startTime().value()
195  + (couplingStep_) * couplingTime();};
196 
197  inline int DEMstepsTillT(scalar t) const {return (t - (particleCloud_.mesh().time().value() - couplingTime()) + SMALL) / DEMts_;};
198 
199  inline void checkTSsize() const
200  {
201  if(particleCloud_.mesh().time().deltaT().value() > couplingInterval_ * DEMts_ + SMALL)
202  {
203  Info << "particleCloud_.mesh().time().deltaT().value() = " << particleCloud_.mesh().time().deltaT().value() << endl;
204  Info << "couplingInterval_ = " << couplingInterval_ << endl;
205  Info << "DEMts_ = " << DEMts_ << endl;
206  FatalError<<"\nError - TS bigger than coupling interval!\n"<< abort(FatalError);
207  }
208  }
209 
210  /*inline bool checkExactTiming() const
211  {
212  return false;
213  }*/
214 
215  //void checkNClumpTypes() const {};
216 
217  inline void readDEMtsfromDict(dictionary& propsDict)
218  {
219  DEMts_ = readScalar(propsDict.lookup("DEMts"));
220  checkTSsize();
221  }
222 
223  inline bool doCoupleNow() const
224  {
225  if (particleCloud_.mesh().time().value()-particleCloud_.mesh().time().startTime().value()
226  - ((1+couplingStep_)*(DEMts_*couplingInterval_))
227  + 1e-10 > 0) // Chr 27.03.2013 : first coupling after DEMts_*couplingInterval_
228 // > particleCloud_.mesh().time().deltaT().value()/2) // Chr 27.03.2013
229  {
230  return true;
231  }
232  else
233  {
234  return false;
235  }
236  }
237 
238  virtual int getNumberOfParticles() const;
239  virtual int getNumberOfClumps() const;
240  virtual int getNumberOfTypes() const;
241  virtual double* getTypeVol() const;
242 
243  inline void setPositions(label n,double* pos) const
244  {
245  for (int i=0;i<n;i++)
246  for (int j=0;j<3;j++)
247  particleCloud_.positions_[i][j]=pos[i*3+j];
248  };
249  inline void setCellIDs(label n,int* ID) const
250  {
251  for (int i=0;i<n;i++)
252  particleCloud_.cellIDs_[i][0]=ID[i];
253  };
254 
255  virtual word myType() const=0;
256 
257  virtual void setCG() const { Warning << "setCG() not executed correctly!" << endl; };
258 };
259 
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 } // End namespace Foam
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #endif
268 
269 // ************************************************************************* //
Definition: dataExchangeModel.H:53
Definition: cfdemCloud.H:81