MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseCG.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 "BaseCG.h"
27 #include "DPMBase.h"
28 
30 {
31  handler_ = nullptr;
32  statFile.getFstream().precision(8);
33  statFile.getFstream().setf(std::ios::left);
35  nX_ = 1;
36  nY_ = 1;
37  nZ_ = 1;
42  selectedParticle_ = [](const BaseInteractable* p) { return true; };
43  logger(DEBUG, "BaseCG::BaseCG() finished");
44 }
45 
47 {
48  std::cout << "BaseCG::clear(), this function shouldn't be called" << std::endl;
49 }
50 
51 
52 void BaseCG::read(std::istream& is UNUSED)
53 {
54 }
55 
59 void BaseCG::write(std::ostream& os) const
60 {
61  //BaseObject::write(os);
62  os << getName();
63  os << " min " << min_;
64  os << " max " << max_;
65  if (!std::isinf(timeMin_)) os << " timeMin " << timeMin_;
66  if (!std::isinf(timeMax_)) os << " timeMax " << timeMax_;
67  os << " n " << nX_ << " " << nY_ << " " << nZ_;
68  os << " width " << getWidth();
69  //statFile
70 }
71 
73 {
74  handler_ = handler;
75 }
76 
81 {
82 #ifdef DEBUG_OUTPUT
83  if (handler_ == nullptr)
84  {
85  std::cerr << "error: handler_==0 " << std::endl;
86  }
87 #endif
88  return handler_;
89 }
90 
92 {
93  eps_ = eps;
94 }
95 
97 {
98  return eps_;
99 }
100 
101 void BaseCG::setNZ(std::size_t nZ)
102 {
103  nZ_ = nZ;
104 }
105 
106 std::size_t BaseCG::getNZ() const
107 {
108  return nZ_;
109 }
110 
111 void BaseCG::setNY(std::size_t nY)
112 {
113  nY_ = nY;
114 }
115 
116 std::size_t BaseCG::getNY() const
117 {
118  return nY_;
119 }
120 
121 void BaseCG::setNX(std::size_t nX)
122 {
123  nX_ = nX;
124 }
125 
126 std::size_t BaseCG::getNX() const
127 {
128  return nX_;
129 }
130 
131 void BaseCG::setN(std::size_t n)
132 {
133  nX_ = n;
134  nY_ = n;
135  nZ_ = n;
136 }
137 
138 void BaseCG::setN(std::array<std::size_t, 3> n)
139 {
140  nX_ = n[0];
141  nY_ = n[1];
142  nZ_ = n[2];
143 }
144 
146 {
147  timeMin_ = timeMin;
148 }
149 
151 {
152  timeMax_ = timeMax;
153 }
154 
156 {
157  return min_;
158 }
159 
161 {
162  return max_;
163 }
164 
166 {
167  min_ = min;
168 }
169 
171 {
172  max_ = max;
173 }
174 
176 {
177  return timeMin_;
178 }
179 
181 {
182  return timeMax_;
183 }
184 
186 {
187  min_.X = min;
188  max_.X = max;
189 }
190 
192 {
193  min_.Y = min;
194  max_.Y = max;
195 }
196 
198 {
199  min_.Z = min;
200  max_.Z = max;
201 }
202 
204 {
205  setX(min,max);
206  setHX(h);
207 }
208 
210 {
211  setY(min,max);
212  setHY(h);
213 }
214 
216 {
217  setZ(min,max);
218  setHZ(h);
219 }
220 
222 {
223  setMin(min);
224  setMax(max);
225  setH(h);
226 }
227 
228 void BaseCG::selectSpecies(unsigned speciesIndex)
229 {
230  selectedParticle_ = [speciesIndex](const BaseInteractable* p)
231  {
232  return p->getIndSpecies() == speciesIndex;
233  };
234 }
235 
236 void BaseCG::setSelectedParticle(const std::function<const bool(const BaseInteractable*)>& selectedParticle)
237 {
238  selectedParticle_ = selectedParticle;
239 }
240 
242 {
243  setHX(h);
244  setHY(h);
245  setHZ(h);
246  logger(INFO, "min % max % h % nz %", min_, max_, h, nZ_);
247 }
248 
250 {
251  logger.assert(h > 0, "setHX(%): h has to be positive");
253  "setHX(%) can only be used after setting min and max values", h);
254  setNX(static_cast<size_t>(std::ceil((max_.X - min_.X) / h)));
255  logger.assert_always(getNX() > 0, "setHX(%) generated nX=% for %<x<%", h, getNX(), min_.X, max_.X);
256 }
257 
259 {
260  logger.assert(h > 0, "setHY(%): h has to be positive");
262  "setHY(%) can only be used after setting min and max values", h);
263  setNY(static_cast<size_t>(std::ceil((max_.Y - min_.Y) / h)));
264  logger.assert_always(getNY() > 0, "setHY(%) generated nY=% for %<y<%", h, getNY(), min_.Y, max_.Y);
265 }
266 
268 {
269  logger.assert(h > 0, "setHZ(%): h has to be positive");
271  "setHZ(%) can only be used after setting min and max values", h);
272  setNZ(static_cast<size_t>(std::ceil((max_.Z - min_.Z) / h)));
273  logger.assert_always(getNZ() > 0, "setHZ(%) generated nZ=% for %<z<%", h, getNZ(), min_.Z, max_.Z);
274 }
275 
Container that stores all CG objects.
Definition: CGHandler.h:64
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:180
Mdouble X
the vector components
Definition: Vector.h:65
std::size_t getNX() const
Returns nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:126
void selectSpecies(unsigned speciesIndex)
Definition: BaseCG.cc:228
void write(std::ostream &os) const override
Writes class content into an output stream, usually a stat file.
Definition: BaseCG.cc:59
CGHandler * getHandler() const
Returns handler_, a pointer to the CGHandler.
Definition: BaseCG.cc:80
Mdouble timeMax_
Definition: BaseCG.h:333
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:303
std::size_t getNY() const
Returns nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:116
void setTimeMax(Mdouble timeMax)
Sets timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:150
void setXGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:203
void setNZ(std::size_t nZ)
Sets nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:101
void setN(std::size_t n)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction.
Definition: BaseCG.cc:131
void setEps(Mdouble eps)
Definition: BaseCG.cc:91
Vec3D getMin() const
Returns min_, the lower limit of the spatial domain.
Definition: BaseCG.cc:155
const Mdouble inf
Definition: GeneralDefine.h:44
const unsigned NEVER
Definition: File.h:35
void setY(Mdouble min, Mdouble max)
Sets min_.Y, max_.Y, the limits of the spatial domain in Y.
Definition: BaseCG.cc:191
Vec3D getMax() const
Returns max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:160
void clear()
This class seems to have no use (?), but is required for any derivative of BaseObject.
Definition: BaseCG.cc:46
void read(std::istream &is) override
Currently, no read functions are implemented for the CGHandler, but the function is required for any ...
Definition: BaseCG.cc:52
std::function< bool(const BaseInteractable *)> selectedParticle_
Definition: BaseCG.h:350
std::size_t getNZ() const
Returns nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:106
void setHX(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX...
Definition: BaseCG.cc:249
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:154
Mdouble eps_
Definition: BaseCG.h:320
void setNY(std::size_t nY)
Sets nY_, the number of spatial mesh points in the y-direction.
Definition: BaseCG.cc:111
BaseCG()
Simple constructor, sets default values.
Definition: BaseCG.cc:29
virtual std::string getName() const =0
A purely virtual function.
void setNX(std::size_t nX)
Sets nX_, the number of spatial mesh points in the x-direction.
Definition: BaseCG.cc:121
void setMax(Vec3D max)
Sets max_, the upper limit of the spatial domain.
Definition: BaseCG.cc:170
void setGrid(Vec3D min, Vec3D max, Mdouble h)
Definition: BaseCG.cc:221
#define UNUSED
Definition: GeneralDefine.h:39
Vec3D min_
Definition: BaseCG.h:340
void setSelectedParticle(const std::function< const bool(const BaseInteractable *)> &selectedParticle)
Definition: BaseCG.cc:236
void setHZ(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX...
Definition: BaseCG.cc:267
void setX(Mdouble min, Mdouble max)
Sets min_.X, max_.X, the limits of the spatial domain in X.
Definition: BaseCG.cc:185
void setYGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:209
Mdouble Y
Definition: Vector.h:65
void setZGrid(Mdouble min, Mdouble max, Mdouble h)
Definition: BaseCG.cc:215
Mdouble getEps() const
Definition: BaseCG.cc:96
void setMin(Vec3D min)
Sets max_, the lower limit of the spatial domain.
Definition: BaseCG.cc:165
std::size_t nY_
Definition: BaseCG.h:309
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:369
std::size_t nZ_
Definition: BaseCG.h:314
void setHY(Mdouble h)
Sets nX_ the number of spatial mesh points in the X-direction. Instead of explicitly defining nX...
Definition: BaseCG.cc:258
Defines the basic properties that a interactable object can have.
CGHandler * handler_
Definition: BaseCG.h:295
std::size_t nX_
Definition: BaseCG.h:304
Definition: Vector.h:49
virtual Mdouble getWidth() const =0
Returns width_, the coarse-graining width.
void setTimeMin(Mdouble timeMin)
Sets timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:145
Mdouble timeMin_
Definition: BaseCG.h:328
Mdouble Z
Definition: Vector.h:65
Vec3D max_
Definition: BaseCG.h:345
void setZ(Mdouble min, Mdouble max)
Sets min_.Z, max_.Z, the limits of the spatial domain in Z.
Definition: BaseCG.cc:197
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:175
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:72
void setH(Mdouble h)
Sets nX_, nY_, nZ_, the number of spatial mesh points in each cartesian direction. However, instead of explicitly defining n, the mesh size h=(max-min)/n is defined.
Definition: BaseCG.cc:241