dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #18636
xy format for solutions output.
Hi!
I've added another simple and light format for solutions output
The file contain a list of x y coordinates. (Like the xyz format)
The xy format is usable only with 1D domains (x) and scalar
solutions (y).
It could be used directly with Xgraphic(wich is part of Xd3d) or gnuplot
for instance.
Nuno Lopes
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: ndl@an9-20100629100842-xtoln1owkzh5byy1
# target_branch: bzr+ssh://bazaar.launchpad.net/~dolfin-\
# core/dolfin/main/
# testament_sha1: 32586ecdd2ec1b54e81e105fb41683c0dbd0ae71
# timestamp: 2010-06-29 11:15:54 +0100
# base_revision_id: logg@xxxxxxxxx-20100629075404-17p8eqmq0vlxp0co
#
# Begin patch
=== modified file 'dolfin/io/File.cpp'
--- dolfin/io/File.cpp 2010-06-02 11:31:31 +0000
+++ dolfin/io/File.cpp 2010-06-29 10:08:42 +0000
@@ -9,7 +9,7 @@
// Modified by Ola Skavhaug 2009.
//
// First added: 2002-11-12
-// Last changed: 2010-02-10
+// Last changed: 2010-06-29
#include <boost/filesystem.hpp>
#include <fstream>
@@ -24,6 +24,7 @@
#include "VTKFile.h"
#include "RAWFile.h"
#include "XYZFile.h"
+#include "XYFile.h"
#include "BinaryFile.h"
using namespace dolfin;
@@ -55,6 +56,8 @@
file = new RAWFile(filename);
else if (extension == ".xyz")
file = new XYZFile(filename);
+ else if (extension == ".xy")
+ file = new XYFile(filename);
else if (extension == ".bin")
file = new BinaryFile(filename);
else
@@ -86,6 +89,9 @@
case xyz:
file = new XYZFile(filename);
break;
+ case xy:
+ file = new XYFile(filename);
+ break;
case binary:
file = new BinaryFile(filename);
break;
=== modified file 'dolfin/io/File.h'
--- dolfin/io/File.h 2010-06-02 11:31:31 +0000
+++ dolfin/io/File.h 2010-06-29 10:08:42 +0000
@@ -7,7 +7,7 @@
// Modified by Ola Skavhaug 2009
//
// First added: 2002-11-12
-// Last changed: 2010-02-10
+// Last changed: 2010-06-29
#ifndef __FILE_H
#define __FILE_H
@@ -32,7 +32,7 @@
public:
/// File formats
- enum Type {xml, matlab, octave, vtk, python, raw, xyz, binary};
+ enum Type {xml, matlab, octave, vtk, python, raw, xyz, xy, binary};
/// Create a file with given name
File(const std::string filename, std::string encoding = "ascii");
=== added file 'dolfin/io/XYFile.cpp'
--- dolfin/io/XYFile.cpp 1970-01-01 00:00:00 +0000
+++ dolfin/io/XYFile.cpp 2010-06-29 10:08:42 +0000
@@ -0,0 +1,142 @@
+// Copyright (C) 2005-2007 Garth N.Wells.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// Modified by Nuno Lopes 2008.
+//
+// First added: 2008-07-02
+#include <sstream>
+#include <fstream>
+#include <dolfin/fem/FiniteElement.h>
+#include <dolfin/mesh/Mesh.h>
+#include <dolfin/mesh/MeshFunction.h>
+#include <dolfin/mesh/Vertex.h>
+#include <dolfin/mesh/Cell.h>
+#include <dolfin/function/Function.h>
+#include <dolfin/function/FunctionSpace.h>
+#include <dolfin/la/Vector.h>
+#include "XYFile.h"
+
+using namespace dolfin;
+
+//----------------------------------------------------------------------------
+XYFile::XYFile(const std::string filename) : GenericFile(filename)
+{
+ type = "XY";
+}
+//----------------------------------------------------------------------------
+XYFile::~XYFile()
+{
+ // Do nothing
+}
+//----------------------------------------------------------------------------
+void XYFile::operator<<(const Function& u)
+{
+ // Update xy file name and clear file
+ xyNameUpdate(counter);
+
+ // Write results
+ ResultsWrite(u);
+
+ // Increase the number of times we have saved the function
+ counter++;
+
+ cout << "Saved function " << u.name() << " (" << u.label()
+ << ") to file " << filename << " in xgraphic xy format." << endl;
+}
+//----------------------------------------------------------------------------
+void XYFile::ResultsWrite(const Function& u) const
+{
+ // Open file
+ std::ofstream fp(xy_filename.c_str(), std::ios_base::app);
+ if (!fp)
+ error("Unable to open file %s", filename.c_str());
+
+ const uint rank = u.function_space().element().value_rank();
+ if(rank > 1)
+ error("Only scalar functions can be saved in xy format.");
+
+ // Get number of components
+ uint dim = 1;
+ for (uint i = 0; i < rank; i++)
+ dim *= u.function_space().element().value_dimension(i);
+
+ const Mesh& mesh = u.function_space().mesh();
+
+ // Allocate memory for function values at vertices
+ const uint size = mesh.num_vertices()*dim;
+ boost::scoped_array<double> values(new double[size]);
+
+ // Get function values at vertices
+ u.compute_vertex_values(values.get(),mesh);
+
+ // Write function data at mesh vertices
+
+ if ( dim > 1 )
+ error("Cannot handle XY file for non-scalar functions. ");
+
+
+
+ std::ostringstream ss;
+ ss << std::scientific;
+ for (VertexIterator vertex(mesh); !vertex.end(); ++vertex)
+ {
+ ss.str("");
+ ss<<vertex->x(0)<<" "<< values[ vertex->index()];
+ ss<<std::endl;
+ fp<<ss.str( );
+ }
+}
+//----------------------------------------------------------------------------
+void XYFile::xyNameUpdate(const int counter)
+{
+ std::string filestart, extension;
+ std::ostringstream fileid, newfilename;
+
+ fileid.fill('0');
+ fileid.width(6);
+
+ filestart.assign(filename, 0, filename.find("."));
+ extension.assign(filename, filename.find("."), filename.size());
+
+ fileid << counter;
+ newfilename << filestart << fileid.str() << ".xy";
+
+ xy_filename = newfilename.str();
+
+ // Make sure file is empty
+ FILE* fp = fopen(xy_filename.c_str(), "w");
+ if (!fp)
+ error("Unable to open file %s", filename.c_str());
+ fclose(fp);
+}
+//----------------------------------------------------------------------------
+template<class T>
+void XYFile::MeshFunctionWrite(T& meshfunction)
+{
+ // Update xy file name and clear file
+ xyNameUpdate(counter);
+
+ Mesh& mesh = meshfunction.mesh();
+
+ if( meshfunction.dim() != mesh.topology().dim() )
+ error("XY output of mesh functions is implemenetd for cell-based functions only.");
+
+ // Open file
+ std::ofstream fp(xy_filename.c_str(), std::ios_base::app);
+
+ fp<<mesh.num_cells( ) <<std::endl;
+ for (CellIterator cell(mesh); !cell.end(); ++cell)
+ fp << meshfunction.get( cell->index() ) << std::endl;
+
+ // Close file
+ fp.close();
+
+ // Increase the number of times we have saved the mesh function
+ counter++;
+
+ cout << "saved mesh function " << counter << " times." << endl;
+
+ cout << "Saved mesh function " << mesh.name() << " (" << mesh.label()
+ << ") to file " << filename << " in XY format." << endl;
+}
+//----------------------------------------------------------------------------
=== added file 'dolfin/io/XYFile.h'
--- dolfin/io/XYFile.h 1970-01-01 00:00:00 +0000
+++ dolfin/io/XYFile.h 2010-06-29 10:08:42 +0000
@@ -0,0 +1,45 @@
+// Copyright (C) 2005-2007 Garth N.Wells.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// Modified by Nuno Lopes 2010.
+//
+// First added: 2010-02-17
+
+#ifndef __XY_FILE_H
+#define __XY_FILE_H
+
+#include <fstream>
+#include "GenericFile.h"
+
+namespace dolfin
+{
+
+ class XYFile : public GenericFile
+ {
+ public:
+
+ /// Simple and light file format for use with Xgraphic (part of Xd3d).
+ // Supports scalar solution on 1D domains. The files only have a
+ /// list of xy coordinates 'x , u(x)=y'
+
+ XYFile(const std::string filename);
+ ~XYFile();
+
+ void operator<< (const Function& u);
+
+ private:
+
+ void ResultsWrite(const Function& u) const;
+ void xyNameUpdate(const int counter);
+
+ template<class T>
+ void MeshFunctionWrite(T& meshfunction);
+
+ // raw filename
+ std::string xy_filename;
+
+ };
+
+}
+
+#endif
# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWZ0sFPsABlhfgEwQe////3/n
3+q////7YA1O+Cg6oroAAA621ahFaaLbRQAAAFHwkkgJ6jEmJ5KeamJiYpgnpNMjI0aYIADRkDUx
TJJ+Jqj0g0/UgGjTQ0AGI0ANGCaNNAHMJoyNDQyGEaGQ00aADEZMgGEAwCUyiE1G1T1Hp6IaI8JM
mQNMRo0xDAQBoMgcwmjI0NDIYRoZDTRoAMRkyAYQDAJEggCARkaE09IZNTCGqep5TwEnqN6RqeU9
pJ7SkEKEmWIxWnOYF4Mg/DB44+CBuzDt6M5dkUB9sg/cdl15POrK81pyKWPORGBdFF5FJMWFEhoh
QjtWjPxSiX6kLTQgbavggbHbEhwVJE7opLezDJoId2gHs7ypMg6LGitjddFMXt8MSQg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