Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
8053ee82
There was an error fetching the commit references. Please try again later.
Commit
8053ee82
authored
6 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
tnl-diff exact-match tells coordinates of mismatches.
parent
75a4ea7a
No related branches found
No related tags found
1 merge request
!26
Lbm
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tools/tnl-diff.h
+210
-50
210 additions, 50 deletions
src/Tools/tnl-diff.h
with
210 additions
and
50 deletions
src/Tools/tnl-diff.h
+
210
−
50
View file @
8053ee82
...
...
@@ -20,6 +20,163 @@
using
namespace
TNL
;
template
<
typename
MeshFunction
,
typename
Mesh
=
typename
MeshFunction
::
MeshType
,
int
EntitiesDimension
=
MeshFunction
::
getEntitiesDimension
()
>
class
ExactMatchTest
{
public:
static
void
run
(
const
MeshFunction
&
f1
,
const
MeshFunction
&
f2
,
const
String
&
f1Name
,
const
String
&
f2Name
,
std
::
fstream
&
outputFile
,
bool
verbose
=
false
)
{
TNL_ASSERT
(
false
,
"Not implemented yet."
);
}
};
template
<
typename
MeshFunction
,
typename
Real
,
typename
Device
,
typename
Index
>
class
ExactMatchTest
<
MeshFunction
,
Meshes
::
Grid
<
1
,
Real
,
Device
,
Index
>
,
1
>
{
public:
static
void
run
(
const
MeshFunction
&
f1
,
const
MeshFunction
&
f2
,
const
String
&
f1Name
,
const
String
&
f2Name
,
std
::
fstream
&
outputFile
,
bool
verbose
=
false
)
{
const
int
Dimension
=
1
;
const
int
EntityDimension
=
1
;
using
Grid
=
Meshes
::
Grid
<
Dimension
,
Real
,
Device
,
Index
>
;
using
Entity
=
typename
Grid
::
template
EntityType
<
EntityDimension
>;
if
(
f1
.
getMesh
().
getDimensions
()
!=
f2
.
getMesh
().
getDimensions
()
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
}
Entity
entity
(
f1
.
getMesh
()
);
for
(
entity
.
getCoordinates
().
x
()
=
0
;
entity
.
getCoordinates
().
x
()
<
f1
.
getMesh
().
getDimensions
().
x
();
entity
.
getCoordinates
().
x
()
++
)
{
entity
.
refresh
();
if
(
f1
.
getValue
(
entity
)
!=
f2
.
getValue
(
entity
)
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
}
}
}
};
template
<
typename
MeshFunction
,
typename
Real
,
typename
Device
,
typename
Index
>
class
ExactMatchTest
<
MeshFunction
,
Meshes
::
Grid
<
2
,
Real
,
Device
,
Index
>
,
2
>
{
public:
static
void
run
(
const
MeshFunction
&
f1
,
const
MeshFunction
&
f2
,
const
String
&
f1Name
,
const
String
&
f2Name
,
std
::
fstream
&
outputFile
,
bool
verbose
=
false
)
{
const
int
Dimension
=
2
;
const
int
EntityDimension
=
2
;
using
Grid
=
Meshes
::
Grid
<
Dimension
,
Real
,
Device
,
Index
>
;
using
Entity
=
typename
Grid
::
template
EntityType
<
EntityDimension
>;
if
(
f1
.
getMesh
().
getDimensions
()
!=
f2
.
getMesh
().
getDimensions
()
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
}
Entity
entity
(
f1
.
getMesh
()
);
for
(
entity
.
getCoordinates
().
y
()
=
0
;
entity
.
getCoordinates
().
y
()
<
f1
.
getMesh
().
getDimensions
().
y
();
entity
.
getCoordinates
().
y
()
++
)
for
(
entity
.
getCoordinates
().
x
()
=
0
;
entity
.
getCoordinates
().
x
()
<
f1
.
getMesh
().
getDimensions
().
x
();
entity
.
getCoordinates
().
x
()
++
)
{
entity
.
refresh
();
if
(
f1
.
getValue
(
entity
)
!=
f2
.
getValue
(
entity
)
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
}
}
}
};
template
<
typename
MeshFunction
,
typename
Real
,
typename
Device
,
typename
Index
>
class
ExactMatchTest
<
MeshFunction
,
Meshes
::
Grid
<
3
,
Real
,
Device
,
Index
>
,
3
>
{
public:
static
void
run
(
const
MeshFunction
&
f1
,
const
MeshFunction
&
f2
,
const
String
&
f1Name
,
const
String
&
f2Name
,
std
::
fstream
&
outputFile
,
bool
verbose
=
false
)
{
const
int
Dimension
=
3
;
const
int
EntityDimension
=
3
;
using
Grid
=
Meshes
::
Grid
<
Dimension
,
Real
,
Device
,
Index
>
;
using
Entity
=
typename
Grid
::
template
EntityType
<
EntityDimension
>;
if
(
f1
.
getMesh
().
getDimensions
()
!=
f2
.
getMesh
().
getDimensions
()
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" are defined on different meshes. "
<<
std
::
endl
;
}
Entity
entity
(
f1
.
getMesh
()
);
for
(
entity
.
getCoordinates
().
z
()
=
0
;
entity
.
getCoordinates
().
z
()
<
f1
.
getMesh
().
getDimensions
().
z
();
entity
.
getCoordinates
().
z
()
++
)
for
(
entity
.
getCoordinates
().
y
()
=
0
;
entity
.
getCoordinates
().
y
()
<
f1
.
getMesh
().
getDimensions
().
y
();
entity
.
getCoordinates
().
y
()
++
)
for
(
entity
.
getCoordinates
().
x
()
=
0
;
entity
.
getCoordinates
().
x
()
<
f1
.
getMesh
().
getDimensions
().
x
();
entity
.
getCoordinates
().
x
()
++
)
{
entity
.
refresh
();
if
(
f1
.
getValue
(
entity
)
!=
f2
.
getValue
(
entity
)
)
{
outputFile
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
if
(
verbose
)
std
::
cout
<<
f1Name
<<
" and "
<<
f2Name
<<
" differs at "
<<
entity
.
getCoordinates
()
<<
" "
<<
f1
.
getValue
(
entity
)
<<
" != "
<<
f2
.
getValue
(
entity
)
<<
std
::
endl
;
}
}
}
};
template
<
typename
MeshPointer
,
typename
Value
,
typename
Real
,
typename
Index
>
bool
computeDifferenceOfMeshFunctions
(
const
MeshPointer
&
meshPointer
,
const
Config
::
ParameterContainer
&
parameters
)
{
...
...
@@ -38,20 +195,24 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con
std
::
cerr
<<
"Unable to open the file "
<<
outputFileName
<<
"."
<<
std
::
endl
;
return
false
;
}
outputFile
<<
"#"
;
outputFile
<<
std
::
setw
(
6
)
<<
"Time"
;
outputFile
<<
std
::
setw
(
18
)
<<
"L1 diff."
<<
std
::
setw
(
18
)
<<
"L2 diff."
<<
std
::
setw
(
18
)
<<
"Max. diff."
<<
std
::
setw
(
18
)
<<
"Total L1 diff."
<<
std
::
setw
(
18
)
<<
"Total L2 diff."
<<
std
::
setw
(
18
)
<<
"Total Max. diff."
<<
std
::
endl
;
if
(
!
exactMatch
)
{
outputFile
<<
"#"
;
outputFile
<<
std
::
setw
(
6
)
<<
"Time"
;
outputFile
<<
std
::
setw
(
18
)
<<
"L1 diff."
<<
std
::
setw
(
18
)
<<
"L2 diff."
<<
std
::
setw
(
18
)
<<
"Max. diff."
<<
std
::
setw
(
18
)
<<
"Total L1 diff."
<<
std
::
setw
(
18
)
<<
"Total L2 diff."
<<
std
::
setw
(
18
)
<<
"Total Max. diff."
<<
std
::
endl
;
}
if
(
verbose
)
std
::
cout
<<
std
::
endl
;
typedef
typename
MeshPointer
::
ObjectType
Mesh
;
Functions
::
MeshFunction
<
Mesh
,
Mesh
::
getMeshDimension
(),
Real
>
v1
(
meshPointer
),
v2
(
meshPointer
),
diff
(
meshPointer
);
using
MeshFunctionType
=
Functions
::
MeshFunction
<
Mesh
,
Mesh
::
getMeshDimension
(),
Real
>
;
MeshFunctionType
v1
(
meshPointer
),
v2
(
meshPointer
),
diff
(
meshPointer
);
Real
totalL1Diff
(
0.0
),
totalL2Diff
(
0.0
),
totalMaxDiff
(
0.0
);
for
(
int
i
=
0
;
i
<
(
int
)
inputFiles
.
size
();
i
++
)
{
...
...
@@ -73,7 +234,8 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con
outputFile
.
close
();
return
false
;
}
outputFile
<<
std
::
setw
(
6
)
<<
i
/
2
*
snapshotPeriod
<<
" "
;
if
(
!
exactMatch
)
outputFile
<<
std
::
setw
(
6
)
<<
i
/
2
*
snapshotPeriod
<<
" "
;
file1
=
inputFiles
[
i
];
file2
=
inputFiles
[
i
+
1
];
i
++
;
...
...
@@ -100,7 +262,8 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con
outputFile
.
close
();
return
false
;
}
outputFile
<<
std
::
setw
(
6
)
<<
(
i
-
1
)
*
snapshotPeriod
<<
" "
;
if
(
!
exactMatch
)
outputFile
<<
std
::
setw
(
6
)
<<
(
i
-
1
)
*
snapshotPeriod
<<
" "
;
file2
=
inputFiles
[
i
];
}
if
(
mode
==
"halves"
)
...
...
@@ -118,52 +281,49 @@ bool computeDifferenceOfMeshFunctions( const MeshPointer& meshPointer, const Con
return
false
;
}
//if( snapshotPeriod != 0.0 )
outputFile
<<
std
::
setw
(
6
)
<<
(
i
-
half
)
*
snapshotPeriod
<<
" "
;
if
(
!
exactMatch
)
outputFile
<<
std
::
setw
(
6
)
<<
(
i
-
half
)
*
snapshotPeriod
<<
" "
;
file1
=
inputFiles
[
i
-
half
];
file2
=
inputFiles
[
i
];
}
diff
=
v1
;
diff
-=
v2
;
if
(
exactMatch
)
{
for
(
Index
i
=
0
;
i
<
diff
.
getData
().
getSize
();
i
++
)
if
(
diff
[
i
]
!=
0
)
{
outputFile
<<
file1
<<
" and "
<<
file2
<<
"differs at position "
<<
i
<<
std
::
endl
;
}
}
Real
l1Diff
=
diff
.
getLpNorm
(
1.0
);
Real
l2Diff
=
diff
.
getLpNorm
(
2.0
);
Real
maxDiff
=
diff
.
getMaxNorm
();
if
(
snapshotPeriod
!=
0.0
)
{
totalL1Diff
+=
snapshotPeriod
*
l1Diff
;
totalL2Diff
+=
snapshotPeriod
*
l2Diff
*
l2Diff
;
}
ExactMatchTest
<
MeshFunctionType
>::
run
(
v1
,
v2
,
file1
,
file2
,
outputFile
,
verbose
);
else
{
totalL1Diff
+=
l1Diff
;
totalL2Diff
+=
l2Diff
*
l2Diff
;
}
totalMaxDiff
=
max
(
totalMaxDiff
,
maxDiff
);
outputFile
<<
std
::
setw
(
18
)
<<
l1Diff
<<
std
::
setw
(
18
)
<<
l2Diff
<<
std
::
setw
(
18
)
<<
maxDiff
<<
std
::
setw
(
18
)
<<
totalL1Diff
<<
std
::
setw
(
18
)
<<
::
sqrt
(
totalL2Diff
)
<<
std
::
setw
(
18
)
<<
totalMaxDiff
<<
std
::
endl
;
if
(
writeDifference
)
{
String
differenceFileName
;
differenceFileName
=
inputFiles
[
i
];
removeFileExtension
(
differenceFileName
);
differenceFileName
+=
".diff.tnl"
;
//diff.setLike( v1 );
diff
=
v1
;
diff
-=
v2
;
diff
.
save
(
differenceFileName
);
Real
l1Diff
=
diff
.
getLpNorm
(
1.0
);
Real
l2Diff
=
diff
.
getLpNorm
(
2.0
);
Real
maxDiff
=
diff
.
getMaxNorm
();
if
(
snapshotPeriod
!=
0.0
)
{
totalL1Diff
+=
snapshotPeriod
*
l1Diff
;
totalL2Diff
+=
snapshotPeriod
*
l2Diff
*
l2Diff
;
}
else
{
totalL1Diff
+=
l1Diff
;
totalL2Diff
+=
l2Diff
*
l2Diff
;
}
totalMaxDiff
=
max
(
totalMaxDiff
,
maxDiff
);
outputFile
<<
std
::
setw
(
18
)
<<
l1Diff
<<
std
::
setw
(
18
)
<<
l2Diff
<<
std
::
setw
(
18
)
<<
maxDiff
<<
std
::
setw
(
18
)
<<
totalL1Diff
<<
std
::
setw
(
18
)
<<
::
sqrt
(
totalL2Diff
)
<<
std
::
setw
(
18
)
<<
totalMaxDiff
<<
std
::
endl
;
if
(
writeDifference
)
{
String
differenceFileName
;
differenceFileName
=
inputFiles
[
i
];
removeFileExtension
(
differenceFileName
);
differenceFileName
+=
".diff.tnl"
;
//diff.setLike( v1 );
diff
=
v1
;
diff
-=
v2
;
diff
.
save
(
differenceFileName
);
}
}
}
outputFile
.
close
();
...
...
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