Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From e165b317a34b77ab98bd1bbcd4767f139a4b1fa8 Mon Sep 17 00:00:00 2001
- From: Pietje Bell <pietjebell@ana-chan.com>
- Date: Tue, 26 Jan 2010 17:08:39 +0100
- Subject: [PATCH] Add importing the channel profile from a file.
- Output files have a new file header, so it breaks backwards compatibility.
- Supported input files are the output files of the channel's velocity profile.
- ---
- Makefile | 2 +-
- build/vs2008/Scrubber.vcproj | 14 +++---
- src/Channel/Channel.cpp | 5 ++
- src/Channel/Channel.h | 9 +++-
- src/InOut/ByteInOut.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++
- src/InOut/ByteInOut.h | 49 ++++++++++++++++++
- src/InOut/InOut.cpp | 58 +++++++++++++++++++++
- src/InOut/InOut.h | 91 +++++++++++++++++++++++++++++++++
- src/InOut/TextInOut.cpp | 95 ++++++++++++++++++++++++++++++++++
- src/InOut/TextInOut.h | 48 +++++++++++++++++
- src/Output/ByteOutput.cpp | 91 ---------------------------------
- src/Output/ByteOutput.h | 47 -----------------
- src/Output/Output.cpp | 58 ---------------------
- src/Output/Output.h | 81 -----------------------------
- src/Output/TextOutput.cpp | 73 --------------------------
- src/Output/TextOutput.h | 46 -----------------
- src/Scrubber.cpp | 69 +++++++++++++++++++++----
- src/Scrubber.h | 13 ++++-
- 18 files changed, 543 insertions(+), 421 deletions(-)
- create mode 100644 src/InOut/ByteInOut.cpp
- create mode 100644 src/InOut/ByteInOut.h
- create mode 100644 src/InOut/InOut.cpp
- create mode 100644 src/InOut/InOut.h
- create mode 100644 src/InOut/TextInOut.cpp
- create mode 100644 src/InOut/TextInOut.h
- delete mode 100644 src/Output/ByteOutput.cpp
- delete mode 100644 src/Output/ByteOutput.h
- delete mode 100644 src/Output/Output.cpp
- delete mode 100644 src/Output/Output.h
- delete mode 100644 src/Output/TextOutput.cpp
- delete mode 100644 src/Output/TextOutput.h
- 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.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
- new file mode 100644
- index 0000000..3a11728
- --- /dev/null
- +++ b/src/InOut/ByteInOut.cpp
- @@ -0,0 +1,115 @@
- +// 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 "ByteInOut.h"
- +
- +#include "Particles/ParticleArray.h"
- +#include "Particles/Particle.h"
- +
- +
- +// Constructor / Destructor
- +ByteInOut::ByteInOut( const ScrubberParam ¶m ) :
- + InOut( 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 );
- + }
- +
- + // Write file type header
- + fwrite( ¶m.output.format, 4, 1, f );
- + }
- +}
- +
- +ByteInOut::~ByteInOut()
- +{
- + if ( param.output.info != OUTPUT_NOTHING )
- + fclose( f );
- +}
- +
- +
- +// Private Methods
- +inline void ByteInOut::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 ByteInOut::writeScalarField( const ScalarField &scalar_field )
- +{
- + // Write header
- + double buf1[] = { dx, radius };
- + fwrite( buf1, 8, 2, f );
- +
- + int buf2[] = { n };
- + 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 );
- + }
- +}
- +
- +void ByteInOut::readProfile( ScrubberParam *param, ScalarField *u )
- +{
- + FILE *f = fopen( param->input.path.c_str(), "rb" );
- + // Skip the file type header
- + fseek ( f , 4 , SEEK_SET );
- +
- + // Read the channel 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
- new file mode 100644
- index 0000000..111976a
- --- /dev/null
- +++ b/src/InOut/ByteInOut.h
- @@ -0,0 +1,49 @@
- +// 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 "InOut.h"
- +
- +#include "Scrubber.h"
- +#include "Typedefs.h"
- +
- +
- +/**
- + * Writes to the output in binary form, and reads input from an identically formatted binary file.
- + */
- +class ByteInOut : public InOut
- +{
- +protected:
- + virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
- +
- +public:
- + /**
- + * Constructor.
- + * @param param Struct of parameters.
- + */
- + ByteInOut( const ScrubberParam ¶m );
- +
- + /**
- + * Destructor.
- + */
- + virtual ~ByteInOut();
- +
- + //FIXME: Should be private.
- + virtual void writeScalarField( const ScalarField &scalar_field );
- +
- + virtual void readProfile( ScrubberParam *param, ScalarField *u );
- +};
- diff --git a/src/InOut/InOut.cpp b/src/InOut/InOut.cpp
- new file mode 100644
- index 0000000..220f5eb
- --- /dev/null
- +++ b/src/InOut/InOut.cpp
- @@ -0,0 +1,58 @@
- +// 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 "InOut.h"
- +
- +#include "Typedefs.h"
- +#include "Particles/ParticleArray.h"
- +#include "Particles/Particle.h"
- +
- +
- +// Constructor / Destructor
- +InOut::InOut( 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->n = param.channel.n;
- +
- + this->param = param; // only needed for outputting cmdline options
- +}
- +
- +InOut::~InOut() {}
- +
- +
- +// Public Methods
- +void InOut::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/InOut/InOut.h b/src/InOut/InOut.h
- new file mode 100644
- index 0000000..1fc5af3
- --- /dev/null
- +++ b/src/InOut/InOut.h
- @@ -0,0 +1,91 @@
- +// 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 reading and writing to and from files.
- + */
- +class InOut
- +{
- +protected:
- + OutputInfo outputinfo;
- +
- + double height;
- + double radius;
- + double dx;
- + int n;
- +
- + 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.
- + */
- + InOut( 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 ~InOut();
- +
- + /**
- + * 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).
- +
- + /**
- + * 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
- new file mode 100644
- index 0000000..95d7953
- --- /dev/null
- +++ b/src/InOut/TextInOut.cpp
- @@ -0,0 +1,95 @@
- +// 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 "TextInOut.h"
- +
- +#include "Particles/ParticleArray.h"
- +#include "Particles/Particle.h"
- +
- +
- +// Constructor / Destructor
- +TextInOut::TextInOut( const ScrubberParam ¶m ) :
- + InOut( 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 );
- + }
- +
- + // Write file type header
- + fwrite( ¶m.output.format, 4, 1, f );
- + }
- +}
- +
- +TextInOut::~TextInOut()
- +{
- + if ( param.output.info != OUTPUT_NOTHING )
- + fclose(f);
- +}
- +
- +
- +// Private Methods
- +inline void TextInOut::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 TextInOut::writeScalarField( const ScalarField &scalar_field )
- +{
- + // Write header
- + 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) );
- +}
- +
- +void TextInOut::readProfile( ScrubberParam *param, ScalarField *u )
- +{
- + FILE *f = fopen( param->input.path.c_str(), "r" );
- + // Skip the file type header
- + fseek ( f , 4 , SEEK_SET );
- +
- + // Read the channel 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
- new file mode 100644
- index 0000000..b629e28
- --- /dev/null
- +++ b/src/InOut/TextInOut.h
- @@ -0,0 +1,48 @@
- +// 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 "InOut.h"
- +
- +#include "Scrubber.h"
- +#include "Typedefs.h"
- +
- +
- +/**
- + * Writes to the output in humanly readable text form, and reads input from an identically formatted text file.
- + */
- +class TextInOut : public InOut
- +{
- +protected:
- + virtual void writePositions( bool first_call, double time, const ParticleArray &particles );
- +
- +public:
- + /**
- + * Constructor.
- + * @param param Struct of parameters.
- + */
- + TextInOut( const ScrubberParam ¶m );
- +
- + /**
- + * Destructor.
- + */
- + virtual ~TextInOut();
- +
- + //FIXME: Should be private.
- + virtual void writeScalarField( const ScalarField &scalar_field );
- +
- + 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..35e0fff 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,50 @@ int main( int argc, char* argv[] )
- parse( argc, argv, ¶m );
- printParam( param );
- - // Making the Output
- - Output * output;
- + ScalarField u;
- +
- + if ( param.input.path != "" )
- + {
- + FILE *f;
- + if( (f = fopen( param.input.path.c_str(), "r" )) == NULL )
- + {
- + printf("Problem opening profile file %s.\n", param.input.path.c_str());
- + exit( 1 );
- + }
- +
- + // Read the file type
- + fread( ¶m.input.format, 4, 1, f );
- + fclose( f );
- +
- + // Making the input reader and read the velocity profile
- + InOut * input;
- +
- + switch ( param.input.format ) {
- + case INOUT_BYTE:
- + input = new ByteInOut( param );
- + break;
- + case INOUT_TEXT:
- + input = new TextInOut( param );
- + break;
- + default:
- + cout << "Unknown input type.";
- + break;
- + }
- +
- + input->readProfile( ¶m, &u );
- +
- + delete input;
- + }
- +
- + // Making the output writer
- + InOut * output;
- switch ( param.output.format ) {
- - case OUTPUT_BYTE:
- - output = new ByteOutput( param );
- + case INOUT_BYTE:
- + output = new ByteInOut( param );
- break;
- - case OUTPUT_TEXT:
- - output = new TextOutput( param );
- + case INOUT_TEXT:
- + output = new TextInOut( param );
- break;
- default:
- cout << "Unknown output type.";
- @@ -74,7 +109,10 @@ int main( int argc, char* argv[] )
- // Making the channel
- Channel *channel = new Channel( param );
- - channel->init();
- + if ( param.input.path == "" )
- + channel->init();
- + else
- + channel->init( u );
- if ( param.output.info == OUTPUT_VELFIELD )
- {
- @@ -203,6 +241,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> (=\"\") Path to profile data (if --pformat > 0).\n"
- "Output Options:\n"
- " --oformat <int> (=1) Output formats:\n"
- " 1: Byte\n"
- @@ -267,8 +311,10 @@ 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', "profile", param->input.path, "" );
- // Output Options
- - ops >> Option( 'a', "oformat", param->output.format, (int) OUTPUT_BYTE )
- + ops >> Option( 'a', "oformat", param->output.format, (int) INOUT_BYTE )
- >> Option( 'a', "oinfo", param->output.info, (int) OUTPUT_NOTHING )
- >> Option( 'a', "oint", param->output.interval, 1.0 )
- >> Option( 'a', "out", param->output.path, "test.data" );
- @@ -301,7 +347,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);
- diff --git a/src/Scrubber.h b/src/Scrubber.h
- index 37e374c..304e355 100644
- --- a/src/Scrubber.h
- +++ b/src/Scrubber.h
- @@ -61,10 +61,10 @@ enum OutputInfo
- OUTPUT_VELFIELD
- };
- -enum OutputFormat
- +enum InOutFormat
- {
- - OUTPUT_BYTE = 1,
- - OUTPUT_TEXT
- + INOUT_BYTE = 1,
- + INOUT_TEXT
- };
- enum EmitterType
- @@ -152,6 +152,13 @@ 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
- {
- --
- 1.6.5.1.1367.gcd48
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement