Skip to content
GitLab
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
e806dac8
Commit
e806dac8
authored
Sep 30, 2019
by
Praetorius, Simon
Browse files
Merge branch 'feature/vtk_writer' into 'master'
Filewriter abstraction See merge request
!61
parents
02a175fc
24b9b299
Changes
30
Hide whitespace changes
Inline
Side-by-side
dune.module
View file @
e806dac8
...
...
@@ -6,4 +6,4 @@ Module: amdis
Version
:
0.2
Maintainer
:
simon
.
praetorius
@
tu
-
dresden
.
de
Depends
:
dune
-
common
(
>=
2.6
)
dune
-
geometry
(
>=
2.6
)
dune
-
localfunctions
(
>=
2.6
)
dune
-
typetree
(
>=
2.6
)
dune
-
grid
(
>=
2.6
)
dune
-
functions
(
>=
2.6
)
Suggests
:
dune
-
uggrid
dune
-
alugrid
dune
-
foamgrid
dune
-
spgrid
dune
-
istl
Suggests
:
dune
-
uggrid
dune
-
alugrid
dune
-
foamgrid
dune
-
spgrid
dune
-
istl
dune
-
vtk
examples/boundary.cc
View file @
e806dac8
...
...
@@ -89,7 +89,7 @@ void run_periodic()
prob
.
assemble
(
adaptInfo
);
prob
.
solve
(
adaptInfo
);
prob
.
writeFiles
(
adaptInfo
,
true
);
prob
.
writeFiles
(
adaptInfo
);
}
...
...
examples/convection_diffusion.cc
View file @
e806dac8
...
...
@@ -37,7 +37,7 @@ int main(int argc, char** argv)
AdaptInfo
adaptInfo
(
"adapt"
);
prob
.
assemble
(
adaptInfo
);
prob
.
solve
(
adaptInfo
);
prob
.
writeFiles
(
adaptInfo
,
true
);
prob
.
writeFiles
(
adaptInfo
);
return
0
;
}
examples/ellipt.cc
View file @
e806dac8
...
...
@@ -69,14 +69,11 @@ int main(int argc, char** argv)
errL2
.
push_back
(
std
::
sqrt
(
errorL2
));
double
errorH1
=
errorL2
+
integrate
(
unary_dot
(
grad_g
-
gradientAtQP
(
prob
.
solution
(
0
))),
prob
.
gridView
(),
6
);
errH1
.
push_back
(
std
::
sqrt
(
errorH1
));
#if WRITE_FILES
Dune
::
VTKWriter
<
typename
ElliptProblem
::
GridView
>
vtkWriter
(
gridView
);
vtkWriter
.
addVertexData
(
prob
.
solution
(
0
),
Dune
::
VTK
::
FieldInfo
(
"u"
,
Dune
::
VTK
::
FieldInfo
::
Type
::
scalar
,
1
));
vtkWriter
.
write
(
"u_"
+
std
::
to_string
(
l
));
#endif
}
// write last solution to file
prob
.
writeFiles
(
adaptInfo
);
msg
(
""
);
msg
(
"{:5} | {:12} | {:12} | {:12} | {:12} | {:12}"
,
"level"
,
"h"
,
"|u - u*|_L2"
,
"|u - u*|_H1"
,
"eoc_L2"
,
"eoc_H1"
);
...
...
examples/init/boundary.dat.2d
View file @
e806dac8
...
...
@@ -8,6 +8,7 @@ ellipt->solver->relative tolerance: 1.e-10
ellipt->solver->info: 1
ellipt->solver->precon: ilu
ellipt->output[0]->format: vtk
ellipt->output[0]->filename: boundary.2d
ellipt->output[0]->name: u
ellipt->output[0]->output directory: ./output
examples/init/cahn_hilliard.dat.2d
View file @
e806dac8
...
...
@@ -18,19 +18,19 @@ ch->solver->relative tolerance: 1e-6
ch->solver->break if tolerance not reached: 1
ch->solver->info: 2
ch->output[0]->format: vtk
ch->output[0]->filename: phi.2d
ch->output[0]->output directory: output
ch->output[0]->name: phi
ch->output[0]->ParaView format: 1
ch->output[0]->ParaView mode: 1
ch->output[0]->ParaView animation: 1
ch->output[0]->mode: 1
ch->output[0]->animation: 1
ch->output[1]->format: vtk
ch->output[1]->filename: mu.2d
ch->output[1]->output directory: output
ch->output[1]->name: mu
ch->output[1]->ParaView format: 1
ch->output[1]->ParaView mode: 1
ch->output[1]->ParaView animation: 1
ch->output[1]->mode: 1
ch->output[1]->animation: 1
adapt->timestep: 0.001
adapt->start time: 0.0
...
...
examples/init/ellipt.dat.2d
View file @
e806dac8
...
...
@@ -13,6 +13,7 @@ ellipt->solver->max iteration: 10000
ellipt->solver->relative tolerance: 1.e-10
ellipt->solver->precon: ilu
ellipt->output[0]->format: vtk backup
ellipt->output[0]->filename: ellipt.2d
ellipt->output[0]->name: u
ellipt->output[0]->output directory: ./output
examples/init/ellipt.dat.3d
View file @
e806dac8
...
...
@@ -13,6 +13,7 @@ ellipt->solver->max iteration: 10000
ellipt->solver->relative tolerance: 1.e-10
ellipt->solver->precon: ilu
ellipt->output[0]->format: vtk
ellipt->output[0]->filename: ellipt.3d
ellipt->output[0]->name: u
ellipt->output[0]->output directory: ./output
examples/init/heat.dat.2d
View file @
e806dac8
...
...
@@ -12,10 +12,12 @@ heat->solver->absolute tolerance: 1e-6
heat->solver->info: 1
heat->solver->precon: ilu
heat->output[0]->format: vtk backup
heat->output[0]->name: u
heat->output[0]->filename: heat.2d
heat->output[0]->output directory: output
heat->output[0]->
ParaView
mode: 1
heat->output[0]->
ParaView
animation: 1
heat->output[0]->mode: 1
heat->output[0]->animation: 1
adapt->timestep: 0.1
adapt->start time: 0.0
...
...
examples/init/stokes.dat.2d
View file @
e806dac8
...
...
@@ -10,18 +10,18 @@ stokes->solver->relative tolerance: 1e-8
stokes->solver->precon: ilu
stokes->solver->info: 2
stokes->output[0]->format: vtk
stokes->output[0]->filename: stokes_u.2d
stokes->output[0]->name: u
stokes->output[0]->subsampling: 2
stokes->output[0]->output directory: ./output
stokes->output[0]->ParaView format: 1
stokes->output[0]->ParaView mode: 1
stokes->output[0]->mode: 1
stokes->output[1]->format: vtk
stokes->output[1]->filename: stokes_p.2d
stokes->output[1]->name: p
stokes->output[1]->output directory: ./output
stokes->output[1]->ParaView format: 1
stokes->output[1]->ParaView mode: 1
stokes->output[1]->mode: 1
stokes->viscosity: 1.0
stokes->density: 1.0
...
...
examples/init/surface.dat.2d
View file @
e806dac8
...
...
@@ -9,6 +9,7 @@ surface->solver->relative tolerance: 1.e-6
surface->solver->info: 1
surface->solver->precon: ilu
surface->output[0]->format: vtk
surface->output[0]->filename: surface.2d
surface->output[0]->name: u
surface->output[0]->output directory: ./output
examples/neumann.cc
View file @
e806dac8
...
...
@@ -45,7 +45,7 @@ void run(Grid& grid)
prob
.
assemble
(
adaptInfo
);
prob
.
solve
(
adaptInfo
);
prob
.
writeFiles
(
adaptInfo
,
true
);
prob
.
writeFiles
(
adaptInfo
);
}
...
...
examples/vecellipt.cc
View file @
e806dac8
...
...
@@ -51,7 +51,7 @@ int main(int argc, char** argv)
#endif
prob
.
solve
(
adaptInfo
);
prob
.
writeFiles
(
adaptInfo
,
true
);
prob
.
writeFiles
(
adaptInfo
);
return
0
;
}
src/amdis/AdaptInfo.hpp
View file @
e806dac8
...
...
@@ -733,10 +733,10 @@ namespace AMDiS
double
lastProcessedTimestep_
=
0.0
;
/// Minimal step size
double
minTimestep_
=
0.0
;
double
minTimestep_
=
std
::
sqrt
(
std
::
numeric_limits
<
double
>::
epsilon
())
;
/// Maximal step size
double
maxTimestep_
=
1.0
;
double
maxTimestep_
=
std
::
sqrt
(
std
::
numeric_limits
<
double
>::
max
())
;
/// Number of current time step
int
timestepNumber_
=
0
;
...
...
src/amdis/BoundaryManager.hpp
View file @
e806dac8
...
...
@@ -25,6 +25,11 @@ namespace AMDiS
return
boundaryIds_
[
intersection
.
boundarySegmentIndex
()];
}
std
::
vector
<
BoundaryType
>
const
boundaryIds
()
const
{
return
boundaryIds_
;
}
protected:
std
::
vector
<
BoundaryType
>
boundaryIds_
;
// maps a boundarySegementIndex to an ID
};
...
...
src/amdis/CMakeLists.txt
View file @
e806dac8
...
...
@@ -39,8 +39,6 @@ install(FILES
DOFVector.inc.hpp
DOFVectorInterface.hpp
Environment.hpp
FileWriter.hpp
FileWriterInterface.hpp
Flag.hpp
GridFunctionOperator.hpp
GridFunctions.hpp
...
...
src/amdis/FileWriterInterface.hpp
deleted
100644 → 0
View file @
02a175fc
#pragma once
#include
<string>
#include
<amdis/Initfile.hpp>
#include
<amdis/Output.hpp>
#include
<amdis/common/Filesystem.hpp>
namespace
AMDiS
{
// forward declaration
class
AdaptInfo
;
class
FileWriterInterface
{
public:
explicit
FileWriterInterface
(
std
::
string
const
&
base
)
{
Parameters
::
get
(
base
+
"->filename"
,
filename_
);
Parameters
::
get
(
base
+
"->output directory"
,
dir_
);
Parameters
::
get
(
base
+
"->name"
,
name_
);
}
virtual
~
FileWriterInterface
()
=
default
;
// pure virtual method to be implemented by derived classes
virtual
void
writeFiles
(
AdaptInfo
&
adaptInfo
,
bool
force
)
=
0
;
public:
// getter and setter
std
::
string
const
&
filename
()
const
{
return
filename_
;
}
std
::
string
const
&
dir
()
const
{
return
dir_
;
}
std
::
string
const
&
name
()
const
{
return
name_
;
}
void
setFilename
(
std
::
string
const
&
filename
)
{
filename_
=
filename
;
}
void
setDir
(
std
::
string
const
&
dir
)
{
dir_
=
dir
;
}
void
setName
(
std
::
string
const
&
name
)
{
name_
=
name
;
}
protected:
std
::
string
filename_
=
"solution"
;
std
::
string
dir_
=
"."
;
std
::
string
name_
=
"solution"
;
};
}
// end namespace AMDiS
src/amdis/ProblemStat.hpp
View file @
e806dac8
...
...
@@ -37,7 +37,7 @@
#include
<amdis/gridfunctions/DiscreteFunction.hpp>
#include
<amdis/gridfunctions/DOFVectorView.hpp>
#include
<amdis/FileWriter
Interfac
e.hpp>
#include
<amdis/
io/
FileWriter
Bas
e.hpp>
#include
<amdis/typetree/TreeData.hpp>
#include
<amdis/typetree/TreePath.hpp>
...
...
@@ -106,14 +106,21 @@ namespace AMDiS
}
/// \brief Initialisation of the problem.
/**
* \brief Initialisation of the problem.
*
* Parameters read in initialize() for problem with name 'PROB'
* MESH[0]->global refinements: nr of initial global refinements
* Parameters read in initialize()
* - `[GRID_NAME]->global refinements`: nr of initial global refinements
**/
void
initialize
(
Flag
initFlag
,
Self
*
adoptProblem
=
nullptr
,
Flag
adoptFlag
=
INIT_NOTHING
);
/// \brief Read the grid and solution from backup files and initialize the problem
/**
* Parameters read in restore() for problem with name 'PROB'
* - `[PROB]->restore->grid`: name of the grid backup file
* - `[PROB]->restore->solution`: name of the solution backup file
**/
void
restore
(
Flag
initFlag
);
/// Add an operator to \ref A.
/** @{ */
...
...
@@ -296,21 +303,9 @@ namespace AMDiS
/// Uniform global refinement by n level
Flag
globalRefine
(
int
n
)
override
;
/// Writes output files.
/// Writes output files.
If force=true write even if timestep out of write rhythm.
void
writeFiles
(
AdaptInfo
&
adaptInfo
,
bool
force
=
false
);
/// Backup the grid
void
backup
(
std
::
string
const
&
filename
)
const
;
/// Implements \ref ProblemStatBase::backup
void
backup
(
AdaptInfo
&
adaptInfo
)
override
;
/// Retore the grid
auto
restore
(
std
::
string
const
&
filename
);
/// Implements \ref ProblemStatBase::restore
void
restore
(
Flag
initFlag
)
override
;
public:
// get-methods
...
...
src/amdis/ProblemStat.inc.hpp
View file @
e806dac8
...
...
@@ -12,10 +12,10 @@
#include
<amdis/AdaptInfo.hpp>
#include
<amdis/BackupRestore.hpp>
#include
<amdis/FileWriter.hpp>
#include
<amdis/Assembler.hpp>
#include
<amdis/GridFunctionOperator.hpp>
#include
<amdis/GridTransferManager.hpp>
#include
<amdis/io/FileWriterCreator.hpp>
#include
<amdis/linearalgebra/SymmetryStructure.hpp>
namespace
AMDiS
{
...
...
@@ -131,6 +131,48 @@ void ProblemStat<Traits>::initialize(
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
restore
(
Flag
initFlag
)
{
std
::
string
grid_filename
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->restore->grid"
).
value
();
std
::
string
solution_filename
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->restore->solution"
).
value
();
test_exit
(
filesystem
::
exists
(
grid_filename
),
"Restore file '{}' not found."
,
grid_filename
);
test_exit
(
filesystem
::
exists
(
solution_filename
),
"Restore file '{}' not found."
,
solution_filename
);
// restore grid from file
if
(
Dune
::
Capabilities
::
hasBackupRestoreFacilities
<
Grid
>::
v
)
adoptGrid
(
std
::
unique_ptr
<
Grid
>
(
Dune
::
BackupRestoreFacility
<
Grid
>::
restore
(
grid_filename
)));
else
adoptGrid
(
std
::
unique_ptr
<
Grid
>
(
BackupRestoreByGridFactory
<
Grid
>::
restore
(
grid_filename
)));
// 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_
->
resize
();
solution_
->
restore
(
solution_filename
);
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
createGrid
()
{
...
...
@@ -256,17 +298,29 @@ void ProblemStat<Traits>::createMarker()
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
createFileWriter
()
{
FileWriterCreator
<
CoefficientVector
>
creator
(
solution_
,
boundaryManager_
);
filewriter_
.
clear
();
auto
localView
=
globalBasis_
->
localView
();
for_each_node
(
localView
.
tree
(),
[
&
,
this
](
auto
const
&
node
,
auto
treePath
)
->
void
for_each_node
(
localView
.
tree
(),
[
&
](
auto
const
&
/*
node
*/
,
auto
treePath
)
->
void
{
std
::
string
componentName
=
name_
+
"->output["
+
to_string
(
treePath
)
+
"]"
;
auto
format
=
Parameters
::
get
<
std
::
vector
<
std
::
string
>>
(
componentName
+
"->format"
);
if
(
!
format
&&
to_string
(
treePath
).
empty
())
{
// alternative for root treepath
componentName
=
name_
+
"->output"
;
format
=
Parameters
::
get
<
std
::
vector
<
std
::
string
>>
(
componentName
+
"->format"
);
}
if
(
!
Parameters
::
get
<
std
::
string
>
(
componentName
+
"->filename"
)
)
if
(
!
format
)
return
;
auto
writer
=
makeFileWriterPtr
(
componentName
,
this
->
solution
(
treePath
));
filewriter_
.
push_back
(
std
::
move
(
writer
));
for
(
std
::
string
const
&
type
:
format
.
value
())
{
auto
writer
=
creator
.
create
(
type
,
componentName
,
treePath
);
if
(
writer
)
filewriter_
.
push_back
(
std
::
move
(
writer
));
}
});
}
...
...
@@ -518,112 +572,8 @@ writeFiles(AdaptInfo& adaptInfo, bool force)
{
Dune
::
Timer
t
;
for
(
auto
writer
:
filewriter_
)
writer
->
write
Files
(
adaptInfo
,
force
);
writer
->
write
(
adaptInfo
,
force
);
msg
(
"writeFiles needed {} seconds"
,
t
.
elapsed
());
}
template
<
class
Grid
,
class
GridView
,
class
=
decltype
(
Dune
::
BackupRestoreFacility
<
Grid
>
::
backup
(
std
::
declval
<
Grid
>
(),
std
::
string
(
""
)))
>
void
backup_impl
(
Grid
const
&
grid
,
GridView
const
&
gv
,
std
::
string
filename
,
std
::
true_type
)
{
Dune
::
BackupRestoreFacility
<
Grid
>::
backup
(
grid
,
filename
);
}
template
<
class
Grid
,
class
GridView
,
bool
B
,
class
=
decltype
(
BackupRestoreByGridFactory
<
Grid
>
::
backup
(
std
::
declval
<
GridView
>
(),
std
::
string
(
""
)))
>
void
backup_impl
(
Grid
const
&
grid
,
GridView
const
&
gv
,
std
::
string
filename
,
bool_t
<
B
>
)
{
warning
(
"Falling back to backup of gridview."
);
BackupRestoreByGridFactory
<
Grid
>::
backup
(
gv
,
filename
);
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
backup
(
std
::
string
const
&
filename
)
const
{
backup_impl
(
*
grid_
,
gridView
(),
filename
,
bool_t
<
Dune
::
Capabilities
::
hasBackupRestoreFacilities
<
Grid
>::
v
>
{});
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
backup
(
AdaptInfo
&
adaptInfo
)
{
auto
param
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->backup->grid"
);
std
::
string
grid_filename
=
param
?
*
param
:
name_
+
"_"
+
std
::
to_string
(
adaptInfo
.
timestepNumber
())
+
".grid"
;
auto
param2
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->backup->solution"
);
std
::
string
solution_filename
=
param2
?
*
param2
:
name_
+
"_"
+
std
::
to_string
(
adaptInfo
.
timestepNumber
())
+
".solution"
;
backup
(
grid_filename
);
solution_
->
backup
(
solution_filename
);
msg
(
"Problem backuped to files '{}' and '{}'."
,
grid_filename
,
solution_filename
);
}
template
<
class
Grid
,
class
=
decltype
(
Dune
::
BackupRestoreFacility
<
Grid
>
::
restore
(
std
::
string
(
""
)))
>
auto
restore_impl
(
std
::
string
filename
,
std
::
true_type
)
{
return
Dune
::
BackupRestoreFacility
<
Grid
>::
restore
(
filename
);
}
template
<
class
Grid
,
bool
B
,
class
=
decltype
(
BackupRestoreByGridFactory
<
Grid
>
::
restore
(
std
::
string
(
""
)))
>
auto
restore_impl
(
std
::
string
filename
,
bool_t
<
B
>
)
{
return
BackupRestoreByGridFactory
<
Grid
>::
restore
(
filename
);
}
template
<
class
Traits
>
auto
ProblemStat
<
Traits
>::
restore
(
std
::
string
const
&
filename
)
{
// restore grid from file
std
::
unique_ptr
<
Grid
>
grid
(
restore_impl
<
Grid
>
(
filename
,
bool_t
<
Dune
::
Capabilities
::
hasBackupRestoreFacilities
<
Grid
>::
v
>
{}));
return
std
::
move
(
grid
);
}
template
<
class
Traits
>
void
ProblemStat
<
Traits
>::
restore
(
Flag
initFlag
)
{
std
::
string
grid_filename
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->restore->grid"
).
value
();
std
::
string
solution_filename
=
Parameters
::
get
<
std
::
string
>
(
name_
+
"->restore->solution"
).
value
();
test_exit
(
filesystem
::
exists
(
grid_filename
),
"Restore file '{}' not found."
,
grid_filename
);
test_exit
(
filesystem
::
exists
(
solution_filename
),
"Restore file '{}' not found."
,
solution_filename
);
// restore grid from file
adoptGrid
(
restore
(
grid_filename
));
// 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_
->
resizeZero
();
solution_
->
restore
(
solution_filename
);
}
}
// end namespace AMDiS
src/amdis/ProblemStatBase.hpp
View file @
e806dac8
...
...
@@ -111,12 +111,6 @@ 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
;
};
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment