Skip to content

Commit

Permalink
Merge pull request #208 from labmec/small-fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
orlandini authored Sep 16, 2024
2 parents c663528 + 2a2aeb1 commit 12d4434
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 58 deletions.
24 changes: 20 additions & 4 deletions Mesh/TPZCompElHCurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ void TPZCompElHCurl<TSHAPE>::CreateHCurlConnects(TPZCompMesh &mesh){
}

template<class TSHAPE>
void TPZCompElHCurl<TSHAPE>::RestrainSide(int side, TPZInterpolatedElement *large, int neighbourside) {
template<class TVar>
void TPZCompElHCurl<TSHAPE>::RestrainSideT(int side, TPZInterpolatedElement *large, int neighbourside) {
const TPZCompElSide thisCompSide(this, side);
const TPZCompElSide largeCompSide(large, neighbourside);
TPZGeoElSide thisGeoSide(this->Reference(), side);
Expand Down Expand Up @@ -727,6 +728,7 @@ void TPZCompElHCurl<TSHAPE>::RestrainSide(int side, TPZInterpolatedElement *larg

MSolve.Solve(MSL, MSL);


const auto thisNumSideNodes = NSideConnects(side);
const auto largeNumSideNodes = large->NSideConnects(neighbourside);
TPZBlock MBlocksmall(0, thisNumSideNodes), MBlocklarge(0, largeNumSideNodes);
Expand Down Expand Up @@ -782,13 +784,27 @@ void TPZCompElHCurl<TSHAPE>::RestrainSide(int side, TPZInterpolatedElement *larg
DebugStop();
}
#endif
TPZFNMatrix<1000, TVar> MSLdep;
if constexpr (std::is_same_v<TVar,REAL>){
MSLdep = MSL;
}else{
const int nr = MSL.Rows();
const int nc = MSL.Cols();
MSLdep.Resize(nr,nc);
auto *my_ptr = MSLdep.Elem();
auto *their_ptr = MSL.Elem();
for(int i = 0; i < nr*nc;i++){
*my_ptr++ = *their_ptr++;
}
}

for (auto jn = 0; jn < largeNumSideNodes; jn++) {
if (MBlocksmall.Size(in) == 0 || MBlocklarge.Size(jn) == 0) {
continue;
}
int64_t jnodindex = large->SideConnectIndex(jn, neighbourside);
TPZConnect::TPZDepend<STATE> *depend =
inod.AddDependency(inodindex, jnodindex, MSL,
TPZConnect::TPZDepend<TVar> *depend =
inod.AddDependency(inodindex, jnodindex, MSLdep,
MBlocksmall.Position(in), MBlocklarge.Position(jn),
MBlocksmall.Size(in), MBlocklarge.Size(jn));
if (blocknorm(in, jn) < 1.e-8) {
Expand All @@ -801,7 +817,7 @@ void TPZCompElHCurl<TSHAPE>::RestrainSide(int side, TPZInterpolatedElement *larg
for (auto jn = 0; jn < largeNumSideNodes; jn++) {
int64_t jnodindex = large->SideConnectIndex(jn, neighbourside);
if (MBlocklarge.Size(jn)) {
inod.AddDependency(inodindex, jnodindex, MSL, MBlocksmall.Position(in), MBlocklarge.Position(jn),
inod.AddDependency(inodindex, jnodindex, MSLdep, MBlocksmall.Position(in), MBlocklarge.Position(jn),
MBlocksmall.Size(in), MBlocklarge.Size(jn));
}
ndepend++;
Expand Down
11 changes: 10 additions & 1 deletion Mesh/TPZCompElHCurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ class TPZCompElHCurl : public TPZIntelGen<TSHAPE> {
/** @brief Sets the interpolation order of side to order*/
void SetSideOrder(int side, int order) override;

void RestrainSide(int side, TPZInterpolatedElement *large, int neighbourside) override;
void RestrainSide(int side, TPZInterpolatedElement *large, int neighbourside) override
{
if(this->Mesh()->GetSolType() == EReal){
RestrainSideT<STATE>(side,large,neighbourside);
}else{
RestrainSideT<CSTATE>(side,large,neighbourside);
}
}
/** @brief Initialize a material data and its attributes based on element dimension, number
* of state variables and material definitions */
void InitMaterialData(TPZMaterialData &data) override;
Expand Down Expand Up @@ -190,6 +197,8 @@ class TPZCompElHCurl : public TPZIntelGen<TSHAPE> {
TPZSolVec<TVar> &sol,
TPZSolVec<TVar> &curlsol);

template<class TVar>
void RestrainSideT(int side, TPZInterpolatedElement *large, int neighbourside);
int MaxOrder() override;
};

Expand Down
15 changes: 13 additions & 2 deletions Mesh/pzconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,19 @@ template<class TVar>
TPZConnect::TPZDepend<TVar>::TPZDepend(int64_t dependindex,TPZFMatrix<TVar> &depmat,int64_t ipos,int64_t jpos, int isize, int jsize) :
fDepMatrix(isize,jsize) {
fDepConnectIndex = dependindex;
int i,j;
for(i=0; i<isize; i++) for(j=0; j<jsize; j++) fDepMatrix(i,j) = depmat(ipos+i,jpos+j);
#ifdef PZDEBUG
if(depmat.Rows() < ipos+isize || depmat.Cols() < jpos+jsize){
DebugStop();
}
if(fDepMatrix.Rows() < isize || fDepMatrix.Cols() < jsize){
DebugStop();
}
#endif
for(auto i=0; i<isize; i++) {
for(auto j=0; j<jsize; j++) {
fDepMatrix.PutVal(i,j,depmat.g(ipos+i,jpos+j));
}
}
fNext = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Mesh/pzgeoelside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ std::ostream &operator << (std::ostream & out,const TPZGeoElSide &geoside){
bool TPZGeoElSide::IsLinearMapping() const
{
if(!fGeoEl) return false;
return fGeoEl->IsLinearMapping();
return fGeoEl->IsLinearMapping(fSide);
}


Expand Down
36 changes: 32 additions & 4 deletions Mesh/pzintel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,18 @@ int64_t TPZInterpolatedElement::CreateMidSideConnect(int side) {
return newnodeindex;
}

void TPZInterpolatedElement::RestrainSide(int side, TPZInterpolatedElement *large, int neighbourside) {
void TPZInterpolatedElement::RestrainSide(int side, TPZInterpolatedElement *large,
int neighbourside)
{
if(this->Mesh()->GetSolType() == EReal){
RestrainSideT<STATE>(side,large,neighbourside);
}else{
RestrainSideT<CSTATE>(side,large,neighbourside);
}
}

template<class TVar>
void TPZInterpolatedElement::RestrainSideT(int side, TPZInterpolatedElement *large, int neighbourside) {
TPZCompElSide thisside(this, side);
TPZGeoElSide thisgeoside = thisside.Reference();
TPZCompElSide largecompside(large, neighbourside);
Expand Down Expand Up @@ -992,13 +1003,30 @@ void TPZInterpolatedElement::RestrainSide(int side, TPZInterpolatedElement *larg
DebugStop();
}
#endif

TPZFNMatrix<1000, TVar> MSLdep;
if constexpr (std::is_same_v<TVar,REAL>){
MSLdep = MSL;
}else{
const int nr = MSL.Rows();
const int nc = MSL.Cols();
MSLdep.Resize(nr,nc);
auto *my_ptr = MSLdep.Elem();
auto *their_ptr = MSL.Elem();
for(int i = 0; i < nr*nc;i++){
*my_ptr++ = *their_ptr++;
}
}

for (jn = 0; jn < numsidenodes_large; jn++) {
if (MBlocksmall.Size(in) == 0 || MBlocklarge.Size(jn) == 0) {
continue;
}
int64_t jnodindex = large->SideConnectIndex(jn, neighbourside);
TPZConnect::TPZDepend<STATE> *depend = inod.AddDependency(inodindex, jnodindex, MSL, MBlocksmall.Position(in), MBlocklarge.Position(jn),
MBlocksmall.Size(in), MBlocklarge.Size(jn));
TPZConnect::TPZDepend<TVar> *depend =
inod.AddDependency(inodindex, jnodindex, MSLdep,
MBlocksmall.Position(in), MBlocklarge.Position(jn),
MBlocksmall.Size(in), MBlocklarge.Size(jn));
if (blocknorm(in, jn) < 1.e-8) {
depend->fDepMatrix.Zero();
}
Expand All @@ -1010,7 +1038,7 @@ void TPZInterpolatedElement::RestrainSide(int side, TPZInterpolatedElement *larg
for (jn = 0; jn < numsidenodes_large; jn++) {
int64_t jnodindex = large->SideConnectIndex(jn, neighbourside);
if (MBlocklarge.Size(jn)) {
inod.AddDependency(inodindex, jnodindex, MSL, MBlocksmall.Position(in), MBlocklarge.Position(jn),
inod.AddDependency(inodindex, jnodindex, MSLdep, MBlocksmall.Position(in), MBlocklarge.Position(jn),
MBlocksmall.Size(in), MBlocklarge.Size(jn));
}
ndepend++;
Expand Down
3 changes: 2 additions & 1 deletion Mesh/pzintel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class TPZInterpolatedElement : public TPZInterpolationSpace {
*/
static int ComputeSideOrder(TPZVec<TPZCompElSide> &elementset);


template<class TVar>
void RestrainSideT(int side, TPZInterpolatedElement *large, int neighbourside);
public:
/**
* @brief Constructor with a mesh and geometric element as arguments
Expand Down
16 changes: 12 additions & 4 deletions Mesh/pzinterpolationspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,19 @@ void TPZInterpolationSpace::RemoveInterface(int side) {
}

void TPZInterpolationSpace::EvaluateError(TPZVec<REAL> &errors,bool store_error){
if(this->Mesh()->GetSolType() == ESolType::EReal){
EvaluateErrorT<STATE>(errors,store_error);
}else{
EvaluateErrorT<CSTATE>(errors,store_error);
}
}

template<class TVar>
void TPZInterpolationSpace::EvaluateErrorT(TPZVec<REAL> &errors,bool store_error){
errors.Fill(0.);
//TODOCOMPLEX
auto *material = this->Material();
auto* materror =
dynamic_cast<TPZMatErrorSingleSpace<STATE> *>(this->Material());
dynamic_cast<TPZMatErrorSingleSpace<TVar> *>(this->Material());
//TPZMaterial * matptr = material.operator->();
if (!material) {
PZError << __PRETTY_FUNCTION__;
Expand Down Expand Up @@ -1180,7 +1188,7 @@ void TPZInterpolationSpace::EvaluateError(TPZVec<REAL> &errors,bool store_error)
TPZManVector<REAL,10> intpoint(problemdimension), values(NErrors);
REAL weight;

TPZMaterialDataT<STATE> data;
TPZMaterialDataT<TVar> data;
this->InitMaterialData(data);
const int nintpoints = intrule->NPoints();

Expand All @@ -1207,7 +1215,7 @@ void TPZInterpolationSpace::EvaluateError(TPZVec<REAL> &errors,bool store_error)
if(store_error)
{
int64_t index = Index();
TPZFMatrix<STATE> &elvals = Mesh()->ElementSolution();
TPZFMatrix<TVar> &elvals = Mesh()->ElementSolution();
if (elvals.Cols() < NErrors) {
PZError<<__PRETTY_FUNCTION__;
PZError << " The element solution of the mesh should be resized before EvaluateError\n";
Expand Down
2 changes: 2 additions & 0 deletions Mesh/pzinterpolationspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ virtual int ClassId() const override;
template<class TVar>
void ComputeRequiredDataT(TPZMaterialDataT<TVar> &data,
TPZVec<REAL> &qsi);
template<class TVar>
void EvaluateErrorT(TPZVec<REAL> &errors, bool store_error );
template<class TVar>
void SolutionInternal(TPZVec<REAL> &qsi,int var,TPZVec<TVar> &sol);
/// Preferred polynomial order
Expand Down
8 changes: 7 additions & 1 deletion SpecialMaps/TPZCylinderMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ namespace pzgeom {
we need to normalise it*/
{
REAL normorth1{0};
for(auto &xx : orth1) {normorth1 += xx*xx;}
for(const auto &xx : orth1) {normorth1 += xx*xx;}
normorth1 = sqrt(normorth1);
for(auto &xx : orth1) {xx /= normorth1;}
}

TPZManVector<REAL,3> orth2(3,0.);
Cross(y,orth1,orth2);
{
REAL normorth2{0};
for(const auto &xx : orth2) {normorth2 += xx*xx;}
normorth2 = sqrt(normorth2);
for(auto &xx : orth2) {xx /= normorth2;}
}
for(int i = 0; i < 3; i++){
fRotation(i,0) = orth1[i];
fRotation(i,1) = orth2[i];
Expand Down
13 changes: 13 additions & 0 deletions SpecialMaps/TPZCylinderMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ namespace pzgeom {

/** @brief Sets axis of the cylinder and compute rotation matrix*/
void SetCylinderAxis(const TPZVec<REAL> &axis);

void GetCylinderAxis(TPZVec<REAL> &axis) const
{
#ifdef PZDEBUG
if(axis.size()!=3){
DebugStop();
}
#endif
//axis is the last column of rotation matrix
axis[0] = fRotation.GetVal(0,2);
axis[1] = fRotation.GetVal(1,2);
axis[2] = fRotation.GetVal(2,2);
}
/** @brief Sets the rotation matrix that converts from the reference cylinder
to the cylinder in the xyz space.
Reference cylinder has axis (0,0,1), therefore last column of rotation matrix
Expand Down
Loading

0 comments on commit 12d4434

Please sign in to comment.