Advertisement
Guest User

Untitled

a guest
May 4th, 2017
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.78 KB | None | 0 0
  1. From e165b317a34b77ab98bd1bbcd4767f139a4b1fa8 Mon Sep 17 00:00:00 2001
  2. From: Pietje Bell <pietjebell@ana-chan.com>
  3. Date: Tue, 26 Jan 2010 17:08:39 +0100
  4. Subject: [PATCH] Add importing the channel profile from a file.
  5.  
  6. Output files have a new file header, so it breaks backwards compatibility.
  7. Supported input files are the output files of the channel's velocity profile.
  8. ---
  9. Makefile | 2 +-
  10. build/vs2008/Scrubber.vcproj | 14 +++---
  11. src/Channel/Channel.cpp | 5 ++
  12. src/Channel/Channel.h | 9 +++-
  13. src/InOut/ByteInOut.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++
  14. src/InOut/ByteInOut.h | 49 ++++++++++++++++++
  15. src/InOut/InOut.cpp | 58 +++++++++++++++++++++
  16. src/InOut/InOut.h | 91 +++++++++++++++++++++++++++++++++
  17. src/InOut/TextInOut.cpp | 95 ++++++++++++++++++++++++++++++++++
  18. src/InOut/TextInOut.h | 48 +++++++++++++++++
  19. src/Output/ByteOutput.cpp | 91 ---------------------------------
  20. src/Output/ByteOutput.h | 47 -----------------
  21. src/Output/Output.cpp | 58 ---------------------
  22. src/Output/Output.h | 81 -----------------------------
  23. src/Output/TextOutput.cpp | 73 --------------------------
  24. src/Output/TextOutput.h | 46 -----------------
  25. src/Scrubber.cpp | 69 +++++++++++++++++++++----
  26. src/Scrubber.h | 13 ++++-
  27. 18 files changed, 543 insertions(+), 421 deletions(-)
  28. create mode 100644 src/InOut/ByteInOut.cpp
  29. create mode 100644 src/InOut/ByteInOut.h
  30. create mode 100644 src/InOut/InOut.cpp
  31. create mode 100644 src/InOut/InOut.h
  32. create mode 100644 src/InOut/TextInOut.cpp
  33. create mode 100644 src/InOut/TextInOut.h
  34. delete mode 100644 src/Output/ByteOutput.cpp
  35. delete mode 100644 src/Output/ByteOutput.h
  36. delete mode 100644 src/Output/Output.cpp
  37. delete mode 100644 src/Output/Output.h
  38. delete mode 100644 src/Output/TextOutput.cpp
  39. delete mode 100644 src/Output/TextOutput.h
  40.  
  41. diff --git a/Makefile b/Makefile
  42. index bed4fd8..0d5b138 100644
  43. --- a/Makefile
  44. +++ b/Makefile
  45. @@ -5,7 +5,7 @@ SRCS = ./external/getopt_pp.cpp \
  46. ./src/Channel/CPModel.cpp ./src/Channel/Channel.cpp \
  47. ./src/Particles/Mover.cpp \
  48. ./src/Emitter/Emitter.cpp ./src/Emitter/GridEmitter.cpp ./src/Emitter/GridOnceEmitter.cpp ./src/Emitter/RandomEmitter.cpp \
  49. - ./src/Output/Output.cpp ./src/Output/ByteOutput.cpp ./src/Output/TextOutput.cpp \
  50. + ./src/InOut/InOut.cpp ./src/InOut/ByteInOut.cpp ./src/InOut/TextInOut.cpp \
  51. ./src/Scrubber.cpp
  52.  
  53. CXXFLAGS = -O2 -DNDEBUG
  54. diff --git a/build/vs2008/Scrubber.vcproj b/build/vs2008/Scrubber.vcproj
  55. index f700a04..4abb59b 100644
  56. --- a/build/vs2008/Scrubber.vcproj
  57. +++ b/build/vs2008/Scrubber.vcproj
  58. @@ -537,30 +537,30 @@
  59. </File>
  60. </Filter>
  61. <Filter
  62. - Name="Output"
  63. + Name="InOut"
  64. >
  65. <File
  66. - RelativePath="..\..\src\Output\ByteOutput.cpp"
  67. + RelativePath="..\..\src\InOut\ByteInOut.cpp"
  68. >
  69. </File>
  70. <File
  71. - RelativePath="..\..\src\Output\ByteOutput.h"
  72. + RelativePath="..\..\src\InOut\ByteInOut.h"
  73. >
  74. </File>
  75. <File
  76. - RelativePath="..\..\src\Output\Output.cpp"
  77. + RelativePath="..\..\src\InOut\InOut.cpp"
  78. >
  79. </File>
  80. <File
  81. - RelativePath="..\..\src\Output\Output.h"
  82. + RelativePath="..\..\src\InOut\InOut.h"
  83. >
  84. </File>
  85. <File
  86. - RelativePath="..\..\src\Output\TextOutput.cpp"
  87. + RelativePath="..\..\src\InOut\TextInOut.cpp"
  88. >
  89. </File>
  90. <File
  91. - RelativePath="..\..\src\Output\TextOutput.h"
  92. + RelativePath="..\..\src\InOut\TextInOut.h"
  93. >
  94. </File>
  95. </Filter>
  96. diff --git a/src/Channel/Channel.cpp b/src/Channel/Channel.cpp
  97. index 9c2bff3..bf22ecc 100644
  98. --- a/src/Channel/Channel.cpp
  99. +++ b/src/Channel/Channel.cpp
  100. @@ -81,6 +81,11 @@ void Channel::init()
  101. u = cpmodel->init( u );
  102. }
  103.  
  104. +void Channel::init( const ScalarField &u )
  105. +{
  106. + this->u = u;
  107. +}
  108. +
  109. PosBox Channel::outsideBox( const Vector2d &pos )
  110. {
  111. if ( pos(1) >= height )
  112. diff --git a/src/Channel/Channel.h b/src/Channel/Channel.h
  113. index 6983240..dc06f4c 100644
  114. --- a/src/Channel/Channel.h
  115. +++ b/src/Channel/Channel.h
  116. @@ -69,12 +69,17 @@ public:
  117. virtual ~Channel();
  118.  
  119. /**
  120. - * Initialize the channel.
  121. - * Generates the velocity profile in the channel by looping until steady.
  122. + * Initialize the channel by calculating the velocity profile.
  123. */
  124. void init();
  125.  
  126. /**
  127. + * Initialize the channel by copying in an existing velocity profile.
  128. + * @param u The ScalarField to be used as the velocity profile.
  129. + */
  130. + void init( const ScalarField &u );
  131. +
  132. + /**
  133. * Checks if the particle has left the box on the sides, top, bottom or is still in the box.
  134. * @param pos Position of the particle.
  135. * @return An enum indicating where the particle is at.
  136. diff --git a/src/InOut/ByteInOut.cpp b/src/InOut/ByteInOut.cpp
  137. new file mode 100644
  138. index 0000000..3a11728
  139. --- /dev/null
  140. +++ b/src/InOut/ByteInOut.cpp
  141. @@ -0,0 +1,115 @@
  142. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  143. +//
  144. +// Permission to use, copy, modify, and/or distribute this software for any
  145. +// purpose with or without fee is hereby granted, provided that the above
  146. +// copyright notice and this permission notice appear in all copies.
  147. +//
  148. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  149. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  150. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  151. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  152. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  153. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  154. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  155. +
  156. +
  157. +// Headers
  158. +#include "ByteInOut.h"
  159. +
  160. +#include "Particles/ParticleArray.h"
  161. +#include "Particles/Particle.h"
  162. +
  163. +
  164. +// Constructor / Destructor
  165. +ByteInOut::ByteInOut( const ScrubberParam &param ) :
  166. + InOut( param )
  167. +{
  168. + if ( param.output.info != OUTPUT_NOTHING )
  169. + {
  170. + f = fopen( param.output.path.c_str(), "wb" );
  171. +
  172. + if ( !f ) {
  173. + printf( "Error in opening output file, exiting\n" );
  174. + exit( 1 );
  175. + }
  176. +
  177. + // Write file type header
  178. + fwrite( &param.output.format, 4, 1, f );
  179. + }
  180. +}
  181. +
  182. +ByteInOut::~ByteInOut()
  183. +{
  184. + if ( param.output.info != OUTPUT_NOTHING )
  185. + fclose( f );
  186. +}
  187. +
  188. +
  189. +// Private Methods
  190. +inline void ByteInOut::writePositions( bool first_call, double time, const ParticleArray &particles )
  191. +{
  192. + if ( first_call )
  193. + {
  194. + // Write the and delimiter values to file.
  195. + // i.e. buf[] = { xmin, xmax, ymin, ymax, zmin, zmax }
  196. + double buf[] = { radius, height };
  197. + fwrite( buf, 8, 2, f );
  198. + }
  199. +
  200. + // Frame data
  201. + double buf1[] = { time };
  202. + fwrite( buf1, 8, 1, f );
  203. +
  204. + int buf2[] = { particles.getLength() };
  205. + fwrite( buf2, 4, 1, f );
  206. +
  207. + // Write data
  208. + for ( int i = 0; i < particles.getLength(); i++ )
  209. + {
  210. + // Readability
  211. + const Vector2d & pos = particles.getParticle( i ).getPos();
  212. +
  213. + double buf[] = { pos(0), pos(1) };
  214. + fwrite( buf, 8, 2, f );
  215. + }
  216. +}
  217. +
  218. +
  219. +// Public Methods
  220. +void ByteInOut::writeScalarField( const ScalarField &scalar_field )
  221. +{
  222. + // Write header
  223. + double buf1[] = { dx, radius };
  224. + fwrite( buf1, 8, 2, f );
  225. +
  226. + int buf2[] = { n };
  227. + fwrite( buf2, 4, 1, f );
  228. +
  229. + // Write the scalar values to file.
  230. + for ( int i = 0; i < scalar_field.shape()(0); i++ )
  231. + {
  232. + double buf3[] = { scalar_field(i) };
  233. + fwrite( buf3, 8, 1, f );
  234. + }
  235. +}
  236. +
  237. +void ByteInOut::readProfile( ScrubberParam *param, ScalarField *u )
  238. +{
  239. + FILE *f = fopen( param->input.path.c_str(), "rb" );
  240. + // Skip the file type header
  241. + fseek ( f , 4 , SEEK_SET );
  242. +
  243. + // Read the channel header
  244. + fread( &param->channel.dx, 8, 1, f );
  245. + fread( &param->channel.radius, 8, 1, f );
  246. + fread( &param->channel.n, 4, 1, f );
  247. +
  248. + u->resize( param->channel.n + 2 );
  249. +
  250. + // FIXME: Check if the lenght of the file is sufficient
  251. + // FIXME: Is there a way to not write the elements iteratively?
  252. + for( int i = 0; i < u->shape()(0); i++ )
  253. + fread( &(*u)(i), 8, 1, f );
  254. +
  255. + fclose( f );
  256. +}
  257. diff --git a/src/InOut/ByteInOut.h b/src/InOut/ByteInOut.h
  258. new file mode 100644
  259. index 0000000..111976a
  260. --- /dev/null
  261. +++ b/src/InOut/ByteInOut.h
  262. @@ -0,0 +1,49 @@
  263. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  264. +//
  265. +// Permission to use, copy, modify, and/or distribute this software for any
  266. +// purpose with or without fee is hereby granted, provided that the above
  267. +// copyright notice and this permission notice appear in all copies.
  268. +//
  269. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  270. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  271. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  272. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  273. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  274. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  275. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  276. +
  277. +#pragma once
  278. +
  279. +// Headers
  280. +#include <fstream>
  281. +#include "InOut.h"
  282. +
  283. +#include "Scrubber.h"
  284. +#include "Typedefs.h"
  285. +
  286. +
  287. +/**
  288. + * Writes to the output in binary form, and reads input from an identically formatted binary file.
  289. + */
  290. +class ByteInOut : public InOut
  291. +{
  292. +protected:
  293. + virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  294. +
  295. +public:
  296. + /**
  297. + * Constructor.
  298. + * @param param Struct of parameters.
  299. + */
  300. + ByteInOut( const ScrubberParam &param );
  301. +
  302. + /**
  303. + * Destructor.
  304. + */
  305. + virtual ~ByteInOut();
  306. +
  307. + //FIXME: Should be private.
  308. + virtual void writeScalarField( const ScalarField &scalar_field );
  309. +
  310. + virtual void readProfile( ScrubberParam *param, ScalarField *u );
  311. +};
  312. diff --git a/src/InOut/InOut.cpp b/src/InOut/InOut.cpp
  313. new file mode 100644
  314. index 0000000..220f5eb
  315. --- /dev/null
  316. +++ b/src/InOut/InOut.cpp
  317. @@ -0,0 +1,58 @@
  318. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  319. +//
  320. +// Permission to use, copy, modify, and/or distribute this software for any
  321. +// purpose with or without fee is hereby granted, provided that the above
  322. +// copyright notice and this permission notice appear in all copies.
  323. +//
  324. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  325. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  326. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  327. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  328. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  329. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  330. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  331. +
  332. +
  333. +// Headers
  334. +#include "InOut.h"
  335. +
  336. +#include "Typedefs.h"
  337. +#include "Particles/ParticleArray.h"
  338. +#include "Particles/Particle.h"
  339. +
  340. +
  341. +// Constructor / Destructor
  342. +InOut::InOut( const ScrubberParam &param )
  343. +{
  344. + // FIXME: Cast to enum from integer (thanks to parameter parser sucking).
  345. + this->outputinfo = (OutputInfo) param.output.info;
  346. +
  347. + this->height = param.channel.height;
  348. + this->radius = param.channel.radius;
  349. + this->dx = param.channel.dx;
  350. + this->n = param.channel.n;
  351. +
  352. + this->param = param; // only needed for outputting cmdline options
  353. +}
  354. +
  355. +InOut::~InOut() {}
  356. +
  357. +
  358. +// Public Methods
  359. +void InOut::writeToFile( double time, const ParticleArray &particles )
  360. +{
  361. + static bool first_call = true;
  362. +
  363. + switch ( outputinfo ) {
  364. + case OUTPUT_NOTHING:
  365. + // Do nothing.
  366. + break;
  367. + case OUTPUT_POSITIONS:
  368. + writePositions( first_call, time, particles );
  369. + break;
  370. + default:
  371. + std::cout << "ERROR: Unknown outputtype.";
  372. + break;
  373. + }
  374. + first_call = false;
  375. +}
  376. diff --git a/src/InOut/InOut.h b/src/InOut/InOut.h
  377. new file mode 100644
  378. index 0000000..1fc5af3
  379. --- /dev/null
  380. +++ b/src/InOut/InOut.h
  381. @@ -0,0 +1,91 @@
  382. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  383. +//
  384. +// Permission to use, copy, modify, and/or distribute this software for any
  385. +// purpose with or without fee is hereby granted, provided that the above
  386. +// copyright notice and this permission notice appear in all copies.
  387. +//
  388. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  389. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  390. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  391. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  392. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  393. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  394. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  395. +
  396. +#pragma once
  397. +
  398. +// Headers
  399. +#include <fstream>
  400. +
  401. +#include "Typedefs.h"
  402. +#include "Scrubber.h"
  403. +
  404. +
  405. +// Forward Declarations
  406. +class Channel;
  407. +class ParticleArray;
  408. +
  409. +
  410. +/**
  411. + * Abstract class for reading and writing to and from files.
  412. + */
  413. +class InOut
  414. +{
  415. +protected:
  416. + OutputInfo outputinfo;
  417. +
  418. + double height;
  419. + double radius;
  420. + double dx;
  421. + int n;
  422. +
  423. + FILE *f;
  424. +
  425. + ScrubberParam param; // To output the cmdline options to file when wanted.
  426. +
  427. +
  428. + /**
  429. + * Write the positions and concentration of particles to the file.
  430. + * @param first_call True if this function is first called.
  431. + * @param time Absolute time in seconds.
  432. + * @param particles Array of particles.
  433. + */
  434. + virtual void writePositions( bool first_call, double time, const ParticleArray &particles ) = 0;
  435. +
  436. +public:
  437. + /**
  438. + * Constructor.
  439. + * @param param Struct of parameters.
  440. + */
  441. + InOut( const ScrubberParam &param );
  442. +
  443. + /**
  444. + * Write the concentration of particles to the file.
  445. + * @param first_call True if this function is first called.
  446. + * @param particles Array of particles.
  447. + */
  448. + virtual ~InOut();
  449. +
  450. + /**
  451. + * Write output to file.
  452. + * Based on the choice of the output type, it calls another function that actually writes.
  453. + * @param time Absolute time in seconds.
  454. + * @param particles Array of particles.
  455. + */
  456. + void writeToFile( double time, const ParticleArray &particles );
  457. +
  458. + /**
  459. + * Write the velocity profile to file.
  460. + * @param scalar_field ScalarField containting the velocity profile.
  461. + */
  462. + virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
  463. +
  464. + /**
  465. + * Read the velocity profile information from a file.
  466. + * In the process, read the amount of gridpoints and the stepsizes,
  467. + * and write these to the parameter struct.
  468. + * @param *param Struct of parameters.
  469. + * @param *u ScalarField to write the velocities to.
  470. + */
  471. + virtual void readProfile( ScrubberParam *param, ScalarField *u ) = 0;
  472. +};
  473. diff --git a/src/InOut/TextInOut.cpp b/src/InOut/TextInOut.cpp
  474. new file mode 100644
  475. index 0000000..95d7953
  476. --- /dev/null
  477. +++ b/src/InOut/TextInOut.cpp
  478. @@ -0,0 +1,95 @@
  479. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  480. +//
  481. +// Permission to use, copy, modify, and/or distribute this software for any
  482. +// purpose with or without fee is hereby granted, provided that the above
  483. +// copyright notice and this permission notice appear in all copies.
  484. +//
  485. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  486. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  487. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  488. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  489. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  490. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  491. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  492. +
  493. +
  494. +// Headers
  495. +#include "TextInOut.h"
  496. +
  497. +#include "Particles/ParticleArray.h"
  498. +#include "Particles/Particle.h"
  499. +
  500. +
  501. +// Constructor / Destructor
  502. +TextInOut::TextInOut( const ScrubberParam &param ) :
  503. + InOut( param )
  504. +{
  505. + if ( param.output.info != OUTPUT_NOTHING )
  506. + {
  507. + f = fopen( param.output.path.c_str(), "w" );
  508. +
  509. + if ( !f ) {
  510. + printf( "Error in opening output file, exiting\n" );
  511. + exit( 1 );
  512. + }
  513. +
  514. + // Write file type header
  515. + fwrite( &param.output.format, 4, 1, f );
  516. + }
  517. +}
  518. +
  519. +TextInOut::~TextInOut()
  520. +{
  521. + if ( param.output.info != OUTPUT_NOTHING )
  522. + fclose(f);
  523. +}
  524. +
  525. +
  526. +// Private Methods
  527. +inline void TextInOut::writePositions( bool first_call, double time, const ParticleArray &particles )
  528. +{
  529. + if ( first_call )
  530. + fprintf( f, "#T X Y C\n" );
  531. +
  532. + for ( int i = 0; i < particles.getLength(); i++ )
  533. + {
  534. + // Readability
  535. + const Vector2d & pos = particles.getParticle( i ).getPos();
  536. +
  537. + // Write output to file
  538. + fprintf( f, "%e %e %e\n",
  539. + time, pos(0), pos(1) );
  540. + }
  541. + fprintf( f, "\n" );
  542. +}
  543. +
  544. +
  545. +// Public Methods
  546. +void TextInOut::writeScalarField( const ScalarField &scalar_field )
  547. +{
  548. + // Write header
  549. + fprintf( f, "dx = %e, radius = %e, n = %d\n", dx, radius, n );
  550. +
  551. + // Write the scalar values to file.
  552. + for ( int i = 0; i < scalar_field.shape()(0); i++ )
  553. + fprintf( f, "%e\n", scalar_field(i) );
  554. +}
  555. +
  556. +void TextInOut::readProfile( ScrubberParam *param, ScalarField *u )
  557. +{
  558. + FILE *f = fopen( param->input.path.c_str(), "r" );
  559. + // Skip the file type header
  560. + fseek ( f , 4 , SEEK_SET );
  561. +
  562. + // Read the channel header
  563. + fscanf( f, "dx = %lf, radius = %lf, n = %d\n", &param->channel.dx, &param->channel.radius, &param->channel.n );
  564. +
  565. + u->resize( param->channel.n + 2 );
  566. +
  567. + // FIXME: Check if the lenght of the file is sufficient
  568. + // FIXME: Is there a way to not write the elements iteratively?
  569. + for( int i = 0; i < u->shape()(0); i++ )
  570. + fscanf( f, "%lf\n", &(*u)(i) );
  571. +
  572. + fclose( f );
  573. +}
  574. diff --git a/src/InOut/TextInOut.h b/src/InOut/TextInOut.h
  575. new file mode 100644
  576. index 0000000..b629e28
  577. --- /dev/null
  578. +++ b/src/InOut/TextInOut.h
  579. @@ -0,0 +1,48 @@
  580. +// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  581. +//
  582. +// Permission to use, copy, modify, and/or distribute this software for any
  583. +// purpose with or without fee is hereby granted, provided that the above
  584. +// copyright notice and this permission notice appear in all copies.
  585. +//
  586. +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  587. +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  588. +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  589. +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  590. +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  591. +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  592. +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  593. +
  594. +#pragma once
  595. +
  596. +// Headers
  597. +#include "InOut.h"
  598. +
  599. +#include "Scrubber.h"
  600. +#include "Typedefs.h"
  601. +
  602. +
  603. +/**
  604. + * Writes to the output in humanly readable text form, and reads input from an identically formatted text file.
  605. + */
  606. +class TextInOut : public InOut
  607. +{
  608. +protected:
  609. + virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  610. +
  611. +public:
  612. + /**
  613. + * Constructor.
  614. + * @param param Struct of parameters.
  615. + */
  616. + TextInOut( const ScrubberParam &param );
  617. +
  618. + /**
  619. + * Destructor.
  620. + */
  621. + virtual ~TextInOut();
  622. +
  623. + //FIXME: Should be private.
  624. + virtual void writeScalarField( const ScalarField &scalar_field );
  625. +
  626. + virtual void readProfile( ScrubberParam *param, ScalarField *u );
  627. +};
  628. diff --git a/src/Output/ByteOutput.cpp b/src/Output/ByteOutput.cpp
  629. deleted file mode 100644
  630. index 5ddc620..0000000
  631. --- a/src/Output/ByteOutput.cpp
  632. +++ /dev/null
  633. @@ -1,91 +0,0 @@
  634. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  635. -//
  636. -// Permission to use, copy, modify, and/or distribute this software for any
  637. -// purpose with or without fee is hereby granted, provided that the above
  638. -// copyright notice and this permission notice appear in all copies.
  639. -//
  640. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  641. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  642. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  643. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  644. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  645. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  646. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  647. -
  648. -
  649. -// Headers
  650. -#include "ByteOutput.h"
  651. -
  652. -#include "Particles/ParticleArray.h"
  653. -#include "Particles/Particle.h"
  654. -
  655. -
  656. -// Constructor / Destructor
  657. -ByteOutput::ByteOutput( const ScrubberParam &param ) :
  658. - Output( param )
  659. -{
  660. - if ( param.output.info != OUTPUT_NOTHING )
  661. - {
  662. - f = fopen( param.output.path.c_str(), "wb" );
  663. -
  664. - if ( !f ) {
  665. - printf( "Error in opening output file, exiting\n" );
  666. - exit( 1 );
  667. - }
  668. - }
  669. -}
  670. -
  671. -ByteOutput::~ByteOutput()
  672. -{
  673. - if ( param.output.info != OUTPUT_NOTHING )
  674. - fclose( f );
  675. -}
  676. -
  677. -
  678. -// Private Methods
  679. -inline void ByteOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
  680. -{
  681. - if ( first_call )
  682. - {
  683. - // Write the and delimiter values to file.
  684. - // i.e. buf[] = { xmin, xmax, ymin, ymax, zmin, zmax }
  685. - double buf[] = { radius, height };
  686. - fwrite( buf, 8, 2, f );
  687. - }
  688. -
  689. - // Frame data
  690. - double buf1[] = { time };
  691. - fwrite( buf1, 8, 1, f );
  692. -
  693. - int buf2[] = { particles.getLength() };
  694. - fwrite( buf2, 4, 1, f );
  695. -
  696. - // Write data
  697. - for ( int i = 0; i < particles.getLength(); i++ )
  698. - {
  699. - // Readability
  700. - const Vector2d & pos = particles.getParticle( i ).getPos();
  701. -
  702. - double buf[] = { pos(0), pos(1) };
  703. - fwrite( buf, 8, 2, f );
  704. - }
  705. -}
  706. -
  707. -
  708. -// Public Methods
  709. -void ByteOutput::writeScalarField( const ScalarField &scalar_field )
  710. -{
  711. - // Write header
  712. - double buf1[] = { dx, radius };
  713. - fwrite( buf1, 8, 2, f );
  714. -
  715. - int buf2[] = { scalar_field.shape()(0) };
  716. - fwrite( buf2, 4, 1, f );
  717. -
  718. - // Write the scalar values to file.
  719. - for ( int i = 0; i < scalar_field.shape()(0); i++ )
  720. - {
  721. - double buf3[] = { scalar_field(i) };
  722. - fwrite( buf3, 8, 1, f );
  723. - }
  724. -}
  725. \ No newline at end of file
  726. diff --git a/src/Output/ByteOutput.h b/src/Output/ByteOutput.h
  727. deleted file mode 100644
  728. index 69bba92..0000000
  729. --- a/src/Output/ByteOutput.h
  730. +++ /dev/null
  731. @@ -1,47 +0,0 @@
  732. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  733. -//
  734. -// Permission to use, copy, modify, and/or distribute this software for any
  735. -// purpose with or without fee is hereby granted, provided that the above
  736. -// copyright notice and this permission notice appear in all copies.
  737. -//
  738. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  739. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  740. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  741. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  742. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  743. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  744. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  745. -
  746. -#pragma once
  747. -
  748. -// Headers
  749. -#include <fstream>
  750. -#include "Output.h"
  751. -
  752. -#include "Scrubber.h"
  753. -#include "Typedefs.h"
  754. -
  755. -
  756. -/**
  757. - * Writes to the output in binary form.
  758. - */
  759. -class ByteOutput : public Output
  760. -{
  761. -protected:
  762. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  763. -
  764. -public:
  765. - /**
  766. - * Constructor.
  767. - * @param param Struct of parameters.
  768. - */
  769. - ByteOutput( const ScrubberParam &param );
  770. -
  771. - /**
  772. - * Destructor.
  773. - */
  774. - virtual ~ByteOutput();
  775. -
  776. - //FIXME: Should be private.
  777. - virtual void writeScalarField( const ScalarField &scalar_field );
  778. -};
  779. \ No newline at end of file
  780. diff --git a/src/Output/Output.cpp b/src/Output/Output.cpp
  781. deleted file mode 100644
  782. index 28cd1b9..0000000
  783. --- a/src/Output/Output.cpp
  784. +++ /dev/null
  785. @@ -1,58 +0,0 @@
  786. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  787. -//
  788. -// Permission to use, copy, modify, and/or distribute this software for any
  789. -// purpose with or without fee is hereby granted, provided that the above
  790. -// copyright notice and this permission notice appear in all copies.
  791. -//
  792. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  793. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  794. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  795. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  796. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  797. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  798. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  799. -
  800. -
  801. -// Headers
  802. -#include "Output.h"
  803. -
  804. -#include "Typedefs.h"
  805. -#include "Particles/ParticleArray.h"
  806. -#include "Particles/Particle.h"
  807. -
  808. -
  809. -// Constructor / Destructor
  810. -Output::Output( const ScrubberParam &param )
  811. -{
  812. - // FIXME: Cast to enum from integer (thanks to parameter parser sucking).
  813. - this->outputinfo = (OutputInfo) param.output.info;
  814. -
  815. - this->height = param.channel.height;
  816. - this->radius = param.channel.radius;
  817. - this->dx = param.channel.dx;
  818. -
  819. - this->param = param; // only needed for outputting cmdline options
  820. -}
  821. -
  822. -Output::~Output() {}
  823. -
  824. -
  825. -// Public Methods
  826. -void Output::writeToFile( double time, const ParticleArray &particles )
  827. -{
  828. - static bool first_call = true;
  829. -
  830. - switch ( outputinfo ) {
  831. - case OUTPUT_NOTHING:
  832. - // Do nothing.
  833. - break;
  834. - case OUTPUT_POSITIONS:
  835. - writePositions( first_call, time, particles );
  836. - break;
  837. - default:
  838. - std::cout << "ERROR: Unknown outputtype.";
  839. - break;
  840. - }
  841. - first_call = false;
  842. -}
  843. -
  844. diff --git a/src/Output/Output.h b/src/Output/Output.h
  845. deleted file mode 100644
  846. index 0df2c66..0000000
  847. --- a/src/Output/Output.h
  848. +++ /dev/null
  849. @@ -1,81 +0,0 @@
  850. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  851. -//
  852. -// Permission to use, copy, modify, and/or distribute this software for any
  853. -// purpose with or without fee is hereby granted, provided that the above
  854. -// copyright notice and this permission notice appear in all copies.
  855. -//
  856. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  857. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  858. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  859. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  860. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  861. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  862. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  863. -
  864. -#pragma once
  865. -
  866. -// Headers
  867. -#include <fstream>
  868. -
  869. -#include "Typedefs.h"
  870. -#include "Scrubber.h"
  871. -
  872. -
  873. -// Forward Declarations
  874. -class Channel;
  875. -class ParticleArray;
  876. -
  877. -
  878. -/**
  879. - * Abstract class for outputting.
  880. - */
  881. -class Output
  882. -{
  883. -protected:
  884. - OutputInfo outputinfo;
  885. -
  886. - double height;
  887. - double radius;
  888. - double dx;
  889. -
  890. - FILE *f;
  891. -
  892. - ScrubberParam param; // To output the cmdline options to file when wanted.
  893. -
  894. -
  895. - /**
  896. - * Write the positions and concentration of particles to the file.
  897. - * @param first_call True if this function is first called.
  898. - * @param time Absolute time in seconds.
  899. - * @param particles Array of particles.
  900. - */
  901. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles ) = 0;
  902. -
  903. -public:
  904. - /**
  905. - * Constructor.
  906. - * @param param Struct of parameters.
  907. - */
  908. - Output( const ScrubberParam &param );
  909. -
  910. - /**
  911. - * Write the concentration of particles to the file.
  912. - * @param first_call True if this function is first called.
  913. - * @param particles Array of particles.
  914. - */
  915. - virtual ~Output();
  916. -
  917. - /**
  918. - * Write output to file.
  919. - * Based on the choice of the output type, it calls another function that actually writes.
  920. - * @param time Absolute time in seconds.
  921. - * @param particles Array of particles.
  922. - */
  923. - void writeToFile( double time, const ParticleArray &particles );
  924. -
  925. - /**
  926. - * Write the velocity profile to file.
  927. - * @param scalar_field ScalarField containting the velocity profile.
  928. - */
  929. - virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
  930. -};
  931. diff --git a/src/Output/TextOutput.cpp b/src/Output/TextOutput.cpp
  932. deleted file mode 100644
  933. index cf2a7cd..0000000
  934. --- a/src/Output/TextOutput.cpp
  935. +++ /dev/null
  936. @@ -1,73 +0,0 @@
  937. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  938. -//
  939. -// Permission to use, copy, modify, and/or distribute this software for any
  940. -// purpose with or without fee is hereby granted, provided that the above
  941. -// copyright notice and this permission notice appear in all copies.
  942. -//
  943. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  944. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  945. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  946. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  947. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  948. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  949. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  950. -
  951. -
  952. -// Headers
  953. -#include "TextOutput.h"
  954. -
  955. -#include "Particles/ParticleArray.h"
  956. -#include "Particles/Particle.h"
  957. -
  958. -
  959. -// Constructor / Destructor
  960. -TextOutput::TextOutput( const ScrubberParam &param ) :
  961. - Output( param )
  962. -{
  963. - if ( param.output.info != OUTPUT_NOTHING )
  964. - {
  965. - f = fopen( param.output.path.c_str(), "w" );
  966. -
  967. - if ( !f ) {
  968. - printf( "Error in opening output file, exiting\n" );
  969. - exit( 1 );
  970. - }
  971. - }
  972. -}
  973. -
  974. -TextOutput::~TextOutput()
  975. -{
  976. - if ( param.output.info != OUTPUT_NOTHING )
  977. - fclose(f);
  978. -}
  979. -
  980. -
  981. -// Private Methods
  982. -inline void TextOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
  983. -{
  984. - if ( first_call )
  985. - fprintf( f, "#T X Y C\n" );
  986. -
  987. - for ( int i = 0; i < particles.getLength(); i++ )
  988. - {
  989. - // Readability
  990. - const Vector2d & pos = particles.getParticle( i ).getPos();
  991. -
  992. - // Write output to file
  993. - fprintf( f, "%e %e %e\n",
  994. - time, pos(0), pos(1) );
  995. - }
  996. - fprintf( f, "\n" );
  997. -}
  998. -
  999. -
  1000. -// Public Methods
  1001. -void TextOutput::writeScalarField( const ScalarField &scalar_field )
  1002. -{
  1003. - // Write header
  1004. - fprintf( f, "dx = %e, radius = %e, n+2 = %d\n", dx, radius, scalar_field.shape()(0) );
  1005. -
  1006. - // Write the scalar values to file.
  1007. - for ( int i = 0; i < scalar_field.shape()(0); i++ )
  1008. - fprintf( f, "%e\n", scalar_field(i) );
  1009. -}
  1010. \ No newline at end of file
  1011. diff --git a/src/Output/TextOutput.h b/src/Output/TextOutput.h
  1012. deleted file mode 100644
  1013. index a2f7e98..0000000
  1014. --- a/src/Output/TextOutput.h
  1015. +++ /dev/null
  1016. @@ -1,46 +0,0 @@
  1017. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  1018. -//
  1019. -// Permission to use, copy, modify, and/or distribute this software for any
  1020. -// purpose with or without fee is hereby granted, provided that the above
  1021. -// copyright notice and this permission notice appear in all copies.
  1022. -//
  1023. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  1024. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  1025. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  1026. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1027. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1028. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  1029. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1030. -
  1031. -#pragma once
  1032. -
  1033. -// Headers
  1034. -#include "Output.h"
  1035. -
  1036. -#include "Scrubber.h"
  1037. -#include "Typedefs.h"
  1038. -
  1039. -
  1040. -/**
  1041. - * Writes to the output in humanly readable text form.
  1042. - */
  1043. -class TextOutput : public Output
  1044. -{
  1045. -protected:
  1046. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  1047. -
  1048. -public:
  1049. - /**
  1050. - * Constructor.
  1051. - * @param param Struct of parameters.
  1052. - */
  1053. - TextOutput( const ScrubberParam &param );
  1054. -
  1055. - /**
  1056. - * Destructor.
  1057. - */
  1058. - virtual ~TextOutput();
  1059. -
  1060. - //FIXME: Should be private.
  1061. - virtual void writeScalarField( const ScalarField &scalar_field );
  1062. -};
  1063. \ No newline at end of file
  1064. diff --git a/src/Scrubber.cpp b/src/Scrubber.cpp
  1065. index 306cfcb..35e0fff 100644
  1066. --- a/src/Scrubber.cpp
  1067. +++ b/src/Scrubber.cpp
  1068. @@ -20,9 +20,9 @@
  1069.  
  1070. #include "getopt_pp.h"
  1071.  
  1072. -#include "Output/Output.h"
  1073. -#include "Output/ByteOutput.h"
  1074. -#include "Output/TextOutput.h"
  1075. +#include "InOut/InOut.h"
  1076. +#include "InOut/ByteInOut.h"
  1077. +#include "InOut/TextInOut.h"
  1078.  
  1079. #include "Emitter/Emitter.h"
  1080. #include "Emitter/GridEmitter.h"
  1081. @@ -56,15 +56,50 @@ int main( int argc, char* argv[] )
  1082. parse( argc, argv, &param );
  1083. printParam( param );
  1084.  
  1085. - // Making the Output
  1086. - Output * output;
  1087. + ScalarField u;
  1088. +
  1089. + if ( param.input.path != "" )
  1090. + {
  1091. + FILE *f;
  1092. + if( (f = fopen( param.input.path.c_str(), "r" )) == NULL )
  1093. + {
  1094. + printf("Problem opening profile file %s.\n", param.input.path.c_str());
  1095. + exit( 1 );
  1096. + }
  1097. +
  1098. + // Read the file type
  1099. + fread( &param.input.format, 4, 1, f );
  1100. + fclose( f );
  1101. +
  1102. + // Making the input reader and read the velocity profile
  1103. + InOut * input;
  1104. +
  1105. + switch ( param.input.format ) {
  1106. + case INOUT_BYTE:
  1107. + input = new ByteInOut( param );
  1108. + break;
  1109. + case INOUT_TEXT:
  1110. + input = new TextInOut( param );
  1111. + break;
  1112. + default:
  1113. + cout << "Unknown input type.";
  1114. + break;
  1115. + }
  1116. +
  1117. + input->readProfile( &param, &u );
  1118. +
  1119. + delete input;
  1120. + }
  1121. +
  1122. + // Making the output writer
  1123. + InOut * output;
  1124.  
  1125. switch ( param.output.format ) {
  1126. - case OUTPUT_BYTE:
  1127. - output = new ByteOutput( param );
  1128. + case INOUT_BYTE:
  1129. + output = new ByteInOut( param );
  1130. break;
  1131. - case OUTPUT_TEXT:
  1132. - output = new TextOutput( param );
  1133. + case INOUT_TEXT:
  1134. + output = new TextInOut( param );
  1135. break;
  1136. default:
  1137. cout << "Unknown output type.";
  1138. @@ -74,7 +109,10 @@ int main( int argc, char* argv[] )
  1139. // Making the channel
  1140. Channel *channel = new Channel( param );
  1141.  
  1142. - channel->init();
  1143. + if ( param.input.path == "" )
  1144. + channel->init();
  1145. + else
  1146. + channel->init( u );
  1147.  
  1148. if ( param.output.info == OUTPUT_VELFIELD )
  1149. {
  1150. @@ -203,6 +241,12 @@ void show_help()
  1151. " --rate <double> (=100.0) Amount of particles emitted per second.\n"
  1152. " --initvel <string> (=[0,0]) Particle's initial velocity in m/s.\n"
  1153. "\n"
  1154. + "Input Options:\n"
  1155. + " --pformat <int> (=0) Profile formats:\n"
  1156. + " 0: Calculate the profile.\n"
  1157. + " 1: Byte\n"
  1158. + " 2: Text\n"
  1159. + " --profile <string> (=\"\") Path to profile data (if --pformat > 0).\n"
  1160. "Output Options:\n"
  1161. " --oformat <int> (=1) Output formats:\n"
  1162. " 1: Byte\n"
  1163. @@ -267,8 +311,10 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
  1164. >> Option( 'a', "dim", s_edim, "[-3:30:3,60:1:60]" )
  1165. >> Option( 'a', "rate", param->emitter.rate, 100.0 )
  1166. >> Option( 'a', "initvel", s_initvel, "[0,0]" );
  1167. + // Input Options
  1168. + ops >> Option( 'a', "profile", param->input.path, "" );
  1169. // Output Options
  1170. - ops >> Option( 'a', "oformat", param->output.format, (int) OUTPUT_BYTE )
  1171. + ops >> Option( 'a', "oformat", param->output.format, (int) INOUT_BYTE )
  1172. >> Option( 'a', "oinfo", param->output.info, (int) OUTPUT_NOTHING )
  1173. >> Option( 'a', "oint", param->output.interval, 1.0 )
  1174. >> Option( 'a', "out", param->output.path, "test.data" );
  1175. @@ -301,7 +347,6 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
  1176. param->maxparticles = param->emitter.p_N;
  1177. }
  1178.  
  1179. -
  1180. param->beta = param->p.density / param->fl.density;
  1181.  
  1182. param->tau_p = param->p.density * 4 * param->p.radius * param->p.radius / (18 * param->fl.nu);
  1183. diff --git a/src/Scrubber.h b/src/Scrubber.h
  1184. index 37e374c..304e355 100644
  1185. --- a/src/Scrubber.h
  1186. +++ b/src/Scrubber.h
  1187. @@ -61,10 +61,10 @@ enum OutputInfo
  1188. OUTPUT_VELFIELD
  1189. };
  1190.  
  1191. -enum OutputFormat
  1192. +enum InOutFormat
  1193. {
  1194. - OUTPUT_BYTE = 1,
  1195. - OUTPUT_TEXT
  1196. + INOUT_BYTE = 1,
  1197. + INOUT_TEXT
  1198. };
  1199.  
  1200. enum EmitterType
  1201. @@ -152,6 +152,13 @@ struct ScrubberParam
  1202. Vector2d init_velocity; /// Initial velocity the particles are emitted with.
  1203. } emitter;
  1204.  
  1205. + // Input specific parameters
  1206. + struct input
  1207. + {
  1208. + int format; /// <enum> Input type.
  1209. + string path; /// Path to profile datafile.
  1210. + } input;
  1211. +
  1212. // Output specific parameters
  1213. struct output
  1214. {
  1215. --
  1216. 1.6.5.1.1367.gcd48
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement