Skip to content

Fix constantface comm#542

Open
NickvonWit wants to merge 3 commits into
IPPL-framework:masterfrom
NickvonWit:fix-constantface-comm
Open

Fix constantface comm#542
NickvonWit wants to merge 3 commits into
IPPL-framework:masterfrom
NickvonWit:fix-constantface-comm

Conversation

@NickvonWit

Copy link
Copy Markdown

Fix face-specific boundary detection in ExtrapolateFace::apply()

This PR fixes #541. It also adds problem specific, Constant or Periodic Face, test files for the CG Solver.

The new test file for the constant face accounts for #535 by shifting the coordinates, to have the halo cells lie on the boundary instead of. The mechanism is explained in detail in my thesis.

File: src/Field/BcTypes.hpp (ExtrapolateFace<Field>::apply())

The old boundary check used an OR over both faces, so a rank touching the lower
global boundary would also apply the upper face BC (and vice versa). On multiple
ranks this overwrote internal halo cells that should come from neighbouring
ranks, breaking ConstantFace / ZeroFace problems.

The check is now face-specific: a face is only treated as a physical boundary if
this rank owns the matching global boundary side. Internal interfaces fall
through to halo exchange as intended.

Before:

bool isBoundary = (lDomains[myRank][d].max() == domain[d].max())
                  || (lDomains[myRank][d].min() == domain[d].min());

After:

const bool isLowerFace = !(face & 1);

const bool isBoundary =
    isLowerFace ? (lDomains[myRank][d].min() == domain[d].min())
                : (lDomains[myRank][d].max() == domain[d].max());

Running the same tests as in #541, again with 4 ranks/CPUs:

TestCGSolver_convergence_constant:

size,h,relError,trueResidual,solverResidual,itCount,solveTime
4,0.2,0.03993833615825652,5.192396279594881e-16,1.548388472317241e-14,4,0.0007419999999999927
8,0.1111111111111111,0.0118946827628043,2.280480765191515e-14,4.454411477477602e-12,18,0.0001960000000000017
16,0.05882352941176471,0.003297211400358864,7.361141393128399e-14,3.744523593663216e-11,30,0.001140999999999989
32,0.0303030303030303,0.00087231155428423,1.311740466831537e-13,1.40521600427478e-10,57,0.008532999999999999
64,0.01538461538461539,0.000224653947278718,4.601852170306531e-13,3.315314961627911e-10,113,0.041592
128,0.007751937984496124,5.702542539421606e-05,2.503480591224792e-12,1.025120149851657e-09,226,0.622335
cg_fix_const

TestCGSolver_convergence_periodic:

size,h,relError,trueResidual,solverResidual,itCount,solveTime
4,0.25,0.6377366121760882,1.596057071843241e-16,5.123796534383003e-14,1,0.0009799999999999948
8,0.125,0.06610999025353599,4.70268102220917e-16,5.55931194985223e-14,4,8.000000000001062e-05
16,0.0625,0.01511692691447543,5.860301855464142e-11,1.112753509887523e-07,12,0.0002899999999999986
32,0.03125,0.003724276265085818,5.170018915267303e-11,2.776629330922694e-07,21,0.001666000000000001
64,0.015625,0.0009277485090611948,9.456697119791474e-11,1.436507970115203e-06,41,0.01862800000000001
128,0.0078125,0.0002317313213305733,8.187506446496449e-11,3.51770745253475e-06,81,0.232264
cg_fix_per

Create a new test file for a Constant Face and Periodic Face
respectively. We remove the old file.
@s-mayani s-mayani self-requested a review June 8, 2026 11:26
}

Inform m("");
m << "size,h,relError,trueResidual,solverResidual,itCount,solveTime" << endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it's better to print only the same things as were being printed by the TestCGSolver_convergence before.

Comment on lines +118 to +143

const double ax = pi * x;
const double ay = pi * y;
const double az = pi * z;

const double sx = sin(sin(ax));
const double sy = sin(sin(ay));
const double sz = sin(sin(az));

const double cx = cos(sin(ax));
const double cy = cos(sin(ay));
const double cz = cos(sin(az));

const double sax = sin(ax);
const double say = sin(ay);
const double saz = sin(az);

const double cax = cos(ax);
const double cay = cos(ay);
const double caz = cos(az);

const double u = sx * sy * sz;

const double f = pi * pi
* (cx * sax * sy * sz + sx * cy * say * sz + sx * sy * cz * saz
+ sx * sy * sz * (cax * cax + cay * cay + caz * caz));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change it back to the same function as the original file, for readability

Comment on lines +187 to +188
m << pt << "," << std::setprecision(16) << dx << "," << relError << "," << trueResidual
<< "," << solverResidual << "," << itCount << "," << solveTime << endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as said before, change back to original output results

}

Inform m("");
m << "size,h,relError,trueResidual,solverResidual,itCount,solveTime" << endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before regarding which results are printed

Comment on lines +116 to +140
const double ax = a * x;
const double ay = a * y;
const double az = a * z;

const double sx = sin(sin(ax));
const double sy = sin(sin(ay));
const double sz = sin(sin(az));

const double cx = cos(sin(ax));
const double cy = cos(sin(ay));
const double cz = cos(sin(az));

const double sax = sin(ax);
const double say = sin(ay);
const double saz = sin(az);

const double cax = cos(ax);
const double cay = cos(ay);
const double caz = cos(az);

const double u = sx * sy * sz;

const double f = a * a
* (cx * sax * sy * sz + sx * cy * say * sz + sx * sy * cz * saz
+ sx * sy * sz * (cax * cax + cay * cay + caz * caz));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as above

Comment on lines +198 to +199
m << pt << "," << std::setprecision(16) << dx << "," << relError << "," << trueResidual
<< "," << solverResidual << "," << itCount << "," << solveTime << endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constant Face Boundary Conditions do not communicate properly

2 participants