Visualize vector expression c++

197
views
0
4 months ago by
Hello everyone,

I have a vector expression like

class B : public Expressionclass B : public Expression{public:      B () : Expression(2) {} void eval(Array<double>& values, const Array<double>& x) const {           values[0] = ((1-pow(x[0],2))*M_PI*cos(2*M_PI*x[1]))/25;                values[1] = 1/5 ;
 } };

and to visualize it I am doing a projection to the mesh like
B bb;
Function b_inter(V); b_inter.interpolate(bb);  dolfin::File(result_dir + "b_interpolated_" + std::to_string(N) + ".pvd") << b_inter;but i get an error saying
error: no match for ‘operator<<’ (operand types are ‘dolfin::GenericFile’ and ‘const std::shared_ptr<dolfin::Mesh>’)

Anyone knows what is going on here?

Thanks in advance

Community: FEniCS Project

1 Answer

3
4 months ago by
Try:
auto b_inter = std::make_shared<dolfin::Function>(V);

and then de-reference the function pointer:

...<< *b_inter;
This did not work :( It gives me an error saying that Function does not have a class called interpolate
written 4 months ago by noname
1
Are you using the pointer correctly (not dot notation)?

auto b_inter = std::make_shared<dolfin::Function>(V);
b_inter->interpolate(bb);
written 4 months ago by jwinkle
This actually works, thanks :) just out of curiosity so what really is the difference between two notations?
written 4 months ago by noname
This is standard C++, so you may not be familiar with pointers in C/C++.  Suggest searching pointer de-referencing vs. dot notation in C++.
the std::make_shared<Class> is a way to generate a class instance from the heap, but with automatic garbage collection (relatively recent in C++ spec.).  This replaces using "new" and "delete".  When you instead declare :
Function b_inter(V);
you are declaring at compile time, so it is an object whose members are referenced using dot notation.  Pointers to objects always use -> for members.
Fenics classes require (mostly) shared_ptr types, which is what make_shared<Class> returns.
written 4 months ago by jwinkle
Please login to add an answer/comment or follow this question.

Similar posts:
Search »