Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
code
pugs
Commits
ba56a8dd
Commit
ba56a8dd
authored
3 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for PETScUtils
parent
d39ce5a2
No related branches found
No related tags found
1 merge request
!103
Set AssertError to inherit from std::runtime_error
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_PETScUtils.cpp
+117
-0
117 additions, 0 deletions
tests/test_PETScUtils.cpp
with
118 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
ba56a8dd
...
@@ -86,6 +86,7 @@ add_executable (unit_tests
...
@@ -86,6 +86,7 @@ add_executable (unit_tests
test_NameProcessor.cpp
test_NameProcessor.cpp
test_OStreamProcessor.cpp
test_OStreamProcessor.cpp
test_ParseError.cpp
test_ParseError.cpp
test_PETScUtils.cpp
test_PugsAssert.cpp
test_PugsAssert.cpp
test_PugsFunctionAdapter.cpp
test_PugsFunctionAdapter.cpp
test_PugsUtils.cpp
test_PugsUtils.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_PETScUtils.cpp
0 → 100644
+
117
−
0
View file @
ba56a8dd
#include
<utils/pugs_config.hpp>
#ifdef PUGS_HAS_PETSC
#include
<catch2/catch_test_macros.hpp>
#include
<catch2/matchers/catch_matchers_all.hpp>
#include
<algebra/PETScUtils.hpp>
#include
<algebra/CRSMatrixDescriptor.hpp>
// clazy:excludeall=non-pod-global-static
TEST_CASE
(
"PETScUtils"
,
"[algebra]"
)
{
SECTION
(
"PETScAijMatrixEmbedder"
)
{
SECTION
(
"from TinyMatrix"
)
{
TinyMatrix
<
3
>
A
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
PETScAijMatrixEmbedder
petsc_A
{
A
};
for
(
size_t
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
double
value
=
0
;
MatGetValue
(
petsc_A
,
i
,
j
,
&
value
);
REQUIRE
(
value
==
1
+
i
*
3
+
j
);
}
}
}
SECTION
(
"from DenseMatrix"
)
{
DenseMatrix
<
double
>
A
(
3
,
3
);
for
(
size_t
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
A
(
i
,
j
)
=
1
+
i
*
3
+
j
;
}
}
PETScAijMatrixEmbedder
petsc_A
{
A
};
REQUIRE
(
petsc_A
.
numberOfRows
()
==
3
);
REQUIRE
(
petsc_A
.
numberOfColumns
()
==
3
);
for
(
size_t
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
double
value
;
MatGetValue
(
petsc_A
,
i
,
j
,
&
value
);
REQUIRE
(
value
==
1
+
i
*
3
+
j
);
}
}
}
SECTION
(
"from DenseMatrix [non-square]"
)
{
DenseMatrix
<
double
>
A
(
4
,
3
);
for
(
size_t
i
=
0
;
i
<
4
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
A
(
i
,
j
)
=
1
+
i
*
3
+
j
;
}
}
PETScAijMatrixEmbedder
petsc_A
{
A
};
REQUIRE
(
petsc_A
.
numberOfRows
()
==
4
);
REQUIRE
(
petsc_A
.
numberOfColumns
()
==
3
);
for
(
size_t
i
=
0
;
i
<
4
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
double
value
=
0
;
MatGetValue
(
petsc_A
,
i
,
j
,
&
value
);
REQUIRE
(
value
==
1
+
i
*
3
+
j
);
}
}
}
}
SECTION
(
"from CRSMatrix"
)
{
Array
<
int
>
non_zeros
(
4
);
non_zeros
[
0
]
=
1
;
non_zeros
[
1
]
=
2
;
non_zeros
[
2
]
=
3
;
non_zeros
[
3
]
=
2
;
CRSMatrixDescriptor
<
double
,
int
>
A
(
4
,
3
,
non_zeros
);
A
(
0
,
0
)
=
1
;
A
(
1
,
0
)
=
2
;
A
(
1
,
2
)
=
3
;
A
(
2
,
0
)
=
4
;
A
(
2
,
1
)
=
5
;
A
(
2
,
2
)
=
6
;
A
(
3
,
1
)
=
7
;
A
(
3
,
2
)
=
8
;
PETScAijMatrixEmbedder
petsc_A
{
A
.
getCRSMatrix
()};
auto
get_value
=
[
&
](
int
i
,
int
j
)
{
double
value
;
MatGetValue
(
petsc_A
,
i
,
j
,
&
value
);
return
value
;
};
REQUIRE
(
get_value
(
0
,
0
)
==
1
);
REQUIRE
(
get_value
(
1
,
0
)
==
2
);
REQUIRE
(
get_value
(
1
,
2
)
==
3
);
REQUIRE
(
get_value
(
2
,
0
)
==
4
);
REQUIRE
(
get_value
(
2
,
1
)
==
5
);
REQUIRE
(
get_value
(
2
,
2
)
==
6
);
REQUIRE
(
get_value
(
3
,
1
)
==
7
);
REQUIRE
(
get_value
(
3
,
2
)
==
8
);
}
}
#endif // PUGS_HAS_PETSC
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