Skip to content

Commit

Permalink
Merge pull request #196 from labmec/cylmap
Browse files Browse the repository at this point in the history
Cylmap
  • Loading branch information
orlandini authored Sep 13, 2023
2 parents 442cc69 + 6f57587 commit dd8911b
Show file tree
Hide file tree
Showing 35 changed files with 437 additions and 248 deletions.
3 changes: 2 additions & 1 deletion Material/Elasticity/TPZElasticity3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ void TPZElasticity3D::Solution(const TPZMaterialDataT<STATE> &data,
Solout[0] = ( PrincipalStress[0] - PrincipalStress[1] ) * ( PrincipalStress[0] - PrincipalStress[1] )
+ ( PrincipalStress[1] - PrincipalStress[2] ) * ( PrincipalStress[1] - PrincipalStress[2] )
+ ( PrincipalStress[2] - PrincipalStress[0] ) * ( PrincipalStress[2] - PrincipalStress[0] );
Solout[0] = Solout[0] / (2. * this->fFy * this->fFy);
// Solout[0] = Solout[0] / (2. * this->fFy * this->fFy);
return;
}//TPZElasticity3D::EVonMisesStress

if(var == TPZElasticity3D::EStress){
Expand Down
23 changes: 21 additions & 2 deletions Matrix/pzfmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,27 @@ void TPZFMatrix<TVar>::DeterminantInverse(TVar &determinant, TPZFMatrix<TVar> &i
int64_t r;
for(r=0; r<this->Rows(); r++) inverse(r,r) = 1.;
copy.Solve_LU(&inverse);
determinant = 1.;
for(r=0; r<this->Rows(); r++) determinant *= copy(r,r);
if(this->Rows() == 1) {
determinant = GetVal(0, 0);
} else if(this->Rows() == 2) {
determinant = g(0,0)*g(1,1)-g(0,1)*g(1,0);
} else if(this->Rows() == 3) {
determinant = 0.;
for(int i=0; i<3; i++) {
int j = (i+1)%3;
int k = (i+2)%3;
determinant += g(0,i)*g(1,j)*g(2,k);
determinant -= g(2,i)*g(1,j)*g(0,k);
}
} else {
// not sure if this is correct
determinant = 1.;
for(int64_t i=0; i<this->Rows(); i++) determinant *= copy.g(i,i);
if(copy.fPivot.size()) {
for(int64_t i=0; i<this->Rows(); i++) if(copy.fPivot[i] != i+1) determinant *= -1.;
}

}
}


Expand Down
11 changes: 9 additions & 2 deletions Mesh/pzcmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,8 +1594,15 @@ void TPZCompMesh::EvaluateError(bool store_error, TPZVec<REAL> &errorSum, std::s
AccountForElementError(celgr,store_error,true_error,errorSum,matset);
}
}
else{
AccountForElementError(cel,store_error,true_error,errorSum,matset);
else {
TPZSubCompMesh *subcmesh = dynamic_cast<TPZSubCompMesh *>(cel);
if(subcmesh) {
TPZCompMesh *cmesh = subcmesh;
cmesh->EvaluateError(store_error, errorSum, matset);
}
else{
AccountForElementError(cel,store_error,true_error,errorSum,matset);
}
}
}
}
Expand Down
94 changes: 59 additions & 35 deletions Mesh/pzelchdiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,9 @@ void TPZCompElHDiv<TSHAPE>::Read(TPZStream &buf, void *context)
}
}
//refinamento
template<class TSHAPE>
void TPZCompElHDiv<TSHAPE>::PRefine(int order)
{
//template<class TSHAPE>
//void TPZCompElHDiv<TSHAPE>::PRefine(int order)
//{
// This function has been deprecated since TPZCompElHDivPressure has been deprecated
// TODO: Delete or update?
/*
Expand Down Expand Up @@ -1141,7 +1141,7 @@ void TPZCompElHDiv<TSHAPE>::PRefine(int order)
}
*/
}
//}

/** @brief Prints the relevant data of the element to the output stream */
template<class TSHAPE>
Expand Down Expand Up @@ -1189,43 +1189,32 @@ void TPZCompElHDiv<TSHAPE>::RestrainSide(int side, TPZInterpolatedElement *large
TPZCompElSide largecompside(large, neighbourside);
TPZGeoElSide largegeoside = largecompside.Reference();

bool orient = CheckRestrainedSideOrientation(thisgeoside,largegeoside);
int det_orient = CheckRestrainedSideOrientation(thisgeoside,largegeoside);

//Checks sideOrient
int cindex = SideConnectLocId(0, thisside.Side());
int sOrientThis = fSideOrient[cindex];
int sOrientLarge = large->GetSideOrient(neighbourside);

bool orient2 = false;


if (TSHAPE::Dimension == 3){
orient = false;
int nedgesThis = thisgeoside.Element()->FirstSide(2);
int nedgesLarge = largegeoside.Element()->FirstSide(2);

//Properly orients the elements with side orientation counter clock-wise
if (thisgeoside.Element()->GetSideOrientation(side-nedgesThis) == -1 || largegeoside.Element()->GetSideOrientation(neighbourside-nedgesLarge) == -1) {
orient = true;
}
}

int equal_orient = sOrientThis * sOrientLarge;
if(det_orient == -1) {
// std::cout << "incompatible side orientations " << " small index " << this->Index() << " large index " << large->Index() << std::endl;
// std::cout << "det_orient " << det_orient << " this orient " << sOrientThis << " large orient " << sOrientLarge << std::endl;

// Checking the normal orientation based on the transformation determinant:
// If negative, the element sides have opposite orientations and vice-versa.
if (orient && (sOrientThis != sOrientLarge)) {

auto depend = myconnect.FirstDepend();
while(depend){
depend->fDepMatrix.MultiplyByScalar(-1.,depend->fDepMatrix);
depend = depend->fNext;
}
}
}

}
}

template<class TSHAPE>
bool TPZCompElHDiv<TSHAPE>::CheckRestrainedSideOrientation(TPZGeoElSide &thisgeoside, TPZGeoElSide &largegeoside){
int TPZCompElHDiv<TSHAPE>::CheckRestrainedSideOrientation(TPZGeoElSide &thisgeoside, TPZGeoElSide &largegeoside){

TPZTransform<> t(thisgeoside.Dimension());
thisgeoside.SideTransform3(largegeoside, t);
Expand All @@ -1236,21 +1225,56 @@ bool TPZCompElHDiv<TSHAPE>::CheckRestrainedSideOrientation(TPZGeoElSide &thisgeo
TPZFMatrix<REAL> inv;
t.Mult().DeterminantInverse(det,inv);

bool orient = det > 0 ? false : true;
int orient = det > 0 ? 1 : -1;
int thissideorient = 1;
int largesideorient = 1;
if(TSHAPE::Dimension == 3) {
int nedgesThis = thisgeoside.Element()->FirstSide(2);
int side = thisgeoside.Side();
//Properly orients the elements with side orientation counter clock-wise
thissideorient = thisgeoside.Element()->GetFaceOrientation(side-nedgesThis);
}
if(largegeoside.Element()->Dimension() == 3) {
int neighbourside = largegeoside.Side();
int nedgesLarge = largegeoside.Element()->FirstSide(2);
largesideorient = largegeoside.Element()->GetFaceOrientation(neighbourside-nedgesLarge);
}
orient = orient*thissideorient*largesideorient;

#ifdef PZDEBUG

// TPZVec<REAL> normalLarge,normalThis;
// TPZManVector<REAL, 3> neighXi(largegeoside.Dimension(), 0);
// TPZManVector<REAL,3> xiSide(thisgeoside.Dimension(),0);
// t.Apply(xiSide, neighXi);
// largegeoside.Normal(neighXi,normalLarge);
// thisgeoside.Normal(xiSide,normalThis);

// std::cout << "Normal Large = " << normalLarge << std::endl;
// std::cout << "Normal This = " << normalThis << std::endl;
// // std::cout << "Transformation matrix = " << t.Mult() << std::endl;
// std::cout << "Transformation determinant = " << det << std::endl;
TPZManVector<REAL,3> normalLarge(3),normalThis(3);
TPZManVector<REAL, 3> neighXi(largegeoside.Dimension(), 0);
TPZManVector<REAL,3> xiSide(thisgeoside.Dimension(),0);
t.Apply(xiSide, neighXi);
largegeoside.Normal(neighXi,normalLarge);
thisgeoside.Normal(xiSide,normalThis);
REAL normalprod = 0.;
for(int i=0; i<3; i++) normalprod += normalLarge[i]*normalThis[i];
if(fabs(fabs(normalprod)-1.) >= 1.e-7) DebugStop();
if(normalprod*orient < 0.) {
this->Reference()->Print();
std::cout << "Side node indexes of this geoside ";
TPZGeoEl *geo = thisgeoside.Element();
int nsidenodes = geo->NSideNodes(thisgeoside.Side());
for(int in = 0; in<nsidenodes; in++) std::cout << geo->SideNodeIndex(thisgeoside.Side(), in) << " ";
std::cout << "Large element\n";
largegeoside.Element()->Print();
TPZFNMatrix<9> gradx(3,3),jac(3,3),jacinv(3,3),axes(3,3);
TPZManVector<REAL,3> xi(3);
geo->CenterPoint(geo->NSides()-1, xi);
geo->GradX(xi, gradx);
REAL detjac;
geo->Jacobian(gradx, jac, axes, detjac, jacinv);
std::cout << "detjac of small element " << detjac << std::endl;

DebugStop();
}

// std::cout << "Normal Large = " << normalLarge << std::endl;
// std::cout << "Normal This = " << normalThis << std::endl;
// std::cout << "Transformation matrix = " << t.Mult() << std::endl;
// std::cout << "Transformation determinant = " << det << std::endl;

#endif

Expand Down
6 changes: 3 additions & 3 deletions Mesh/pzelchdiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ class TPZCompElHDiv : public TPZIntelGen<TSHAPE> {
/** @brief Read the element data from a stream */
void Read(TPZStream &buf, void *context) override;
/** @brief Refinement along the element */
virtual void PRefine(int order) override;
// virtual void PRefine(int order) override;

//Checks the normal orientation of two neighbour GeoElSides;
//Returns true if the sides have opposite normal vectors and false if they are equal.
bool CheckRestrainedSideOrientation(TPZGeoElSide &thisGeoSide, TPZGeoElSide &largeGeoSide);
//Returns -1 if the sides have opposite normal vectors and 1 if they are equal.
int CheckRestrainedSideOrientation(TPZGeoElSide &thisGeoSide, TPZGeoElSide &largeGeoSide);


protected:
Expand Down
50 changes: 49 additions & 1 deletion Mesh/pzelchdivbound2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ TPZIntelGen<TSHAPE>(mesh,gel,1), fSideOrient(1), fhdivfam(hdivfam){
}
}

// DetermineSideOrient();
#ifdef PZ_LOG
if (logger.isDebugEnabled())
{
Expand Down Expand Up @@ -211,7 +212,7 @@ MElementType TPZCompElHDivBound2<TSHAPE>::Type() {
template<class TSHAPE>
void TPZCompElHDivBound2<TSHAPE>::SetSideOrient(int side, int sideorient)
{
if (side != TSHAPE::NSides - 1) {
if (side != TSHAPE::NSides - 1 || std::abs(sideorient) != 1) {
DebugStop();
}
fSideOrient = sideorient;
Expand Down Expand Up @@ -709,6 +710,53 @@ int TPZCompElHDivBound2<TSHAPE>::MaxOrder(){
return maxorder + 1;
}

/// Set the sideorient value in accordance to the sideorient of the neighbouring element
template<class TSHAPE>
void TPZCompElHDivBound2<TSHAPE>::DetermineSideOrient() {
// find a neighbour as a computational element

TPZGeoElSide gelside(this->Reference());
int dim = gelside.Dimension();
TPZStack<TPZCompElSide> neigh;
gelside.EqualLevelCompElementList(neigh, 1, 1);
if(neigh.size() == 0) return;
TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(neigh[0].Element());
if(!intel) DebugStop();
int neighsideorient = intel->GetSideOrient(neigh[0].Side());
TPZGeoElSide neighside = neigh[0].Reference();
int64_t neighcon = intel->SideConnectIndex(0, neigh[0].Side());
if(neighcon == fConnectIndexes[0]) {
if(dim == 2) {
TPZManVector<REAL,3> neighcenter(neighside.Dimension()), neighnormal(3);
neighside.CenterPoint(neighcenter);
neighside.Normal(neighcenter, neighnormal);
TPZFNMatrix<9,REAL> gradx(3,2),jac(2,2),jacinv(2,2),axes(2,3);
REAL detjac;
TPZManVector<REAL,2> ksi(2);
TPZGeoEl *gelskel = gelside.Element();
gelskel->CenterPoint(gelskel->NSides()-1, ksi);
gelskel->GradX(ksi, gradx);
gelskel->Jacobian(gradx, jac, axes, detjac, jacinv);
TPZManVector<REAL,3> skelnormal(3);
for (int i = 0; i<3; i++) {
int j = (i+1)%3;
int k = (i+2)%3;
skelnormal[i] = axes(0,j)*axes(1,k)-axes(0,k)*axes(1,j);
}
REAL inner = 0.;
for(int i=0; i<3; i++) inner += skelnormal[i]*neighnormal[i];
if(fabs(fabs(inner)-1.) > 1.e-6) DebugStop();
if(inner > 0.) SetSideOrient(gelside.Side(), neighsideorient);
else SetSideOrient(gelside.Side(), -neighsideorient);
} else if (dim == 1) {
auto tr = gelside.NeighbourSideTransform(neighside);
if(tr.Mult()(0,0) > 0.) SetSideOrient(gelside.Side(), neighsideorient);
else SetSideOrient(gelside.Side(), -neighsideorient);
}
}
}



#include "pzshapetriang.h"

Expand Down
5 changes: 4 additions & 1 deletion Mesh/pzelchdivbound2.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ class TPZCompElHDivBound2 : public TPZIntelGen<TSHAPE> {

virtual int SideConnectLocId(int node, int side) const override;


/// Allow to influence the normal direction of this element (-1 or 1)
virtual void SetSideOrient(int side, int sideorient) override;

virtual int GetSideOrient(int side) override;

/// Set the sideorient value in accordance to the sideorient of the neighbouring element
void DetermineSideOrient();

/** @brief Identifies the interpolation order on the interior of the element*/
virtual void GetInterpolationOrder(TPZVec<int> &ord) override;
Expand Down
2 changes: 1 addition & 1 deletion Mesh/pzgeoel.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class TPZGeoEl : public virtual TPZSavable {
}

/// return the orientation of a face +1: counterclockwise -1:clockwise
virtual int GetSideOrientation(int face) const = 0;
virtual int GetFaceOrientation(int face) const = 0;

/** @brief Get the transform id the face to face*/
int GetTransformId2dQ(TPZVec<int64_t> &idfrom,TPZVec<int64_t> &idto);
Expand Down
2 changes: 1 addition & 1 deletion Mesh/pzgeoelrefless.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ virtual int ClassId() const override;
virtual int NSideSubElements(int side) const override;

/// return the orientation of a face +1: counterclockwise -1:clockwise
virtual int GetSideOrientation(int face) const override;
virtual int GetFaceOrientation(int face) const override;

/**
* @brief Method which creates a computational boundary condition element based
Expand Down
14 changes: 7 additions & 7 deletions Mesh/pzgeoelrefless.h.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ TPZGeoElRefLess<TGeo>::NSideSubElements(int side) const {
/// return the orientation of a face +1: counterclockwise -1:clockwise

template<class TGeo>
int TPZGeoElRefLess<TGeo>::GetSideOrientation(int face) const
int TPZGeoElRefLess<TGeo>::GetFaceOrientation(int face) const
{
return TGeo::GetSideOrient(face);
return TGeo::GetFaceOrient(face);
}

template<class TGeo>
Expand Down Expand Up @@ -258,19 +258,19 @@ TPZGeoElRefLess<TGeo>::CreateBCGeoEl(int side, int bc){
switch (TGeo::Type())
{
case ETriangle:
sideorient = pztopology::TPZTriangle::GetSideOrient(faceSide);
sideorient = pztopology::TPZTriangle::GetFaceOrient(faceSide);
break;
case EQuadrilateral:
sideorient = pztopology::TPZQuadrilateral::GetSideOrient(faceSide);
sideorient = pztopology::TPZQuadrilateral::GetFaceOrient(faceSide);
break;
case ETetraedro:
sideorient = pztopology::TPZTetrahedron::GetSideOrient(faceSide);
sideorient = pztopology::TPZTetrahedron::GetFaceOrient(faceSide);
break;
case ECube:
sideorient = pztopology::TPZCube::GetSideOrient(faceSide);
sideorient = pztopology::TPZCube::GetFaceOrient(faceSide);
break;
case EPrisma:
sideorient = pztopology::TPZPrism::GetSideOrient(faceSide);
sideorient = pztopology::TPZPrism::GetFaceOrient(faceSide);
break;

default:
Expand Down
11 changes: 10 additions & 1 deletion Mesh/pzgeoelside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,15 @@ void TPZGeoElSide::Normal(TPZVec<REAL> &point, TPZGeoEl *LeftEl, TPZGeoEl *Right
/** @brief compute the normal to the point */
void TPZGeoElSide::Normal(TPZVec<REAL> &qsi_side, TPZVec<REAL> &normal) const{

if(Dimension() == 2 && fGeoEl->Dimension() == 2) {
TPZFNMatrix<9,REAL> gradx(3,2);
fGeoEl->GradX(qsi_side, gradx);
TPZFNMatrix<6,REAL> jac(2,2),jacinv(2,2),axes(2,3);
REAL detjac;
fGeoEl->Jacobian(gradx, jac, axes, detjac, jacinv);
for(int i=0; i<3; i++) normal[i] = axes(0,(i+1)%3)*axes(1,(i+2)%3)-axes(0,(i+2)%3)*axes(1,(i+1)%3);
return;
}
if (Dimension() != fGeoEl->Dimension()-1) {
DebugStop();
}
Expand Down Expand Up @@ -1509,7 +1518,7 @@ bool TPZGeoElSide::IsNeighbourCounterClockWise(TPZGeoElSide &neighbour)
DebugStop();
}
int face = fSide-fGeoEl->FirstSide(2);
int faceorient = fGeoEl->GetSideOrientation(face);
int faceorient = fGeoEl->GetFaceOrientation(face);
if(faceorient == -1) trid = (trid+1)%2;
return trid == 0;
}
1 change: 1 addition & 0 deletions Mesh/pzinterpolationspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ int TPZInterpolationSpace::GetSideOrient(int side){
int nnos = gel->NCornerNodes();
// para elemento quadratico, ie, quadrilatero de 8 nos
if (gel->Type()==EQuadrilateral && nnos>side) {
DebugStop();
int sideorient = gel->NormalOrientation(side);
return sideorient;
}
Expand Down
Loading

0 comments on commit dd8911b

Please sign in to comment.