Parameter map default value

20 views
Skip to first unread message

Franco Milicchio

unread,
Feb 13, 2017, 8:15:03 AM2/13/17
to deal.II User Group
Hello, 

I know this is a weird question, but is there a way of telling a Map that there is a default value? 

For instance I'd like to express something like "stress:4, power" instead of what I have to do right now, such as "stress:4, power:8" (or whatever number).

The following is the code I am using now:

        params->declare_entry("csv", "strain:3, work:1", dealii::Patterns::Map(dealii::Patterns::Selection("time|displacement|stress|strain|work|power"), dealii::Patterns::Integer(0), 1), "Dump to CSV file, comma separated values (time, displacement, stress, strain, work, power)");


Thanks!
    Franco

Wolfgang Bangerth

unread,
Feb 14, 2017, 7:41:06 PM2/14/17
to dea...@googlegroups.com
On 02/13/2017 06:15 AM, Franco Milicchio wrote:
> Hello,
>
> I know this is a weird question, but is there a way of telling a *Map*
> that there is a default value?
>
> For instance I'd like to express something like "*stress:4, power*"
> instead of what I have to do right now, such as "*stress:4, power:8*"
> (or whatever number).
>
> The following is the code I am using now:
>
> params->declare_entry("csv", "strain:3, work:1",
> dealii::Patterns::Map(dealii::Patterns::Selection("time|displacement|stress|strain|work|power"),
> dealii::Patterns::Integer(0), 1), "Dump to CSV file, comma separated
> values (time, displacement, stress, strain, work, power)");

Not a weird question. But also not something that's implemented.

I've been thinking for a minute on how to implement this, but the answer
is that it's not going to be easy because the patterns are really only
used to describe if a particular value for a parameter *satisfies
certain requirements*, but the patterns have nothing to do with the code
that later on parses and interprets the value.

So one thing you can do is to describe the parameter as
Patterns::Map(Patterns::Selection("..."), Patterns::Anything(), 1)
which works because Anything also matches the empty string (along with
anything else, of course). You would then just have to ensure later on
that what is in this spot is either the empty string (which you can
interpret as a default value), or indeed a positive integer.

I'm going to note that figuring out that a string is indeed a positive
integer (and nothing else) is not trivial.

Best
W.


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/
Reply all
Reply to author
Forward
0 new messages