Skip to content

Commit 2e0401c

Browse files
committed
Added: New method SAM::getNoSpecified DOFs().
Removed: Unused methods SAM::initForAssembly() and SAM::getNoElmEquations(). Changed: Use std::accumulate to calculate element size from connectivity. Changed: Don't check return value for methods that will never fail.
1 parent f515e99 commit 2e0401c

File tree

5 files changed

+60
-131
lines changed

5 files changed

+60
-131
lines changed

src/ASM/AlgEqSystem.C

+7-3
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,21 @@ bool AlgEqSystem::init (LinAlg::MatrixType mtype, const LinSolParams* spar,
7070
if (!b[i]) return false;
7171
}
7272

73-
bool ok = true;
73+
if (sam.getNoEquations() < 0)
74+
return false;
75+
7476
if (A.size() == 1 && !b.empty())
7577
{
7678
A.front()._b = b.front();
77-
ok = sam.initForAssembly(*b.front(), withReactions ? &R : nullptr);
79+
b.front()->redim(sam.getNoEquations());
80+
if (withReactions)
81+
R.resize(sam.getNoSpecifiedDOFs());
7882
}
7983

8084
for (i = 0; i < b.size(); i++)
8185
b[i]->redim(sam.getNoEquations());
8286

83-
return ok;
87+
return true;
8488
}
8589

8690

src/ASM/ReactionsOnly.C

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ ReactionsOnly::ReactionsOnly (const SAM* sam, const ProcessAdm& adm,
2222
RealArray* rf, Vector* sf)
2323
: mySam(sam), myAdm(adm), R(rf), S(sf)
2424
{
25-
mySam->initForAssembly(b,R);
25+
b.redim(sam->getNoEquations());
26+
if (R)
27+
R->resize(sam->getNoSpecifiedDOFs());
2628
}
2729

2830

src/LinAlg/SAM.C

+42-90
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "SAM.h"
1515
#include "SystemMatrix.h"
16+
#include <numeric>
1617
#include <iomanip>
1718

1819
#ifdef USE_F77SAM
@@ -182,7 +183,7 @@ void SAM::print (std::ostream& os) const
182183
}
183184
code[i] = dofType[i] = '\0';
184185
os <<'\t'<< code;
185-
if ((size_t)n < nodeType.size())
186+
if (n < static_cast<int>(nodeType.size()))
186187
os <<'\t'<< nodeType[n];
187188
if (strlen(dofType) > 0)
188189
os <<'\t' << dofType;
@@ -332,15 +333,14 @@ int SAM::getNoNodes (char dofType) const
332333
}
333334

334335

335-
bool SAM::getDofCouplings (IntVec& irow, IntVec& jcol) const
336+
void SAM::getDofCouplings (IntVec& irow, IntVec& jcol) const
336337
{
337338
irow.clear();
338339
jcol.clear();
339340

340341
// Find the set of DOF couplings for each free DOF
341342
std::vector<IntSet> dofc;
342-
if (!this->getDofCouplings(dofc))
343-
return false;
343+
this->getDofCouplings(dofc);
344344

345345
irow.resize(neq+1);
346346
irow.front() = 0;
@@ -353,19 +353,16 @@ bool SAM::getDofCouplings (IntVec& irow, IntVec& jcol) const
353353
jcol.reserve(irow.back());
354354
for (i = 0; i < neq; i++)
355355
jcol.insert(jcol.end(),dofc[i].begin(),dofc[i].end());
356-
357-
return true;
358356
}
359357

360358

361-
bool SAM::getDofCouplings (std::vector<IntSet>& dofc) const
359+
void SAM::getDofCouplings (std::vector<IntSet>& dofc) const
362360
{
363361
dofc.resize(neq);
364362
for (int iel = 1; iel <= nel; iel++)
365363
{
366364
IntVec meen;
367-
if (!this->getElmEqns(meen,iel))
368-
return false;
365+
this->getElmEqns(meen,iel);
369366

370367
for (size_t j = 0; j < meen.size(); j++)
371368
{
@@ -415,35 +412,6 @@ bool SAM::getDofCouplings (std::vector<IntSet>& dofc) const
415412
}
416413
}
417414
}
418-
419-
return true;
420-
}
421-
422-
423-
bool SAM::initForAssembly (SystemMatrix& sysK, SystemVector& sysRHS,
424-
RealArray* reactionForces, bool dontLockSP) const
425-
{
426-
sysK.initAssembly(*this,dontLockSP);
427-
return this->initForAssembly(sysRHS,reactionForces);
428-
}
429-
430-
431-
bool SAM::initForAssembly (SystemMatrix& sysM) const
432-
{
433-
sysM.initAssembly(*this);
434-
return neq > 0 ? true : false;
435-
}
436-
437-
438-
bool SAM::initForAssembly (SystemVector& sysRHS,
439-
RealArray* reactionForces) const
440-
{
441-
sysRHS.redim(neq);
442-
sysRHS.init();
443-
if (reactionForces)
444-
reactionForces->resize(nspdof,true);
445-
446-
return neq > 0 ? true : false;
447415
}
448416

449417

@@ -579,7 +547,7 @@ bool SAM::assembleSystem (SystemVector& sysRHS, const Real* nS, int inod,
579547
for (int j = madof[inod-1]; j < madof[inod]; j++, k++)
580548
{
581549
int ipR = -msc[j-1];
582-
if (ipR > 0 && (size_t)ipR <= reactionForces->size())
550+
if (ipR > 0 && ipR <= static_cast<int>(reactionForces->size()))
583551
(*reactionForces)[ipR-1] += nS[k];
584552
}
585553
}
@@ -617,7 +585,10 @@ void SAM::addToRHS (SystemVector& sysRHS, const RealArray& S) const
617585
{
618586
if (ndof < 1 || S.empty()) return;
619587

620-
for (size_t i = 0; i < S.size() && i < (size_t)ndof; i++)
588+
int n = S.size();
589+
if (n > ndof) n = ndof;
590+
591+
for (int i = 0; i < n; i++)
621592
this->assembleRHS(sysRHS.getPtr(),S[i],meqn[i]);
622593
}
623594

@@ -651,7 +622,7 @@ void SAM::assembleReactions (RealArray& rf, const RealArray& eS, int iel) const
651622
for (int j = madof[node-1]; j < madof[node] && k < eS.size(); j++, k++)
652623
{
653624
int ipR = -msc[j-1];
654-
if (ipR > 0 && (size_t)ipR <= rf.size())
625+
if (ipR > 0 && ipR <= static_cast<int>(rf.size()))
655626
rf[ipR-1] += eS[k];
656627
}
657628
}
@@ -689,32 +660,34 @@ bool SAM::getElmEqns (IntVec& meen, int iel, size_t nedof) const
689660
}
690661

691662
int ip = mpmnpc[iel-1];
692-
int nenod = mpmnpc[iel] - ip;
663+
int nenod = mpmnpc[iel] - (ip--);
693664
if (nenod < 1) return true;
694-
if (nedof == 0)
695-
for (int i = 0; i < nenod; i++)
696-
{
697-
int node = abs(mmnpc[ip-1+i]);
698-
nedof += madof[node] - madof[node-1];
699-
}
665+
666+
int neldof = 0;
667+
if (nedof == 0) // Calculate element size from the nodal connectivity
668+
neldof = std::accumulate(mmnpc+ip, mmnpc+ip+nenod, 0,
669+
[this](const int& offs, const int& inod) {
670+
int node = inod > 0 ? inod : -inod;
671+
return offs + madof[node] - madof[node-1]; });
672+
700673
#ifdef USE_F77SAM
701-
int neldof, neslv, neprd;
702-
meen.resize(nedof,0);
703-
elmeq_(madof,mmnpc+ip-1,mpmceq,meqn,nenod,&meen.front(),neldof,neslv,neprd);
704-
if (neldof < static_cast<int>(nedof)) meen.resize(neldof);
674+
int neslv, neprd;
675+
meen.resize(nedof > 0 ? nedof : neldof, 0);
676+
elmeq_(madof,mmnpc+ip,mpmceq,meqn,nenod,&meen.front(),neldof,neslv,neprd);
677+
if (neldof < static_cast<int>(meen.size())) meen.resize(neldof);
705678
#else
706-
meen.reserve(nedof);
679+
meen.reserve(nedof > 0 ? nedof : neldof);
707680
for (int i = 0; i < nenod; i++, ip++)
708681
{
709-
int node = mmnpc[ip-1];
682+
int node = mmnpc[ip];
710683
if (node > 0)
711684
meen.insert(meen.end(),meqn+madof[node-1]-1,meqn+madof[node]-1);
712685
else if (node < 0)
713686
meen.insert(meen.end(),madof[-node]-madof[-node-1],0);
714687
}
715-
int neldof = meen.size();
688+
neldof = meen.size();
716689
#endif
717-
if (neldof == static_cast<int>(nedof)) return true;
690+
if (nedof == 0 || neldof == static_cast<int>(nedof)) return true;
718691

719692
std::cerr <<" *** SAM::getElmEqns: Invalid element matrix dimension "
720693
<< nedof <<" for element "<< iel
@@ -723,15 +696,15 @@ bool SAM::getElmEqns (IntVec& meen, int iel, size_t nedof) const
723696
}
724697

725698

726-
bool SAM::getUniqueEqns (IntSet& meen, int iel) const
699+
void SAM::getUniqueEqns (IntSet& meen, int iel) const
727700
{
728701
meen.clear();
729702

730-
IntVec meenTmp;
731-
if (!this->getElmEqns(meenTmp, iel))
732-
return false;
703+
IntVec tmp;
704+
if (!this->getElmEqns(tmp,iel))
705+
return; // only if element index is out of range
733706

734-
for (int jeq : meenTmp)
707+
for (int jeq : tmp)
735708
if (jeq < 0)
736709
{
737710
int jpmceq1 = mpmceq[-jeq-1];
@@ -742,26 +715,6 @@ bool SAM::getUniqueEqns (IntSet& meen, int iel) const
742715
}
743716
else if (jeq > 0)
744717
meen.insert(jeq);
745-
746-
return true;
747-
}
748-
749-
750-
size_t SAM::getNoElmEqns (int iel) const
751-
{
752-
size_t result = 0;
753-
if (iel < 1 || iel > nel)
754-
std::cerr <<" *** SAM::getNoElmEqns: Element "<< iel
755-
<<" is out of range [1,"<< nel <<"]."<< std::endl;
756-
757-
else for (int ip = mpmnpc[iel-1]; ip < mpmnpc[iel]; ip++)
758-
{
759-
int node = abs(mmnpc[ip-1]);
760-
if (node > 0)
761-
result += madof[node] - madof[node-1];
762-
}
763-
764-
return result;
765718
}
766719

767720

@@ -784,9 +737,9 @@ bool SAM::getNodeEqns (IntVec& mnen, int inod) const
784737

785738
std::pair<int,int> SAM::getNodeDOFs (int inod) const
786739
{
787-
if (inod < 1 || inod > nnod) return std::make_pair(0,0);
740+
if (inod < 1 || inod > nnod) return { 0, 0 };
788741

789-
return std::make_pair(madof[inod-1],madof[inod]-1);
742+
return { madof[inod-1], madof[inod]-1 };
790743
}
791744

792745

@@ -805,15 +758,15 @@ int SAM::getEquation (int inod, int ldof) const
805758
bool SAM::expandSolution (const SystemVector& solVec, Vector& dofVec,
806759
Real scaleSD) const
807760
{
808-
if (solVec.dim() < (size_t)neq) return false;
761+
if (static_cast<int>(solVec.dim()) < neq) return false;
809762

810763
return this->expandVector(solVec.getRef(),dofVec,scaleSD);
811764
}
812765

813766

814767
bool SAM::expandVector (const Vector& solVec, Vector& dofVec) const
815768
{
816-
if (solVec.size() < (size_t)neq) return false;
769+
if (static_cast<int>(solVec.size()) < neq) return false;
817770

818771
return this->expandVector(solVec.ptr(),dofVec,Real(0));
819772
}
@@ -889,7 +842,6 @@ bool SAM::applyDirichlet (Vector& dofVec) const
889842
}
890843

891844

892-
893845
Real SAM::dot (const Vector& x, const Vector& y, char dofType) const
894846
{
895847
if ((nodeType.empty() && dof_type.empty()) || dofType == 'A')
@@ -939,7 +891,7 @@ Real SAM::normInf (const Vector& x, size_t& comp, char dofType) const
939891
{
940892
// All DOFs are of the same type and the number of nodal DOFs is constant
941893
int nndof = madof[1] - madof[0];
942-
if ((int)comp <= nndof)
894+
if (static_cast<int>(comp) <= nndof)
943895
return x.normInf(--comp,nndof);
944896
else
945897
return Real(0);
@@ -980,7 +932,7 @@ Real SAM::normReact (const RealArray& u, const RealArray& rf) const
980932
Real retVal = Real(0);
981933

982934
for (int i = 0; i < ndof; i++)
983-
if (meqn[i] < 0 && msc[i] < 0 && -msc[i] <= (int)rf.size())
935+
if (meqn[i] < 0 && msc[i] < 0 && -msc[i] <= static_cast<int>(rf.size()))
984936
if (mpmceq[-meqn[i]] - mpmceq[-meqn[i]-1] == 1) // Only prescribed DOFs
985937
{
986938
Real RF = rf[-msc[i]-1];
@@ -1020,7 +972,7 @@ Real SAM::getReaction (int dir, const RealArray& rf, const IntVec* nodes) const
1020972
{
1021973
int idof = madof[i]+dir-2;
1022974
int ipr = idof < madof[i+1]-1 ? -msc[idof]-1 : -1;
1023-
if (ipr >= 0 && ipr < (int)rf.size())
975+
if (ipr >= 0 && ipr < static_cast<int>(rf.size()))
1024976
{
1025977
retVal += rf[ipr];
1026978
if (nodes) // clear this force component to avoid it being added twice
@@ -1046,7 +998,7 @@ bool SAM::getNodalReactions (int inod, const RealArray& rf,
1046998
int ip = madof[inod-1]-1;
1047999
nrf.resize(madof[inod]-1-ip);
10481000
for (size_t i = 0; i < nrf.size(); i++, ip++)
1049-
if (msc[ip] < 0 && -msc[ip] <= (int)rf.size())
1001+
if (msc[ip] < 0 && -msc[ip] <= static_cast<int>(rf.size()))
10501002
{
10511003
haveRF = true;
10521004
nrf[i] = rf[-msc[ip]-1];

0 commit comments

Comments
 (0)