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
ee7732b3
Commit
ee7732b3
authored
Mar 28, 2019
by
Praetorius, Simon
Browse files
add functions backup() and restore() to ProblemStat
parent
73513f33
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/amdis/Initfile.hpp
View file @
ee7732b3
...
...
@@ -47,6 +47,12 @@ namespace AMDiS
value
=
pt
().
get
(
key
,
value
);
}
template
<
class
T
>
static
void
set
(
std
::
string
const
&
key
,
T
const
&
value
)
{
pt
()[
key
]
=
value
;
}
/// Returns specified info level
static
int
getMsgInfo
()
{
...
...
src/amdis/ProblemStat.hpp
View file @
ee7732b3
...
...
@@ -274,6 +274,12 @@ namespace AMDiS
/// Writes output files.
void
writeFiles
(
AdaptInfo
&
adaptInfo
,
bool
force
=
false
);
/// Implements \ref ProblemStatBase::backup
void
backup
(
AdaptInfo
&
adaptInfo
)
override
;
/// Implements \ref ProblemStatBase::restore
void
restore
(
Flag
initFlag
)
override
;
public:
// get-methods
...
...
src/amdis/ProblemStat.inc.hpp
View file @
ee7732b3
...
...
@@ -484,4 +484,56 @@ writeFiles(AdaptInfo& adaptInfo, bool force)
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
backup
(
AdaptInfo
&
adaptInfo
)
{
auto
param
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->backup filename"
);
std
::
string
filename
=
param
?
*
param
:
name_
+
"_"
+
std
::
to_string
(
adaptInfo
.
timestepNumber
())
+
".backup"
;
Dune
::
BackupRestoreFacility
<
Grid
>::
backup
(
*
grid_
,
filename
);
// TODO: backup data
msg
(
"Problem backuped to file '{}'."
,
filename
);
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
restore
(
Flag
initFlag
)
{
std
::
string
filename
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->restore filename"
).
value
();
test_exit
(
filesystem
::
exists
(
filename
),
"Restore file '{}' not found."
,
filename
);
// restore grid from file
std
::
shared_ptr
<
Grid
>
grid
(
Dune
::
BackupRestoreFacility
<
Grid
>::
restore
(
filename
));
adoptGrid
(
grid
);
// create fespace
if
(
initFlag
.
isSet
(
INIT_FE_SPACE
)
||
initFlag
.
isSet
(
INIT_SYSTEM
))
createGlobalBasis
();
// create system
if
(
initFlag
.
isSet
(
INIT_SYSTEM
))
createMatricesAndVectors
();
// create solver
if
(
linearSolver_
)
warning
(
"solver already created
\n
"
);
else
if
(
initFlag
.
isSet
(
INIT_SOLVER
))
createSolver
();
// create marker
if
(
initFlag
.
isSet
(
INIT_MARKER
))
createMarker
();
// create file writer
if
(
initFlag
.
isSet
(
INIT_FILEWRITER
))
createFileWriter
();
solution_
->
compress
();
// TODO: read data
}
}
// end namespace AMDiS
src/amdis/ProblemStatBase.hpp
View file @
ee7732b3
...
...
@@ -111,6 +111,12 @@ namespace AMDiS
*/
virtual
void
estimate
(
AdaptInfo
&
adaptInfo
)
=
0
;
/// \brief backup the grid and the solution to a file
virtual
void
backup
(
AdaptInfo
&
adaptInfo
)
=
0
;
/// \brief restore the grid and the solution from a file
virtual
void
restore
(
Flag
initFlag
)
=
0
;
/// Returns the name of the problem.
virtual
std
::
string
const
&
name
()
const
=
0
;
};
...
...
test/BackupRestoreTest.cpp
0 → 100644
View file @
ee7732b3
#include
<amdis/AMDiS.hpp>
#include
<amdis/ProblemStat.hpp>
#include
"Tests.hpp"
using
namespace
AMDiS
;
template
<
class
Grid
,
class
Factory
>
void
test
(
Factory
factory
)
{
using
Param
=
TaylorHoodBasis
<
Grid
>
;
using
Problem
=
ProblemStat
<
Param
>
;
std
::
size_t
num_elements
=
0
;
std
::
size_t
num_vertices
=
0
;
// backup
{
std
::
unique_ptr
<
Grid
>
grid
(
factory
());
Problem
prob
(
"test"
,
*
grid
);
prob
.
initialize
(
INIT_ALL
);
prob
.
globalRefine
(
2
);
num_elements
=
prob
.
grid
()
->
size
(
0
);
num_vertices
=
prob
.
grid
()
->
size
(
Grid
::
dimension
);
AdaptInfo
adaptInfo
(
"adapt"
);
prob
.
backup
(
adaptInfo
);
}
// restore
{
Problem
prob
(
"test"
);
prob
.
restore
(
INIT_ALL
);
AMDIS_TEST_EQ
(
num_elements
,
prob
.
grid
()
->
size
(
0
));
AMDIS_TEST_EQ
(
num_vertices
,
prob
.
grid
()
->
size
(
Grid
::
dimension
));
}
}
template
<
class
Grid
>
void
test_cube
()
{
using
Factory
=
Dune
::
StructuredGridFactory
<
Grid
>
;
test
<
Grid
>
([]()
{
return
Factory
::
createCubeGrid
({
0.0
,
0.0
},
{
1.0
,
1.0
},
std
::
array
<
unsigned
int
,
2
>
{
2
,
2
});
});
}
template
<
class
Grid
>
void
test_simplex
()
{
using
Factory
=
Dune
::
StructuredGridFactory
<
Grid
>
;
test
<
Grid
>
([]()
{
return
Factory
::
createSimplexGrid
({
0.0
,
0.0
},
{
1.0
,
1.0
},
std
::
array
<
unsigned
int
,
2
>
{
2
,
2
});
});
}
int
main
(
int
argc
,
char
**
argv
)
{
AMDiS
::
init
(
argc
,
argv
);
std
::
string
filename
=
"test.backup"
;
Parameters
::
set
(
"test->backup filename"
,
filename
);
Parameters
::
set
(
"test->restore filename"
,
filename
);
test_cube
<
Dune
::
YaspGrid
<
2
>>
();
// test_cube<Dune::UGGrid<2>>();
// test_simplex<Dune::AlbertaGrid<2,2>>();
// test_simplex<Dune::UGGrid<2>>();
AMDiS
::
finalize
();
return
0
;
}
test/CMakeLists.txt
View file @
ee7732b3
...
...
@@ -2,6 +2,10 @@
dune_add_test
(
SOURCES AdaptInfoTest.cpp
LINK_LIBRARIES amdis
)
dune_add_test
(
SOURCES BackupRestoreTest.cpp
LINK_LIBRARIES amdis
)
add_dune_alberta_flags
(
GRIDDIM 2 WORLDDIM 2 BackupRestoreTest
)
dune_add_test
(
SOURCES ConceptsTest.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