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

Andres rev patch #42

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ docs/build/

# branch-specific tests
test_*/
src/irrevolutions/test/output/*
src/irrevolutions/test/output/*
**/output/**
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,6 @@ This code was initially conceived as a support for the teaching course MEC647,
master programme, joint between École Polytechnique and ENSTA-Paristech throughout 2020-2022.
Hence the cryptic repository name.

### Course Schedule


- 0 Introduction, motivation, and a simple experiment, in theory.
- 1 Numerics, from the basics to the solution of a linear variational problem
- 2 The notion of stability, stability of a brittle bar. The elasticity problem
- 3 Energetics link fracture to damage. Project walkthrough
- 4 The damage problem: analytics and numerics
- 5 Calibration (material, numerical) and tests
- 6 Data analysis and presentation
- Rest
- 7 Defence


### Authors
- Cf. commit messages

### Course Instructors/Authors

- V Lazarus, Sorbonne Université.
- A Leon Baldelli, CR CNRS.


### Acknowledgements

Expand All @@ -113,4 +91,4 @@ Corrado Maurini, Sorbonne Université.

### License

MIT License, see `LICENSE` file.
See `LICENSE` file.
17 changes: 17 additions & 0 deletions playground/tutorials/course.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

### Course Schedule

- 0 Introduction, motivation, and a simple experiment, in theory.
- 1 Numerics, from the basics to the solution of a linear variational problem
- 2 The notion of Stability. The elasticity problem. Stability of a brittle bar.
- 3 Energetics link fracture to damage. Project walkthrough
- 4 The damage problem: analytics and numerics
- 5 Calibration (material, numerical) and tests
- 6 Data analysis and presentation
- Rest
- 7 Play: Defence or Attack

### Course Instructors/Authors

<!-- - V Lazarus, Sorbonne Université. -->
- A Leon Baldelli, CR CNRS, ∂'Alembert
49 changes: 27 additions & 22 deletions src/irrevolutions/meshes/test_fuse.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import os
import gmsh
import pytest

# initialise gmsh engine
gmsh.initialize()
# Define the test parameters
TEST_CASES = [
{"name": "minimal_2d", "units": 1, "expected_mesh_size": 2}
# Add more test cases if needed
]

# assign name to geomtry
gmsh.model.add("simple_2d")
@pytest.mark.parametrize("test_case", TEST_CASES)
def test_generate_2d_mesh(test_case):
# Run the script
gmsh.initialize()
gmsh.model.add("simple_2d")
units = test_case["units"]
rectangle_1 = gmsh.model.occ.addRectangle(0.0, 0.0, 0.0, units, 0.5*units, tag=1)
rectangle_2 = gmsh.model.occ.addRectangle(0.0, 0.5*units, 0.0, units, 0.5*units, tag=2)
rectangles = gmsh.model.occ.fuse([(2,1)], [(2,2)], tag=3, removeObject=True, removeTool=True)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(2, [3], 1)
gmsh.model.setPhysicalName(2, 1, "rectangles")
gmsh.model.mesh.generate(1)
gmsh.model.mesh.generate(2)

units = 1
rectangle_1 = gmsh.model.occ.addRectangle(0.0, 0.0, 0.0, units, 0.5*units, tag=1)
rectangle_2 = gmsh.model.occ.addRectangle(0.0, 0.5*units, 0.0, units, 0.5*units, tag=2)
# link both domains and remove old rectangles
rectangles = gmsh.model.occ.fuse([(2,1)], [(2,2)], tag=3, removeObject=True, removeTool=True)
# Verify the generated mesh
mesh_file_path = os.path.join(os.path.dirname(__file__), "output", f"{test_case['name']}_mesh.msh")
gmsh.write(mesh_file_path)

# sycrhonise geometry with gmsh
gmsh.model.occ.synchronize()
assert os.path.isfile(mesh_file_path)

# create groups
gmsh.model.addPhysicalGroup(2, [3], 1)
gmsh.model.setPhysicalName(2, 1, "rectangles")

# gnerate 2D mesh, write mesh and convert to xdmf
gmsh.model.mesh.generate(1)
gmsh.model.mesh.generate(2)
gmsh.write("mesh_2d_minimal.msh")

# finalize gmsh engine
gmsh.finalize()
# Clean up
gmsh.finalize()
3 changes: 2 additions & 1 deletion src/irrevolutions/meshes/test_occ_2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gmsh
import os

gmsh.initialize()

Expand Down Expand Up @@ -33,7 +34,7 @@
gmsh.model.mesh.generate(2)

# Write the mesh file
gmsh.write("mesh.msh")
gmsh.write(os.path.join(os.path.dirname(__file__), "mesh.msh"))

# Finalize Gmsh
gmsh.finalize()
71 changes: 42 additions & 29 deletions src/irrevolutions/meshes/test_occ_crack.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
import gmsh
import sys
import os
import pytest

gmsh.initialize(sys.argv)
def generate_square_with_cracks():

gmsh.model.add("square with cracks")
gmsh.initialize(sys.argv)

surf1 = 1
gmsh.model.occ.addRectangle(0, 0, 0, 1, 1, surf1)
gmsh.model.add("square with cracks")

pt1 = gmsh.model.occ.addPoint(0.2, 0.2, 0)
pt2 = gmsh.model.occ.addPoint(0.4, 0.4, 0)
line1 = gmsh.model.occ.addLine(pt1, pt2)
pt3 = gmsh.model.occ.addPoint(0.4, 0.4, 0)
pt4 = gmsh.model.occ.addPoint(0.4, 0.9, 0)
line2 = gmsh.model.occ.addLine(pt3, pt4)
surf1 = 1
gmsh.model.occ.addRectangle(0, 0, 0, 1, 1, surf1)

o, m = gmsh.model.occ.fragment([(2, surf1)], [(1, line1), (1, line2)])
gmsh.model.occ.synchronize()
pt1 = gmsh.model.occ.addPoint(0.2, 0.2, 0)
pt2 = gmsh.model.occ.addPoint(0.4, 0.4, 0)
line1 = gmsh.model.occ.addLine(pt1, pt2)
pt3 = gmsh.model.occ.addPoint(0.4, 0.4, 0)
pt4 = gmsh.model.occ.addPoint(0.4, 0.9, 0)
line2 = gmsh.model.occ.addLine(pt3, pt4)

# m contains, for each input entity (surf1, line1 and line2), the child entities
# (if any) after the fragmentation, as lists of tuples. To apply the crack
# plugin we group all the intersecting lines in a physical group
o, m = gmsh.model.occ.fragment([(2, surf1)], [(1, line1), (1, line2)])
gmsh.model.occ.synchronize()

new_surf = m[0][0][1]
new_lines = [item[1] for sublist in m[1:] for item in sublist]
# m contains, for each input entity (surf1, line1 and line2), the child entities
# (if any) after the fragmentation, as lists of tuples. To apply the crack
# plugin we group all the intersecting lines in a physical group

gmsh.model.addPhysicalGroup(2, [new_surf], 100)
gmsh.model.addPhysicalGroup(1, new_lines, 101)
new_surf = m[0][0][1]
new_lines = [item[1] for sublist in m[1:] for item in sublist]

gmsh.model.mesh.generate(2)
gmsh.model.addPhysicalGroup(2, [new_surf], 100)
gmsh.model.addPhysicalGroup(1, new_lines, 101)

gmsh.plugin.setNumber("Crack", "Dimension", 1)
gmsh.plugin.setNumber("Crack", "PhysicalGroup", 101)
gmsh.plugin.setNumber("Crack", "DebugView", 1)
gmsh.plugin.run("Crack")
gmsh.model.mesh.generate(2)

# save all the elements in the mesh (even those that do not belong to any
# physical group):
gmsh.option.setNumber("Mesh.SaveAll", 1)
gmsh.write("crack.msh")
gmsh.plugin.setNumber("Crack", "Dimension", 1)
gmsh.plugin.setNumber("Crack", "PhysicalGroup", 101)
gmsh.plugin.setNumber("Crack", "DebugView", 1)
gmsh.plugin.run("Crack")

gmsh.finalize()
# save all the elements in the mesh (even those that do not belong to any
# physical group):
gmsh.option.setNumber("Mesh.SaveAll", 1)
output_file = os.path.join(os.path.dirname(__file__), "output", "crack.msh")

gmsh.finalize()

return output_file

def test_generate_square_with_cracks():
output_file = generate_square_with_cracks()
assert os.path.isfile(output_file)

if __name__ == "__main__":
pytest.main(args=[__file__])
39 changes: 24 additions & 15 deletions src/irrevolutions/meshes/test_occ_pacman.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import gmsh
import numpy as np

import os
import pytest
import sys

def create_triangle_with_angle(opening_deg, rotation = 0):

gmsh.initialize(sys.argv)

# Create a new model
gmsh.model.add("triangle_with_angle")

Expand Down Expand Up @@ -35,6 +39,12 @@ def create_triangle_with_angle(opening_deg, rotation = 0):

domain = gmsh.model.occ.rotate([(2, triangle_surface)], *p0, *_rotation_axis, angle_radians)

gmsh.model.mesh.generate(2)
output_file = os.path.join(os.path.dirname(__file__), "output", "triangle_with_angle.msh")
gmsh.write(output_file)

gmsh.finalize()
return output_file
# gmsh.model.occ.rotate([(2, triangle_surface)], base_point1, 0, 0, 1, angle_radians)

# Generate mesh
Expand Down Expand Up @@ -64,7 +74,6 @@ def create_pacman(opening_deg, rotation = 0):
base_point2 = gmsh.model.occ.addPoint(adjacent_length, 0, 0)
base_line = gmsh.model.occ.addLine(base_point1, base_point2)


# Define the vertex of the triangle
vertex_point = gmsh.model.occ.addPoint(adjacent_length * np.cos(angle_radians),
adjacent_length * np.sin(angle_radians), 0)
Expand Down Expand Up @@ -116,20 +125,20 @@ def create_pacman(opening_deg, rotation = 0):
occ.synchronize()

gmsh.model.mesh.generate(2)
# Write the mesh file
gmsh.write("test_occ.msh")
output_file = os.path.join(os.path.dirname(__file__), "output", "pacman.msh")
gmsh.write(output_file)

gmsh.finalize()
return output_file

# Finalize Gmsh
return True

# Example: Create a triangle with a 45-degree angle
def test_create_triangle_with_angle():
output_file = create_triangle_with_angle(opening_deg=30, rotation=0)
assert os.path.isfile(output_file)

def test_create_pacman():
output_file = create_pacman(opening_deg=30, rotation=180-30/2)
assert os.path.isfile(output_file)

if __name__ == "__main__":
gmsh.initialize()

# domain = create_triangle_with_angle(opening_deg = 30, rotation = 0)
domain = create_pacman(opening_deg = 30, rotation = 180-30/2)

gmsh.finalize()

pass
pytest.main(args=[__file__])
Loading
Loading