Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
074f8e52
Commit
074f8e52
authored
May 23, 2018
by
Praetorius, Simon
Browse files
resolved merge conflict
parents
9a807d6d
64766b4e
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/amdis/AdaptInfo.cpp
View file @
074f8e52
#include
"AdaptInfo.hpp"
// std c++ headers
#include
<string>
#include
<iostream>
#include
<string>
#include
<amdis/Initfile.hpp>
...
...
@@ -16,8 +16,6 @@ namespace AMDiS
Parameters
::
get
(
prefix
+
"->time relative tolerance"
,
timeRelativeTolerance
);
Parameters
::
get
(
prefix
+
"->coarsen allowed"
,
coarsenAllowed
);
Parameters
::
get
(
prefix
+
"->refinement allowed"
,
refinementAllowed
);
Parameters
::
get
(
prefix
+
"->refine bisections"
,
refineBisections
);
Parameters
::
get
(
prefix
+
"->coarsen bisections"
,
coarseBisections
);
Parameters
::
get
(
prefix
+
"->sum factor"
,
fac_sum
);
Parameters
::
get
(
prefix
+
"->max factor"
,
fac_max
);
...
...
@@ -27,7 +25,7 @@ namespace AMDiS
}
AdaptInfo
::
AdaptInfo
(
std
::
string
name
,
int
size
)
AdaptInfo
::
AdaptInfo
(
std
::
string
name
)
:
name
(
name
)
{
// init();
...
...
@@ -43,37 +41,24 @@ namespace AMDiS
Parameters
::
get
(
name
+
"->max timestep"
,
maxTimestep
);
Parameters
::
get
(
name
+
"->number of timesteps"
,
nTimesteps
);
Parameters
::
get
(
name
+
"->time tolerance"
,
globalTimeTolerance
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
scalContents
.
emplace_back
(
new
ScalContent
(
name
+
"["
+
std
::
to_string
(
i
)
+
"]"
));
}
void
AdaptInfo
::
setScalContents
(
int
newSize
)
{
int
oldSize
=
int
(
scalContents
.
size
());
if
(
newSize
>
oldSize
)
{
for
(
int
i
=
oldSize
;
i
<
newSize
;
++
i
)
scalContents
.
emplace_back
(
new
ScalContent
(
name
+
"["
+
std
::
to_string
(
i
)
+
"]"
));
}
}
void
AdaptInfo
::
printTimeErrorLowInfo
()
const
{
for
(
std
::
size_t
i
=
0
;
i
<
scalContents
.
size
();
i
++
)
for
(
auto
const
&
scalContent
:
scalContents
)
{
auto
i
=
scalContent
.
first
;
std
::
cout
<<
" Time error estimate ["
<<
i
<<
"] = "
<<
getTimeEstCombined
(
i
)
<<
"
\n
"
<<
" Time error estimate sum ["
<<
i
<<
"] = "
<<
scalContent
s
[
i
]
->
est_t_sum
<<
"
\n
"
<<
scalContent
.
second
.
est_t_sum
<<
"
\n
"
<<
" Time error estimate max ["
<<
i
<<
"] = "
<<
scalContent
s
[
i
]
->
est_t_max
<<
"
\n
"
<<
scalContent
.
second
.
est_t_max
<<
"
\n
"
<<
" Time error low bound ["
<<
i
<<
"] = "
<<
scalContent
s
[
i
]
->
timeErrLow
<<
"
\n
"
<<
scalContent
.
second
.
timeErrLow
<<
"
\n
"
<<
" Time error high bound ["
<<
i
<<
"] = "
<<
scalContent
s
[
i
]
->
timeTolerance
<<
"
\n
"
;
<<
scalContent
.
second
.
timeTolerance
<<
"
\n
"
;
}
}
...
...
src/amdis/AdaptInfo.hpp
View file @
074f8e52
...
...
@@ -4,12 +4,15 @@
#include
<algorithm>
#include
<cmath>
#include
<limits>
#include
<map>
#include
<string>
#include
<
vector
>
#include
<
utility
>
// AMDiS includes
#include
<amdis/Output.hpp>
#include
<amdis/common/ConceptsBase.hpp>
#include
<amdis/common/Math.hpp>
#include
<amdis/utility/TreePath.hpp>
namespace
AMDiS
{
...
...
@@ -18,11 +21,13 @@ namespace AMDiS
* \ingroup Adaption
*
* \brief
* Holds adapt parameters and infos about the problem. Base class
* for AdaptInfoScal and AdaptInfoVec.
* Holds adapt parameters and infos about the problem.
*/
class
AdaptInfo
{
public:
using
Key
=
std
::
string
;
protected:
/** \brief
* Stores adapt infos for a scalar problem or for one component of a
...
...
@@ -66,25 +71,11 @@ namespace AMDiS
/// true if refinement is allowed, false otherwise.
int
refinementAllowed
=
1
;
/** \brief
* parameter to tell the marking strategy how many bisections should be
* performed when an element is marked for refinement; usually the value is
* 1 or DIM
*/
int
refineBisections
=
1
;
/** \brief
* parameter to tell the marking strategy how many bisections should
* be undone when an element is marked for coarsening; usually the value is
* 1 or DIM
*/
int
coarseBisections
=
1
;
};
public:
/// Constructor.
explicit
AdaptInfo
(
std
::
string
name
,
int
size
=
1
);
explicit
AdaptInfo
(
std
::
string
name
);
/// Destructor.
virtual
~
AdaptInfo
()
{}
...
...
@@ -95,61 +86,78 @@ namespace AMDiS
/// Returns whether space tolerance is reached.
virtual
bool
spaceToleranceReached
()
const
{
for
(
std
::
size_t
i
=
0
;
i
<
scalContents
.
size
();
i
++
)
{
if
(
!
(
scalContents
[
i
]
->
est_sum
<
scalContents
[
i
]
->
spaceTolerance
))
for
(
auto
const
&
scalContent
:
scalContents
)
{
if
(
!
(
scalContent
.
second
.
est_sum
<
scalContent
.
second
.
spaceTolerance
))
return
false
;
}
return
true
;
}
/// Returns whether space tolerance of component
i
is reached.
virtual
bool
spaceToleranceReached
(
int
i
)
const
/// Returns whether space tolerance of component
associated with key
is reached.
virtual
bool
spaceToleranceReached
(
Key
key
)
const
{
if
(
!
(
s
calContent
s
[
i
]
->
est_sum
<
s
calContent
s
[
i
]
->
spaceTolerance
))
if
(
!
(
getS
calContent
(
key
).
est_sum
<
getS
calContent
(
key
).
spaceTolerance
))
return
false
;
else
return
true
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
bool
spaceToleranceReached
(
const
TP
&
tp
)
const
{
return
spaceToleranceReached
(
to_string
(
tp
));
}
/// Returns whether time tolerance is reached.
virtual
bool
timeToleranceReached
()
const
{
for
(
std
::
size_t
i
=
0
;
i
<
scalContents
.
size
();
i
++
)
if
(
!
(
getTimeEstCombined
(
i
)
<
scalContent
s
[
i
]
->
timeTolerance
))
for
(
auto
const
&
scalContent
:
scalContents
)
if
(
!
(
getTimeEstCombined
(
scalContent
.
first
)
<
scalContent
.
second
.
timeTolerance
))
return
false
;
return
true
;
}
/// Returns whether time tolerance of component
i
is reached.
virtual
bool
timeToleranceReached
(
int
i
)
const
/// Returns whether time tolerance of component
associated with key
is reached.
virtual
bool
timeToleranceReached
(
Key
key
)
const
{
if
(
!
(
getTimeEstCombined
(
i
)
<
s
calContent
s
[
i
]
->
timeTolerance
))
if
(
!
(
getTimeEstCombined
(
key
)
<
getS
calContent
(
key
).
timeTolerance
))
return
false
;
else
return
true
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
bool
timeToleranceReached
(
const
TP
&
tp
)
const
{
return
timeToleranceReached
(
to_string
(
tp
));
}
/// Returns whether time error is under its lower bound.
virtual
bool
timeErrorLow
()
const
{
for
(
std
::
size_t
i
=
0
;
i
<
scalContents
.
size
();
i
++
)
if
(
!
(
getTimeEstCombined
(
i
)
<
scalContent
s
[
i
]
->
timeErrLow
))
for
(
auto
const
&
scalContent
:
scalContents
)
if
(
!
(
getTimeEstCombined
(
scalContent
.
first
)
<
scalContent
.
second
.
timeErrLow
))
return
false
;
return
true
;
}
/// Returns the time estimation as a combination
/// of maximal and integral time error
double
getTimeEstCombined
(
std
::
size_t
i
)
const
double
getTimeEstCombined
(
Key
key
)
const
{
return
s
calContent
s
[
i
]
->
est_t_max
*
s
calContent
s
[
i
]
->
fac_max
+
s
calContent
s
[
i
]
->
est_t_sum
*
s
calContent
s
[
i
]
->
fac_sum
;
getS
calContent
(
key
).
est_t_max
*
getS
calContent
(
key
).
fac_max
+
getS
calContent
(
key
).
est_t_sum
*
getS
calContent
(
key
).
fac_sum
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeEstCombined
(
const
TP
&
tp
)
const
{
return
getTimeEstCombined
(
to_string
(
tp
));
}
/// Print debug information about time error and its bound.
void
printTimeErrorLowInfo
()
const
;
...
...
@@ -275,63 +283,111 @@ namespace AMDiS
}
/// Sets \ref est_sum.
void
setEstSum
(
double
e
,
int
index
)
void
setEstSum
(
double
e
,
Key
key
)
{
scalContents
[
index
]
->
est_sum
=
e
;
getScalContent
(
key
).
est_sum
=
e
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
setEstSum
(
double
e
,
const
TP
&
tp
)
{
setEstSum
(
e
,
to_string
(
tp
));
}
/// Sets \ref est_max.
void
setEstMax
(
double
e
,
int
index
)
void
setEstMax
(
double
e
,
Key
key
)
{
getScalContent
(
key
).
est_max
=
e
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
setEstMax
(
double
e
,
const
TP
&
tp
)
{
s
calContents
[
index
]
->
est_max
=
e
;
s
etEstMax
(
e
,
to_string
(
tp
))
;
}
/// Sets \ref est_max.
void
setTimeEstMax
(
double
e
,
int
index
)
void
setTimeEstMax
(
double
e
,
Key
key
)
{
getScalContent
(
key
).
est_t_max
=
e
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
setTimeEstMax
(
double
e
,
const
TP
&
tp
)
{
s
calContents
[
index
]
->
est_t_max
=
e
;
s
etTimeEstMax
(
e
,
to_string
(
tp
))
;
}
/// Sets \ref est_t_sum.
void
setTimeEstSum
(
double
e
,
int
index
)
void
setTimeEstSum
(
double
e
,
Key
key
)
{
getScalContent
(
key
).
est_t_sum
=
e
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
setTimeEstSum
(
double
e
,
const
TP
&
tp
)
{
s
calContents
[
index
]
->
est_t_sum
=
e
;
s
etTimeEstSum
(
e
,
to_string
(
tp
))
;
}
/// Returns \ref est_sum.
double
getEstSum
(
int
index
)
const
double
getEstSum
(
Key
key
)
const
{
AMDIS_FUNCNAME_DBG
(
"AdaptInfo::getEstSum()"
)
;
test_exit_dbg
(
size_t
(
index
)
<
scalContents
.
size
(),
"Wrong index for adaptInfo!
\n
"
);
return
getScalContent
(
key
).
est_sum
;
}
return
scalContents
[
index
]
->
est_sum
;
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getEstSum
(
const
TP
&
tp
)
{
return
getEstSum
(
to_string
(
tp
));
}
/// Returns \ref est_t_sum.
double
getEstTSum
(
int
index
)
const
double
getEstTSum
(
Key
key
)
const
{
return
getScalContent
(
key
).
est_t_sum
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getEstTSum
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
est_t_sum
;
return
getEstTSum
(
to_string
(
tp
))
;
}
/// Returns \ref est_max.
double
getEstMax
(
int
index
)
const
double
getEstMax
(
Key
key
)
const
{
AMDIS_FUNCNAME_DBG
(
"AdaptInfo::getEstSum()"
)
;
test_exit_dbg
(
size_t
(
index
)
<
scalContents
.
size
(),
"Wrong index for adaptInfo!
\n
"
);
return
getScalContent
(
key
).
est_max
;
}
return
scalContents
[
index
]
->
est_max
;
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getEstMax
(
const
TP
&
tp
)
{
return
getEstMax
(
to_string
(
tp
));
}
/// Returns \ref est_max.
double
getTimeEstMax
(
int
index
)
const
double
getTimeEstMax
(
Key
key
)
const
{
return
getScalContent
(
key
).
est_t_max
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeEstmax
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
est_t_max
;
return
getTimeEstMax
(
to_string
(
tp
))
;
}
/// Returns \ref est_t_sum.
double
getTimeEstSum
(
int
index
)
const
double
getTimeEstSum
(
Key
key
)
const
{
return
getScalContent
(
key
).
est_t_sum
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeEstSum
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
est_t_sum
;
return
getTimeEstSum
(
to_string
(
tp
))
;
}
/// Returns \ref est_t the estimated overall time error
...
...
@@ -346,27 +402,51 @@ namespace AMDiS
}
/// Returns \ref spaceTolerance.
double
getSpaceTolerance
(
int
index
)
const
double
getSpaceTolerance
(
Key
key
)
const
{
return
getScalContent
(
key
).
spaceTolerance
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getSpaceTolerance
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
spaceTolerance
;
return
getSpaceTolerance
(
to_string
(
tp
))
;
}
/// Sets \ref spaceTolerance.
void
setSpaceTolerance
(
int
index
,
double
tol
)
void
setSpaceTolerance
(
Key
key
,
double
tol
)
{
scalContents
[
index
]
->
spaceTolerance
=
tol
;
getScalContent
(
key
).
spaceTolerance
=
tol
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
setSpaceTolerance
(
const
TP
&
tp
,
double
tol
)
{
return
setSpaceTolerance
(
to_string
(
tp
),
tol
);
}
/// Returns \ref timeTolerance.
double
getTimeTolerance
(
int
index
)
const
double
getTimeTolerance
(
Key
key
)
const
{
return
getScalContent
(
key
).
timeTolerance
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeTolerance
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
timeTolerance
;
return
getTimeTolerance
(
to_string
(
tp
))
;
}
/// Returns \ref timeRelativeTolerance.
double
getTimeRelativeTolerance
(
int
index
)
const
double
getTimeRelativeTolerance
(
Key
key
)
const
{
return
getScalContent
(
key
).
timeRelativeTolerance
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeRelativeTolerance
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
t
imeRelativeTolerance
;
return
getT
imeRelativeTolerance
(
to_string
(
tp
))
;
}
/// Sets \ref time
...
...
@@ -488,45 +568,63 @@ namespace AMDiS
}
/// Returns \ref timeErrLow.
double
getTimeErrLow
(
int
index
)
const
double
getTimeErrLow
(
Key
key
)
const
{
return
getScalContent
(
key
).
timeErrLow
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
double
getTimeErrLow
(
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
timeErrLow
;
return
getTimeErrLow
(
to_string
(
tp
))
;
}
/// Returns whether coarsening is allowed or not.
bool
isCoarseningAllowed
(
int
index
)
const
bool
isCoarseningAllowed
(
Key
key
)
const
{
return
(
scalContents
[
index
]
->
coarsenAllowed
==
1
);
return
(
getScalContent
(
key
).
coarsenAllowed
==
1
);
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
bool
isCoarseningAllowed
(
const
TP
&
tp
)
{
return
isCoarseningAllowed
(
to_string
(
tp
));
}
/// Returns whether coarsening is allowed or not.
bool
isRefinementAllowed
(
int
index
)
const
bool
isRefinementAllowed
(
Key
key
)
const
{
return
(
s
calContent
s
[
index
]
->
refinementAllowed
==
1
);
return
(
getS
calContent
(
key
).
refinementAllowed
==
1
);
}
///
void
allowRefinement
(
bool
allow
,
int
index
)
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
bool
isRefinementAllowed
(
const
TP
&
tp
)
{
scalContents
[
index
]
->
r
efinementAllowed
=
allow
;
return
isR
efinementAllowed
(
to_string
(
tp
))
;
}
///
void
allow
Coarsening
(
bool
allow
,
int
index
)
void
allow
Refinement
(
bool
allow
,
Key
key
)
{
s
calContent
s
[
index
]
->
coars
enAllowed
=
allow
;
getS
calContent
(
key
).
refinem
en
t
Allowed
=
allow
;
}
/// Returns \ref refineBisections
int
getRefineBisections
(
int
index
)
const
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
allowRefinement
(
bool
allow
,
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
refineBisections
;
return
allowRefinement
(
allow
,
to_string
(
tp
))
;
}
/// Returns \ref coarseBisections
int
getCoarseBisections
(
int
index
)
const
///
void
allowCoarsening
(
bool
allow
,
Key
key
)
{
getScalContent
(
key
).
coarsenAllowed
=
allow
;
}
template
<
class
TP
,
REQUIRES
(
Concepts
::
PreTreePath
<
TP
>
)
>
void
allowCoarsening
(
bool
allow
,
const
TP
&
tp
)
{
return
scalContents
[
index
]
->
coarseBisections
;
return
allowCoarsening
(
allow
,
to_string
(
tp
))
;
}
int
getSize
()
const
...
...
@@ -596,9 +694,6 @@ namespace AMDiS
rosenbrockMode
=
b
;
}
/// Creates new scalContents with the given size.
void
setScalContents
(
int
newSize
);
/** \brief
* Resets timestep, current time and time boundaries without
* any check. Is used by the parareal algorithm.
...
...
@@ -614,6 +709,13 @@ namespace AMDiS
timestepNumber
=
0
;
}
private:
ScalContent
&
getScalContent
(
Key
key
)
const
{
auto
result
=
scalContents
.
emplace
(
std
::
piecewise_construct
,
std
::
forward_as_tuple
(
key
),
std
::
forward_as_tuple
(
name
+
"["
+
key
+
"]"
)
);
return
result
.
first
->
second
;
}
protected:
/// Name.
std
::
string
name
;
...
...
@@ -648,7 +750,7 @@ namespace AMDiS
/// Final time
double
endTime
=
1.0
;
///Time step size to be used
///
Time step size to be used
double
timestep
=
0.0
;
/// Last processed time step size of finished iteration
...
...
@@ -685,8 +787,8 @@ namespace AMDiS
/// tolerance for the overall time error
double
globalTimeTolerance
=
1.0
;
/// Scalar adapt infos
.
std
::
vector
<
std
::
unique_ptr
<
ScalContent
>
>
scalContents
;
/// Scalar adapt infos
mutable
std
::
map
<
Key
,
ScalContent
>
scalContents
;
/// Is true, if the adaptive procedure was deserialized from a file. TODO: remove deserialization
bool
deserialized
=
false
;
...
...
test/AdaptInfoTest.cpp
0 → 100644
View file @
074f8e52
#include
<amdis/AdaptInfo.cpp>
#include
<amdis/AMDiS.hpp>
#include
<amdis/common/Literals.hpp>
#include
<amdis/utility/TreePath.hpp>
#include
"Tests.hpp"
using
namespace
AMDiS
;
int
main
()
{
AdaptInfo
adaptInfo
(
"adapt"
);
auto
root_tp
=
treepath
();
auto
tp
=
treepath
(
0
_c
);
std
::
string
str
=
"0"
;
adaptInfo
.
setEstSum
(
0.1
,
tp
);
AMDIS_TEST_EQ
(
adaptInfo
.
getEstSum
(
tp
),
0.1
);
adaptInfo
.
setEstSum
(
0.2
,
root_tp
);
AMDIS_TEST_EQ
(
adaptInfo
.
getEstSum
(
root_tp
),
0.2
);
AMDIS_TEST_EQ
(
adaptInfo
.
getSize
(),
2
);
adaptInfo
.
setEstSum
(
0.3
,
"0"
);
AMDIS_TEST_EQ
(
adaptInfo
.
getEstSum
(
tp
),
0.3
);
adaptInfo
.
setEstSum
(
0.4
,
0
_c
);
AMDIS_TEST_EQ
(
adaptInfo
.
getEstSum
(
tp
),
0.4
);
adaptInfo
.
setEstSum
(
0.5
,
str
);
AMDIS_TEST_EQ
(
adaptInfo
.
getEstSum
(
tp
),
0.5
);
return
report_errors
();
}
\ No newline at end of file
test/CMakeLists.txt
View file @
074f8e52
dune_add_test
(
SOURCES AdaptInfoTest.cpp
LINK_LIBRARIES amdis
)
dune_add_test
(
SOURCES ClonablePtrTest.cpp
LINK_LIBRARIES amdis
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment