Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs-feliks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
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
Feliks Kiszkurno
ogs-feliks
Commits
c2182f91
Commit
c2182f91
authored
10 months ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[T] Added cell average unit test
parent
241a2737
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/ProcessLib/TestReflectIPData.cpp
+122
-0
122 additions, 0 deletions
Tests/ProcessLib/TestReflectIPData.cpp
with
122 additions
and
0 deletions
Tests/ProcessLib/TestReflectIPData.cpp
+
122
−
0
View file @
c2182f91
...
...
@@ -14,6 +14,8 @@
#include
<numeric>
#include
<random>
#include
"MeshToolsLib/MeshGenerators/MeshGenerator.h"
#include
"ProcessLib/Output/CellAverageData.h"
#include
"ProcessLib/Reflection/ReflectionIPData.h"
#include
"ProcessLib/Reflection/ReflectionSetIPData.h"
...
...
@@ -130,6 +132,8 @@ struct LocAsmIF
makeReflectionData
(
&
LocAsmIF
::
ip_data_level1
),
makeReflectionData
(
&
LocAsmIF
::
ip_data_level1b
)};
}
static
auto
getReflectionDataForOutput
()
{
return
reflect
();
}
};
template
<
int
dim
>
...
...
@@ -700,3 +704,121 @@ TYPED_TEST(ProcessLib_ReflectIPData, RawDataTypes)
static_assert
(
!
PRD
::
is_raw_data
<
Eigen
::
Matrix
<
double
,
kv_size
,
kv_size
>>::
value
);
}
TYPED_TEST
(
ProcessLib_ReflectIPData
,
CellAverageTest
)
{
constexpr
int
dim
=
TypeParam
::
value
;
auto
constexpr
kv_size
=
MathLib
::
KelvinVector
::
kelvin_vector_dimensions
(
dim
);
using
LocAsm
=
LocAsmIF
<
dim
>
;
std
::
size_t
const
num_int_pts
=
8
;
std
::
vector
<
std
::
unique_ptr
<
LocAsm
>>
loc_asms
;
loc_asms
.
push_back
(
std
::
make_unique
<
LocAsm
>
(
num_int_pts
));
auto
&
loc_asm
=
*
loc_asms
.
front
();
std
::
unique_ptr
<
MeshLib
::
Mesh
>
mesh
{
MeshToolsLib
::
MeshGenerator
::
generateLineMesh
(
1.0
,
1
)};
auto
const
ref
=
ReferenceData
<
dim
>::
create
(
*
loc_asms
.
front
(),
true
);
// compute cell average reference data /////////////////////////////////////
std
::
map
<
std
::
string
,
std
::
vector
<
double
>>
map_name_to_cell_average
;
ProcessLib
::
Reflection
::
forEachReflectedFlattenedIPDataAccessor
<
dim
,
LocAsm
>
(
LocAsm
::
reflect
(),
[
&
loc_asm
,
&
map_name_to_cell_average
](
std
::
string
const
&
name
,
unsigned
const
num_comp
,
auto
&&
double_vec_from_loc_asm
)
{
auto
[
it
,
emplaced
]
=
map_name_to_cell_average
.
emplace
(
name
,
num_comp
);
EXPECT_TRUE
(
emplaced
)
<<
'\''
<<
name
<<
"' seems to exist twice in the reflection data."
;
auto
const
&
ip_data
=
double_vec_from_loc_asm
(
loc_asm
);
ASSERT_EQ
(
num_int_pts
*
num_comp
,
ip_data
.
size
());
// TODO this implementation in the unit test might be too close to
// the production code. In fact, it's almost the same code.
// each integration point corresponds to a column in the mapped
// matrix, vector components/matrix entries are stored contiguously
// in memory.
Eigen
::
Map
<
const
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
ColMajor
>>
ip_data_mat
{
ip_data
.
data
(),
num_comp
,
num_int_pts
};
Eigen
::
Map
<
Eigen
::
VectorXd
>
cell_avg_vec
{
it
->
second
.
data
(),
num_comp
};
cell_avg_vec
=
ip_data_mat
.
rowwise
().
mean
();
});
// function under test /////////////////////////////////////////////////////
ProcessLib
::
CellAverageData
cell_average_data
{
*
mesh
};
cell_average_data
.
computeSecondaryVariable
(
dim
,
loc_asms
);
// checks //////////////////////////////////////////////////////////////////
auto
check
=
[
&
map_name_to_cell_average
,
&
mesh
](
std
::
string
const
&
name
,
unsigned
const
num_comp_expected
)
{
auto
const
it
=
map_name_to_cell_average
.
find
(
name
);
ASSERT_NE
(
map_name_to_cell_average
.
end
(),
it
)
<<
"No cell average reference data found for data with name '"
<<
name
<<
"'"
;
auto
const
&
cell_avg_expected
=
it
->
second
;
auto
const
&
props
=
mesh
->
getProperties
();
ASSERT_TRUE
(
props
.
existsPropertyVector
<
double
>
(
name
+
"_avg"
))
<<
"Property vector '"
<<
name
+
"_avg"
<<
"' does not exist in the mesh."
;
auto
const
&
cell_avg_actual
=
*
props
.
getPropertyVector
<
double
>
(
name
+
"_avg"
);
ASSERT_EQ
(
MeshLib
::
MeshItemType
::
Cell
,
cell_avg_actual
.
getMeshItemType
());
ASSERT_EQ
(
mesh
->
getNumberOfElements
(),
cell_avg_actual
.
getNumberOfTuples
());
ASSERT_EQ
(
num_comp_expected
,
cell_avg_actual
.
getNumberOfGlobalComponents
());
EXPECT_THAT
(
cell_avg_actual
,
testing
::
Pointwise
(
testing
::
DoubleEq
(),
cell_avg_expected
))
<<
"Values differ for cell average data with name '"
<<
name
<<
"'"
;
};
// level 0
check
(
"scalar"
,
1
);
check
(
"vector"
,
dim
);
check
(
"kelvin"
,
kv_size
);
// level 1
check
(
"scalar1"
,
1
);
check
(
"vector1"
,
dim
);
check
(
"kelvin1"
,
kv_size
);
// level 3
check
(
"scalar3"
,
1
);
check
(
"vector3"
,
dim
);
check
(
"kelvin3"
,
kv_size
);
check
(
"matrix3"
,
dim
*
4
);
check
(
"matrix3_1"
,
dim
*
4
);
check
(
"matrix3_2"
,
4
);
// b levels
check
(
"scalar1b"
,
1
);
check
(
"scalar2b"
,
1
);
check
(
"scalar3b"
,
1
);
}
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