Integrate difference isn't picking on the

122 views
Skip to first unread message

Abbas Ballout

unread,
Jul 14, 2023, 11:34:59 AM7/14/23
to deal.II User Group
I am overriding the value and the gradient member functions in the TensorFunction class then similar to step 7 I am using compute_global_error to compute the L2: and H1 norms. I have to convert my TensorFunction to a vector valued function in order to do this using VectorFunctionFromTensorFunction<dim>.
I am getting an exception thrown when I ask for the H1 norm saying that the gradient operator is not overridden. 

Here is a sketch of the code:


class Exact : public TensorFunction<1, dim>
{
public:
Exact() : TensorFunction<1, dim>(dim)
{
}

virtual Tensor<1, dim> value(const Point<dim> &p) const override;
virtual Tensor<2, dim> gradient(const Point<dim> &p) const override;
};


Tensor<1, dim> Exact<dim>::value(const Point<dim> &p) const
{
return Tensor<1, dim>;
}


Tensor<2, dim> Exact<dim>::gradient(const Point<dim> &p) const
{
return Tensor<2, dim>;
}

int main()
{
//blablabla tri, dofs, fe..

         // declate then convert tensor function 
Exact<dim> exact_solution;
VectorFunctionFromTensorFunction<dim> exact_solution_vector_function(exact_solution, 0, dim);

//L2 works fine
VectorTools::integrate_difference(dof_handler,
solution,
exact_solution_vector_function,
difference_per_cell,
quadrature_formula,
VectorTools::L2_norm);
// THis throws exception
VectorTools::integrate_difference(dof_handler,
solution,
exact_solution_vector_function,
difference_per_cell,
quadrature_formula,
VectorTools::H1_seminorm);;


}

Doing something as simple as:
Point<dim> p1;
exact_solution_vector_function.value(p1);
exact_solution_vector_function.gradient(p1);
is raising the exception. 


I attached the code with the cmake below too.


step-1.zip

Wolfgang Bangerth

unread,
Jul 14, 2023, 2:55:34 PM7/14/23
to dea...@googlegroups.com
On 7/14/23 09:34, Abbas Ballout wrote:
> // THis throws exception
> VectorTools::integrate_difference(dof_handler,
> solution,
> exact_solution_vector_function,
> difference_per_cell,
> quadrature_formula,
> VectorTools::H1_seminorm);;

Well, what's the error message? A good rule of thumb is that 50% debugging
consists of carefully reading what the error message says.

Best
W.

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


Abbas Ballout

unread,
Jul 16, 2023, 9:22:55 AM7/16/23
to deal.II User Group
In hindsight I could've written something simpler. 
Here it is:

--------------------------------------------------------------------------------------------
#include <deal.II/base/tensor_function.h>
#include <deal.II/numerics/vector_tools.h>

using namespace dealii;

template <int dim>
class Exact : public TensorFunction<1, dim>
{
public:
Exact() : TensorFunction<1, dim>(dim)
{}
virtual Tensor<1, dim> value(const Point<dim> &p) const override;
virtual Tensor<2, dim> gradient(const Point<dim> &p) const override;
};

template <int dim>
Tensor<1, dim> Exact<dim>::value(const Point<dim> &p) const
{
return Tensor<1, dim>();
}

template <int dim>
Tensor<2, dim> Exact<dim>::gradient(const Point<dim> &p) const
{
return Tensor<2, dim>();
}

int main()
{
const int dim = 2;
Exact<dim> exact_solution;
VectorFunctionFromTensorFunction<dim> exact_solution_vector_function(exact_solution, 0, dim);

Point<dim> p1;
exact_solution_vector_function.value(p1);
exact_solution_vector_function.gradient(p1);

return 0;
}
--------------------------------------------------------------------------------------------
I get this error when I call the exact_solution_vector_function.gradient(p1):
!ERROR Message:
An error occurred in line <135> of file </home/abbas/dealii-candi/deal-II/dealii/include/deal.II/base/function.templates.h> in function
    dealii::Tensor<1, dim, Number> dealii::Function<dim, RangeNumberType>::gradient(const dealii::Point<dim>&, unsigned int) const [with int dim = 2; RangeNumberType = double]
The violated condition was:
    false
Additional information:
    You (or a place in the library) are trying to call a function that is
    declared as a virtual function in a base class but that has not been
    overridden in your derived class.


Calling value  works fine but not  gradient even though I have overridden both functions.

Wolfgang Bangerth

unread,
Jul 16, 2023, 8:44:01 PM7/16/23
to dea...@googlegroups.com
On 7/16/23 07:22, Abbas Ballout wrote:
> I get this error when I call the exact_solution_vector_function.gradient(p1):
> !ERROR Message:
> /An error occurred in line <135> of file
> </home/abbas/dealii-candi/deal-II/dealii/include/deal.II/base/function.templates.h> in function
>     dealii::Tensor<1, dim, Number> dealii::Function<dim,
> RangeNumberType>::gradient(const dealii::Point<dim>&, unsigned int) const
> [with int dim = 2; RangeNumberType = double]
> The violated condition was:
>     false
> Additional information:
>     You (or a place in the library) are trying to call a function that is
>     declared as a virtual function in a base class but that has not been
>     overridden in your derived class./
> /
> /
> Calling value  works fine but not gradient even though I have overridden both
> functions.

You do in your own class, but VectorFunctionFromTensorFunction does not.
That's not by design, but probably simply because nobody has ever had a need
for this. Would you like to try and write a patch that adds
VectorFunctionFromTensorFunction::gradient()? You could model it on
VectorFunctionFromTensorFunction::value().

Best
Wolfgang

Abbas Ballout

unread,
Jul 17, 2023, 3:48:00 AM7/17/23
to deal.II User Group
YES. Would take me a while but I ll do it. 
Be prepared for many questions. 

Abbas Ballout

unread,
Jul 22, 2023, 12:36:59 PM7/22/23
to deal.II User Group
If I change a single line in deal I'll have to wait a good amount of time for it to compile. 
Do you all go through this? All I have is a 4 cores and 16 GBs of RAM on my Laptop.  

Lucas Myers

unread,
Jul 22, 2023, 12:53:24 PM7/22/23
to dea...@googlegroups.com
I haven't tried this with deal.II yet, but I've recently started using the mold linker for programs I write which have many compilation units (link to GitHub here: https://github.com/rui314/mold). If you're only changing one line then probably only one compilation unit is being recompiled, so the bulk of the wait time is probably being taken by the linker. 

Note that, to get a significant speedup, you'll have to recompile with all of your cores so the linking can be parallelized. I've found that using all cores to compile sometimes causes make to get killed because it uses too much memory, but if most things are compiled and you're just on the linking stage you don't really run into this. 

Alternatively, I think that some other folks use gold linker or the lld linker (in case you can't get mold to work). 

- Lucas


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/15f0b1e7-d5ea-49ed-b58f-ea10fae84d52n%40googlegroups.com.

Abbas Ballout

unread,
Jul 27, 2023, 1:24:33 PM7/27/23
to deal.II User Group
Lucas 
It's not the linker but I am guessing it's when I edit something deep within the library.h files. 
Since everything is linked to it many files are being rebuilt   
I didn't know about other linker so thanks for the tip. I am sure I will do that in the future. 

Anyone, 
This is my first pull request ever and I don't know exactly how to approach this. 
Details: 
I extended the VectorFunctionFromTensorFunction<dim>. to return the gradient of a function, 
I ended up editing the files: function.h and function.templates.h. but I ended up copying from other files. 

I am getting the right H1 convergence in my example code so I know what I am doing works. 
How do I proceed? 

Best,
Abbas  
 

Daniel Arndt

unread,
Jul 27, 2023, 2:39:33 PM7/27/23
to dea...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages