C++ dolfin::norm only on part of function

12 months ago by

I've got a function from which I need to calculate a L1-norm. I tried it like this:

dolfin::norm(func.vector(), std::string("l1));

Unfortunately the function contains at least one element which is "NaN". Is there a way to create a new function with the same content despite the "NaNs" or to calculate the norm only on a part of the function?
Thanks in advance,

Community: FEniCS Project

1 Answer

12 months ago by
You can calculate the norm manually by using ``func.vector().array()`` to access numpy array.  You can then replace any nans of the array with numpy too:

is there a similar way to do this in C++?
written 12 months ago by Justus Schock  
You have access to the dolfin::Function.vector()->get_local(), so from there I don't know if there is something in std to replace Nan's, perhaps just a for loop?
written 12 months ago by pf4d  
std::vector<double> values;

for(unsigned int i = 0; i < values.size(); i++){
        if (values[i] != values[i]){
            values[i] = 0.0;

did the trick. I only did not knew how to access the vectors content. Thanks a lot.

written 12 months ago by Justus Schock  
Happy to be of service!
written 12 months ago by pf4d  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »