Skip to content

Commit

Permalink
vectorization work:
Browse files Browse the repository at this point in the history
 - beams (BEAMOR, CBEAM, PBEAM, PBEAML, PBCOMP)
  - required to now how beams be consistent
 - add_cbeam (or whatever) returns integer pointers (e.g., index, not object)
 - using center_of_mass for inertia calcs now
 - g0 default is -1, not 0

f06:
 - removed unused export_csv
 - fixing path % subcase -> (path % subcase) to fix parentheses issue
  • Loading branch information
SteveDoyle2 committed Sep 10, 2023
1 parent fe0ab7a commit 53ab755
Show file tree
Hide file tree
Showing 13 changed files with 867 additions and 390 deletions.
2 changes: 1 addition & 1 deletion pyNastran/bdf/cards/elements/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def center_of_mass_xform(self):
#x = self.get_orientation_vector()
return (ga + gb) / 2.

def get_orientation_vector(self, xyz):
def get_orientation_vector(self, xyz: np.ndarray):
"""
Element offsets are defined in a Cartesian system located at the
connecting grid point. The components of the offsets are always
Expand Down
499 changes: 252 additions & 247 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/add_card.py

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/bdf_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def inertia_sum(self, element_id: Optional[np.ndarray]=None) -> tuple[float, np.
log = self.log
element_ids_all = []
inertias = []
mass = 0.
total_mass = 0.
mass_cg = np.zeros(3, dtype='float64')
for card in self.elements:
if card.n == 0 or card.type in NO_MASS:
Expand All @@ -1280,8 +1280,16 @@ def inertia_sum(self, element_id: Optional[np.ndarray]=None) -> tuple[float, np.
#inertiai = card.inertia()
massi = card.mass()
massi_sum = massi.sum()
centroid = card.centroid()
mass += massi_sum
assert massi.shape == (card.n, ), massi.shape

if hasattr(card, 'center_of_mass'):
centroid = card.center_of_mass()
assert centroid.shape == (card.n, 3), centroid.shape
else:
centroid = card.centroid()
assert centroid.shape == (card.n, 3), centroid.shape

total_mass += massi_sum
if np.any(np.isnan(centroid)):
log.error(f'{card.type} has nan centroid; centroid={centroid}')
raise RuntimeError(f'{card.type} has nan centroid; centroid={centroid}')
Expand All @@ -1291,13 +1299,13 @@ def inertia_sum(self, element_id: Optional[np.ndarray]=None) -> tuple[float, np.
mass_cg += mass_centroid.sum(axis=0)
inertias.append((massi, centroid))

if mass == 0.:
if total_mass == 0.:
cg = np.full(3, np.nan, dtype='float64')
inertia = np.full(6, np.nan, dtype='float64')
log.error('no elements with mass...inertia is nan')
return mass, cg, inertia
return total_mass, cg, inertia

cg = mass_cg / mass
cg = mass_cg / total_mass
Ixx = 0.
Iyy = 0.
Izz = 0.
Expand All @@ -1318,16 +1326,16 @@ def inertia_sum(self, element_id: Optional[np.ndarray]=None) -> tuple[float, np.

#if fem1.wtmass != 1.0:
#print('weight = %s' % (mass1 / fem1.wtmass))
log.debug(f'mass = {mass}')
log.debug(f'mass = {total_mass}')
log.debug(f'cg = {cg}')
#print('Ixx=%s, Iyy=%s, Izz=%s \nIxy=%s, Ixz=%s, Iyz=%s' % tuple(inertia1))
log.debug(f'Ixx={Ixx:g} Iyy={Iyy:g} Izz={Izz:g}\nIxy={Ixy:g} Ixz={Ixz:g} Iyz={Iyz:g}')
#if element_id is None:
return mass, cg, inertia
return total_mass, cg, inertia

def inertia(self) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""
mass moment of inertia
[mass, cg, mass moment of inertia]
"""
log = self.log
element_ids_all = []
Expand Down Expand Up @@ -1361,15 +1369,21 @@ def inertia(self) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
mass = np.hstack(masses)
centroid = np.vstack(centroids)
abs_mass = np.abs(mass).sum()
neids = len(element_id)
#if abs_mass == 0.:
#assert len(element_id) > 0, element_id
#cg = np.full(3, np.nan, dtype='float64')
#inertia = np.full(6, np.nan, dtype='float64')
#log.error('no elements with mass...inertia is nan')
#return element_id, abs_mass, cg, inertia
mass_cg = mass[:, None] * centroid
cg = mass_cg.sum(axis=0) / mass.sum()
assert len(cg) == 3, cg
imass = (mass != 0)
cg = np.zeros(centroid.shape, dtype=centroid.dtype)
cg[imass] = mass_cg[imass, :] / mass

#cg = mass_cg.sum(axis=0) / mass.sum()
#assert len(cg) == 3, cg
assert cg.shape == (neids, 3), cg.shape

dxyz = centroid - cg
dx = dxyz[:, 0]
Expand Down
2 changes: 1 addition & 1 deletion pyNastran/dev/bdf_vectorized3/cards/elements/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def init_x_g0(card: BDFCard, eid: int):
g0 = field5
x = [np.nan, np.nan, np.nan]
elif isinstance(field5, float):
g0 = 0
g0 = -1
x = np.array([field5,
double_or_blank(card, 6, 'x2', default=np.nan),
double_or_blank(card, 7, 'x3', default=np.nan)], dtype='float64')
Expand Down
Loading

0 comments on commit 53ab755

Please sign in to comment.