Skip to content

Commit 2e81b08

Browse files
committed
Changed: Explicit nodal constraints and whole patch constraints
are now handled by SIMbase::addConstraint() which then is used in the SIM[123]D methods removing the code duplications there. SIMsupel then no longer needs to override this method to work.
1 parent 551de78 commit 2e81b08

File tree

6 files changed

+66
-83
lines changed

6 files changed

+66
-83
lines changed

src/SIM/SIM1D.C

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -489,49 +489,30 @@ bool SIM1D::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
489489

490490
if (lndx < -10) lndx += 10; // no projection in 1D
491491

492-
IFEM::cout <<"\tConstraining P"<< patch;
493-
if (ldim == 0)
494-
IFEM::cout << " V"<< abs(lndx);
495-
IFEM::cout <<" in direction(s) "<< dirs;
496-
if (code != 0) IFEM::cout <<" code = "<< code;
497-
#if SP_DEBUG > 1
498-
std::cout << std::endl;
499-
#endif
492+
if (this->SIMbase::addConstraint(patch,lndx,ldim,dirs,code,ngnod,1,ovrD))
493+
return true;
500494

501495
// Must dynamic cast here, since ASM1D is not derived from ASMbase
502496
ASM1D* pch = dynamic_cast<ASM1D*>(myModel[patch-1]);
503497
if (!pch) return error("1D patch",patch);
504498

505-
switch (ldim)
506-
{
507-
case 0: // Vertex constraints
508-
switch (lndx)
509-
{
510-
case 1: pch->constrainNode(0.0,dirs,code); break;
511-
case 2: pch->constrainNode(1.0,dirs,code); break;
512-
case -1:
513-
ngnod += pch->constrainEndLocal(0,dirs,code);
514-
break;
515-
case -2:
516-
ngnod += pch->constrainEndLocal(1,dirs,code);
517-
break;
518-
default:
519-
return error("vertex index",lndx,true);
520-
}
521-
break;
522-
523-
case 1: // Curve constraint
524-
myModel[patch-1]->constrainPatch(dirs,code);
525-
break;
526-
527-
case 4: // Explicit nodal constraints
528-
myModel[patch-1]->constrainNodes(myModel[patch-1]->getNodeSet(lndx),
529-
dirs,code,ovrD);
530-
break;
499+
if (ldim == 0) // Vertex constraints
500+
switch (lndx)
501+
{
502+
case 1: pch->constrainNode(0.0,dirs,code); break;
503+
case 2: pch->constrainNode(1.0,dirs,code); break;
504+
case -1:
505+
ngnod += pch->constrainEndLocal(0,dirs,code);
506+
break;
507+
case -2:
508+
ngnod += pch->constrainEndLocal(1,dirs,code);
509+
break;
510+
default:
511+
return error("vertex index",lndx,true);
512+
}
531513

532-
default:
533-
return error("local dimension switch",ldim,true);
534-
}
514+
else
515+
return error("local dimension switch",ldim,true);
535516

536517
return true;
537518
}

src/SIM/SIM2D.C

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -704,21 +704,14 @@ bool SIM2D::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
704704
if (patch < 1 || patch > (int)myModel.size())
705705
return error("patch index",patch);
706706

707+
if (this->SIMbase::addConstraint(patch,lndx,abs(ldim),dirs,code,
708+
ngnod,basis,ovrD))
709+
return true;
710+
707711
bool open = ldim < 0; // open means without its end points
708712
bool project = lndx < -10;
709713
if (project) lndx += 10;
710714

711-
IFEM::cout <<"\tConstraining P"<< patch;
712-
if (abs(ldim) < 2)
713-
IFEM::cout << (ldim == 0 ? " V" : " E") << abs(lndx);
714-
IFEM::cout <<" in direction(s) "<< dirs;
715-
if (lndx < 0) IFEM::cout << (project ? " (local projected)" : " (local)");
716-
if (code != 0) IFEM::cout <<" code = "<< abs(code);
717-
if (basis > 1) IFEM::cout <<" basis = "<< (int)basis;
718-
#if SP_DEBUG > 1
719-
std::cout << std::endl;
720-
#endif
721-
722715
// Must dynamic cast here, since ASM2D is not derived from ASMbase
723716
ASM2D* pch = dynamic_cast<ASM2D*>(myModel[patch-1]);
724717
if (!pch) return error("2D patch",patch);
@@ -760,15 +753,6 @@ bool SIM2D::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
760753
}
761754
break;
762755

763-
case 2: // Face constraints
764-
myModel[patch-1]->constrainPatch(dirs,code);
765-
break;
766-
767-
case 4: // Explicit nodal constraints
768-
myModel[patch-1]->constrainNodes(myModel[patch-1]->getNodeSet(lndx),
769-
dirs,code,ovrD);
770-
break;
771-
772756
default:
773757
return error("local dimension switch",ldim,true);
774758
}

src/SIM/SIM3D.C

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,14 @@ bool SIM3D::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
580580
return error("patch index",patch);
581581

582582
int aldim = abs(ldim);
583+
if (this->SIMbase::addConstraint(patch,lndx,aldim,dirs,code,ngnod,basis,ovrD))
584+
return true;
585+
583586
bool open = ldim < 0; // open means without face edges or edge ends
584587
bool project = lndx < -10;
585588
if (project) lndx += 10;
586589
if (lndx < 0 && aldim > 3) aldim = 2; // local tangent direction is indicated
587590

588-
IFEM::cout <<"\tConstraining P"<< patch;
589-
if (aldim < 3)
590-
IFEM::cout << (ldim == 0 ? " V" : (aldim == 1 ? " E" : " F")) << lndx;
591-
IFEM::cout <<" in direction(s) "<< dirs;
592-
if (lndx < 0) IFEM::cout << (project ? " (local projected)" : " (local)");
593-
if (code != 0) IFEM::cout <<" code = "<< abs(code);
594-
if (basis > 1) IFEM::cout <<" basis = "<< (int)basis;
595-
#if SP_DEBUG > 1
596-
std::cout << std::endl;
597-
#endif
598-
599591
// Must dynamic cast here, since ASM3D is not derived from ASMbase
600592
ASM3D* pch = dynamic_cast<ASM3D*>(myModel[patch-1]);
601593
if (!pch) return error("3D patch",patch);
@@ -656,15 +648,6 @@ bool SIM3D::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
656648
}
657649
break;
658650

659-
case 3: // Volume constraints
660-
myModel[patch-1]->constrainPatch(dirs,code);
661-
break;
662-
663-
case 4: // Explicit nodal constraints
664-
myModel[patch-1]->constrainNodes(myModel[patch-1]->getNodeSet(lndx),
665-
dirs,code,ovrD);
666-
break;
667-
668651
default:
669652
return error("local dimension switch",ldim,true);
670653
}

src/SIM/SIMbase.C

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,45 @@ bool SIMbase::preprocess (const IntVec& ignored, bool fixDup)
414414
}
415415

416416

417+
bool SIMbase::addConstraint (int patch, int lndx, int ldim, int dirs, int code,
418+
int& ngnod, char basis, bool ovrD)
419+
{
420+
if (patch < 1 || patch > static_cast<int>(myModel.size()))
421+
{
422+
std::cerr <<" *** SIMbase::addConstraint: Invalid patch index ("<< patch
423+
<<")."<< std::endl;
424+
return false;
425+
}
426+
427+
const int numdim = this->getNoParamDim();
428+
const bool doProject = lndx < -10;
429+
if (doProject) lndx += 10;
430+
if (lndx < 0 && numdim == 3 && ldim > 3)
431+
ldim = 2; // local tangent direction is indicated
432+
433+
IFEM::cout <<"\tConstraining P"<< patch;
434+
if (ldim >= 0 && ldim < numdim)
435+
IFEM::cout << (ldim == 0 ? " V" : (ldim == 1 ? " E" : " F")) << abs(lndx);
436+
IFEM::cout <<" in direction(s) "<< dirs;
437+
if (lndx < 0) IFEM::cout << (doProject ? " (local projected)" : " (local)");
438+
if (code != 0) IFEM::cout <<" code = "<< abs(code);
439+
if (basis > 1) IFEM::cout <<" basis = "<< static_cast<int>(basis);
440+
#if SP_DEBUG > 1
441+
std::cout << std::endl;
442+
#endif
443+
444+
if (ldim == numdim) // Constrain the whole patch (all control/nodal points)
445+
myModel[patch-1]->constrainPatch(dirs,code);
446+
else if (ldim == 4) // Explicit nodal constraints
447+
myModel[patch-1]->constrainNodes(myModel[patch-1]->getNodeSet(lndx),
448+
dirs,code,ovrD);
449+
else
450+
return false;
451+
452+
return true;
453+
}
454+
455+
417456
bool SIMbase::merge (SIMbase* that, const std::map<int,int>* old2new, int poff)
418457
{
419458
if (this == that)

src/SIM/SIMbase.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ class SIMbase : public SIMadmin, public SIMdependency
8686
bool readModel(const char* fileName);
8787

8888
//! \brief Creates the computational FEM model from the spline patches.
89-
//! \param[in] resetNumb If \e 'y', start element and node numbers from zero
90-
virtual bool createFEMmodel(char resetNumb = 'y') = 0;
89+
virtual bool createFEMmodel(char resetNumb) = 0;
9190

9291
//! \brief Initializes the property containers of the model.
9392
//! \details Use this method to clear the model before re-reading
@@ -619,7 +618,7 @@ class SIMbase : public SIMadmin, public SIMdependency
619618
//! \param[in] basis Which basis to apply the constraint to (mixed methods)
620619
//! \param[in] ovrD If \e true, override conflicting Dirichlet conditions
621620
virtual bool addConstraint(int patch, int lndx, int ldim, int dirs, int code,
622-
int& ngnod, char basis = 1, bool ovrD = false) = 0;
621+
int& ngnod, char basis = 1, bool ovrD = false);
623622

624623
//! \brief Preprocessing performed before the FEM model generation.
625624
virtual void preprocessA() {}

src/SIM/SIMdummy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ template<class Base> class SIMdummy : public Base
5050
//! \brief Parses a dimension-specific subelement of the \a geometry XML-tag.
5151
virtual bool parseGeometryDimTag(const tinyxml2::XMLElement*)
5252
{ return false; }
53-
//! \brief Preprocesses a user-defined Dirichlet boundary property.
54-
virtual bool addConstraint(int,int,int,int,int,int&,char,bool)
55-
{ return false; }
5653
//! \brief Preprocesses the result sampling points.
5754
virtual void preprocessResultPoints() {}
5855
//! \brief Creates a model generator.

0 commit comments

Comments
 (0)