diff --git a/fem_2d.py b/fem_2d.py index 1401033656c5eda045a7904ae8cf9c608a8336eb..4ae1446f5c507d01a7aa46a54f762d2e14690085 100644 --- a/fem_2d.py +++ b/fem_2d.py @@ -333,7 +333,7 @@ class Visualizer: self.fig, self.ax = plt.subplots(figsize=(self.plot_multiplier, self.plot_multiplier)) self.ax.set_xlim(-1, 10) - self.ax.set_ylim(0, 10) + self.ax.set_ylim(-0.5, 10) def draw_elements(self, number_nodes=False): """ @@ -365,16 +365,13 @@ class Visualizer: if constr is not None: # Draw constraint here pos = node.position + print(pos) if constr.value[0]: - self.ax.text(pos[0], - pos[1]-self.text_size/150, - '^', ha='center', - fontsize=1.5 *self.text_size) + self.ax.plot(pos[0], pos[1], marker=5, color=self.constraint_color, + markersize=20) if constr.value[1]: - self.ax.text(pos[0]-self.text_size/300, - pos[1]-self.text_size/300, - '>', ha='center', - fontsize=1.5 *self.text_size) + self.ax.plot(pos[0], pos[1], marker=6, color=self.constraint_color, + markersize=20) self.ax.set_aspect('equal', adjustable='box') def draw_forces(self): @@ -445,3 +442,23 @@ class Visualizer: -direction[1], width=0.05, color=self.displaced_element_color) self.ax.set_aspect('equal', adjustable='box') + + + def draw_displaced_constraints(self): + """ + Draws constraints on its displaced locations. + """ + + for node in self.struct.node_list: + constr = node.constraint_2d + if constr is not None: + # Draw constraint here + pos = node.position + node.displacement * self.displacement_scale + print(pos) + if constr.value[0]: + self.ax.plot(pos[0], pos[1], marker=5, color=self.displaced_element_color, + markersize=20) + if constr.value[1]: + self.ax.plot(pos[0], pos[1], marker=6, color=self.displaced_element_color, + markersize=20) + self.ax.set_aspect('equal', adjustable='box') diff --git a/models_2d.py b/models_2d.py index 47b15a5eea036032a67e43718345f43aae598a12..48386057a3538e12869e8f9ab445af6ec1d5a484 100644 --- a/models_2d.py +++ b/models_2d.py @@ -37,6 +37,16 @@ def simple_square_finer(): area_ref = 0.5 return create_mesh(vertices, edges, area_ref) +def simple_square_finest(): + """ + Missing docstring. + """ + vertices = [(0, 0), (4, 0), (4, 4), (0, 4)] + edges = round_trip_connect(0, len(vertices) - 1) + global area_ref + area_ref = 0.1 + return create_mesh(vertices, edges, area_ref) + def round_trip_connect(start, end): """ diff --git a/tests_2d.py b/tests_2d.py index deff60e33c0af1c1e46013b127cf48157ab9d088..d6aca024c1ead4e218299d78c348ea7f69c1c3d1 100644 --- a/tests_2d.py +++ b/tests_2d.py @@ -3,44 +3,43 @@ Missing docstring... """ from fem_2d import Structure2DPlaneStress, Constraint2D, Force2D, Visualizer -from models_2d import simple_square_coarse, simple_square_fine, simple_square_finer +from models_2d import simple_square_coarse, simple_square_fine +from models_2d import simple_square_finer, simple_square_finest # This test the simple square fine -SQ_MESH_POINTS, SQ_MESH_ELEMENTS = simple_square_finer() +SQ_MESH_POINTS, SQ_MESH_ELEMENTS = simple_square_coarse() STR = Structure2DPlaneStress(SQ_MESH_ELEMENTS, SQ_MESH_POINTS, elastic_modulus=10e6, poisson_ratio=0.3, thickness=0.1) -plot_multiplier = 7 -displacement_scale = 200000 -VIS = Visualizer(STR, plot_multiplier, displacement_scale) - +plot_multiplier = 10 +displacement_scale = 1000000 STRUCT = list() STRUCT.append(STR) -VISUA = list() -VISUA.append(VIS) STR.node_list[0].constraint_2d = Constraint2D([1, 1]) STR.node_list[1].constraint_2d = Constraint2D([0, 1]) -STR.node_list[2].force_2d = Force2D([1, 0]) +STR.node_list[2].force_2d = Force2D([1, 1]) STR.node_list[3].constraint_2d = Constraint2D([1, 0]) STR.solve() STR.set_displacements() -""" + STR.print_details() STR.print_results() """ - +VIS = Visualizer(STR, plot_multiplier, displacement_scale) +VISUA = list() +VISUA.append(VIS) VIS.draw_elements(number_nodes=False) +VIS.draw_constraints() VIS.draw_forces() -""" + VIS.draw_displaced_elements(number_nodes=False) VIS.draw_displaced_forces() - -VIS.draw_constraints() +VIS.draw_displaced_constraints() """ \ No newline at end of file