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
Backofen, Rainer
amdis
Commits
a21c01e0
Commit
a21c01e0
authored
May 07, 2013
by
Praetorius, Simon
Browse files
BaseProblems updated and some Warnings removed
parent
57117087
Changes
2
Show whitespace changes
Inline
Side-by-side
extensions/base_problems/BaseProblem.h
View file @
a21c01e0
...
...
@@ -7,13 +7,14 @@
#include "time/RosenbrockStationary.h"
#include "CouplingTimeInterface.h"
#include "VtuReader.h"
#include "pugixml.hpp"
using
namespace
AMDiS
;
const
Flag
MESH_ADOPTED
=
1
<<
2
;
const
Flag
DATA_ADOPTED
=
1
<<
3
;
template
<
typename
ProblemType
=
ProblemStat
>
template
<
typename
ProblemType
=
ProblemStat
,
bool
safeguard
=
false
>
class
BaseProblem
:
public
ProblemIterationInterface
,
public
ProblemInstatBase
{
...
...
@@ -163,14 +164,13 @@ public:
/// for rosenbrock-problems a special time-operator can be added
void
addTimeOperator
(
RosenbrockStationary
*
prob
,
int
i
,
int
j
);
template
<
typename
T
>
static
void
initFileWriterFromFile
(
AdaptInfo
*
adaptInfo
,
FileWriterTemplated
<
T
>&
fileWriter
,
bool
keep_all
=
false
);
protected:
ProblemType
*
prob
;
/// catch errors and exceptions in solve-block and continue with last iteration on failure
/// standard: false
bool
secureIteration
;
/// dimension of the mesh (set in \ref initialize(...) )
unsigned
dim
;
...
...
extensions/base_problems/BaseProblem.hh
View file @
a21c01e0
using
namespace
AMDiS
;
template
<
typename
ProblemType
>
BaseProblem
<
ProblemType
>::
BaseProblem
(
const
std
::
string
&
name_
,
bool
createProblem
)
template
<
typename
ProblemType
,
bool
safeguard
>
BaseProblem
<
ProblemType
,
safeguard
>::
BaseProblem
(
const
std
::
string
&
name_
,
bool
createProblem
)
:
ProblemInstatBase
(
name_
,
NULL
),
prob
(
NULL
),
secureIteration
(
false
),
dim
(
1
),
dow
(
1
),
nTimesteps
(
-
1
),
...
...
@@ -16,13 +15,11 @@ BaseProblem<ProblemType>::BaseProblem(const std::string &name_, bool createProbl
prob
=
new
ProblemType
(
name
+
"->space"
);
dow
=
Global
::
getGeo
(
WORLD
);
Initfile
::
get
(
name
+
"->secure iteration"
,
secureIteration
);
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
initialize
(
Flag
initFlag
,
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
initialize
(
Flag
initFlag
,
ProblemStat
*
adoptProblem
,
Flag
adoptFlag
)
{
FUNCNAME
(
"BaseProblem::initialize()"
);
...
...
@@ -34,8 +31,8 @@ void BaseProblem<ProblemType>::initialize(Flag initFlag,
}
template
<
typename
ProblemType
>
Flag
BaseProblem
<
ProblemType
>::
initDataFromFile
(
AdaptInfo
*
adaptInfo
)
template
<
typename
ProblemType
,
bool
safeguard
>
Flag
BaseProblem
<
ProblemType
,
safeguard
>::
initDataFromFile
(
AdaptInfo
*
adaptInfo
)
{
FUNCNAME
(
"BaseProblem::initDataFromFile()"
);
...
...
@@ -53,7 +50,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
// read data and mesh from arh-files/dat-files
MSG
(
"read data from file...
\n
"
);
if
(
readFormat
==
"arh"
)
{
if
(
readFormat
==
"arh"
)
{
std
::
string
filename
=
""
;
Initfile
::
get
(
name
+
"->value file"
,
filename
);
if
(
filename
.
size
()
==
0
)
return
initFlag
;
...
...
@@ -65,7 +63,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
solutions
.
push_back
(
prob
->
getSolution
()
->
getDOFVector
(
i
));
ArhReader
::
read
(
filename
,
prob
->
getMesh
(),
solutions
);
}
else
if
(
readFormat
==
"dat"
)
{
else
if
(
readFormat
==
"dat"
)
{
bool
preserveMacroFileInfo
=
false
;
Parameters
::
get
(
prob
->
getMesh
()
->
getName
()
+
"->preserve macroFileInfo"
,
preserveMacroFileInfo
);
if
(
prob
->
getMesh
()
->
getMacroFileInfo
()
==
NULL
||
!
preserveMacroFileInfo
)
...
...
@@ -79,7 +78,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
ValueReader
::
readValue
(
filename
,
prob
->
getMesh
(),
prob
->
getSolution
()
->
getDOFVector
(
i
),
prob
->
getMesh
()
->
getMacroFileInfo
());
}
}
else
if
(
readFormat
==
"vtu"
)
{
else
if
(
readFormat
==
"vtu"
)
{
std
::
vector
<
std
::
string
>
filenames
;
Initfile
::
get
(
name
+
"->value file"
,
filenames
);
if
(
filenames
.
size
()
==
0
)
...
...
@@ -115,7 +115,8 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
}
else
throw
(
std
::
runtime_error
(
"You have to specify a .vtu file!"
));
}
else
if
(
readFormat
==
"multi-vtu"
)
{
else
if
(
readFormat
==
"multi-vtu"
)
{
size_t
numFiles
=
0
;
Initfile
::
get
(
name
+
"->number of files"
,
numFiles
);
for
(
size_t
n
=
0
;
n
<
numFiles
;
n
++
)
{
...
...
@@ -159,6 +160,17 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
throw
(
std
::
runtime_error
(
"Parameter 'read data from file' set to 'true', but no parameter 'read format' specified!"
));
}
bool
readPvdFromFile
=
false
;
Initfile
::
get
(
name
+
"->read pvd from file"
,
readPvdFromFile
,
2
);
if
(
readPvdFromFile
)
{
vector
<
FileWriterInterface
*>&
fileWriters
=
prob
->
getFileWriterList
();
for
(
size_t
i
=
0
;
i
<
fileWriters
.
size
();
i
++
)
{
FileWriterTemplated
<
double
>*
fileWriter
=
dynamic_cast
<
FileWriterTemplated
<
double
>*>
(
fileWriters
[
i
]);
if
(
fileWriter
)
initFileWriterFromFile
(
adaptInfo
,
*
fileWriter
);
}
}
initFlag
.
setFlag
(
DATA_ADOPTED
);
initFlag
.
setFlag
(
MESH_ADOPTED
);
...
...
@@ -166,8 +178,36 @@ Flag BaseProblem<ProblemType>::initDataFromFile(AdaptInfo *adaptInfo)
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
beginIteration
(
AdaptInfo
*
adaptInfo
)
template
<
typename
ProblemType
,
bool
safeguard
>
template
<
typename
T
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
initFileWriterFromFile
(
AdaptInfo
*
adaptInfo
,
FileWriterTemplated
<
T
>&
fileWriter
,
bool
keep_all
)
{
using
namespace
pugi
;
if
(
!
boost
::
filesystem
::
exists
(
fileWriter
.
getFilename
()
+
".pvd"
))
return
;
xml_document
vtu
;
if
(
!
vtu
.
load_file
((
fileWriter
.
getFilename
()
+
".pvd"
).
c_str
()))
throw
(
std
::
runtime_error
(
"Could not load pvd file! Error in xml structure."
));
xml_node
VTKFile
=
vtu
.
child
(
"VTKFile"
);
xml_node
Collection
=
VTKFile
.
child
(
"Collection"
);
std
::
vector
<
std
::
pair
<
double
,
std
::
string
>
>&
paraviewAnimationFrames
=
fileWriter
.
getParaviewAnimationFrames
();
for
(
xml_node
DataSet
=
Collection
.
child
(
"DataSet"
);
DataSet
;
DataSet
=
DataSet
.
next_sibling
(
"DataSet"
))
{
std
::
string
timestepStr
=
DataSet
.
attribute
(
"timestep"
).
value
();
std
::
string
fileStr
=
DataSet
.
attribute
(
"file"
).
value
();
double
time
=
boost
::
lexical_cast
<
double
>
(
timestepStr
);
if
(
keep_all
||
time
<=
adaptInfo
->
getStartTime
())
paraviewAnimationFrames
.
push_back
(
std
::
make_pair
(
time
,
fileStr
));
}
}
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
beginIteration
(
AdaptInfo
*
adaptInfo
)
{
FUNCNAME
(
"BaseProblem::beginIteration()"
);
MSG
(
"
\n
"
);
...
...
@@ -190,8 +230,8 @@ void BaseProblem<ProblemType>::beginIteration(AdaptInfo *adaptInfo)
}
template
<
typename
ProblemType
>
Flag
BaseProblem
<
ProblemType
>::
oneIteration
(
AdaptInfo
*
adaptInfo
,
template
<
typename
ProblemType
,
bool
safeguard
>
Flag
BaseProblem
<
ProblemType
,
safeguard
>::
oneIteration
(
AdaptInfo
*
adaptInfo
,
Flag
toDo
)
{
FUNCNAME
(
"BaseProblem::oneIteration()"
);
...
...
@@ -220,7 +260,7 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo,
#endif
if
(
toDo
.
isSet
(
SOLVE
))
{
if
(
s
ecureIteration
)
{
if
(
s
afeguard
)
{
try
{
prob
->
solve
(
adaptInfo
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -250,8 +290,8 @@ Flag BaseProblem<ProblemType>::oneIteration(AdaptInfo *adaptInfo,
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
endIteration
(
AdaptInfo
*
adaptInfo
)
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
endIteration
(
AdaptInfo
*
adaptInfo
)
{
FUNCNAME
(
"BaseProblem::endIteration()"
);
MSG
(
"
\n
"
);
...
...
@@ -259,20 +299,15 @@ void BaseProblem<ProblemType>::endIteration(AdaptInfo *adaptInfo)
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
closeTimestep
(
AdaptInfo
*
adaptInfo
)
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
closeTimestep
(
AdaptInfo
*
adaptInfo
)
{
int
outputPeriod
=
1
;
Initfile
::
get
(
"user parameter->write every ith timestep"
,
outputPeriod
);
if
(
adaptInfo
->
getTimestepNumber
()
%
outputPeriod
==
0
&&
adaptInfo
->
getStartTime
()
<
adaptInfo
->
getEndTime
())
{
writeFiles
(
adaptInfo
,
false
);
}
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
addTimeOperator
(
ProblemStat
*
prob
,
int
i
,
int
j
)
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
addTimeOperator
(
ProblemStat
*
prob
,
int
i
,
int
j
)
{
Operator
*
op
=
new
Operator
(
prob
->
getFeSpace
(
i
),
prob
->
getFeSpace
(
j
));
op
->
addZeroOrderTerm
(
new
Simple_ZOT
);
...
...
@@ -284,8 +319,8 @@ void BaseProblem<ProblemType>::addTimeOperator(ProblemStat *prob, int i, int j)
}
template
<
typename
ProblemType
>
void
BaseProblem
<
ProblemType
>::
addTimeOperator
(
RosenbrockStationary
*
prob
,
int
i
,
int
j
)
template
<
typename
ProblemType
,
bool
safeguard
>
void
BaseProblem
<
ProblemType
,
safeguard
>::
addTimeOperator
(
RosenbrockStationary
*
prob
,
int
i
,
int
j
)
{
prob
->
addTimeOperator
(
i
,
j
);
}
Write
Preview
Markdown
is supported
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