Skip to content

Commit

Permalink
feat(gmshreader): changing node ordering of periodic els if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandini committed Sep 16, 2024
1 parent 04988c3 commit e3b8a1e
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions Pre/TPZGmshReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@ void TPZGmshReader::SetPeriodicElements(
auto &periodic_nodes = periodic_nodes_by_physical_ids[dim][depmatid];
//we have found a dependent el
const auto nnodes = depel->NNodes();
const auto nsides = depel->NSides();
const auto dep_type = depel->Type();
TPZManVector<int64_t,8> mapped_nodes(nnodes);
for (auto in = 0; in < nnodes; in++) {
Expand All @@ -1463,10 +1464,13 @@ void TPZGmshReader::SetPeriodicElements(
if(found_indep){break;}
const int indep_type = indepel->Type();
const bool sametype = indep_type == dep_type;
constexpr int max_nnodes{8};
TPZManVector<int64_t,max_nnodes> indepnodes(nnodes);
indepel->GetNodeIndices(indepnodes);
if (indepel->MaterialId() == indepmatid && sametype) {
bool samenodes = true;
for (auto in = 0; in < nnodes && samenodes; in++) {
const auto indepnode = indepel->NodeIndex(in);
const auto indepnode = indepnodes[in];
const bool hasnode =
std::find(mapped_nodes.begin(), mapped_nodes.end(),
indepnode) != mapped_nodes.end();
Expand All @@ -1475,7 +1479,29 @@ void TPZGmshReader::SetPeriodicElements(
if (samenodes) {
m_periodic_els[depel->Id()] = indepel->Id();
found_indep=true;
#ifdef PZDEBUG
//now we check if we need to change orientation
bool sameorient{true};
for (auto in = 0; in < nnodes && sameorient; in++) {
if(indepnodes[in] != mapped_nodes[in]){
sameorient=false;
}
}
//nothing to else be done here
if(sameorient){break;}
/*
WARNING:
right now, SetPeriodic is called before BuildConnectivity.
should this change in the future, changing node ordering is
not enough, connectivity should be changed as well.
For this purpose, TPZChangeEl::ChangeNodeOrdering
should be sued.
*/
for (auto in = 0; in < nnodes; in++) {
const auto mapped = mapped_nodes[in];
indepel->SetNodeIndex(in, mapped);
}
//since we are changing node ordering we dont need to perform this check again
#ifdef PZDEBUG2
const int dim = depel->Dimension();
TPZManVector<REAL,3> qsi(dim,0);
TPZFNMatrix<9,REAL> jac, jacinv;
Expand All @@ -1492,8 +1518,15 @@ void TPZGmshReader::SetPeriodicElements(
for(int ic = 0; ic < nc; ic++){
if(res.GetVal(ir,ic) > tol){
PZError<<__PRETTY_FUNCTION__
<<"\nError in periodic elements orientation!"
<<std::endl;
<<"\nError in periodic elements orientation!\n"
<<"dep el "<<depel->Id()<<" indep el "<<indepel->Id()<<std::endl;
TPZManVector<REAL,3> qsi(depel->Dimension(),0), xcenter(3,0);
depel->CenterPoint(depel->NSides()-1, qsi);
depel->X(qsi,xcenter);
PZError<<"dep el center : "<<xcenter[0]<<','<<xcenter[1]<<','<<xcenter[2]<<std::endl;
indepel->CenterPoint(indepel->NSides()-1, qsi);
indepel->X(qsi,xcenter);
PZError<<"indep el center : "<<xcenter[0]<<','<<xcenter[1]<<','<<xcenter[2]<<std::endl;
dep_axes.Print("dep axes",PZError);
indep_axes.Print("indep axes",PZError);
DebugStop();
Expand Down

0 comments on commit e3b8a1e

Please sign in to comment.