From ea941e285db8992899706505d56191f1e0b702fa Mon Sep 17 00:00:00 2001
From: Ernesto Oquelis <ernesto.oquelis@gmail.com>
Date: Wed, 26 Sep 2018 18:39:57 +0200
Subject: [PATCH] finishing visualizer

---
 fem_2d.py   | 15 ++++++++++++++-
 tests_2d.py |  2 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/fem_2d.py b/fem_2d.py
index eb062c5..45dc5d2 100644
--- a/fem_2d.py
+++ b/fem_2d.py
@@ -142,6 +142,8 @@ class Structure2DPlaneStress:
         self.k_es = None
         self.k_global = None
         self.r_global = None
+        self.mesh_elements = mesh_elements
+        self.mesh_points = mesh_points
         self.kept = None
         self.thickness = thickness
         self.structure_displacement = None
@@ -305,12 +307,23 @@ class Structure2DPlaneStress:
             print('{:<10}{:>15.6E}{:>15.6E}'.format(node_id, displacement[0],
                                                     displacement[1]))
 
+    def plot(self, figsize, node_labels_size):
+        import matplotlib.pyplot as plt
+        plt.figure(figsize=(figsize, figsize))
+        plt.triplot(self.mesh_points[:, 0], self.mesh_points[:, 1],
+                    self.mesh_elements)
+        plt.gca().set_aspect('equal')
+        for x_plot, y_plot in enumerate(self.mesh_points):
+            plt.text(y_plot[0] - 0.01, y_plot[1] + 0.01, x_plot, ha='right',
+                     fontsize=node_labels_size)
+        plt.show()
+
 '''
 class Visualizer:
     """
     Class visualizer.
     """
-    def __init__(self, struct, viewer):
+    def __init__(self, struct):
         self.struct = struct
         self.viewer = viewer
         self.num_nodes = self.struct.get_number_nodes()
diff --git a/tests_2d.py b/tests_2d.py
index 1841903..3f9ddbb 100644
--- a/tests_2d.py
+++ b/tests_2d.py
@@ -13,6 +13,7 @@ STR = Structure2DPlaneStress(SQ_MESH_ELEMENTS, SQ_MESH_POINTS,
                              poisson_ratio=0.3,
                              thickness=0.1)
 
+plot_multiplier = 5
 
 STRUCT = list()
 STRUCT.append(STR)
@@ -26,3 +27,4 @@ STR.node_list[4].constraint_2d = Constraint2D([1, 1])
 STR.solve()
 STR.set_displacements()
 STR.print_results()
+STR.plot(figsize=plot_multiplier, node_labels_size=2.5*plot_multiplier)
\ No newline at end of file
-- 
GitLab