Skip to content

Commit

Permalink
Merge pull request OpenSees#862 from mhscott/warping
Browse files Browse the repository at this point in the history
Getting warping ND fiber section to work with OpenSeesPy
  • Loading branch information
mhscott authored May 31, 2022
2 parents 0beed7b + f86ab41 commit 4393424
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 35 deletions.
53 changes: 50 additions & 3 deletions SRC/interpreter/OpenSeesSectionCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void* OPS_FiberSectionWarping3d();
void* OPS_FiberSectionAsym3d();
void* OPS_NDFiberSection2d();
void* OPS_NDFiberSection3d();
void* OPS_NDFiberSectionWarping2d();
void* OPS_UniaxialFiber2d();
void* OPS_UniaxialFiber3d();
void* OPS_NDFiber2d();
Expand Down Expand Up @@ -101,6 +102,7 @@ namespace {
static FiberSectionAsym3d* theActiveFiberSectionAsym3d = 0;
static NDFiberSection2d* theActiveNDFiberSection2d = 0;
static NDFiberSection3d* theActiveNDFiberSection3d = 0;
static NDFiberSectionWarping2d* theActiveNDFiberSectionWarping2d = 0;

static FiberSection2dThermal* theActiveFiberSection2dThermal = 0;
static FiberSection3dThermal* theActiveFiberSection3dThermal = 0;
Expand Down Expand Up @@ -273,6 +275,21 @@ namespace {
return theSec;
}

static void* OPS_NDFiberSectionWarping()
{
void* theSec = 0;
int ndm = OPS_GetNDM();
if(ndm == 2) {
theSec = OPS_NDFiberSectionWarping2d();
theActiveNDFiberSectionWarping2d = (NDFiberSectionWarping2d*)theSec;
} else if(ndm == 3) {
//theSec = OPS_NDFiberSection3d();
//theActiveNDFiberSection3d = (NDFiberSection3d*)theSec;
}

return theSec;
}

static void* OPS_UniaxialSection()
{
int numdata = OPS_GetNumRemainingInputArgs();
Expand Down Expand Up @@ -1080,6 +1097,7 @@ namespace {
functionMap.insert(std::make_pair("FiberAsym", &OPS_FiberSectionAsym));
functionMap.insert(std::make_pair("FiberThermal", &OPS_FiberSectionThermal));
functionMap.insert(std::make_pair("NDFiber", &OPS_NDFiberSection));
functionMap.insert(std::make_pair("NDFiberWarping", &OPS_NDFiberSectionWarping));
functionMap.insert(std::make_pair("Uniaxial", &OPS_UniaxialSection));
functionMap.insert(std::make_pair("Generic1D", &OPS_UniaxialSection));
functionMap.insert(std::make_pair("Generic1d", &OPS_UniaxialSection));
Expand Down Expand Up @@ -1119,7 +1137,8 @@ int OPS_Section()
theActiveFiberSectionAsym3d = 0;
theActiveNDFiberSection2d = 0;
theActiveNDFiberSection3d = 0;

theActiveNDFiberSectionWarping2d = 0;

theActiveFiberSection2dThermal = 0;
theActiveFiberSection3dThermal = 0;
//theActiveFiberSectionGJThermal = 0;
Expand Down Expand Up @@ -1157,7 +1176,8 @@ int OPS_Section()
theActiveFiberSectionAsym3d = 0;
theActiveNDFiberSection2d = 0;
theActiveNDFiberSection3d = 0;

theActiveNDFiberSectionWarping2d = 0;

theActiveFiberSection2dThermal = 0;
theActiveFiberSection3dThermal = 0;
//theActiveFiberSectionGJThermal = 0;
Expand All @@ -1182,7 +1202,7 @@ int OPS_Fiber()

theFiber = (UniaxialFiber3d*) OPS_UniaxialFiber3d();

} else if (theActiveNDFiberSection2d != 0) {
} else if (theActiveNDFiberSection2d != 0 || theActiveNDFiberSectionWarping2d != 0) {

theFiber = (NDFiber2d*) OPS_NDFiber2d();

Expand Down Expand Up @@ -1225,6 +1245,10 @@ int OPS_Fiber()

res = theActiveNDFiberSection3d->addFiber(*theFiber);

} else if (theActiveNDFiberSectionWarping2d != 0) {

res = theActiveNDFiberSectionWarping2d->addFiber(*theFiber);

} else if (theActiveFiberSection2dThermal != 0) {

res = theActiveFiberSection2dThermal->addFiber(*theFiber);
Expand Down Expand Up @@ -1377,6 +1401,17 @@ int OPS_Patch()
}
theFiber = new NDFiber3d(j,*ndmaterial,area,cPos(0),cPos(1));
theActiveNDFiberSection3d->addFiber(*theFiber);

} else if (theActiveNDFiberSectionWarping2d != 0) {

ndmaterial = OPS_getNDMaterial(matTag);
if (ndmaterial == 0) {
opserr << "WARNING material "<<matTag<<" cannot be found\n";
delete thePatch;
return -1;
}
theFiber = new NDFiber2d(j,*ndmaterial,area,cPos(0));
theActiveNDFiberSectionWarping2d->addFiber(*theFiber);
}

delete cells[j];
Expand Down Expand Up @@ -1522,7 +1557,19 @@ int OPS_Layer()
}
theFiber = new NDFiber3d(j,*ndmaterial,area,cPos(0),cPos(1));
theActiveNDFiberSection3d->addFiber(*theFiber);

} else if (theActiveNDFiberSectionWarping2d != 0) {

ndmaterial = OPS_getNDMaterial(matTag);
if (ndmaterial == 0) {
opserr << "WARNING material "<<matTag<<" cannot be found\n";
delete theLayer;
return -1;
}
theFiber = new NDFiber2d(j,*ndmaterial,area,cPos(0));
theActiveNDFiberSectionWarping2d->addFiber(*theFiber);
}


}

Expand Down
148 changes: 119 additions & 29 deletions SRC/material/section/NDFiberSectionWarping2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,45 @@
#include <NDMaterial.h>
#include <SectionIntegration.h>
#include <Parameter.h>
#include <elementAPI.h>

ID NDFiberSectionWarping2d::code(5);

void* OPS_NDFiberSectionWarping2d()
{
int numData = OPS_GetNumRemainingInputArgs();
if(numData < 1) {
opserr<<"insufficient arguments for NDFiberSectionWarping2d\n";
return 0;
}

numData = 1;
int tag;
if (OPS_GetIntInput(&numData,&tag) < 0) return 0;

double alpha = 1.0;
bool computeCentroid = true;
while (OPS_GetNumRemainingInputArgs() > 0) {
const char* opt = OPS_GetString();
if (strcmp(opt, "-noCentroid") == 0)
computeCentroid = false;
if (strcmp(opt, "-alpha") == 0 || strcmp(opt, "-shape") == 0) {
if (OPS_GetNumRemainingInputArgs() < 1)
break;
numData = 1;
if (OPS_GetDoubleInput(&numData,&alpha) < 0)
return 0;
}
}

int num = 30;
return new NDFiberSectionWarping2d(tag, num, alpha);
}

// constructors:
NDFiberSectionWarping2d::NDFiberSectionWarping2d(int tag, int num, Fiber **fibers, double a):
SectionForceDeformation(tag, SEC_TAG_NDFiberSectionWarping2d),
numFibers(num), theMaterials(0), matData(0), yBar(0.0), alpha(a), sectionIntegr(0),
numFibers(num), sizeFibers(num), theMaterials(0), matData(0), yBar(0.0), alpha(a), sectionIntegr(0),
e(5), eCommit(5), s(0), ks(0), parameterID(0), dedh(5), yBarZero(0.0)
{
if (numFibers != 0) {
Expand Down Expand Up @@ -141,10 +173,56 @@ SectionForceDeformation(tag, SEC_TAG_NDFiberSectionWarping2d),
code(4) = SECTION_RESPONSE_Q;
}

NDFiberSectionWarping2d::NDFiberSectionWarping2d(int tag, int num, double a):
SectionForceDeformation(tag, SEC_TAG_NDFiberSectionWarping2d),
numFibers(0), sizeFibers(num), theMaterials(0), matData(0),
yBar(0.0), alpha(a), sectionIntegr(0), e(5), s(0), ks(0),
parameterID(0), dedh(5)
{
if (sizeFibers != 0) {
theMaterials = new NDMaterial *[sizeFibers];

if (theMaterials == 0) {
opserr << "NDFiberSection2d::NDFiberSection2d -- failed to allocate Material pointers";
exit(-1);
}

matData = new double [sizeFibers*2];

if (matData == 0) {
opserr << "NDFiberSection2d::NDFiberSection2d -- failed to allocate double array for material data\n";
exit(-1);
}


for (int i = 0; i < sizeFibers; i++) {
matData[i*2] = 0.0;
matData[i*2+1] = 0.0;
theMaterials[i] = 0;
}
}

int order = 5;
s = new Vector(sData, order);
ks = new Matrix(kData, order, order);

for (int i = 0; i < order; i++) {
sData[i] = 0.0;
for (int j = 0; j < order; j++)
kData[5*i + j] = 0.0;
}

code(0) = SECTION_RESPONSE_P;
code(1) = SECTION_RESPONSE_MZ;
code(2) = SECTION_RESPONSE_VY;
code(3) = SECTION_RESPONSE_R;
code(4) = SECTION_RESPONSE_Q;
}

NDFiberSectionWarping2d::NDFiberSectionWarping2d(int tag, int num, NDMaterial **mats,
SectionIntegration &si, double a):
SectionForceDeformation(tag, SEC_TAG_NDFiberSectionWarping2d),
numFibers(num), theMaterials(0), matData(0), yBar(0.0), alpha(a),
numFibers(num), sizeFibers(num), theMaterials(0), matData(0), yBar(0.0), alpha(a),
sectionIntegr(0), e(5), eCommit(5), s(0), ks(0), parameterID(0), dedh(5), yBarZero(0.0)
{
if (numFibers != 0) {
Expand Down Expand Up @@ -238,7 +316,7 @@ SectionForceDeformation(tag, SEC_TAG_NDFiberSectionWarping2d),
// constructor for blank object that recvSelf needs to be invoked upon
NDFiberSectionWarping2d::NDFiberSectionWarping2d():
SectionForceDeformation(0, SEC_TAG_NDFiberSectionWarping2d),
numFibers(0), theMaterials(0), matData(0), yBar(0.0), alpha(6.0/6),
numFibers(0), sizeFibers(0), theMaterials(0), matData(0), yBar(0.0), alpha(6.0/6),
sectionIntegr(0), e(5), eCommit(5), s(0), ks(0), parameterID(0), dedh(5), yBarZero(0.0)
{
s = new Vector(sData, 5);
Expand Down Expand Up @@ -284,9 +362,10 @@ SectionForceDeformation(0, SEC_TAG_NDFiberSectionWarping2d),
}

int
NDFiberSectionWarping2d::addFiber(Fiber &newFiber)
NDFiberSectionWarping2d::addFiber(Fiber &newFiber)
{
// need to create larger arrays
if (numFibers == sizeFibers) {
int newSize = numFibers+1;
NDMaterial **newArray = new NDMaterial *[newSize];
double *newMatData = new double [2 * newSize];
Expand All @@ -303,36 +382,45 @@ int
newMatData[2*i+1] = matData[2*i+1];
}

// set the new pointers and data
double yLoc, zLoc, Area;
newFiber.getFiberLocation(yLoc, zLoc);
Area = newFiber.getArea();
newMatData[numFibers*2] = yLoc;
newMatData[numFibers*2+1] = Area;
NDMaterial *theMat = newFiber.getNDMaterial();
newArray[numFibers] = theMat->getCopy("BeamFiber2d");

if (newArray[numFibers] == 0) {
opserr <<"NDFiberSectionWarping2d::addFiber -- failed to get copy of a Material\n";
delete [] newMatData;
return -1;
}

numFibers++;

if (theMaterials != 0) {
delete [] theMaterials;
delete [] matData;
}

theMaterials = newArray;
matData = newMatData;
// initial memory
for (int i = numFibers; i < newSize; i++) {
newArray[i] = 0;
newMatData[2*i] = 0.0;
newMatData[2*i+1] = 0.0;
}
sizeFibers = newSize;

// set new memory
if (theMaterials != 0) {
delete [] theMaterials;
delete [] matData;
}

theMaterials = newArray;
matData = newMatData;
}

// set the new pointers and data
double yLoc, zLoc, Area;
newFiber.getFiberLocation(yLoc, zLoc);
Area = newFiber.getArea();
matData[numFibers*2] = yLoc;
matData[numFibers*2+1] = Area;
NDMaterial *theMat = newFiber.getNDMaterial();
theMaterials[numFibers] = theMat->getCopy("BeamFiber2d");

if (theMaterials[numFibers] == 0) {
opserr <<"NDFiberSectionWarping2d::addFiber -- failed to get copy of a Material\n";
return -1;
}

numFibers++;

double Qz = 0.0;
double A = 0.0;

// Recompute centroid
for (i = 0; i < numFibers; i++) {
for (int i = 0; i < numFibers; i++) {
yLoc = -matData[2*i];
Area = matData[2*i+1];
A += Area;
Expand Down Expand Up @@ -706,6 +794,7 @@ SectionForceDeformation*
theCopy->setTag(this->getTag());

theCopy->numFibers = numFibers;
theCopy->sizeFibers = numFibers;

if (numFibers != 0) {
theCopy->theMaterials = new NDMaterial *[numFibers];
Expand Down Expand Up @@ -1214,6 +1303,7 @@ int

// create memory to hold material pointers and fiber data
numFibers = data(1);
sizeFibers = data(1);
if (numFibers != 0) {
theMaterials = new NDMaterial *[numFibers];

Expand Down
7 changes: 4 additions & 3 deletions SRC/material/section/NDFiberSectionWarping2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class NDFiberSectionWarping2d : public SectionForceDeformation
public:
NDFiberSectionWarping2d();
NDFiberSectionWarping2d(int tag, int numFibers, Fiber **fibers, double a = 1.0);
NDFiberSectionWarping2d(int tag, int numFibers, NDMaterial **mats,
SectionIntegration &si, double a = 1.0);
NDFiberSectionWarping2d(int tag, int num, double a = 1.0);
NDFiberSectionWarping2d(int tag, int numFibers, NDMaterial **mats,
SectionIntegration &si, double a = 1.0);
~NDFiberSectionWarping2d();

const char *getClassType(void) const {return "NDFiberSectionWarping2d";};
Expand Down Expand Up @@ -96,7 +97,7 @@ class NDFiberSectionWarping2d : public SectionForceDeformation
protected:

// private:
int numFibers; // number of fibers in the section
int numFibers,sizeFibers; // number of fibers in the section
NDMaterial **theMaterials; // array of pointers to materials
double *matData; // data for the materials [yloc and area]
double kData[25]; // data for ks matrix
Expand Down

0 comments on commit 4393424

Please sign in to comment.