The Conley-Morse Graphs Software
dataconv.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file dataconv.h
4///
5/// Data conversion for sending/receiving.
6/// This file contains the definitions of the operators << and >>
7/// for encoding some variables to the binary data structure
8/// and retrieving them. This binary data structure is used
9/// in the communication between the coordinator and workers.
10///
11/// @author Pawel Pilarczyk
12///
13/////////////////////////////////////////////////////////////////////////////
14
15// Copyright (C) 1997-2014 by Pawel Pilarczyk.
16//
17// This file is part of my research software package. This is free software:
18// you can redistribute it and/or modify it under the terms of the GNU
19// General Public License as published by the Free Software Foundation,
20// either version 3 of the License, or (at your option) any later version.
21//
22// This software is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with this software; see the file "license.txt". If not,
29// please, see <https://www.gnu.org/licenses/>.
30
31// Started on February 15, 2008. Last revision: February 29, 2008.
32
33
34#ifndef _CMGRAPHS_DATACONV_H_
35#define _CMGRAPHS_DATACONV_H_
36
37
38// include some standard C++ header files
39#include <string>
40#include <sstream>
41
42// include selected header files from the CHomP library
43#include "chomp/system/config.h"
44#include "chomp/system/textfile.h"
45#include "chomp/multiwork/mw.h"
46
47// include local header files
48#include "config.h"
49#include "typedefs.h"
50#include "typedyns.h"
51#include "utils.h"
52#include "eigenval.h"
53
54
55// --------------------------------------------------
56// ------------------ Conley index ------------------
57// --------------------------------------------------
58
59/// Writes a Conley index to a MultiWork data structure.
60inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
61 const theConleyIndexType &ind)
62{
63 std::ostringstream s;
64 s << ind;
65 data << s. str ();
66 return data;
67} /* operator << */
68
69/// Reads a Conley index from a MultiWork data structure.
70inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
72{
73 std::string str;
74 data >> str;
75 std::istringstream s (str);
76 s >> ind;
77 return data;
78} /* operator >> */
79
80
81// --------------------------------------------------
82// ------------ Conley index eigenvalues ------------
83// --------------------------------------------------
84
85/// Writes a set of Conley index eigenvalues to a MultiWork data structure.
86inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
87 const IndexEigenValues &eigenValues)
88{
89 int maxLevel = eigenValues. maxLevel ();
90 data << maxLevel;
91 for (int level = 0; level < maxLevel; ++ level)
92 {
93 const std::vector<double> &re = eigenValues. re (level);
94 const std::vector<double> &im = eigenValues. im (level);
95 unsigned int nValues = re. size ();
96 if (nValues != im. size ())
97 throw "Different sizes of Re and Im vectors.";
98 data << nValues;
99 for (unsigned int i = 0; i < nValues; ++ i)
100 data << re [i] << im [i];
101 }
102 return data;
103} /* operator << */
104
105/// Reads a set of Conley index eigenvalues from a MultiWork data structure.
106inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
107 IndexEigenValues &eigenValues)
108{
109 int maxLevel = 0;
110 data >> maxLevel;
111 for (int level = 0; level < maxLevel; ++ level)
112 {
113 std::vector<double> &reVector = eigenValues. re (level);
114 std::vector<double> &imVector = eigenValues. im (level);
115 unsigned int nValues = 0;
116 data >> nValues;
117 for (unsigned int i = 0; i < nValues; ++ i)
118 {
119 double re = 0, im = 0;
120 data >> re >> im;
121 reVector. push_back (re);
122 imVector. push_back (im);
123 }
124 }
125 return data;
126} /* operator >> */
127
128
129// --------------------------------------------------
130// ----------------- parameter cube -----------------
131// --------------------------------------------------
132
133/// Writes a parameter cube to a MultiWork data structure.
134inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
135 const parCube &q)
136{
137 int dim = q. dim ();
138 data << dim;
139 parCube::CoordType c [parCube::MaxDim];
140 for (int i = 0; i < parCube::MaxDim; ++ i)
141 c [i] = 0;
142 q. coord (c);
143 for (int i = 0; i < dim; ++ i)
144 data << static_cast<int> (c [i]);
145 return data;
146} /* operator << */
147
148/// Reads a parameter cube from a MultiWork data structure.
149inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
150 parCube &q)
151{
152 int dim = 0;
153 data >> dim;
154 if (dim != paramDim)
155 throw "Wrong cube dimension in mwData.";
156 parCube::CoordType c [paramDim];
157 for (int i = 0; i < dim; ++ i)
158 {
159 int number = 0;
160 data >> number;
161 c [i] = static_cast<parCube::CoordType> (number);
162 }
163 q = parCube (c, dim);
164
165 return data;
166} /* operator >> */
167
168
169// --------------------------------------------------
170// ------------- set of parameter cubes -------------
171// --------------------------------------------------
172
173/// Writes a set of parameter cubes to a MultiWork data structure.
174inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
175 const parCubes &X)
176{
177 int size = X. size ();
178 data << size;
179 for (int i = 0; i < size; ++ i)
180 data << X [i];
181 return data;
182} /* operator << */
183
184/// Reads a set of parameter cubes from a MultiWork data structure.
185inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
186 parCubes &X)
187{
188 int size = 0;
189 data >> size;
190 if (size < 0)
191 throw "Negative size of a set of cubes in mwData.";
192 for (int i = 0; i < size; ++ i)
193 {
194 parCube q;
195 data >> q;
196 X. add (q);
197 }
198 return data;
199} /* operator >> */
200
201
202// --------------------------------------------------
203// ---------------- phase space cube ----------------
204// --------------------------------------------------
205
206/// Writes a phase space cube to a MultiWork data structure.
207inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
208 const spcCube &q)
209{
210 int dim = q. dim ();
211 data << dim;
212 spcCube::CoordType c [spcCube::MaxDim];
213 q. coord (c);
214 for (int i = 0; i < dim; ++ i)
215 data << static_cast<int> (c [i]);
216 return data;
217} /* operator << */
218
219/// Reads a phase space cube from a MultiWork data structure.
220inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
221 spcCube &q)
222{
223 int dim = 0;
224 data >> dim;
225 if (dim != spaceDim)
226 throw "Wrong cube dimension in mwData.";
227 spcCube::CoordType c [paramDim];
228 for (int i = 0; i < dim; ++ i)
229 {
230 int number = 0;
231 data >> number;
232 c [i] = static_cast<spcCube::CoordType> (number);
233 }
234 q = spcCube (c, dim);
235
236 return data;
237} /* operator >> */
238
239
240// --------------------------------------------------
241// ----------------- directed graph -----------------
242// --------------------------------------------------
243
244/// Writes a directed graph to a MultiWork data structure.
245inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
246 const chomp::homology::diGraph<> &g)
247{
248 // write the number of vertices of the directed graph
249 int nVert = g. countVertices ();
250 data << nVert;
251
252 // the numbers of edges emanating from each vertex and their targets
253 for (int v = 0; v < nVert; ++ v)
254 {
255 // write the number of edges emanating vrom this vertex
256 int nEdg = g. countEdges (v);
257 data << nEdg;
258
259 // write the target vertices of the edges
260 for (int e = 0; e < nEdg; ++ e)
261 {
262 int target = g. getEdge (v, e);
263 data << target;
264 }
265 }
266
267 return data;
268} /* operator << */
269
270/// Reads a directed graph from a MultiWork data structure.
271inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
272 chomp::homology::diGraph<> &g)
273{
274 // determine the number of vertices
275 int nVert = -1;
276 data >> nVert;
277 if (nVert < 0)
278 throw "Negative number of vertices decoded from mwData.";
279
280 // read the numbers of edges emanating from each vertex
281 // and add their targets
282 for (int v = 0; v < nVert; ++ v)
283 {
284 // add the vertex to the graph
285 g. addVertex ();
286
287 // read the number of edges emanating from this vertex
288 int nEdg = -1;
289 data >> nEdg;
290
291 // read the target vertices and add them to the graph
292 for (int e = 0; e < nEdg; ++ e)
293 {
294 int target = -1;
295 data >> target;
296 if ((target < 0) || (target >= nVert))
297 throw "Wrong vertex number found in mwData.";
298 g. addEdge (target);
299 }
300 }
301
302 return data;
303} /* operator >> */
304
305
306#endif // _CMGRAPHS_DATACONV_H_
307
The class that computes and returns properties of the Conley index.
Definition: conindex.h:86
Eigenvalues of the Conley index map gathered by levels.
Definition: eigenval.h:63
Choice of configuration settings.
chomp::multiwork::mwData & operator<<(chomp::multiwork::mwData &data, const theConleyIndexType &ind)
Writes a Conley index to a MultiWork data structure.
Definition: dataconv.h:60
chomp::multiwork::mwData & operator>>(chomp::multiwork::mwData &data, theConleyIndexType &ind)
Reads a Conley index from a MultiWork data structure.
Definition: dataconv.h:70
Eigenvalues of the Conley index map.
const int paramDim
The dimension of the parameter space to iterate.
Definition: p_differ.h:67
const int spaceDim
The dimension of the phase space.
Definition: p_differ.h:48
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
chomp::homology::tCubeFix< paramDim, parCoord > parCube
The type of a cube in the set of parameters.
Definition: typeparam.h:58
chomp::homology::hashedset< parCube > parCubes
The type of a set of cubes in the set of parameters.
Definition: typeparam.h:61
chomp::homology::tCubeBase< spcCoord > spcCube
The type of a cube in the phase space.
Definition: typespace.h:55
Utilites and helper functions.