Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior with global x, y, z variables for finite element function value #253

Closed
sgarnotel opened this issue Jan 30, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@sgarnotel
Copy link
Member

I noticed a strange behavior using global x, y and z global variable to get finite element function value at some points.

mesh Th = square(10, 10);
fespace Uh(Th, P1);
Uh u = x*y;

x = 0.5;
y = 0.5;

cout << u << endl;
// Good result
// 0.25

cout << u(x, y) << endl;
// Good result
// 0.25

{
	load "iovtk"
	savevtk("test.vtu", Th, u); // This line break the code
}

x = 0.5;
y = 0.5;
cout << u << endl;
// Wrong result
// 0.033333

cout << u(x, y) << endl;
// Good result
// 0.25

Before I use savevtk, the result is correct using the global variables x and y, equally using u(x, y). But after use savevtk the result is wrong using global variables x and y, but correct using u(x, y)

@sgarnotel sgarnotel added the bug Something isn't working label Jan 30, 2023
@frederichecht
Copy link
Contributor

frederichecht commented Feb 6, 2023 via email

@sgarnotel
Copy link
Member Author

Just copy/paste to highlight the diff

--- a/plugin/seq/iovtk.cpp
+++ b/plugin/seq/iovtk.cpp
@@ -1847,7 +1847,7 @@ class VTK_WriteMesh_Op : public E_F0mps {
 
     void writesolutionP0_float_binary(FILE *fp, const Mesh &Th, Stack stack, bool surface,
                                       bool bigEndian) const {
-      MeshPoint *mp3(MeshPointStack(stack));
+      MeshPoint *mp3(MeshPointStack(stack)),mps=*mp3;
       R2 Cdg_hat = R2(1. / 3., 1. / 3.);
 
       for (int it = 0; it < Th.nt; it++) {
@@ -1886,7 +1886,7 @@ class VTK_WriteMesh_Op : public E_F0mps {
       }
 
       fprintf(fp, "\n");
-    }
+      *mp3 = mps;}
 
     void writesolutionP0_float(FILE *fp, const Mesh &Th, Stack stack, bool surface) const {
       MeshPoint *mp3(MeshPointStack(stack));
@@ -2770,6 +2770,8 @@ void VTK_WRITE_MESH(const string &filename, FILE *fp, const Mesh &Th, bool 

@prj- prj- closed this as completed Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants