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
Backofen, Rainer
amdis
Commits
50f57133
Commit
50f57133
authored
Jun 16, 2011
by
Praetorius, Simon
Browse files
Initfile with variable replacement
parent
5695b4dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
AMDiS/src/Initfile.cc
View file @
50f57133
...
...
@@ -46,7 +46,7 @@ namespace AMDiS {
// initialize global strcutures using parameters
Global
::
init
();
}
}
;
/// Fill an initfile from a file with filename fn
...
...
@@ -62,7 +62,7 @@ namespace AMDiS {
fn_include_list
.
insert
(
fn
);
read
(
inputFile
);
}
}
}
;
/// Fill an initfile from an input stream
...
...
@@ -80,7 +80,8 @@ namespace AMDiS {
&&
sw
[
pos0
]
!=
'#'
&&
sw
[
pos0
]
!=
0
)
{
// parse line and extract map: tag->value
Parser
parser
(
sw
);
operator
[](
parser
.
name
)
=
parser
.
value
;
operator
[](
variableReplacement
(
InitfileInternal
::
trim
(
parser
.
name
)))
=
variableReplacement
(
InitfileInternal
::
trim
(
parser
.
value
));
}
else
if
(
sw
[
pos0
]
==
'#'
&&
static_cast
<
size_t
>
(
sw
.
find
(
"#include"
))
==
pos0
)
{
// include file by '#include "filename"' or '#include <filename>'
...
...
@@ -109,7 +110,35 @@ namespace AMDiS {
}
in
.
getline
(
swap
,
line_length
);
}
}
};
std
::
string
Initfile
::
variableReplacement
(
const
std
::
string
&
input
)
const
{
std
::
string
whitespaces
=
"
\t\r\f
"
;
std
::
string
inputSwap
=
input
;
size_t
posVar
=
inputSwap
.
find_first_of
(
'$'
);
while
(
posVar
!=
string
::
npos
)
{
size_t
posVarBegin
,
posVarEnd
;
if
(
inputSwap
[
posVar
+
1
]
==
'{'
)
{
posVarEnd
=
inputSwap
.
find_first_of
(
'}'
,
posVar
+
2
);
posVarBegin
=
posVar
+
1
;
}
else
{
posVarEnd
=
inputSwap
.
find_first_of
(
whitespaces
,
posVar
+
1
);
posVarBegin
=
posVar
;
}
std
::
string
varName
=
inputSwap
.
substr
(
posVarBegin
+
1
,
posVarEnd
-
posVarBegin
-
1
);
std
::
string
varParam
=
checkedGet
(
varName
);
// if varname is found in parameter list then replace variable by value
// otherwise throw tarNotFound exception
std
::
string
replaceName
=
inputSwap
.
substr
(
posVar
,
posVarEnd
-
posVar
+
(
posVarBegin
-
posVar
));
inputSwap
.
replace
(
inputSwap
.
find
(
replaceName
),
replaceName
.
length
(),
varParam
);
posVar
=
inputSwap
.
find_first_of
(
'$'
);
}
return
inputSwap
;
};
void
Initfile
::
readArgv
(
int
argc
,
char
**
argv
)
...
...
@@ -144,7 +173,7 @@ namespace AMDiS {
if
(
msgInfo
==
0
)
paramInfo
=
0
;
}
}
;
/// print all parameters to std::cout
...
...
@@ -153,7 +182,7 @@ namespace AMDiS {
initIntern
();
for
(
Initfile
::
iterator
it
=
singlett
->
begin
();
it
!=
singlett
->
end
();
it
++
)
std
::
cout
<<
(
*
it
).
first
<<
" => "
<<
(
*
it
).
second
<<
std
::
endl
;
}
}
;
/// Write data-map to initfile
...
...
AMDiS/src/Initfile.h
View file @
50f57133
...
...
@@ -581,6 +581,11 @@ protected:
return
it
->
second
;
}
/// replace variables by its value defined as parameter previousely
/// variable definition is simple parameter definition
/// variable evaluation by ${variablename} or $variablename
/// the last version only for variablenames without whitespaces
std
::
string
variableReplacement
(
const
std
::
string
&
input
)
const
;
/** Fill the initfile from an input stream.
* @param in: the stream to fill the data from.
...
...
AMDiS/src/ProblemStat.h
View file @
50f57133
...
...
@@ -519,6 +519,12 @@ namespace AMDiS {
return
exactSolutionFcts
[
i
];
}
///
vector
<
AbstractFunction
<
double
,
WorldVector
<
double
>
>*
>
getExactSolutionFcts
()
{
return
exactSolutionFcts
;
}
///
void
setComputeExactError
(
bool
v
)
{
...
...
demo/init/ellipt.dat.2d
View file @
50f57133
...
...
@@ -6,10 +6,9 @@ elliptMesh->global refinements: 0
ellipt->mesh: elliptMesh
ellipt->dim: 2
ellipt->polynomial degree[0]: 1
ellipt->polynomial degree[1]: 1
ellipt->components: 2
ellipt->components: 1
ellipt->solver:
umfpack %
cg
ellipt->solver: cg
ellipt->solver->symmetric strategy: 1
ellipt->solver->store symbolic: 0
ellipt->solver->max iteration: 1000
...
...
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