Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Koch
dune-common
Commits
853853e6
Commit
853853e6
authored
20 years ago
by
Oliver Sander
Browse files
Options
Downloads
Patches
Plain Diff
added a method which writes BCRSMatrices in a Matlab-readable format
[[Imported from SVN: r1642]]
parent
33793999
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
istl/io.hh
+51
-0
51 additions, 0 deletions
istl/io.hh
with
51 additions
and
0 deletions
istl/io.hh
+
51
−
0
View file @
853853e6
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include
"istlexception.hh"
#include
"istlexception.hh"
#include
<dune/common/fvector.hh>
#include
<dune/common/fvector.hh>
#include
<dune/common/fmatrix.hh>
#include
<dune/common/fmatrix.hh>
#include
<dune/istl/bcrsmatrix.hh>
/** \file
/** \file
...
@@ -195,6 +196,56 @@ namespace Dune {
...
@@ -195,6 +196,56 @@ namespace Dune {
s
.
setf
(
std
::
ios_base
::
fixed
,
std
::
ios_base
::
floatfield
);
s
.
setf
(
std
::
ios_base
::
fixed
,
std
::
ios_base
::
floatfield
);
}
}
/** \brief Writes sparse matrix in a Matlab-readable format
*
* This routine writes the argument BCRSMatrix to a file with the name given by
* the filename argument. The file format is ASCII, with no header, and three
* data columns. Each row describes a scalar matrix entry and consists of the
* matrix row and column numbers (both counted starting from 1), and the matrix
* entry. Such a file can be read from Matlab using the command
* \verbatim
new_mat = spconvert(load('filename'));
\endverbatim
*/
template
<
class
BlockType
>
void
writeMatrixToMatlab
(
const
BCRSMatrix
<
BlockType
>&
matrix
,
const
std
::
string
&
filename
)
{
FILE
*
fp
=
fopen
(
filename
.
c_str
(),
"w"
);
int
blocksize
=
3
;
typedef
typename
BCRSMatrix
<
BlockType
>::
row_type
RowType
;
// Loop over all matrix rows
for
(
int
rowIdx
=
0
;
rowIdx
<
matrix
.
N
();
rowIdx
++
)
{
const
RowType
&
row
=
matrix
[
rowIdx
];
typedef
typename
RowType
::
ConstIterator
ColumnIterator
;
ColumnIterator
cIt
=
row
.
begin
();
ColumnIterator
cEndIt
=
row
.
end
();
// Loop over all columns in this row
for
(;
cIt
!=
cEndIt
;
++
cIt
)
{
for
(
int
i
=
0
;
i
<
blocksize
;
i
++
)
{
for
(
int
j
=
0
;
j
<
blocksize
;
j
++
)
{
//+1 for Matlab numbering
fprintf
(
fp
,
"%d %d %g
\n
"
,
rowIdx
*
blocksize
+
i
+
1
,
cIt
.
index
()
*
blocksize
+
j
+
1
,
(
*
cIt
)[
i
][
j
]);
}
}
}
}
fclose
(
fp
);
}
/** @} end documentation */
/** @} end documentation */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment