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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
b77081bc
Commit
b77081bc
authored
Mar 10, 2022
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add a few attributes to ItemValue and precise error messages
parent
6d796584
No related branches found
No related tags found
1 merge request
!133
Simplify access functions to the number of items
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mesh/ItemArray.hpp
+14
-16
14 additions, 16 deletions
src/mesh/ItemArray.hpp
tests/test_ItemArray.cpp
+41
-9
41 additions, 9 deletions
tests/test_ItemArray.cpp
with
55 additions
and
25 deletions
src/mesh/ItemArray.hpp
+
14
−
16
View file @
b77081bc
...
...
@@ -43,7 +43,7 @@ class ItemArray
friend
ItemArray
<
std
::
remove_const_t
<
DataType
>
,
item_type
,
ConnectivityWeakPtr
>
;
public
:
friend
PUGS_INLINE
ItemArray
<
std
::
remove_const_t
<
DataType
>
,
item_type
,
ConnectivityPtr
>
[[
nodiscard
]]
friend
PUGS_INLINE
ItemArray
<
std
::
remove_const_t
<
DataType
>
,
item_type
,
ConnectivityPtr
>
copy
(
const
ItemArray
<
DataType
,
item_type
,
ConnectivityPtr
>&
source
)
{
ItemArray
<
std
::
remove_const_t
<
DataType
>
,
item_type
,
ConnectivityPtr
>
image
;
...
...
@@ -62,19 +62,18 @@ class ItemArray
copy_to
(
const
ItemArray
<
DataType
,
item_type
,
ConnectivityPtr
>&
source
,
const
ItemArray
<
std
::
remove_const_t
<
DataType
>
,
item_type
,
ConnectivityPtr2
>&
destination
)
{
Assert
(
destination
.
connectivity_ptr
()
==
source
.
connectivity_ptr
());
Assert
(
destination
.
connectivity_ptr
()
==
source
.
connectivity_ptr
(),
"different connectivities"
);
Assert
(
source
.
sizeOfArrays
()
==
destination
.
sizeOfArrays
(),
"incompatible size of arrays"
)
copy_to
(
source
.
m_values
,
destination
.
m_values
);
}
PUGS_INLINE
bool
[[
nodiscard
]]
PUGS_INLINE
bool
isBuilt
()
const
noexcept
{
return
m_connectivity_ptr
.
use_count
()
!=
0
;
}
PUGS_INLINE
std
::
shared_ptr
<
const
IConnectivity
>
[[
nodiscard
]]
PUGS_INLINE
std
::
shared_ptr
<
const
IConnectivity
>
connectivity_ptr
()
const
noexcept
{
if
constexpr
(
std
::
is_same_v
<
ConnectivityPtr
,
ConnectivitySharedPtr
>
)
{
...
...
@@ -93,27 +92,26 @@ class ItemArray
}
template
<
ItemType
item_t
>
PUGS_INLINE
typename
Table
<
DataType
>::
UnsafeRowView
[[
nodiscard
]]
PUGS_INLINE
typename
Table
<
DataType
>::
UnsafeRowView
operator
[](
const
ItemIdT
<
item_t
>&
item_id
)
const
noexcept
(
NO_ASSERT
)
{
static_assert
(
item_t
==
item_type
,
"invalid ItemId type"
);
Assert
(
this
->
isBuilt
());
Assert
(
this
->
isBuilt
(),
"ItemArray is not built"
);
Assert
(
item_id
<
this
->
numberOfItems
(),
"invalid item_id"
);
return
m_values
[
item_id
];
}
PUGS_INLINE
size_t
[[
nodiscard
]]
PUGS_INLINE
size_t
numberOfItems
()
const
noexcept
(
NO_ASSERT
)
{
Assert
(
this
->
isBuilt
());
Assert
(
this
->
isBuilt
()
,
"ItemArray is not built"
);
return
m_values
.
numberOfRows
();
}
PUGS_INLINE
size_t
[[
nodiscard
]]
PUGS_INLINE
size_t
sizeOfArrays
()
const
{
Assert
(
this
->
isBuilt
());
Assert
(
this
->
isBuilt
()
,
"ItemArray is not built"
);
return
m_values
.
numberOfColumns
();
}
...
...
@@ -169,7 +167,7 @@ class ItemArray
ItemArray
(
const
IConnectivity
&
connectivity
,
const
Table
<
DataType
>&
table
)
noexcept
(
NO_ASSERT
)
:
m_connectivity_ptr
{
connectivity
.
shared_ptr
()},
m_values
{
table
}
{
Assert
(
connectivity
.
numberOf
<
item_type
>
()
==
table
.
numberOfRows
(),
"
I
nvalid table, wrong number of rows"
);
Assert
(
connectivity
.
numberOf
<
item_type
>
()
==
table
.
numberOfRows
(),
"
i
nvalid table, wrong number of rows"
);
}
PUGS_INLINE
...
...
This diff is collapsed.
Click to expand it.
tests/test_ItemArray.cpp
+
41
−
9
View file @
b77081bc
...
...
@@ -297,16 +297,16 @@ TEST_CASE("ItemArray", "[mesh]")
SECTION
(
"checking for build ItemArray"
)
{
CellArray
<
int
>
cell_array
;
REQUIRE_THROWS_
AS
(
cell_array
[
CellId
{
0
}],
AssertError
);
REQUIRE_THROWS_
WITH
(
cell_array
[
CellId
{
0
}],
"ItemArray is not built"
);
FaceArray
<
int
>
face_array
;
REQUIRE_THROWS_
AS
(
face_array
[
FaceId
{
0
}],
AssertError
);
REQUIRE_THROWS_
WITH
(
face_array
[
FaceId
{
0
}],
"ItemArray is not built"
);
EdgeArray
<
int
>
edge_array
;
REQUIRE_THROWS_
AS
(
edge_array
[
EdgeId
{
0
}],
AssertError
);
REQUIRE_THROWS_
WITH
(
edge_array
[
EdgeId
{
0
}],
"ItemArray is not built"
);
NodeArray
<
int
>
node_array
;
REQUIRE_THROWS_
AS
(
node_array
[
NodeId
{
0
}],
AssertError
);
REQUIRE_THROWS_
WITH
(
node_array
[
NodeId
{
0
}],
"ItemArray is not built"
);
}
SECTION
(
"checking for bounds violation"
)
...
...
@@ -322,19 +322,19 @@ TEST_CASE("ItemArray", "[mesh]")
CellArray
<
int
>
cell_array
{
connectivity
,
1
};
CellId
invalid_cell_id
=
connectivity
.
numberOfCells
();
REQUIRE_THROWS_
AS
(
cell_array
[
invalid_cell_id
],
AssertError
);
REQUIRE_THROWS_
WITH
(
cell_array
[
invalid_cell_id
],
"invalid item_id"
);
FaceArray
<
int
>
face_array
{
connectivity
,
2
};
FaceId
invalid_face_id
=
connectivity
.
numberOfFaces
();
REQUIRE_THROWS_
AS
(
face_array
[
invalid_face_id
],
AssertError
);
REQUIRE_THROWS_
WITH
(
face_array
[
invalid_face_id
],
"invalid item_id"
);
EdgeArray
<
int
>
edge_array
{
connectivity
,
1
};
EdgeId
invalid_edge_id
=
connectivity
.
numberOfEdges
();
REQUIRE_THROWS_
AS
(
edge_array
[
invalid_edge_id
],
AssertError
);
REQUIRE_THROWS_
WITH
(
edge_array
[
invalid_edge_id
],
"invalid item_id"
);
NodeArray
<
int
>
node_array
{
connectivity
,
0
};
NodeId
invalid_node_id
=
connectivity
.
numberOfNodes
();
REQUIRE_THROWS_
AS
(
node_array
[
invalid_node_id
],
AssertError
);
REQUIRE_THROWS_
WITH
(
node_array
[
invalid_node_id
],
"invalid item_id"
);
}
}
}
...
...
@@ -351,7 +351,39 @@ TEST_CASE("ItemArray", "[mesh]")
const
Connectivity
<
3
>&
connectivity
=
mesh_3d
->
connectivity
();
Table
<
size_t
>
values
{
connectivity
.
numberOfCells
()
+
3
,
3
};
REQUIRE_THROWS_WITH
(
CellArray
<
size_t
>
(
connectivity
,
values
),
"Invalid table, wrong number of rows"
);
REQUIRE_THROWS_WITH
(
CellArray
<
size_t
>
(
connectivity
,
values
),
"invalid table, wrong number of rows"
);
}
}
}
SECTION
(
"invalid copy_to"
)
{
std
::
array
mesh_list
=
MeshDataBaseForTests
::
get
().
all2DMeshes
();
for
(
auto
named_mesh
:
mesh_list
)
{
SECTION
(
named_mesh
.
name
())
{
auto
mesh_2d
=
named_mesh
.
mesh
();
const
Connectivity
<
2
>&
connectivity_2d
=
mesh_2d
->
connectivity
();
std
::
array
mesh_list
=
MeshDataBaseForTests
::
get
().
all3DMeshes
();
for
(
auto
named_mesh
:
mesh_list
)
{
SECTION
(
named_mesh
.
name
())
{
auto
mesh_3d
=
named_mesh
.
mesh
();
const
Connectivity
<
3
>&
connectivity_3d
=
mesh_3d
->
connectivity
();
CellArray
<
int
>
cell_2d_array
{
connectivity_2d
,
3
};
CellArray
<
int
>
cell_3d_array
{
connectivity_3d
,
3
};
REQUIRE_THROWS_WITH
(
copy_to
(
cell_2d_array
,
cell_3d_array
),
"different connectivities"
);
CellArray
<
int
>
cell_2d_array2
{
connectivity_2d
,
2
};
REQUIRE_THROWS_WITH
(
copy_to
(
cell_2d_array
,
cell_2d_array2
),
"incompatible size of arrays"
);
}
}
}
}
}
...
...
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