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

Fixing issue with writeBDF in parallel #204

Merged
merged 4 commits into from
May 3, 2023
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
1 change: 1 addition & 0 deletions tacs/TACS.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ cdef extern from "TACSElement.h":
int getDesignVarsPerNode()
int getDesignVarNums(int, int, int*)
int getDesignVars(int, int, TacsScalar*)
int setDesignVars(int, int, const TacsScalar*)
int getDesignVarRange(int, int, TacsScalar*, TacsScalar*)
TACSElementBasis* getElementBasis()
TACSElementModel* getElementModel()
Expand Down
21 changes: 21 additions & 0 deletions tacs/TACS.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,27 @@ cdef class Element:
self.ptr.getDesignVars(elemIndex, dvLen, <TacsScalar*>dvs.data)
return dvs

def setDesignVars(self, int elemIndex, np.ndarray[TacsScalar, ndim=1] dvs):
"""
setDesignVars(self, int elemIndex, np.ndarray[TacsScalar, ndim=1] dvs)

Set the design variable values associated with this element

Args:
elemIndex (integer) The element index
dvs (np.ndarray) An array of the design variable values
"""
cdef int dvsPerNode = 0
cdef int dvLen = 0

if self.ptr is NULL:
return None

dvsPerNode = self.ptr.getDesignVarsPerNode()
dvLen = self.ptr.getDesignVarNums(elemIndex, 0, NULL)
assert len(dvs) == dvLen * dvsPerNode
self.ptr.setDesignVars(elemIndex, dvLen, <TacsScalar*>dvs.data)

def getDesignVarRange(self, int elemIndex):
"""
getDesignVarRange(self, int elemIndex)
Expand Down
13 changes: 10 additions & 3 deletions tacs/pytacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,9 +1573,11 @@ def writeBDF(self, fileName, problems):
)

# Make sure design variables are up-to-date
x_bvec = self.createDesignVec(asBVec=True)
x_bvec.getArray()[:] = problems[0].getDesignVars()
self.assembler.setDesignVars(x_bvec)
dv_bvec = self.createDesignVec(asBVec=True)
dv_bvec.getArray()[:] = problems[0].getDesignVars()
# Transfer all non-local dvs
dv_bvec.beginDistributeValues()
dv_bvec.endDistributeValues()

# Get local node info for each processor
multNodes = self.getLocalMultiplierNodeIDs()
Expand Down Expand Up @@ -1621,6 +1623,11 @@ def writeBDF(self, fileName, problems):
for compID, propID in enumerate(self.bdfInfo.properties):
# Get TACS element object
elemObj = self.meshLoader.getElementObject(compID, 0)
# get dv nums for element
dvNums = elemObj.getDesignVarNums(0)
# Update design variable values
dvVals = dv_bvec.getValues(dvNums)
elemObj.setDesignVars(0, dvVals)
# Get TACS constitutive object for element (if applicable)
conObj = elemObj.getConstitutive()
if conObj is not None:
Expand Down