MaMiCo 1.2
Loading...
Searching...
No Matches
CouplingCellPlotter.h
1// Copyright (C) 2015 Technische Universitaet Muenchen
2// This file is part of the Mamico project. For conditions of distribution
3// and use, please see the copyright notice in Mamico's main folder, or at
4// www5.in.tum.de/mamico
5#ifndef _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_
6#define _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_
7
8#include "coupling/KineticEnergyController.h"
9#include "coupling/cell-mappings/ComputeMassMapping.h"
10#include "coupling/cell-mappings/ComputeMomentumMapping.h"
11#include "coupling/cell-mappings/VTKMoleculePlotter.h"
12#include "coupling/datastructures/LinkedCellContainer.h"
13#include "coupling/interface/MDSolverInterface.h"
14#include "tarch/la/Vector.h"
15#include <fstream>
16#include <sstream>
17
18namespace coupling {
19template <class LinkedCell, unsigned int dim> class CouplingCellPlotter;
20}
21
28template <class LinkedCell, unsigned int dim> class coupling::CouplingCellPlotter {
29public:
37 CouplingCellPlotter(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, datastructures::LinkedCellContainer<LinkedCell, dim>& cells,
39 plotMoleculeFile(ID, filename, rank, t, cells, mdSolverInterface);
40 plotCouplingCellFile(ID, filename, rank, t, cells, mdSolverInterface);
41 }
42
45
46private:
56 void plotMoleculeFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t,
59 // open files
60 std::ofstream moleculeFile;
61 // store positions and velocities of molecules
62 std::stringstream moleculeVelocities;
63 std::stringstream moleculePositions;
64 std::stringstream moleculePotentials;
65 // zeros appended in vtk file
66 std::string appendFloatZeros("");
67 switch (dim) {
68 case 1:
69 appendFloatZeros = " 0.0 0.0";
70 break;
71 case 2:
72 appendFloatZeros = " 0.0";
73 break;
74 case 3:
75 appendFloatZeros = "";
76 break;
77 default:
78 break;
79 }
80 Writer4Molecules writer(moleculeVelocities, moleculePositions, moleculePotentials, appendFloatZeros, mdSolverInterface);
82 // open file and write info
83 open(ID, filename, "Molecules", rank, t, moleculeFile);
84 moleculeFile << "# vtk DataFile Version 2.0" << std::endl;
85 moleculeFile << "Generated by MaMiCo (Philipp Neumann)" << std::endl;
86 moleculeFile << "ASCII" << std::endl;
87 moleculeFile << "DATASET UNSTRUCTURED_GRID" << std::endl;
88 moleculeFile << "POINTS " << writer.getMoleculeCounter() << " float" << std::endl;
89 moleculeFile << moleculePositions.str() << std::endl << std::endl;
90 moleculeFile << "POINT_DATA " << writer.getMoleculeCounter() << std::endl;
91 moleculeFile << "VECTORS velocity float" << std::endl;
92 moleculeFile << moleculeVelocities.str() << std::endl;
93 moleculeFile << "SCALARS potentialEnergy float 1" << std::endl;
94 moleculeFile << "LOOKUP_TABLE DEFAULT" << std::endl;
95 moleculeFile << moleculePotentials.str() << std::endl;
96 moleculePositions.clear();
97 moleculePositions.str("");
98 moleculeVelocities.clear();
99 moleculeVelocities.str("");
100 moleculePotentials.clear();
101 moleculePotentials.str("");
102 moleculeFile.close();
103 }
104
113 void plotCouplingCellFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t,
116 // stringstreams for all cell properties of interest
117 std::stringstream microscopicMasses;
118 microscopicMasses << "SCALARS microscopicMassBuffer float 1" << std::endl;
119 microscopicMasses << "LOOKUP_TABLE DEFAULT" << std::endl;
120 std::stringstream macroscopicMasses;
121 macroscopicMasses << "SCALARS macroscopicMassBuffer float 1" << std::endl;
122 macroscopicMasses << "LOOKUP_TABLE DEFAULT" << std::endl;
123 std::stringstream microscopicMomenta;
124 microscopicMomenta << "VECTORS microscopicMomentumBuffer float" << std::endl;
125 std::stringstream macroscopicMomenta;
126 macroscopicMomenta << "VECTORS macroscopicMomentumBuffer float" << std::endl;
127 std::stringstream meanVelocities;
128 meanVelocities << "VECTORS meanVelocity float" << std::endl;
129 std::stringstream masses;
130 masses << "SCALARS mass float 1" << std::endl;
131 masses << "LOOKUP_TABLE DEFAULT" << std::endl;
132 std::stringstream energies;
133 energies << "SCALARS meanPotentialEnergyBuffer float 1" << std::endl;
134 energies << "LOOKUP_TABLE DEFAULT" << std::endl;
135 std::stringstream temperatures;
136 temperatures << "SCALARS temperature float 1" << std::endl;
137 temperatures << "LOOKUP_TABLE DEFAULT" << std::endl;
138 // ofstream for file
139 std::ofstream ofCell;
140 // zeros appended in vtk file
141 std::string appendFloatZeros("");
142 switch (dim) {
143 case 1:
144 appendFloatZeros = " 0.0 0.0";
145 break;
146 case 2:
147 appendFloatZeros = " 0.0";
148 break;
149 case 3:
150 appendFloatZeros = "";
151 break;
152 default:
153 break;
154 }
155
156 tarch::la::Vector<3, double> original = I11{{0, 0, 0}}.getCellMidPoint() - 0.5 * IDXS.getCouplingCellSize();
157
158 // open file
159 open(ID, filename, "CouplingCells", rank, t, ofCell);
160 Writer4Cells writer(microscopicMasses, macroscopicMasses, microscopicMomenta, macroscopicMomenta, meanVelocities, masses, energies, temperatures,
161 appendFloatZeros, mdSolverInterface);
163 ofCell << "# vtk DataFile Version 2.0" << std::endl;
164 ofCell << "generated by MaMiCo (Philipp Neumann)" << std::endl;
165 ofCell << "ASCII" << std::endl << std::endl;
166 ofCell << "DATASET STRUCTURED_POINTS" << std::endl;
167 ofCell << "DIMENSIONS " << I03::numberCellsInDomain << std::endl;
168 ofCell << "ORIGIN ";
169 for (unsigned int d = 0; d < 3; d++) {
170 ofCell << original[d] << " ";
171 }
172 ofCell << std::endl;
173 ofCell << "SPACING ";
174 for (unsigned int d = 0; d < dim; d++) {
175 ofCell << IDXS.getCouplingCellSize()[d] << " ";
176 }
177 for (unsigned int d = dim; d < 3; d++) {
178 ofCell << "1.0 ";
179 }
180 ofCell << std::endl;
181 ofCell << "POINT_DATA " << I02::linearNumberCellsInDomain << std::endl << std::endl;
182 ofCell << microscopicMasses.str() << std::endl << std::endl;
183 microscopicMasses.clear();
184 microscopicMasses.str("");
185 ofCell << macroscopicMasses.str() << std::endl << std::endl;
186 macroscopicMasses.clear();
187 macroscopicMasses.str("");
188 ofCell << masses.str() << std::endl << std::endl;
189 masses.clear();
190 masses.str("");
191 ofCell << energies.str() << std::endl << std::endl;
192 energies.clear();
193 energies.str("");
194 ofCell << temperatures.str() << std::endl << std::endl;
195 temperatures.clear();
196 temperatures.str("");
197 ofCell << microscopicMomenta.str() << std::endl << std::endl;
198 microscopicMomenta.clear();
199 microscopicMomenta.str("");
200 ofCell << macroscopicMomenta.str() << std::endl << std::endl;
201 macroscopicMomenta.clear();
202 macroscopicMomenta.str("");
203 ofCell << meanVelocities.str() << std::endl << std::endl;
204 meanVelocities.clear();
205 meanVelocities.str("");
206 // close file
207 ofCell.close();
208 }
209
217 void open(unsigned int ID, std::string filename, std::string fileType, unsigned int rank, unsigned int t, std::ofstream& of) {
218 std::stringstream ss;
219 ss << filename << "_" << fileType << "_" << ID << "_" << rank << "_" << t << ".vtk";
220 of.open(ss.str().c_str());
221 if (!of.is_open()) {
222 std::cout << "ERROR coupling::CouplingCellPlotter: Could not open file " << ss.str() << "!" << std::endl;
223 exit(EXIT_FAILURE);
224 }
225 }
226
230 public:
243 Writer4Cells(std::stringstream& microscopicMasses, std::stringstream& macroscopicMasses, std::stringstream& microscopicMomenta,
244 std::stringstream& macroscopicMomenta, std::stringstream& meanVelocities, std::stringstream& masses, std::stringstream& energies,
245 std::stringstream& temperatures, const std::string& appendFloatZeros,
247 : _microscopicMasses(microscopicMasses), _macroscopicMasses(macroscopicMasses), _microscopicMomenta(microscopicMomenta),
248 _macroscopicMomenta(macroscopicMomenta), _meanVelocities(meanVelocities), _masses(masses), _energies(energies), _temperatures(temperatures),
249 _appendFloatZeros(appendFloatZeros), _computeMassMapping(mdSolverInterface), _computeMomentumMapping(mdSolverInterface),
250 _kineticEnergyController(mdSolverInterface) {}
251
254
258
262
267 // compute local quantities from molecules, if this is an inner cell
268 double mass = 0.0;
269 tarch::la::Vector<dim, double> meanVelocity(0.0);
270 double temperature = 0.0;
271
272 if (I10::contains(index)) {
274 mass = _computeMassMapping.getMass();
276 meanVelocity = _computeMomentumMapping.getMeanVelocity();
277 temperature = _kineticEnergyController.computeTemperature(cell);
278 }
279
280 // write data to streams
281 _microscopicMasses << cell.getMicroscopicMass() << std::endl;
282 _macroscopicMasses << cell.getMacroscopicMass() << std::endl;
283 _masses << mass << std::endl;
284 _temperatures << temperature << std::endl;
285 _energies << cell.getPotentialEnergy() << std::endl;
286 for (unsigned int d = 0; d < dim; d++) {
289 _meanVelocities << meanVelocity[d] << " ";
290 }
293 _meanVelocities << _appendFloatZeros << std::endl;
294 }
295
296 private:
299 std::stringstream& _microscopicMasses;
302 std::stringstream& _macroscopicMasses;
305 std::stringstream& _microscopicMomenta;
308 std::stringstream& _macroscopicMomenta;
310 std::stringstream& _meanVelocities;
312 std::stringstream& _masses;
314 std::stringstream& _energies;
316 std::stringstream& _temperatures;
318 const std::string _appendFloatZeros;
325 };
326
331 public:
339 Writer4Molecules(std::stringstream& moleculeVelocities, std::stringstream& moleculePositions, std::stringstream& moleculePotentials,
340 const std::string& appendFloatZeros, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
341 : _moleculeVelocities(moleculeVelocities), _moleculePositions(moleculePositions), _moleculePotentials(moleculePotentials),
342 _appendFloatZeros(appendFloatZeros), _mdSolverInterface(mdSolverInterface), _moleculeCounter(0) {}
343
347
351
359
362 unsigned int getMoleculeCounter() const { return _moleculeCounter; }
363
364 private:
366 std::stringstream& _moleculeVelocities;
368 std::stringstream& _moleculePositions;
370 std::stringstream& _moleculePotentials;
372 const std::string _appendFloatZeros;
376 unsigned int _moleculeCounter;
377 };
378};
379#endif // _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLPLOTTER_H_
class for writing coupling cell data to stringstreams.
Definition CouplingCellPlotter.h:229
coupling::cellmappings::ComputeMomentumMapping< LinkedCell, dim > _computeMomentumMapping
Definition CouplingCellPlotter.h:322
std::stringstream & _microscopicMasses
Definition CouplingCellPlotter.h:299
std::stringstream & _macroscopicMasses
Definition CouplingCellPlotter.h:302
std::stringstream & _microscopicMomenta
Definition CouplingCellPlotter.h:305
std::stringstream & _energies
Definition CouplingCellPlotter.h:314
coupling::cellmappings::ComputeMassMapping< LinkedCell, dim > _computeMassMapping
Definition CouplingCellPlotter.h:320
void endCellIteration()
does everything which is neccessary after the application of the writer to the cells
Definition CouplingCellPlotter.h:261
~Writer4Cells()
a simple destructor
Definition CouplingCellPlotter.h:253
std::stringstream & _macroscopicMomenta
Definition CouplingCellPlotter.h:308
Writer4Cells(std::stringstream &microscopicMasses, std::stringstream &macroscopicMasses, std::stringstream &microscopicMomenta, std::stringstream &macroscopicMomenta, std::stringstream &meanVelocities, std::stringstream &masses, std::stringstream &energies, std::stringstream &temperatures, const std::string &appendFloatZeros, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
a simple constructor
Definition CouplingCellPlotter.h:243
const std::string _appendFloatZeros
Definition CouplingCellPlotter.h:318
std::stringstream & _masses
Definition CouplingCellPlotter.h:312
void apply(coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > &cell, const I02 &index)
writes the data from the cell to the stringstreams
Definition CouplingCellPlotter.h:266
void beginCellIteration()
does everything which is neccessary before the application of the writer to the cells
Definition CouplingCellPlotter.h:257
coupling::KineticEnergyController< LinkedCell, dim > _kineticEnergyController
Definition CouplingCellPlotter.h:324
std::stringstream & _temperatures
Definition CouplingCellPlotter.h:316
std::stringstream & _meanVelocities
Definition CouplingCellPlotter.h:310
class for writing molecule data to stringstreams.
Definition CouplingCellPlotter.h:330
const std::string _appendFloatZeros
Definition CouplingCellPlotter.h:372
std::stringstream & _moleculePotentials
Definition CouplingCellPlotter.h:370
Writer4Molecules(std::stringstream &moleculeVelocities, std::stringstream &moleculePositions, std::stringstream &moleculePotentials, const std::string &appendFloatZeros, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
a simple constructor
Definition CouplingCellPlotter.h:339
coupling::interface::MDSolverInterface< LinkedCell, dim > *const _mdSolverInterface
Definition CouplingCellPlotter.h:374
unsigned int _moleculeCounter
Definition CouplingCellPlotter.h:376
unsigned int getMoleculeCounter() const
returns the number of molecules
Definition CouplingCellPlotter.h:362
void endCellIteration()
does everything which is neccessary after the application of the writer to the cells
Definition CouplingCellPlotter.h:350
void apply(coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > &cell, const I02 &index)
aplication of the vtkMoleculePlotter to the coupling cells
Definition CouplingCellPlotter.h:353
void beginCellIteration()
does everything which is neccessary before the application of the writer to the cells
Definition CouplingCellPlotter.h:346
std::stringstream & _moleculePositions
Definition CouplingCellPlotter.h:368
std::stringstream & _moleculeVelocities
Definition CouplingCellPlotter.h:366
plots the coupling cell data.
Definition CouplingCellPlotter.h:28
~CouplingCellPlotter()
a simple destructor
Definition CouplingCellPlotter.h:44
void plotCouplingCellFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, coupling::datastructures::LinkedCellContainer< LinkedCell, dim > &cells, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
writes molecule information + coupling cell information to VTK file.
Definition CouplingCellPlotter.h:113
void open(unsigned int ID, std::string filename, std::string fileType, unsigned int rank, unsigned int t, std::ofstream &of)
opens a file
Definition CouplingCellPlotter.h:217
void plotMoleculeFile(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, coupling::datastructures::LinkedCellContainer< LinkedCell, dim > &cells, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
writes molecule information to VTK file.
Definition CouplingCellPlotter.h:56
CouplingCellPlotter(unsigned int ID, std::string filename, unsigned int rank, unsigned int t, datastructures::LinkedCellContainer< LinkedCell, dim > &cells, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
a simple constructor
Definition CouplingCellPlotter.h:37
controles and regulates the kinetic energy of the MD system.
Definition KineticEnergyController.h:27
This class computes the mass over certain linked cells.
Definition ComputeMassMapping.h:23
This class computes the momentum over certain linked cells.
Definition ComputeMomentumMapping.h:24
This class writes molecule data to streams for .vtk file.
Definition VTKMoleculePlotter.h:25
const unsigned int & getParticleCounter() const
Definition VTKMoleculePlotter.h:78
defines the cell type with cell-averaged quantities. Derived from the class coupling::datastructures:...
Definition CouplingCellWithLinkedCells.h:26
void iterateConstCells(A &a) const
Definition CouplingCellWithLinkedCells.h:90
const tarch::la::Vector< dim, double > & getMicroscopicMomentum() const
Definition CouplingCell.h:51
const tarch::la::Vector< dim, double > & getMacroscopicMomentum() const
Definition CouplingCell.h:64
const double & getPotentialEnergy() const
Definition CouplingCell.h:68
const double & getMicroscopicMass() const
Definition CouplingCell.h:45
const double & getMacroscopicMass() const
Definition CouplingCell.h:58
provides access to the coupling cells with linked cells.
Definition LinkedCellContainer.h:21
static unsigned int linearNumberCellsInDomain
Definition CellIndex.h:270
static tarch::la::Vector< dim, unsigned int > numberCellsInDomain
Definition CellIndex.h:264
static bool contains(const coupling::indexing::BaseIndex< dim > &index)
Definition CellIndex.h:227
interface to the MD simulation
Definition MDSolverInterface.h:25
Definition Vector.h:24
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15