Use SIMAPy to create a grid of connected bodies
create_connected_bodies.py
1import os
2import numpy as np
3from pathlib import Path
4from simapy.sima import simo,hydro,sima
5
6from simapy.sima_writer import SIMAWriter
7
8def __create_body(name, x, y) -> simo.SIMOBody:
9 bdy = simo.SIMOBody()
10 bdy.name = name
11 bdy.initialPosition = sima.Position(x=x,y=y)
12 bp = simo.SIMOBodyPoint()
13 bp.name = name + "_bp1"
14 bdy.bodyPoints.append(bp)
15 bdy.structuralMass = hydro.StructuralMass(mass=10.0)
16 return bdy
17
18def __create_coupling(name) -> simo.SimpleWireCoupling:
19 swc = simo.SimpleWireCoupling()
20 swc.name = name
21 swc.ea = 10.0
22 swc.length = 1.0
23 return swc
24
25if __name__ == "__main__":
26 task = simo.SIMOTask()
27 model = simo.SIMOModel()
28 task.model=model
29
30 nx = 6 # Number of bodies in grid x-direction
31 ny = 8 # Number of bodies in grid y-direction
32 dx = 10.0 # Grid Spacing in x-direction
33 dy = 20.0 # Grid spacing in y-direction
34
35 # Create bodies
36 ib = 1
37 for y in np.linspace(0.0, 200.0, ny):
38 for x in np.linspace(0.0, 100.0, nx):
39 # Copy imported body as starting point
40 body = __create_body(f'Body{ib}',x,y)
41 # Modify position and name
42 model.bodies.append(body)
43 ib += 1
44
45 # Create couplings
46 for i in range(nx - 1):
47 for j in range(ny):
48 idx1 = i + j * nx
49 idx2 = (i + 1) + j * nx
50 coupling = __create_coupling(f'cpl_{i}_{j}_1')
51 coupling.endPoint1 = model.bodies[idx1].bodyPoints[0]
52 coupling.endPoint2 = model.bodies[idx2].bodyPoints[0]
53 model.simpleWireCouplings.append(coupling)
54
55 for i in range(nx):
56 for j in range(ny - 1):
57 idx1 = i + j * nx
58 idx2 = i + (j + 1) * nx
59 coupling = __create_coupling(f'cpl_{i}_{j}_2')
60 coupling.endPoint1 = model.bodies[idx1].bodyPoints[0]
61 coupling.endPoint2 = model.bodies[idx2].bodyPoints[0]
62 model.simpleWireCouplings.append(coupling)
63
64 output = Path(__file__).parent / ".." / ".." / "output" / "simo"
65 os.makedirs(output, exist_ok=True)
66
67 # Write model to JSON file
68 writer = SIMAWriter()
69 writer.write([task], output / 'simotask.json')
Create Connected Bodies
Source Code
create_connected_bodies.py
1import os
2import numpy as np
3from pathlib import Path
4from simapy.sima import simo,hydro,sima
5
6from simapy.sima_writer import SIMAWriter
7
8def __create_body(name, x, y) -> simo.SIMOBody:
9 bdy = simo.SIMOBody()
10 bdy.name = name
11 bdy.initialPosition = sima.Position(x=x,y=y)
12 bp = simo.SIMOBodyPoint()
13 bp.name = name + "_bp1"
14 bdy.bodyPoints.append(bp)
15 bdy.structuralMass = hydro.StructuralMass(mass=10.0)
16 return bdy
17
18def __create_coupling(name) -> simo.SimpleWireCoupling:
19 swc = simo.SimpleWireCoupling()
20 swc.name = name
21 swc.ea = 10.0
22 swc.length = 1.0
23 return swc
24
25if __name__ == "__main__":
26 task = simo.SIMOTask()
27 model = simo.SIMOModel()
28 task.model=model
29
30 nx = 6 # Number of bodies in grid x-direction
31 ny = 8 # Number of bodies in grid y-direction
32 dx = 10.0 # Grid Spacing in x-direction
33 dy = 20.0 # Grid spacing in y-direction
34
35 # Create bodies
36 ib = 1
37 for y in np.linspace(0.0, 200.0, ny):
38 for x in np.linspace(0.0, 100.0, nx):
39 # Copy imported body as starting point
40 body = __create_body(f'Body{ib}',x,y)
41 # Modify position and name
42 model.bodies.append(body)
43 ib += 1
44
45 # Create couplings
46 for i in range(nx - 1):
47 for j in range(ny):
48 idx1 = i + j * nx
49 idx2 = (i + 1) + j * nx
50 coupling = __create_coupling(f'cpl_{i}_{j}_1')
51 coupling.endPoint1 = model.bodies[idx1].bodyPoints[0]
52 coupling.endPoint2 = model.bodies[idx2].bodyPoints[0]
53 model.simpleWireCouplings.append(coupling)
54
55 for i in range(nx):
56 for j in range(ny - 1):
57 idx1 = i + j * nx
58 idx2 = i + (j + 1) * nx
59 coupling = __create_coupling(f'cpl_{i}_{j}_2')
60 coupling.endPoint1 = model.bodies[idx1].bodyPoints[0]
61 coupling.endPoint2 = model.bodies[idx2].bodyPoints[0]
62 model.simpleWireCouplings.append(coupling)
63
64 output = Path(__file__).parent / ".." / ".." / "output" / "simo"
65 os.makedirs(output, exist_ok=True)
66
67 # Write model to JSON file
68 writer = SIMAWriter()
69 writer.write([task], output / 'simotask.json')