From cc627e5d406178690756e8a1d204c4a0daae4619 Mon Sep 17 00:00:00 2001
From: Laurent Stainier <laurent.stainier@ec-nantes.fr>
Date: Wed, 14 May 2003 13:35:50 +0000
Subject: [PATCH] In tensor display, min/max values are now consistent with the
 scalar Von Mises value displayed.

---
 Common/Views.cpp         | 32 ++++++++++++++++++++++++++++----
 Graphics/PostElement.cpp | 28 ++++++++++------------------
 2 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/Common/Views.cpp b/Common/Views.cpp
index 5ce4e860f1..9aaf727bb8 100644
--- a/Common/Views.cpp
+++ b/Common/Views.cpp
@@ -1,4 +1,4 @@
-// $Id: Views.cpp,v 1.94 2003-04-14 22:55:56 geuzaine Exp $
+// $Id: Views.cpp,v 1.95 2003-05-14 13:35:50 stainier Exp $
 //
 // Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle
 //
@@ -157,6 +157,27 @@ Post_View *BeginView(int allocate)
   return v;
 }
 
+// utility function
+
+double ComputeVonMises(double*); // prototype
+
+double ComputeVonMises(double *V) {
+  static const double THIRD = 1.e0 / 3.e0;
+  double tr = (V[0] + V[4] + V[8]) * THIRD;
+  double v11 = V[0] - tr;
+  double v12 = V[1];
+  double v13 = V[2];
+  double v21 = V[3];
+  double v22 = V[4] - tr;
+  double v23 = V[5];
+  double v31 = V[6];
+  double v32 = V[7];
+  double v33 = V[8] - tr;
+  return sqrt(1.5 * (v11 * v11 + v12 * v12 + v13 * v13 +
+                     v21 * v21 + v22 * v22 + v23 * v23 +
+                     v31 * v31 + v32 * v32 + v33 * v33));
+}
+  
 void Stat_Element(Post_View * v, int type, int nbnod, int N,
                   double *X, double *Y, double *Z, double *V)
 {
@@ -202,9 +223,12 @@ void Stat_Element(Post_View * v, int type, int nbnod, int N,
     v->ScalarOnly = 0;
     break;
 
-  case 2:      // tensor - TODO!
+  case 2:      // tensor
+    // by lack of any current better solution,
+    // tensors are displayed as their Von Mises
+    // invariant (J2 invariant)
     if(v->Min == VAL_INF || v->Max == -VAL_INF) {
-      l0 = sqrt(DSQR(V[0]) + DSQR(V[4]) + DSQR(V[8]));
+      l0 = ComputeVonMises(V);
       v->Min = l0;
       v->Max = l0;
       v->NbTimeStep = N / (9 * nbnod);
@@ -213,7 +237,7 @@ void Stat_Element(Post_View * v, int type, int nbnod, int N,
       v->NbTimeStep = N / (9 * nbnod);
 
     for(i = 0; i < N; i += 9) {
-      l0 = sqrt(DSQR(V[i]) + DSQR(V[i + 4]) + DSQR(V[i + 8]));
+      l0 = ComputeVonMises(V+i);
       if(l0 < v->Min)
         v->Min = l0;
       if(l0 > v->Max)
diff --git a/Graphics/PostElement.cpp b/Graphics/PostElement.cpp
index 770155e84c..1dfc24d1a0 100644
--- a/Graphics/PostElement.cpp
+++ b/Graphics/PostElement.cpp
@@ -1,4 +1,4 @@
-// $Id: PostElement.cpp,v 1.14 2003-03-21 00:52:39 geuzaine Exp $
+// $Id: PostElement.cpp,v 1.15 2003-05-14 13:35:50 stainier Exp $
 //
 // Copyright (C) 1997-2003 C. Geuzaine, J.-F. Remacle
 //
@@ -1009,6 +1009,8 @@ void Draw_VectorPyramid(ARGS)
 
 // Tensor Elements
 
+extern double ComputeVonMises(double*);
+
 void Draw_TensorElement(int type, Post_View * View,
                         double ValMin, double ValMax, double Raise[3][8],
                         double *X, double *Y, double *Z, double *V)
@@ -1042,26 +1044,16 @@ void Draw_TensorElement(int type, Post_View * View,
     break;
   }
 
-  /// we want to compute "von mises" value i.e. max eigenvalue
+  /// by lack of any current better solution,
+  /// tensors are displayed as their Von Mises
+  /// invariant (J2 invariant)
   /// this will simply call the scalar function
   if(View->TensorType == DRAW_POST_VONMISES) {
-    static const double THIRD = 1.e0 / 3.e0;
+
     double V_VonMises[8];
-    for(int i = 0; i < nbnod; i++) {
-      double tr = (V[0 + 9 * i] + V[4 + 9 * i] + V[8 + 9 * i]) * THIRD;
-      double v11 = V[0 + 9 * i] - tr;
-      double v12 = V[1 + 9 * i];
-      double v13 = V[2 + 9 * i];
-      double v21 = V[3 + 9 * i];
-      double v22 = V[4 + 9 * i] - tr;
-      double v23 = V[5 + 9 * i];
-      double v31 = V[6 + 9 * i];
-      double v32 = V[7 + 9 * i];
-      double v33 = V[8 + 9 * i] - tr;
-      V_VonMises[i] = sqrt(1.5 * (v11 * v11 + v12 * v12 + v13 * v13 +
-                                  v21 * v21 + v22 * v22 + v23 * v23 +
-                                  v31 * v31 + v32 * v32 + v33 * v33));
-    }
+    for(int i = 0; i < nbnod; i++)
+      V_VonMises[i] = ComputeVonMises(V + 9*i);
+
     switch (type) {
     case POINT:
       Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, X, Y, Z, V_VonMises);
-- 
GitLab