WriterRaw Class Reference

#include <WriterRaw.hpp>

Inheritance diagram for WriterRaw:

Inheritance graph
[legend]
Collaboration diagram for WriterRaw:

Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector
< ConstReferenceCounting
< FieldOfScalarFunction > > 
FieldList
typedef std::vector
< ConstReferenceCounting
< ScalarFunctionBase > > 
ScalarFunctionList

Public Member Functions

void proceed () const
 WriterRaw (ConstReferenceCounting< Mesh > mesh, const std::string &filename, const FileDescriptor &fileDescriptor)
 ~WriterRaw ()
void add (ConstReferenceCounting< ScalarFunctionBase > function)
void add (ConstReferenceCounting< FieldOfScalarFunction > field)

Protected Attributes

ConstReferenceCounting< Mesh__mesh
const std::string __filename
const FileDescriptor__fileDescriptor
const std::string __CR
FieldList __fieldList
ScalarFunctionList __scalarFunctionList

Private Member Functions

 WriterRaw (const WriterRaw &)
void __saveScalarFunction (std::ostream &file, const ScalarFunctionBase &f) const


Detailed Description

Definition at line 35 of file WriterRaw.hpp.


Member Typedef Documentation

Definition at line 44 of file WriterBase.hpp.

Definition at line 45 of file WriterBase.hpp.


Constructor & Destructor Documentation

WriterRaw::WriterRaw ( const WriterRaw  )  [private]

Copy constructor is forbidden

WriterRaw::WriterRaw ( ConstReferenceCounting< Mesh mesh,
const std::string &  filename,
const FileDescriptor fileDescriptor 
)

Constructor

Parameters:
mesh given mesh
filename name of the file to create
fileDescriptor describes file type

Definition at line 128 of file WriterRaw.cpp.

00131   : WriterBase(mesh,
00132                filename,
00133                fileDescriptor)
00134 {
00135   ;
00136 }

WriterRaw::~WriterRaw (  ) 

Destructor

Definition at line 139 of file WriterRaw.cpp.

00140 {
00141   ;
00142 }


Member Function Documentation

void WriterRaw::__saveScalarFunction ( std::ostream &  file,
const ScalarFunctionBase f 
) const [private]

Save scalar function to a file

Parameters:
file given file
f function to save

Definition at line 34 of file WriterRaw.cpp.

References WriterBase::__CR, WriterBase::__fileDescriptor, WriterBase::__mesh, FEMFunctionBase::baseMesh(), FileDescriptor::binary, FileDescriptor::dos, ScalarFunctionBase::femfunction, FileDescriptor::formatDefault, littleEndianize(), FileDescriptor::mac, FileDescriptor::type(), ScalarFunctionBase::type(), ErrorHandler::unexpected, and FileDescriptor::unices.

Referenced by proceed().

00036 {
00037   Vector<double> values(__mesh->numberOfVertices());
00038 
00039   switch (f.type()) {
00040   case ScalarFunctionBase::femfunction: {
00041     const FEMFunctionBase& fem
00042       = static_cast<const FEMFunctionBase&>(f);
00043     if (fem.baseMesh() == __mesh) {
00044       for (size_t i=0; i<values.size(); ++i) {
00045         values[i] = static_cast<double>(fem[i]);
00046       }
00047       break;
00048     } // if not continues the standard method
00049   }
00050   default: {
00051     for (size_t i=0; i<values.size(); ++i) {
00052       const TinyVector<3,real_t>& X = __mesh->vertex(i);
00053       values[i] = f(X);
00054     }
00055   }
00056   }
00057 
00058   switch (__fileDescriptor.type()) {
00059   case FileDescriptor::binary: {
00060 
00061 #ifdef WORDS_BIGENDIAN
00062     littleEndianize(values);
00063 #endif // WORDS_BIGENDIAN
00064 
00065     file.write(reinterpret_cast<char*>(&values[0]),
00066                values.size()*sizeof(double)/sizeof(char));
00067     break;
00068   }
00069   case FileDescriptor::formatDefault:
00070   case FileDescriptor::dos:
00071   case FileDescriptor::mac:
00072   case FileDescriptor::unices: {
00073     for (size_t i=0; i<values.size(); ++i) {
00074       file << values[i] << __CR;
00075     }
00076     break;
00077   }
00078   default: {
00079     throw ErrorHandler(__FILE__,__LINE__,
00080                        "unexpected file type",
00081                        ErrorHandler::unexpected);
00082   }
00083   }
00084 }

Here is the call graph for this function:

void WriterRaw::proceed (  )  const [virtual]

Save data in the file

Implements WriterBase.

Definition at line 88 of file WriterRaw.cpp.

References WriterBase::__fieldList, WriterBase::__filename, __saveScalarFunction(), WriterBase::__scalarFunctionList, FieldOfScalarFunction::function(), ErrorHandler::normal, FieldOfScalarFunction::numberOfComponents(), and stringify().

00089 {
00090   std::ofstream file(__filename.c_str());
00091   if (file.bad()) {
00092     throw ErrorHandler(__FILE__,__LINE__,
00093                        "cannot open file '"
00094                        +stringify(__filename)+"'",
00095                        ErrorHandler::normal);
00096   }
00097 
00098   if (__fieldList.size() + __scalarFunctionList.size() == 0) {
00099     throw ErrorHandler(__FILE__,__LINE__,
00100                        "cannot save mesh in raw format: '"
00101                        +stringify(__filename)+"'",
00102                        ErrorHandler::normal);
00103   }
00104 
00105   if (__fieldList.size() + __scalarFunctionList.size() > 1) {
00106     throw ErrorHandler(__FILE__,__LINE__,
00107                        "cannot save more than one field or function in raw format: '"
00108                        +stringify(__filename)+"'",
00109                        ErrorHandler::normal);
00110   }
00111 
00112   if (__fieldList.size() > 0) {
00113     const FieldOfScalarFunction& field = *__fieldList[0];
00114     for (size_t i = 0; i<field.numberOfComponents(); ++i) {
00115       const ScalarFunctionBase& f = *field.function(i);
00116       __saveScalarFunction(file,f);
00117     }
00118   }
00119 
00120   // Save scalar function
00121   if (__scalarFunctionList.size() > 0) {
00122     const ScalarFunctionBase& f = *__scalarFunctionList[0];
00123     __saveScalarFunction(file,f);
00124   }
00125 }

Here is the call graph for this function:

void WriterBase::add ( ConstReferenceCounting< ScalarFunctionBase function  )  [inherited]

Adds a function to the list of functions

Parameters:
function given function

Definition at line 32 of file WriterBase.cpp.

References WriterBase::__scalarFunctionList.

00033 {
00034   __scalarFunctionList.push_back(function);
00035 }

void WriterBase::add ( ConstReferenceCounting< FieldOfScalarFunction field  )  [inherited]

Adds a field to the list of fields

Parameters:
field given field

Definition at line 38 of file WriterBase.cpp.

References WriterBase::__fieldList.

00039 {
00040   __fieldList.push_back(field);
00041 }


Member Data Documentation

const std::string WriterBase::__filename [protected, inherited]

name of the file

Definition at line 50 of file WriterBase.hpp.

Referenced by WriterVTK::__proceed(), WriterMedit::__proceedData(), WriterMedit::__proceedMesh(), and proceed().

const FileDescriptor& WriterBase::__fileDescriptor [protected, inherited]

describes file type

Definition at line 53 of file WriterBase.hpp.

Referenced by __saveScalarFunction().

const std::string WriterBase::__CR [protected, inherited]

type of carriage return for text files

Definition at line 54 of file WriterBase.hpp.

Referenced by WriterMedit::__proceedData(), WriterMedit::__proceedMesh(), WriterMedit::__saveElements(), and __saveScalarFunction().

FieldList WriterBase::__fieldList [protected, inherited]

the function list

Definition at line 59 of file WriterBase.hpp.

Referenced by WriterVTK::__proceed(), WriterMedit::__proceedData(), WriterBase::add(), proceed(), and WriterMedit::proceed().


The documentation for this class was generated from the following files:

Generated on Wed Nov 19 00:18:12 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6