Thread Previous • Date Previous • Date Next • Thread Next |
Anders Logg wrote:
On Mon, Jul 24, 2006 at 06:56:32PM +0200, Dag Lindbo wrote:Hi all, The Function class is causing some headaches for me, as I try to normalize 2-vectors on my mesh. I have a form that defines the computation of a gradient, so in my solver i have a vactor-values function, normal_phi (whose components are the gradient vectors at each vertex). So far it's OK. Now I loop over all vertices and manually normalize each vector in normal_phi. This works too. But then the function, normal_phi, goes into a another form, as a Function("vector-element"). Upon this call I get a sig11: Segmentation Violation. If I do no normalization I get no violation! So I wonder what has happened. The code is very short, so I hope someone could look at it: unsigned int Nv = FEM::size(mesh, element); (...) grad_pde.solve(norml_phi); //When I write norml_phi[0] and norml_phi[1] to file they look great
Function grad_phi = norml_phi[0]; Vector& norml = grad_phi.vector();
Why are you taking a sub-function here? For the below code to make sense, should you use
Vector& norml = norml_phi.vector();That said, the above might work since as far as I recall, the sub-function grad_phi has a copy of the entire vector from norml_phi and
grad_phi.vector() returns a reference to the entire vector (I think).
for(VertexIterator vertex(mesh); !vertex.end(); ++vertex) { unsigned int vid = vertex->id(); real gpx = norml( vid ); real gpy = norml( vid + Nv); real p = std::sqrt( gpx*gpx+gpy*gpy ); norml( vid ) = gpx/p; norml( vid + Nv) = gpy/p; } norml_phi.attach(norml); // I write to VTK-file here and it looks perfect (...) kappa_pde.solve(kappa); // < SIG 11
Not sure why you get the error message, but assuming that the gradients are not the primal unknown in your problem I would recommend computing the term
normal_grad = gpx*gpx + gpy*gpydirectly using FFC, then take the square root. This will generalise more easily to any type of element.
Garth
Best regards, Dag Lindbo _______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@xxxxxxxxxx http://www.fenics.org/mailman/listinfo/dolfin-devJust back from my vacation... Did you solve this or is this still a problem? /Anders _______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@xxxxxxxxxx http://www.fenics.org/mailman/listinfo/dolfin-dev
-- Dr. Garth N. Wells Faculty of Civil Engineering and Geosciences Delft University of Technology Stevinweg 1 2628 CN Delft Netherlands tel. +31 15 278 7922 fax. +31 15 278 6383 e-mail g.n.wells@xxxxxxxxxx url http://www.mechanics.citg.tudelft.nl/~garth
Thread Previous • Date Previous • Date Next • Thread Next |