Advertisement
Guest User

Untitled

a guest
May 5th, 2017
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.47 KB | None | 0 0
  1. diff --git a/Makefile b/Makefile
  2. index bed4fd8..0d5b138 100644
  3. --- a/Makefile
  4. +++ b/Makefile
  5. @@ -5,7 +5,7 @@ SRCS = ./external/getopt_pp.cpp \
  6. ./src/Channel/CPModel.cpp ./src/Channel/Channel.cpp \
  7. ./src/Particles/Mover.cpp \
  8. ./src/Emitter/Emitter.cpp ./src/Emitter/GridEmitter.cpp ./src/Emitter/GridOnceEmitter.cpp ./src/Emitter/RandomEmitter.cpp \
  9. - ./src/Output/Output.cpp ./src/Output/ByteOutput.cpp ./src/Output/TextOutput.cpp \
  10. + ./src/InOut/InOut.cpp ./src/InOut/ByteInOut.cpp ./src/InOut/TextInOut.cpp \
  11. ./src/Scrubber.cpp
  12.  
  13. CXXFLAGS = -O2 -DNDEBUG
  14. diff --git a/build/vs2008/Scrubber.sln b/build/vs2008/Scrubber.sln
  15. index eb51992..f01406e 100644
  16. --- a/build/vs2008/Scrubber.sln
  17. +++ b/build/vs2008/Scrubber.sln
  18. @@ -1,6 +1,7 @@
  19. +
  20. Microsoft Visual Studio Solution File, Format Version 10.00
  21. # Visual Studio 2008
  22. -Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "Scrubber", "Scrubber.icproj", "{ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}"
  23. +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scrubber", "Scrubber.vcproj", "{D4423193-7F06-45F2-BD8A-AEFF115699D4}"
  24. EndProject
  25. Global
  26. GlobalSection(SolutionConfigurationPlatforms) = preSolution
  27. @@ -12,30 +13,18 @@ Global
  28. ReleaseIntel|x64 = ReleaseIntel|x64
  29. EndGlobalSection
  30. GlobalSection(ProjectConfigurationPlatforms) = postSolution
  31. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|Win32.ActiveCfg = Debug|Win32
  32. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|Win32.Build.0 = Debug|Win32
  33. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|x64.ActiveCfg = Debug|x64
  34. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|x64.Build.0 = Debug|x64
  35. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|Win32.ActiveCfg = Release|Win32
  36. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|Win32.Build.0 = Release|Win32
  37. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|x64.ActiveCfg = Release|x64
  38. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|x64.Build.0 = Release|x64
  39. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
  40. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
  41. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
  42. - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
  43. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
  44. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
  45. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
  46. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
  47. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.Build.0 = Release|x64
  48. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.ActiveCfg = Release|x64
  49. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.Build.0 = Release|Win32
  50. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.ActiveCfg = Release|Win32
  51. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.Build.0 = Debug|x64
  52. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.ActiveCfg = Debug|x64
  53. - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.Build.0 = Debug|Win32
  54. {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.ActiveCfg = Debug|Win32
  55. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.Build.0 = Debug|Win32
  56. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.ActiveCfg = Debug|x64
  57. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.Build.0 = Debug|x64
  58. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.ActiveCfg = Release|Win32
  59. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.Build.0 = Release|Win32
  60. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.ActiveCfg = Release|x64
  61. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.Build.0 = Release|x64
  62. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
  63. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
  64. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
  65. + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
  66. EndGlobalSection
  67. GlobalSection(SolutionProperties) = preSolution
  68. HideSolutionNode = FALSE
  69. diff --git a/build/vs2008/Scrubber.vcproj b/build/vs2008/Scrubber.vcproj
  70. index f700a04..4abb59b 100644
  71. --- a/build/vs2008/Scrubber.vcproj
  72. +++ b/build/vs2008/Scrubber.vcproj
  73. @@ -537,30 +537,30 @@
  74. </File>
  75. </Filter>
  76. <Filter
  77. - Name="Output"
  78. + Name="InOut"
  79. >
  80. <File
  81. - RelativePath="..\..\src\Output\ByteOutput.cpp"
  82. + RelativePath="..\..\src\InOut\ByteInOut.cpp"
  83. >
  84. </File>
  85. <File
  86. - RelativePath="..\..\src\Output\ByteOutput.h"
  87. + RelativePath="..\..\src\InOut\ByteInOut.h"
  88. >
  89. </File>
  90. <File
  91. - RelativePath="..\..\src\Output\Output.cpp"
  92. + RelativePath="..\..\src\InOut\InOut.cpp"
  93. >
  94. </File>
  95. <File
  96. - RelativePath="..\..\src\Output\Output.h"
  97. + RelativePath="..\..\src\InOut\InOut.h"
  98. >
  99. </File>
  100. <File
  101. - RelativePath="..\..\src\Output\TextOutput.cpp"
  102. + RelativePath="..\..\src\InOut\TextInOut.cpp"
  103. >
  104. </File>
  105. <File
  106. - RelativePath="..\..\src\Output\TextOutput.h"
  107. + RelativePath="..\..\src\InOut\TextInOut.h"
  108. >
  109. </File>
  110. </Filter>
  111. diff --git a/src/Channel/Channel.cpp b/src/Channel/Channel.cpp
  112. index 9c2bff3..bf22ecc 100644
  113. --- a/src/Channel/Channel.cpp
  114. +++ b/src/Channel/Channel.cpp
  115. @@ -81,6 +81,11 @@ void Channel::init()
  116. u = cpmodel->init( u );
  117. }
  118.  
  119. +void Channel::init( const ScalarField &u )
  120. +{
  121. + this->u = u;
  122. +}
  123. +
  124. PosBox Channel::outsideBox( const Vector2d &pos )
  125. {
  126. if ( pos(1) >= height )
  127. diff --git a/src/Channel/Channel.h b/src/Channel/Channel.h
  128. index 6983240..dc06f4c 100644
  129. --- a/src/Channel/Channel.h
  130. +++ b/src/Channel/Channel.h
  131. @@ -69,12 +69,17 @@ public:
  132. virtual ~Channel();
  133.  
  134. /**
  135. - * Initialize the channel.
  136. - * Generates the velocity profile in the channel by looping until steady.
  137. + * Initialize the channel by calculating the velocity profile.
  138. */
  139. void init();
  140.  
  141. /**
  142. + * Initialize the channel by copying in an existing velocity profile.
  143. + * @param u The ScalarField to be used as the velocity profile.
  144. + */
  145. + void init( const ScalarField &u );
  146. +
  147. + /**
  148. * Checks if the particle has left the box on the sides, top, bottom or is still in the box.
  149. * @param pos Position of the particle.
  150. * @return An enum indicating where the particle is at.
  151. diff --git a/src/InOut/ByteInOut.cpp b/src/InOut/ByteInOut.cpp
  152. index 908a576..3f749ae 100644
  153. --- a/src/InOut/ByteInOut.cpp
  154. +++ b/src/InOut/ByteInOut.cpp
  155. @@ -79,7 +79,7 @@ void ByteInOut::writeScalarField( const ScalarField &scalar_field )
  156. double buf1[] = { dx, radius };
  157. fwrite( buf1, 8, 2, f );
  158.  
  159. - int buf2[] = { scalar_field.shape()(0) };
  160. + int buf2[] = { n };
  161. fwrite( buf2, 4, 1, f );
  162.  
  163. // Write the scalar values to file.
  164. @@ -88,4 +88,23 @@ void ByteInOut::writeScalarField( const ScalarField &scalar_field )
  165. double buf3[] = { scalar_field(i) };
  166. fwrite( buf3, 8, 1, f );
  167. }
  168. -}
  169. \ No newline at end of file
  170. +}
  171. +
  172. +void ByteInOut::readProfile( ScrubberParam *param, ScalarField *u )
  173. +{
  174. + FILE *f = fopen( param->input.path.c_str(), "rb" );
  175. +
  176. + // Read the header
  177. + fread( &param->channel.dx, 8, 1, f );
  178. + fread( &param->channel.radius, 8, 1, f );
  179. + fread( &param->channel.n, 4, 1, f );
  180. +
  181. + u->resize( param->channel.n + 2 );
  182. +
  183. + // FIXME: Check if the lenght of the file is sufficient
  184. + // FIXME: Is there a way to not write the elements iteratively?
  185. + for( int i = 0; i < u->shape()(0); i++ )
  186. + fread( &(*u)(i), 8, 1, f );
  187. +
  188. + fclose( f );
  189. +}
  190. diff --git a/src/InOut/ByteInOut.h b/src/InOut/ByteInOut.h
  191. index 265f0b9..111976a 100644
  192. --- a/src/InOut/ByteInOut.h
  193. +++ b/src/InOut/ByteInOut.h
  194. @@ -23,7 +23,7 @@
  195.  
  196.  
  197. /**
  198. - * Writes to the output in binary form.
  199. + * Writes to the output in binary form, and reads input from an identically formatted binary file.
  200. */
  201. class ByteInOut : public InOut
  202. {
  203. @@ -44,4 +44,6 @@ public:
  204.  
  205. //FIXME: Should be private.
  206. virtual void writeScalarField( const ScalarField &scalar_field );
  207. -};
  208. \ No newline at end of file
  209. +
  210. + virtual void readProfile( ScrubberParam *param, ScalarField *u );
  211. +};
  212. diff --git a/src/InOut/InOut.cpp b/src/InOut/InOut.cpp
  213. index 0c438be..220f5eb 100644
  214. --- a/src/InOut/InOut.cpp
  215. +++ b/src/InOut/InOut.cpp
  216. @@ -30,6 +30,7 @@ InOut::InOut( const ScrubberParam &param )
  217. this->height = param.channel.height;
  218. this->radius = param.channel.radius;
  219. this->dx = param.channel.dx;
  220. + this->n = param.channel.n;
  221.  
  222. this->param = param; // only needed for outputting cmdline options
  223. }
  224. @@ -55,4 +56,3 @@ void InOut::writeToFile( double time, const ParticleArray &particles )
  225. }
  226. first_call = false;
  227. }
  228. -
  229. diff --git a/src/InOut/InOut.h b/src/InOut/InOut.h
  230. index bc3668c..1fc5af3 100644
  231. --- a/src/InOut/InOut.h
  232. +++ b/src/InOut/InOut.h
  233. @@ -27,7 +27,7 @@ class ParticleArray;
  234.  
  235.  
  236. /**
  237. - * Abstract class for outputting.
  238. + * Abstract class for reading and writing to and from files.
  239. */
  240. class InOut
  241. {
  242. @@ -37,6 +37,7 @@ protected:
  243. double height;
  244. double radius;
  245. double dx;
  246. + int n;
  247.  
  248. FILE *f;
  249.  
  250. @@ -78,4 +79,13 @@ public:
  251. * @param scalar_field ScalarField containting the velocity profile.
  252. */
  253. virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
  254. +
  255. + /**
  256. + * Read the velocity profile information from a file.
  257. + * In the process, read the amount of gridpoints and the stepsizes,
  258. + * and write these to the parameter struct.
  259. + * @param *param Struct of parameters.
  260. + * @param *u ScalarField to write the velocities to.
  261. + */
  262. + virtual void readProfile( ScrubberParam *param, ScalarField *u ) = 0;
  263. };
  264. diff --git a/src/InOut/TextInOut.cpp b/src/InOut/TextInOut.cpp
  265. index 2ff43e2..5a1546f 100644
  266. --- a/src/InOut/TextInOut.cpp
  267. +++ b/src/InOut/TextInOut.cpp
  268. @@ -65,9 +65,26 @@ inline void TextInOut::writePositions( bool first_call, double time, const Parti
  269. void TextInOut::writeScalarField( const ScalarField &scalar_field )
  270. {
  271. // Write header
  272. - fprintf( f, "dx = %e, radius = %e, n+2 = %d\n", dx, radius, scalar_field.shape()(0) );
  273. + fprintf( f, "dx = %e, radius = %e, n = %d\n", dx, radius, n );
  274.  
  275. // Write the scalar values to file.
  276. for ( int i = 0; i < scalar_field.shape()(0); i++ )
  277. fprintf( f, "%e\n", scalar_field(i) );
  278. -}
  279. \ No newline at end of file
  280. +}
  281. +
  282. +void TextInOut::readProfile( ScrubberParam *param, ScalarField *u )
  283. +{
  284. + FILE *f = fopen( param->input.path.c_str(), "r" );
  285. +
  286. + // Read the header
  287. + fscanf( f, "dx = %lf, radius = %lf, n = %d\n", &param->channel.dx, &param->channel.radius, &param->channel.n );
  288. +
  289. + u->resize( param->channel.n + 2 );
  290. +
  291. + // FIXME: Check if the lenght of the file is sufficient
  292. + // FIXME: Is there a way to not write the elements iteratively?
  293. + for( int i = 0; i < u->shape()(0); i++ )
  294. + fscanf( f, "%lf\n", &(*u)(i) );
  295. +
  296. + fclose( f );
  297. +}
  298. diff --git a/src/InOut/TextInOut.h b/src/InOut/TextInOut.h
  299. index b200aa5..b629e28 100644
  300. --- a/src/InOut/TextInOut.h
  301. +++ b/src/InOut/TextInOut.h
  302. @@ -22,7 +22,7 @@
  303.  
  304.  
  305. /**
  306. - * Writes to the output in humanly readable text form.
  307. + * Writes to the output in humanly readable text form, and reads input from an identically formatted text file.
  308. */
  309. class TextInOut : public InOut
  310. {
  311. @@ -43,4 +43,6 @@ public:
  312.  
  313. //FIXME: Should be private.
  314. virtual void writeScalarField( const ScalarField &scalar_field );
  315. -};
  316. \ No newline at end of file
  317. +
  318. + virtual void readProfile( ScrubberParam *param, ScalarField *u );
  319. +};
  320. diff --git a/src/Output/ByteOutput.cpp b/src/Output/ByteOutput.cpp
  321. deleted file mode 100644
  322. index 5ddc620..0000000
  323. --- a/src/Output/ByteOutput.cpp
  324. +++ /dev/null
  325. @@ -1,91 +0,0 @@
  326. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  327. -//
  328. -// Permission to use, copy, modify, and/or distribute this software for any
  329. -// purpose with or without fee is hereby granted, provided that the above
  330. -// copyright notice and this permission notice appear in all copies.
  331. -//
  332. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  333. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  334. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  335. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  336. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  337. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  338. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  339. -
  340. -
  341. -// Headers
  342. -#include "ByteOutput.h"
  343. -
  344. -#include "Particles/ParticleArray.h"
  345. -#include "Particles/Particle.h"
  346. -
  347. -
  348. -// Constructor / Destructor
  349. -ByteOutput::ByteOutput( const ScrubberParam &param ) :
  350. - Output( param )
  351. -{
  352. - if ( param.output.info != OUTPUT_NOTHING )
  353. - {
  354. - f = fopen( param.output.path.c_str(), "wb" );
  355. -
  356. - if ( !f ) {
  357. - printf( "Error in opening output file, exiting\n" );
  358. - exit( 1 );
  359. - }
  360. - }
  361. -}
  362. -
  363. -ByteOutput::~ByteOutput()
  364. -{
  365. - if ( param.output.info != OUTPUT_NOTHING )
  366. - fclose( f );
  367. -}
  368. -
  369. -
  370. -// Private Methods
  371. -inline void ByteOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
  372. -{
  373. - if ( first_call )
  374. - {
  375. - // Write the and delimiter values to file.
  376. - // i.e. buf[] = { xmin, xmax, ymin, ymax, zmin, zmax }
  377. - double buf[] = { radius, height };
  378. - fwrite( buf, 8, 2, f );
  379. - }
  380. -
  381. - // Frame data
  382. - double buf1[] = { time };
  383. - fwrite( buf1, 8, 1, f );
  384. -
  385. - int buf2[] = { particles.getLength() };
  386. - fwrite( buf2, 4, 1, f );
  387. -
  388. - // Write data
  389. - for ( int i = 0; i < particles.getLength(); i++ )
  390. - {
  391. - // Readability
  392. - const Vector2d & pos = particles.getParticle( i ).getPos();
  393. -
  394. - double buf[] = { pos(0), pos(1) };
  395. - fwrite( buf, 8, 2, f );
  396. - }
  397. -}
  398. -
  399. -
  400. -// Public Methods
  401. -void ByteOutput::writeScalarField( const ScalarField &scalar_field )
  402. -{
  403. - // Write header
  404. - double buf1[] = { dx, radius };
  405. - fwrite( buf1, 8, 2, f );
  406. -
  407. - int buf2[] = { scalar_field.shape()(0) };
  408. - fwrite( buf2, 4, 1, f );
  409. -
  410. - // Write the scalar values to file.
  411. - for ( int i = 0; i < scalar_field.shape()(0); i++ )
  412. - {
  413. - double buf3[] = { scalar_field(i) };
  414. - fwrite( buf3, 8, 1, f );
  415. - }
  416. -}
  417. \ No newline at end of file
  418. diff --git a/src/Output/ByteOutput.h b/src/Output/ByteOutput.h
  419. deleted file mode 100644
  420. index 69bba92..0000000
  421. --- a/src/Output/ByteOutput.h
  422. +++ /dev/null
  423. @@ -1,47 +0,0 @@
  424. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  425. -//
  426. -// Permission to use, copy, modify, and/or distribute this software for any
  427. -// purpose with or without fee is hereby granted, provided that the above
  428. -// copyright notice and this permission notice appear in all copies.
  429. -//
  430. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  431. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  432. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  433. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  434. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  435. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  436. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  437. -
  438. -#pragma once
  439. -
  440. -// Headers
  441. -#include <fstream>
  442. -#include "Output.h"
  443. -
  444. -#include "Scrubber.h"
  445. -#include "Typedefs.h"
  446. -
  447. -
  448. -/**
  449. - * Writes to the output in binary form.
  450. - */
  451. -class ByteOutput : public Output
  452. -{
  453. -protected:
  454. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  455. -
  456. -public:
  457. - /**
  458. - * Constructor.
  459. - * @param param Struct of parameters.
  460. - */
  461. - ByteOutput( const ScrubberParam &param );
  462. -
  463. - /**
  464. - * Destructor.
  465. - */
  466. - virtual ~ByteOutput();
  467. -
  468. - //FIXME: Should be private.
  469. - virtual void writeScalarField( const ScalarField &scalar_field );
  470. -};
  471. \ No newline at end of file
  472. diff --git a/src/Output/Output.cpp b/src/Output/Output.cpp
  473. deleted file mode 100644
  474. index 28cd1b9..0000000
  475. --- a/src/Output/Output.cpp
  476. +++ /dev/null
  477. @@ -1,58 +0,0 @@
  478. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  479. -//
  480. -// Permission to use, copy, modify, and/or distribute this software for any
  481. -// purpose with or without fee is hereby granted, provided that the above
  482. -// copyright notice and this permission notice appear in all copies.
  483. -//
  484. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  485. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  486. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  487. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  488. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  489. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  490. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  491. -
  492. -
  493. -// Headers
  494. -#include "Output.h"
  495. -
  496. -#include "Typedefs.h"
  497. -#include "Particles/ParticleArray.h"
  498. -#include "Particles/Particle.h"
  499. -
  500. -
  501. -// Constructor / Destructor
  502. -Output::Output( const ScrubberParam &param )
  503. -{
  504. - // FIXME: Cast to enum from integer (thanks to parameter parser sucking).
  505. - this->outputinfo = (OutputInfo) param.output.info;
  506. -
  507. - this->height = param.channel.height;
  508. - this->radius = param.channel.radius;
  509. - this->dx = param.channel.dx;
  510. -
  511. - this->param = param; // only needed for outputting cmdline options
  512. -}
  513. -
  514. -Output::~Output() {}
  515. -
  516. -
  517. -// Public Methods
  518. -void Output::writeToFile( double time, const ParticleArray &particles )
  519. -{
  520. - static bool first_call = true;
  521. -
  522. - switch ( outputinfo ) {
  523. - case OUTPUT_NOTHING:
  524. - // Do nothing.
  525. - break;
  526. - case OUTPUT_POSITIONS:
  527. - writePositions( first_call, time, particles );
  528. - break;
  529. - default:
  530. - std::cout << "ERROR: Unknown outputtype.";
  531. - break;
  532. - }
  533. - first_call = false;
  534. -}
  535. -
  536. diff --git a/src/Output/Output.h b/src/Output/Output.h
  537. deleted file mode 100644
  538. index 0df2c66..0000000
  539. --- a/src/Output/Output.h
  540. +++ /dev/null
  541. @@ -1,81 +0,0 @@
  542. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  543. -//
  544. -// Permission to use, copy, modify, and/or distribute this software for any
  545. -// purpose with or without fee is hereby granted, provided that the above
  546. -// copyright notice and this permission notice appear in all copies.
  547. -//
  548. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  549. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  550. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  551. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  552. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  553. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  554. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  555. -
  556. -#pragma once
  557. -
  558. -// Headers
  559. -#include <fstream>
  560. -
  561. -#include "Typedefs.h"
  562. -#include "Scrubber.h"
  563. -
  564. -
  565. -// Forward Declarations
  566. -class Channel;
  567. -class ParticleArray;
  568. -
  569. -
  570. -/**
  571. - * Abstract class for outputting.
  572. - */
  573. -class Output
  574. -{
  575. -protected:
  576. - OutputInfo outputinfo;
  577. -
  578. - double height;
  579. - double radius;
  580. - double dx;
  581. -
  582. - FILE *f;
  583. -
  584. - ScrubberParam param; // To output the cmdline options to file when wanted.
  585. -
  586. -
  587. - /**
  588. - * Write the positions and concentration of particles to the file.
  589. - * @param first_call True if this function is first called.
  590. - * @param time Absolute time in seconds.
  591. - * @param particles Array of particles.
  592. - */
  593. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles ) = 0;
  594. -
  595. -public:
  596. - /**
  597. - * Constructor.
  598. - * @param param Struct of parameters.
  599. - */
  600. - Output( const ScrubberParam &param );
  601. -
  602. - /**
  603. - * Write the concentration of particles to the file.
  604. - * @param first_call True if this function is first called.
  605. - * @param particles Array of particles.
  606. - */
  607. - virtual ~Output();
  608. -
  609. - /**
  610. - * Write output to file.
  611. - * Based on the choice of the output type, it calls another function that actually writes.
  612. - * @param time Absolute time in seconds.
  613. - * @param particles Array of particles.
  614. - */
  615. - void writeToFile( double time, const ParticleArray &particles );
  616. -
  617. - /**
  618. - * Write the velocity profile to file.
  619. - * @param scalar_field ScalarField containting the velocity profile.
  620. - */
  621. - virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
  622. -};
  623. diff --git a/src/Output/TextOutput.cpp b/src/Output/TextOutput.cpp
  624. deleted file mode 100644
  625. index cf2a7cd..0000000
  626. --- a/src/Output/TextOutput.cpp
  627. +++ /dev/null
  628. @@ -1,73 +0,0 @@
  629. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  630. -//
  631. -// Permission to use, copy, modify, and/or distribute this software for any
  632. -// purpose with or without fee is hereby granted, provided that the above
  633. -// copyright notice and this permission notice appear in all copies.
  634. -//
  635. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  636. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  637. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  638. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  639. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  640. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  641. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  642. -
  643. -
  644. -// Headers
  645. -#include "TextOutput.h"
  646. -
  647. -#include "Particles/ParticleArray.h"
  648. -#include "Particles/Particle.h"
  649. -
  650. -
  651. -// Constructor / Destructor
  652. -TextOutput::TextOutput( const ScrubberParam &param ) :
  653. - Output( param )
  654. -{
  655. - if ( param.output.info != OUTPUT_NOTHING )
  656. - {
  657. - f = fopen( param.output.path.c_str(), "w" );
  658. -
  659. - if ( !f ) {
  660. - printf( "Error in opening output file, exiting\n" );
  661. - exit( 1 );
  662. - }
  663. - }
  664. -}
  665. -
  666. -TextOutput::~TextOutput()
  667. -{
  668. - if ( param.output.info != OUTPUT_NOTHING )
  669. - fclose(f);
  670. -}
  671. -
  672. -
  673. -// Private Methods
  674. -inline void TextOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
  675. -{
  676. - if ( first_call )
  677. - fprintf( f, "#T X Y C\n" );
  678. -
  679. - for ( int i = 0; i < particles.getLength(); i++ )
  680. - {
  681. - // Readability
  682. - const Vector2d & pos = particles.getParticle( i ).getPos();
  683. -
  684. - // Write output to file
  685. - fprintf( f, "%e %e %e\n",
  686. - time, pos(0), pos(1) );
  687. - }
  688. - fprintf( f, "\n" );
  689. -}
  690. -
  691. -
  692. -// Public Methods
  693. -void TextOutput::writeScalarField( const ScalarField &scalar_field )
  694. -{
  695. - // Write header
  696. - fprintf( f, "dx = %e, radius = %e, n+2 = %d\n", dx, radius, scalar_field.shape()(0) );
  697. -
  698. - // Write the scalar values to file.
  699. - for ( int i = 0; i < scalar_field.shape()(0); i++ )
  700. - fprintf( f, "%e\n", scalar_field(i) );
  701. -}
  702. \ No newline at end of file
  703. diff --git a/src/Output/TextOutput.h b/src/Output/TextOutput.h
  704. deleted file mode 100644
  705. index a2f7e98..0000000
  706. --- a/src/Output/TextOutput.h
  707. +++ /dev/null
  708. @@ -1,46 +0,0 @@
  709. -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
  710. -//
  711. -// Permission to use, copy, modify, and/or distribute this software for any
  712. -// purpose with or without fee is hereby granted, provided that the above
  713. -// copyright notice and this permission notice appear in all copies.
  714. -//
  715. -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  716. -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  717. -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  718. -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  719. -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  720. -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  721. -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  722. -
  723. -#pragma once
  724. -
  725. -// Headers
  726. -#include "Output.h"
  727. -
  728. -#include "Scrubber.h"
  729. -#include "Typedefs.h"
  730. -
  731. -
  732. -/**
  733. - * Writes to the output in humanly readable text form.
  734. - */
  735. -class TextOutput : public Output
  736. -{
  737. -protected:
  738. - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
  739. -
  740. -public:
  741. - /**
  742. - * Constructor.
  743. - * @param param Struct of parameters.
  744. - */
  745. - TextOutput( const ScrubberParam &param );
  746. -
  747. - /**
  748. - * Destructor.
  749. - */
  750. - virtual ~TextOutput();
  751. -
  752. - //FIXME: Should be private.
  753. - virtual void writeScalarField( const ScalarField &scalar_field );
  754. -};
  755. \ No newline at end of file
  756. diff --git a/src/Scrubber.cpp b/src/Scrubber.cpp
  757. index 306cfcb..81a8cbe 100644
  758. --- a/src/Scrubber.cpp
  759. +++ b/src/Scrubber.cpp
  760. @@ -20,9 +20,9 @@
  761.  
  762. #include "getopt_pp.h"
  763.  
  764. -#include "Output/Output.h"
  765. -#include "Output/ByteOutput.h"
  766. -#include "Output/TextOutput.h"
  767. +#include "InOut/InOut.h"
  768. +#include "InOut/ByteInOut.h"
  769. +#include "InOut/TextInOut.h"
  770.  
  771. #include "Emitter/Emitter.h"
  772. #include "Emitter/GridEmitter.h"
  773. @@ -56,15 +56,39 @@ int main( int argc, char* argv[] )
  774. parse( argc, argv, &param );
  775. printParam( param );
  776.  
  777. - // Making the Output
  778. - Output * output;
  779. + ScalarField u;
  780. +
  781. + if ( param.input.format > INPUT_NOTHING )
  782. + {
  783. + // Making the input reader and read the velocity profile
  784. + InOut * input;
  785. +
  786. + switch ( param.input.format ) {
  787. + case INPUT_BYTE:
  788. + input = new ByteInOut( param );
  789. + break;
  790. + case INPUT_TEXT:
  791. + input = new TextInOut( param );
  792. + break;
  793. + default:
  794. + cout << "Unknown output type.";
  795. + break;
  796. + }
  797. +
  798. + input->readProfile( &param, &u );
  799. +
  800. + delete input;
  801. + }
  802. +
  803. + // Making the outputter
  804. + InOut * output;
  805.  
  806. switch ( param.output.format ) {
  807. case OUTPUT_BYTE:
  808. - output = new ByteOutput( param );
  809. + output = new ByteInOut( param );
  810. break;
  811. case OUTPUT_TEXT:
  812. - output = new TextOutput( param );
  813. + output = new TextInOut( param );
  814. break;
  815. default:
  816. cout << "Unknown output type.";
  817. @@ -74,7 +98,10 @@ int main( int argc, char* argv[] )
  818. // Making the channel
  819. Channel *channel = new Channel( param );
  820.  
  821. - channel->init();
  822. + if ( param.input.format == INPUT_NOTHING )
  823. + channel->init();
  824. + else
  825. + channel->init( u );
  826.  
  827. if ( param.output.info == OUTPUT_VELFIELD )
  828. {
  829. @@ -203,6 +230,12 @@ void show_help()
  830. " --rate <double> (=100.0) Amount of particles emitted per second.\n"
  831. " --initvel <string> (=[0,0]) Particle's initial velocity in m/s.\n"
  832. "\n"
  833. + "Input Options:\n"
  834. + " --pformat <int> (=0) Profile formats:\n"
  835. + " 0: Calculate the profile.\n"
  836. + " 1: Byte\n"
  837. + " 2: Text\n"
  838. + " --profile <string> (=profile.data) Path to profile data (if --pformat > 0).\n"
  839. "Output Options:\n"
  840. " --oformat <int> (=1) Output formats:\n"
  841. " 1: Byte\n"
  842. @@ -267,6 +300,9 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
  843. >> Option( 'a', "dim", s_edim, "[-3:30:3,60:1:60]" )
  844. >> Option( 'a', "rate", param->emitter.rate, 100.0 )
  845. >> Option( 'a', "initvel", s_initvel, "[0,0]" );
  846. + // Input Options
  847. + ops >> Option( 'a', "pformat", param->input.format, (int) INPUT_NOTHING )
  848. + >> Option( 'a', "profile", param->input.path, "profile.data" );
  849. // Output Options
  850. ops >> Option( 'a', "oformat", param->output.format, (int) OUTPUT_BYTE )
  851. >> Option( 'a', "oinfo", param->output.info, (int) OUTPUT_NOTHING )
  852. @@ -301,7 +337,6 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
  853. param->maxparticles = param->emitter.p_N;
  854. }
  855.  
  856. -
  857. param->beta = param->p.density / param->fl.density;
  858.  
  859. param->tau_p = param->p.density * 4 * param->p.radius * param->p.radius / (18 * param->fl.nu);
  860. @@ -309,6 +344,18 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
  861.  
  862. param->dt = param->dtscale * param->tau_p;
  863.  
  864. + // Check if input file exists when needed:
  865. + if ( param->input.format > INPUT_NOTHING )
  866. + {
  867. + FILE *fpin;
  868. + if( (fpin = fopen(param->input.path.c_str(), "r")) == NULL )
  869. + {
  870. + printf("Problem opening profile file %s.\n", param->input.path.c_str());
  871. + exit( 1 );
  872. + }
  873. + fclose( fpin );
  874. + }
  875. +
  876. // Can't output more data than we have
  877. if ( param->output.interval < param->dt )
  878. {
  879. diff --git a/src/Scrubber.h b/src/Scrubber.h
  880. index 37e374c..837faad 100644
  881. --- a/src/Scrubber.h
  882. +++ b/src/Scrubber.h
  883. @@ -61,6 +61,13 @@ enum OutputInfo
  884. OUTPUT_VELFIELD
  885. };
  886.  
  887. +enum InputFormat
  888. +{
  889. + INPUT_NOTHING,
  890. + INPUT_BYTE,
  891. + INPUT_TEXT
  892. +};
  893. +
  894. enum OutputFormat
  895. {
  896. OUTPUT_BYTE = 1,
  897. @@ -152,6 +159,14 @@ struct ScrubberParam
  898. Vector2d init_velocity; /// Initial velocity the particles are emitted with.
  899. } emitter;
  900.  
  901. + // Input specific parameters
  902. + struct input
  903. + {
  904. + int format; /// <enum> Input type.
  905. + string path; /// Path to profile datafile.
  906. +
  907. + } input;
  908. +
  909. // Output specific parameters
  910. struct output
  911. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement