13
13
14
14
#include "SAM.h"
15
15
#include "SystemMatrix.h"
16
+ #include <numeric>
16
17
#include <iomanip>
17
18
18
19
#ifdef USE_F77SAM
@@ -182,7 +183,7 @@ void SAM::print (std::ostream& os) const
182
183
}
183
184
code [i ] = dofType [i ] = '\0' ;
184
185
os <<'\t' << code ;
185
- if (( size_t ) n < nodeType .size ())
186
+ if (n < static_cast < int > ( nodeType .size () ))
186
187
os <<'\t' << nodeType [n ];
187
188
if (strlen (dofType ) > 0 )
188
189
os <<'\t' << dofType ;
@@ -332,15 +333,14 @@ int SAM::getNoNodes (char dofType) const
332
333
}
333
334
334
335
335
- bool SAM ::getDofCouplings (IntVec & irow , IntVec & jcol ) const
336
+ void SAM ::getDofCouplings (IntVec & irow , IntVec & jcol ) const
336
337
{
337
338
irow .clear ();
338
339
jcol .clear ();
339
340
340
341
// Find the set of DOF couplings for each free DOF
341
342
std ::vector < IntSet > dofc ;
342
- if (!this -> getDofCouplings (dofc ))
343
- return false;
343
+ this -> getDofCouplings (dofc );
344
344
345
345
irow .resize (neq + 1 );
346
346
irow .front () = 0 ;
@@ -353,19 +353,16 @@ bool SAM::getDofCouplings (IntVec& irow, IntVec& jcol) const
353
353
jcol .reserve (irow .back ());
354
354
for (i = 0 ; i < neq ; i ++ )
355
355
jcol .insert (jcol .end (),dofc [i ].begin (),dofc [i ].end ());
356
-
357
- return true;
358
356
}
359
357
360
358
361
- bool SAM ::getDofCouplings (std ::vector < IntSet > & dofc ) const
359
+ void SAM ::getDofCouplings (std ::vector < IntSet > & dofc ) const
362
360
{
363
361
dofc .resize (neq );
364
362
for (int iel = 1 ; iel <= nel ; iel ++ )
365
363
{
366
364
IntVec meen ;
367
- if (!this -> getElmEqns (meen ,iel ))
368
- return false;
365
+ this -> getElmEqns (meen ,iel );
369
366
370
367
for (size_t j = 0 ; j < meen .size (); j ++ )
371
368
{
@@ -415,35 +412,6 @@ bool SAM::getDofCouplings (std::vector<IntSet>& dofc) const
415
412
}
416
413
}
417
414
}
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;
447
415
}
448
416
449
417
@@ -579,7 +547,7 @@ bool SAM::assembleSystem (SystemVector& sysRHS, const Real* nS, int inod,
579
547
for (int j = madof [inod - 1 ]; j < madof [inod ]; j ++ , k ++ )
580
548
{
581
549
int ipR = - msc [j - 1 ];
582
- if (ipR > 0 && ( size_t ) ipR <= reactionForces -> size ())
550
+ if (ipR > 0 && ipR <= static_cast < int > ( reactionForces -> size () ))
583
551
(* reactionForces )[ipR - 1 ] += nS [k ];
584
552
}
585
553
}
@@ -617,7 +585,10 @@ void SAM::addToRHS (SystemVector& sysRHS, const RealArray& S) const
617
585
{
618
586
if (ndof < 1 || S .empty ()) return ;
619
587
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 ++ )
621
592
this -> assembleRHS (sysRHS .getPtr (),S [i ],meqn [i ]);
622
593
}
623
594
@@ -651,7 +622,7 @@ void SAM::assembleReactions (RealArray& rf, const RealArray& eS, int iel) const
651
622
for (int j = madof [node - 1 ]; j < madof [node ] && k < eS .size (); j ++ , k ++ )
652
623
{
653
624
int ipR = - msc [j - 1 ];
654
- if (ipR > 0 && ( size_t ) ipR <= rf .size ())
625
+ if (ipR > 0 && ipR <= static_cast < int > ( rf .size () ))
655
626
rf [ipR - 1 ] += eS [k ];
656
627
}
657
628
}
@@ -689,32 +660,34 @@ bool SAM::getElmEqns (IntVec& meen, int iel, size_t nedof) const
689
660
}
690
661
691
662
int ip = mpmnpc [iel - 1 ];
692
- int nenod = mpmnpc [iel ] - ip ;
663
+ int nenod = mpmnpc [iel ] - ( ip -- ) ;
693
664
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
+
700
673
#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 );
705
678
#else
706
- meen .reserve (nedof );
679
+ meen .reserve (nedof > 0 ? nedof : neldof );
707
680
for (int i = 0 ; i < nenod ; i ++ , ip ++ )
708
681
{
709
- int node = mmnpc [ip - 1 ];
682
+ int node = mmnpc [ip ];
710
683
if (node > 0 )
711
684
meen .insert (meen .end (),meqn + madof [node - 1 ]- 1 ,meqn + madof [node ]- 1 );
712
685
else if (node < 0 )
713
686
meen .insert (meen .end (),madof [- node ]- madof [- node - 1 ],0 );
714
687
}
715
- int neldof = meen .size ();
688
+ neldof = meen .size ();
716
689
#endif
717
- if (neldof == static_cast < int > (nedof )) return true;
690
+ if (nedof == 0 || neldof == static_cast < int > (nedof )) return true;
718
691
719
692
std ::cerr <<" *** SAM::getElmEqns: Invalid element matrix dimension "
720
693
<< nedof <<" for element " << iel
@@ -723,15 +696,15 @@ bool SAM::getElmEqns (IntVec& meen, int iel, size_t nedof) const
723
696
}
724
697
725
698
726
- bool SAM ::getUniqueEqns (IntSet & meen , int iel ) const
699
+ void SAM ::getUniqueEqns (IntSet & meen , int iel ) const
727
700
{
728
701
meen .clear ();
729
702
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
733
706
734
- for (int jeq : meenTmp )
707
+ for (int jeq : tmp )
735
708
if (jeq < 0 )
736
709
{
737
710
int jpmceq1 = mpmceq [- jeq - 1 ];
@@ -742,26 +715,6 @@ bool SAM::getUniqueEqns (IntSet& meen, int iel) const
742
715
}
743
716
else if (jeq > 0 )
744
717
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 ;
765
718
}
766
719
767
720
@@ -784,9 +737,9 @@ bool SAM::getNodeEqns (IntVec& mnen, int inod) const
784
737
785
738
std ::pair < int ,int > SAM ::getNodeDOFs (int inod ) const
786
739
{
787
- if (inod < 1 || inod > nnod ) return std :: make_pair ( 0 , 0 ) ;
740
+ if (inod < 1 || inod > nnod ) return { 0 , 0 } ;
788
741
789
- return std :: make_pair ( madof [inod - 1 ],madof [inod ]- 1 ) ;
742
+ return { madof [inod - 1 ], madof [inod ]- 1 } ;
790
743
}
791
744
792
745
@@ -805,15 +758,15 @@ int SAM::getEquation (int inod, int ldof) const
805
758
bool SAM ::expandSolution (const SystemVector & solVec , Vector & dofVec ,
806
759
Real scaleSD ) const
807
760
{
808
- if (solVec .dim () < ( size_t ) neq ) return false;
761
+ if (static_cast < int > ( solVec .dim ()) < neq ) return false;
809
762
810
763
return this -> expandVector (solVec .getRef (),dofVec ,scaleSD );
811
764
}
812
765
813
766
814
767
bool SAM ::expandVector (const Vector & solVec , Vector & dofVec ) const
815
768
{
816
- if (solVec .size () < ( size_t ) neq ) return false;
769
+ if (static_cast < int > ( solVec .size ()) < neq ) return false;
817
770
818
771
return this -> expandVector (solVec .ptr (),dofVec ,Real (0 ));
819
772
}
@@ -889,7 +842,6 @@ bool SAM::applyDirichlet (Vector& dofVec) const
889
842
}
890
843
891
844
892
-
893
845
Real SAM ::dot (const Vector & x , const Vector & y , char dofType ) const
894
846
{
895
847
if ((nodeType .empty () && dof_type .empty ()) || dofType == 'A' )
@@ -939,7 +891,7 @@ Real SAM::normInf (const Vector& x, size_t& comp, char dofType) const
939
891
{
940
892
// All DOFs are of the same type and the number of nodal DOFs is constant
941
893
int nndof = madof [1 ] - madof [0 ];
942
- if (( int ) comp <= nndof )
894
+ if (static_cast < int > ( comp ) <= nndof )
943
895
return x .normInf (-- comp ,nndof );
944
896
else
945
897
return Real (0 );
@@ -980,7 +932,7 @@ Real SAM::normReact (const RealArray& u, const RealArray& rf) const
980
932
Real retVal = Real (0 );
981
933
982
934
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 () ))
984
936
if (mpmceq [- meqn [i ]] - mpmceq [- meqn [i ]- 1 ] == 1 ) // Only prescribed DOFs
985
937
{
986
938
Real RF = rf [- msc [i ]- 1 ];
@@ -1020,7 +972,7 @@ Real SAM::getReaction (int dir, const RealArray& rf, const IntVec* nodes) const
1020
972
{
1021
973
int idof = madof [i ]+ dir - 2 ;
1022
974
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 () ))
1024
976
{
1025
977
retVal += rf [ipr ];
1026
978
if (nodes ) // clear this force component to avoid it being added twice
@@ -1046,7 +998,7 @@ bool SAM::getNodalReactions (int inod, const RealArray& rf,
1046
998
int ip = madof [inod - 1 ]- 1 ;
1047
999
nrf .resize (madof [inod ]- 1 - ip );
1048
1000
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 () ))
1050
1002
{
1051
1003
haveRF = true;
1052
1004
nrf [i ] = rf [- msc [ip ]- 1 ];
0 commit comments