← Back to team overview

dolfin team mailing list archive

Re: xy format for solutions.

 

On Wednesday 08 September 2010 21:14:46 Garth N. Wells wrote:
> > 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
> 

Done
All in XYZFile.cpp...just added a few lines.

-- 
Nuno David Lopes

e-mail:ndl @ ptmat.fc.ul.pt        (FCUL/CMAF)
       nlopes @ dec.isel.ipl.pt    (ISEL)
       ndlopes @ gmail.com
http://ptmat.ptmat.fc.ul.pt/%7Endl/ 

Thu Sep  9 11:27:56 WEST 2010
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: ndl@an9-20100909102504-hzf23szf3o6nvyj1
# target_branch: bzr+ssh://bazaar.launchpad.net/%2Bbranch/dolfin/
# testament_sha1: cb9cb83237ad3766a1e5e1b1e110adb80ccaad20
# timestamp: 2010-09-09 11:25:59 +0100
# base_revision_id: johannr@xxxxxxxxx-20100909075345-6y0x7o7jehug6nxa
# 
# Begin patch
=== modified file 'dolfin/io/XYZFile.cpp'
--- dolfin/io/XYZFile.cpp	2010-09-03 20:14:27 +0000
+++ dolfin/io/XYZFile.cpp	2010-09-09 10:25:04 +0000
@@ -5,19 +5,19 @@
 //
 // First added:  2008-07-02
 
+#include <sstream>
 #include <fstream>
-#include <sstream>
 #include <boost/scoped_array.hpp>
 
 #include <dolfin/common/Array.h>
 #include <dolfin/fem/FiniteElement.h>
-#include <dolfin/function/Function.h>
-#include <dolfin/function/FunctionSpace.h>
-#include <dolfin/la/Vector.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 "XYZFile.h"
 
 using namespace dolfin;
@@ -78,13 +78,29 @@
     error("Cannot handle XYZ file for non-scalar functions. ");
   std::ostringstream ss;
   ss << std::scientific;
-  for (VertexIterator vertex(mesh); !vertex.end(); ++vertex)
-  {
-    ss.str("");
-    ss << vertex->x(0) << " " << vertex->x(1) << " " << values[ vertex->index() ];
-    ss <<std::endl;
-    fp << ss.str( );
-  }
+
+
+  if (mesh.topology().dim()==1)
+    {
+      for (VertexIterator vertex(mesh); !vertex.end(); ++vertex)
+        {
+          ss.str("");
+          ss<<vertex->x(0)<<" "<< values[ vertex->index()];
+          ss <<std::endl;
+          fp << ss.str( );
+        }
+    }
+  else if (mesh.topology().dim()==2)
+    {
+      for (VertexIterator vertex(mesh); !vertex.end(); ++vertex)
+        {
+          ss.str("");
+          ss << vertex->x(0) << " " << vertex->x(1) << " " << values[ vertex->index() ];
+          ss <<std::endl;
+          fp << ss.str( );
+        }
+    }
+  else error("Unable to write XYZ file, mesh topology dimension is not supported for this format.");
 }
 //----------------------------------------------------------------------------
 void XYZFile::xyz_name_update(int counter)
@@ -104,9 +120,10 @@
   xyz_filename = newfilename.str();
 
   // Make sure file is empty
-  std::ofstream fp(xyz_filename.c_str(), std::ios_base::trunc);
+  FILE* fp = fopen(xyz_filename.c_str(), "w");
   if (!fp)
     error("Unable to open file %s", filename.c_str());
+  fclose(fp);
 }
 //----------------------------------------------------------------------------
 template<class T>
@@ -122,17 +139,19 @@
 
   // Open file
   std::ofstream fp(xyz_filename.c_str(), std::ios_base::app);
-  if (!fp)
-    error("Unable to open file %s", filename.c_str());
 
-  fp << mesh.num_cells() <<std::endl;
+  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 XYZ format." << endl;
 }

# Begin bundle
IyBCYXphYXIgcmV2aXNp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