Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Makefile b/Makefile
- index bed4fd8..0d5b138 100644
- --- a/Makefile
- +++ b/Makefile
- @@ -5,7 +5,7 @@ SRCS = ./external/getopt_pp.cpp \
- ./src/Channel/CPModel.cpp ./src/Channel/Channel.cpp \
- ./src/Particles/Mover.cpp \
- ./src/Emitter/Emitter.cpp ./src/Emitter/GridEmitter.cpp ./src/Emitter/GridOnceEmitter.cpp ./src/Emitter/RandomEmitter.cpp \
- - ./src/Output/Output.cpp ./src/Output/ByteOutput.cpp ./src/Output/TextOutput.cpp \
- + ./src/InOut/InOut.cpp ./src/InOut/ByteInOut.cpp ./src/InOut/TextInOut.cpp \
- ./src/Scrubber.cpp
- CXXFLAGS = -O2 -DNDEBUG
- diff --git a/build/vs2008/Scrubber.sln b/build/vs2008/Scrubber.sln
- index eb51992..f01406e 100644
- --- a/build/vs2008/Scrubber.sln
- +++ b/build/vs2008/Scrubber.sln
- @@ -1,6 +1,7 @@
- +
- Microsoft Visual Studio Solution File, Format Version 10.00
- # Visual Studio 2008
- -Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "Scrubber", "Scrubber.icproj", "{ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}"
- +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scrubber", "Scrubber.vcproj", "{D4423193-7F06-45F2-BD8A-AEFF115699D4}"
- EndProject
- Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- @@ -12,30 +13,18 @@ Global
- ReleaseIntel|x64 = ReleaseIntel|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|Win32.ActiveCfg = Debug|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|Win32.Build.0 = Debug|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|x64.ActiveCfg = Debug|x64
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Debug|x64.Build.0 = Debug|x64
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|Win32.ActiveCfg = Release|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|Win32.Build.0 = Release|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|x64.ActiveCfg = Release|x64
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.Release|x64.Build.0 = Release|x64
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
- - {ED04EEF8-DA35-43D7-AE2B-5FA7BD91E055}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.Build.0 = Release|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.ActiveCfg = Release|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.Build.0 = Release|Win32
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.ActiveCfg = Release|Win32
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.Build.0 = Debug|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.ActiveCfg = Debug|x64
- - {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.Build.0 = Debug|Win32
- {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.ActiveCfg = Debug|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|Win32.Build.0 = Debug|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.ActiveCfg = Debug|x64
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Debug|x64.Build.0 = Debug|x64
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.ActiveCfg = Release|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|Win32.Build.0 = Release|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.ActiveCfg = Release|x64
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.Release|x64.Build.0 = Release|x64
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.ActiveCfg = ReleaseIntel|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|Win32.Build.0 = ReleaseIntel|Win32
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.ActiveCfg = ReleaseIntel|x64
- + {D4423193-7F06-45F2-BD8A-AEFF115699D4}.ReleaseIntel|x64.Build.0 = ReleaseIntel|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- diff --git a/build/vs2008/Scrubber.vcproj b/build/vs2008/Scrubber.vcproj
- index f700a04..4abb59b 100644
- --- a/build/vs2008/Scrubber.vcproj
- +++ b/build/vs2008/Scrubber.vcproj
- @@ -537,30 +537,30 @@
- </File>
- </Filter>
- <Filter
- - Name="Output"
- + Name="InOut"
- >
- <File
- - RelativePath="..\..\src\Output\ByteOutput.cpp"
- + RelativePath="..\..\src\InOut\ByteInOut.cpp"
- >
- </File>
- <File
- - RelativePath="..\..\src\Output\ByteOutput.h"
- + RelativePath="..\..\src\InOut\ByteInOut.h"
- >
- </File>
- <File
- - RelativePath="..\..\src\Output\Output.cpp"
- + RelativePath="..\..\src\InOut\InOut.cpp"
- >
- </File>
- <File
- - RelativePath="..\..\src\Output\Output.h"
- + RelativePath="..\..\src\InOut\InOut.h"
- >
- </File>
- <File
- - RelativePath="..\..\src\Output\TextOutput.cpp"
- + RelativePath="..\..\src\InOut\TextInOut.cpp"
- >
- </File>
- <File
- - RelativePath="..\..\src\Output\TextOutput.h"
- + RelativePath="..\..\src\InOut\TextInOut.h"
- >
- </File>
- </Filter>
- diff --git a/src/Channel/Channel.cpp b/src/Channel/Channel.cpp
- index 9c2bff3..bf22ecc 100644
- --- a/src/Channel/Channel.cpp
- +++ b/src/Channel/Channel.cpp
- @@ -81,6 +81,11 @@ void Channel::init()
- u = cpmodel->init( u );
- }
- +void Channel::init( const ScalarField &u )
- +{
- + this->u = u;
- +}
- +
- PosBox Channel::outsideBox( const Vector2d &pos )
- {
- if ( pos(1) >= height )
- diff --git a/src/Channel/Channel.h b/src/Channel/Channel.h
- index 6983240..dc06f4c 100644
- --- a/src/Channel/Channel.h
- +++ b/src/Channel/Channel.h
- @@ -69,12 +69,17 @@ public:
- virtual ~Channel();
- /**
- - * Initialize the channel.
- - * Generates the velocity profile in the channel by looping until steady.
- + * Initialize the channel by calculating the velocity profile.
- */
- void init();
- /**
- + * Initialize the channel by copying in an existing velocity profile.
- + * @param u The ScalarField to be used as the velocity profile.
- + */
- + void init( const ScalarField &u );
- +
- + /**
- * Checks if the particle has left the box on the sides, top, bottom or is still in the box.
- * @param pos Position of the particle.
- * @return An enum indicating where the particle is at.
- diff --git a/src/InOut/ByteInOut.cpp b/src/InOut/ByteInOut.cpp
- index 908a576..3f749ae 100644
- --- a/src/InOut/ByteInOut.cpp
- +++ b/src/InOut/ByteInOut.cpp
- @@ -79,7 +79,7 @@ void ByteInOut::writeScalarField( const ScalarField &scalar_field )
- double buf1[] = { dx, radius };
- fwrite( buf1, 8, 2, f );
- - int buf2[] = { scalar_field.shape()(0) };
- + int buf2[] = { n };
- fwrite( buf2, 4, 1, f );
- // Write the scalar values to file.
- @@ -88,4 +88,23 @@ void ByteInOut::writeScalarField( const ScalarField &scalar_field )
- double buf3[] = { scalar_field(i) };
- fwrite( buf3, 8, 1, f );
- }
- -}
- \ No newline at end of file
- +}
- +
- +void ByteInOut::readProfile( ScrubberParam *param, ScalarField *u )
- +{
- + FILE *f = fopen( param->input.path.c_str(), "rb" );
- +
- + // Read the header
- + fread( ¶m->channel.dx, 8, 1, f );
- + fread( ¶m->channel.radius, 8, 1, f );
- + fread( ¶m->channel.n, 4, 1, f );
- +
- + u->resize( param->channel.n + 2 );
- +
- + // FIXME: Check if the lenght of the file is sufficient
- + // FIXME: Is there a way to not write the elements iteratively?
- + for( int i = 0; i < u->shape()(0); i++ )
- + fread( &(*u)(i), 8, 1, f );
- +
- + fclose( f );
- +}
- diff --git a/src/InOut/ByteInOut.h b/src/InOut/ByteInOut.h
- index 265f0b9..111976a 100644
- --- a/src/InOut/ByteInOut.h
- +++ b/src/InOut/ByteInOut.h
- @@ -23,7 +23,7 @@
- /**
- - * Writes to the output in binary form.
- + * Writes to the output in binary form, and reads input from an identically formatted binary file.
- */
- class ByteInOut : public InOut
- {
- @@ -44,4 +44,6 @@ public:
- //FIXME: Should be private.
- virtual void writeScalarField( const ScalarField &scalar_field );
- -};
- \ No newline at end of file
- +
- + virtual void readProfile( ScrubberParam *param, ScalarField *u );
- +};
- diff --git a/src/InOut/InOut.cpp b/src/InOut/InOut.cpp
- index 0c438be..220f5eb 100644
- --- a/src/InOut/InOut.cpp
- +++ b/src/InOut/InOut.cpp
- @@ -30,6 +30,7 @@ InOut::InOut( const ScrubberParam ¶m )
- this->height = param.channel.height;
- this->radius = param.channel.radius;
- this->dx = param.channel.dx;
- + this->n = param.channel.n;
- this->param = param; // only needed for outputting cmdline options
- }
- @@ -55,4 +56,3 @@ void InOut::writeToFile( double time, const ParticleArray &particles )
- }
- first_call = false;
- }
- -
- diff --git a/src/InOut/InOut.h b/src/InOut/InOut.h
- index bc3668c..1fc5af3 100644
- --- a/src/InOut/InOut.h
- +++ b/src/InOut/InOut.h
- @@ -27,7 +27,7 @@ class ParticleArray;
- /**
- - * Abstract class for outputting.
- + * Abstract class for reading and writing to and from files.
- */
- class InOut
- {
- @@ -37,6 +37,7 @@ protected:
- double height;
- double radius;
- double dx;
- + int n;
- FILE *f;
- @@ -78,4 +79,13 @@ public:
- * @param scalar_field ScalarField containting the velocity profile.
- */
- virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
- +
- + /**
- + * Read the velocity profile information from a file.
- + * In the process, read the amount of gridpoints and the stepsizes,
- + * and write these to the parameter struct.
- + * @param *param Struct of parameters.
- + * @param *u ScalarField to write the velocities to.
- + */
- + virtual void readProfile( ScrubberParam *param, ScalarField *u ) = 0;
- };
- diff --git a/src/InOut/TextInOut.cpp b/src/InOut/TextInOut.cpp
- index 2ff43e2..5a1546f 100644
- --- a/src/InOut/TextInOut.cpp
- +++ b/src/InOut/TextInOut.cpp
- @@ -65,9 +65,26 @@ inline void TextInOut::writePositions( bool first_call, double time, const Parti
- void TextInOut::writeScalarField( const ScalarField &scalar_field )
- {
- // Write header
- - fprintf( f, "dx = %e, radius = %e, n+2 = %d\n", dx, radius, scalar_field.shape()(0) );
- + fprintf( f, "dx = %e, radius = %e, n = %d\n", dx, radius, n );
- // Write the scalar values to file.
- for ( int i = 0; i < scalar_field.shape()(0); i++ )
- fprintf( f, "%e\n", scalar_field(i) );
- -}
- \ No newline at end of file
- +}
- +
- +void TextInOut::readProfile( ScrubberParam *param, ScalarField *u )
- +{
- + FILE *f = fopen( param->input.path.c_str(), "r" );
- +
- + // Read the header
- + fscanf( f, "dx = %lf, radius = %lf, n = %d\n", ¶m->channel.dx, ¶m->channel.radius, ¶m->channel.n );
- +
- + u->resize( param->channel.n + 2 );
- +
- + // FIXME: Check if the lenght of the file is sufficient
- + // FIXME: Is there a way to not write the elements iteratively?
- + for( int i = 0; i < u->shape()(0); i++ )
- + fscanf( f, "%lf\n", &(*u)(i) );
- +
- + fclose( f );
- +}
- diff --git a/src/InOut/TextInOut.h b/src/InOut/TextInOut.h
- index b200aa5..b629e28 100644
- --- a/src/InOut/TextInOut.h
- +++ b/src/InOut/TextInOut.h
- @@ -22,7 +22,7 @@
- /**
- - * Writes to the output in humanly readable text form.
- + * Writes to the output in humanly readable text form, and reads input from an identically formatted text file.
- */
- class TextInOut : public InOut
- {
- @@ -43,4 +43,6 @@ public:
- //FIXME: Should be private.
- virtual void writeScalarField( const ScalarField &scalar_field );
- -};
- \ No newline at end of file
- +
- + virtual void readProfile( ScrubberParam *param, ScalarField *u );
- +};
- diff --git a/src/Output/ByteOutput.cpp b/src/Output/ByteOutput.cpp
- deleted file mode 100644
- index 5ddc620..0000000
- --- a/src/Output/ByteOutput.cpp
- +++ /dev/null
- @@ -1,91 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -
- -// Headers
- -#include "ByteOutput.h"
- -
- -#include "Particles/ParticleArray.h"
- -#include "Particles/Particle.h"
- -
- -
- -// Constructor / Destructor
- -ByteOutput::ByteOutput( const ScrubberParam ¶m ) :
- - Output( param )
- -{
- - if ( param.output.info != OUTPUT_NOTHING )
- - {
- - f = fopen( param.output.path.c_str(), "wb" );
- -
- - if ( !f ) {
- - printf( "Error in opening output file, exiting\n" );
- - exit( 1 );
- - }
- - }
- -}
- -
- -ByteOutput::~ByteOutput()
- -{
- - if ( param.output.info != OUTPUT_NOTHING )
- - fclose( f );
- -}
- -
- -
- -// Private Methods
- -inline void ByteOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
- -{
- - if ( first_call )
- - {
- - // Write the and delimiter values to file.
- - // i.e. buf[] = { xmin, xmax, ymin, ymax, zmin, zmax }
- - double buf[] = { radius, height };
- - fwrite( buf, 8, 2, f );
- - }
- -
- - // Frame data
- - double buf1[] = { time };
- - fwrite( buf1, 8, 1, f );
- -
- - int buf2[] = { particles.getLength() };
- - fwrite( buf2, 4, 1, f );
- -
- - // Write data
- - for ( int i = 0; i < particles.getLength(); i++ )
- - {
- - // Readability
- - const Vector2d & pos = particles.getParticle( i ).getPos();
- -
- - double buf[] = { pos(0), pos(1) };
- - fwrite( buf, 8, 2, f );
- - }
- -}
- -
- -
- -// Public Methods
- -void ByteOutput::writeScalarField( const ScalarField &scalar_field )
- -{
- - // Write header
- - double buf1[] = { dx, radius };
- - fwrite( buf1, 8, 2, f );
- -
- - int buf2[] = { scalar_field.shape()(0) };
- - fwrite( buf2, 4, 1, f );
- -
- - // Write the scalar values to file.
- - for ( int i = 0; i < scalar_field.shape()(0); i++ )
- - {
- - double buf3[] = { scalar_field(i) };
- - fwrite( buf3, 8, 1, f );
- - }
- -}
- \ No newline at end of file
- diff --git a/src/Output/ByteOutput.h b/src/Output/ByteOutput.h
- deleted file mode 100644
- index 69bba92..0000000
- --- a/src/Output/ByteOutput.h
- +++ /dev/null
- @@ -1,47 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -#pragma once
- -
- -// Headers
- -#include <fstream>
- -#include "Output.h"
- -
- -#include "Scrubber.h"
- -#include "Typedefs.h"
- -
- -
- -/**
- - * Writes to the output in binary form.
- - */
- -class ByteOutput : public Output
- -{
- -protected:
- - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
- -
- -public:
- - /**
- - * Constructor.
- - * @param param Struct of parameters.
- - */
- - ByteOutput( const ScrubberParam ¶m );
- -
- - /**
- - * Destructor.
- - */
- - virtual ~ByteOutput();
- -
- - //FIXME: Should be private.
- - virtual void writeScalarField( const ScalarField &scalar_field );
- -};
- \ No newline at end of file
- diff --git a/src/Output/Output.cpp b/src/Output/Output.cpp
- deleted file mode 100644
- index 28cd1b9..0000000
- --- a/src/Output/Output.cpp
- +++ /dev/null
- @@ -1,58 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -
- -// Headers
- -#include "Output.h"
- -
- -#include "Typedefs.h"
- -#include "Particles/ParticleArray.h"
- -#include "Particles/Particle.h"
- -
- -
- -// Constructor / Destructor
- -Output::Output( const ScrubberParam ¶m )
- -{
- - // FIXME: Cast to enum from integer (thanks to parameter parser sucking).
- - this->outputinfo = (OutputInfo) param.output.info;
- -
- - this->height = param.channel.height;
- - this->radius = param.channel.radius;
- - this->dx = param.channel.dx;
- -
- - this->param = param; // only needed for outputting cmdline options
- -}
- -
- -Output::~Output() {}
- -
- -
- -// Public Methods
- -void Output::writeToFile( double time, const ParticleArray &particles )
- -{
- - static bool first_call = true;
- -
- - switch ( outputinfo ) {
- - case OUTPUT_NOTHING:
- - // Do nothing.
- - break;
- - case OUTPUT_POSITIONS:
- - writePositions( first_call, time, particles );
- - break;
- - default:
- - std::cout << "ERROR: Unknown outputtype.";
- - break;
- - }
- - first_call = false;
- -}
- -
- diff --git a/src/Output/Output.h b/src/Output/Output.h
- deleted file mode 100644
- index 0df2c66..0000000
- --- a/src/Output/Output.h
- +++ /dev/null
- @@ -1,81 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -#pragma once
- -
- -// Headers
- -#include <fstream>
- -
- -#include "Typedefs.h"
- -#include "Scrubber.h"
- -
- -
- -// Forward Declarations
- -class Channel;
- -class ParticleArray;
- -
- -
- -/**
- - * Abstract class for outputting.
- - */
- -class Output
- -{
- -protected:
- - OutputInfo outputinfo;
- -
- - double height;
- - double radius;
- - double dx;
- -
- - FILE *f;
- -
- - ScrubberParam param; // To output the cmdline options to file when wanted.
- -
- -
- - /**
- - * Write the positions and concentration of particles to the file.
- - * @param first_call True if this function is first called.
- - * @param time Absolute time in seconds.
- - * @param particles Array of particles.
- - */
- - virtual void writePositions( bool first_call, double time, const ParticleArray &particles ) = 0;
- -
- -public:
- - /**
- - * Constructor.
- - * @param param Struct of parameters.
- - */
- - Output( const ScrubberParam ¶m );
- -
- - /**
- - * Write the concentration of particles to the file.
- - * @param first_call True if this function is first called.
- - * @param particles Array of particles.
- - */
- - virtual ~Output();
- -
- - /**
- - * Write output to file.
- - * Based on the choice of the output type, it calls another function that actually writes.
- - * @param time Absolute time in seconds.
- - * @param particles Array of particles.
- - */
- - void writeToFile( double time, const ParticleArray &particles );
- -
- - /**
- - * Write the velocity profile to file.
- - * @param scalar_field ScalarField containting the velocity profile.
- - */
- - virtual void writeScalarField( const ScalarField &scalar_field ) = 0; //FIXME: Should be private (and callable from writeToFile).
- -};
- diff --git a/src/Output/TextOutput.cpp b/src/Output/TextOutput.cpp
- deleted file mode 100644
- index cf2a7cd..0000000
- --- a/src/Output/TextOutput.cpp
- +++ /dev/null
- @@ -1,73 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -
- -// Headers
- -#include "TextOutput.h"
- -
- -#include "Particles/ParticleArray.h"
- -#include "Particles/Particle.h"
- -
- -
- -// Constructor / Destructor
- -TextOutput::TextOutput( const ScrubberParam ¶m ) :
- - Output( param )
- -{
- - if ( param.output.info != OUTPUT_NOTHING )
- - {
- - f = fopen( param.output.path.c_str(), "w" );
- -
- - if ( !f ) {
- - printf( "Error in opening output file, exiting\n" );
- - exit( 1 );
- - }
- - }
- -}
- -
- -TextOutput::~TextOutput()
- -{
- - if ( param.output.info != OUTPUT_NOTHING )
- - fclose(f);
- -}
- -
- -
- -// Private Methods
- -inline void TextOutput::writePositions( bool first_call, double time, const ParticleArray &particles )
- -{
- - if ( first_call )
- - fprintf( f, "#T X Y C\n" );
- -
- - for ( int i = 0; i < particles.getLength(); i++ )
- - {
- - // Readability
- - const Vector2d & pos = particles.getParticle( i ).getPos();
- -
- - // Write output to file
- - fprintf( f, "%e %e %e\n",
- - time, pos(0), pos(1) );
- - }
- - fprintf( f, "\n" );
- -}
- -
- -
- -// Public Methods
- -void TextOutput::writeScalarField( const ScalarField &scalar_field )
- -{
- - // Write header
- - fprintf( f, "dx = %e, radius = %e, n+2 = %d\n", dx, radius, scalar_field.shape()(0) );
- -
- - // Write the scalar values to file.
- - for ( int i = 0; i < scalar_field.shape()(0); i++ )
- - fprintf( f, "%e\n", scalar_field(i) );
- -}
- \ No newline at end of file
- diff --git a/src/Output/TextOutput.h b/src/Output/TextOutput.h
- deleted file mode 100644
- index a2f7e98..0000000
- --- a/src/Output/TextOutput.h
- +++ /dev/null
- @@ -1,46 +0,0 @@
- -// Copyright (c) 2009, Pietje Bell <pietjebell@ana-chan.com>
- -//
- -// Permission to use, copy, modify, and/or distribute this software for any
- -// purpose with or without fee is hereby granted, provided that the above
- -// copyright notice and this permission notice appear in all copies.
- -//
- -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- -
- -#pragma once
- -
- -// Headers
- -#include "Output.h"
- -
- -#include "Scrubber.h"
- -#include "Typedefs.h"
- -
- -
- -/**
- - * Writes to the output in humanly readable text form.
- - */
- -class TextOutput : public Output
- -{
- -protected:
- - virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
- -
- -public:
- - /**
- - * Constructor.
- - * @param param Struct of parameters.
- - */
- - TextOutput( const ScrubberParam ¶m );
- -
- - /**
- - * Destructor.
- - */
- - virtual ~TextOutput();
- -
- - //FIXME: Should be private.
- - virtual void writeScalarField( const ScalarField &scalar_field );
- -};
- \ No newline at end of file
- diff --git a/src/Scrubber.cpp b/src/Scrubber.cpp
- index 306cfcb..81a8cbe 100644
- --- a/src/Scrubber.cpp
- +++ b/src/Scrubber.cpp
- @@ -20,9 +20,9 @@
- #include "getopt_pp.h"
- -#include "Output/Output.h"
- -#include "Output/ByteOutput.h"
- -#include "Output/TextOutput.h"
- +#include "InOut/InOut.h"
- +#include "InOut/ByteInOut.h"
- +#include "InOut/TextInOut.h"
- #include "Emitter/Emitter.h"
- #include "Emitter/GridEmitter.h"
- @@ -56,15 +56,39 @@ int main( int argc, char* argv[] )
- parse( argc, argv, ¶m );
- printParam( param );
- - // Making the Output
- - Output * output;
- + ScalarField u;
- +
- + if ( param.input.format > INPUT_NOTHING )
- + {
- + // Making the input reader and read the velocity profile
- + InOut * input;
- +
- + switch ( param.input.format ) {
- + case INPUT_BYTE:
- + input = new ByteInOut( param );
- + break;
- + case INPUT_TEXT:
- + input = new TextInOut( param );
- + break;
- + default:
- + cout << "Unknown output type.";
- + break;
- + }
- +
- + input->readProfile( ¶m, &u );
- +
- + delete input;
- + }
- +
- + // Making the outputter
- + InOut * output;
- switch ( param.output.format ) {
- case OUTPUT_BYTE:
- - output = new ByteOutput( param );
- + output = new ByteInOut( param );
- break;
- case OUTPUT_TEXT:
- - output = new TextOutput( param );
- + output = new TextInOut( param );
- break;
- default:
- cout << "Unknown output type.";
- @@ -74,7 +98,10 @@ int main( int argc, char* argv[] )
- // Making the channel
- Channel *channel = new Channel( param );
- - channel->init();
- + if ( param.input.format == INPUT_NOTHING )
- + channel->init();
- + else
- + channel->init( u );
- if ( param.output.info == OUTPUT_VELFIELD )
- {
- @@ -203,6 +230,12 @@ void show_help()
- " --rate <double> (=100.0) Amount of particles emitted per second.\n"
- " --initvel <string> (=[0,0]) Particle's initial velocity in m/s.\n"
- "\n"
- + "Input Options:\n"
- + " --pformat <int> (=0) Profile formats:\n"
- + " 0: Calculate the profile.\n"
- + " 1: Byte\n"
- + " 2: Text\n"
- + " --profile <string> (=profile.data) Path to profile data (if --pformat > 0).\n"
- "Output Options:\n"
- " --oformat <int> (=1) Output formats:\n"
- " 1: Byte\n"
- @@ -267,6 +300,9 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
- >> Option( 'a', "dim", s_edim, "[-3:30:3,60:1:60]" )
- >> Option( 'a', "rate", param->emitter.rate, 100.0 )
- >> Option( 'a', "initvel", s_initvel, "[0,0]" );
- + // Input Options
- + ops >> Option( 'a', "pformat", param->input.format, (int) INPUT_NOTHING )
- + >> Option( 'a', "profile", param->input.path, "profile.data" );
- // Output Options
- ops >> Option( 'a', "oformat", param->output.format, (int) OUTPUT_BYTE )
- >> Option( 'a', "oinfo", param->output.info, (int) OUTPUT_NOTHING )
- @@ -301,7 +337,6 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
- param->maxparticles = param->emitter.p_N;
- }
- -
- param->beta = param->p.density / param->fl.density;
- param->tau_p = param->p.density * 4 * param->p.radius * param->p.radius / (18 * param->fl.nu);
- @@ -309,6 +344,18 @@ void parse( int argc, char* argv[], ScrubberParam *param ) {
- param->dt = param->dtscale * param->tau_p;
- + // Check if input file exists when needed:
- + if ( param->input.format > INPUT_NOTHING )
- + {
- + FILE *fpin;
- + if( (fpin = fopen(param->input.path.c_str(), "r")) == NULL )
- + {
- + printf("Problem opening profile file %s.\n", param->input.path.c_str());
- + exit( 1 );
- + }
- + fclose( fpin );
- + }
- +
- // Can't output more data than we have
- if ( param->output.interval < param->dt )
- {
- diff --git a/src/Scrubber.h b/src/Scrubber.h
- index 37e374c..837faad 100644
- --- a/src/Scrubber.h
- +++ b/src/Scrubber.h
- @@ -61,6 +61,13 @@ enum OutputInfo
- OUTPUT_VELFIELD
- };
- +enum InputFormat
- +{
- + INPUT_NOTHING,
- + INPUT_BYTE,
- + INPUT_TEXT
- +};
- +
- enum OutputFormat
- {
- OUTPUT_BYTE = 1,
- @@ -152,6 +159,14 @@ struct ScrubberParam
- Vector2d init_velocity; /// Initial velocity the particles are emitted with.
- } emitter;
- + // Input specific parameters
- + struct input
- + {
- + int format; /// <enum> Input type.
- + string path; /// Path to profile datafile.
- +
- + } input;
- +
- // Output specific parameters
- struct output
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement