Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redesign-prototype
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
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
Model registry
Operate
Terraform modules
Analyze
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
Nektar
redesign-prototype
Commits
e83c7bc5
Commit
e83c7bc5
authored
1 year ago
by
Chris Cantwell
Browse files
Options
Downloads
Plain Diff
Merge branch 'compare_fields' into 'master'
Add a `Field::compare` method See merge request
!9
parents
142c6bd4
7e8f4042
No related branches found
Branches containing commit
Tags
v4.3.4
Tags containing commit
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Field.hpp
+33
-0
33 additions, 0 deletions
Field.hpp
tests/init_fields.hpp
+3
-0
3 additions, 0 deletions
tests/init_fields.hpp
tests/test_bwdtrans.cpp
+23
-3
23 additions, 3 deletions
tests/test_bwdtrans.cpp
with
59 additions
and
3 deletions
Field.hpp
+
33
−
0
View file @
e83c7bc5
...
@@ -99,6 +99,39 @@ public:
...
@@ -99,6 +99,39 @@ public:
return
*
this
;
return
*
this
;
}
}
/**
* @brief Compare this field to another field, with absolute
* tolerance tol.
* @return bool
*/
bool
compare
(
Field
<
TType
,
TState
>
&
rhs
,
double
tol
)
{
const
std
::
vector
<
BlockAttributes
>&
rhs_blocks
=
rhs
.
GetBlocks
();
TType
*
store
=
GetStorage
().
GetCPUPtr
();
TType
*
rhs_store
=
rhs
.
GetStorage
().
GetCPUPtr
();
if
(
rhs_blocks
.
size
()
!=
block_attributes
.
size
())
return
false
;
size_t
i
{
0
};
for
(
size_t
bl
=
0
;
bl
<
block_attributes
.
size
();
++
bl
){
size_t
num_elements
=
block_attributes
[
bl
].
num_elements
;
size_t
num_pts
=
block_attributes
[
bl
].
num_pts
;
// Check that each block have the same structure
if
(
num_elements
!=
rhs_blocks
[
bl
].
num_elements
)
return
false
;
if
(
num_pts
!=
rhs_blocks
[
bl
].
num_pts
)
return
false
;
// Compare elements in the blocks
for
(
size_t
el
=
0
;
el
<
num_elements
;
++
el
)
{
for
(
size_t
coeff
=
0
;
coeff
<
num_pts
;
++
coeff
)
{
i
=
coeff
+
el
*
num_pts
+
bl
*
num_pts
*
num_elements
;
if
(
std
::
abs
(
store
[
i
]
-
rhs_store
[
i
])
>
tol
)
return
false
;
}
}
}
return
true
;
}
/**
/**
* @brief Static templated creation method.
* @brief Static templated creation method.
*
*
...
...
This diff is collapsed.
Click to expand it.
tests/init_fields.hpp
+
3
−
0
View file @
e83c7bc5
...
@@ -32,6 +32,7 @@ class InitFields
...
@@ -32,6 +32,7 @@ class InitFields
public:
public:
Field
<
double
,
stateIn
>
*
fixt_in
;
Field
<
double
,
stateIn
>
*
fixt_in
;
Field
<
double
,
stateOut
>
*
fixt_out
;
Field
<
double
,
stateOut
>
*
fixt_out
;
Field
<
double
,
stateOut
>
*
fixt_expected
;
MultiRegions
::
ExpListSharedPtr
fixt_explist
{
nullptr
};
MultiRegions
::
ExpListSharedPtr
fixt_explist
{
nullptr
};
~
InitFields
()
~
InitFields
()
{
{
...
@@ -67,8 +68,10 @@ public:
...
@@ -67,8 +68,10 @@ public:
// Create two Field objects with a MemoryRegionCPU backend by default
// Create two Field objects with a MemoryRegionCPU backend by default
auto
f_in
=
Field
<
double
,
stateIn
>::
create
(
blocks_in
);
auto
f_in
=
Field
<
double
,
stateIn
>::
create
(
blocks_in
);
auto
f_out
=
Field
<
double
,
stateOut
>::
create
(
blocks_out
);
auto
f_out
=
Field
<
double
,
stateOut
>::
create
(
blocks_out
);
auto
f_expected
=
Field
<
double
,
stateOut
>::
create
(
blocks_out
);
fixt_in
=
new
Field
<
double
,
stateIn
>
(
std
::
move
(
f_in
));
fixt_in
=
new
Field
<
double
,
stateIn
>
(
std
::
move
(
f_in
));
fixt_out
=
new
Field
<
double
,
stateOut
>
(
std
::
move
(
f_out
));
fixt_out
=
new
Field
<
double
,
stateOut
>
(
std
::
move
(
f_out
));
fixt_expected
=
new
Field
<
double
,
stateOut
>
(
std
::
move
(
f_expected
));
}
}
protected
:
protected
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_bwdtrans.cpp
+
23
−
3
View file @
e83c7bc5
...
@@ -63,8 +63,28 @@ BOOST_FIXTURE_TEST_CASE(bwdtrans, Line)
...
@@ -63,8 +63,28 @@ BOOST_FIXTURE_TEST_CASE(bwdtrans, Line)
}
}
}
}
BwdTrans
<>::
create
(
fixt_explist
,
"StdMat"
)
->
apply
(
*
fixt_in
,
*
fixt_out
);
// TODO: Initialise expected solution
x
=
fixt_expected
->
GetStorage
().
GetCPUPtr
();
double
*
y
=
fixt_out
->
GetStorage
().
GetCPUPtr
();
// For each element, initialise first coefficient to zero and rest
BOOST_TEST
(
y
[
0
]
==
1.0
);
// to 1.
for
(
auto
const
&
block
:
fixt_expected
->
GetBlocks
())
{
for
(
size_t
el
=
0
;
el
<
block
.
num_elements
;
++
el
)
{
for
(
size_t
coeff
=
0
;
coeff
<
block
.
num_pts
;
++
coeff
)
{
if
(
coeff
==
0
)
{
*
(
x
++
)
=
1.0
;
}
else
{
*
(
x
++
)
=
0.0
;
}
}
}
}
BwdTrans
<>::
create
(
fixt_explist
,
"StdMat"
)
->
apply
(
*
fixt_in
,
*
fixt_out
);
double
TOL
{
0.01
};
BOOST_TEST
(
fixt_out
->
compare
(
*
fixt_expected
,
TOL
));
}
}
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