Skip to content

Commit

Permalink
Merge pull request #579 from ambaker1/nodeBounds_fix
Browse files Browse the repository at this point in the history
Node bounds fix
  • Loading branch information
mhscott committed May 24, 2021
2 parents 65d7a9f + 63b56c6 commit 534919c
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 23 deletions.
128 changes: 105 additions & 23 deletions SRC/domain/domain/Domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Domain::Domain()
dbEle(0), dbNod(0), dbSPs(0), dbPCs(0), dbMPs(0), dbLPs(0), dbParam(0),
eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0),
theElementGraph(0),
theRegions(0), numRegions(0), commitTag(0),
theRegions(0), numRegions(0), commitTag(0), initBounds(true), resetBounds(false),
theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0),
theModalProperties(0),
theModalDampingFactors(0), inclModalMatrix(false),
Expand Down Expand Up @@ -154,7 +154,7 @@ Domain::Domain(int numNodes, int numElements, int numSPs, int numMPs,
dbEle(0), dbNod(0), dbSPs(0), dbPCs(0), dbMPs(0), dbLPs(0), dbParam(0),
eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0),
theElementGraph(0),
theRegions(0), numRegions(0), commitTag(0),
theRegions(0), numRegions(0), commitTag(0), initBounds(true), resetBounds(false),
theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0),
theModalProperties(0),
theModalDampingFactors(0), inclModalMatrix(false),
Expand Down Expand Up @@ -215,7 +215,7 @@ Domain::Domain(TaggedObjectStorage &theNodesStorage,
theSPs(&theSPsStorage),
theMPs(&theMPsStorage),
theLoadPatterns(&theLoadPatternsStorage),
theRegions(0), numRegions(0), commitTag(0),
theRegions(0), numRegions(0), commitTag(0), initBounds(true), resetBounds(false),
theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0),
theModalProperties(0),
theModalDampingFactors(0), inclModalMatrix(false),
Expand Down Expand Up @@ -274,7 +274,7 @@ Domain::Domain(TaggedObjectStorage &theStorage)
dbEle(0), dbNod(0), dbSPs(0), dbPCs(0), dbMPs(0), dbLPs(0), dbParam(0),
eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0),
theElementGraph(0),
theRegions(0), numRegions(0), commitTag(0),
theRegions(0), numRegions(0), commitTag(0),initBounds(true), resetBounds(false),
theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0),
theModalProperties(0),
theModalDampingFactors(0), inclModalMatrix(false),
Expand Down Expand Up @@ -488,27 +488,46 @@ Domain::addNode(Node * node)
if (result == true) {
node->setDomain(this);
this->domainChange();

// see if the physical bounds are changed
// note this assumes 0,0,0,0,0,0 as startup min,max values
const Vector &crds = node->getCrds();
const Vector& crds = node->getCrds();
int dim = crds.Size();
if (dim >= 1) {
double x = crds(0);
if (x < theBounds(0)) theBounds(0) = x;
if (x > theBounds(3)) theBounds(3) = x;
}
if (dim >= 2) {
double y = crds(1);
if (y < theBounds(1)) theBounds(1) = y;
if (y > theBounds(4)) theBounds(4) = y;
}
if (dim == 3) {
double z = crds(2);
if (z < theBounds(2)) theBounds(2) = z;
if (z > theBounds(5)) theBounds(5) = z;
if (initBounds) {
if (dim >= 1) {
double x = crds(0);
theBounds(0) = x;
theBounds(3) = x;
}
if (dim >= 2) {
double y = crds(1);
theBounds(1) = y;
theBounds(4) = y;
}
if (dim == 3) {
double z = crds(2);
theBounds(2) = z;
theBounds(5) = z;
}
initBounds = false;
}
else {
if (dim >= 1) {
double x = crds(0);
if (x < theBounds(0)) theBounds(0) = x;
if (x > theBounds(3)) theBounds(3) = x;
}
if (dim >= 2) {
double y = crds(1);
if (y < theBounds(1)) theBounds(1) = y;
if (y > theBounds(4)) theBounds(4) = y;
}
if (dim == 3) {
double z = crds(2);
if (z < theBounds(2)) theBounds(2) = z;
if (z > theBounds(5)) theBounds(5) = z;
}
}

} else
opserr << "Domain::addNode - node with tag " << nodTag << "could not be added to container\n";

Expand Down Expand Up @@ -987,12 +1006,13 @@ Domain::clearAll(void) {
this->setModalDampingFactors(0);

// set the bounds around the origin
initBounds = true;
theBounds(0) = 0;
theBounds(1) = 0;
theBounds(2) = 0;
theBounds(3) = 0;
theBounds(4) = 0;
theBounds(5) = 0;
theBounds(4) = 0;
theBounds(5) = 0;

currentGeoTag = 0;
lastGeoSendTag = -1;
Expand Down Expand Up @@ -1057,11 +1077,16 @@ Domain::removeNode(int tag)

// mark the domain has having changed
this->domainChange();

// adjust node bounds
resetBounds = true;

// perform a downward cast to a Node (safe as only Node added to
// this container and return the result of the cast
Node *result = (Node *)mc;
// result->setDomain(0);


return result;
}

Expand Down Expand Up @@ -1596,6 +1621,63 @@ Domain::getNumParameters(void) const
const Vector &
Domain::getPhysicalBounds(void)
{
// reset bounds if nodes were deleted
if (resetBounds) {
initBounds = true;
theBounds(0) = 0;
theBounds(1) = 0;
theBounds(2) = 0;
theBounds(3) = 0;
theBounds(4) = 0;
theBounds(5) = 0;
if (theNodes->getNumComponents() != 0) {
initBounds = false;
Node* nodePtr;
NodeIter& theNodeIter = this->getNodes();
// initialize with first node
nodePtr = theNodeIter();
const Vector& crds = nodePtr->getCrds();
int dim = crds.Size();
double x, y, z;
if (dim >= 1) {
x = crds(0);
theBounds(0) = x;
theBounds(3) = x;
}
if (dim >= 2) {
y = crds(1);
theBounds(1) = y;
theBounds(4) = y;
}
if (dim == 3) {
z = crds(2);
theBounds(2) = z;
theBounds(5) = z;
}
// adjust for other nodes
while ((nodePtr = theNodeIter()) != 0) {
const Vector& crds = nodePtr->getCrds();
dim = crds.Size();
if (dim >= 1) {
x = crds(0);
if (x < theBounds(0)) theBounds(0) = x;
if (x > theBounds(3)) theBounds(3) = x;
}
if (dim >= 2) {
y = crds(1);
if (y < theBounds(1)) theBounds(1) = y;
if (y > theBounds(4)) theBounds(4) = y;
}
if (dim == 3) {
z = crds(2);
if (z < theBounds(2)) theBounds(2) = z;
if (z > theBounds(5)) theBounds(5) = z;
}
}
}
resetBounds = false;
}

return theBounds;
}

Expand Down
2 changes: 2 additions & 0 deletions SRC/domain/domain/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Domain
int commitTag;

Vector theBounds;
bool initBounds; // added to fix bug when all nodes are positive or negative - ambaker1
bool resetBounds; // added to optimize bound resetting for when nodes are removed.

Vector *theEigenvalues;
double theEigenvalueSetTime;
Expand Down

0 comments on commit 534919c

Please sign in to comment.