Skip to content

Commit 614b2c3

Browse files
Uniform format for float in ccx input file
1 parent aac9c1d commit 614b2c3

38 files changed

+198
-164
lines changed

examples/crankshaft/crankshaft.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@
101101
)
102102

103103
f_res = 500.
104-
for t in np.linspace(0,1,12, endpoint=False):
105-
fx, fy = f_res * np.cos(np.pi*t), f_res * np.sin(np.pi*t)
106-
# Add step
104+
# Apply the force f_res in 12 steps from 0° to 330°
105+
n_steps = 12
106+
for i in range(n_steps):
107+
# calc force components
108+
angle = i / n_steps * 2 * np.pi
109+
fx, fy = f_res * np.cos(angle), f_res * np.sin(angle)
110+
# make new step
107111
step = sk.Step(nlgeom=True)
108112
load = sk.Cload(ref_load_1 , 1, fx)
109113
load.add_load(ref_load_1, 2, fy)

pygccx/auxiliary.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from protocols import number
2+
3+
def f2s(x:number) -> str:
4+
"""Returns a string of the given number in the form 15.7e"""
5+
return f'{x:.7e}'

pygccx/mesh/mesh.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .element import Element
2525
from .set import Set
2626
import protocols
27+
from auxiliary import f2s
2728

2829
@dataclass(repr=False)
2930
class Mesh:
@@ -322,7 +323,8 @@ def _write_nodes_ccx(self, buffer:list[str]):
322323
if not self.nodes: return
323324
buffer += ['*NODE']
324325
for nid, coords in self.nodes.items():
325-
buffer += ['{},{:15.7e},{:15.7e},{:15.7e}'.format(nid, *coords)]
326+
buffer += [f'{nid},' + ','.join(map(f2s, coords))]
327+
# buffer += ['{},{:15.7e},{:15.7e},{:15.7e}'.format(nid, *coords)]
326328

327329
def _write_elements_ccx(self, buffer:list[str]):
328330
if not self.elements:return

pygccx/model_keywords/amplitude.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy.typing as npt
2424

2525
from protocols import number
26+
from auxiliary import f2s
2627

2728
@dataclass
2829
class Amplitude:
@@ -56,12 +57,12 @@ class Amplitude:
5657
def __str__(self):
5758
s = f'*AMPLITUDE,NAME={self.name},'
5859
if self.use_total_time: s += 'TIME=TOTAL TIME,'
59-
if self.shift_x is not None: s += f'SHIFTX={self.shift_x},'
60-
if self.shift_y is not None: s += f'SHIFTY={self.shift_y},'
61-
s = f'{s[:-1]}\n' # delete last ','
60+
if self.shift_x is not None: s += f'SHIFTX={f2s(self.shift_x)},'
61+
if self.shift_y is not None: s += f'SHIFTY={f2s(self.shift_y)},'
62+
s = s.rstrip(',') + '\n'
6263

6364

6465
for t, a in zip(self.times, self.amps):
65-
s += f'{t:15.7e},{a:15.7e}\n'
66+
s += f'{f2s(t)},{f2s(a)}\n'
6667

6768
return s

pygccx/model_keywords/clearance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from dataclasses import dataclass
2121
from protocols import ISurface, number
22+
from auxiliary import f2s
2223

2324
@dataclass
2425
class Clearance:
@@ -45,4 +46,4 @@ class Clearance:
4546
"""A short description of this Instance. This is written to the ccx input file."""
4647

4748
def __str__(self):
48-
return f'*CLEARANCE,MASTER={self.master.name},SLAVE={self.slave.name},VALUE={self.value}\n'
49+
return f'*CLEARANCE,MASTER={self.master.name},SLAVE={self.slave.name},VALUE={f2s(self.value)}\n'

pygccx/model_keywords/contact_pair.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from typing import Optional, Any
2222
from enums import EContactTypes, ESetTypes, ESurfTypes
2323
from protocols import IKeyword, ISet, ISurface, number
24+
from auxiliary import f2s
2425

2526
@dataclass
2627
class ContactPair:
@@ -95,7 +96,7 @@ def __str__(self):
9596
if self.small_sliding: s += f',SMALL SLIDING'
9697
if self.adjust is not None:
9798
if isinstance(self.adjust, ISet): s += f',ADJUST={self.adjust.name}'
98-
else: s += f',ADJUST={self.adjust}'
99+
else: s += f',ADJUST={f2s(self.adjust)}'
99100
s += '\n'
100101

101102
s += f'{self.dep_surf.name},{self.ind_surf.name}\n'

pygccx/model_keywords/distributing_coupling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from typing import Any
2222
from protocols import ISet, number
2323
from enums import ESetTypes
24+
from auxiliary import f2s
2425

2526
@dataclass
2627
class DistribuitingCoupling:
@@ -90,8 +91,8 @@ def __str__(self):
9091

9192
for nid_or_set, weight in self.conditions:
9293
if isinstance(nid_or_set, ISet):
93-
s += f'{nid_or_set.name},{weight:.7e}\n'
94+
s += f'{nid_or_set.name},{f2s(weight)}\n'
9495
else:
95-
s += f'{nid_or_set},{weight:.7e}\n'
96+
s += f'{nid_or_set},{f2s(weight)}\n'
9697

9798
return s

pygccx/model_keywords/elastic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from dataclasses import dataclass, field, InitVar
2121
from enums import EELasticTypes
2222
from protocols import number
23+
from auxiliary import f2s
2324

2425
@dataclass
2526
class Elastic:
@@ -88,7 +89,7 @@ def __str__(self):
8889
for p in self.elastic_params_for_temps:
8990
lines = [p[i:i+n] for i in range(0, len(p) or 1, n)]
9091
for i, line in enumerate(lines):
91-
s += ','.join(map(str, line))
92+
s += ','.join(map(f2s, line))
9293
s += '\n' if i == len(lines) -1 else ',\n'
9394

9495
return s

pygccx/model_keywords/friction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from typing import Any
2222

2323
from protocols import number
24+
from auxiliary import f2s
2425
@dataclass
2526
class Friction:
2627

@@ -54,5 +55,5 @@ def __setattr__(self, name: str, value: Any) -> None:
5455

5556
def __str__(self):
5657
s = '*FRICTION\n'
57-
s += f'{self.mue},{self.lam}\n'
58+
s += f'{f2s(self.mue)},{f2s(self.lam)}\n'
5859
return s

pygccx/model_keywords/gap.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy.typing as npt
2424

2525
from protocols import ISet, number
26+
from auxiliary import f2s
2627
from enums import ESetTypes
2728

2829
@dataclass
@@ -72,9 +73,10 @@ def __setattr__(self, name: str, value: Any) -> None:
7273
def __str__(self):
7374
s = f'*GAP,ELSET={self.elset.name}\n'
7475
nx, ny, nz = self.direction
75-
s += f'{self.clearance:.7e},{nx:.7e},{ny:.7e},{nz:.7e},'
76+
s += f'{f2s(self.clearance)},{f2s(nx)},{f2s(ny)},{f2s(nz)},'
77+
7678

77-
s += f',{self.k:.7e}' if self.k is not None else ','
78-
s += f',{self.f_inf:.7e}' if self.f_inf is not None else ','
79+
s += f',{f2s(self.k)}' if self.k is not None else ','
80+
s += f',{f2s(self.f_inf)}' if self.f_inf is not None else ','
7981

8082
return s.rstrip(',') + '\n'

0 commit comments

Comments
 (0)