Skip to content

Commit

Permalink
Initialise random number generator in _checkNonlinearity (#278)
Browse files Browse the repository at this point in the history
* Initialise random number generator in `_checkNonlinearity`

* Add `initRand` to TACS.pyx

* Add `initRand` to TACS.pxd

* Adding virtual function for initRand to TACSVec class

---------

Co-authored-by: Tim Brooks <41971846+timryanb@users.noreply.github.com>
  • Loading branch information
A-CGray and timryanb authored Nov 6, 2023
1 parent f91b8b1 commit 0cafe05
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bpmat/KSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class TACSVec : public TACSObject {
// Additional useful member functions
// ----------------------------------
virtual void setRand(double lower = -1.0, double upper = 1.0) {}
virtual void initRand() {}
virtual void applyBCs(TACSBcMap *map, TACSVec *vec = NULL) {}
virtual void setBCs(TACSBcMap *map) {}
};
Expand Down
9 changes: 8 additions & 1 deletion tacs/TACS.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,13 @@ cdef class Vec:
self.ptr.setRand(lower, upper)
return

def initRand(self):
"""
Initialise random number generator
"""
self.ptr.initRand()
return

def getValues(self, np.ndarray[int, ndim=1] var):
"""
Get the values from the given global indices
Expand Down Expand Up @@ -4227,4 +4234,4 @@ cdef class SpectralIntegrator:
Compute the solution at the given time instance
"""
self.ptr.computeSolutionAndDeriv(t, NULL, u.getBVecPtr(), NULL)
return
return
1 change: 1 addition & 0 deletions tacs/cpp_headers/TACS.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ cdef extern from "KSM.h":
void copyValues(TACSVec *x)
void axpby(TacsScalar alpha, TacsScalar beta, TACSVec *x)
void zeroEntries()
void initRand()
void setRand(double lower, double upper)

cdef cppclass TACSMat(TACSObject):
Expand Down
1 change: 1 addition & 0 deletions tacs/pytacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def _checkNonlinearity(self) -> bool:
self.assembler.assembleRes(res0)

# Evaluate r(u) - r(0)
state.initRand()
state.setRand()
self.setBCsInVec(state)
self.assembler.setVariables(state, state, state)
Expand Down

0 comments on commit 0cafe05

Please sign in to comment.