[dune-fem] b4102c1 added dump on file for discretefunction (usefull to debug in Matlab

Agnese, Marco m.agnese13 at imperial.ac.uk
Mon Feb 9 16:36:56 CET 2015


Hi Robert,
I added both the methods for matrix and vector. 

In the commit, I wrote Matlab just to give an example but these functions simply dumps the values into file using a standard format. 

More precisely  the method print() for matrix dump on file only the non-zeros value in the usual format

i j value

and I it is also possible to give an offset in order to be usable directly from matlab (which needs offset 0), but by default the offset is 0. 
The previous print, instead, was printing all the values giving origin to a very big output.  

For what concern the discrete function, it simply dumps on file all the values. I haven't used the already implemented print function because it puts in the first line the name of the discrete function and therefore,in general, the file need to be edited before be imported into an external program.

I know that these method are trivial and very simple to implement, but I think that they speed up the debug process and avoid the users to waste time in rewriting this method. Therefore, for my point of view are useful. For this reason I added them to dune-fem instead of implementing in my own codes.

Nevertheless, if you think that it doesn't make sense to have them into dune-fem, we can remove them form the trunk. I don't want to force my point of view since I have very little experience.

Best regards,
Marco.

________________________________________
From: Robert Kloefkorn [robertk at posteo.de]
Sent: Monday, February 09, 2015 3:16 PM
To: Agnese, Marco; dune-fem-devel at listserv.uni-stuttgart.de; dune-fem at dune-project.org
Subject: Fwd: b4102c1 added dump on file for discretefunction (usefull to debug in Matlab

Hi Marco,

thanks for contributing to dune-fem.

Nevertheless, I would like to point out, that the method you added in
your last patch is very user specific (matlab etc.) and also available
via the method

write( OutStreamInterface< StreamTraits > &out ) const

where in your case OutStreamInterface is to chosen as
ASCIIOutStream file( filename );

Also, there is a reason why the method print( filename ) is not
available. Creating a filename is something the user should do, because
it reduces maintenance on dune-fem side. The same holds for the methods
that were added to some of the matrix classes some weeks ago.

If you think that this is a feature that is badly needed, then please
express this on the dune-fem list (dune-fem at dune-project.org).

Thanks and regards,

Robert


-------- Forwarded Message --------
Subject:        b4102c1 added dump on file for discretefunction (usefull to
debug in Matlab
Date:   Mon, 9 Feb 2015 15:02:30 +0000
From:   marco.agnese88 at gmail.com <ma2413 at imperial.ac.uk>



b4102c1 added dump on file for discretefunction (usefull to debug in
Matlab commit b4102c1bb3b143d231e8363fe60086fe8eab37a7
Author: marco.agnese88 at gmail.com <ma2413 at imperial.ac.uk>
Date: Mon, 9 Feb 2015 15:02:30 +0000

added dump on file for discretefunction (usefull to debug in Matlab

diff --git a/dune/fem/function/common/discretefunction.hh
b/dune/fem/function/common/discretefunction.hh
index f47812f..389b884 100644
--- a/dune/fem/function/common/discretefunction.hh
+++ b/dune/fem/function/common/discretefunction.hh
@@ -3,6 +3,8 @@

// C++ includes
#include <string>
+#include <iostream>
+#include <fstream>

// dune-common inlcudes
#include <dune/common/version.hh>
@@ -348,6 +350,15 @@ namespace Dune
asImp().print( out );
}

+ /** brief dump all DoFs into a file (for debugging purposes)
+ *
+ * param[in] filename name of file to dump into
+ */
+ inline void print( const std :: string &filename ) const
+ {
+ asImp().print( filename );
+ }
+
/** brief check for NaNs
* returns if one of the DoFs is NaN b false is returned, otherwise b true
*/
@@ -664,6 +675,9 @@ namespace Dune
/** copydoc Dune::Fem::DiscreteFunctionInterface::print */
void print ( std :: ostream &out ) const;

+ /** copydoc Dune::Fem::DiscreteFunctionInterface::print */
+ void print ( const std :: string &filename ) const;
+
/** copydoc Dune::Fem::DiscreteFunctionInterface::dofsValid */
inline bool dofsValid () const;

diff --git a/dune/fem/function/common/discretefunction_inline.hh
b/dune/fem/function/common/discretefunction_inline.hh
index 82503bb..4a74f6a 100644
--- a/dune/fem/function/common/discretefunction_inline.hh
+++ b/dune/fem/function/common/discretefunction_inline.hh
@@ -100,6 +100,23 @@ namespace Dune
out << (*dit) << std::endl;
}

+ template< class Impl >
+ inline void DiscreteFunctionDefault<Impl >
+ :: print ( const std::string &filename ) const
+ {
+ std::cout << "Dump " << BaseType :: name() << " on file" << std::endl;
+ std::ofstream ofs;
+ ofs.open(filename.c_str());
+ if(ofs.is_open())
+ {
+ const ConstDofIteratorType end = BaseType :: dend();
+ for( ConstDofIteratorType dit = BaseType :: dbegin(); dit != end; ++dit )
+ ofs << (*dit) << std::endl;
+ }
+ else
+ std::cout << "Not able to open the file " << filename << std::endl;
+ ofs.close();
+ }

template< class Impl >
inline bool DiscreteFunctionDefault< Impl >







More information about the dune-fem mailing list