Re: [deal.II] interpolate_boundary_values and multiple scalar components

2023-10-16 Thread Wolfgang Bangerth

On 10/15/23 22:34, Chad Balen wrote:


I wasn't b/c it typically runs slower than release mode... Ok I just finished 
installing a debug version and it gives an error message. Wow, that would've 
really helped me solve this problem sooner.


There are 14795 checks for this kind of mistake in deal.II. You really deprive 
yourself of a valuable source of debugging help if you don't run a program in 
debug mode until you know for a fact that it's working correctly.


Best
 W.

--

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


--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/e04ef261-7907-8912-e25b-b7bfe2f4588a%40colostate.edu.


Re: [deal.II] interpolate_boundary_values and multiple scalar components

2023-10-15 Thread Chad Balen
Hi Wolfgang,


*> Are you running your program in debug mode? You should have gotten an
error message with the code above.*

I wasn't b/c it typically runs slower than release mode... Ok I just
finished installing a debug version and it gives an error message. Wow,
that would've really helped me solve this problem sooner.

Thanks for the help,
Chad


On Sun, Oct 15, 2023 at 7:28 PM Wolfgang Bangerth 
wrote:

> On 10/14/23 21:01, Chad wrote:
> >
> > dealii::VectorTools::interpolate_boundary_values(dof_handler, 1,
> > dealii::Functions::ConstantFunction(1.0), boundary_values,
> var1Mask);
> > dealii::VectorTools::interpolate_boundary_values(dof_handler, 1,
> > dealii::Functions::ConstantFunction(2.0), boundary_values,
> var2Mask);
> >
> > Var1 displays the correct BC in the vtu file but Var2 displays results
> as if a
> > BC of 0.0 was used instead of 2.0.
>
> I am surprised this actually works. The boundary value function needs to
> have
> the same number of vector components as the finite element in use. Are you
> running your program in debug mode? You should have gotten an error
> message
> with the code above.
>
> > The fix seems to be that you need to
> > actually use:
> >
> > dealii::VectorTools::interpolate_boundary_values(dof_handler, 1,
> > dealii::Functions::ConstantFunction(2.0, *X*), boundary_values,
> var2Mask);
> >
> > where X >= (varIndex+1); i.e. 1 & 2 for var1 & var2 respectively.
> Looking at
> > the documentation for ConstantFunction
> > <
> https://www.dealii.org/current/doxygen/deal.II/classFunctions_1_1ConstantFunction.html#a97c9eeab728d22be4b3dddb351d8e754>
> I'd assume that the default value of 1 along with the ComponentMask would
> be sufficient to apply the BC since I only need a ConstantFunction of size
> 1 and the ComponentMask would then determine which component(s) to apply
> this value to. However, it appears you need a ConstantFunction with a size
> of ComponentMask+1 so the mask can access the ConstantFunction component(s)
> matching the ComponentMask(s).
>
> The general rule is that you need to pass function objects that have the
> same
> number of components as the finite element in question -- regardless of
> whether or not you are only evaluating some of the components. That's
> because
> oftentimes you create function objects that will be used in a variety of
> contexts (for boundary values of different kinds, computing the error,
> evaluating error estimators, etc.) where sometimes you might apply a mask
> and
> othertimes you don't.
>
> Best
>   W.
>
> --
> 
> Wolfgang Bangerth  email: bange...@colostate.edu
> www: http://www.math.colostate.edu/~bangerth/
>
>
> --
> 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 a topic in the
> Google Groups "deal.II User Group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/dealii/XaO4TZYrhCQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> dealii+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dealii/9f8d708a-053d-5ee3-eee1-d17380509a79%40colostate.edu
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/CAJ93qFjRSmCYEGLdzRaOjrAYmDp7dJVQmXGc%3DzY-uuSvyYg-_A%40mail.gmail.com.


Re: [deal.II] interpolate_boundary_values and multiple scalar components

2023-10-15 Thread Wolfgang Bangerth

On 10/14/23 21:01, Chad wrote:


dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(1.0), boundary_values, var1Mask);
dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(2.0), boundary_values, var2Mask);


Var1 displays the correct BC in the vtu file but Var2 displays results as if a 
BC of 0.0 was used instead of 2.0.


I am surprised this actually works. The boundary value function needs to have 
the same number of vector components as the finite element in use. Are you 
running your program in debug mode? You should have gotten an error message 
with the code above.


The fix seems to be that you need to 
actually use:


dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(2.0, *X*), boundary_values, var2Mask);


where X >= (varIndex+1); i.e. 1 & 2 for var1 & var2 respectively. Looking at 
the documentation for ConstantFunction 
 I'd assume that the default value of 1 along with the ComponentMask would be sufficient to apply the BC since I only need a ConstantFunction of size 1 and the ComponentMask would then determine which component(s) to apply this value to. However, it appears you need a ConstantFunction with a size of ComponentMask+1 so the mask can access the ConstantFunction component(s) matching the ComponentMask(s).


The general rule is that you need to pass function objects that have the same 
number of components as the finite element in question -- regardless of 
whether or not you are only evaluating some of the components. That's because 
oftentimes you create function objects that will be used in a variety of 
contexts (for boundary values of different kinds, computing the error, 
evaluating error estimators, etc.) where sometimes you might apply a mask and 
othertimes you don't.


Best
 W.

--

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


--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/9f8d708a-053d-5ee3-eee1-d17380509a79%40colostate.edu.


[deal.II] interpolate_boundary_values and multiple scalar components

2023-10-14 Thread Chad
So I think I finally figured out the issue but I still wanted to bring this 
up to help others and b/c the documentation seems a bit unintuitive to me. 
I took step-20 and modified it to have:

   - 2 scalar diffusion equations with FE_Q for both components
   - Dirichlet BC on the left wall (boundary ID 1) with 
   Functions::ConstantFunction()
   - Neumann BC on the right wall (boundary ID 2)

When trying to implement the Dirichlet BCs I used:

dealii::FEValuesExtractors::Scalar const var1(0);
dealii::FEValuesExtractors::Scalar const var2(1);
dealii::ComponentMask const var1Mask = fe.component_mask(var1);
dealii::ComponentMask const var2Mask = fe.component_mask(var2);

dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(1.0), boundary_values, var1Mask);
dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(2.0), boundary_values, var2Mask);

Var1 displays the correct BC in the vtu file but Var2 displays results as 
if a BC of 0.0 was used instead of 2.0. The fix seems to be that you need 
to actually use:

dealii::VectorTools::interpolate_boundary_values(dof_handler, 1, 
dealii::Functions::ConstantFunction(2.0, *X*), boundary_values, 
var2Mask);

where X >= (varIndex+1); i.e. 1 & 2 for var1 & var2 respectively. Looking 
at the documentation for ConstantFunction 

 
I'd assume that the default value of 1 along with the ComponentMask would 
be sufficient to apply the BC since I only need a ConstantFunction of size 
1 and the ComponentMask would then determine which component(s) to apply 
this value to. However, it appears you need a ConstantFunction with a size 
of ComponentMask+1 so the mask can access the ConstantFunction component(s) 
matching the ComponentMask(s).

I also attached my modified step-20 for others to see where I was playing 
around with interpolate_boundary_values() in make_grid_and_dofs().

Hope this helps,
Chad

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/d7ba3fa9-74f8-43d9-8f62-55db5421d1f7n%40googlegroups.com.


step-20b.tar.gz
Description: GNU Zip compressed data