← Back to team overview

dolfin team mailing list archive

Re: xy format for solutions.

 



On 08/09/10 21:13, ndlopes@xxxxxxxxx wrote:
The xy format is just:
------------------------
x_0  u(x_0)
x_1  u(x_1)
...........
x_n  u(x_n)
----------------------
while the xyz format is something like
-----------------------
x_0  y_0  u(x_0,y_0)
x_1  y_1  u(x_1,y_1)
.............
x_n  y_n u(x_n,y_n)
-------------------------
where u is the solution.

When you say "merging the classes"  do you mean to keep only the xyz format
and when the dimension is 1  output  the solutions as in the xy format?


Yes. Once class should handle

  x0 x1, . . . xn

output.

Garth

On Wednesday 08 September 2010 18:16:52 Garth N. Wells wrote:
On 08/09/10 18:15, Anders Logg wrote:
Yes, why not. Could you send a sample output in the xy format?
.........................................
0.000000e+00 3.604320e-05
9.836066e-02 3.791263e-05
1.967213e-01 1.789361e-05
2.950820e-01 -7.128666e-06
3.934426e-01 -3.047573e-05
4.918033e-01 -4.010990e-05
5.901639e-01 -2.751590e-05
6.885246e-01 -6.833624e-06
7.868852e-01 2.042466e-05
8.852459e-01 4.019479e-05
9.836066e-01 5.532863e-05
........................................


I would suggest merging the xy and xyx classes.

Garth

--
Anders

On Wed, Sep 08, 2010 at 06:11:22PM +0100, ndlopes@xxxxxxxxx wrote:
Hi,

Is it possible to consider a new output format for 1D problems?
I'm using it for some time and now I've updated it to dolfin-0.9.9.

The solutions file contain a list of  x y  coordinates.
(analogous to the xyz format)
It could be used directly with Xgraphic (wich is part of Xd3d),
gnuplot or with simple python/matplotlib  scripts for instance.

Hope it works.

Nuno Lopes


# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: ndl@an9-20100908165948-xqvxgx0834mlrkpt
# target_branch: bzr+ssh://bazaar.launchpad.net/~dolfin-\
#   core/dolfin/main/
# testament_sha1: 1a4383b33310156a890260ef4c35ceba6d7930e8
# timestamp: 2010-09-08 18:01:16 +0100
# base_revision_id: johannr@xxxxxxxxx-20100908084437-u2bw3adyeepm4de3
#
# Begin patch
=== modified file 'dolfin/io/File.cpp'
--- dolfin/io/File.cpp	2010-09-06 15:19:48 +0000
+++ dolfin/io/File.cpp	2010-09-08 16:59:48 +0000
@@ -9,19 +9,20 @@

   // Modified by Ola Skavhaug 2009.
   //
   // First added:  2002-11-12

-// Last changed: 2010-09-06
+// Last changed: 2010-09-08

+#include<boost/filesystem.hpp>

   #include<fstream>

-#include<boost/filesystem.hpp>
+#include<dolfin/main/MPI.h>
+#include<dolfin/log/dolfin_log.h>

   #include<dolfin/function/Function.h>

-#include<dolfin/log/dolfin_log.h>
-#include<dolfin/main/MPI.h>

   #include "File.h"
   #include "XMLFile.h"
   #include "PythonFile.h"
   #include "VTKFile.h"
   #include "RAWFile.h"
   #include "XYZFile.h"

+#include "XYFile.h"

   #include "BinaryFile.h"

   using namespace dolfin;

@@ -34,14 +35,11 @@

     const std::string extension = boost::filesystem::extension(path);

     // Create directory if we have a parent path

-  if (path.has_parent_path())
+  if ( path.has_parent_path() )

     {

       const boost::filesystem::path directory = path.parent_path();

-    if (!boost::filesystem::is_directory(directory))
-    {
-      cout<<   "Creating directory \""<<   directory.string()<<   "\"."<<
endl; -      boost::filesystem::create_directories(directory);
-    }
+    cout<<   "Creating directory \""<<   directory.string()<<   "\"."<<
endl; +    boost::filesystem::create_directories(directory);

     }

     // Choose format based on extension

@@ -64,6 +62,8 @@

       file.reset(new RAWFile(filename));

     else if (extension == ".xyz")

       file.reset(new XYZFile(filename));

+  else if (extension == ".xy")
+    file.reset(new XYFile(filename));

     else if (extension == ".bin")

       file.reset(new BinaryFile(filename));

     else

@@ -89,6 +89,9 @@

     case xyz:
       file.reset(new XYZFile(filename));
       break;

+  case xy:
+    file.reset(new XYFile(filename));
+    break;

     case binary:
       file.reset(new BinaryFile(filename));
       break;

=== modified file 'dolfin/io/File.h'
--- dolfin/io/File.h	2010-08-26 21:44:34 +0000
+++ dolfin/io/File.h	2010-09-08 16:59:48 +0000
@@ -7,7 +7,7 @@

   // Modified by Ola Skavhaug 2009
   //
   // First added:  2002-11-12

-// Last changed: 2010-02-10
+// Last changed: 2010-09-08

   #ifndef __FILE_H
   #define __FILE_H

@@ -33,7 +33,7 @@

     public:
       /// File formats

-    enum Type {xml, vtk, python, raw, xyz, binary};
+    enum Type {xml, 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-09-08 16:59:48 +0000
@@ -0,0 +1,143 @@
+// Copyright (C) 2005-2007 Garth N.Wells.
+// Licensed under the GNU LGPL Version 2.1.
+//
+// Modified by Nuno Lopes 2010.
+//
+// First added:  2010-09-08
+
+#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
+  xy_name_update(counter);
+
+  // Write results
+  results_write(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::results_write(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;
+  Array<double>   values(size);
+
+  // Get function values at vertices
+  u.compute_vertex_values(values,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::xy_name_update(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::mesh_function_write(T&   meshfunction)
+{
+  // Update xy file name and clear file
+  xy_name_update(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-09-08 16:59:48 +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 Xd3d. Supports
+    /// scalar solution on 2D convex 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 results_write(const Function&   u) const;
+    void xy_name_update(const int counter);
+
+    template<class T>
+    void mesh_function_write(T&   meshfunction);
+
+    // raw filename
+    std::string xy_filename;
+
+  };
+
+}
+
+#endif

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWfjaqNUABrtfgEwQe///
/3/n
z+6////7YA29r5WttCNnVx3NUAjV0tbtXbYUXaba0MrYbWOgHCSRJhA0U8ym0TZTTEGIIaM
ammjN
QBoBoyCUQExNAIJiano0o/VD1PRGmg0NAaAADQHMJoyNDQyGEaGQ00aADEZMgGEAwCQohqa
aqH5J
6NAp41T1NpB+VHojJp6j1Gg00A9TRppocwmjI0NDIYRoZDTRoAMRkyAYQDAJEghMEaRkJk1
N6k8n
lDUyGpoeU8k009Q0yaaaGmlKpJNcxzZQjSPW0Hcw/7n3bKz8acvVG2b1+tqn8Sh/B2djl50
oTzPq
xY0ldJRM1+2GCkRwuij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rKJiBPb8riA0CXy+eO9ZJamCxeTQj0W0JBUS85jM2vOXsW3
zlVDK
tRRDEb3IC8ji0YHMql5GZLZmCwLy8YMbB3++CW1Hsrgw80CcWcTtDUj3nAzQcCYU4KcsjWV
GHisM
Fl7AVsjeRqJfHwBSWLMBsZFI4QwGhpQUa6gHDhTS7/Pj4NcqYBCmK7HYSvKqoJQW+V5mG1O
RaCW1
hLKWw5kYsoKECdYF8s9SPFnS0mlQBjRmQSWbba6W0zpqPslDP1MoCbgmRVDuLrgnp62ux7r
bdVx4
nIavK1Qk1azQJIvP7BdoWmxttGPT49QbA4spgTUZr1/XJlJk7xYEiMGGg6hbYMR9nYbUtaq
gvb3i
qang60oDZsOBB/Qw1hk9AxR7x9kXwfOkpjCZaikxlsTURMoxk5I7gIkFWJbZNjBg2pxFtlD
ThYrk
tz9hdgBmB1wYz6XQWvfKKouotpTuFo0C9VA3UJs2pQWtt2EkkRdlEQoFlzakdbS8a/gBroa
XIFWx
mfkDxZBiKAPaDBjTaCp+CwA7Qr67SvXUM1lBiUV2UabkGCl9z4fbbJOnOHkSzDyBX3gpl/m
dvzKp
Ra4vR+c19bNGHEEyvAF7fp/XgCqCqjvxI9bL0wn79rcvRoeb0psfyQ2fltnJzZ9oEjpaDzp
hd8e4 7xzt4+WTr4AMBmvMDMMyTRNPm/4u5IpwoSHxtVGq

_______________________________________________
Mailing list: https://launchpad.net/~dolfin
Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp

--
Anders

_______________________________________________
Mailing list: https://launchpad.net/~dolfin
Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp




References