Advertisement
Guest User

Untitled

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