Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-fufem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
agnumpde
dune-fufem
Commits
5b4326e3
Commit
5b4326e3
authored
Mar 28, 2019
by
Patrick Jaap
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of symmetric matrices
parent
23b1e546
Branches
Branches containing commit
No related tags found
1 merge request
!46
Implementation of symmetric matrices
Pipeline
#16231
passed
Mar 28, 2019
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/fufem/symmetricmatrix.hh
+109
-0
109 additions, 0 deletions
dune/fufem/symmetricmatrix.hh
with
109 additions
and
0 deletions
dune/fufem/symmetricmatrix.hh
0 → 100644
+
109
−
0
View file @
5b4326e3
#ifndef DUNE_FUFEM_SYMMETRICMATRIX_HH
#define DUNE_FUFEM_SYMMETRICMATRIX_HH
#include
<dune/common/fvector.hh>
namespace
Dune
{
/** \brief A class implementing a symmetric matrix with compile-time size
*
* A \f$ dim\times dim \f$ matrix is stored internally as a <tt>Dune::FieldVector<double, dim*(dim+1)/2></tt>
* The components are assumed to be \f$ [ E(1,1),\ E(2,1),\ E(2,2),\ E(3,1),\ E(3,2),\ E(3,3) ]\f$
* and analogous for other dimensions
* \tparam dim number of lines/columns of the matrix
*/
template
<
class
T
,
int
N
>
class
SymmetricMatrix
{
public:
/** \brief The type used for scalars
*/
typedef
T
field_type
;
/** \brief Default constructor, creates uninitialized matrix
*/
SymmetricMatrix
()
{}
/** \brief Construct from raw memory */
template
<
class
Iterator
>
SymmetricMatrix
(
Iterator
it
)
{
for
(
size_t
i
=
0
;
i
<
data_
.
size
();
++
i
,
++
it
)
data_
[
i
]
=
*
it
;
}
SymmetricMatrix
<
T
,
N
>&
operator
=
(
const
T
&
s
)
{
data_
=
s
;
return
*
this
;
}
SymmetricMatrix
<
T
,
N
>&
operator
*=
(
const
T
&
s
)
{
data_
*=
s
;
return
*
this
;
}
/** \brief Matrix style random read/write access to components
* \param i line index
* \param j column index
* \note You need to know what you are doing: You can only access the lower
* left triangular submatrix using this methods. It requires i>=j.
*/
T
&
operator
()
(
int
i
,
int
j
)
{
if
(
i
>=
j
)
return
data_
[
i
*
(
i
+
1
)
/
2
+
j
];
else
return
data_
[
j
*
(
j
+
1
)
/
2
+
i
];
}
/** \brief Matrix style random read access to components
* \param i line index
* \param j column index
* \note You need to know what you are doing: You can only access the lower
* left triangular submatrix using this methods. It requires i>=j.
*/
const
T
&
operator
()
(
int
i
,
int
j
)
const
{
if
(
i
>=
j
)
return
data_
[
i
*
(
i
+
1
)
/
2
+
j
];
else
return
data_
[
j
*
(
j
+
1
)
/
2
+
i
];
}
T
energyScalarProduct
(
const
FieldVector
<
T
,
N
>&
v1
,
const
FieldVector
<
T
,
N
>&
v2
)
const
{
T
result
=
0
;
for
(
size_t
i
=
0
;
i
<
N
;
i
++
)
for
(
size_t
j
=
0
;
j
<=
i
;
j
++
)
result
+=
(
1
-
0.5
*
(
i
==
j
))
*
operator
()(
i
,
j
)
*
(
v1
[
i
]
*
v2
[
j
]
+
v1
[
j
]
*
v2
[
i
]);
return
result
;
}
void
axpy
(
const
T
&
a
,
const
SymmetricMatrix
<
T
,
N
>&
other
)
{
data_
.
axpy
(
a
,
other
.
data_
);
}
Dune
::
FieldVector
<
T
,
N
*
(
N
+
1
)
/
2
>
data
()
const
{
return
data_
;
}
Dune
::
FieldVector
<
T
,
N
*
(
N
+
1
)
/
2
>&
data
()
{
return
data_
;
}
private
:
Dune
::
FieldVector
<
T
,
N
*
(
N
+
1
)
/
2
>
data_
;
};
}
#endif
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