Recommendation: BCs in config

39 views
Skip to first unread message

Franco Milicchio

unread,
Feb 13, 2017, 9:01:51 AM2/13/17
to deal.II User Group
Dear all,

I want to have a series of functions read from an input file handled by the ParameterHandler class. These are the BCs of my problem, but I don't know how I could express them, since I'd like to have an unknown number of them. 

As far as I've understood, the parameters sections must have a unique name, so I simply cannot do something like this:

subsection dirichlet

  subsection bc
    set value = 0.5 * x + y
  end

  subsection bc
    set value = x * y^2
  end

end

and I am forced to use bc1, bc2, and so on as names. Moreover, this means that I have to declare beforehand all the possible sections within a reasonable number of BCs.

Do you have any suggestions?

Thanks!




Bruno Turcksin

unread,
Feb 13, 2017, 9:09:20 AM2/13/17
to deal.II User Group
Franco,

you could write everything into one string and then split it. So it would like this:

subsection bc
  set value = 0.5*x+y; x*y^2
end

Take a look here http://stackoverflow.com/questions/236129/split-a-string-in-c for some ideas how to split a string.

Best,

Bruno

Franco Milicchio

unread,
Feb 13, 2017, 9:46:29 AM2/13/17
to deal.II User Group


On Monday, February 13, 2017 at 3:09:20 PM UTC+1, Bruno Turcksin wrote:
Franco,

you could write everything into one string and then split it. So it would like this:

subsection bc
  set value = 0.5*x+y; x*y^2
end

Take a look here http://stackoverflow.com/questions/236129/split-a-string-in-c for some ideas how to split a string.

Best,

Bruno

Thanks for your answer, Bruno.

Yes, I have thought of that but I cannot see right now how I could express vector functions. Using a custom separator isn't really nice here...

Thank you!

Bruno Turcksin

unread,
Feb 13, 2017, 9:52:23 AM2/13/17
to dea...@googlegroups.com
2017-02-13 9:46 GMT-05:00 Franco Milicchio <franco.m...@gmail.com>:
> Yes, I have thought of that but I cannot see right now how I could express
> vector functions. Using a custom separator isn't really nice here...
Why not? You can split the string several times using different separators:

set value = 0.5*x+y, x, y; x*y^2

You first split value in 0.5*x+y, x, y and x*y^2 and then you can
split 0.5*x+y, x, y in three components.

Best,

Bruno

Franco Milicchio

unread,
Feb 13, 2017, 10:34:30 AM2/13/17
to deal.II User Group


On Monday, February 13, 2017 at 3:52:23 PM UTC+1, Bruno Turcksin wrote:
Why not? You can split the string several times using different separators:

set value = 0.5*x+y, x, y; x*y^2

You first split value in 0.5*x+y, x, y and x*y^2 and then you can
split 0.5*x+y, x, y in three components.



Because I can imagine that having several BCs with some magic char there is simply a recipe for disaster :)

Just think about this example:

  set dirichlet = x^2+y^2 : if(x < 0, 1, 3) : 0; 0 : 0 : 0

 Since I am working with people not well versed in programming, that is quite a concern to me.

Cheers!

Bruno Turcksin

unread,
Feb 13, 2017, 10:49:48 AM2/13/17
to dea...@googlegroups.com
2017-02-13 10:34 GMT-05:00 Franco Milicchio <franco.m...@gmail.com>:
> Because I can imagine that having several BCs with some magic char there is
> simply a recipe for disaster :)
>
> Just think about this example:
>
> set dirichlet = x^2+y^2 : if(x < 0, 1, 3) : 0; 0 : 0 : 0
>
> Since I am working with people not well versed in programming, that is
> quite a concern to me.
Well then you will need to declare everything in advance. The only
solution I can think of is to use sth like boost::property_tree
instead of ParameterHandler.

Best,

Bruno

luca.heltai

unread,
Feb 13, 2017, 11:32:09 AM2/13/17
to Deal.II Users
Actually, you have some alternatives…

Take a look at this class:

https://github.com/mathLab/deal2lkit/blob/master/include/deal2lkit/parsed_mapped_functions.h

It does something similar to what you are asking for.

(documentation here:

http://mathlab.github.io/deal2lkit/class_parsed_mapped_functions.html

Best,
Luca.
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Wolfgang Bangerth

unread,
Feb 14, 2017, 7:28:16 PM2/14/17
to dea...@googlegroups.com
On 02/13/2017 07:09 AM, Bruno Turcksin wrote:
>
>
> you could write everything into one string and then split it. So it
> would like this:
>
> subsection bc
> set value = 0.5*x+y; x*y^2
> end
>
> Take a look here
> http://stackoverflow.com/questions/236129/split-a-string-in-c for some
> ideas how to split a string.

Yes, this is the way to go. In fact, we have a function that splits strings:

https://www.dealii.org/8.4.0/doxygen/deal.II/namespaceUtilities.html#a8d799bb35ac16d206818c88e82afbfae

We use the scheme Bruno proposes to split strings first by semicolon,
and then again by comma all the time in our own projects. If you don't
like semicolons/commas, any other choice of course also works.

As far as working with people who are not used to programming -- this is
a tricky question. It is true that you need to provide a way that's
readable, but using work-arounds like have multiple sections is also not
entirely obvious and will invite questions whose answers you also have
to document somewhere. It is a balance that's sometimes difficult to
strike. I typically strive for a solution that is easiest to describe
and easiest to understand *in its entirety*. In your case, I would
probably choose splitting on semicolons and colons, and in the
documentation show how you can split different, semicolon-separated
parts of the formula onto separate lines using a backslash at the end of
the line to show that that makes formulas easier to read.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Franco Milicchio

unread,
Feb 15, 2017, 4:31:32 AM2/15/17
to deal.II User Group, bang...@colostate.edu

> Take a look here
> http://stackoverflow.com/questions/236129/split-a-string-in-c for some
> ideas how to split a string.

Yes, this is the way to go. In fact, we have a function that splits strings:

https://www.dealii.org/8.4.0/doxygen/deal.II/namespaceUtilities.html#a8d799bb35ac16d206818c88e82afbfae

We use the scheme Bruno proposes to split strings first by semicolon,
and then again by comma all the time in our own projects. If you don't
like semicolons/commas, any other choice of course also works.

As far as working with people who are not used to programming -- this is
a tricky question. It is true that you need to provide a way that's
readable, but using work-arounds like have multiple sections is also not
entirely obvious and will invite questions whose answers you also have
to document somewhere. It is a balance that's sometimes difficult to
strike. I typically strive for a solution that is easiest to describe
and easiest to understand *in its entirety*. In your case, I would
probably choose splitting on semicolons and colons, and in the
documentation show how you can split different, semicolon-separated
parts of the formula onto separate lines using a backslash at the end of
the line to show that that makes formulas easier to read.




Thanks, Wolfgang, I've implemented this, and I am now exploring Luca's code.

Cheers,
    Franco 
Reply all
Reply to author
Forward
0 new messages