Timo,

Yes, now it is absolutely clear, thank you!

Best regards,

Dmitry


On 29.03.2022 20:13, Timo Koch wrote:
Hi Dmitry,

the problem is the line

  template<class TypeTag, class MyTypeTag>
             struct TestProperty {
                 static constexpr bool value = false; };
here you define a default for _all_ TypeTags that don’t have this property 
specialised. Therefore the property is already defined for TestTag3 and it 
correctly returns 0.
It never has to go into the inheritance tree because the property is defined 
for TestTag3 directly.

For the inheritance to “work" you should replace the “value” member with an 
alias “using type = UndefinedProperty” for the unspecialised case above (see 
dumux/common/properties.hh).

If you want a “default” you could consider this the property value specialised 
for the last type tag in the inheritance tree.
So if you want to explicitly set a default, you could create a DefaultTag, 
specialise the property for that tag and then make semantically explicit in 
your “InheritsFrom” that this is the default by putting that tag last in the 
tuple.
Defaults are rather useful at the user end of the hierarchy, e.g. a model tag 
(last level of inheritance before the user) provides defaults for most 
properties and then the user can use the default if they don’t want to 
overwrite.
Broad defaults, or as in your case a default for all type tags ever defined is 
probably seldom useful.

Hope this explains it.

Best
Timo


On 29. Mar 2022, at 11:11, Dmitry Pavlov <dmitry.pav...@outlook.com> wrote:

Hello,

Seeking advice on DuMux's (DUNE's) mechanism of type tags and properties. 
Probably I misinterpret this part of the Handbook:

If you call GetProp the property system will first look for the properties 
defined in BaseTagName1 in the InheritsFrom list. If a defined property is 
found this property is returned. If no defined property is found the search 
will continue in the ancestors of BaseTagName1. If again no defined property is 
found the search will continue in the second BaseTagName2 in the list, and so 
on. If no defined property is found at all, a compiler error is triggered.

I assume that the following code will yield the positive value of the TestProperty. The 
"default" value is false, but TestTag3 inherits TestTag1 where the value is 
true.

namespace Dumux {
     namespace Properties {
         namespace TTag {

             struct TestTag1  { };
             struct TestTag2  { };

             struct TestTag3
             { using InheritsFrom = std::tuple<TestTag1, TestTag2>; };

             template<class TypeTag, class MyTypeTag>
             struct TestProperty {
                 static constexpr bool value = false; };

             template<class TypeTag>
             struct TestProperty<TypeTag, TTag::TestTag1> {
                 static constexpr bool value = true; };

} } }

....

       static constexpr bool testprop =
           GetProp<Properties::TTag::TestTag3, 
Properties::TTag::TestProperty>::value;

       std::cout << "testprop is " << testprop << "\n";


Yet it prints

testprop is 0


What am I missing?


Best regards,

Dmitry


_______________________________________________
DuMux mailing list
DuMux@listserv.uni-stuttgart.de
https://listserv.uni-stuttgart.de/mailman/listinfo/dumux
_______________________________________________
DuMux mailing list
DuMux@listserv.uni-stuttgart.de
https://listserv.uni-stuttgart.de/mailman/listinfo/dumux

Reply via email to