← Back to team overview

dolfin team mailing list archive

Fwd: [Branch ~dolfin-core/dolfin/main] Rev 4698: Work on extending BinaryFile to handle meshes. Input/output of arrays implemented

 

Does this work in parallel?

Garth

-------- Original Message --------
Subject: [Branch ~dolfin-core/dolfin/main] Rev 4698: Work on extending BinaryFile to handle meshes. Input/output of arrays implemented
Date: Tue, 27 Apr 2010 21:44:21 -0000
From: noreply@xxxxxxxxxxxxx
Reply-To: noreply@xxxxxxxxxxxxx
To: Garth Wells <gnw20@xxxxxxxxx>

------------------------------------------------------------
revno: 4698
committer: Anders Logg <logg@xxxxxxxxx>
branch nick: dolfin-dev
timestamp: Tue 2010-04-27 23:07:58 +0200
message:
Work on extending BinaryFile to handle meshes. Input/output of arrays implemented
  in common functions (not yet used).
modified:
  demo/adaptivity/time-series/cpp/main.cpp
  dolfin/io/BinaryFile.cpp
  dolfin/io/BinaryFile.h


--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/main

Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription

=== modified file 'demo/adaptivity/time-series/cpp/main.cpp'
--- demo/adaptivity/time-series/cpp/main.cpp	2010-04-03 04:57:11 +0000
+++ demo/adaptivity/time-series/cpp/main.cpp	2010-04-27 21:07:58 +0000
@@ -2,7 +2,7 @@
 // Licensed under the GNU LGPL Version 2.1.
 //
 // First added:  2009-11-11
-// Last changed: 2009-11-11
+// Last changed: 2010-04-27
 //
 // This program demonstrates the use of the TimeSeries
 // class for storing a series of meshes and vectors.
@@ -19,7 +19,6 @@
   // Create a mesh and a vector
   UnitSquare unitsquare_mesh(2, 2);
   Mesh mesh(unitsquare_mesh);
-
   Vector x;
 
   // Add a bunch of meshes and vectors to the series
@@ -34,6 +33,12 @@
     series.store(new_mesh, t);
     series.store(x, t);
 
+    //for (dolfin::uint i = 0; i < x.size(); i++)
+    //  x.setitem(i, (t + 1.0)*static_cast<double>(i));
+    for (dolfin::uint i = 0; i < x.size(); i++)
+      x.setitem(i, 3.0);
+    info(x, true);
+
     mesh = new_mesh;
     t += 0.2;
   }
@@ -42,6 +47,8 @@
   series.retrieve(mesh, 0.3);
   series.retrieve(x, 0.3);
 
+  info(x, true);
+
   // Plot mesh
   plot(mesh);
 

=== modified file 'dolfin/io/BinaryFile.cpp'
--- dolfin/io/BinaryFile.cpp	2010-03-09 23:40:57 +0000
+++ dolfin/io/BinaryFile.cpp	2010-04-27 21:07:58 +0000
@@ -2,7 +2,7 @@
 // Licensed under the GNU LGPL Version 2.1.
 //
 // First added:  2009-11-11
-// Last changed: 2010-02-10
+// Last changed: 2010-04-27
 
 #include <dolfin/log/log.h>
 #include <istream>
@@ -115,3 +115,44 @@
   warning("Writing mesh in binary format not implemented.");
 }
 //-----------------------------------------------------------------------------
+dolfin::uint BinaryFile::read_uint(std::ifstream& file) const
+{
+  uint value = 0;
+  file.read((char*) &value, sizeof(uint));
+  return value;
+}
+//-----------------------------------------------------------------------------
+void BinaryFile::read_array(uint n, uint* values,
+                            std::ifstream& file) const
+{
+  for (uint i = 0; i < n; ++i)
+    file.read((char*) (values + i), sizeof(uint));
+}
+//-----------------------------------------------------------------------------
+void BinaryFile::read_array(uint n, double* values,
+                            std::ifstream& file) const
+{
+  for (uint i = 0; i < n; ++i)
+    file.read((char*) (values + i), sizeof(double));
+}
+//-----------------------------------------------------------------------------
+void BinaryFile::write_uint(uint value,
+                            std::ofstream& file) const
+{
+  file.write((char*) &value, sizeof(uint));
+}
+//-----------------------------------------------------------------------------
+void BinaryFile::write_array(uint n, const uint* values,
+                             std::ofstream& file) const
+{
+  for (uint i = 0; i < n; ++i)
+    file.write((char*) &values[i], sizeof(uint));
+}
+//-----------------------------------------------------------------------------
+void BinaryFile::write_array(uint n, const double* values,
+                             std::ofstream& file) const
+{
+  for (uint i = 0; i < n; ++i)
+    file.write((char*) &values[i], sizeof(double));
+}
+//-----------------------------------------------------------------------------

=== modified file 'dolfin/io/BinaryFile.h'
--- dolfin/io/BinaryFile.h	2010-02-10 18:13:32 +0000
+++ dolfin/io/BinaryFile.h	2010-04-27 21:07:58 +0000
@@ -2,7 +2,7 @@
 // Licensed under the GNU LGPL Version 2.1.
 //
 // First added:  2009-11-11
-// Last changed: 2010-02-10
+// Last changed: 2010-04-27
 
 #ifndef __BINARY_FILE_H
 #define __BINARY_FILE_H
@@ -56,6 +56,26 @@
     /// Write mesh
     void operator<< (const Mesh& mesh);
 
+  private:
+
+    // Read uint
+    uint read_uint(std::ifstream& file) const;
+
+    // Read array (uint)
+    void read_array(uint n, uint* values, std::ifstream& file) const;
+
+    // Read array (double)
+    void read_array(uint n, double* values, std::ifstream& file) const;
+
+    // Write uint
+    void write_uint(uint value, std::ofstream& file) const;
+
+    // Write array (uint)
+    void write_array(uint n, const uint* values, std::ofstream& file) const;
+
+    // Write array (double)
+    void write_array(uint n, const double* values, std::ofstream& file) const;
+
   };
 
 }



Follow ups