MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DPMBaseXBalls.icc
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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.
28 //icc means included cc file
29 
30 void DPMBase::outputXBallsDataParticle(const unsigned int i, const unsigned int format, std::ostream& os) const
31 {
32  //dataFile.precision(14);
34  //This outputs the data about particle i again to the file.
35  switch (format)
36  {
37  case 8:
38  {
39  if (getSystemDimensions() == 1)
40  {
41  os << particleHandler.getObject(i)->getPosition().X << " 0 " << particleHandler.getObject(i)->getVelocity().X << " 0 " << particleHandler.getObject(i)->getRadius() << " 0 0 0" << std::endl;
42  break;
43  }
44  else
45  {
47  os
48  << particleHandler.getObject(i)->getPosition().X << " "
49  << particleHandler.getObject(i)->getPosition().Y << " "
50  << particleHandler.getObject(i)->getVelocity().X << " "
51  << particleHandler.getObject(i)->getVelocity().Y << " "
52  << particleHandler.getObject(i)->getRadius() << " "
53  << -angle.Z << " " // negative b/c we are plotting (x,y) coordinates on the xz-axis of xballs
55  << getInfo(*particleHandler.getObject(i)) << std::endl;
56  }
57  break;
58  }
59  case 14:
60  {
62  os
63  << particleHandler.getObject(i)->getPosition().X << " "
64  << particleHandler.getObject(i)->getPosition().Y << " "
65  << particleHandler.getObject(i)->getPosition().Z << " "
66  << particleHandler.getObject(i)->getVelocity().X << " "
67  << particleHandler.getObject(i)->getVelocity().Y << " "
68  << particleHandler.getObject(i)->getVelocity().Z << " "
69  << particleHandler.getObject(i)->getRadius() << " "
70  << angle.X << " " // negative b/c we are plotting (x,y) coordinates on the xz-axis of xballs
71  << angle.Y << " " // negative b/c we are plotting (x,y) coordinates on the xz-axis of xballs
72  << angle.Z << " " // negative b/c we are plotting (x,y) coordinates on the xz-axis of xballs
76  << getInfo(*particleHandler.getObject(i)) << std::endl;
77  break;
78  } //end case 3
79  default:
80  {
81  std::cerr << "format not found" << std::endl;
82  break;
83  }
84  } //end switch statement
85 }
86 
90 
92 {
93  std::stringstream file_name;
94  std::ofstream script_file;
95  file_name << getName() << ".xballs";
96  script_file.open((file_name.str()).c_str());
97 
99  script_file << "#!/bin/bash" << std::endl;
100  script_file << "x=$(echo $0 | cut -c2-)" << std::endl;
101  script_file << "file=$PWD$x" << std::endl;
102  script_file << "dirname=`dirname \"$file\"`" << std::endl;
103  script_file << "cd $dirname" << std::endl;
104 
105  Mdouble scale;
106  //Mdouble offset = 0;
107  int verticalOffset = 0;
108  int horizontalOffset = static_cast<int> (500.0 * (0.0 - getXMin()) / (getXMax() - getXMin()));
109  int format;
110 
111  if (getSystemDimensions() < 3)
112  { // dim = 1 or 2
113  format = 8;
114  verticalOffset = static_cast<int> (500. * (0.0 - getYMin()) / (getYMax() - getYMin()));
115  if (getXBallsScale() < 0)
116  {
117  scale = 1.0 / std::max(getYMax() - getYMin(), getXMax() - getXMin());
118  }
119  else
120  {
121  scale = getXBallsScale();
122  }
123  }
124  else
125  { //dim==3
126  format = 14;
127  verticalOffset = static_cast<int> (500. * (0.0 - getZMin()) / (getZMax() - getZMin()));
128  if (getXBallsScale() < 0)
129  {
130  scale = 1.2 / std::max(getZMax() - getZMin(), getXMax() - getXMin());
131  }
132  else
133  {
134  scale = getXBallsScale();
135  }
136 
137  }
138 
139  script_file << getMercuryBuildDir() << "/XBalls/xballs -format " << format
140  << " -f " << dataFile.getFullName()
141  << " -s " << scale
142  << " -cmode " << getXBallsColourMode()
143  << " -cmax -sort ";
144  if (verticalOffset >= 1)
145  script_file << " -o " << verticalOffset;
146  else if (verticalOffset >= 1)
147  script_file << " -mo " << -verticalOffset;
148  if (horizontalOffset >= 1)
149  script_file << " -moh " << horizontalOffset;
150  else if (horizontalOffset >= 1)
151  script_file << " -oh " << -horizontalOffset;
152  script_file << getXBallsAdditionalArguments()
153  << " $*";
155  if (getXBallsVectorScale() > -1)
156  {
157  script_file << " -vscale " << getXBallsVectorScale();
158  }
159  script_file.close();
160 
161  //This line changes teh file permision and give the owener (i.e. you) read, write and excute permission to the file.
162 #ifdef UNIX
163  chmod((file_name.str().c_str()), S_IRWXU);
164 #endif
165 
166 }
167 
Mdouble X
the vector components
Definition: Vector.h:52
int getXBallsColourMode() const
Get the xball colour mode (CMode)
Definition: DPMBase.cc:382
unsigned int getSystemDimensions() const
Returns the dimension of the simulation. Note there is also a particle dimension. ...
Definition: DPMBase.cc:466
Mdouble getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax...
Definition: DPMBase.cc:259
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin...
Definition: DPMBase.cc:224
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:170
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
Definition: DPMBase.cc:238
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
virtual void outputXBallsDataParticle(const unsigned int i, const unsigned int format, std::ostream &os) const
This function writes out the particle locations into an output stream in a format the XBalls program ...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
const Vec3D & getOrientation() const
Returns the orientation of this BaseInteractable.
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax...
Definition: DPMBase.cc:231
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:415
virtual void writeXBallsScript() const
This writes a script which can be used to load the xballs problem to display the data just generated...
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
Mdouble getRadius() const
Returns the particle's radius_.
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax...
Definition: DPMBase.cc:245
Mdouble Y
Definition: Vector.h:52
virtual double getInfo(const BaseParticle &P) const
A virtual method that allows the user to overrride and set what is written into the info column in th...
Definition: DPMBase.cc:580
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin...
Definition: DPMBase.cc:252
double getXBallsVectorScale() const
Returns the scale of vectors used in xballs.
Definition: DPMBase.cc:396
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
std::string getXBallsAdditionalArguments() const
Definition: DPMBase.cc:410
double getXBallsScale() const
Returns the scale of the view in xballs.
Definition: DPMBase.cc:424
Mdouble Z
Definition: Vector.h:52
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:131
const std::string getMercuryBuildDir()