Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaofan Chen
ogs
Commits
b548934e
Commit
b548934e
authored
2 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[T] Added tests for localDOF()
parent
aa89b823
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
Tests/NumLib/TestLocalDOF.cpp
+141
-0
141 additions, 0 deletions
Tests/NumLib/TestLocalDOF.cpp
with
141 additions
and
0 deletions
Tests/NumLib/TestLocalDOF.cpp
0 → 100644
+
141
−
0
View file @
b548934e
/**
* \file
*
* \copyright
* Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include
<gtest/gtest.h>
#include
<numeric>
#include
<random>
#include
"NumLib/DOF/LocalDOF.h"
static
double
testLocalDOFRandom
()
{
std
::
random_device
device
;
std
::
default_random_engine
engine
(
device
());
std
::
uniform_real_distribution
<
double
>
distribution
(
100
,
200
);
return
distribution
(
engine
);
}
template
<
unsigned
NPoints
>
struct
MockShapeFunction
{
static
constexpr
unsigned
NPOINTS
=
NPoints
;
};
TEST
(
NumLib_LocalDOF
,
Scalar
)
{
using
N1
=
MockShapeFunction
<
2
>
;
using
N2
=
MockShapeFunction
<
3
>
;
using
N3
=
MockShapeFunction
<
4
>
;
auto
const
value
=
testLocalDOFRandom
();
auto
const
x
=
Eigen
::
VectorXd
::
LinSpaced
(
9
,
value
,
value
+
8
).
eval
();
auto
const
[
x1
,
x2
,
x3
]
=
NumLib
::
localDOF
<
N1
,
N2
,
N3
>
(
x
);
#ifndef OGS_EIGEN_DYNAMIC_SHAPE_MATRICES
static_assert
(
decltype
(
x1
)
::
RowsAtCompileTime
==
2
);
static_assert
(
decltype
(
x2
)
::
RowsAtCompileTime
==
3
);
static_assert
(
decltype
(
x3
)
::
RowsAtCompileTime
==
4
);
#endif
ASSERT_EQ
(
x
.
rows
(),
x1
.
rows
()
+
x2
.
rows
()
+
x3
.
rows
());
ASSERT_EQ
(
2
,
x1
.
rows
());
ASSERT_EQ
(
3
,
x2
.
rows
());
ASSERT_EQ
(
4
,
x3
.
rows
());
EXPECT_DOUBLE_EQ
(
x
[
0
],
x1
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
1
],
x1
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
2
],
x2
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
3
],
x2
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
4
],
x2
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
5
],
x3
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
6
],
x3
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
7
],
x3
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
8
],
x3
[
3
]);
}
TEST
(
NumLib_LocalDOF
,
Vectorial
)
{
using
N1
=
MockShapeFunction
<
2
>
;
using
N2
=
MockShapeFunction
<
3
>
;
using
N3
=
MockShapeFunction
<
4
>
;
constexpr
auto
num_dof_total
=
2
+
3
*
2
+
4
;
// also works with std::vector
auto
const
value
=
testLocalDOFRandom
();
std
::
vector
<
double
>
x
(
num_dof_total
);
std
::
iota
(
x
.
begin
(),
x
.
end
(),
value
);
{
auto
const
[
x1
,
x2
,
x3
]
=
NumLib
::
localDOF
<
N1
,
NumLib
::
Vectorial
<
N2
,
2
>
,
N3
>
(
x
);
#ifndef OGS_EIGEN_DYNAMIC_SHAPE_MATRICES
static_assert
(
decltype
(
x1
)
::
RowsAtCompileTime
==
2
);
static_assert
(
decltype
(
x2
)
::
RowsAtCompileTime
==
3
*
2
);
static_assert
(
decltype
(
x3
)
::
RowsAtCompileTime
==
4
);
#endif
ASSERT_EQ
(
num_dof_total
,
x1
.
rows
()
+
x2
.
rows
()
+
x3
.
rows
());
ASSERT_EQ
(
2
,
x1
.
rows
());
ASSERT_EQ
(
3
*
2
,
x2
.
rows
());
ASSERT_EQ
(
4
,
x3
.
rows
());
EXPECT_DOUBLE_EQ
(
x
[
0
],
x1
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
1
],
x1
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
2
],
x2
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
3
],
x2
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
4
],
x2
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
5
],
x2
[
3
]);
EXPECT_DOUBLE_EQ
(
x
[
6
],
x2
[
4
]);
EXPECT_DOUBLE_EQ
(
x
[
7
],
x2
[
5
]);
EXPECT_DOUBLE_EQ
(
x
[
8
],
x3
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
9
],
x3
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
10
],
x3
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
11
],
x3
[
3
]);
}
// same but with vectorial d.o.f. first
{
auto
const
[
x1
,
x2
,
x3
]
=
NumLib
::
localDOF
<
NumLib
::
Vectorial
<
N2
,
2
>
,
N1
,
N3
>
(
x
);
#ifndef OGS_EIGEN_DYNAMIC_SHAPE_MATRICES
static_assert
(
decltype
(
x1
)
::
RowsAtCompileTime
==
3
*
2
);
static_assert
(
decltype
(
x2
)
::
RowsAtCompileTime
==
2
);
static_assert
(
decltype
(
x3
)
::
RowsAtCompileTime
==
4
);
#endif
ASSERT_EQ
(
num_dof_total
,
x1
.
rows
()
+
x2
.
rows
()
+
x3
.
rows
());
ASSERT_EQ
(
3
*
2
,
x1
.
rows
());
ASSERT_EQ
(
2
,
x2
.
rows
());
ASSERT_EQ
(
4
,
x3
.
rows
());
EXPECT_DOUBLE_EQ
(
x
[
0
],
x1
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
1
],
x1
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
2
],
x1
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
3
],
x1
[
3
]);
EXPECT_DOUBLE_EQ
(
x
[
4
],
x1
[
4
]);
EXPECT_DOUBLE_EQ
(
x
[
5
],
x1
[
5
]);
EXPECT_DOUBLE_EQ
(
x
[
6
],
x2
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
7
],
x2
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
8
],
x3
[
0
]);
EXPECT_DOUBLE_EQ
(
x
[
9
],
x3
[
1
]);
EXPECT_DOUBLE_EQ
(
x
[
10
],
x3
[
2
]);
EXPECT_DOUBLE_EQ
(
x
[
11
],
x3
[
3
]);
}
}
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