diff --git a/examples/Hdiv-mass/basis/Hdiv-hex.h b/examples/Hdiv-mass/basis/Hdiv-hex.h index a01b1a3ef3..9259bede85 100644 --- a/examples/Hdiv-mass/basis/Hdiv-hex.h +++ b/examples/Hdiv-mass/basis/Hdiv-hex.h @@ -16,119 +16,115 @@ // To see how the nodal basis is constructed visit: // https://github.com/rezgarshakeri/H-div-Tests -int NodalHdivBasisHex(CeedScalar *x, CeedScalar *Bx, CeedScalar *By, - CeedScalar *Bz) { - - Bx[ 0] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 0] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 0] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 1] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 1] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 1] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 2] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 2] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 2] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 3] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 3] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 3] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] + - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 4] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 4] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 4] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 5] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 5] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 5] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 6] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 6] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 6] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 7] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 7] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 7] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 8] = 0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] - 0.0625*x[2] + 0.0625 ; - By[ 8] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bz[ 8] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[ 9] = -0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] + 0.0625*x[2] - 0.0625 ; - By[ 9] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bz[ 9] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[10] = -0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] + 0.0625*x[2] + 0.0625 ; - By[10] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - Bz[10] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[11] = 0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] - 0.0625*x[2] - 0.0625 ; - By[11] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - Bz[11] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[12] = 0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] - 0.0625*x[2] + 0.0625 ; - By[12] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - Bz[12] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[13] = -0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] + 0.0625*x[2] - 0.0625 ; - By[13] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - Bz[13] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[14] = -0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] + 0.0625*x[2] + 0.0625 ; - By[14] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bz[14] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[15] = 0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] - 0.0625*x[2] - 0.0625 ; - By[15] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bz[15] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[16] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] - 0.125*x[1] - 0.125*x[2] + 0.125 ; - By[16] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[16] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[17] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - By[17] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[17] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[18] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - By[18] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[18] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[19] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - By[19] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[19] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[20] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - By[20] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[20] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[21] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - By[21] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[21] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[22] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - By[22] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[22] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[23] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] - 0.125*x[2] - 0.125 ; - By[23] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[23] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; +int NodalHdivBasisHex(CeedScalar *x, CeedScalar *Bx, CeedScalar *By, CeedScalar *Bz) { + Bx[0] = 0.0625 * x[0] * x[0] - 0.0625; + By[0] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[0] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[1] = 0.0625 - 0.0625 * x[0] * x[0]; + By[1] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[1] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[2] = 0.0625 * x[0] * x[0] - 0.0625; + By[2] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[2] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[3] = 0.0625 - 0.0625 * x[0] * x[0]; + By[3] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[3] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[4] = 0.0625 * x[0] * x[0] - 0.0625; + By[4] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[4] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[5] = 0.0625 - 0.0625 * x[0] * x[0]; + By[5] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[5] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[6] = 0.0625 * x[0] * x[0] - 0.0625; + By[6] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[6] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[7] = 0.0625 - 0.0625 * x[0] * x[0]; + By[7] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[7] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[8] = 0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] - 0.0625 * x[2] + 0.0625; + By[8] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bz[8] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[9] = -0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] + 0.0625 * x[2] - 0.0625; + By[9] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bz[9] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[10] = -0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] + 0.0625 * x[2] + 0.0625; + By[10] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - 0.125 * x[2] - + 0.125; + Bz[10] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[11] = 0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] - 0.0625 * x[2] - 0.0625; + By[11] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] - 0.125; + Bz[11] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[12] = 0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] - 0.0625 * x[2] + 0.0625; + By[12] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] + 0.125; + Bz[12] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[13] = -0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] + 0.0625 * x[2] - 0.0625; + By[13] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - 0.125 * x[2] + + 0.125; + Bz[13] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[14] = -0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] + 0.0625 * x[2] + 0.0625; + By[14] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bz[14] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[15] = 0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] - 0.0625 * x[2] - 0.0625; + By[15] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + + 0.125 * x[2] + 0.125; + Bz[15] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[16] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] - 0.125 * x[2] + + 0.125; + By[16] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[16] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[17] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] + 0.125; + By[17] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[17] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[18] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + + 0.125 * x[2] + 0.125; + By[18] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[18] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[19] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + By[19] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[19] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[20] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + By[20] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[20] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[21] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + + 0.125 * x[2] - 0.125; + By[21] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[21] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[22] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] - 0.125; + By[22] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[22] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[23] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] - 0.125 * x[2] - + 0.125; + By[23] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[23] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; return 0; } -static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, - CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) { - +static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) { // Get 1D quadrature on [-1,1] CeedScalar q_ref_1d[Q], q_weight_1d[Q]; switch (quad_mode) { - case CEED_GAUSS: - CeedGaussQuadrature(Q, q_ref_1d, q_weight_1d); - break; - case CEED_GAUSS_LOBATTO: - CeedLobattoQuadrature(Q, q_ref_1d, q_weight_1d); - break; + case CEED_GAUSS: + CeedGaussQuadrature(Q, q_ref_1d, q_weight_1d); + break; + case CEED_GAUSS_LOBATTO: + CeedLobattoQuadrature(Q, q_ref_1d, q_weight_1d); + break; } // Divergence operator; Divergence of nodal basis for ref element @@ -136,27 +132,25 @@ static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, // Loop over quadrature points CeedScalar Bx[24], By[24], Bz[24]; CeedScalar x[3]; - for (CeedInt k=0; k #include #include #include -#include + #include "../include/structs.h" // --------------------------------------------------------------------------- // Set-up DM // --------------------------------------------------------------------------- -PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data, - DM *dm); +PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data, DM *dm); -#endif // setupdm_h +#endif // setupdm_h diff --git a/examples/Hdiv-mass/include/setup-libceed.h b/examples/Hdiv-mass/include/setup-libceed.h index bced0f69cc..7be8d75464 100644 --- a/examples/Hdiv-mass/include/setup-libceed.h +++ b/examples/Hdiv-mass/include/setup-libceed.h @@ -10,15 +10,10 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data); // Utility function - essential BC dofs are encoded in closure indices as -(i+1) PetscInt Involute(PetscInt i); // Utility function to create local CEED restriction from DMPlex -PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, - CeedInt height, DMLabel domain_label, CeedInt value, - CeedElemRestriction *elem_restr); +PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr); // Utility function to create local CEED Oriented restriction from DMPlex -PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, - CeedInt P, CeedElemRestriction *elem_restr_oriented); +PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P, CeedElemRestriction *elem_restr_oriented); // Set up libCEED for a given degree -PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, - ProblemData *problem_data, PetscInt U_g_size, - PetscInt U_loc_size, CeedData ceed_data, +PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ProblemData *problem_data, PetscInt U_g_size, PetscInt U_loc_size, CeedData ceed_data, CeedVector rhs_ceed, CeedVector *target); -#endif // setuplibceed_h +#endif // setuplibceed_h diff --git a/examples/Hdiv-mass/include/structs.h b/examples/Hdiv-mass/include/structs.h index b4a8754e65..69f65d916b 100644 --- a/examples/Hdiv-mass/include/structs.h +++ b/examples/Hdiv-mass/include/structs.h @@ -8,8 +8,8 @@ typedef struct AppCtx_ *AppCtx; struct AppCtx_ { // libCEED arguments - PetscInt degree; - PetscInt q_extra; + PetscInt degree; + PetscInt q_extra; // Problem type arguments PetscFunctionList problems; char problem_name[PETSC_MAX_PATH_LEN]; @@ -19,8 +19,7 @@ struct AppCtx_ { typedef struct CeedData_ *CeedData; struct CeedData_ { CeedBasis basis_x, basis_u; - CeedElemRestriction elem_restr_x, elem_restr_u, - elem_restr_u_i; + CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_u_i; CeedQFunction qf_residual, qf_error; CeedOperator op_residual, op_error; CeedVector x_ceed, y_ceed; @@ -52,8 +51,8 @@ struct PH3DContext_ { // Struct that contains all enums and structs used for the physics of all problems typedef struct Physics_ *Physics; struct Physics_ { - PQ2DContext pq2d_ctx; - PH3DContext ph3d_ctx; + PQ2DContext pq2d_ctx; + PH3DContext ph3d_ctx; }; // PETSc user data @@ -72,11 +71,11 @@ struct User_ { // Problem specific data typedef struct { CeedQFunctionUser setup_rhs, residual, setup_error; - const char *setup_rhs_loc, *residual_loc, *setup_error_loc; + const char *setup_rhs_loc, *residual_loc, *setup_error_loc; CeedQuadMode quadrature_mode; CeedInt elem_node, dim; - PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics); + PetscErrorCode (*setup_ctx)(Ceed, CeedData, Physics); } ProblemData; -#endif // structs_h \ No newline at end of file +#endif // structs_h \ No newline at end of file diff --git a/examples/Hdiv-mass/main.c b/examples/Hdiv-mass/main.c index ddd66fbb70..338e745cfb 100644 --- a/examples/Hdiv-mass/main.c +++ b/examples/Hdiv-mass/main.c @@ -43,19 +43,24 @@ int main(int argc, char **argv) { // Create structs // --------------------------------------------------------------------------- AppCtx app_ctx; - ierr = PetscCalloc1(1, &app_ctx); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &app_ctx); + CHKERRQ(ierr); ProblemData *problem_data = NULL; - ierr = PetscCalloc1(1, &problem_data); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &problem_data); + CHKERRQ(ierr); User user; - ierr = PetscCalloc1(1, &user); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &user); + CHKERRQ(ierr); CeedData ceed_data; - ierr = PetscCalloc1(1, &ceed_data); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &ceed_data); + CHKERRQ(ierr); Physics phys_ctx; - ierr = PetscCalloc1(1, &phys_ctx); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &phys_ctx); + CHKERRQ(ierr); user->app_ctx = app_ctx; user->phys = phys_ctx; @@ -64,11 +69,13 @@ int main(int argc, char **argv) { // Process command line options // --------------------------------------------------------------------------- // -- Register problems to be available on the command line - ierr = RegisterProblems_Hdiv(app_ctx); CHKERRQ(ierr); + ierr = RegisterProblems_Hdiv(app_ctx); + CHKERRQ(ierr); // -- Process general command line options MPI_Comm comm = PETSC_COMM_WORLD; - ierr = ProcessCommandLineOptions(comm, app_ctx); CHKERRQ(ierr); + ierr = ProcessCommandLineOptions(comm, app_ctx); + CHKERRQ(ierr); // --------------------------------------------------------------------------- // Choose the problem from the list of registered problems @@ -77,9 +84,9 @@ int main(int argc, char **argv) { PetscErrorCode (*p)(ProblemData *, void *); ierr = PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name, &p); CHKERRQ(ierr); - if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found", - app_ctx->problem_name); - ierr = (*p)(problem_data, &user); CHKERRQ(ierr); + if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found", app_ctx->problem_name); + ierr = (*p)(problem_data, &user); + CHKERRQ(ierr); } // --------------------------------------------------------------------------- @@ -94,48 +101,60 @@ int main(int argc, char **argv) { // Set-up DM // --------------------------------------------------------------------------- // PETSc objects - DM dm; - VecType vec_type; - ierr = CreateDistributedDM(comm, problem_data, &dm); CHKERRQ(ierr); - ierr = DMGetVecType(dm, &vec_type); CHKERRQ(ierr); - if (!vec_type) { // Not yet set by user -dm_vec_type + DM dm; + VecType vec_type; + ierr = CreateDistributedDM(comm, problem_data, &dm); + CHKERRQ(ierr); + ierr = DMGetVecType(dm, &vec_type); + CHKERRQ(ierr); + if (!vec_type) { // Not yet set by user -dm_vec_type switch (mem_type_backend) { - case CEED_MEM_HOST: vec_type = VECSTANDARD; break; - case CEED_MEM_DEVICE: { - const char *resolved; - CeedGetResource(ceed, &resolved); - if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; - else if (strstr(resolved, "/gpu/hip/occa")) - vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678 - else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP; - else vec_type = VECSTANDARD; - } + case CEED_MEM_HOST: + vec_type = VECSTANDARD; + break; + case CEED_MEM_DEVICE: { + const char *resolved; + CeedGetResource(ceed, &resolved); + if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; + else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD; // https://github.com/CEED/libCEED/issues/678 + else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP; + else vec_type = VECSTANDARD; + } } - ierr = DMSetVecType(dm, vec_type); CHKERRQ(ierr); + ierr = DMSetVecType(dm, vec_type); + CHKERRQ(ierr); } // --------------------------------------------------------------------------- // Create global, local solution, local rhs vector // --------------------------------------------------------------------------- - Vec U_g, U_loc; - PetscInt U_l_size, U_g_size, U_loc_size; + Vec U_g, U_loc; + PetscInt U_l_size, U_g_size, U_loc_size; // Create global and local solution vectors - ierr = DMCreateGlobalVector(dm, &U_g); CHKERRQ(ierr); - ierr = VecGetSize(U_g, &U_g_size); CHKERRQ(ierr); + ierr = DMCreateGlobalVector(dm, &U_g); + CHKERRQ(ierr); + ierr = VecGetSize(U_g, &U_g_size); + CHKERRQ(ierr); // Local size for matShell - ierr = VecGetLocalSize(U_g, &U_l_size); CHKERRQ(ierr); + ierr = VecGetLocalSize(U_g, &U_l_size); + CHKERRQ(ierr); // Create local unknown vector U_loc - ierr = DMCreateLocalVector(dm, &U_loc); CHKERRQ(ierr); + ierr = DMCreateLocalVector(dm, &U_loc); + CHKERRQ(ierr); // Local size for libCEED - ierr = VecGetSize(U_loc, &U_loc_size); CHKERRQ(ierr); + ierr = VecGetSize(U_loc, &U_loc_size); + CHKERRQ(ierr); // Get RHS vector - Vec rhs_loc; + Vec rhs_loc; PetscScalar *r; - CeedVector rhs_ceed, target; + CeedVector rhs_ceed, target; PetscMemType mem_type; - ierr = VecDuplicate(U_loc, &rhs_loc); CHKERRQ(ierr); - ierr = VecZeroEntries(rhs_loc); CHKERRQ(ierr); - ierr = VecGetArrayAndMemType(rhs_loc, &r, &mem_type); CHKERRQ(ierr); + ierr = VecDuplicate(U_loc, &rhs_loc); + CHKERRQ(ierr); + ierr = VecZeroEntries(rhs_loc); + CHKERRQ(ierr); + ierr = VecGetArrayAndMemType(rhs_loc, &r, &mem_type); + CHKERRQ(ierr); CeedVectorCreate(ceed, U_l_size, &rhs_ceed); CeedVectorSetArray(rhs_ceed, MemTypeP2C(mem_type), CEED_USE_POINTER, r); @@ -143,103 +162,135 @@ int main(int argc, char **argv) { // Setup libCEED // --------------------------------------------------------------------------- // -- Set up libCEED objects - ierr = SetupLibceed(dm, ceed, app_ctx, problem_data, U_g_size, - U_loc_size, ceed_data, rhs_ceed, &target); CHKERRQ(ierr); + ierr = SetupLibceed(dm, ceed, app_ctx, problem_data, U_g_size, U_loc_size, ceed_data, rhs_ceed, &target); + CHKERRQ(ierr); // --------------------------------------------------------------------------- // Gather RHS // --------------------------------------------------------------------------- Vec rhs; CeedVectorTakeArray(rhs_ceed, MemTypeP2C(mem_type), NULL); - ierr = VecRestoreArrayAndMemType(rhs_loc, &r); CHKERRQ(ierr); - ierr = VecDuplicate(U_g, &rhs); CHKERRQ(ierr); - ierr = VecZeroEntries(rhs); CHKERRQ(ierr); - ierr = DMLocalToGlobal(dm, rhs_loc, ADD_VALUES, rhs); CHKERRQ(ierr); - //VecView(rhs, PETSC_VIEWER_STDOUT_WORLD); + ierr = VecRestoreArrayAndMemType(rhs_loc, &r); + CHKERRQ(ierr); + ierr = VecDuplicate(U_g, &rhs); + CHKERRQ(ierr); + ierr = VecZeroEntries(rhs); + CHKERRQ(ierr); + ierr = DMLocalToGlobal(dm, rhs_loc, ADD_VALUES, rhs); + CHKERRQ(ierr); + // VecView(rhs, PETSC_VIEWER_STDOUT_WORLD); // --------------------------------------------------------------------------- // Setup Mat, KSP // --------------------------------------------------------------------------- - user->comm = comm; - user->dm = dm; + user->comm = comm; + user->dm = dm; user->X_loc = U_loc; - ierr = VecDuplicate(U_loc, &user->Y_loc); CHKERRQ(ierr); - user->x_ceed = ceed_data->x_ceed; - user->y_ceed = ceed_data->y_ceed; + ierr = VecDuplicate(U_loc, &user->Y_loc); + CHKERRQ(ierr); + user->x_ceed = ceed_data->x_ceed; + user->y_ceed = ceed_data->y_ceed; user->op_apply = ceed_data->op_residual; user->op_error = ceed_data->op_error; - user->ceed = ceed; + user->ceed = ceed; // Operator Mat mat; - ierr = MatCreateShell(comm, U_l_size, U_l_size, U_g_size, U_g_size, - user, &mat); CHKERRQ(ierr); - ierr = MatShellSetOperation(mat, MATOP_MULT, - (void(*)(void))MatMult_Ceed); CHKERRQ(ierr); - ierr = MatShellSetVecType(mat, vec_type); CHKERRQ(ierr); + ierr = MatCreateShell(comm, U_l_size, U_l_size, U_g_size, U_g_size, user, &mat); + CHKERRQ(ierr); + ierr = MatShellSetOperation(mat, MATOP_MULT, (void (*)(void))MatMult_Ceed); + CHKERRQ(ierr); + ierr = MatShellSetVecType(mat, vec_type); + CHKERRQ(ierr); KSP ksp; - ierr = KSPCreate(comm, &ksp); CHKERRQ(ierr); - ierr = KSPSetOperators(ksp, mat, mat); CHKERRQ(ierr); - ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); - ierr = KSPSetUp(ksp); CHKERRQ(ierr); - ierr = KSPSolve(ksp, rhs, U_g); CHKERRQ(ierr); - //printf("U_g\n"); - //VecView(U_g, PETSC_VIEWER_STDOUT_WORLD); - // --------------------------------------------------------------------------- - // Compute pointwise L2 maximum error - // --------------------------------------------------------------------------- + ierr = KSPCreate(comm, &ksp); + CHKERRQ(ierr); + ierr = KSPSetOperators(ksp, mat, mat); + CHKERRQ(ierr); + ierr = KSPSetFromOptions(ksp); + CHKERRQ(ierr); + ierr = KSPSetUp(ksp); + CHKERRQ(ierr); + ierr = KSPSolve(ksp, rhs, U_g); + CHKERRQ(ierr); + // printf("U_g\n"); + // VecView(U_g, PETSC_VIEWER_STDOUT_WORLD); + // --------------------------------------------------------------------------- + // Compute pointwise L2 maximum error + // --------------------------------------------------------------------------- CeedScalar l2_error; - ierr = ComputeError(user, U_g, target, &l2_error); CHKERRQ(ierr); + ierr = ComputeError(user, U_g, target, &l2_error); + CHKERRQ(ierr); // --------------------------------------------------------------------------- // Output results // --------------------------------------------------------------------------- - KSPType ksp_type; + KSPType ksp_type; KSPConvergedReason reason; - PetscReal rnorm; - PetscInt its; - ierr = KSPGetType(ksp, &ksp_type); CHKERRQ(ierr); - ierr = KSPGetConvergedReason(ksp, &reason); CHKERRQ(ierr); - ierr = KSPGetIterationNumber(ksp, &its); CHKERRQ(ierr); - ierr = KSPGetResidualNorm(ksp, &rnorm); CHKERRQ(ierr); + PetscReal rnorm; + PetscInt its; + ierr = KSPGetType(ksp, &ksp_type); + CHKERRQ(ierr); + ierr = KSPGetConvergedReason(ksp, &reason); + CHKERRQ(ierr); + ierr = KSPGetIterationNumber(ksp, &its); + CHKERRQ(ierr); + ierr = KSPGetResidualNorm(ksp, &rnorm); + CHKERRQ(ierr); ierr = PetscPrintf(comm, " KSP:\n" " KSP Type : %s\n" " KSP Convergence : %s\n" - " Total KSP Iterations : %" PetscInt_FMT "\n" + " Total KSP Iterations : %" PetscInt_FMT + "\n" " Final rnorm : %e\n" " L2 Error : %e\n", - ksp_type, KSPConvergedReasons[reason], its, - (double)rnorm, (double)l2_error); CHKERRQ(ierr); + ksp_type, KSPConvergedReasons[reason], its, (double)rnorm, (double)l2_error); + CHKERRQ(ierr); // --------------------------------------------------------------------------- // Free objects // --------------------------------------------------------------------------- // Free PETSc objects - ierr = DMDestroy(&dm); CHKERRQ(ierr); - ierr = VecDestroy(&U_g); CHKERRQ(ierr); - ierr = VecDestroy(&U_loc); CHKERRQ(ierr); - ierr = VecDestroy(&rhs); CHKERRQ(ierr); - ierr = VecDestroy(&rhs_loc); CHKERRQ(ierr); - ierr = VecDestroy(&user->Y_loc); CHKERRQ(ierr); - ierr = MatDestroy(&mat); CHKERRQ(ierr); - ierr = KSPDestroy(&ksp); CHKERRQ(ierr); + ierr = DMDestroy(&dm); + CHKERRQ(ierr); + ierr = VecDestroy(&U_g); + CHKERRQ(ierr); + ierr = VecDestroy(&U_loc); + CHKERRQ(ierr); + ierr = VecDestroy(&rhs); + CHKERRQ(ierr); + ierr = VecDestroy(&rhs_loc); + CHKERRQ(ierr); + ierr = VecDestroy(&user->Y_loc); + CHKERRQ(ierr); + ierr = MatDestroy(&mat); + CHKERRQ(ierr); + ierr = KSPDestroy(&ksp); + CHKERRQ(ierr); // -- Function list - ierr = PetscFunctionListDestroy(&app_ctx->problems); CHKERRQ(ierr); + ierr = PetscFunctionListDestroy(&app_ctx->problems); + CHKERRQ(ierr); // -- Structs - ierr = PetscFree(app_ctx); CHKERRQ(ierr); - ierr = PetscFree(problem_data); CHKERRQ(ierr); - ierr = PetscFree(user); CHKERRQ(ierr); - ierr = PetscFree(phys_ctx->pq2d_ctx); CHKERRQ(ierr); - ierr = PetscFree(phys_ctx); CHKERRQ(ierr); + ierr = PetscFree(app_ctx); + CHKERRQ(ierr); + ierr = PetscFree(problem_data); + CHKERRQ(ierr); + ierr = PetscFree(user); + CHKERRQ(ierr); + ierr = PetscFree(phys_ctx->pq2d_ctx); + CHKERRQ(ierr); + ierr = PetscFree(phys_ctx); + CHKERRQ(ierr); // Free libCEED objects CeedVectorDestroy(&rhs_ceed); CeedVectorDestroy(&target); - ierr = CeedDataDestroy(ceed_data); CHKERRQ(ierr); + ierr = CeedDataDestroy(ceed_data); + CHKERRQ(ierr); CeedDestroy(&ceed); return PetscFinalize(); diff --git a/examples/Hdiv-mass/main.h b/examples/Hdiv-mass/main.h index da283f2d04..c5ecde00d9 100644 --- a/examples/Hdiv-mass/main.h +++ b/examples/Hdiv-mass/main.h @@ -2,10 +2,10 @@ #ifndef MAIN_H #define MAIN_H -#include "include/setup-libceed.h" -#include "include/setup-dm.h" #include "include/cl-options.h" -#include "include/problems.h" #include "include/matops.h" +#include "include/problems.h" +#include "include/setup-dm.h" +#include "include/setup-libceed.h" -#endif // MAIN_H \ No newline at end of file +#endif // MAIN_H \ No newline at end of file diff --git a/examples/Hdiv-mass/problems/mass2d.c b/examples/Hdiv-mass/problems/mass2d.c index 4049b42d5d..2e58f87045 100644 --- a/examples/Hdiv-mass/problems/mass2d.c +++ b/examples/Hdiv-mass/problems/mass2d.c @@ -17,33 +17,34 @@ /// @file /// Utility functions for setting up POISSON_QUAD2D -#include "../include/setup-libceed.h" #include "../include/problems.h" -#include "../qfunctions/poisson-rhs2d.h" -#include "../qfunctions/poisson-mass2d.h" +#include "../include/setup-libceed.h" #include "../qfunctions/poisson-error2d.h" +#include "../qfunctions/poisson-mass2d.h" +#include "../qfunctions/poisson-rhs2d.h" // Hdiv_POISSON_MASS2D is registered in cl-option.c PetscErrorCode Hdiv_POISSON_MASS2D(ProblemData *problem_data, void *ctx) { - User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; - PetscInt ierr; + User user = *(User *)ctx; + MPI_Comm comm = PETSC_COMM_WORLD; + PetscInt ierr; PetscFunctionBeginUser; - ierr = PetscCalloc1(1, &user->phys->pq2d_ctx); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &user->phys->pq2d_ctx); + CHKERRQ(ierr); // ------------------------------------------------------ // SET UP POISSON_QUAD2D // ------------------------------------------------------ - problem_data->dim = 2; - problem_data->elem_node = 4; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->setup_rhs = SetupRhs2D; - problem_data->setup_rhs_loc = SetupRhs2D_loc; - problem_data->residual = SetupMass2D; - problem_data->residual_loc = SetupMass2D_loc; - problem_data->setup_error = SetupError2D; - problem_data->setup_error_loc = SetupError2D_loc; + problem_data->dim = 2; + problem_data->elem_node = 4; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->setup_rhs = SetupRhs2D; + problem_data->setup_rhs_loc = SetupRhs2D_loc; + problem_data->residual = SetupMass2D; + problem_data->residual_loc = SetupMass2D_loc; + problem_data->setup_error = SetupError2D; + problem_data->setup_error_loc = SetupError2D_loc; // ------------------------------------------------------ // Command line Options diff --git a/examples/Hdiv-mass/problems/mass3d.c b/examples/Hdiv-mass/problems/mass3d.c index a86d3c5600..2997ebb572 100644 --- a/examples/Hdiv-mass/problems/mass3d.c +++ b/examples/Hdiv-mass/problems/mass3d.c @@ -17,33 +17,34 @@ /// @file /// Utility functions for setting up POISSON_QUAD2D -#include "../include/setup-libceed.h" #include "../include/problems.h" -#include "../qfunctions/poisson-rhs3d.h" -#include "../qfunctions/poisson-mass3d.h" +#include "../include/setup-libceed.h" #include "../qfunctions/poisson-error3d.h" +#include "../qfunctions/poisson-mass3d.h" +#include "../qfunctions/poisson-rhs3d.h" // Hdiv_POISSON_MASS2D is registered in cl-option.c PetscErrorCode Hdiv_POISSON_MASS3D(ProblemData *problem_data, void *ctx) { - User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; - PetscInt ierr; + User user = *(User *)ctx; + MPI_Comm comm = PETSC_COMM_WORLD; + PetscInt ierr; PetscFunctionBeginUser; - ierr = PetscCalloc1(1, &user->phys->ph3d_ctx); CHKERRQ(ierr); + ierr = PetscCalloc1(1, &user->phys->ph3d_ctx); + CHKERRQ(ierr); // ------------------------------------------------------ // SET UP POISSON_QUAD3D // ------------------------------------------------------ - problem_data->dim = 3; - problem_data->elem_node = 8; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->setup_rhs = SetupRhs3D; - problem_data->setup_rhs_loc = SetupRhs3D_loc; - problem_data->residual = SetupMass3D; - problem_data->residual_loc = SetupMass3D_loc; - problem_data->setup_error = SetupError3D; - problem_data->setup_error_loc = SetupError3D_loc; + problem_data->dim = 3; + problem_data->elem_node = 8; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->setup_rhs = SetupRhs3D; + problem_data->setup_rhs_loc = SetupRhs3D_loc; + problem_data->residual = SetupMass3D; + problem_data->residual_loc = SetupMass3D_loc; + problem_data->setup_error = SetupError3D; + problem_data->setup_error_loc = SetupError3D_loc; // ------------------------------------------------------ // Command line Options diff --git a/examples/Hdiv-mass/qfunctions/poisson-error2d.h b/examples/Hdiv-mass/qfunctions/poisson-error2d.h index ad80fe4be4..f48574f93c 100644 --- a/examples/Hdiv-mass/qfunctions/poisson-error2d.h +++ b/examples/Hdiv-mass/qfunctions/poisson-error2d.h @@ -21,38 +21,37 @@ #define ERROR2D_H #include + #include "utils.h" // ----------------------------------------------------------------------------- // Compuet error // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupError2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupError2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1], - (*target) = in[2], (*w) = in[3]; + const CeedScalar(*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0], (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1], + (*target) = in[2], (*w) = in[3]; // Outputs - CeedScalar (*error) = out[0]; + CeedScalar(*error) = out[0]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i + #include "utils.h" // ----------------------------------------------------------------------------- // Compuet error // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupError3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupError3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1], - (*target) = in[2], (*w) = in[3]; + const CeedScalar(*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0], (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1], + (*target) = in[2], (*w) = in[3]; // Outputs - CeedScalar (*error) = out[0]; + CeedScalar(*error) = out[0]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i + #include "utils.h" // ----------------------------------------------------------------------------- // This QFunction applies the mass operator for a vector field of 2 components. @@ -35,28 +36,27 @@ // Note we need to apply Piola map on the basis, which is J*u/detJ // So (v,u) = \int (v^T * u detJ*w) ==> \int (v^T J^T*J*u*w/detJ) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupMass2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupMass2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; // *INDENT-ON* // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i + #include "utils.h" // ----------------------------------------------------------------------------- // This QFunction applies the mass operator for a vector field of 2 components. @@ -35,43 +36,42 @@ // Note we need to apply Piola map on the basis, which is J*u/detJ // So (v,u) = \int (v^T * u detJ*w) ==> \int (v^T J^T*J*u*w/detJ) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupMass3D)(void *ctx, CeedInt Q, const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupMass3D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; // *INDENT-ON* // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i + #include "utils.h" #ifndef M_PI -#define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846 #endif // ----------------------------------------------------------------------------- // This QFunction sets up the rhs and true solution for the problem @@ -40,41 +41,38 @@ // Note we need to apply Piola map on the basis, which is J*u/detJ // So (v,ue) = \int (v^T * ue detJ*w) ==> \int (v^T J^T* ue * w) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupRhs2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupRhs2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0], - (*w) = in[1], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[2]; + const CeedScalar(*coords) = in[0], (*w) = in[1], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[2]; // Outputs - //CeedScalar (*rhs)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; - CeedScalar (*true_soln) = out[0], (*rhs) = out[1]; + // CeedScalar (*rhs)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*true_soln) = out[0], (*rhs) = out[1]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i + #include "utils.h" #ifndef M_PI -#define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846 #endif // ----------------------------------------------------------------------------- // This QFunction sets up the rhs and true solution for the problem @@ -39,46 +40,41 @@ // Note we need to apply Piola map on the basis, which is J*u/detJ // So (v,ue) = \int (v^T * ue detJ*w) ==> \int (v^T J^T* ue * w) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(SetupRhs3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(SetupRhs3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0], - (*w) = in[1], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; + const CeedScalar(*coords) = in[0], (*w) = in[1], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; // Outputs - //CeedScalar (*rhs)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; - CeedScalar (*true_soln) = out[0], (*rhs) = out[1]; + // CeedScalar (*rhs)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*true_soln) = out[0], (*rhs) = out[1]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i +#include "ceed/ceed-f64.h" + #define PI_DOUBLE 3.14159265358979323846 // ----------------------------------------------------------------------------- // Compute alpha * A * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { +CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { for (CeedInt j = 0; j < 3; j++) { for (CeedInt k = 0; k < 3; k++) { C[j][k] = 0; @@ -29,8 +29,8 @@ CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A^T * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar B[3][3], + CeedScalar C[3][3]) { for (CeedInt j = 0; j < 3; j++) { for (CeedInt k = 0; k < 3; k++) { C[j][k] = 0; @@ -48,26 +48,24 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- CEED_QFUNCTION_HELPER CeedScalar MatDet3x3(const CeedScalar A[3][3]) { // Compute det(A) - const CeedScalar B11 = A[1][1]*A[2][2] - A[1][2]*A[2][1]; - const CeedScalar B12 = A[0][2]*A[2][1] - A[0][1]*A[2][2]; - const CeedScalar B13 = A[0][1]*A[1][2] - A[0][2]*A[1][1]; - return A[0][0]*B11 + A[1][0]*B12 + A[2][0]*B13; - + const CeedScalar B11 = A[1][1] * A[2][2] - A[1][2] * A[2][1]; + const CeedScalar B12 = A[0][2] * A[2][1] - A[0][1] * A[2][2]; + const CeedScalar B13 = A[0][1] * A[1][2] - A[0][2] * A[1][1]; + return A[0][0] * B11 + A[1][0] * B12 + A[2][0] * B13; }; // ----------------------------------------------------------------------------- // Compute inverse of 3x3 symmetric matrix // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], - const CeedScalar det_A, CeedScalar A_inv[3][3]) { +CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], const CeedScalar det_A, CeedScalar A_inv[3][3]) { // Compute A^(-1) : A-Inverse CeedScalar B[6] = { - A[1][1] * A[2][2] - A[1][2] * A[2][1], /* *NOPAD* */ - A[0][0] * A[2][2] - A[0][2] * A[2][0], /* *NOPAD* */ - A[0][0] * A[1][1] - A[0][1] * A[1][0], /* *NOPAD* */ - A[0][2] * A[1][0] - A[0][0] * A[1][2], /* *NOPAD* */ - A[0][1] * A[1][2] - A[0][2] * A[1][1], /* *NOPAD* */ - A[0][2] * A[2][1] - A[0][1] * A[2][2] /* *NOPAD* */ + A[1][1] * A[2][2] - A[1][2] * A[2][1], /* *NOPAD* */ + A[0][0] * A[2][2] - A[0][2] * A[2][0], /* *NOPAD* */ + A[0][0] * A[1][1] - A[0][1] * A[1][0], /* *NOPAD* */ + A[0][2] * A[1][0] - A[0][0] * A[1][2], /* *NOPAD* */ + A[0][1] * A[1][2] - A[0][2] * A[1][1], /* *NOPAD* */ + A[0][2] * A[2][1] - A[0][1] * A[2][2] /* *NOPAD* */ }; CeedScalar A_inv1[6]; for (CeedInt m = 0; m < 6; m++) { @@ -88,13 +86,11 @@ CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { +CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { // Compute v = alpha*A*u for (CeedInt k = 0; k < 3; k++) { v[k] = 0; - for (CeedInt m = 0; m < 3; m++) - v[k] += A[k][m] * u[m] * alpha; + for (CeedInt m = 0; m < 3; m++) v[k] += A[k][m] * u[m] * alpha; } return 0; @@ -103,13 +99,11 @@ CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A^T*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { // Compute v = alpha*A^T*u for (CeedInt k = 0; k < 3; k++) { v[k] = 0; - for (CeedInt m = 0; m < 3; m++) - v[k] += A[m][k] * u[m] * alpha; + for (CeedInt m = 0; m < 3; m++) v[k] += A[m][k] * u[m] * alpha; } return 0; @@ -118,8 +112,7 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { +CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { for (CeedInt j = 0; j < 2; j++) { for (CeedInt k = 0; k < 2; k++) { C[j][k] = 0; @@ -135,8 +128,8 @@ CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A^T * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar B[2][2], + CeedScalar C[2][2]) { for (CeedInt j = 0; j < 2; j++) { for (CeedInt k = 0; k < 2; k++) { C[j][k] = 0; @@ -154,20 +147,18 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- CEED_QFUNCTION_HELPER CeedScalar MatDet2x2(const CeedScalar A[2][2]) { // Compute det(A) - return A[0][0]*A[1][1] - A[1][0]*A[0][1]; - + return A[0][0] * A[1][1] - A[1][0] * A[0][1]; }; // ----------------------------------------------------------------------------- // Compute inverse of 2x2 symmetric matrix // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], - const CeedScalar det_A, CeedScalar A_inv[2][2]) { +CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], const CeedScalar det_A, CeedScalar A_inv[2][2]) { // Compute A^(-1) : A-Inverse - A_inv[0][0] = A[1][1]/ det_A; - A_inv[0][1] = -A[0][1]/ det_A; - A_inv[1][0] = -A[1][0]/ det_A; - A_inv[1][1] = A[0][0]/ det_A; + A_inv[0][0] = A[1][1] / det_A; + A_inv[0][1] = -A[0][1] / det_A; + A_inv[1][0] = -A[1][0] / det_A; + A_inv[1][1] = A[0][0] / det_A; return 0; }; @@ -175,13 +166,11 @@ CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { +CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { // Compute v = alpha*A*u for (CeedInt k = 0; k < 2; k++) { v[k] = 0; - for (CeedInt m = 0; m < 2; m++) - v[k] += A[k][m] * u[m] * alpha; + for (CeedInt m = 0; m < 2; m++) v[k] += A[k][m] * u[m] * alpha; } return 0; @@ -190,13 +179,11 @@ CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A^T*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { // Compute v = alpha*A^T*u for (CeedInt k = 0; k < 2; k++) { v[k] = 0; - for (CeedInt m = 0; m < 2; m++) - v[k] += A[m][k] * u[m] * alpha; + for (CeedInt m = 0; m < 2; m++) v[k] += A[m][k] * u[m] * alpha; } return 0; diff --git a/examples/Hdiv-mass/src/cl-options.c b/examples/Hdiv-mass/src/cl-options.c index 250d96d79a..105de000df 100644 --- a/examples/Hdiv-mass/src/cl-options.c +++ b/examples/Hdiv-mass/src/cl-options.c @@ -18,19 +18,20 @@ /// Command line option processing for H(div) example using PETSc #include "../include/cl-options.h" + #include "../include/problems.h" // Register problems to be available on the command line PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx) { app_ctx->problems = NULL; - PetscErrorCode ierr; + PetscErrorCode ierr; PetscFunctionBeginUser; // 1) poisson-quad2d (Hdiv_POISSON_MASS2D is created in poisson-mass2d.c) - ierr = PetscFunctionListAdd(&app_ctx->problems, "mass2d", - Hdiv_POISSON_MASS2D); CHKERRQ(ierr); + ierr = PetscFunctionListAdd(&app_ctx->problems, "mass2d", Hdiv_POISSON_MASS2D); + CHKERRQ(ierr); // 2) poisson-hex3d - ierr = PetscFunctionListAdd(&app_ctx->problems, "mass3d", - Hdiv_POISSON_MASS3D); CHKERRQ(ierr); + ierr = PetscFunctionListAdd(&app_ctx->problems, "mass3d", Hdiv_POISSON_MASS3D); + CHKERRQ(ierr); // 3) poisson-prism3d @@ -41,26 +42,23 @@ PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx) { // Process general command line options PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx) { - - PetscBool problem_flag = PETSC_FALSE; + PetscBool problem_flag = PETSC_FALSE; PetscErrorCode ierr; PetscFunctionBeginUser; - PetscOptionsBegin(comm, NULL, - "H(div) examples in PETSc with libCEED", NULL); + PetscOptionsBegin(comm, NULL, "H(div) examples in PETSc with libCEED", NULL); - ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, - app_ctx->problems, - app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), - &problem_flag); CHKERRQ(ierr); + ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, app_ctx->problems, app_ctx->problem_name, app_ctx->problem_name, + sizeof(app_ctx->problem_name), &problem_flag); + CHKERRQ(ierr); app_ctx->degree = 1; - ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", - NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr); + ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", NULL, app_ctx->degree, &app_ctx->degree, NULL); + CHKERRQ(ierr); app_ctx->q_extra = 0; - ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", - NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr); + ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); + CHKERRQ(ierr); // Provide default problem if not specified if (!problem_flag) { diff --git a/examples/Hdiv-mass/src/matops.c b/examples/Hdiv-mass/src/matops.c index 5a31719a35..45c39f0160 100644 --- a/examples/Hdiv-mass/src/matops.c +++ b/examples/Hdiv-mass/src/matops.c @@ -1,4 +1,5 @@ #include "../include/matops.h" + #include "../include/setup-libceed.h" // ----------------------------------------------------------------------------- @@ -7,35 +8,39 @@ // ----------------------------------------------------------------------------- PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) { PetscErrorCode ierr; - PetscScalar *x, *y; - PetscMemType x_mem_type, y_mem_type; + PetscScalar *x, *y; + PetscMemType x_mem_type, y_mem_type; PetscFunctionBeginUser; // Global-to-local - ierr = DMGlobalToLocal(user->dm, X, INSERT_VALUES, user->X_loc); CHKERRQ(ierr); + ierr = DMGlobalToLocal(user->dm, X, INSERT_VALUES, user->X_loc); + CHKERRQ(ierr); // Setup libCEED vectors - ierr = VecGetArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x, - &x_mem_type); CHKERRQ(ierr); - ierr = VecGetArrayAndMemType(user->Y_loc, &y, &y_mem_type); CHKERRQ(ierr); + ierr = VecGetArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x, &x_mem_type); + CHKERRQ(ierr); + ierr = VecGetArrayAndMemType(user->Y_loc, &y, &y_mem_type); + CHKERRQ(ierr); CeedVectorSetArray(user->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x); CeedVectorSetArray(user->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y); // Apply libCEED operator - CeedOperatorApply(user->op_apply, user->x_ceed, user->y_ceed, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(user->op_apply, user->x_ceed, user->y_ceed, CEED_REQUEST_IMMEDIATE); // Restore PETSc vectors CeedVectorTakeArray(user->x_ceed, MemTypeP2C(x_mem_type), NULL); CeedVectorTakeArray(user->y_ceed, MemTypeP2C(y_mem_type), NULL); ierr = VecRestoreArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x); CHKERRQ(ierr); - ierr = VecRestoreArrayAndMemType(user->Y_loc, &y); CHKERRQ(ierr); + ierr = VecRestoreArrayAndMemType(user->Y_loc, &y); + CHKERRQ(ierr); // Local-to-global - ierr = VecZeroEntries(Y); CHKERRQ(ierr); - ierr = DMLocalToGlobal(user->dm, user->Y_loc, ADD_VALUES, Y); CHKERRQ(ierr); + ierr = VecZeroEntries(Y); + CHKERRQ(ierr); + ierr = DMLocalToGlobal(user->dm, user->Y_loc, ADD_VALUES, Y); + CHKERRQ(ierr); PetscFunctionReturn(0); }; @@ -45,14 +50,16 @@ PetscErrorCode ApplyLocal_Ceed(User user, Vec X, Vec Y) { // ----------------------------------------------------------------------------- PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y) { PetscErrorCode ierr; - User user; + User user; PetscFunctionBeginUser; - ierr = MatShellGetContext(A, &user); CHKERRQ(ierr); + ierr = MatShellGetContext(A, &user); + CHKERRQ(ierr); // libCEED for local action of residual evaluator - ierr = ApplyLocal_Ceed(user, X, Y); CHKERRQ(ierr); + ierr = ApplyLocal_Ceed(user, X, Y); + CHKERRQ(ierr); PetscFunctionReturn(0); }; @@ -60,28 +67,28 @@ PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y) { // ----------------------------------------------------------------------------- // This function calculates the error in the final solution // ----------------------------------------------------------------------------- -PetscErrorCode ComputeError(User user, Vec X, CeedVector target, - CeedScalar *l2_error) { +PetscErrorCode ComputeError(User user, Vec X, CeedVector target, CeedScalar *l2_error) { PetscErrorCode ierr; - PetscScalar *x; - PetscMemType mem_type; - CeedVector collocated_error; - CeedSize length; + PetscScalar *x; + PetscMemType mem_type; + CeedVector collocated_error; + CeedSize length; PetscFunctionBeginUser; CeedVectorGetLength(target, &length); CeedVectorCreate(user->ceed, length, &collocated_error); // Global-to-local - ierr = DMGlobalToLocal(user->dm, X, INSERT_VALUES, user->X_loc); CHKERRQ(ierr); + ierr = DMGlobalToLocal(user->dm, X, INSERT_VALUES, user->X_loc); + CHKERRQ(ierr); // Setup CEED vector - ierr = VecGetArrayAndMemType(user->X_loc, &x, &mem_type); CHKERRQ(ierr); + ierr = VecGetArrayAndMemType(user->X_loc, &x, &mem_type); + CHKERRQ(ierr); CeedVectorSetArray(user->x_ceed, MemTypeP2C(mem_type), CEED_USE_POINTER, x); // Apply CEED operator - CeedOperatorApply(user->op_error, user->x_ceed, collocated_error, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(user->op_error, user->x_ceed, collocated_error, CEED_REQUEST_IMMEDIATE); // Restore PETSc vector CeedVectorTakeArray(user->x_ceed, MemTypeP2C(mem_type), NULL); ierr = VecRestoreArrayReadAndMemType(user->X_loc, (const PetscScalar **)&x); diff --git a/examples/Hdiv-mass/src/setup-dm.c b/examples/Hdiv-mass/src/setup-dm.c index 7023fdbe6d..a48ee93606 100644 --- a/examples/Hdiv-mass/src/setup-dm.c +++ b/examples/Hdiv-mass/src/setup-dm.c @@ -3,47 +3,66 @@ // --------------------------------------------------------------------------- // Set-up DM // --------------------------------------------------------------------------- -PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data, - DM *dm) { - PetscErrorCode ierr; +PetscErrorCode CreateDistributedDM(MPI_Comm comm, ProblemData *problem_data, DM *dm) { + PetscErrorCode ierr; PetscSection sec; PetscInt dofs_per_face; PetscInt p_start, p_end; - PetscInt c_start, c_end; // cells - PetscInt f_start, f_end; // faces - PetscInt v_start, v_end; // vertices + PetscInt c_start, c_end; // cells + PetscInt f_start, f_end; // faces + PetscInt v_start, v_end; // vertices PetscFunctionBeginUser; // Create DMPLEX - ierr = DMCreate(comm, dm); CHKERRQ(ierr); - ierr = DMSetType(*dm, DMPLEX); CHKERRQ(ierr); + ierr = DMCreate(comm, dm); + CHKERRQ(ierr); + ierr = DMSetType(*dm, DMPLEX); + CHKERRQ(ierr); // Set Tensor elements - ierr = PetscOptionsSetValue(NULL, "-dm_plex_simplex", "0"); CHKERRQ(ierr); + ierr = PetscOptionsSetValue(NULL, "-dm_plex_simplex", "0"); + CHKERRQ(ierr); // Set CL options - ierr = DMSetFromOptions(*dm); CHKERRQ(ierr); - ierr = DMViewFromOptions(*dm, NULL, "-dm_view"); CHKERRQ(ierr); + ierr = DMSetFromOptions(*dm); + CHKERRQ(ierr); + ierr = DMViewFromOptions(*dm, NULL, "-dm_view"); + CHKERRQ(ierr); // Get plex limits - ierr = DMPlexGetChart(*dm, &p_start, &p_end); CHKERRQ(ierr); - ierr = DMPlexGetHeightStratum(*dm, 0, &c_start, &c_end); CHKERRQ(ierr); - ierr = DMPlexGetHeightStratum(*dm, 1, &f_start, &f_end); CHKERRQ(ierr); - ierr = DMPlexGetDepthStratum(*dm, 0, &v_start, &v_end); CHKERRQ(ierr); + ierr = DMPlexGetChart(*dm, &p_start, &p_end); + CHKERRQ(ierr); + ierr = DMPlexGetHeightStratum(*dm, 0, &c_start, &c_end); + CHKERRQ(ierr); + ierr = DMPlexGetHeightStratum(*dm, 1, &f_start, &f_end); + CHKERRQ(ierr); + ierr = DMPlexGetDepthStratum(*dm, 0, &v_start, &v_end); + CHKERRQ(ierr); // Create section - ierr = PetscSectionCreate(comm, &sec); CHKERRQ(ierr); - ierr = PetscSectionSetNumFields(sec,1); CHKERRQ(ierr); - ierr = PetscSectionSetFieldName(sec,0,"Velocity"); CHKERRQ(ierr); - ierr = PetscSectionSetFieldComponents(sec,0,1); CHKERRQ(ierr); - ierr = PetscSectionSetChart(sec,p_start,p_end); CHKERRQ(ierr); + ierr = PetscSectionCreate(comm, &sec); + CHKERRQ(ierr); + ierr = PetscSectionSetNumFields(sec, 1); + CHKERRQ(ierr); + ierr = PetscSectionSetFieldName(sec, 0, "Velocity"); + CHKERRQ(ierr); + ierr = PetscSectionSetFieldComponents(sec, 0, 1); + CHKERRQ(ierr); + ierr = PetscSectionSetChart(sec, p_start, p_end); + CHKERRQ(ierr); // Setup dofs per face for (PetscInt f = f_start; f < f_end; f++) { - ierr = DMPlexGetConeSize(*dm, f, &dofs_per_face); CHKERRQ(ierr); - ierr = PetscSectionSetFieldDof(sec, f, 0, dofs_per_face); CHKERRQ(ierr); - ierr = PetscSectionSetDof (sec, f, dofs_per_face); CHKERRQ(ierr); + ierr = DMPlexGetConeSize(*dm, f, &dofs_per_face); + CHKERRQ(ierr); + ierr = PetscSectionSetFieldDof(sec, f, 0, dofs_per_face); + CHKERRQ(ierr); + ierr = PetscSectionSetDof(sec, f, dofs_per_face); + CHKERRQ(ierr); } - ierr = PetscSectionSetUp(sec); CHKERRQ(ierr); - ierr = DMSetSection(*dm,sec); CHKERRQ(ierr); - ierr = PetscSectionDestroy(&sec); CHKERRQ(ierr); + ierr = PetscSectionSetUp(sec); + CHKERRQ(ierr); + ierr = DMSetSection(*dm, sec); + CHKERRQ(ierr); + ierr = PetscSectionDestroy(&sec); + CHKERRQ(ierr); PetscFunctionReturn(0); }; \ No newline at end of file diff --git a/examples/Hdiv-mass/src/setup-libceed.c b/examples/Hdiv-mass/src/setup-libceed.c index 767ceca67a..fd5c29b7b6 100644 --- a/examples/Hdiv-mass/src/setup-libceed.c +++ b/examples/Hdiv-mass/src/setup-libceed.c @@ -1,14 +1,13 @@ #include "../include/setup-libceed.h" -#include "../include/petsc-macros.h" -#include "../basis/Hdiv-quad.h" + #include "../basis/Hdiv-hex.h" +#include "../basis/Hdiv-quad.h" +#include "../include/petsc-macros.h" // ----------------------------------------------------------------------------- // Convert PETSc MemType to libCEED MemType // ----------------------------------------------------------------------------- -CeedMemType MemTypeP2C(PetscMemType mem_type) { - return PetscMemTypeDevice(mem_type) ? CEED_MEM_DEVICE : CEED_MEM_HOST; -} +CeedMemType MemTypeP2C(PetscMemType mem_type) { return PetscMemTypeDevice(mem_type) ? CEED_MEM_DEVICE : CEED_MEM_HOST; } // ----------------------------------------------------------------------------- // Destroy libCEED objects // ----------------------------------------------------------------------------- @@ -33,7 +32,8 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data) { // Operators CeedOperatorDestroy(&ceed_data->op_residual); CeedOperatorDestroy(&ceed_data->op_error); - ierr = PetscFree(ceed_data); CHKERRQ(ierr); + ierr = PetscFree(ceed_data); + CHKERRQ(ierr); PetscFunctionReturn(0); }; @@ -41,28 +41,23 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data) { // ----------------------------------------------------------------------------- // Utility function - essential BC dofs are encoded in closure indices as -(i+1) // ----------------------------------------------------------------------------- -PetscInt Involute(PetscInt i) { - return i >= 0 ? i : -(i + 1); -}; +PetscInt Involute(PetscInt i) { return i >= 0 ? i : -(i + 1); }; // ----------------------------------------------------------------------------- // Get CEED restriction data from DMPlex // ----------------------------------------------------------------------------- -PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, - DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { - PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; +PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { + PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; PetscErrorCode ierr; PetscFunctionBeginUser; - ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, - &elem_size, &num_comp, &num_dof, &elem_restr_offsets); + ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, &elem_size, &num_comp, &num_dof, &elem_restr_offsets); CHKERRQ(ierr); - CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, - 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, - elem_restr_offsets, elem_restr); - ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr); + CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, elem_restr_offsets, elem_restr); + ierr = PetscFree(elem_restr_offsets); + CHKERRQ(ierr); PetscFunctionReturn(0); }; @@ -70,182 +65,176 @@ PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, // ----------------------------------------------------------------------------- // Get Oriented CEED restriction data from DMPlex // ----------------------------------------------------------------------------- -PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, - CeedInt P, CeedElemRestriction *elem_restr_oriented) { - PetscSection section; - PetscInt p, num_elem, num_dof, *restr_indices, elem_offset, num_fields, - dim, c_start, c_end; - Vec U_loc; - PetscErrorCode ierr; - const PetscInt *ornt; // this is for orientation of dof +PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, CeedInt P, CeedElemRestriction *elem_restr_oriented) { + PetscSection section; + PetscInt p, num_elem, num_dof, *restr_indices, elem_offset, num_fields, dim, c_start, c_end; + Vec U_loc; + PetscErrorCode ierr; + const PetscInt *ornt; // this is for orientation of dof PetscFunctionBeginUser; - ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); - ierr = DMGetLocalSection(dm, §ion); CHKERRQ(ierr); - ierr = PetscSectionGetNumFields(section, &num_fields); CHKERRQ(ierr); - PetscInt num_comp[num_fields], field_offsets[num_fields+1]; + ierr = DMGetDimension(dm, &dim); + CHKERRQ(ierr); + ierr = DMGetLocalSection(dm, §ion); + CHKERRQ(ierr); + ierr = PetscSectionGetNumFields(section, &num_fields); + CHKERRQ(ierr); + PetscInt num_comp[num_fields], field_offsets[num_fields + 1]; field_offsets[0] = 0; for (PetscInt f = 0; f < num_fields; f++) { - ierr = PetscSectionGetFieldComponents(section, f, &num_comp[f]); CHKERRQ(ierr); - field_offsets[f+1] = field_offsets[f] + num_comp[f]; + ierr = PetscSectionGetFieldComponents(section, f, &num_comp[f]); + CHKERRQ(ierr); + field_offsets[f + 1] = field_offsets[f] + num_comp[f]; } - ierr = DMPlexGetHeightStratum(dm, 0, &c_start, &c_end); CHKERRQ(ierr); + ierr = DMPlexGetHeightStratum(dm, 0, &c_start, &c_end); + CHKERRQ(ierr); num_elem = c_end - c_start; - ierr = PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), - &restr_indices); CHKERRQ(ierr); - bool *orient_indices; // to flip the dof - ierr = PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), &orient_indices); + ierr = PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &restr_indices); + CHKERRQ(ierr); + bool *orient_indices; // to flip the dof + ierr = PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &orient_indices); CHKERRQ(ierr); for (p = 0, elem_offset = 0; p < num_elem; p++) { PetscInt num_indices, *indices, faces_per_elem, dofs_per_face; - ierr = DMPlexGetClosureIndices(dm, section, section, p, PETSC_TRUE, - &num_indices, &indices, NULL, NULL); + ierr = DMPlexGetClosureIndices(dm, section, section, p, PETSC_TRUE, &num_indices, &indices, NULL, NULL); CHKERRQ(ierr); - ierr = DMPlexGetConeOrientation(dm, p, &ornt); CHKERRQ(ierr); + ierr = DMPlexGetConeOrientation(dm, p, &ornt); + CHKERRQ(ierr); // Get number of faces per element - ierr = DMPlexGetConeSize(dm, p, &faces_per_elem); CHKERRQ(ierr); + ierr = DMPlexGetConeSize(dm, p, &faces_per_elem); + CHKERRQ(ierr); dofs_per_face = faces_per_elem - 2; for (PetscInt f = 0; f < faces_per_elem; f++) { for (PetscInt i = 0; i < dofs_per_face; i++) { - PetscInt ii = dofs_per_face*f + i; + PetscInt ii = dofs_per_face * f + i; // Essential boundary conditions are encoded as -(loc+1), but we don't care so we decode. - PetscInt loc = Involute(indices[ii*num_comp[0]]); + PetscInt loc = Involute(indices[ii * num_comp[0]]); restr_indices[elem_offset] = loc; // Set orientation orient_indices[elem_offset] = ornt[f] < 0; elem_offset++; } } - ierr = DMPlexRestoreClosureIndices(dm, section, section, p, PETSC_TRUE, - &num_indices, &indices, NULL, NULL); + ierr = DMPlexRestoreClosureIndices(dm, section, section, p, PETSC_TRUE, &num_indices, &indices, NULL, NULL); CHKERRQ(ierr); } - //if (elem_offset != num_elem*dim*PetscPowInt(P, dim)) - // SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_LIB, - // "ElemRestriction of size (%" PetscInt_FMT ",%" PetscInt_FMT ") - // initialized %" PetscInt_FMT "nodes", num_elem, - // dim*PetscPowInt(P, dim),elem_offset); - ierr = DMGetLocalVector(dm, &U_loc); CHKERRQ(ierr); - ierr = VecGetLocalSize(U_loc, &num_dof); CHKERRQ(ierr); - ierr = DMRestoreLocalVector(dm, &U_loc); CHKERRQ(ierr); + // if (elem_offset != num_elem*dim*PetscPowInt(P, dim)) + // SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_LIB, + // "ElemRestriction of size (%" PetscInt_FMT ",%" PetscInt_FMT ") + // initialized %" PetscInt_FMT "nodes", num_elem, + // dim*PetscPowInt(P, dim),elem_offset); + ierr = DMGetLocalVector(dm, &U_loc); + CHKERRQ(ierr); + ierr = VecGetLocalSize(U_loc, &num_dof); + CHKERRQ(ierr); + ierr = DMRestoreLocalVector(dm, &U_loc); + CHKERRQ(ierr); // dof per element in Hdiv is dim*P^dim, for linear element P=2 - CeedElemRestrictionCreateOriented(ceed, num_elem, dim*PetscPowInt(P, dim), - field_offsets[num_fields], - 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, - restr_indices, orient_indices, - elem_restr_oriented); - ierr = PetscFree(restr_indices); CHKERRQ(ierr); - ierr = PetscFree(orient_indices); CHKERRQ(ierr); + CeedElemRestrictionCreateOriented(ceed, num_elem, dim * PetscPowInt(P, dim), field_offsets[num_fields], 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, + restr_indices, orient_indices, elem_restr_oriented); + ierr = PetscFree(restr_indices); + CHKERRQ(ierr); + ierr = PetscFree(orient_indices); + CHKERRQ(ierr); PetscFunctionReturn(0); }; // ----------------------------------------------------------------------------- // Set up libCEED on the fine grid for a given degree // ----------------------------------------------------------------------------- -PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, - ProblemData *problem_data, PetscInt U_g_size, - PetscInt U_loc_size, CeedData ceed_data, +PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, ProblemData *problem_data, PetscInt U_g_size, PetscInt U_loc_size, CeedData ceed_data, CeedVector rhs_ceed, CeedVector *target) { - int ierr; - CeedInt P = app_ctx->degree + 1; + int ierr; + CeedInt P = app_ctx->degree + 1; // Number of quadratures in 1D, q_extra is set in cl-options.c - CeedInt Q = P + 1 + app_ctx->q_extra; - CeedInt dim, num_comp_x, num_comp_u; - //CeedInt elem_node = problem_data->elem_node; - DM dm_coord; - Vec coords; - PetscInt c_start, c_end, num_elem; + CeedInt Q = P + 1 + app_ctx->q_extra; + CeedInt dim, num_comp_x, num_comp_u; + // CeedInt elem_node = problem_data->elem_node; + DM dm_coord; + Vec coords; + PetscInt c_start, c_end, num_elem; const PetscScalar *coordArray; - CeedVector x_coord; - CeedQFunction qf_setup_rhs, qf_residual, qf_error; - CeedOperator op_setup_rhs, op_residual, op_error; + CeedVector x_coord; + CeedQFunction qf_setup_rhs, qf_residual, qf_error; + CeedOperator op_setup_rhs, op_residual, op_error; PetscFunctionBeginUser; // --------------------------------------------------------------------------- // libCEED bases:Hdiv basis_u and Lagrange basis_x // --------------------------------------------------------------------------- - dim = problem_data->dim; + dim = problem_data->dim; num_comp_x = dim; - num_comp_u = 1; // one vector dof + num_comp_u = 1; // one vector dof // Number of quadratures per element - CeedInt num_qpts = PetscPowInt(Q, dim); - CeedInt P_u = dim*PetscPowInt(P, dim); // dof per element - CeedScalar q_ref[dim*num_qpts], q_weights[num_qpts]; - CeedScalar div[P_u*num_qpts], interp[dim*P_u*num_qpts]; + CeedInt num_qpts = PetscPowInt(Q, dim); + CeedInt P_u = dim * PetscPowInt(P, dim); // dof per element + CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts]; + CeedScalar div[P_u * num_qpts], interp[dim * P_u * num_qpts]; if (dim == 2) { HdivBasisQuad(Q, q_ref, q_weights, interp, div, problem_data->quadrature_mode); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, - interp, div, q_ref, q_weights, &ceed_data->basis_u); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, interp, div, q_ref, q_weights, &ceed_data->basis_u); } else { HdivBasisHex(Q, q_ref, q_weights, interp, div, problem_data->quadrature_mode); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, - interp, div, q_ref, q_weights, &ceed_data->basis_u); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, interp, div, q_ref, q_weights, &ceed_data->basis_u); } - CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, - problem_data->quadrature_mode, &ceed_data->basis_x); + CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, problem_data->quadrature_mode, &ceed_data->basis_x); // --------------------------------------------------------------------------- // libCEED restrictions // --------------------------------------------------------------------------- - ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); + ierr = DMGetCoordinateDM(dm, &dm_coord); + CHKERRQ(ierr); ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); CHKERRQ(ierr); - CeedInt height = 0; // 0 means no boundary conditions - DMLabel domain_label = 0; - PetscInt value = 0; + CeedInt height = 0; // 0 means no boundary conditions + DMLabel domain_label = 0; + PetscInt value = 0; // -- Coordinate restriction - ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, - value, &ceed_data->elem_restr_x); CHKERRQ(ierr); + ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, &ceed_data->elem_restr_x); + CHKERRQ(ierr); // -- Solution and projected true solution restriction - ierr = CreateRestrictionFromPlexOriented(ceed, dm, - P, &ceed_data->elem_restr_u); + ierr = CreateRestrictionFromPlexOriented(ceed, dm, P, &ceed_data->elem_restr_u); CHKERRQ(ierr); // -- Geometric ceed_data restriction - ierr = DMPlexGetHeightStratum(dm, 0, &c_start, &c_end); CHKERRQ(ierr); + ierr = DMPlexGetHeightStratum(dm, 0, &c_start, &c_end); + CHKERRQ(ierr); num_elem = c_end - c_start; - CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, dim, - dim*num_elem*num_qpts, - CEED_STRIDES_BACKEND, &ceed_data->elem_restr_u_i); + CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, dim, dim * num_elem * num_qpts, CEED_STRIDES_BACKEND, &ceed_data->elem_restr_u_i); // --------------------------------------------------------------------------- // Element coordinates // --------------------------------------------------------------------------- - ierr = DMGetCoordinatesLocal(dm, &coords); CHKERRQ(ierr); - ierr = VecGetArrayRead(coords, &coordArray); CHKERRQ(ierr); + ierr = DMGetCoordinatesLocal(dm, &coords); + CHKERRQ(ierr); + ierr = VecGetArrayRead(coords, &coordArray); + CHKERRQ(ierr); CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &x_coord, NULL); - CeedVectorSetArray(x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, - (PetscScalar *)coordArray); - ierr = VecRestoreArrayRead(coords, &coordArray); CHKERRQ(ierr); + CeedVectorSetArray(x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, (PetscScalar *)coordArray); + ierr = VecRestoreArrayRead(coords, &coordArray); + CHKERRQ(ierr); // --------------------------------------------------------------------------- // Setup RHS and true solution // --------------------------------------------------------------------------- - CeedVectorCreate(ceed, num_elem*num_qpts*dim, target); + CeedVectorCreate(ceed, num_elem * num_qpts * dim, target); // Create the q-function that sets up the RHS and true solution - CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_rhs, - problem_data->setup_rhs_loc, &qf_setup_rhs); + CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_rhs, problem_data->setup_rhs_loc, &qf_setup_rhs); CeedQFunctionAddInput(qf_setup_rhs, "x", num_comp_x, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_setup_rhs, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_setup_rhs, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_setup_rhs, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddOutput(qf_setup_rhs, "true_soln", dim, CEED_EVAL_NONE); CeedQFunctionAddOutput(qf_setup_rhs, "rhs", dim, CEED_EVAL_INTERP); // Create the operator that builds the RHS and true solution - CeedOperatorCreate(ceed, qf_setup_rhs, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_setup_rhs); - CeedOperatorSetField(op_setup_rhs, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_rhs, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_rhs, "true_soln", ceed_data->elem_restr_u_i, - CEED_BASIS_COLLOCATED, *target); - CeedOperatorSetField(op_setup_rhs, "rhs", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_setup_rhs, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_setup_rhs); + CeedOperatorSetField(op_setup_rhs, "x", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_setup_rhs, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_setup_rhs, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_setup_rhs, "true_soln", ceed_data->elem_restr_u_i, CEED_BASIS_COLLOCATED, *target); + CeedOperatorSetField(op_setup_rhs, "rhs", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); // Setup RHS and true solution CeedOperatorApply(op_setup_rhs, x_coord, rhs_ceed, CEED_REQUEST_IMMEDIATE); @@ -262,24 +251,18 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, // Create the QFunction and Operator that computes the residual of the PDE. // --------------------------------------------------------------------------- // -- QFunction - CeedQFunctionCreateInterior(ceed, 1, problem_data->residual, - problem_data->residual_loc, &qf_residual); + CeedQFunctionCreateInterior(ceed, 1, problem_data->residual, problem_data->residual_loc, &qf_residual); CeedQFunctionAddInput(qf_residual, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_residual, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_residual, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_residual, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_residual, "v", dim, CEED_EVAL_INTERP); // -- Operator - CeedOperatorCreate(ceed, qf_residual, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_residual); - CeedOperatorSetField(op_residual, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_residual, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, x_coord); - CeedOperatorSetField(op_residual, "u", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "v", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_residual, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_residual); + CeedOperatorSetField(op_residual, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_residual, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, x_coord); + CeedOperatorSetField(op_residual, "u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "v", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_residual = qf_residual; @@ -289,26 +272,19 @@ PetscErrorCode SetupLibceed(DM dm, Ceed ceed, AppCtx app_ctx, // Setup Error Qfunction // --------------------------------------------------------------------------- // Create the q-function that sets up the error - CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_error, - problem_data->setup_error_loc, &qf_error); - CeedQFunctionAddInput(qf_error, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionCreateInterior(ceed, 1, problem_data->setup_error, problem_data->setup_error_loc, &qf_error); + CeedQFunctionAddInput(qf_error, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_error, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_error, "true_soln", dim, CEED_EVAL_NONE); CeedQFunctionAddInput(qf_error, "weight", 1, CEED_EVAL_WEIGHT); CeedQFunctionAddOutput(qf_error, "error", dim, CEED_EVAL_NONE); // Create the operator that builds the error - CeedOperatorCreate(ceed, qf_error, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_error); - CeedOperatorSetField(op_error, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, x_coord); - CeedOperatorSetField(op_error, "u", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_error, "true_soln", ceed_data->elem_restr_u_i, - CEED_BASIS_COLLOCATED, *target); - CeedOperatorSetField(op_error, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_error, "error", ceed_data->elem_restr_u_i, - CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_error, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_error); + CeedOperatorSetField(op_error, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, x_coord); + CeedOperatorSetField(op_error, "u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_error, "true_soln", ceed_data->elem_restr_u_i, CEED_BASIS_COLLOCATED, *target); + CeedOperatorSetField(op_error, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_error, "error", ceed_data->elem_restr_u_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_error = qf_error; ceed_data->op_error = op_error; diff --git a/examples/Hdiv-mixed/basis/Hdiv-hex.h b/examples/Hdiv-mixed/basis/Hdiv-hex.h index e14b873dfb..1777981e11 100644 --- a/examples/Hdiv-mixed/basis/Hdiv-hex.h +++ b/examples/Hdiv-mixed/basis/Hdiv-hex.h @@ -18,119 +18,115 @@ // To see how the nodal basis is constructed visit: // https://github.com/rezgarshakeri/H-div-Tests -int NodalHdivBasisHex(CeedScalar *x, CeedScalar *Bx, CeedScalar *By, - CeedScalar *Bz) { - - Bx[ 0] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 0] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 0] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 1] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 1] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 1] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 2] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 2] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 2] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 3] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 3] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 3] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] + - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bx[ 4] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 4] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 4] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 5] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 5] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] + 0.0625*x[1]*x[1] - 0.0625 ; - Bz[ 5] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 6] = 0.0625*x[0]*x[0] - 0.0625 ; - By[ 6] = 0.0625*x[0]*x[1]*x[1] - 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 6] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 7] = 0.0625 - 0.0625*x[0]*x[0] ; - By[ 7] = -0.0625*x[0]*x[1]*x[1] + 0.0625*x[0] - 0.0625*x[1]*x[1] + 0.0625 ; - Bz[ 7] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bx[ 8] = 0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] - 0.0625*x[2] + 0.0625 ; - By[ 8] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bz[ 8] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[ 9] = -0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] + 0.0625*x[2] - 0.0625 ; - By[ 9] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - Bz[ 9] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[10] = -0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] + 0.0625*x[2] + 0.0625 ; - By[10] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - Bz[10] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[11] = 0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] - 0.0625*x[2] - 0.0625 ; - By[11] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - Bz[11] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[12] = 0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] - 0.0625*x[2] + 0.0625 ; - By[12] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - Bz[12] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[13] = -0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] + 0.0625*x[2] - 0.0625 ; - By[13] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] - 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - Bz[13] = 0.0625*x[2]*x[2] - 0.0625 ; - Bx[14] = -0.0625*x[0]*x[0]*x[2] - 0.0625*x[0]*x[0] + 0.0625*x[2] + 0.0625 ; - By[14] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bz[14] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[15] = 0.0625*x[0]*x[0]*x[2] + 0.0625*x[0]*x[0] - 0.0625*x[2] - 0.0625 ; - By[15] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] - 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - Bz[15] = 0.0625 - 0.0625*x[2]*x[2] ; - Bx[16] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] - 0.125*x[1] - 0.125*x[2] + 0.125 ; - By[16] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[16] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[17] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] + 0.125 ; - By[17] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[17] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[18] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] + 0.125 ; - By[18] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[18] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[19] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] + - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] + 0.125 ; - By[19] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[19] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[20] = 0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] + 0.125*x[1] + 0.125*x[2] - 0.125 ; - By[20] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[20] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[21] = -0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] - 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] - 0.125*x[1] + 0.125*x[2] - 0.125 ; - By[21] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[21] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] + 0.0625*x[2]*x[2] - 0.0625 ; - Bx[22] = -0.125*x[0]*x[1]*x[2] - 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - + 0.125*x[1]*x[2] + 0.125*x[1] - 0.125*x[2] - 0.125 ; - By[22] = 0.0625*x[1]*x[1] - 0.0625 ; - Bz[22] = 0.0625*x[1]*x[2]*x[2] - 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; - Bx[23] = 0.125*x[0]*x[1]*x[2] + 0.125*x[0]*x[1] + 0.125*x[0]*x[2] + 0.125*x[0] - - 0.125*x[1]*x[2] - 0.125*x[1] - 0.125*x[2] - 0.125 ; - By[23] = 0.0625 - 0.0625*x[1]*x[1] ; - Bz[23] = -0.0625*x[1]*x[2]*x[2] + 0.0625*x[1] - 0.0625*x[2]*x[2] + 0.0625 ; +int NodalHdivBasisHex(CeedScalar *x, CeedScalar *Bx, CeedScalar *By, CeedScalar *Bz) { + Bx[0] = 0.0625 * x[0] * x[0] - 0.0625; + By[0] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[0] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[1] = 0.0625 - 0.0625 * x[0] * x[0]; + By[1] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[1] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[2] = 0.0625 * x[0] * x[0] - 0.0625; + By[2] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[2] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[3] = 0.0625 - 0.0625 * x[0] * x[0]; + By[3] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[3] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bx[4] = 0.0625 * x[0] * x[0] - 0.0625; + By[4] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[4] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[5] = 0.0625 - 0.0625 * x[0] * x[0]; + By[5] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] + 0.0625 * x[1] * x[1] - 0.0625; + Bz[5] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[6] = 0.0625 * x[0] * x[0] - 0.0625; + By[6] = 0.0625 * x[0] * x[1] * x[1] - 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[6] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[7] = 0.0625 - 0.0625 * x[0] * x[0]; + By[7] = -0.0625 * x[0] * x[1] * x[1] + 0.0625 * x[0] - 0.0625 * x[1] * x[1] + 0.0625; + Bz[7] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bx[8] = 0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] - 0.0625 * x[2] + 0.0625; + By[8] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bz[8] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[9] = -0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] + 0.0625 * x[2] - 0.0625; + By[9] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + Bz[9] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[10] = -0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] + 0.0625 * x[2] + 0.0625; + By[10] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - 0.125 * x[2] - + 0.125; + Bz[10] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[11] = 0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] - 0.0625 * x[2] - 0.0625; + By[11] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] - 0.125; + Bz[11] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[12] = 0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] - 0.0625 * x[2] + 0.0625; + By[12] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] + 0.125; + Bz[12] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[13] = -0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] + 0.0625 * x[2] - 0.0625; + By[13] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] - 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - 0.125 * x[2] + + 0.125; + Bz[13] = 0.0625 * x[2] * x[2] - 0.0625; + Bx[14] = -0.0625 * x[0] * x[0] * x[2] - 0.0625 * x[0] * x[0] + 0.0625 * x[2] + 0.0625; + By[14] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + Bz[14] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[15] = 0.0625 * x[0] * x[0] * x[2] + 0.0625 * x[0] * x[0] - 0.0625 * x[2] - 0.0625; + By[15] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] - 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + + 0.125 * x[2] + 0.125; + Bz[15] = 0.0625 - 0.0625 * x[2] * x[2]; + Bx[16] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] - 0.125 * x[2] + + 0.125; + By[16] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[16] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[17] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] + 0.125; + By[17] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[17] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[18] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] + + 0.125 * x[2] + 0.125; + By[18] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[18] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[19] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] + + 0.125; + By[19] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[19] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[20] = 0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] + 0.125 * x[1] + 0.125 * x[2] - + 0.125; + By[20] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[20] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[21] = -0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] - 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] - 0.125 * x[1] + + 0.125 * x[2] - 0.125; + By[21] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[21] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] + 0.0625 * x[2] * x[2] - 0.0625; + Bx[22] = -0.125 * x[0] * x[1] * x[2] - 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] + 0.125 * x[1] * x[2] + 0.125 * x[1] - + 0.125 * x[2] - 0.125; + By[22] = 0.0625 * x[1] * x[1] - 0.0625; + Bz[22] = 0.0625 * x[1] * x[2] * x[2] - 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; + Bx[23] = 0.125 * x[0] * x[1] * x[2] + 0.125 * x[0] * x[1] + 0.125 * x[0] * x[2] + 0.125 * x[0] - 0.125 * x[1] * x[2] - 0.125 * x[1] - 0.125 * x[2] - + 0.125; + By[23] = 0.0625 - 0.0625 * x[1] * x[1]; + Bz[23] = -0.0625 * x[1] * x[2] * x[2] + 0.0625 * x[1] - 0.0625 * x[2] * x[2] + 0.0625; return 0; } -static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, - CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) { - +static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) { // Get 1D quadrature on [-1,1] CeedScalar q_ref_1d[Q], q_weight_1d[Q]; switch (quad_mode) { - case CEED_GAUSS: - CeedGaussQuadrature(Q, q_ref_1d, q_weight_1d); - break; - case CEED_GAUSS_LOBATTO: - CeedLobattoQuadrature(Q, q_ref_1d, q_weight_1d); - break; + case CEED_GAUSS: + CeedGaussQuadrature(Q, q_ref_1d, q_weight_1d); + break; + case CEED_GAUSS_LOBATTO: + CeedLobattoQuadrature(Q, q_ref_1d, q_weight_1d); + break; } // Divergence operator; Divergence of nodal basis for ref element @@ -138,27 +134,27 @@ static void HdivBasisHex(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, // Loop over quadrature points CeedScalar Bx[24], By[24], Bz[24]; CeedScalar x[3]; - for (CeedInt k=0; k #include -#include "structs.h" #include "../include/setup-libceed.h" -PetscErrorCode PrintOutput(DM dm, Ceed ceed, AppCtx app_ctx, PetscBool has_ts, - CeedMemType mem_type_backend, - TS ts, SNES snes, KSP ksp, - Vec U, CeedScalar l2_error_u, - CeedScalar l2_error_p); -PetscErrorCode SetupProjectVelocityCtx_Hdiv(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, OperatorApplyContext ctx_Hdiv); -PetscErrorCode SetupProjectVelocityCtx_H1(MPI_Comm comm, DM dm_H1, Ceed ceed, - CeedData ceed_data, VecType vec_type, OperatorApplyContext ctx_H1); -PetscErrorCode ProjectVelocity(AppCtx app_ctx, - Vec U, Vec *U_H1); +#include "structs.h" +PetscErrorCode PrintOutput(DM dm, Ceed ceed, AppCtx app_ctx, PetscBool has_ts, CeedMemType mem_type_backend, TS ts, SNES snes, KSP ksp, Vec U, + CeedScalar l2_error_u, CeedScalar l2_error_p); +PetscErrorCode SetupProjectVelocityCtx_Hdiv(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_Hdiv); +PetscErrorCode SetupProjectVelocityCtx_H1(MPI_Comm comm, DM dm_H1, Ceed ceed, CeedData ceed_data, VecType vec_type, OperatorApplyContext ctx_H1); +PetscErrorCode ProjectVelocity(AppCtx app_ctx, Vec U, Vec *U_H1); PetscErrorCode CtxVecDestroy(AppCtx app_ctx); -#endif // post_processing_h +#endif // post_processing_h diff --git a/examples/Hdiv-mixed/include/register-problem.h b/examples/Hdiv-mixed/include/register-problem.h index 9d54e26794..88e4b2a34a 100644 --- a/examples/Hdiv-mixed/include/register-problem.h +++ b/examples/Hdiv-mixed/include/register-problem.h @@ -9,22 +9,18 @@ PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx); // Set up problems function prototype // ----------------------------------------------------------------------------- // 1) darcy2d -PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx); +PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx); // 2) darcy3d -PetscErrorCode Hdiv_DARCY3D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx); +PetscErrorCode Hdiv_DARCY3D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx); // 3) darcy3dprism // 4) richard -PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx); +PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx); -PetscErrorCode Hdiv_RICHARD3D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx); +PetscErrorCode Hdiv_RICHARD3D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx); extern int FreeContextPetsc(void *); -#endif // register_problems_h +#endif // register_problems_h diff --git a/examples/Hdiv-mixed/include/setup-boundary.h b/examples/Hdiv-mixed/include/setup-boundary.h index 21e62d536f..c62fb92982 100644 --- a/examples/Hdiv-mixed/include/setup-boundary.h +++ b/examples/Hdiv-mixed/include/setup-boundary.h @@ -1,10 +1,11 @@ #ifndef setup_boundary_h #define setup_boundary_h +#include #include #include #include -#include + #include "structs.h" // --------------------------------------------------------------------------- @@ -16,10 +17,6 @@ PetscErrorCode CreateBCLabel(DM dm, const char name[]); // Add Dirichlet boundaries to DM // --------------------------------------------------------------------------- PetscErrorCode DMAddBoundariesDirichlet(DM dm); -PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, - const PetscReal coords[], - PetscInt num_comp_u, PetscScalar *u, void *ctx); -PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, - AppCtx app_ctx, ProblemData problem_data, DM dm, - CeedVector bc_pressure); -#endif // setup_boundary_h +PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, const PetscReal coords[], PetscInt num_comp_u, PetscScalar *u, void *ctx); +PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, AppCtx app_ctx, ProblemData problem_data, DM dm, CeedVector bc_pressure); +#endif // setup_boundary_h diff --git a/examples/Hdiv-mixed/include/setup-dm.h b/examples/Hdiv-mixed/include/setup-dm.h index b61ac7e17d..71469cbd37 100644 --- a/examples/Hdiv-mixed/include/setup-dm.h +++ b/examples/Hdiv-mixed/include/setup-dm.h @@ -1,18 +1,18 @@ #ifndef setupdm_h #define setupdm_h +#include #include #include #include -#include + #include "structs.h" // --------------------------------------------------------------------------- // Setup DM // --------------------------------------------------------------------------- -PetscErrorCode CreateDM(MPI_Comm comm, MatType mat_type, - VecType vec_type, DM *dm); +PetscErrorCode CreateDM(MPI_Comm comm, MatType mat_type, VecType vec_type, DM *dm); PetscErrorCode PerturbVerticesSmooth(DM dm); PetscErrorCode PerturbVerticesRandom(DM dm); -#endif // setupdm_h +#endif // setupdm_h diff --git a/examples/Hdiv-mixed/include/setup-fe.h b/examples/Hdiv-mixed/include/setup-fe.h index 24dcda84ab..382b047740 100644 --- a/examples/Hdiv-mixed/include/setup-fe.h +++ b/examples/Hdiv-mixed/include/setup-fe.h @@ -1,16 +1,16 @@ #ifndef setupfe_h #define setupfe_h +#include #include #include #include -#include + #include "structs.h" // --------------------------------------------------------------------------- // Setup FE // --------------------------------------------------------------------------- PetscErrorCode SetupFEHdiv(MPI_Comm comm, DM dm, DM dm_u0, DM dm_p0); -PetscErrorCode SetupFEH1(ProblemData problem_data, - AppCtx app_ctx, DM dm_H1); -#endif // setupfe_h +PetscErrorCode SetupFEH1(ProblemData problem_data, AppCtx app_ctx, DM dm_H1); +#endif // setupfe_h diff --git a/examples/Hdiv-mixed/include/setup-libceed.h b/examples/Hdiv-mixed/include/setup-libceed.h index aac44d76fd..3b509b4a65 100644 --- a/examples/Hdiv-mixed/include/setup-libceed.h +++ b/examples/Hdiv-mixed/include/setup-libceed.h @@ -10,17 +10,11 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data); // Utility function - essential BC dofs are encoded in closure indices as -(i+1) PetscInt Involute(PetscInt i); // Utility function to create local CEED restriction from DMPlex -PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, - CeedInt height, DMLabel domain_label, CeedInt value, - CeedElemRestriction *elem_restr); +PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr); // Utility function to create local CEED Oriented restriction from DMPlex -PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, DM dm_u0, - DM dm_p0, CeedInt P, - CeedElemRestriction *elem_restr_u, CeedElemRestriction *elem_restr_p, - CeedElemRestriction *elem_restr_u0, CeedElemRestriction *elem_restr_p0); +PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, DM dm_u0, DM dm_p0, CeedInt P, CeedElemRestriction *elem_restr_u, + CeedElemRestriction *elem_restr_p, CeedElemRestriction *elem_restr_u0, + CeedElemRestriction *elem_restr_p0); // Set up libCEED for a given degree -PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, - Ceed ceed, AppCtx app_ctx, - ProblemData problem_data, - CeedData ceed_data); -#endif // setuplibceed_h +PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, Ceed ceed, AppCtx app_ctx, ProblemData problem_data, CeedData ceed_data); +#endif // setuplibceed_h diff --git a/examples/Hdiv-mixed/include/setup-matops.h b/examples/Hdiv-mixed/include/setup-matops.h index 7c21ed22d4..dad7737099 100644 --- a/examples/Hdiv-mixed/include/setup-matops.h +++ b/examples/Hdiv-mixed/include/setup-matops.h @@ -6,9 +6,7 @@ #include "structs.h" -PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, - OperatorApplyContext op_apply_ctx); -PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y, - OperatorApplyContext op_apply_ctx); +PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx); +PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx); -#endif // setup_matops_h +#endif // setup_matops_h diff --git a/examples/Hdiv-mixed/include/setup-solvers.h b/examples/Hdiv-mixed/include/setup-solvers.h index c7a40a1722..5502172408 100644 --- a/examples/Hdiv-mixed/include/setup-solvers.h +++ b/examples/Hdiv-mixed/include/setup-solvers.h @@ -7,19 +7,13 @@ #include "petscvec.h" #include "structs.h" -PetscErrorCode SetupJacobianOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - VecType vec_type, - OperatorApplyContext ctx_jacobian); -PetscErrorCode SetupResidualOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - OperatorApplyContext ctx_residual); -PetscErrorCode SetupErrorOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - OperatorApplyContext ctx_error); +PetscErrorCode SetupJacobianOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, VecType vec_type, OperatorApplyContext ctx_jacobian); +PetscErrorCode SetupResidualOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_residual); +PetscErrorCode SetupErrorOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_error); PetscErrorCode ApplyMatOp(Mat A, Vec X, Vec Y); PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx); PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, void *ctx); -PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, - SNES snes, KSP ksp, Vec *U); -PetscErrorCode ComputeL2Error(CeedData ceed_data, AppCtx app_ctx, Vec U, - CeedScalar *l2_error_u, CeedScalar *l2_error_p); +PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp, Vec *U); +PetscErrorCode ComputeL2Error(CeedData ceed_data, AppCtx app_ctx, Vec U, CeedScalar *l2_error_u, CeedScalar *l2_error_p); -#endif // setup_solvers_h +#endif // setup_solvers_h diff --git a/examples/Hdiv-mixed/include/setup-ts.h b/examples/Hdiv-mixed/include/setup-ts.h index d461ba5675..d490ba9bab 100644 --- a/examples/Hdiv-mixed/include/setup-ts.h +++ b/examples/Hdiv-mixed/include/setup-ts.h @@ -6,17 +6,11 @@ #include "structs.h" -PetscErrorCode CreateInitialConditions(CeedData ceed_data, AppCtx app_ctx, - VecType vec_type, Vec U); -PetscErrorCode SetupResidualOperatorCtx_Ut(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, OperatorApplyContext ctx_residual_ut); -PetscErrorCode SetupResidualOperatorCtx_U0(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, OperatorApplyContext ctx_initial_u0); -PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, OperatorApplyContext ctx_initial_p0); -PetscErrorCode TSFormIResidual(TS ts, PetscReal time, Vec X, Vec X_t, Vec Y, - void *ctx_residual_ut); -PetscErrorCode TSSolveRichard(CeedData ceed_data, AppCtx app_ctx, - TS ts, Vec *U); +PetscErrorCode CreateInitialConditions(CeedData ceed_data, AppCtx app_ctx, VecType vec_type, Vec U); +PetscErrorCode SetupResidualOperatorCtx_Ut(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_residual_ut); +PetscErrorCode SetupResidualOperatorCtx_U0(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_initial_u0); +PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_initial_p0); +PetscErrorCode TSFormIResidual(TS ts, PetscReal time, Vec X, Vec X_t, Vec Y, void *ctx_residual_ut); +PetscErrorCode TSSolveRichard(CeedData ceed_data, AppCtx app_ctx, TS ts, Vec *U); -#endif // setup_ts_h +#endif // setup_ts_h diff --git a/examples/Hdiv-mixed/include/structs.h b/examples/Hdiv-mixed/include/structs.h index 63d97eddce..1c70274d64 100644 --- a/examples/Hdiv-mixed/include/structs.h +++ b/examples/Hdiv-mixed/include/structs.h @@ -7,73 +7,61 @@ // PETSc operator contexts typedef struct OperatorApplyContext_ *OperatorApplyContext; struct OperatorApplyContext_ { - MPI_Comm comm; - Vec X_loc, Y_loc, X_t_loc; - CeedVector x_ceed, y_ceed, x_t_ceed, x_coord, rhs_ceed_H1; - CeedOperator op_apply, op_rhs_H1; - DM dm; - Ceed ceed; - CeedScalar t, dt; - CeedContextFieldLabel solution_time_label, final_time_label, - timestep_label; - CeedElemRestriction elem_restr_u_H1; - VecType vec_type; + MPI_Comm comm; + Vec X_loc, Y_loc, X_t_loc; + CeedVector x_ceed, y_ceed, x_t_ceed, x_coord, rhs_ceed_H1; + CeedOperator op_apply, op_rhs_H1; + DM dm; + Ceed ceed; + CeedScalar t, dt; + CeedContextFieldLabel solution_time_label, final_time_label, timestep_label; + CeedElemRestriction elem_restr_u_H1; + VecType vec_type; }; // libCEED data struct typedef struct CeedData_ *CeedData; struct CeedData_ { - CeedBasis basis_x, basis_u, basis_p, basis_u_face; - CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i, - elem_restr_p, elem_restr_p_i, elem_restr_u0, - elem_restr_p0, elem_restr_u_H1; - CeedQFunction qf_residual, qf_jacobian, qf_error, qf_ics_u, qf_ics_p, - qf_rhs_u0, qf_rhs_p0, qf_rhs_H1, qf_post_mass; - CeedOperator op_residual, op_jacobian, op_error, op_ics_u, op_ics_p, - op_rhs_u0, op_rhs_p0, op_rhs_H1, op_post_mass; - CeedVector x_ceed, y_ceed, x_coord, x_t_ceed, rhs_u0_ceed, - u0_ceed, v0_ceed, rhs_p0_ceed, p0_ceed, q0_ceed, - rhs_ceed_H1, u_ceed, up_ceed, vp_ceed; - CeedInt num_elem; + CeedBasis basis_x, basis_u, basis_p, basis_u_face; + CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_U_i, elem_restr_p, elem_restr_p_i, elem_restr_u0, elem_restr_p0, elem_restr_u_H1; + CeedQFunction qf_residual, qf_jacobian, qf_error, qf_ics_u, qf_ics_p, qf_rhs_u0, qf_rhs_p0, qf_rhs_H1, qf_post_mass; + CeedOperator op_residual, op_jacobian, op_error, op_ics_u, op_ics_p, op_rhs_u0, op_rhs_p0, op_rhs_H1, op_post_mass; + CeedVector x_ceed, y_ceed, x_coord, x_t_ceed, rhs_u0_ceed, u0_ceed, v0_ceed, rhs_p0_ceed, p0_ceed, q0_ceed, rhs_ceed_H1, u_ceed, up_ceed, vp_ceed; + CeedInt num_elem; }; // Application context from user command line options typedef struct AppCtx_ *AppCtx; struct AppCtx_ { - char ceed_resource[PETSC_MAX_PATH_LEN]; // libCEED backend - MPI_Comm comm; + char ceed_resource[PETSC_MAX_PATH_LEN]; // libCEED backend + MPI_Comm comm; // Degree of polynomial (1 only), extra quadrature pts - PetscInt degree; - PetscInt q_extra; + PetscInt degree; + PetscInt q_extra; // For applying traction BCs - PetscInt bc_pressure_count; - PetscInt bc_faces[16]; // face ID - PetscScalar bc_pressure_value[16]; + PetscInt bc_pressure_count; + PetscInt bc_faces[16]; // face ID + PetscScalar bc_pressure_value[16]; // Problem type arguments - PetscFunctionList problems; - char problem_name[PETSC_MAX_PATH_LEN]; - CeedScalar t_final, t; - PetscBool view_solution, quartic; - char output_dir[PETSC_MAX_PATH_LEN]; - PetscInt output_freq; - OperatorApplyContext ctx_residual, ctx_jacobian, ctx_error, ctx_residual_ut, - ctx_initial_u0, ctx_initial_p0, ctx_Hdiv, ctx_H1; + PetscFunctionList problems; + char problem_name[PETSC_MAX_PATH_LEN]; + CeedScalar t_final, t; + PetscBool view_solution, quartic; + char output_dir[PETSC_MAX_PATH_LEN]; + PetscInt output_freq; + OperatorApplyContext ctx_residual, ctx_jacobian, ctx_error, ctx_residual_ut, ctx_initial_u0, ctx_initial_p0, ctx_Hdiv, ctx_H1; }; // Problem specific data typedef struct ProblemData_ *ProblemData; struct ProblemData_ { - CeedQFunctionUser true_solution, residual, jacobian, error, ics_u, ics_p, - bc_pressure, rhs_u0, rhs_p0, post_rhs, post_mass; - const char *true_solution_loc, *residual_loc, *jacobian_loc, - *error_loc, *bc_pressure_loc, *ics_u_loc, *ics_p_loc, *rhs_u0_loc, - *rhs_p0_loc, *post_rhs_loc, *post_mass_loc; - CeedQuadMode quadrature_mode; - CeedInt elem_node, dim, q_data_size_face; - CeedQFunctionContext true_qfunction_ctx, error_qfunction_ctx, - residual_qfunction_ctx, jacobian_qfunction_ctx, - rhs_u0_qfunction_ctx ; - PetscBool has_ts, view_solution, quartic; + CeedQFunctionUser true_solution, residual, jacobian, error, ics_u, ics_p, bc_pressure, rhs_u0, rhs_p0, post_rhs, post_mass; + const char *true_solution_loc, *residual_loc, *jacobian_loc, *error_loc, *bc_pressure_loc, *ics_u_loc, *ics_p_loc, *rhs_u0_loc, *rhs_p0_loc, + *post_rhs_loc, *post_mass_loc; + CeedQuadMode quadrature_mode; + CeedInt elem_node, dim, q_data_size_face; + CeedQFunctionContext true_qfunction_ctx, error_qfunction_ctx, residual_qfunction_ctx, jacobian_qfunction_ctx, rhs_u0_qfunction_ctx; + PetscBool has_ts, view_solution, quartic; }; -#endif // structs_h \ No newline at end of file +#endif // structs_h \ No newline at end of file diff --git a/examples/Hdiv-mixed/main.c b/examples/Hdiv-mixed/main.c index 814fd086f8..a0df25b77e 100644 --- a/examples/Hdiv-mixed/main.c +++ b/examples/Hdiv-mixed/main.c @@ -40,31 +40,29 @@ int main(int argc, char **argv) { // --------------------------------------------------------------------------- // Initialize PETSc // --------------------------------------------------------------------------- - PetscCall( PetscInitialize(&argc, &argv, NULL, help) ); + PetscCall(PetscInitialize(&argc, &argv, NULL, help)); // --------------------------------------------------------------------------- // Create structs // --------------------------------------------------------------------------- AppCtx app_ctx; - PetscCall( PetscCalloc1(1, &app_ctx) ); + PetscCall(PetscCalloc1(1, &app_ctx)); ProblemData problem_data = NULL; - PetscCall( PetscCalloc1(1, &problem_data) ); + PetscCall(PetscCalloc1(1, &problem_data)); CeedData ceed_data; - PetscCall( PetscCalloc1(1, &ceed_data) ); + PetscCall(PetscCalloc1(1, &ceed_data)); - OperatorApplyContext ctx_jacobian, ctx_residual, ctx_residual_ut, - ctx_initial_u0, ctx_initial_p0, - ctx_error, ctx_Hdiv, ctx_H1; - PetscCall( PetscCalloc1(1, &ctx_jacobian) ); - PetscCall( PetscCalloc1(1, &ctx_residual) ); - PetscCall( PetscCalloc1(1, &ctx_residual_ut) ); - PetscCall( PetscCalloc1(1, &ctx_initial_u0) ); - PetscCall( PetscCalloc1(1, &ctx_initial_p0) ); - PetscCall( PetscCalloc1(1, &ctx_error) ); - PetscCall( PetscCalloc1(1, &ctx_Hdiv) ); - PetscCall( PetscCalloc1(1, &ctx_H1) ); + OperatorApplyContext ctx_jacobian, ctx_residual, ctx_residual_ut, ctx_initial_u0, ctx_initial_p0, ctx_error, ctx_Hdiv, ctx_H1; + PetscCall(PetscCalloc1(1, &ctx_jacobian)); + PetscCall(PetscCalloc1(1, &ctx_residual)); + PetscCall(PetscCalloc1(1, &ctx_residual_ut)); + PetscCall(PetscCalloc1(1, &ctx_initial_u0)); + PetscCall(PetscCalloc1(1, &ctx_initial_p0)); + PetscCall(PetscCalloc1(1, &ctx_error)); + PetscCall(PetscCalloc1(1, &ctx_Hdiv)); + PetscCall(PetscCalloc1(1, &ctx_H1)); // Context for Darcy problem app_ctx->ctx_residual = ctx_residual; app_ctx->ctx_jacobian = ctx_jacobian; @@ -78,7 +76,7 @@ int main(int argc, char **argv) { app_ctx->ctx_error = ctx_error; // Context for post-processing app_ctx->ctx_Hdiv = ctx_Hdiv; - app_ctx->ctx_H1 = ctx_H1; + app_ctx->ctx_H1 = ctx_H1; // --------------------------------------------------------------------------- // Initialize libCEED @@ -86,21 +84,23 @@ int main(int argc, char **argv) { // -- Initialize backend Ceed ceed; CeedInit("/cpu/self/ref/serial", &ceed); - //CeedInit(app_ctx->ceed_resource, &ceed); + // CeedInit(app_ctx->ceed_resource, &ceed); CeedMemType mem_type_backend; CeedGetPreferredMemType(ceed, &mem_type_backend); VecType vec_type = NULL; MatType mat_type = NULL; switch (mem_type_backend) { - case CEED_MEM_HOST: vec_type = VECSTANDARD; break; - case CEED_MEM_DEVICE: { - const char *resolved; - CeedGetResource(ceed, &resolved); - if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; - else if (strstr(resolved, "/gpu/hip")) vec_type = VECKOKKOS; - else vec_type = VECSTANDARD; - } + case CEED_MEM_HOST: + vec_type = VECSTANDARD; + break; + case CEED_MEM_DEVICE: { + const char *resolved; + CeedGetResource(ceed, &resolved); + if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; + else if (strstr(resolved, "/gpu/hip")) vec_type = VECKOKKOS; + else vec_type = VECSTANDARD; + } } if (strstr(vec_type, VECCUDA)) mat_type = MATAIJCUSPARSE; else if (strstr(vec_type, VECKOKKOS)) mat_type = MATAIJKOKKOS; @@ -111,99 +111,92 @@ int main(int argc, char **argv) { // --------------------------------------------------------------------------- // Create DM // --------------------------------------------------------------------------- - DM dm, dm_u0, dm_p0, dm_H1; + DM dm, dm_u0, dm_p0, dm_H1; // DM for mixed problem - PetscCall( CreateDM(comm, mat_type, vec_type, &dm) ); + PetscCall(CreateDM(comm, mat_type, vec_type, &dm)); // DM for projecting initial velocity to Hdiv space - PetscCall( CreateDM(comm, mat_type, vec_type, &dm_u0) ); + PetscCall(CreateDM(comm, mat_type, vec_type, &dm_u0)); // DM for projecting initial pressure in L2 - PetscCall( CreateDM(comm, mat_type, vec_type, &dm_p0) ); + PetscCall(CreateDM(comm, mat_type, vec_type, &dm_p0)); // DM for projecting solution U into H1 space for PetscViewer - PetscCall( CreateDM(comm, mat_type, vec_type, &dm_H1) ); + PetscCall(CreateDM(comm, mat_type, vec_type, &dm_H1)); // TODO: add mesh option // perturb dm to have smooth random mesh - //PetscCall( PerturbVerticesSmooth(dm) ); - //PetscCall( PerturbVerticesSmooth(dm_H1) ); + // PetscCall( PerturbVerticesSmooth(dm) ); + // PetscCall( PerturbVerticesSmooth(dm_H1) ); // perturb dm to have random mesh - //PetscCall(PerturbVerticesRandom(dm) ); - //PetscCall(PerturbVerticesRandom(dm_H1) ); + // PetscCall(PerturbVerticesRandom(dm) ); + // PetscCall(PerturbVerticesRandom(dm_H1) ); // --------------------------------------------------------------------------- // Process command line options // --------------------------------------------------------------------------- // -- Register problems to be available on the command line - PetscCall( RegisterProblems_Hdiv(app_ctx) ); + PetscCall(RegisterProblems_Hdiv(app_ctx)); app_ctx->comm = comm; - PetscCall( ProcessCommandLineOptions(app_ctx) ); + PetscCall(ProcessCommandLineOptions(app_ctx)); // --------------------------------------------------------------------------- // Choose the problem from the list of registered problems // --------------------------------------------------------------------------- { PetscErrorCode (*p)(Ceed, ProblemData, DM, void *); - PetscCall( PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name, - &p) ); - if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found", - app_ctx->problem_name); - PetscCall( (*p)(ceed, problem_data, dm, &app_ctx) ); + PetscCall(PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name, &p)); + if (!p) SETERRQ(PETSC_COMM_SELF, 1, "Problem '%s' not found", app_ctx->problem_name); + PetscCall((*p)(ceed, problem_data, dm, &app_ctx)); } // --------------------------------------------------------------------------- // Setup FE for H(div) mixed-problem and H1 projection in post-processing.c // --------------------------------------------------------------------------- - PetscCall( SetupFEHdiv(comm, dm, dm_u0, dm_p0) ); - PetscCall( SetupFEH1(problem_data, app_ctx, dm_H1) ); + PetscCall(SetupFEHdiv(comm, dm, dm_u0, dm_p0)); + PetscCall(SetupFEH1(problem_data, app_ctx, dm_H1)); // --------------------------------------------------------------------------- // Create global unkown solution // --------------------------------------------------------------------------- - Vec U; // U=[p,u] - PetscCall( DMCreateGlobalVector(dm, &U) ); + Vec U; // U=[p,u] + PetscCall(DMCreateGlobalVector(dm, &U)); // --------------------------------------------------------------------------- // Setup libCEED // --------------------------------------------------------------------------- // -- Set up libCEED objects - PetscCall( SetupLibceed(dm, dm_u0, dm_p0, dm_H1, ceed, app_ctx, - problem_data, ceed_data) ); + PetscCall(SetupLibceed(dm, dm_u0, dm_p0, dm_H1, ceed, app_ctx, problem_data, ceed_data)); // --------------------------------------------------------------------------- // Setup pressure boundary conditions // --------------------------------------------------------------------------- // --Create empty local vector for libCEED - Vec P_loc; - PetscInt P_loc_size; - CeedScalar *p0; - CeedVector P_ceed; + Vec P_loc; + PetscInt P_loc_size; + CeedScalar *p0; + CeedVector P_ceed; PetscMemType pressure_mem_type; - PetscCall( DMCreateLocalVector(dm, &P_loc) ); - PetscCall( VecGetSize(P_loc, &P_loc_size) ); - PetscCall( VecZeroEntries(P_loc) ); - PetscCall( VecGetArrayAndMemType(P_loc, &p0, &pressure_mem_type) ); + PetscCall(DMCreateLocalVector(dm, &P_loc)); + PetscCall(VecGetSize(P_loc, &P_loc_size)); + PetscCall(VecZeroEntries(P_loc)); + PetscCall(VecGetArrayAndMemType(P_loc, &p0, &pressure_mem_type)); CeedVectorCreate(ceed, P_loc_size, &P_ceed); - CeedVectorSetArray(P_ceed, MemTypeP2C(pressure_mem_type), CEED_USE_POINTER, - p0); + CeedVectorSetArray(P_ceed, MemTypeP2C(pressure_mem_type), CEED_USE_POINTER, p0); // -- Apply operator to create local pressure vector on boundary - PetscCall( DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm, - P_ceed) ); - //CeedVectorView(P_ceed, "%12.8f", stdout); - // -- Map local to global + PetscCall(DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm, P_ceed)); + // CeedVectorView(P_ceed, "%12.8f", stdout); + // -- Map local to global Vec P; CeedVectorTakeArray(P_ceed, MemTypeP2C(pressure_mem_type), NULL); - PetscCall( VecRestoreArrayAndMemType(P_loc, &p0) ); - PetscCall( DMCreateGlobalVector(dm, &P) ); - PetscCall( VecZeroEntries(P) ); - PetscCall( DMLocalToGlobal(dm, P_loc, ADD_VALUES, P) ); + PetscCall(VecRestoreArrayAndMemType(P_loc, &p0)); + PetscCall(DMCreateGlobalVector(dm, &P)); + PetscCall(VecZeroEntries(P)); + PetscCall(DMLocalToGlobal(dm, P_loc, ADD_VALUES, P)); // --------------------------------------------------------------------------- // Setup context for projection problem; post-processing.c // --------------------------------------------------------------------------- - PetscCall( SetupProjectVelocityCtx_Hdiv(comm, dm, ceed, ceed_data, - app_ctx->ctx_Hdiv) ); - PetscCall( SetupProjectVelocityCtx_H1(comm, dm_H1, ceed, ceed_data, - vec_type, app_ctx->ctx_H1) ); + PetscCall(SetupProjectVelocityCtx_Hdiv(comm, dm, ceed, ceed_data, app_ctx->ctx_Hdiv)); + PetscCall(SetupProjectVelocityCtx_H1(comm, dm_H1, ceed, ceed_data, vec_type, app_ctx->ctx_H1)); // --------------------------------------------------------------------------- // Setup TSSolve for Richard problem @@ -213,110 +206,100 @@ int main(int argc, char **argv) { // --------------------------------------------------------------------------- // Setup context for initial conditions // --------------------------------------------------------------------------- - PetscCall( SetupResidualOperatorCtx_U0(comm, dm_u0, ceed, ceed_data, - app_ctx->ctx_initial_u0) ); - PetscCall( SetupResidualOperatorCtx_P0(comm, dm_p0, ceed, ceed_data, - app_ctx->ctx_initial_p0) ); - PetscCall( SetupResidualOperatorCtx_Ut(comm, dm, ceed, ceed_data, - app_ctx->ctx_residual_ut) ); - PetscCall( CreateInitialConditions(ceed_data, app_ctx, vec_type, U) ); - //VecView(U, PETSC_VIEWER_STDOUT_WORLD); - // Solve Richards problem - PetscCall( TSCreate(comm, &ts) ); - PetscCall( VecZeroEntries(app_ctx->ctx_residual_ut->X_loc) ); - PetscCall( VecZeroEntries(app_ctx->ctx_residual_ut->X_t_loc) ); - PetscCall( TSSolveRichard(ceed_data, app_ctx, ts, &U) ); - //VecView(U, PETSC_VIEWER_STDOUT_WORLD); + PetscCall(SetupResidualOperatorCtx_U0(comm, dm_u0, ceed, ceed_data, app_ctx->ctx_initial_u0)); + PetscCall(SetupResidualOperatorCtx_P0(comm, dm_p0, ceed, ceed_data, app_ctx->ctx_initial_p0)); + PetscCall(SetupResidualOperatorCtx_Ut(comm, dm, ceed, ceed_data, app_ctx->ctx_residual_ut)); + PetscCall(CreateInitialConditions(ceed_data, app_ctx, vec_type, U)); + // VecView(U, PETSC_VIEWER_STDOUT_WORLD); + // Solve Richards problem + PetscCall(TSCreate(comm, &ts)); + PetscCall(VecZeroEntries(app_ctx->ctx_residual_ut->X_loc)); + PetscCall(VecZeroEntries(app_ctx->ctx_residual_ut->X_t_loc)); + PetscCall(TSSolveRichard(ceed_data, app_ctx, ts, &U)); + // VecView(U, PETSC_VIEWER_STDOUT_WORLD); } // --------------------------------------------------------------------------- // Setup SNES for Darcy problem // --------------------------------------------------------------------------- SNES snes; - KSP ksp; + KSP ksp; if (!problem_data->has_ts) { - PetscCall( SetupJacobianOperatorCtx(dm, ceed, ceed_data, vec_type, - app_ctx->ctx_jacobian) ); - PetscCall( SetupResidualOperatorCtx(dm, ceed, ceed_data, - app_ctx->ctx_residual) ); + PetscCall(SetupJacobianOperatorCtx(dm, ceed, ceed_data, vec_type, app_ctx->ctx_jacobian)); + PetscCall(SetupResidualOperatorCtx(dm, ceed, ceed_data, app_ctx->ctx_residual)); // Create SNES - PetscCall( SNESCreate(comm, &snes) ); - PetscCall( SNESGetKSP(snes, &ksp) ); - PetscCall( PDESolver(ceed_data, app_ctx, snes, ksp, &U) ); - //VecView(U, PETSC_VIEWER_STDOUT_WORLD); + PetscCall(SNESCreate(comm, &snes)); + PetscCall(SNESGetKSP(snes, &ksp)); + PetscCall(PDESolver(ceed_data, app_ctx, snes, ksp, &U)); + // VecView(U, PETSC_VIEWER_STDOUT_WORLD); } // --------------------------------------------------------------------------- // Compute L2 error of mms problem // --------------------------------------------------------------------------- - PetscCall( SetupErrorOperatorCtx(dm, ceed, ceed_data, app_ctx->ctx_error) ); + PetscCall(SetupErrorOperatorCtx(dm, ceed, ceed_data, app_ctx->ctx_error)); CeedScalar l2_error_u, l2_error_p; - PetscCall( ComputeL2Error(ceed_data, app_ctx, U, - &l2_error_u, &l2_error_p) ); + PetscCall(ComputeL2Error(ceed_data, app_ctx, U, &l2_error_u, &l2_error_p)); // --------------------------------------------------------------------------- // Print solver iterations and final norms // --------------------------------------------------------------------------- - PetscCall( PrintOutput(dm, ceed, app_ctx, problem_data->has_ts, - mem_type_backend, - ts, snes, ksp, U, l2_error_u, l2_error_p) ); + PetscCall(PrintOutput(dm, ceed, app_ctx, problem_data->has_ts, mem_type_backend, ts, snes, ksp, U, l2_error_u, l2_error_p)); // --------------------------------------------------------------------------- // Save solution (paraview) // --------------------------------------------------------------------------- if (app_ctx->view_solution) { PetscViewer viewer_p; - PetscCall( PetscViewerVTKOpen(comm,"darcy_pressure.vtu",FILE_MODE_WRITE, - &viewer_p) ); - PetscCall( VecView(U, viewer_p) ); - PetscCall( PetscViewerDestroy(&viewer_p) ); + PetscCall(PetscViewerVTKOpen(comm, "darcy_pressure.vtu", FILE_MODE_WRITE, &viewer_p)); + PetscCall(VecView(U, viewer_p)); + PetscCall(PetscViewerDestroy(&viewer_p)); - Vec U_H1; // velocity in H1 space for post-processing - PetscCall( DMCreateGlobalVector(dm_H1, &U_H1) ); - PetscCall( ProjectVelocity(app_ctx, U, &U_H1) ); + Vec U_H1; // velocity in H1 space for post-processing + PetscCall(DMCreateGlobalVector(dm_H1, &U_H1)); + PetscCall(ProjectVelocity(app_ctx, U, &U_H1)); PetscViewer viewer_u; - PetscCall( PetscViewerVTKOpen(comm,"darcy_velocity.vtu",FILE_MODE_WRITE, - &viewer_u) ); - PetscCall( VecView(U_H1, viewer_u) ); - PetscCall( PetscViewerDestroy(&viewer_u) ); - PetscCall( VecDestroy(&U_H1) ); + PetscCall(PetscViewerVTKOpen(comm, "darcy_velocity.vtu", FILE_MODE_WRITE, &viewer_u)); + PetscCall(VecView(U_H1, viewer_u)); + PetscCall(PetscViewerDestroy(&viewer_u)); + PetscCall(VecDestroy(&U_H1)); } // --------------------------------------------------------------------------- // Free objects // --------------------------------------------------------------------------- // Free PETSc objects - PetscCall( DMDestroy(&dm) ); - PetscCall( DMDestroy(&dm_u0) ); - PetscCall( DMDestroy(&dm_p0) ); - PetscCall( DMDestroy(&dm_H1) ); - PetscCall( VecDestroy(&U) ); - PetscCall( CtxVecDestroy(app_ctx) ); + PetscCall(DMDestroy(&dm)); + PetscCall(DMDestroy(&dm_u0)); + PetscCall(DMDestroy(&dm_p0)); + PetscCall(DMDestroy(&dm_H1)); + PetscCall(VecDestroy(&U)); + PetscCall(CtxVecDestroy(app_ctx)); if (problem_data->has_ts) { - PetscCall( TSDestroy(&ts) ); + PetscCall(TSDestroy(&ts)); } else { - PetscCall( SNESDestroy(&snes) ); + PetscCall(SNESDestroy(&snes)); } - PetscCall( CeedDataDestroy(ceed_data, problem_data) ); + PetscCall(CeedDataDestroy(ceed_data, problem_data)); // -- Function list - PetscCall( PetscFunctionListDestroy(&app_ctx->problems) ); + PetscCall(PetscFunctionListDestroy(&app_ctx->problems)); // -- Structs - PetscCall( PetscFree(app_ctx) ); - PetscCall( PetscFree(problem_data) ); - PetscCall( PetscFree(ctx_initial_u0) ); - PetscCall( PetscFree(ctx_initial_p0) ); - PetscCall( PetscFree(ctx_residual_ut) ); - PetscCall( PetscFree(ctx_residual) ); - PetscCall( PetscFree(ctx_jacobian) ); - PetscCall( PetscFree(ctx_error) ); - PetscCall( PetscFree(ctx_H1) ); - PetscCall( PetscFree(ctx_Hdiv) ); + PetscCall(PetscFree(app_ctx)); + PetscCall(PetscFree(problem_data)); + PetscCall(PetscFree(ctx_initial_u0)); + PetscCall(PetscFree(ctx_initial_p0)); + PetscCall(PetscFree(ctx_residual_ut)); + PetscCall(PetscFree(ctx_residual)); + PetscCall(PetscFree(ctx_jacobian)); + PetscCall(PetscFree(ctx_error)); + PetscCall(PetscFree(ctx_H1)); + PetscCall(PetscFree(ctx_Hdiv)); // Free libCEED objects - //CeedVectorDestroy(&bc_pressure); + // CeedVectorDestroy(&bc_pressure); CeedDestroy(&ceed); return PetscFinalize(); diff --git a/examples/Hdiv-mixed/main.h b/examples/Hdiv-mixed/main.h index 7033f49f38..8f3e6abe05 100644 --- a/examples/Hdiv-mixed/main.h +++ b/examples/Hdiv-mixed/main.h @@ -2,15 +2,15 @@ #ifndef MAIN_H #define MAIN_H -#include "include/setup-libceed.h" -#include "include/setup-dm.h" -#include "include/setup-fe.h" -#include "include/setup-boundary.h" #include "include/cl-options.h" +#include "include/post-processing.h" #include "include/register-problem.h" +#include "include/setup-boundary.h" +#include "include/setup-dm.h" +#include "include/setup-fe.h" +#include "include/setup-libceed.h" #include "include/setup-matops.h" #include "include/setup-solvers.h" #include "include/setup-ts.h" -#include "include/post-processing.h" -#endif // MAIN_H \ No newline at end of file +#endif // MAIN_H \ No newline at end of file diff --git a/examples/Hdiv-mixed/problems/darcy2d.c b/examples/Hdiv-mixed/problems/darcy2d.c index 16d61dbb62..4864993661 100644 --- a/examples/Hdiv-mixed/problems/darcy2d.c +++ b/examples/Hdiv-mixed/problems/darcy2d.c @@ -18,56 +18,55 @@ /// Utility functions for setting up Darcy problem in 2D #include "../include/register-problem.h" -#include "../qfunctions/darcy-true2d.h" -#include "../qfunctions/darcy-system2d.h" #include "../qfunctions/darcy-error2d.h" -#include "../qfunctions/post-processing2d.h" -#include "../qfunctions/darcy-true-quartic2d.h" #include "../qfunctions/darcy-system-quartic2d.h" +#include "../qfunctions/darcy-system2d.h" +#include "../qfunctions/darcy-true-quartic2d.h" +#include "../qfunctions/darcy-true2d.h" +#include "../qfunctions/post-processing2d.h" //#include "../qfunctions/pressure-boundary2d.h" -PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx) { +PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx) { AppCtx app_ctx = *(AppCtx *)ctx; DARCYContext darcy_ctx; CeedQFunctionContext darcy_context; PetscFunctionBeginUser; - PetscCall( PetscCalloc1(1, &darcy_ctx) ); + PetscCall(PetscCalloc1(1, &darcy_ctx)); // ------------------------------------------------------ // SET UP POISSON_QUAD2D // ------------------------------------------------------ - problem_data->dim = 2; - problem_data->elem_node = 4; - problem_data->q_data_size_face = 3; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->true_solution = DarcyTrue2D; - problem_data->true_solution_loc = DarcyTrue2D_loc; - problem_data->residual = DarcySystem2D; - problem_data->residual_loc = DarcySystem2D_loc; - problem_data->jacobian = JacobianDarcySystem2D; - problem_data->jacobian_loc = JacobianDarcySystem2D_loc; - problem_data->error = DarcyError2D; - problem_data->error_loc = DarcyError2D_loc; - //problem_data->bc_pressure = BCPressure2D; - //problem_data->bc_pressure_loc = BCPressure2D_loc; - problem_data->post_rhs = PostProcessingRhs2D; - problem_data->post_rhs_loc = PostProcessingRhs2D_loc; - problem_data->post_mass = PostProcessingMass2D; - problem_data->post_mass_loc = PostProcessingMass2D_loc; - problem_data->has_ts = PETSC_FALSE; - problem_data->view_solution = app_ctx->view_solution; - problem_data->quartic = app_ctx->quartic; + problem_data->dim = 2; + problem_data->elem_node = 4; + problem_data->q_data_size_face = 3; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->true_solution = DarcyTrue2D; + problem_data->true_solution_loc = DarcyTrue2D_loc; + problem_data->residual = DarcySystem2D; + problem_data->residual_loc = DarcySystem2D_loc; + problem_data->jacobian = JacobianDarcySystem2D; + problem_data->jacobian_loc = JacobianDarcySystem2D_loc; + problem_data->error = DarcyError2D; + problem_data->error_loc = DarcyError2D_loc; + // problem_data->bc_pressure = BCPressure2D; + // problem_data->bc_pressure_loc = BCPressure2D_loc; + problem_data->post_rhs = PostProcessingRhs2D; + problem_data->post_rhs_loc = PostProcessingRhs2D_loc; + problem_data->post_mass = PostProcessingMass2D; + problem_data->post_mass_loc = PostProcessingMass2D_loc; + problem_data->has_ts = PETSC_FALSE; + problem_data->view_solution = app_ctx->view_solution; + problem_data->quartic = app_ctx->quartic; if (app_ctx->quartic) { - problem_data->true_solution = DarcyTrueQuartic2D; - problem_data->true_solution_loc = DarcyTrueQuartic2D_loc; - problem_data->residual = DarcySystemQuartic2D; - problem_data->residual_loc = DarcySystemQuartic2D_loc; - problem_data->jacobian = JacobianDarcySystemQuartic2D; - problem_data->jacobian_loc = JacobianDarcySystemQuartic2D_loc; + problem_data->true_solution = DarcyTrueQuartic2D; + problem_data->true_solution_loc = DarcyTrueQuartic2D_loc; + problem_data->residual = DarcySystemQuartic2D; + problem_data->residual_loc = DarcySystemQuartic2D_loc; + problem_data->jacobian = JacobianDarcySystemQuartic2D; + problem_data->jacobian_loc = JacobianDarcySystemQuartic2D_loc; } // ------------------------------------------------------ @@ -75,44 +74,34 @@ PetscErrorCode Hdiv_DARCY2D(Ceed ceed, ProblemData problem_data, DM dm, // ------------------------------------------------------ CeedScalar kappa = 10., rho_a0 = 998.2, g = 9.8, alpha_a = 1., b_a = 10.; PetscOptionsBegin(app_ctx->comm, NULL, "Options for Hdiv-mixed problem", NULL); - PetscCall( PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, - kappa, &kappa, NULL)); - PetscCall( PetscOptionsScalar("-rho_a0", "Density at p0", NULL, - rho_a0, &rho_a0, NULL)); - PetscCall( PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", - NULL, - alpha_a, &alpha_a, NULL)); - PetscCall( PetscOptionsScalar("-b_a", "Parameter for relative permeability", - NULL, - b_a, &b_a, NULL)); + PetscCall(PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, kappa, &kappa, NULL)); + PetscCall(PetscOptionsScalar("-rho_a0", "Density at p0", NULL, rho_a0, &rho_a0, NULL)); + PetscCall(PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", NULL, alpha_a, &alpha_a, NULL)); + PetscCall(PetscOptionsScalar("-b_a", "Parameter for relative permeability", NULL, b_a, &b_a, NULL)); PetscOptionsEnd(); PetscReal domain_min[2], domain_max[2], domain_size[2]; - PetscCall( DMGetBoundingBox(dm, domain_min, domain_max) ); - for (PetscInt i=0; i<2; i++) domain_size[i] = domain_max[i] - domain_min[i]; + PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); + for (PetscInt i = 0; i < 2; i++) domain_size[i] = domain_max[i] - domain_min[i]; - darcy_ctx->kappa = kappa; - darcy_ctx->rho_a0 = rho_a0; - darcy_ctx->g = g; + darcy_ctx->kappa = kappa; + darcy_ctx->rho_a0 = rho_a0; + darcy_ctx->g = g; darcy_ctx->alpha_a = alpha_a; - darcy_ctx->b_a = b_a; - darcy_ctx->lx = domain_size[0]; - darcy_ctx->ly = domain_size[1]; + darcy_ctx->b_a = b_a; + darcy_ctx->lx = domain_size[0]; + darcy_ctx->ly = domain_size[1]; CeedQFunctionContextCreate(ceed, &darcy_context); - CeedQFunctionContextSetData(darcy_context, CEED_MEM_HOST, CEED_COPY_VALUES, - sizeof(*darcy_ctx), darcy_ctx); - //CeedQFunctionContextSetDataDestroy(darcy_context, CEED_MEM_HOST, - // FreeContextPetsc); + CeedQFunctionContextSetData(darcy_context, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*darcy_ctx), darcy_ctx); + // CeedQFunctionContextSetDataDestroy(darcy_context, CEED_MEM_HOST, + // FreeContextPetsc); problem_data->true_qfunction_ctx = darcy_context; - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->residual_qfunction_ctx); - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->jacobian_qfunction_ctx); - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->error_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->residual_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->jacobian_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->error_qfunction_ctx); - PetscCall( PetscFree(darcy_ctx) ); + PetscCall(PetscFree(darcy_ctx)); PetscFunctionReturn(0); } diff --git a/examples/Hdiv-mixed/problems/darcy3d.c b/examples/Hdiv-mixed/problems/darcy3d.c index 0003bb010e..4cdbc75a71 100644 --- a/examples/Hdiv-mixed/problems/darcy3d.c +++ b/examples/Hdiv-mixed/problems/darcy3d.c @@ -18,89 +18,78 @@ /// Utility functions for setting up Darcy problem in 3D #include "../include/register-problem.h" -#include "../qfunctions/darcy-true3d.h" -#include "../qfunctions/darcy-system3d.h" #include "../qfunctions/darcy-error3d.h" +#include "../qfunctions/darcy-system3d.h" +#include "../qfunctions/darcy-true3d.h" #include "../qfunctions/post-processing3d.h" //#include "../qfunctions/pressure-boundary3d.h" -PetscErrorCode Hdiv_DARCY3D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx) { - AppCtx app_ctx = *(AppCtx *)ctx; +PetscErrorCode Hdiv_DARCY3D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx) { + AppCtx app_ctx = *(AppCtx *)ctx; DARCYContext darcy_ctx; CeedQFunctionContext darcy_context; PetscFunctionBeginUser; - PetscCall( PetscCalloc1(1, &darcy_ctx) ); + PetscCall(PetscCalloc1(1, &darcy_ctx)); // ------------------------------------------------------ // SET UP POISSON_QUAD2D // ------------------------------------------------------ - problem_data->dim = 3; - problem_data->elem_node = 8; - problem_data->q_data_size_face = 4; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->true_solution = DarcyTrue3D; - problem_data->true_solution_loc = DarcyTrue3D_loc; - problem_data->residual = DarcySystem3D; - problem_data->residual_loc = DarcySystem3D_loc; - problem_data->jacobian = JacobianDarcySystem3D; - problem_data->jacobian_loc = JacobianDarcySystem3D_loc; - problem_data->error = DarcyError3D; - problem_data->error_loc = DarcyError3D_loc; - //problem_data->bc_pressure = BCPressure3D; - //problem_data->bc_pressure_loc = BCPressure3D_loc; - problem_data->post_rhs = PostProcessingRhs3D; - problem_data->post_rhs_loc = PostProcessingRhs3D_loc; - problem_data->post_mass = PostProcessingMass3D; - problem_data->post_mass_loc = PostProcessingMass3D_loc; - problem_data->has_ts = PETSC_FALSE; - problem_data->view_solution = app_ctx->view_solution; + problem_data->dim = 3; + problem_data->elem_node = 8; + problem_data->q_data_size_face = 4; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->true_solution = DarcyTrue3D; + problem_data->true_solution_loc = DarcyTrue3D_loc; + problem_data->residual = DarcySystem3D; + problem_data->residual_loc = DarcySystem3D_loc; + problem_data->jacobian = JacobianDarcySystem3D; + problem_data->jacobian_loc = JacobianDarcySystem3D_loc; + problem_data->error = DarcyError3D; + problem_data->error_loc = DarcyError3D_loc; + // problem_data->bc_pressure = BCPressure3D; + // problem_data->bc_pressure_loc = BCPressure3D_loc; + problem_data->post_rhs = PostProcessingRhs3D; + problem_data->post_rhs_loc = PostProcessingRhs3D_loc; + problem_data->post_mass = PostProcessingMass3D; + problem_data->post_mass_loc = PostProcessingMass3D_loc; + problem_data->has_ts = PETSC_FALSE; + problem_data->view_solution = app_ctx->view_solution; // ------------------------------------------------------ // Command line Options // ------------------------------------------------------ CeedScalar kappa = 1., rho_a0 = 998.2, g = 9.8, alpha_a = 1., b_a = 10.; PetscOptionsBegin(app_ctx->comm, NULL, "Options for Hdiv-mixed problem", NULL); - PetscCall( PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, - kappa, &kappa, NULL)); - PetscCall( PetscOptionsScalar("-rho_a0", "Density at p0", NULL, - rho_a0, &rho_a0, NULL)); - PetscCall( PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", - NULL, - alpha_a, &alpha_a, NULL)); - PetscCall( PetscOptionsScalar("-b_a", "Parameter for relative permeability", - NULL, - b_a, &b_a, NULL)); + PetscCall(PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, kappa, &kappa, NULL)); + PetscCall(PetscOptionsScalar("-rho_a0", "Density at p0", NULL, rho_a0, &rho_a0, NULL)); + PetscCall(PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", NULL, alpha_a, &alpha_a, NULL)); + PetscCall(PetscOptionsScalar("-b_a", "Parameter for relative permeability", NULL, b_a, &b_a, NULL)); PetscOptionsEnd(); PetscReal domain_min[3], domain_max[3], domain_size[3]; - PetscCall( DMGetBoundingBox(dm, domain_min, domain_max) ); - for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; + PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); + for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; - darcy_ctx->kappa = kappa; - darcy_ctx->rho_a0 = rho_a0; - darcy_ctx->g = g; + darcy_ctx->kappa = kappa; + darcy_ctx->rho_a0 = rho_a0; + darcy_ctx->g = g; darcy_ctx->alpha_a = alpha_a; - darcy_ctx->b_a = b_a; - darcy_ctx->lx = domain_size[0]; - darcy_ctx->ly = domain_size[1]; - darcy_ctx->lz = domain_size[2]; + darcy_ctx->b_a = b_a; + darcy_ctx->lx = domain_size[0]; + darcy_ctx->ly = domain_size[1]; + darcy_ctx->lz = domain_size[2]; CeedQFunctionContextCreate(ceed, &darcy_context); - CeedQFunctionContextSetData(darcy_context, CEED_MEM_HOST, CEED_COPY_VALUES, - sizeof(*darcy_ctx), darcy_ctx); - //CeedQFunctionContextSetDataDestroy(darcy_context, CEED_MEM_HOST, - // FreeContextPetsc); + CeedQFunctionContextSetData(darcy_context, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*darcy_ctx), darcy_ctx); + // CeedQFunctionContextSetDataDestroy(darcy_context, CEED_MEM_HOST, + // FreeContextPetsc); problem_data->true_qfunction_ctx = darcy_context; - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->residual_qfunction_ctx); - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->jacobian_qfunction_ctx); - CeedQFunctionContextReferenceCopy(darcy_context, - &problem_data->error_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->residual_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->jacobian_qfunction_ctx); + CeedQFunctionContextReferenceCopy(darcy_context, &problem_data->error_qfunction_ctx); - PetscCall( PetscFree(darcy_ctx) ); + PetscCall(PetscFree(darcy_ctx)); PetscFunctionReturn(0); } diff --git a/examples/Hdiv-mixed/problems/register-problem.c b/examples/Hdiv-mixed/problems/register-problem.c index 5e4ffe7b43..994e4f4605 100644 --- a/examples/Hdiv-mixed/problems/register-problem.c +++ b/examples/Hdiv-mixed/problems/register-problem.c @@ -24,25 +24,19 @@ PetscErrorCode RegisterProblems_Hdiv(AppCtx app_ctx) { app_ctx->problems = NULL; PetscFunctionBeginUser; // 1) darcy2d (Hdiv_DARCY2D is created in darcy2d.c) - PetscCall( PetscFunctionListAdd(&app_ctx->problems, "darcy2d", - Hdiv_DARCY2D) ); + PetscCall(PetscFunctionListAdd(&app_ctx->problems, "darcy2d", Hdiv_DARCY2D)); // 2) darcy3d (Hdiv_DARCY3D is created in dacry3d.c) - PetscCall( PetscFunctionListAdd(&app_ctx->problems, "darcy3d", - Hdiv_DARCY3D) ); + PetscCall(PetscFunctionListAdd(&app_ctx->problems, "darcy3d", Hdiv_DARCY3D)); // 3) darcy3d-prism // 4) richard - PetscCall( PetscFunctionListAdd(&app_ctx->problems, "richard2d", - Hdiv_RICHARD2D) ); - PetscCall( PetscFunctionListAdd(&app_ctx->problems, "richard3d", - Hdiv_RICHARD3D) ); + PetscCall(PetscFunctionListAdd(&app_ctx->problems, "richard2d", Hdiv_RICHARD2D)); + PetscCall(PetscFunctionListAdd(&app_ctx->problems, "richard3d", Hdiv_RICHARD3D)); PetscFunctionReturn(0); } - // Free a plain data context that was allocated using PETSc; returning libCEED error codes int FreeContextPetsc(void *data) { - if (PetscFree(data)) return CeedError(NULL, CEED_ERROR_ACCESS, - "PetscFree failed"); + if (PetscFree(data)) return CeedError(NULL, CEED_ERROR_ACCESS, "PetscFree failed"); return CEED_ERROR_SUCCESS; } \ No newline at end of file diff --git a/examples/Hdiv-mixed/problems/richard2d.c b/examples/Hdiv-mixed/problems/richard2d.c index aa9bbd2c6d..a2b4cad337 100644 --- a/examples/Hdiv-mixed/problems/richard2d.c +++ b/examples/Hdiv-mixed/problems/richard2d.c @@ -18,116 +18,99 @@ /// Utility functions for setting up Richard problem in 2D #include "../include/register-problem.h" -#include "../qfunctions/richard-system2d.h" -#include "../qfunctions/richard-true2d.h" -#include "../qfunctions/richard-ics2d.h" #include "../qfunctions/darcy-error2d.h" #include "../qfunctions/post-processing2d.h" +#include "../qfunctions/richard-ics2d.h" +#include "../qfunctions/richard-system2d.h" +#include "../qfunctions/richard-true2d.h" //#include "../qfunctions/pressure-boundary2d.h" #include "petscsystypes.h" -PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx) { +PetscErrorCode Hdiv_RICHARD2D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx) { AppCtx app_ctx = *(AppCtx *)ctx; RICHARDContext richard_ctx; CeedQFunctionContext richard_context; PetscFunctionBeginUser; - PetscCall( PetscCalloc1(1, &richard_ctx) ); + PetscCall(PetscCalloc1(1, &richard_ctx)); // ------------------------------------------------------ // SET UP POISSON_QUAD2D // ------------------------------------------------------ - problem_data->dim = 2; - problem_data->elem_node = 4; - problem_data->q_data_size_face = 3; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->true_solution = RichardTrue2D; - problem_data->true_solution_loc = RichardTrue2D_loc; - problem_data->rhs_u0 = RichardRhsU02D; - problem_data->rhs_u0_loc = RichardRhsU02D_loc; - problem_data->ics_u = RichardICsU2D; - problem_data->ics_u_loc = RichardICsU2D_loc; - problem_data->rhs_p0 = RichardRhsP02D; - problem_data->rhs_p0_loc = RichardRhsP02D_loc; - problem_data->ics_p = RichardICsP2D; - problem_data->ics_p_loc = RichardICsP2D_loc; - problem_data->residual = RichardSystem2D; - problem_data->residual_loc = RichardSystem2D_loc; - //problem_data->jacobian = JacobianRichardSystem2D; - //problem_data->jacobian_loc = JacobianRichardSystem2D_loc; - problem_data->error = DarcyError2D; - problem_data->error_loc = DarcyError2D_loc; - //problem_data->bc_pressure = BCPressure2D; - //problem_data->bc_pressure_loc = BCPressure2D_loc; - problem_data->post_rhs = PostProcessingRhs2D; - problem_data->post_rhs_loc = PostProcessingRhs2D_loc; - problem_data->post_mass = PostProcessingMass2D; - problem_data->post_mass_loc = PostProcessingMass2D_loc; - problem_data->has_ts = PETSC_TRUE; - problem_data->view_solution = app_ctx->view_solution; + problem_data->dim = 2; + problem_data->elem_node = 4; + problem_data->q_data_size_face = 3; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->true_solution = RichardTrue2D; + problem_data->true_solution_loc = RichardTrue2D_loc; + problem_data->rhs_u0 = RichardRhsU02D; + problem_data->rhs_u0_loc = RichardRhsU02D_loc; + problem_data->ics_u = RichardICsU2D; + problem_data->ics_u_loc = RichardICsU2D_loc; + problem_data->rhs_p0 = RichardRhsP02D; + problem_data->rhs_p0_loc = RichardRhsP02D_loc; + problem_data->ics_p = RichardICsP2D; + problem_data->ics_p_loc = RichardICsP2D_loc; + problem_data->residual = RichardSystem2D; + problem_data->residual_loc = RichardSystem2D_loc; + // problem_data->jacobian = JacobianRichardSystem2D; + // problem_data->jacobian_loc = JacobianRichardSystem2D_loc; + problem_data->error = DarcyError2D; + problem_data->error_loc = DarcyError2D_loc; + // problem_data->bc_pressure = BCPressure2D; + // problem_data->bc_pressure_loc = BCPressure2D_loc; + problem_data->post_rhs = PostProcessingRhs2D; + problem_data->post_rhs_loc = PostProcessingRhs2D_loc; + problem_data->post_mass = PostProcessingMass2D; + problem_data->post_mass_loc = PostProcessingMass2D_loc; + problem_data->has_ts = PETSC_TRUE; + problem_data->view_solution = app_ctx->view_solution; // ------------------------------------------------------ // Command line Options // ------------------------------------------------------ - CeedScalar kappa = 10., alpha_a = 1., b_a = 10., rho_a0 = 998.2, - beta = 0., g = 9.8, p0 = 101325; + CeedScalar kappa = 10., alpha_a = 1., b_a = 10., rho_a0 = 998.2, beta = 0., g = 9.8, p0 = 101325; PetscOptionsBegin(app_ctx->comm, NULL, "Options for Hdiv-mixed problem", NULL); - PetscCall( PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, - kappa, &kappa, NULL)); - PetscCall( PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", - NULL, - alpha_a, &alpha_a, NULL)); - PetscCall( PetscOptionsScalar("-b_a", "Parameter for relative permeability", - NULL, - b_a, &b_a, NULL)); - PetscCall( PetscOptionsScalar("-rho_a0", "Density at p0", NULL, - rho_a0, &rho_a0, NULL)); - PetscCall( PetscOptionsScalar("-beta", "Water compressibility", NULL, - beta, &beta, NULL)); + PetscCall(PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, kappa, &kappa, NULL)); + PetscCall(PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", NULL, alpha_a, &alpha_a, NULL)); + PetscCall(PetscOptionsScalar("-b_a", "Parameter for relative permeability", NULL, b_a, &b_a, NULL)); + PetscCall(PetscOptionsScalar("-rho_a0", "Density at p0", NULL, rho_a0, &rho_a0, NULL)); + PetscCall(PetscOptionsScalar("-beta", "Water compressibility", NULL, beta, &beta, NULL)); app_ctx->t_final = 0.5; - PetscCall( PetscOptionsScalar("-t_final", "End time", NULL, - app_ctx->t_final, &app_ctx->t_final, NULL)); + PetscCall(PetscOptionsScalar("-t_final", "End time", NULL, app_ctx->t_final, &app_ctx->t_final, NULL)); PetscOptionsEnd(); PetscReal domain_min[2], domain_max[2], domain_size[2]; - PetscCall( DMGetBoundingBox(dm, domain_min, domain_max) ); - for (PetscInt i=0; i<2; i++) domain_size[i] = domain_max[i] - domain_min[i]; + PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); + for (PetscInt i = 0; i < 2; i++) domain_size[i] = domain_max[i] - domain_min[i]; - richard_ctx->kappa = kappa; + richard_ctx->kappa = kappa; richard_ctx->alpha_a = alpha_a; - richard_ctx->b_a = b_a; - richard_ctx->rho_a0 = rho_a0; - richard_ctx->beta = beta; - richard_ctx->g = g; - richard_ctx->p0 = p0; - richard_ctx->gamma = 5.; - richard_ctx->t = 0.; + richard_ctx->b_a = b_a; + richard_ctx->rho_a0 = rho_a0; + richard_ctx->beta = beta; + richard_ctx->g = g; + richard_ctx->p0 = p0; + richard_ctx->gamma = 5.; + richard_ctx->t = 0.; richard_ctx->t_final = app_ctx->t_final; - richard_ctx->lx = domain_size[0]; - richard_ctx->ly = domain_size[1]; + richard_ctx->lx = domain_size[0]; + richard_ctx->ly = domain_size[1]; CeedQFunctionContextCreate(ceed, &richard_context); - CeedQFunctionContextSetData(richard_context, CEED_MEM_HOST, CEED_COPY_VALUES, - sizeof(*richard_ctx), richard_ctx); - //CeedQFunctionContextSetDataDestroy(richard_context, CEED_MEM_HOST, - // FreeContextPetsc); - CeedQFunctionContextRegisterDouble(richard_context, "time", - offsetof(struct RICHARDContext_, t), 1, "current solver time"); - CeedQFunctionContextRegisterDouble(richard_context, "final_time", - offsetof(struct RICHARDContext_, t_final), 1, "final time"); - CeedQFunctionContextRegisterDouble(richard_context, "time_step", - offsetof(struct RICHARDContext_, dt), 1, "time step"); + CeedQFunctionContextSetData(richard_context, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*richard_ctx), richard_ctx); + // CeedQFunctionContextSetDataDestroy(richard_context, CEED_MEM_HOST, + // FreeContextPetsc); + CeedQFunctionContextRegisterDouble(richard_context, "time", offsetof(struct RICHARDContext_, t), 1, "current solver time"); + CeedQFunctionContextRegisterDouble(richard_context, "final_time", offsetof(struct RICHARDContext_, t_final), 1, "final time"); + CeedQFunctionContextRegisterDouble(richard_context, "time_step", offsetof(struct RICHARDContext_, dt), 1, "time step"); problem_data->true_qfunction_ctx = richard_context; - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->rhs_u0_qfunction_ctx); - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->residual_qfunction_ctx); - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->error_qfunction_ctx); - PetscCall( PetscFree(richard_ctx) ); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->rhs_u0_qfunction_ctx); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->residual_qfunction_ctx); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->error_qfunction_ctx); + PetscCall(PetscFree(richard_ctx)); PetscFunctionReturn(0); } diff --git a/examples/Hdiv-mixed/problems/richard3d.c b/examples/Hdiv-mixed/problems/richard3d.c index 9559138526..92663aa2c3 100644 --- a/examples/Hdiv-mixed/problems/richard3d.c +++ b/examples/Hdiv-mixed/problems/richard3d.c @@ -18,117 +18,100 @@ /// Utility functions for setting up Richard problem in 3D #include "../include/register-problem.h" -#include "../qfunctions/richard-system3d.h" -#include "../qfunctions/richard-true3d.h" -#include "../qfunctions/richard-ics3d.h" #include "../qfunctions/darcy-error3d.h" #include "../qfunctions/post-processing3d.h" +#include "../qfunctions/richard-ics3d.h" +#include "../qfunctions/richard-system3d.h" +#include "../qfunctions/richard-true3d.h" //#include "../qfunctions/pressure-boundary2d.h" #include "petscsystypes.h" -PetscErrorCode Hdiv_RICHARD3D(Ceed ceed, ProblemData problem_data, DM dm, - void *ctx) { +PetscErrorCode Hdiv_RICHARD3D(Ceed ceed, ProblemData problem_data, DM dm, void *ctx) { AppCtx app_ctx = *(AppCtx *)ctx; RICHARDContext richard_ctx; CeedQFunctionContext richard_context; PetscFunctionBeginUser; - PetscCall( PetscCalloc1(1, &richard_ctx) ); + PetscCall(PetscCalloc1(1, &richard_ctx)); // ------------------------------------------------------ // SET UP POISSON_QUAD2D // ------------------------------------------------------ - problem_data->dim = 3; - problem_data->elem_node = 8; - problem_data->q_data_size_face = 4; - problem_data->quadrature_mode = CEED_GAUSS; - problem_data->true_solution = RichardTrue3D; - problem_data->true_solution_loc = RichardTrue3D_loc; - problem_data->rhs_u0 = RichardRhsU03D; - problem_data->rhs_u0_loc = RichardRhsU03D_loc; - problem_data->ics_u = RichardICsU3D; - problem_data->ics_u_loc = RichardICsU3D_loc; - problem_data->rhs_p0 = RichardRhsP03D; - problem_data->rhs_p0_loc = RichardRhsP03D_loc; - problem_data->ics_p = RichardICsP3D; - problem_data->ics_p_loc = RichardICsP3D_loc; - problem_data->residual = RichardSystem3D; - problem_data->residual_loc = RichardSystem3D_loc; - //problem_data->jacobian = JacobianRichardSystem2D; - //problem_data->jacobian_loc = JacobianRichardSystem2D_loc; - problem_data->error = DarcyError3D; - problem_data->error_loc = DarcyError3D_loc; - //problem_data->bc_pressure = BCPressure2D; - //problem_data->bc_pressure_loc = BCPressure2D_loc; - problem_data->post_rhs = PostProcessingRhs3D; - problem_data->post_rhs_loc = PostProcessingRhs3D_loc; - problem_data->post_mass = PostProcessingMass3D; - problem_data->post_mass_loc = PostProcessingMass3D_loc; - problem_data->has_ts = PETSC_TRUE; - problem_data->view_solution = app_ctx->view_solution; + problem_data->dim = 3; + problem_data->elem_node = 8; + problem_data->q_data_size_face = 4; + problem_data->quadrature_mode = CEED_GAUSS; + problem_data->true_solution = RichardTrue3D; + problem_data->true_solution_loc = RichardTrue3D_loc; + problem_data->rhs_u0 = RichardRhsU03D; + problem_data->rhs_u0_loc = RichardRhsU03D_loc; + problem_data->ics_u = RichardICsU3D; + problem_data->ics_u_loc = RichardICsU3D_loc; + problem_data->rhs_p0 = RichardRhsP03D; + problem_data->rhs_p0_loc = RichardRhsP03D_loc; + problem_data->ics_p = RichardICsP3D; + problem_data->ics_p_loc = RichardICsP3D_loc; + problem_data->residual = RichardSystem3D; + problem_data->residual_loc = RichardSystem3D_loc; + // problem_data->jacobian = JacobianRichardSystem2D; + // problem_data->jacobian_loc = JacobianRichardSystem2D_loc; + problem_data->error = DarcyError3D; + problem_data->error_loc = DarcyError3D_loc; + // problem_data->bc_pressure = BCPressure2D; + // problem_data->bc_pressure_loc = BCPressure2D_loc; + problem_data->post_rhs = PostProcessingRhs3D; + problem_data->post_rhs_loc = PostProcessingRhs3D_loc; + problem_data->post_mass = PostProcessingMass3D; + problem_data->post_mass_loc = PostProcessingMass3D_loc; + problem_data->has_ts = PETSC_TRUE; + problem_data->view_solution = app_ctx->view_solution; // ------------------------------------------------------ // Command line Options // ------------------------------------------------------ - CeedScalar kappa = 10., alpha_a = 1., b_a = 10., rho_a0 = 998.2, - beta = 0., g = 9.8, p0 = 101325; + CeedScalar kappa = 10., alpha_a = 1., b_a = 10., rho_a0 = 998.2, beta = 0., g = 9.8, p0 = 101325; PetscOptionsBegin(app_ctx->comm, NULL, "Options for Hdiv-mixed problem", NULL); - PetscCall( PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, - kappa, &kappa, NULL)); - PetscCall( PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", - NULL, - alpha_a, &alpha_a, NULL)); - PetscCall( PetscOptionsScalar("-b_a", "Parameter for relative permeability", - NULL, - b_a, &b_a, NULL)); - PetscCall( PetscOptionsScalar("-rho_a0", "Density at p0", NULL, - rho_a0, &rho_a0, NULL)); - PetscCall( PetscOptionsScalar("-beta", "Water compressibility", NULL, - beta, &beta, NULL)); + PetscCall(PetscOptionsScalar("-kappa", "Hydraulic Conductivity", NULL, kappa, &kappa, NULL)); + PetscCall(PetscOptionsScalar("-alpha_a", "Parameter for relative permeability", NULL, alpha_a, &alpha_a, NULL)); + PetscCall(PetscOptionsScalar("-b_a", "Parameter for relative permeability", NULL, b_a, &b_a, NULL)); + PetscCall(PetscOptionsScalar("-rho_a0", "Density at p0", NULL, rho_a0, &rho_a0, NULL)); + PetscCall(PetscOptionsScalar("-beta", "Water compressibility", NULL, beta, &beta, NULL)); app_ctx->t_final = 0.5; - PetscCall( PetscOptionsScalar("-t_final", "End time", NULL, - app_ctx->t_final, &app_ctx->t_final, NULL)); + PetscCall(PetscOptionsScalar("-t_final", "End time", NULL, app_ctx->t_final, &app_ctx->t_final, NULL)); PetscOptionsEnd(); PetscReal domain_min[3], domain_max[3], domain_size[3]; - PetscCall( DMGetBoundingBox(dm, domain_min, domain_max) ); - for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; + PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); + for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; - richard_ctx->kappa = kappa; + richard_ctx->kappa = kappa; richard_ctx->alpha_a = alpha_a; - richard_ctx->b_a = b_a; - richard_ctx->rho_a0 = rho_a0; - richard_ctx->beta = beta; - richard_ctx->g = g; - richard_ctx->p0 = p0; - richard_ctx->gamma = 5.; - richard_ctx->t = 0.; + richard_ctx->b_a = b_a; + richard_ctx->rho_a0 = rho_a0; + richard_ctx->beta = beta; + richard_ctx->g = g; + richard_ctx->p0 = p0; + richard_ctx->gamma = 5.; + richard_ctx->t = 0.; richard_ctx->t_final = app_ctx->t_final; - richard_ctx->lx = domain_size[0]; - richard_ctx->ly = domain_size[1]; - richard_ctx->lz = domain_size[2]; + richard_ctx->lx = domain_size[0]; + richard_ctx->ly = domain_size[1]; + richard_ctx->lz = domain_size[2]; CeedQFunctionContextCreate(ceed, &richard_context); - CeedQFunctionContextSetData(richard_context, CEED_MEM_HOST, CEED_COPY_VALUES, - sizeof(*richard_ctx), richard_ctx); - //CeedQFunctionContextSetDataDestroy(richard_context, CEED_MEM_HOST, - // FreeContextPetsc); - CeedQFunctionContextRegisterDouble(richard_context, "time", - offsetof(struct RICHARDContext_, t), 1, "current solver time"); - CeedQFunctionContextRegisterDouble(richard_context, "final_time", - offsetof(struct RICHARDContext_, t_final), 1, "final time"); - CeedQFunctionContextRegisterDouble(richard_context, "time_step", - offsetof(struct RICHARDContext_, dt), 1, "time step"); + CeedQFunctionContextSetData(richard_context, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(*richard_ctx), richard_ctx); + // CeedQFunctionContextSetDataDestroy(richard_context, CEED_MEM_HOST, + // FreeContextPetsc); + CeedQFunctionContextRegisterDouble(richard_context, "time", offsetof(struct RICHARDContext_, t), 1, "current solver time"); + CeedQFunctionContextRegisterDouble(richard_context, "final_time", offsetof(struct RICHARDContext_, t_final), 1, "final time"); + CeedQFunctionContextRegisterDouble(richard_context, "time_step", offsetof(struct RICHARDContext_, dt), 1, "time step"); problem_data->true_qfunction_ctx = richard_context; - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->rhs_u0_qfunction_ctx); - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->residual_qfunction_ctx); - CeedQFunctionContextReferenceCopy(richard_context, - &problem_data->error_qfunction_ctx); - PetscCall( PetscFree(richard_ctx) ); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->rhs_u0_qfunction_ctx); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->residual_qfunction_ctx); + CeedQFunctionContextReferenceCopy(richard_context, &problem_data->error_qfunction_ctx); + PetscCall(PetscFree(richard_ctx)); PetscFunctionReturn(0); } diff --git a/examples/Hdiv-mixed/qfunctions/darcy-error2d.h b/examples/Hdiv-mixed/qfunctions/darcy-error2d.h index 62c574337b..1378260d2a 100644 --- a/examples/Hdiv-mixed/qfunctions/darcy-error2d.h +++ b/examples/Hdiv-mixed/qfunctions/darcy-error2d.h @@ -20,8 +20,9 @@ #ifndef DARCY_ERROR2D_H #define DARCY_ERROR2D_H -#include #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -38,43 +39,39 @@ struct DARCYContext_ { CeedScalar lx, ly; }; #endif -CEED_QFUNCTION(DarcyError2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyError2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*p) = (const CeedScalar(*))in[3], - (*true_soln) = in[4]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*p) = (const CeedScalar(*))in[3], (*true_soln) = in[4]; // Outputs - CeedScalar (*error) = out[0]; + CeedScalar(*error) = out[0]; // Context - DARCYContext context = (DARCYContext)ctx; - //const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; + DARCYContext context = (DARCYContext)ctx; + // const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include -#include "utils.h" +#include +#include "utils.h" // ----------------------------------------------------------------------------- // Compuet error @@ -39,45 +39,41 @@ struct DARCYContext_ { CeedScalar lx, ly, lz; }; #endif -CEED_QFUNCTION(DarcyError3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyError3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*p) = (const CeedScalar(*))in[3], - (*true_soln) = in[4]; + const CeedScalar(*w) = in[0], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*p) = (const CeedScalar(*))in[3], (*true_soln) = in[4]; // Outputs - CeedScalar (*error) = out[0]; + CeedScalar(*error) = out[0]; // Context - DARCYContext context = (DARCYContext)ctx; - //const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; + DARCYContext context = (DARCYContext)ctx; + // const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -68,29 +69,23 @@ struct DARCYContext_ { // ----------------------------------------------------------------------------- // Residual evaluation for Darcy problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(DarcySystemQuartic2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcySystemQuartic2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*div_u) = (const CeedScalar(*))in[3], - (*p) = (const CeedScalar(*))in[4], - (*f) = in[5]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*div_u) = (const CeedScalar(*))in[3], (*p) = (const CeedScalar(*))in[4], + (*f) = in[5]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], - (*div_v) = (CeedScalar(*))out[1], - (*q) = (CeedScalar(*))out[2]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], (*div_v) = (CeedScalar(*))out[1], (*q) = (CeedScalar(*))out[2]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -75,56 +76,52 @@ struct DARCYContext_ { // ----------------------------------------------------------------------------- // Residual evaluation for Darcy problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(DarcySystem2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcySystem2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*div_u) = (const CeedScalar(*))in[3], - (*p) = (const CeedScalar(*))in[4], - (*f) = in[5], - (*coords) = in[6]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*div_u) = (const CeedScalar(*))in[3], (*p) = (const CeedScalar(*))in[4], + (*f) = in[5], (*coords) = in[6]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], - (*div_v) = (CeedScalar(*))out[1], - (*q) = (CeedScalar(*))out[2]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], (*div_v) = (CeedScalar(*))out[1], (*q) = (CeedScalar(*))out[2]; // Context - DARCYContext context = (DARCYContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; ikappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -74,59 +75,53 @@ struct DARCYContext_ { // ----------------------------------------------------------------------------- // Residual evaluation for Darcy problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(DarcySystem3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcySystem3D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*div_u) = (const CeedScalar(*))in[3], - (*p) = (const CeedScalar(*))in[4], - (*f) = in[5], - (*coords) = in[6]; + const CeedScalar(*w) = in[0], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*div_u) = (const CeedScalar(*))in[3], (*p) = (const CeedScalar(*))in[4], + (*f) = in[5], (*coords) = in[6]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], - (*div_v) = (CeedScalar(*))out[1], - (*q) = (CeedScalar(*))out[2]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], (*div_v) = (CeedScalar(*))out[1], (*q) = (CeedScalar(*))out[2]; // Context - DARCYContext context = (DARCYContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; ikappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // *INDENT-ON* // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -56,43 +57,40 @@ struct DARCYContext_ { CeedScalar lx, ly; }; #endif -CEED_QFUNCTION(DarcyTrueQuartic2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyTrueQuartic2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0]; + const CeedScalar(*coords) = in[0]; // Outputs - CeedScalar (*true_force) = out[0], (*true_solution) = out[1]; + CeedScalar(*true_force) = out[0], (*true_solution) = out[1]; // Context - DARCYContext context = (DARCYContext)ctx; - const CeedScalar lx = context->lx; - const CeedScalar ly = context->ly; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar lx = context->lx; + const CeedScalar ly = context->ly; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -59,52 +60,47 @@ struct DARCYContext_ { CeedScalar lx, ly; }; #endif -CEED_QFUNCTION(DarcyTrue2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyTrue2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0]; + const CeedScalar(*coords) = in[0]; // Outputs - CeedScalar (*true_force) = out[0], (*true_solution) = out[1]; + CeedScalar(*true_force) = out[0], (*true_solution) = out[1]; // Context - DARCYContext context = (DARCYContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - const CeedScalar lx = context->lx; - const CeedScalar ly = context->ly; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + const CeedScalar lx = context->lx; + const CeedScalar ly = context->ly; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- @@ -59,59 +60,52 @@ struct DARCYContext_ { CeedScalar lx, ly, lz; }; #endif -CEED_QFUNCTION(DarcyTrue3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(DarcyTrue3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0]; + const CeedScalar(*coords) = in[0]; // Outputs - CeedScalar (*true_force) = out[0], (*true_soln) = out[1]; + CeedScalar(*true_force) = out[0], (*true_soln) = out[1]; // Context - DARCYContext context = (DARCYContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - const CeedScalar lx = context->lx; - const CeedScalar ly = context->ly; - const CeedScalar lz = context->lz; + DARCYContext context = (DARCYContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + const CeedScalar lx = context->lx; + const CeedScalar ly = context->ly; + const CeedScalar lz = context->lz; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -29,22 +30,20 @@ // We solve (v, u) = (v, uh), to project Hdiv to L2 space // This QFunction create post_rhs = (v, uh) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(PostProcessingRhs2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(PostProcessingRhs2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*post_rhs) = out[0]; + CeedScalar(*post_rhs) = out[0]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -29,23 +30,21 @@ // We solve (v, u) = (v, uh), to project Hdiv to L2 space // This QFunction create post_rhs = (v, uh) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(PostProcessingRhs3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(PostProcessingRhs3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*post_rhs) = out[0]; + CeedScalar(*post_rhs) = out[0]; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- // Strong form: @@ -33,24 +34,23 @@ // Note that the Piola map of the H(div) basis and physical normal "n" got canceled // and we need to multiply by the reference normal "N" on each face // ----------------------------------------------------------------------------- -CEED_QFUNCTION(BCPressure2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, CeedScalar *const *out) { +CEED_QFUNCTION(BCPressure2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0]; + const CeedScalar(*w) = in[0]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; // *INDENT-ON* // User context CeedPragmaSIMD - // Quadrature Point Loop - for (CeedInt i=0; i #include +#include + #include "utils.h" // ----------------------------------------------------------------------------- // Strong form: @@ -33,23 +34,22 @@ // Note that the Piola map of the H(div) basis and physical normal "n" got canceled // and we need to multiply by the reference normal "N" on each face // ----------------------------------------------------------------------------- -CEED_QFUNCTION(BCPressure3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, CeedScalar *const *out) { +CEED_QFUNCTION(BCPressure3D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0]; + const CeedScalar(*w) = in[0]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; // *INDENT-OFF* // User context CeedPragmaSIMD - // Quadrature Point Loop - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -76,73 +77,67 @@ struct RICHARDContext_ { // We solve (v, u) = (v, ue) at t=0, to project ue to Hdiv space // This QFunction create rhs_u0 = (v, ue) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardRhsU02D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardRhsU02D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*coords) = in[1], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*coords) = in[1], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*rhs_u0) = out[0]; + CeedScalar(*rhs_u0) = out[0]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -44,78 +45,71 @@ struct RICHARDContext_ { // We solve (v, u) = (v, ue) at t=0, to project ue to Hdiv space // This QFunction create rhs_u0 = (v, ue) // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardRhsU03D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardRhsU03D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*coords) = in[1], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; + const CeedScalar(*w) = in[0], (*coords) = in[1], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; // Outputs - CeedScalar (*rhs_u0) = out[0]; + CeedScalar(*rhs_u0) = out[0]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -81,68 +82,63 @@ struct RICHARDContext_ { // ----------------------------------------------------------------------------- // Residual evaluation for Richard problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardSystem2D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardSystem2D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*div_u) = (const CeedScalar(*))in[3], - (*p) = (const CeedScalar(*))in[4], - (*f) = in[5], - (*coords) = in[6], - (*p_t) = (const CeedScalar(*))in[7]; + const CeedScalar(*w) = in[0], (*dxdX)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*div_u) = (const CeedScalar(*))in[3], (*p) = (const CeedScalar(*))in[4], + (*f) = in[5], (*coords) = in[6], (*p_t) = (const CeedScalar(*))in[7]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], - (*div_v) = (CeedScalar(*))out[1], - (*q) = (CeedScalar(*))out[2]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], (*div_v) = (CeedScalar(*))out[1], (*q) = (CeedScalar(*))out[2]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - //const CeedScalar beta = context->beta; - //const CeedScalar p0 = context->p0; // atmospheric pressure - const CeedScalar gamma = context->gamma; - CeedScalar t = context->t; - //CeedScalar dt = context->dt; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + // const CeedScalar beta = context->beta; + // const CeedScalar p0 = context->p0; // atmospheric pressure + const CeedScalar gamma = context->gamma; + CeedScalar t = context->t; + // CeedScalar dt = context->dt; // *INDENT-ON* // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "ceed/ceed-f64.h" #include "utils.h" @@ -81,70 +82,64 @@ struct RICHARDContext_ { // ----------------------------------------------------------------------------- // Residual evaluation for Richard problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardSystem3D)(void *ctx, CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardSystem3D)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*w) = in[0], - (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], - (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], - (*div_u) = (const CeedScalar(*))in[3], - (*p) = (const CeedScalar(*))in[4], - (*f) = in[5], - (*coords) = in[6], - (*p_t) = (const CeedScalar(*))in[7]; + const CeedScalar(*w) = in[0], (*dxdX)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1], + (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*div_u) = (const CeedScalar(*))in[3], (*p) = (const CeedScalar(*))in[4], + (*f) = in[5], (*coords) = in[6], (*p_t) = (const CeedScalar(*))in[7]; // Outputs - CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], - (*div_v) = (CeedScalar(*))out[1], - (*q) = (CeedScalar(*))out[2]; + CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0], (*div_v) = (CeedScalar(*))out[1], (*q) = (CeedScalar(*))out[2]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar rho_a0 = context->rho_a0; - const CeedScalar g = context->g; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - //const CeedScalar beta = context->beta; - //const CeedScalar p0 = context->p0; // atmospheric pressure - const CeedScalar gamma = context->gamma; - CeedScalar t = context->t; - //CeedScalar dt = context->dt; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar rho_a0 = context->rho_a0; + const CeedScalar g = context->g; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + // const CeedScalar beta = context->beta; + // const CeedScalar p0 = context->p0; // atmospheric pressure + const CeedScalar gamma = context->gamma; + CeedScalar t = context->t; + // CeedScalar dt = context->dt; // *INDENT-ON* // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // See Matthew Farthing, Christopher Kees, Cass Miller (2003) @@ -74,58 +75,53 @@ struct RICHARDContext_ { // ----------------------------------------------------------------------------- // True solution for Richard problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardTrue2D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardTrue2D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0]; + const CeedScalar(*coords) = in[0]; // Outputs - CeedScalar (*true_force) = out[0], (*true_solution) = out[1]; + CeedScalar(*true_force) = out[0], (*true_solution) = out[1]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - const CeedScalar gamma = context->gamma; - CeedScalar t_final = context->t_final; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + const CeedScalar gamma = context->gamma; + CeedScalar t_final = context->t_final; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i #include +#include + #include "utils.h" // See Matthew Farthing, Christopher Kees, Cass Miller (2003) @@ -74,64 +75,58 @@ struct RICHARDContext_ { // ----------------------------------------------------------------------------- // True solution for Richard problem // ----------------------------------------------------------------------------- -CEED_QFUNCTION(RichardTrue3D)(void *ctx, const CeedInt Q, - const CeedScalar *const *in, - CeedScalar *const *out) { +CEED_QFUNCTION(RichardTrue3D)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs - const CeedScalar (*coords) = in[0]; + const CeedScalar(*coords) = in[0]; // Outputs - CeedScalar (*true_force) = out[0], (*true_solution) = out[1]; + CeedScalar(*true_force) = out[0], (*true_solution) = out[1]; // Context - RICHARDContext context = (RICHARDContext)ctx; - const CeedScalar kappa = context->kappa; - const CeedScalar alpha_a = context->alpha_a; - const CeedScalar b_a = context->b_a; - const CeedScalar gamma = context->gamma; - CeedScalar t_final = context->t_final; + RICHARDContext context = (RICHARDContext)ctx; + const CeedScalar kappa = context->kappa; + const CeedScalar alpha_a = context->alpha_a; + const CeedScalar b_a = context->b_a; + const CeedScalar gamma = context->gamma; + CeedScalar t_final = context->t_final; // Quadrature Point Loop - CeedPragmaSIMD - for (CeedInt i=0; i +#include "ceed/ceed-f64.h" + #define PI_DOUBLE 3.14159265358979323846 // ----------------------------------------------------------------------------- // Compute alpha * A * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { +CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { for (CeedInt j = 0; j < 3; j++) { for (CeedInt k = 0; k < 3; k++) { C[j][k] = 0; @@ -29,8 +29,8 @@ CEED_QFUNCTION_HELPER int AlphaMatMatMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A^T * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar B[3][3], CeedScalar C[3][3]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar B[3][3], + CeedScalar C[3][3]) { for (CeedInt j = 0; j < 3; j++) { for (CeedInt k = 0; k < 3; k++) { C[j][k] = 0; @@ -48,26 +48,24 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- CEED_QFUNCTION_HELPER CeedScalar MatDet3x3(const CeedScalar A[3][3]) { // Compute det(A) - const CeedScalar B11 = A[1][1]*A[2][2] - A[1][2]*A[2][1]; - const CeedScalar B12 = A[0][2]*A[2][1] - A[0][1]*A[2][2]; - const CeedScalar B13 = A[0][1]*A[1][2] - A[0][2]*A[1][1]; - return A[0][0]*B11 + A[1][0]*B12 + A[2][0]*B13; - + const CeedScalar B11 = A[1][1] * A[2][2] - A[1][2] * A[2][1]; + const CeedScalar B12 = A[0][2] * A[2][1] - A[0][1] * A[2][2]; + const CeedScalar B13 = A[0][1] * A[1][2] - A[0][2] * A[1][1]; + return A[0][0] * B11 + A[1][0] * B12 + A[2][0] * B13; }; // ----------------------------------------------------------------------------- // Compute inverse of 3x3 symmetric matrix // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], - const CeedScalar det_A, CeedScalar A_inv[3][3]) { +CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], const CeedScalar det_A, CeedScalar A_inv[3][3]) { // Compute A^(-1) : A-Inverse CeedScalar B[6] = { - A[1][1] * A[2][2] - A[1][2] * A[2][1], /* *NOPAD* */ - A[0][0] * A[2][2] - A[0][2] * A[2][0], /* *NOPAD* */ - A[0][0] * A[1][1] - A[0][1] * A[1][0], /* *NOPAD* */ - A[0][2] * A[1][0] - A[0][0] * A[1][2], /* *NOPAD* */ - A[0][1] * A[1][2] - A[0][2] * A[1][1], /* *NOPAD* */ - A[0][2] * A[2][1] - A[0][1] * A[2][2] /* *NOPAD* */ + A[1][1] * A[2][2] - A[1][2] * A[2][1], /* *NOPAD* */ + A[0][0] * A[2][2] - A[0][2] * A[2][0], /* *NOPAD* */ + A[0][0] * A[1][1] - A[0][1] * A[1][0], /* *NOPAD* */ + A[0][2] * A[1][0] - A[0][0] * A[1][2], /* *NOPAD* */ + A[0][1] * A[1][2] - A[0][2] * A[1][1], /* *NOPAD* */ + A[0][2] * A[2][1] - A[0][1] * A[2][2] /* *NOPAD* */ }; CeedScalar A_inv1[6]; for (CeedInt m = 0; m < 6; m++) { @@ -88,13 +86,11 @@ CEED_QFUNCTION_HELPER int MatInverse3x3(const CeedScalar A[3][3], // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { +CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { // Compute v = alpha*A*u for (CeedInt k = 0; k < 3; k++) { v[k] = 0; - for (CeedInt m = 0; m < 3; m++) - v[k] += A[k][m] * u[m] * alpha; + for (CeedInt m = 0; m < 3; m++) v[k] += A[k][m] * u[m] * alpha; } return 0; @@ -103,13 +99,11 @@ CEED_QFUNCTION_HELPER int AlphaMatVecMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A^T*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, - const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, const CeedScalar A[3][3], const CeedScalar u[3], CeedScalar v[3]) { // Compute v = alpha*A^T*u for (CeedInt k = 0; k < 3; k++) { v[k] = 0; - for (CeedInt m = 0; m < 3; m++) - v[k] += A[m][k] * u[m] * alpha; + for (CeedInt m = 0; m < 3; m++) v[k] += A[m][k] * u[m] * alpha; } return 0; @@ -118,8 +112,7 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult3x3(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { +CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { for (CeedInt j = 0; j < 2; j++) { for (CeedInt k = 0; k < 2; k++) { C[j][k] = 0; @@ -135,8 +128,8 @@ CEED_QFUNCTION_HELPER int AlphaMatMatMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute alpha * A^T * B = C // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar B[2][2], CeedScalar C[2][2]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar B[2][2], + CeedScalar C[2][2]) { for (CeedInt j = 0; j < 2; j++) { for (CeedInt k = 0; k < 2; k++) { C[j][k] = 0; @@ -154,20 +147,18 @@ CEED_QFUNCTION_HELPER int AlphaMatTransposeMatMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- CEED_QFUNCTION_HELPER CeedScalar MatDet2x2(const CeedScalar A[2][2]) { // Compute det(A) - return A[0][0]*A[1][1] - A[1][0]*A[0][1]; - + return A[0][0] * A[1][1] - A[1][0] * A[0][1]; }; // ----------------------------------------------------------------------------- // Compute inverse of 2x2 symmetric matrix // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], - const CeedScalar det_A, CeedScalar A_inv[2][2]) { +CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], const CeedScalar det_A, CeedScalar A_inv[2][2]) { // Compute A^(-1) : A-Inverse - A_inv[0][0] = A[1][1]/ det_A; - A_inv[0][1] = -A[0][1]/ det_A; - A_inv[1][0] = -A[1][0]/ det_A; - A_inv[1][1] = A[0][0]/ det_A; + A_inv[0][0] = A[1][1] / det_A; + A_inv[0][1] = -A[0][1] / det_A; + A_inv[1][0] = -A[1][0] / det_A; + A_inv[1][1] = A[0][0] / det_A; return 0; }; @@ -175,13 +166,11 @@ CEED_QFUNCTION_HELPER int MatInverse2x2(const CeedScalar A[2][2], // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { +CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { // Compute v = alpha*A*u for (CeedInt k = 0; k < 2; k++) { v[k] = 0; - for (CeedInt m = 0; m < 2; m++) - v[k] += A[k][m] * u[m] * alpha; + for (CeedInt m = 0; m < 2; m++) v[k] += A[k][m] * u[m] * alpha; } return 0; @@ -190,13 +179,11 @@ CEED_QFUNCTION_HELPER int AlphaMatVecMult2x2(const CeedScalar alpha, // ----------------------------------------------------------------------------- // Compute matrix-vector product: alpha*A^T*u // ----------------------------------------------------------------------------- -CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult2x2(const CeedScalar alpha, - const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { +CEED_QFUNCTION_HELPER int AlphaMatTransposeVecMult2x2(const CeedScalar alpha, const CeedScalar A[2][2], const CeedScalar u[2], CeedScalar v[2]) { // Compute v = alpha*A^T*u for (CeedInt k = 0; k < 2; k++) { v[k] = 0; - for (CeedInt m = 0; m < 2; m++) - v[k] += A[m][k] * u[m] * alpha; + for (CeedInt m = 0; m < 2; m++) v[k] += A[m][k] * u[m] * alpha; } return 0; diff --git a/examples/Hdiv-mixed/src/cl-options.c b/examples/Hdiv-mixed/src/cl-options.c index 85c18442e2..0d67fedb59 100644 --- a/examples/Hdiv-mixed/src/cl-options.c +++ b/examples/Hdiv-mixed/src/cl-options.c @@ -21,17 +21,14 @@ // Process general command line options PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx) { - PetscBool problem_flag = PETSC_FALSE; - PetscBool ceed_flag = PETSC_FALSE; + PetscBool ceed_flag = PETSC_FALSE; PetscFunctionBeginUser; - PetscOptionsBegin(app_ctx->comm, NULL, "H(div) examples in PETSc with libCEED", - NULL); + PetscOptionsBegin(app_ctx->comm, NULL, "H(div) examples in PETSc with libCEED", NULL); - PetscCall( PetscOptionsString("-ceed", "CEED resource specifier", - NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, - sizeof(app_ctx->ceed_resource), &ceed_flag) ); + PetscCall(PetscOptionsString("-ceed", "CEED resource specifier", NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, + sizeof(app_ctx->ceed_resource), &ceed_flag)); // Provide default ceed resource if not specified if (!ceed_flag) { @@ -39,48 +36,31 @@ PetscErrorCode ProcessCommandLineOptions(AppCtx app_ctx) { strncpy(app_ctx->ceed_resource, ceed_resource, 10); } - PetscCall( PetscOptionsFList("-problem", "Problem to solve", NULL, - app_ctx->problems, - app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), - &problem_flag) ); + PetscCall(PetscOptionsFList("-problem", "Problem to solve", NULL, app_ctx->problems, app_ctx->problem_name, app_ctx->problem_name, + sizeof(app_ctx->problem_name), &problem_flag)); // Provide default problem if not specified if (!problem_flag) { const char *problem_name = "darcy2d"; strncpy(app_ctx->problem_name, problem_name, 16); } app_ctx->degree = 1; - PetscCall( PetscOptionsInt("-degree", "Polynomial degree of finite elements", - NULL, app_ctx->degree, &app_ctx->degree, NULL) ); + PetscCall(PetscOptionsInt("-degree", "Polynomial degree of finite elements", NULL, app_ctx->degree, &app_ctx->degree, NULL)); app_ctx->q_extra = 0; - PetscCall( PetscOptionsInt("-q_extra", "Number of extra quadrature points", - NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL) ); + PetscCall(PetscOptionsInt("-q_extra", "Number of extra quadrature points", NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL)); app_ctx->view_solution = PETSC_FALSE; - PetscCall( PetscOptionsBool("-view_solution", - "View solution in Paraview", - NULL, app_ctx->view_solution, - &(app_ctx->view_solution), NULL) ); + PetscCall(PetscOptionsBool("-view_solution", "View solution in Paraview", NULL, app_ctx->view_solution, &(app_ctx->view_solution), NULL)); app_ctx->quartic = PETSC_FALSE; - PetscCall( PetscOptionsBool("-quartic", - "To test PetscViewer", - NULL, app_ctx->quartic, - &(app_ctx->quartic), NULL) ); + PetscCall(PetscOptionsBool("-quartic", "To test PetscViewer", NULL, app_ctx->quartic, &(app_ctx->quartic), NULL)); - PetscCall( PetscStrncpy(app_ctx->output_dir, ".", 2) ); - PetscCall( PetscOptionsString("-output_dir", "Output directory", - NULL, app_ctx->output_dir, app_ctx->output_dir, - sizeof(app_ctx->output_dir), NULL) ); + PetscCall(PetscStrncpy(app_ctx->output_dir, ".", 2)); + PetscCall(PetscOptionsString("-output_dir", "Output directory", NULL, app_ctx->output_dir, app_ctx->output_dir, sizeof(app_ctx->output_dir), NULL)); app_ctx->output_freq = 10; - PetscCall( PetscOptionsInt("-output_freq", - "Frequency of output, in number of steps", - NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL) ); + PetscCall(PetscOptionsInt("-output_freq", "Frequency of output, in number of steps", NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL)); app_ctx->bc_pressure_count = 16; // we can set one face by: -bc_faces 1 OR multiple faces by :-bc_faces 1,2,3 - PetscCall( PetscOptionsIntArray("-bc_faces", - "Face IDs to apply pressure BC", - NULL, app_ctx->bc_faces, &app_ctx->bc_pressure_count, NULL) ); - + PetscCall(PetscOptionsIntArray("-bc_faces", "Face IDs to apply pressure BC", NULL, app_ctx->bc_faces, &app_ctx->bc_pressure_count, NULL)); PetscOptionsEnd(); diff --git a/examples/Hdiv-mixed/src/post-processing.c b/examples/Hdiv-mixed/src/post-processing.c index df94038ed4..2a99a61cf3 100644 --- a/examples/Hdiv-mixed/src/post-processing.c +++ b/examples/Hdiv-mixed/src/post-processing.c @@ -1,272 +1,244 @@ #include "../include/post-processing.h" + #include "../include/setup-solvers.h" #include "ceed/ceed.h" // ----------------------------------------------------------------------------- // This function print the output // ----------------------------------------------------------------------------- -PetscErrorCode PrintOutput(DM dm, Ceed ceed, AppCtx app_ctx, PetscBool has_ts, - CeedMemType mem_type_backend, - TS ts, SNES snes, KSP ksp, - Vec U, CeedScalar l2_error_u, CeedScalar l2_error_p) { - +PetscErrorCode PrintOutput(DM dm, Ceed ceed, AppCtx app_ctx, PetscBool has_ts, CeedMemType mem_type_backend, TS ts, SNES snes, KSP ksp, Vec U, + CeedScalar l2_error_u, CeedScalar l2_error_p) { PetscFunctionBeginUser; const char *used_resource; CeedGetResource(ceed, &used_resource); char hostname[PETSC_MAX_PATH_LEN]; - PetscCall( PetscGetHostName(hostname, sizeof hostname) ); + PetscCall(PetscGetHostName(hostname, sizeof hostname)); PetscInt comm_size; - PetscCall( MPI_Comm_size(app_ctx->comm, &comm_size) ); - PetscCall( PetscPrintf(app_ctx->comm, - "\n-- Mixed H(div) Example - libCEED + PETSc --\n" - " MPI:\n" - " Hostname : %s\n" - " Total ranks : %d\n" - " libCEED:\n" - " libCEED Backend : %s\n" - " libCEED Backend MemType : %s\n", - hostname, comm_size, used_resource, CeedMemTypes[mem_type_backend]) ); + PetscCall(MPI_Comm_size(app_ctx->comm, &comm_size)); + PetscCall(PetscPrintf(app_ctx->comm, + "\n-- Mixed H(div) Example - libCEED + PETSc --\n" + " MPI:\n" + " Hostname : %s\n" + " Total ranks : %d\n" + " libCEED:\n" + " libCEED Backend : %s\n" + " libCEED Backend MemType : %s\n", + hostname, comm_size, used_resource, CeedMemTypes[mem_type_backend])); MatType mat_type; VecType vec_type; - PetscCall( DMGetMatType(dm, &mat_type) ); - PetscCall( DMGetVecType(dm, &vec_type) ); - PetscCall( PetscPrintf(app_ctx->comm, - " PETSc:\n" - " DM MatType : %s\n" - " DM VecType : %s\n", - mat_type, vec_type) ); - - PetscInt U_l_size, U_g_size; - PetscCall( VecGetSize(U, &U_g_size) ); - PetscCall( VecGetLocalSize(U, &U_l_size) ); - PetscCall( PetscPrintf(app_ctx->comm, - " Problem:\n" - " Problem Name : %s\n" - " Global nodes (u + p) : %" PetscInt_FMT "\n" - " Owned nodes (u + p) : %" PetscInt_FMT "\n", - app_ctx->problem_name, U_g_size, U_l_size - ) ); + PetscCall(DMGetMatType(dm, &mat_type)); + PetscCall(DMGetVecType(dm, &vec_type)); + PetscCall(PetscPrintf(app_ctx->comm, + " PETSc:\n" + " DM MatType : %s\n" + " DM VecType : %s\n", + mat_type, vec_type)); + + PetscInt U_l_size, U_g_size; + PetscCall(VecGetSize(U, &U_g_size)); + PetscCall(VecGetLocalSize(U, &U_l_size)); + PetscCall(PetscPrintf(app_ctx->comm, + " Problem:\n" + " Problem Name : %s\n" + " Global nodes (u + p) : %" PetscInt_FMT "\n" + " Owned nodes (u + p) : %" PetscInt_FMT "\n", + app_ctx->problem_name, U_g_size, U_l_size)); // --TS if (has_ts) { - PetscInt ts_steps; - TSType ts_type; + PetscInt ts_steps; + TSType ts_type; TSConvergedReason ts_reason; - PetscCall( TSGetStepNumber(ts, &ts_steps) ); - PetscCall( TSGetType(ts, &ts_type) ); - PetscCall( TSGetConvergedReason(ts, &ts_reason) ); - PetscCall( PetscPrintf(app_ctx->comm, - " TS:\n" - " TS Type : %s\n" - " TS Convergence : %s\n" - " Number of TS steps : %" PetscInt_FMT "\n" - " Final time : %g\n", - ts_type, TSConvergedReasons[ts_reason], - ts_steps, (double)app_ctx->t_final) ); - - PetscCall( TSGetSNES(ts, &snes) ); + PetscCall(TSGetStepNumber(ts, &ts_steps)); + PetscCall(TSGetType(ts, &ts_type)); + PetscCall(TSGetConvergedReason(ts, &ts_reason)); + PetscCall(PetscPrintf(app_ctx->comm, + " TS:\n" + " TS Type : %s\n" + " TS Convergence : %s\n" + " Number of TS steps : %" PetscInt_FMT "\n" + " Final time : %g\n", + ts_type, TSConvergedReasons[ts_reason], ts_steps, (double)app_ctx->t_final)); + + PetscCall(TSGetSNES(ts, &snes)); } // -- SNES PetscInt its, snes_its = 0; - PetscCall( SNESGetIterationNumber(snes, &its) ); + PetscCall(SNESGetIterationNumber(snes, &its)); snes_its += its; - SNESType snes_type; + SNESType snes_type; SNESConvergedReason snes_reason; - PetscReal snes_rnorm; - PetscCall( SNESGetType(snes, &snes_type) ); - PetscCall( SNESGetConvergedReason(snes, &snes_reason) ); - PetscCall( SNESGetFunctionNorm(snes, &snes_rnorm) ); - PetscCall( PetscPrintf(app_ctx->comm, - " SNES:\n" - " SNES Type : %s\n" - " SNES Convergence : %s\n" - " Total SNES Iterations : %" PetscInt_FMT "\n" - " Final rnorm : %e\n", - snes_type, SNESConvergedReasons[snes_reason], - snes_its, (double)snes_rnorm) ); + PetscReal snes_rnorm; + PetscCall(SNESGetType(snes, &snes_type)); + PetscCall(SNESGetConvergedReason(snes, &snes_reason)); + PetscCall(SNESGetFunctionNorm(snes, &snes_rnorm)); + PetscCall(PetscPrintf(app_ctx->comm, + " SNES:\n" + " SNES Type : %s\n" + " SNES Convergence : %s\n" + " Total SNES Iterations : %" PetscInt_FMT "\n" + " Final rnorm : %e\n", + snes_type, SNESConvergedReasons[snes_reason], snes_its, (double)snes_rnorm)); if (!has_ts) { PetscInt ksp_its = 0; - PetscCall( SNESGetLinearSolveIterations(snes, &its) ); + PetscCall(SNESGetLinearSolveIterations(snes, &its)); ksp_its += its; - KSPType ksp_type; + KSPType ksp_type; KSPConvergedReason ksp_reason; - PetscReal ksp_rnorm; - PC pc; - PCType pc_type; - PetscCall( KSPGetPC(ksp, &pc) ); - PetscCall( PCGetType(pc, &pc_type) ); - PetscCall( KSPGetType(ksp, &ksp_type) ); - PetscCall( KSPGetConvergedReason(ksp, &ksp_reason) ); - PetscCall( KSPGetIterationNumber(ksp, &ksp_its) ); - PetscCall( KSPGetResidualNorm(ksp, &ksp_rnorm) ); - PetscCall( PetscPrintf(app_ctx->comm, - " KSP:\n" - " KSP Type : %s\n" - " PC Type : %s\n" - " KSP Convergence : %s\n" - " Total KSP Iterations : %" PetscInt_FMT "\n" - " Final rnorm : %e\n", - ksp_type, pc_type, KSPConvergedReasons[ksp_reason], ksp_its, - (double)ksp_rnorm ) ); + PetscReal ksp_rnorm; + PC pc; + PCType pc_type; + PetscCall(KSPGetPC(ksp, &pc)); + PetscCall(PCGetType(pc, &pc_type)); + PetscCall(KSPGetType(ksp, &ksp_type)); + PetscCall(KSPGetConvergedReason(ksp, &ksp_reason)); + PetscCall(KSPGetIterationNumber(ksp, &ksp_its)); + PetscCall(KSPGetResidualNorm(ksp, &ksp_rnorm)); + PetscCall(PetscPrintf(app_ctx->comm, + " KSP:\n" + " KSP Type : %s\n" + " PC Type : %s\n" + " KSP Convergence : %s\n" + " Total KSP Iterations : %" PetscInt_FMT "\n" + " Final rnorm : %e\n", + ksp_type, pc_type, KSPConvergedReasons[ksp_reason], ksp_its, (double)ksp_rnorm)); } - PetscCall( PetscPrintf(app_ctx->comm, - " L2 Error (MMS):\n" - " L2 error of u and p : %e, %e\n", - (double)l2_error_u, - (double)l2_error_p) ); + PetscCall(PetscPrintf(app_ctx->comm, + " L2 Error (MMS):\n" + " L2 error of u and p : %e, %e\n", + (double)l2_error_u, (double)l2_error_p)); PetscFunctionReturn(0); }; // ----------------------------------------------------------------------------- // Setup operator context data for initial condition, u field // ----------------------------------------------------------------------------- -PetscErrorCode SetupProjectVelocityCtx_Hdiv(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, - OperatorApplyContext ctx_Hdiv) { +PetscErrorCode SetupProjectVelocityCtx_Hdiv(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_Hdiv) { PetscFunctionBeginUser; ctx_Hdiv->comm = comm; - ctx_Hdiv->dm = dm; - PetscCall( DMCreateLocalVector(dm, &ctx_Hdiv->X_loc) ); + ctx_Hdiv->dm = dm; + PetscCall(DMCreateLocalVector(dm, &ctx_Hdiv->X_loc)); ctx_Hdiv->x_ceed = ceed_data->u_ceed; - //ctx_project_velocity->y_ceed = ceed_data->v0_ceed; + // ctx_project_velocity->y_ceed = ceed_data->v0_ceed; ctx_Hdiv->ceed = ceed; - //ctx_project_velocity->op_apply = ceed_data->op_ics_u; + // ctx_project_velocity->op_apply = ceed_data->op_ics_u; PetscFunctionReturn(0); } -PetscErrorCode SetupProjectVelocityCtx_H1(MPI_Comm comm, DM dm_H1, Ceed ceed, - CeedData ceed_data, VecType vec_type, - OperatorApplyContext ctx_H1) { +PetscErrorCode SetupProjectVelocityCtx_H1(MPI_Comm comm, DM dm_H1, Ceed ceed, CeedData ceed_data, VecType vec_type, OperatorApplyContext ctx_H1) { PetscFunctionBeginUser; ctx_H1->comm = comm; - ctx_H1->dm = dm_H1; - PetscCall( DMCreateLocalVector(dm_H1, &ctx_H1->X_loc) ); - PetscCall( VecDuplicate(ctx_H1->X_loc, &ctx_H1->Y_loc) ); - ctx_H1->x_ceed = ceed_data->up_ceed; - ctx_H1->y_ceed = ceed_data->vp_ceed; - ctx_H1->x_coord = ceed_data->x_coord; - ctx_H1->ceed = ceed; - ctx_H1->op_apply = ceed_data->op_post_mass; - ctx_H1->op_rhs_H1 = ceed_data->op_rhs_H1; + ctx_H1->dm = dm_H1; + PetscCall(DMCreateLocalVector(dm_H1, &ctx_H1->X_loc)); + PetscCall(VecDuplicate(ctx_H1->X_loc, &ctx_H1->Y_loc)); + ctx_H1->x_ceed = ceed_data->up_ceed; + ctx_H1->y_ceed = ceed_data->vp_ceed; + ctx_H1->x_coord = ceed_data->x_coord; + ctx_H1->ceed = ceed; + ctx_H1->op_apply = ceed_data->op_post_mass; + ctx_H1->op_rhs_H1 = ceed_data->op_rhs_H1; ctx_H1->elem_restr_u_H1 = ceed_data->elem_restr_u_H1; - ctx_H1->vec_type = vec_type; + ctx_H1->vec_type = vec_type; PetscFunctionReturn(0); } // ----------------------------------------------------------------------------- // This function print the output // ----------------------------------------------------------------------------- -PetscErrorCode ProjectVelocity(AppCtx app_ctx, - Vec U, Vec *U_H1) { - +PetscErrorCode ProjectVelocity(AppCtx app_ctx, Vec U, Vec *U_H1) { PetscFunctionBeginUser; const PetscScalar *x; - PetscMemType x_mem_type; + PetscMemType x_mem_type; // ---------------------------------------------- // Create local rhs for u field // ---------------------------------------------- - Vec rhs_loc_H1; + Vec rhs_loc_H1; PetscScalar *ru; PetscMemType ru_mem_type; - PetscCall( DMCreateLocalVector(app_ctx->ctx_H1->dm, &rhs_loc_H1) ); - PetscCall( VecZeroEntries(rhs_loc_H1) ); - PetscCall( VecGetArrayAndMemType(rhs_loc_H1, &ru, &ru_mem_type) ); - CeedElemRestrictionCreateVector(app_ctx->ctx_H1->elem_restr_u_H1, - &app_ctx->ctx_H1->rhs_ceed_H1, - NULL); - CeedVectorSetArray(app_ctx->ctx_H1->rhs_ceed_H1, MemTypeP2C(ru_mem_type), - CEED_USE_POINTER, ru); + PetscCall(DMCreateLocalVector(app_ctx->ctx_H1->dm, &rhs_loc_H1)); + PetscCall(VecZeroEntries(rhs_loc_H1)); + PetscCall(VecGetArrayAndMemType(rhs_loc_H1, &ru, &ru_mem_type)); + CeedElemRestrictionCreateVector(app_ctx->ctx_H1->elem_restr_u_H1, &app_ctx->ctx_H1->rhs_ceed_H1, NULL); + CeedVectorSetArray(app_ctx->ctx_H1->rhs_ceed_H1, MemTypeP2C(ru_mem_type), CEED_USE_POINTER, ru); // Global-to-local: map final U in Hdiv space to local vector - PetscCall( DMGlobalToLocal(app_ctx->ctx_Hdiv->dm, - U, INSERT_VALUES, app_ctx->ctx_Hdiv->X_loc) ); + PetscCall(DMGlobalToLocal(app_ctx->ctx_Hdiv->dm, U, INSERT_VALUES, app_ctx->ctx_Hdiv->X_loc)); // Place Hdiv PETSc vectors in CEED vectors - PetscCall( VecGetArrayReadAndMemType(app_ctx->ctx_Hdiv->X_loc, - &x, &x_mem_type) ); - CeedVectorSetArray(app_ctx->ctx_Hdiv->x_ceed, MemTypeP2C(x_mem_type), - CEED_USE_POINTER, (PetscScalar *)x); + PetscCall(VecGetArrayReadAndMemType(app_ctx->ctx_Hdiv->X_loc, &x, &x_mem_type)); + CeedVectorSetArray(app_ctx->ctx_Hdiv->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, (PetscScalar *)x); // Apply operator to create RHS for u field - CeedOperatorApply(app_ctx->ctx_H1->op_rhs_H1, app_ctx->ctx_H1->x_coord, - app_ctx->ctx_H1->rhs_ceed_H1, CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(app_ctx->ctx_H1->op_rhs_H1, app_ctx->ctx_H1->x_coord, app_ctx->ctx_H1->rhs_ceed_H1, CEED_REQUEST_IMMEDIATE); // Restore Hdiv vector - CeedVectorTakeArray(app_ctx->ctx_Hdiv->x_ceed, - MemTypeP2C(x_mem_type), NULL); - PetscCall( VecRestoreArrayReadAndMemType(app_ctx->ctx_Hdiv->X_loc, &x) ); + CeedVectorTakeArray(app_ctx->ctx_Hdiv->x_ceed, MemTypeP2C(x_mem_type), NULL); + PetscCall(VecRestoreArrayReadAndMemType(app_ctx->ctx_Hdiv->X_loc, &x)); // ---------------------------------------------- // Create global rhs for u field // ---------------------------------------------- Vec rhs_H1; - CeedVectorTakeArray(app_ctx->ctx_H1->rhs_ceed_H1, MemTypeP2C(ru_mem_type), - NULL); - PetscCall( VecRestoreArrayAndMemType(rhs_loc_H1, &ru) ); - PetscCall( DMCreateGlobalVector(app_ctx->ctx_H1->dm, &rhs_H1) ); - PetscCall( VecZeroEntries(rhs_H1) ); - PetscCall( DMLocalToGlobal(app_ctx->ctx_H1->dm, rhs_loc_H1, ADD_VALUES, - rhs_H1) ); + CeedVectorTakeArray(app_ctx->ctx_H1->rhs_ceed_H1, MemTypeP2C(ru_mem_type), NULL); + PetscCall(VecRestoreArrayAndMemType(rhs_loc_H1, &ru)); + PetscCall(DMCreateGlobalVector(app_ctx->ctx_H1->dm, &rhs_H1)); + PetscCall(VecZeroEntries(rhs_H1)); + PetscCall(DMLocalToGlobal(app_ctx->ctx_H1->dm, rhs_loc_H1, ADD_VALUES, rhs_H1)); // ---------------------------------------------- // Solve for U_H1, M*U_H1 = rhs_H1 // ---------------------------------------------- PetscInt UH1_g_size, UH1_l_size; - PetscCall( VecGetSize(*U_H1, &UH1_g_size) ); + PetscCall(VecGetSize(*U_H1, &UH1_g_size)); // Local size for matShell - PetscCall( VecGetLocalSize(*U_H1, &UH1_l_size) ); + PetscCall(VecGetLocalSize(*U_H1, &UH1_l_size)); // Operator Mat mat_ksp_projection; // -- Form Action of residual on u - PetscCall( MatCreateShell(app_ctx->comm, UH1_l_size, UH1_l_size, UH1_g_size, - UH1_g_size, app_ctx->ctx_H1, &mat_ksp_projection) ); - PetscCall( MatShellSetOperation(mat_ksp_projection, MATOP_MULT, - (void (*)(void))ApplyMatOp) ); - PetscCall( MatShellSetVecType(mat_ksp_projection, app_ctx->ctx_H1->vec_type) ); + PetscCall(MatCreateShell(app_ctx->comm, UH1_l_size, UH1_l_size, UH1_g_size, UH1_g_size, app_ctx->ctx_H1, &mat_ksp_projection)); + PetscCall(MatShellSetOperation(mat_ksp_projection, MATOP_MULT, (void (*)(void))ApplyMatOp)); + PetscCall(MatShellSetVecType(mat_ksp_projection, app_ctx->ctx_H1->vec_type)); KSP ksp_projection; - PetscCall( KSPCreate(app_ctx->ctx_H1->comm, &ksp_projection) ); - PetscCall( KSPSetOperators(ksp_projection, mat_ksp_projection, - mat_ksp_projection) ); - PetscCall( KSPSetFromOptions(ksp_projection) ); - PetscCall( KSPSetUp(ksp_projection) ); - PetscCall( VecZeroEntries(*U_H1) ); - PetscCall( KSPSolve(ksp_projection, rhs_H1, *U_H1) ); + PetscCall(KSPCreate(app_ctx->ctx_H1->comm, &ksp_projection)); + PetscCall(KSPSetOperators(ksp_projection, mat_ksp_projection, mat_ksp_projection)); + PetscCall(KSPSetFromOptions(ksp_projection)); + PetscCall(KSPSetUp(ksp_projection)); + PetscCall(VecZeroEntries(*U_H1)); + PetscCall(KSPSolve(ksp_projection, rhs_H1, *U_H1)); // Clean up - PetscCall( VecDestroy(&rhs_loc_H1) ); - PetscCall( VecDestroy(&rhs_H1) ); - PetscCall( MatDestroy(&mat_ksp_projection) ); - PetscCall( KSPDestroy(&ksp_projection) ); + PetscCall(VecDestroy(&rhs_loc_H1)); + PetscCall(VecDestroy(&rhs_H1)); + PetscCall(MatDestroy(&mat_ksp_projection)); + PetscCall(KSPDestroy(&ksp_projection)); CeedVectorDestroy(&app_ctx->ctx_H1->rhs_ceed_H1); PetscFunctionReturn(0); }; - PetscErrorCode CtxVecDestroy(AppCtx app_ctx) { - PetscFunctionBegin; - PetscCall( VecDestroy(&app_ctx->ctx_H1->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_H1->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_Hdiv->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_initial_u0->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_initial_u0->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_initial_p0->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_initial_p0->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_residual_ut->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_residual_ut->X_t_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_residual_ut->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_jacobian->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_jacobian->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_residual->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_residual->X_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_error->Y_loc) ); - PetscCall( VecDestroy(&app_ctx->ctx_error->X_loc) ); + PetscCall(VecDestroy(&app_ctx->ctx_H1->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_H1->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_Hdiv->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_initial_u0->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_initial_u0->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_initial_p0->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_initial_p0->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_residual_ut->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_residual_ut->X_t_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_residual_ut->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_jacobian->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_jacobian->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_residual->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_residual->X_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_error->Y_loc)); + PetscCall(VecDestroy(&app_ctx->ctx_error->X_loc)); PetscFunctionReturn(0); } // ----------------------------------------------------------------------------- diff --git a/examples/Hdiv-mixed/src/setup-boundary.c b/examples/Hdiv-mixed/src/setup-boundary.c index e3a3a859ae..81cd9bd42f 100644 --- a/examples/Hdiv-mixed/src/setup-boundary.c +++ b/examples/Hdiv-mixed/src/setup-boundary.c @@ -4,14 +4,14 @@ // Create boundary label // --------------------------------------------------------------------------- PetscErrorCode CreateBCLabel(DM dm, const char name[]) { - DMLabel label; + DMLabel label; PetscFunctionBeginUser; - PetscCall( DMCreateLabel(dm, name) ); - PetscCall( DMGetLabel(dm, name, &label) ); - PetscCall( DMPlexMarkBoundaryFaces(dm, PETSC_DETERMINE, label) ); - PetscCall( DMPlexLabelComplete(dm, label) ); + PetscCall(DMCreateLabel(dm, name)); + PetscCall(DMGetLabel(dm, name, &label)); + PetscCall(DMPlexMarkBoundaryFaces(dm, PETSC_DETERMINE, label)); + PetscCall(DMPlexLabelComplete(dm, label)); PetscFunctionReturn(0); }; @@ -20,23 +20,19 @@ PetscErrorCode CreateBCLabel(DM dm, const char name[]) { // Add Dirichlet boundaries to DM // --------------------------------------------------------------------------- PetscErrorCode DMAddBoundariesDirichlet(DM dm) { - PetscFunctionBeginUser; // BCs given by manufactured solution - PetscBool has_label; - const char *name = "MMS Face Sets"; - PetscInt face_ids[1] = {1}; - PetscCall( DMHasLabel(dm, name, &has_label) ); + PetscBool has_label; + const char *name = "MMS Face Sets"; + PetscInt face_ids[1] = {1}; + PetscCall(DMHasLabel(dm, name, &has_label)); if (!has_label) { - PetscCall( CreateBCLabel(dm, name) ); + PetscCall(CreateBCLabel(dm, name)); } DMLabel label; - PetscCall( DMGetLabel(dm, name, &label) ); - PetscCall( DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, face_ids, 0, 0, - NULL, - (void(*)(void))BoundaryDirichletMMS, NULL, NULL, NULL) ); - + PetscCall(DMGetLabel(dm, name, &label)); + PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, face_ids, 0, 0, NULL, (void (*)(void))BoundaryDirichletMMS, NULL, NULL, NULL)); PetscFunctionReturn(0); } @@ -44,38 +40,30 @@ PetscErrorCode DMAddBoundariesDirichlet(DM dm) { // --------------------------------------------------------------------------- // Add Neumann boundaries to DM // --------------------------------------------------------------------------- -PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, - AppCtx app_ctx, ProblemData problem_data, DM dm, - CeedVector bc_pressure) { - PetscInt dim; - CeedQFunction qf_pressure; - CeedOperator op_pressure; +PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, AppCtx app_ctx, ProblemData problem_data, DM dm, CeedVector bc_pressure) { + PetscInt dim; + CeedQFunction qf_pressure; + CeedOperator op_pressure; PetscFunctionBeginUser; - PetscCall( DMGetDimension(dm, &dim) ); + PetscCall(DMGetDimension(dm, &dim)); if (app_ctx->bc_pressure_count > 0) { DMLabel domain_label; PetscCall(DMGetLabel(dm, "Face Sets", &domain_label)); // Compute contribution on each boundary face for (CeedInt i = 0; i < app_ctx->bc_pressure_count; i++) { - - CeedQFunctionCreateInterior(ceed, 1, problem_data->bc_pressure, - problem_data->bc_pressure_loc, &qf_pressure); + CeedQFunctionCreateInterior(ceed, 1, problem_data->bc_pressure, problem_data->bc_pressure_loc, &qf_pressure); CeedQFunctionAddInput(qf_pressure, "weight", 1, CEED_EVAL_WEIGHT); CeedQFunctionAddOutput(qf_pressure, "v", dim, CEED_EVAL_INTERP); // -- Apply operator - CeedOperatorCreate(ceed, qf_pressure, NULL, NULL, - &op_pressure); - CeedOperatorSetField(op_pressure, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_pressure, "v", ceed_data->elem_restr_u, - ceed_data->basis_u_face, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_pressure, NULL, NULL, &op_pressure); + CeedOperatorSetField(op_pressure, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_pressure, "v", ceed_data->elem_restr_u, ceed_data->basis_u_face, CEED_VECTOR_ACTIVE); // ---- Compute pressure on face - CeedOperatorApplyAdd(op_pressure, ceed_data->x_coord, bc_pressure, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApplyAdd(op_pressure, ceed_data->x_coord, bc_pressure, CEED_REQUEST_IMMEDIATE); // -- Cleanup CeedQFunctionDestroy(&qf_pressure); @@ -87,14 +75,12 @@ PetscErrorCode DMAddBoundariesPressure(Ceed ceed, CeedData ceed_data, } #ifndef M_PI -#define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846 #endif // --------------------------------------------------------------------------- // Boundary function for manufactured solution // --------------------------------------------------------------------------- -PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, - const PetscReal coords[], - PetscInt num_comp_u, PetscScalar *u, void *ctx) { +PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, const PetscReal coords[], PetscInt num_comp_u, PetscScalar *u, void *ctx) { PetscScalar x = coords[0]; PetscScalar y = coords[1]; PetscScalar z = coords[1]; @@ -102,12 +88,12 @@ PetscErrorCode BoundaryDirichletMMS(PetscInt dim, PetscReal t, PetscFunctionBeginUser; if (dim == 2) { - u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y) - M_PI*y; - u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y) - M_PI*x; + u[0] = -M_PI * cos(M_PI * x) * sin(M_PI * y) - M_PI * y; + u[1] = -M_PI * sin(M_PI * x) * cos(M_PI * y) - M_PI * x; } else { - u[0] = -M_PI*cos(M_PI*x) *sin(M_PI*y) *sin(M_PI*z) - M_PI*y*z; - u[1] = -M_PI*sin(M_PI*x) *cos(M_PI*y) *sin(M_PI*z) - M_PI*x*z; - u[2] = -M_PI*sin(M_PI*x) *sin(M_PI*y) *cos(M_PI*z) - M_PI*x*y; + u[0] = -M_PI * cos(M_PI * x) * sin(M_PI * y) * sin(M_PI * z) - M_PI * y * z; + u[1] = -M_PI * sin(M_PI * x) * cos(M_PI * y) * sin(M_PI * z) - M_PI * x * z; + u[2] = -M_PI * sin(M_PI * x) * sin(M_PI * y) * cos(M_PI * z) - M_PI * x * y; } PetscFunctionReturn(0); diff --git a/examples/Hdiv-mixed/src/setup-dm.c b/examples/Hdiv-mixed/src/setup-dm.c index dff3592bec..3e39ebd7e6 100644 --- a/examples/Hdiv-mixed/src/setup-dm.c +++ b/examples/Hdiv-mixed/src/setup-dm.c @@ -1,128 +1,123 @@ #include "../include/setup-dm.h" + #include "petscerror.h" // --------------------------------------------------------------------------- // Setup DM // --------------------------------------------------------------------------- -PetscErrorCode CreateDM(MPI_Comm comm, MatType mat_type, - VecType vec_type, DM *dm) { - +PetscErrorCode CreateDM(MPI_Comm comm, MatType mat_type, VecType vec_type, DM *dm) { PetscFunctionBeginUser; // Create DMPLEX - PetscCall( DMCreate(comm, dm) ); - PetscCall( DMSetType(*dm, DMPLEX) ); - PetscCall( DMSetMatType(*dm, mat_type) ); - PetscCall( DMSetVecType(*dm, vec_type) ); + PetscCall(DMCreate(comm, dm)); + PetscCall(DMSetType(*dm, DMPLEX)); + PetscCall(DMSetMatType(*dm, mat_type)); + PetscCall(DMSetVecType(*dm, vec_type)); // Set Tensor elements - PetscCall( PetscOptionsSetValue(NULL, "-dm_plex_simplex", "0") ); + PetscCall(PetscOptionsSetValue(NULL, "-dm_plex_simplex", "0")); // Set CL options - PetscCall( DMSetFromOptions(*dm) ); - PetscCall( DMViewFromOptions(*dm, NULL, "-dm_view") ); + PetscCall(DMSetFromOptions(*dm)); + PetscCall(DMViewFromOptions(*dm, NULL, "-dm_view")); PetscFunctionReturn(0); }; PetscErrorCode PerturbVerticesSmooth(DM dm) { - Vec coordinates; PetscSection coordSection; PetscScalar *coords; - PetscInt v,vStart,vEnd,offset,dim; - PetscReal x,y,z; + PetscInt v, vStart, vEnd, offset, dim; + PetscReal x, y, z; PetscFunctionBeginUser; - PetscCall( DMGetDimension(dm, &dim) ); - PetscCall( DMGetCoordinateSection(dm, &coordSection) ); - PetscCall( DMGetCoordinatesLocal(dm, &coordinates) ); - PetscCall( DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd) ); - PetscCall( VecGetArray(coordinates,&coords) ); - for(v=vStart; vdegree + 2 + app_ctx->q_extra; + PetscInt q_degree = app_ctx->degree + 2 + app_ctx->q_extra; PetscBool is_simplex = PETSC_TRUE; PetscFunctionBeginUser; // Check if simplex or tensor-product element - PetscCall( DMPlexIsSimplex(dm_H1, &is_simplex) ); + PetscCall(DMPlexIsSimplex(dm_H1, &is_simplex)); // Create FE space - PetscCall( PetscFECreateLagrange(app_ctx->comm, problem_data->dim, - problem_data->dim, is_simplex, - app_ctx->degree, q_degree, &fe) ); - PetscCall( PetscObjectSetName((PetscObject)fe, "U") ); - PetscCall( DMAddField(dm_H1, NULL, (PetscObject)fe) ); - PetscCall( DMCreateDS(dm_H1) ); + PetscCall(PetscFECreateLagrange(app_ctx->comm, problem_data->dim, problem_data->dim, is_simplex, app_ctx->degree, q_degree, &fe)); + PetscCall(PetscObjectSetName((PetscObject)fe, "U")); + PetscCall(DMAddField(dm_H1, NULL, (PetscObject)fe)); + PetscCall(DMCreateDS(dm_H1)); { // create FE field for coordinates @@ -109,19 +107,19 @@ PetscErrorCode SetupFEH1(ProblemData problem_data, } PetscCall(DMPlexSetClosurePermutationTensor(dm_H1, PETSC_DETERMINE, NULL)); // Cleanup - PetscCall( PetscFEDestroy(&fe) ); + PetscCall(PetscFEDestroy(&fe)); // Empty name for conserved field (because there is only one field) PetscSection section; - PetscCall( DMGetLocalSection(dm_H1, §ion) ); - PetscCall( PetscSectionSetFieldName(section, 0, "Velocity") ); + PetscCall(DMGetLocalSection(dm_H1, §ion)); + PetscCall(PetscSectionSetFieldName(section, 0, "Velocity")); if (problem_data->dim == 2) { - PetscCall( PetscSectionSetComponentName(section, 0, 0, "Velocity_X") ); - PetscCall( PetscSectionSetComponentName(section, 0, 1, "Velocity_Y") ); + PetscCall(PetscSectionSetComponentName(section, 0, 0, "Velocity_X")); + PetscCall(PetscSectionSetComponentName(section, 0, 1, "Velocity_Y")); } else { - PetscCall( PetscSectionSetComponentName(section, 0, 0, "Velocity_X") ); - PetscCall( PetscSectionSetComponentName(section, 0, 1, "Velocity_Y") ); - PetscCall( PetscSectionSetComponentName(section, 0, 2, "Velocity_Z") ); + PetscCall(PetscSectionSetComponentName(section, 0, 0, "Velocity_X")); + PetscCall(PetscSectionSetComponentName(section, 0, 1, "Velocity_Y")); + PetscCall(PetscSectionSetComponentName(section, 0, 2, "Velocity_Z")); } PetscFunctionReturn(0); }; \ No newline at end of file diff --git a/examples/Hdiv-mixed/src/setup-libceed.c b/examples/Hdiv-mixed/src/setup-libceed.c index 8748a60173..dc091f35e0 100644 --- a/examples/Hdiv-mixed/src/setup-libceed.c +++ b/examples/Hdiv-mixed/src/setup-libceed.c @@ -1,23 +1,22 @@ #include "../include/setup-libceed.h" -#include "../include/setup-boundary.h" -#include "../include/petsc-macros.h" -#include "../basis/Hdiv-quad.h" + +#include + #include "../basis/Hdiv-hex.h" +#include "../basis/Hdiv-quad.h" #include "../basis/L2-P0.h" +#include "../include/petsc-macros.h" +#include "../include/setup-boundary.h" #include "ceed/ceed.h" -#include // ----------------------------------------------------------------------------- // Convert PETSc MemType to libCEED MemType // ----------------------------------------------------------------------------- -CeedMemType MemTypeP2C(PetscMemType mem_type) { - return PetscMemTypeDevice(mem_type) ? CEED_MEM_DEVICE : CEED_MEM_HOST; -} +CeedMemType MemTypeP2C(PetscMemType mem_type) { return PetscMemTypeDevice(mem_type) ? CEED_MEM_DEVICE : CEED_MEM_HOST; } // ----------------------------------------------------------------------------- // Destroy libCEED objects // ----------------------------------------------------------------------------- PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data) { - PetscFunctionBegin; // Vectors @@ -28,7 +27,7 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data) { // Restrictions CeedElemRestrictionDestroy(&ceed_data->elem_restr_x); CeedElemRestrictionDestroy(&ceed_data->elem_restr_u); - CeedElemRestrictionDestroy(&ceed_data->elem_restr_U_i); // U = [p,u] + CeedElemRestrictionDestroy(&ceed_data->elem_restr_U_i); // U = [p,u] CeedElemRestrictionDestroy(&ceed_data->elem_restr_p); CeedElemRestrictionDestroy(&ceed_data->elem_restr_p_i); CeedElemRestrictionDestroy(&ceed_data->elem_restr_u0); @@ -54,21 +53,21 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data) { CeedQFunctionDestroy(&ceed_data->qf_ics_p); CeedOperatorDestroy(&ceed_data->op_ics_p); } - //QFunctions + // QFunctions CeedQFunctionDestroy(&ceed_data->qf_residual); CeedQFunctionDestroy(&ceed_data->qf_error); - //Operators + // Operators CeedOperatorDestroy(&ceed_data->op_residual); CeedOperatorDestroy(&ceed_data->op_error); if (!problem_data->has_ts) { - //QFunctions + // QFunctions CeedQFunctionDestroy(&ceed_data->qf_jacobian); - //Operators + // Operators CeedOperatorDestroy(&ceed_data->op_jacobian); } // data for post-processing - if(problem_data->view_solution) { + if (problem_data->view_solution) { CeedVectorDestroy(&ceed_data->up_ceed); CeedVectorDestroy(&ceed_data->vp_ceed); CeedVectorDestroy(&ceed_data->u_ceed); @@ -78,7 +77,7 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data) { CeedQFunctionDestroy(&ceed_data->qf_post_mass); CeedOperatorDestroy(&ceed_data->op_post_mass); } - PetscCall( PetscFree(ceed_data) ); + PetscCall(PetscFree(ceed_data)); PetscFunctionReturn(0); }; @@ -86,26 +85,20 @@ PetscErrorCode CeedDataDestroy(CeedData ceed_data, ProblemData problem_data) { // ----------------------------------------------------------------------------- // Utility function - essential BC dofs are encoded in closure indices as -(i+1) // ----------------------------------------------------------------------------- -PetscInt Involute(PetscInt i) { - return i >= 0 ? i : -(i + 1); -}; +PetscInt Involute(PetscInt i) { return i >= 0 ? i : -(i + 1); }; // ----------------------------------------------------------------------------- // Get CEED restriction data from DMPlex // ----------------------------------------------------------------------------- -PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, - DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { +PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; PetscFunctionBeginUser; - PetscCall( DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, - &elem_size, &num_comp, &num_dof, &elem_restr_offsets) ); + PetscCall(DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, &elem_size, &num_comp, &num_dof, &elem_restr_offsets)); - CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, - 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, - elem_restr_offsets, elem_restr); - PetscCall( PetscFree(elem_restr_offsets) ); + CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, elem_restr_offsets, elem_restr); + PetscCall(PetscFree(elem_restr_offsets)); PetscFunctionReturn(0); }; @@ -113,267 +106,217 @@ PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, // ----------------------------------------------------------------------------- // Get Oriented CEED restriction data from DMPlex // ----------------------------------------------------------------------------- -PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, DM dm_u0, - DM dm_p0, CeedInt P, CeedElemRestriction *elem_restr_u, - CeedElemRestriction *elem_restr_p, - CeedElemRestriction *elem_restr_u0, CeedElemRestriction *elem_restr_p0) { +PetscErrorCode CreateRestrictionFromPlexOriented(Ceed ceed, DM dm, DM dm_u0, DM dm_p0, CeedInt P, CeedElemRestriction *elem_restr_u, + CeedElemRestriction *elem_restr_p, CeedElemRestriction *elem_restr_u0, + CeedElemRestriction *elem_restr_p0) { PetscSection section, section_u0, section_p0; - PetscInt p, num_elem, num_dof, num_dof_u0, num_dof_p0, *restr_indices_u, - *restr_indices_p, *restr_indices_u0, *restr_indices_p0, - elem_offset, num_fields, num_fields_u0, num_fields_p0, - dim, c_start, c_end; - Vec U_loc; - const PetscInt *ornt; // this is for orientation of dof + PetscInt p, num_elem, num_dof, num_dof_u0, num_dof_p0, *restr_indices_u, *restr_indices_p, *restr_indices_u0, *restr_indices_p0, elem_offset, + num_fields, num_fields_u0, num_fields_p0, dim, c_start, c_end; + Vec U_loc; + const PetscInt *ornt; // this is for orientation of dof PetscFunctionBeginUser; // Section for mixed problem - PetscCall( DMGetDimension(dm, &dim) ); - PetscCall( DMGetLocalSection(dm, §ion) ); - PetscCall( PetscSectionGetNumFields(section, &num_fields) ); - PetscInt num_comp[num_fields], field_offsets[num_fields+1]; + PetscCall(DMGetDimension(dm, &dim)); + PetscCall(DMGetLocalSection(dm, §ion)); + PetscCall(PetscSectionGetNumFields(section, &num_fields)); + PetscInt num_comp[num_fields], field_offsets[num_fields + 1]; field_offsets[0] = 0; for (PetscInt f = 0; f < num_fields; f++) { - PetscCall( PetscSectionGetFieldComponents(section, f, &num_comp[f]) ); - field_offsets[f+1] = field_offsets[f] + num_comp[f]; + PetscCall(PetscSectionGetFieldComponents(section, f, &num_comp[f])); + field_offsets[f + 1] = field_offsets[f] + num_comp[f]; } // Section for initial conditions u0 - PetscCall( DMGetLocalSection(dm_u0, §ion_u0) ); - PetscCall( PetscSectionGetNumFields(section_u0, &num_fields_u0) ); - PetscInt num_comp_u0[num_fields_u0], field_offsets_u0[num_fields_u0+1]; + PetscCall(DMGetLocalSection(dm_u0, §ion_u0)); + PetscCall(PetscSectionGetNumFields(section_u0, &num_fields_u0)); + PetscInt num_comp_u0[num_fields_u0], field_offsets_u0[num_fields_u0 + 1]; field_offsets_u0[0] = 0; for (PetscInt f = 0; f < num_fields_u0; f++) { - PetscCall( PetscSectionGetFieldComponents(section_u0, f, &num_comp_u0[f]) ); - field_offsets_u0[f+1] = field_offsets_u0[f] + num_comp_u0[f]; + PetscCall(PetscSectionGetFieldComponents(section_u0, f, &num_comp_u0[f])); + field_offsets_u0[f + 1] = field_offsets_u0[f] + num_comp_u0[f]; } // Section for initial conditions p0 - PetscCall( DMGetLocalSection(dm_p0, §ion_p0) ); - PetscCall( PetscSectionGetNumFields(section_p0, &num_fields_p0) ); - PetscInt num_comp_p0[num_fields_p0], field_offsets_p0[num_fields_p0+1]; + PetscCall(DMGetLocalSection(dm_p0, §ion_p0)); + PetscCall(PetscSectionGetNumFields(section_p0, &num_fields_p0)); + PetscInt num_comp_p0[num_fields_p0], field_offsets_p0[num_fields_p0 + 1]; field_offsets_p0[0] = 0; for (PetscInt f = 0; f < num_fields_p0; f++) { - PetscCall( PetscSectionGetFieldComponents(section_p0, f, &num_comp_p0[f]) ); - field_offsets_p0[f+1] = field_offsets_p0[f] + num_comp_p0[f]; + PetscCall(PetscSectionGetFieldComponents(section_p0, f, &num_comp_p0[f])); + field_offsets_p0[f + 1] = field_offsets_p0[f] + num_comp_p0[f]; } - PetscCall( DMPlexGetHeightStratum(dm, 0, &c_start, &c_end) ); + PetscCall(DMPlexGetHeightStratum(dm, 0, &c_start, &c_end)); num_elem = c_end - c_start; - PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), - &restr_indices_u) ); - PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), - &restr_indices_u0) ); - PetscCall( PetscMalloc1(num_elem,&restr_indices_p) ); - PetscCall( PetscMalloc1(num_elem,&restr_indices_p0) ); - bool *orient_indices_u, *orient_indices_u0; // to flip the dof - PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), &orient_indices_u) ); - PetscCall( PetscMalloc1(num_elem*dim*PetscPowInt(P, dim), &orient_indices_u0) ); + PetscCall(PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &restr_indices_u)); + PetscCall(PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &restr_indices_u0)); + PetscCall(PetscMalloc1(num_elem, &restr_indices_p)); + PetscCall(PetscMalloc1(num_elem, &restr_indices_p0)); + bool *orient_indices_u, *orient_indices_u0; // to flip the dof + PetscCall(PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &orient_indices_u)); + PetscCall(PetscMalloc1(num_elem * dim * PetscPowInt(P, dim), &orient_indices_u0)); for (p = 0, elem_offset = 0; p < num_elem; p++) { - PetscInt num_indices, *indices, faces_per_elem, dofs_per_face, - num_indices_u0, *indices_u0, num_indices_p0, *indices_p0; - PetscCall( DMPlexGetClosureIndices(dm, section, section, p, PETSC_TRUE, - &num_indices, &indices, NULL, NULL) ); - PetscCall( DMPlexGetClosureIndices(dm_u0, section_u0, section_u0, p, PETSC_TRUE, - &num_indices_u0, &indices_u0, NULL, NULL) ); - PetscCall( DMPlexGetClosureIndices(dm_p0, section_p0, section_p0, p, PETSC_TRUE, - &num_indices_p0, &indices_p0, NULL, NULL) ); - restr_indices_p[p] = indices[num_indices - 1]; + PetscInt num_indices, *indices, faces_per_elem, dofs_per_face, num_indices_u0, *indices_u0, num_indices_p0, *indices_p0; + PetscCall(DMPlexGetClosureIndices(dm, section, section, p, PETSC_TRUE, &num_indices, &indices, NULL, NULL)); + PetscCall(DMPlexGetClosureIndices(dm_u0, section_u0, section_u0, p, PETSC_TRUE, &num_indices_u0, &indices_u0, NULL, NULL)); + PetscCall(DMPlexGetClosureIndices(dm_p0, section_p0, section_p0, p, PETSC_TRUE, &num_indices_p0, &indices_p0, NULL, NULL)); + restr_indices_p[p] = indices[num_indices - 1]; restr_indices_p0[p] = indices_p0[0]; - PetscCall( DMPlexGetConeOrientation(dm, p, &ornt) ); + PetscCall(DMPlexGetConeOrientation(dm, p, &ornt)); // Get number of faces per element - PetscCall( DMPlexGetConeSize(dm, p, &faces_per_elem) ); + PetscCall(DMPlexGetConeSize(dm, p, &faces_per_elem)); dofs_per_face = faces_per_elem - 2; for (PetscInt f = 0; f < faces_per_elem; f++) { for (PetscInt i = 0; i < dofs_per_face; i++) { - PetscInt ii = dofs_per_face*f + i; + PetscInt ii = dofs_per_face * f + i; // Essential boundary conditions are encoded as -(loc+1), but we don't care so we decode. - PetscInt loc = Involute(indices[ii*num_comp[0]]); + PetscInt loc = Involute(indices[ii * num_comp[0]]); restr_indices_u[elem_offset] = loc; // Set orientation orient_indices_u[elem_offset] = ornt[f] < 0; - PetscInt loc_u0 = Involute(indices_u0[ii*num_comp_u0[0]]); + PetscInt loc_u0 = Involute(indices_u0[ii * num_comp_u0[0]]); restr_indices_u0[elem_offset] = loc_u0; // Set orientation orient_indices_u0[elem_offset] = ornt[f] < 0; elem_offset++; } } - PetscCall( DMPlexRestoreClosureIndices(dm, section, section, p, PETSC_TRUE, - &num_indices, &indices, NULL, NULL) ); - PetscCall( DMPlexRestoreClosureIndices(dm_u0, section_u0, section_u0, p, - PETSC_TRUE, - &num_indices_u0, &indices_u0, NULL, NULL) ); - PetscCall( DMPlexRestoreClosureIndices(dm_p0, section_p0, section_p0, p, - PETSC_TRUE, - &num_indices_p0, &indices_p0, NULL, NULL) ); + PetscCall(DMPlexRestoreClosureIndices(dm, section, section, p, PETSC_TRUE, &num_indices, &indices, NULL, NULL)); + PetscCall(DMPlexRestoreClosureIndices(dm_u0, section_u0, section_u0, p, PETSC_TRUE, &num_indices_u0, &indices_u0, NULL, NULL)); + PetscCall(DMPlexRestoreClosureIndices(dm_p0, section_p0, section_p0, p, PETSC_TRUE, &num_indices_p0, &indices_p0, NULL, NULL)); } - //if (elem_offset != num_elem*dim*PetscPowInt(P, dim)) - // SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, - // "ElemRestriction of size (%" PetscInt_FMT ", %" PetscInt_FMT" ) - // initialized %" PetscInt_FMT " nodes", num_elem, - // dim*PetscPowInt(P, dim),elem_offset); + // if (elem_offset != num_elem*dim*PetscPowInt(P, dim)) + // SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, + // "ElemRestriction of size (%" PetscInt_FMT ", %" PetscInt_FMT" ) + // initialized %" PetscInt_FMT " nodes", num_elem, + // dim*PetscPowInt(P, dim),elem_offset); - PetscCall( DMGetLocalVector(dm, &U_loc) ); - PetscCall( VecGetLocalSize(U_loc, &num_dof) ); - PetscCall( DMRestoreLocalVector(dm, &U_loc) ); + PetscCall(DMGetLocalVector(dm, &U_loc)); + PetscCall(VecGetLocalSize(U_loc, &num_dof)); + PetscCall(DMRestoreLocalVector(dm, &U_loc)); // dof per element in Hdiv is dim*P^dim, for linear element P=2 - CeedElemRestrictionCreateOriented(ceed, num_elem, dim*PetscPowInt(P, dim), - 1, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, - restr_indices_u, orient_indices_u, - elem_restr_u); - CeedElemRestrictionCreate(ceed, num_elem, 1, - 1, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, - restr_indices_p, elem_restr_p); - PetscCall( DMGetLocalVector(dm_u0, &U_loc) ); - PetscCall( VecGetLocalSize(U_loc, &num_dof_u0) ); - PetscCall( DMRestoreLocalVector(dm_u0, &U_loc) ); + CeedElemRestrictionCreateOriented(ceed, num_elem, dim * PetscPowInt(P, dim), 1, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices_u, + orient_indices_u, elem_restr_u); + CeedElemRestrictionCreate(ceed, num_elem, 1, 1, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices_p, elem_restr_p); + PetscCall(DMGetLocalVector(dm_u0, &U_loc)); + PetscCall(VecGetLocalSize(U_loc, &num_dof_u0)); + PetscCall(DMRestoreLocalVector(dm_u0, &U_loc)); // dof per element in Hdiv is dim*P^dim, for linear element P=2 - CeedElemRestrictionCreateOriented(ceed, num_elem, dim*PetscPowInt(P, dim), - 1, 1, num_dof_u0, CEED_MEM_HOST, CEED_COPY_VALUES, - restr_indices_u0, orient_indices_u0, - elem_restr_u0); - PetscCall( DMGetLocalVector(dm_p0, &U_loc) ); - PetscCall( VecGetLocalSize(U_loc, &num_dof_p0) ); - PetscCall( DMRestoreLocalVector(dm_p0, &U_loc) ); - CeedElemRestrictionCreate(ceed, num_elem, 1, - 1, 1, num_dof_p0, CEED_MEM_HOST, CEED_COPY_VALUES, - restr_indices_p0, elem_restr_p0); - PetscCall( PetscFree(restr_indices_p) ); - PetscCall( PetscFree(restr_indices_u) ); - PetscCall( PetscFree(orient_indices_u) ); - PetscCall( PetscFree(restr_indices_u0) ); - PetscCall( PetscFree(orient_indices_u0) ); - PetscCall( PetscFree(restr_indices_p0) ); + CeedElemRestrictionCreateOriented(ceed, num_elem, dim * PetscPowInt(P, dim), 1, 1, num_dof_u0, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices_u0, + orient_indices_u0, elem_restr_u0); + PetscCall(DMGetLocalVector(dm_p0, &U_loc)); + PetscCall(VecGetLocalSize(U_loc, &num_dof_p0)); + PetscCall(DMRestoreLocalVector(dm_p0, &U_loc)); + CeedElemRestrictionCreate(ceed, num_elem, 1, 1, 1, num_dof_p0, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices_p0, elem_restr_p0); + PetscCall(PetscFree(restr_indices_p)); + PetscCall(PetscFree(restr_indices_u)); + PetscCall(PetscFree(orient_indices_u)); + PetscCall(PetscFree(restr_indices_u0)); + PetscCall(PetscFree(orient_indices_u0)); + PetscCall(PetscFree(restr_indices_p0)); PetscFunctionReturn(0); }; // ----------------------------------------------------------------------------- // Set up libCEED on the fine grid for a given degree // ----------------------------------------------------------------------------- -PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, - Ceed ceed, AppCtx app_ctx, - ProblemData problem_data, - CeedData ceed_data) { - CeedInt P = app_ctx->degree + 1; +PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, Ceed ceed, AppCtx app_ctx, ProblemData problem_data, CeedData ceed_data) { + CeedInt P = app_ctx->degree + 1; // Number of quadratures in 1D, q_extra is set in cl-options.c - CeedInt Q = P + 1 + app_ctx->q_extra; - CeedInt dim, num_comp_x, num_comp_u, num_comp_p; - DM dm_coord; - Vec coords; - PetscInt c_start, c_end, num_elem; + CeedInt Q = P + 1 + app_ctx->q_extra; + CeedInt dim, num_comp_x, num_comp_u, num_comp_p; + DM dm_coord; + Vec coords; + PetscInt c_start, c_end, num_elem; const PetscScalar *coordArray; - CeedQFunction qf_true, qf_residual, qf_jacobian, qf_error; - CeedOperator op_true, op_residual, op_jacobian, op_error; + CeedQFunction qf_true, qf_residual, qf_jacobian, qf_error; + CeedOperator op_true, op_residual, op_jacobian, op_error; PetscFunctionBeginUser; // --------------------------------------------------------------------------- // libCEED bases:Hdiv basis_u and Lagrange basis_x // --------------------------------------------------------------------------- - dim = problem_data->dim; + dim = problem_data->dim; num_comp_x = dim; - num_comp_u = 1; // one vector dof - num_comp_p = 1; // one scalar dof + num_comp_u = 1; // one vector dof + num_comp_p = 1; // one scalar dof // Number of quadratures per element - CeedInt num_qpts = PetscPowInt(Q, dim); + CeedInt num_qpts = PetscPowInt(Q, dim); // Pressure and velocity dof per element - CeedInt P_p = 1, P_u = dim*PetscPowInt(P, dim); - CeedScalar q_ref[dim*num_qpts], q_weights[num_qpts]; - CeedScalar div[P_u*num_qpts], interp_u[dim*P_u*num_qpts], - interp_p[P_p*num_qpts], *grad=NULL; + CeedInt P_p = 1, P_u = dim * PetscPowInt(P, dim); + CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts]; + CeedScalar div[P_u * num_qpts], interp_u[dim * P_u * num_qpts], interp_p[P_p * num_qpts], *grad = NULL; if (dim == 2) { - HdivBasisQuad(Q, q_ref, q_weights, interp_u, div, - problem_data->quadrature_mode); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, - interp_u, div, q_ref, q_weights, &ceed_data->basis_u); + HdivBasisQuad(Q, q_ref, q_weights, interp_u, div, problem_data->quadrature_mode); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, interp_u, div, q_ref, q_weights, &ceed_data->basis_u); L2BasisP0(dim, Q, q_ref, q_weights, interp_p, problem_data->quadrature_mode); - CeedBasisCreateH1(ceed, CEED_TOPOLOGY_QUAD, num_comp_p, 1, num_qpts, interp_p, - grad, q_ref,q_weights, &ceed_data->basis_p); - HdivBasisQuad(Q, q_ref, q_weights, interp_u, div, - CEED_GAUSS_LOBATTO); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, - interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); + CeedBasisCreateH1(ceed, CEED_TOPOLOGY_QUAD, num_comp_p, 1, num_qpts, interp_p, grad, q_ref, q_weights, &ceed_data->basis_p); + HdivBasisQuad(Q, q_ref, q_weights, interp_u, div, CEED_GAUSS_LOBATTO); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp_u, P_u, num_qpts, interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); } else { HdivBasisHex(Q, q_ref, q_weights, interp_u, div, problem_data->quadrature_mode); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, - interp_u, div, q_ref, q_weights, &ceed_data->basis_u); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, interp_u, div, q_ref, q_weights, &ceed_data->basis_u); L2BasisP0(dim, Q, q_ref, q_weights, interp_p, problem_data->quadrature_mode); - CeedBasisCreateH1(ceed, CEED_TOPOLOGY_HEX, num_comp_p, 1, num_qpts, interp_p, - grad, q_ref,q_weights, &ceed_data->basis_p); + CeedBasisCreateH1(ceed, CEED_TOPOLOGY_HEX, num_comp_p, 1, num_qpts, interp_p, grad, q_ref, q_weights, &ceed_data->basis_p); HdivBasisHex(Q, q_ref, q_weights, interp_u, div, CEED_GAUSS_LOBATTO); - CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, - interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); + CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_HEX, num_comp_u, P_u, num_qpts, interp_u, div, q_ref, q_weights, &ceed_data->basis_u_face); } - CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, - problem_data->quadrature_mode, &ceed_data->basis_x); + CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, problem_data->quadrature_mode, &ceed_data->basis_x); // --------------------------------------------------------------------------- // libCEED restrictions // --------------------------------------------------------------------------- - PetscCall( DMGetCoordinateDM(dm, &dm_coord) ); - PetscCall( DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL) ); - CeedInt height = 0; // 0 means no boundary conditions - DMLabel domain_label = 0; - PetscInt value = 0; + PetscCall(DMGetCoordinateDM(dm, &dm_coord)); + PetscCall(DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL)); + CeedInt height = 0; // 0 means no boundary conditions + DMLabel domain_label = 0; + PetscInt value = 0; // -- Coordinate restriction - PetscCall( CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, - value, &ceed_data->elem_restr_x) ); + PetscCall(CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, &ceed_data->elem_restr_x)); // -- Solution restriction - PetscCall( CreateRestrictionFromPlexOriented(ceed, dm, dm_u0, dm_p0, P, - &ceed_data->elem_restr_u, &ceed_data->elem_restr_p, - &ceed_data->elem_restr_u0, &ceed_data->elem_restr_p0) ); + PetscCall(CreateRestrictionFromPlexOriented(ceed, dm, dm_u0, dm_p0, P, &ceed_data->elem_restr_u, &ceed_data->elem_restr_p, + &ceed_data->elem_restr_u0, &ceed_data->elem_restr_p0)); // -- Geometric ceed_data restriction - PetscCall( DMPlexGetHeightStratum(dm, 0, &c_start, &c_end) ); - num_elem = c_end - c_start; + PetscCall(DMPlexGetHeightStratum(dm, 0, &c_start, &c_end)); + num_elem = c_end - c_start; ceed_data->num_elem = num_elem; - CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, (dim+1), - (dim+1)*num_elem*num_qpts, - CEED_STRIDES_BACKEND, &ceed_data->elem_restr_U_i); - CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, 1, - 1*num_elem*num_qpts, - CEED_STRIDES_BACKEND, &ceed_data->elem_restr_p_i); + CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, (dim + 1), (dim + 1) * num_elem * num_qpts, CEED_STRIDES_BACKEND, + &ceed_data->elem_restr_U_i); + CeedElemRestrictionCreateStrided(ceed, num_elem, num_qpts, 1, 1 * num_elem * num_qpts, CEED_STRIDES_BACKEND, &ceed_data->elem_restr_p_i); // --------------------------------------------------------------------------- // Element coordinates // --------------------------------------------------------------------------- - PetscCall( DMGetCoordinatesLocal(dm, &coords) ); - PetscCall( VecGetArrayRead(coords, &coordArray) ); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, - NULL); - CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, - (PetscScalar *)coordArray); - PetscCall( VecRestoreArrayRead(coords, &coordArray) ); + PetscCall(DMGetCoordinatesLocal(dm, &coords)); + PetscCall(VecGetArrayRead(coords, &coordArray)); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL); + CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, (PetscScalar *)coordArray); + PetscCall(VecRestoreArrayRead(coords, &coordArray)); // --------------------------------------------------------------------------- // Setup true solution for [p,u] // --------------------------------------------------------------------------- CeedVector true_vec, true_force; - CeedVectorCreate(ceed, num_elem*num_qpts*(dim+1), &true_vec); - CeedVectorCreate(ceed, num_elem*num_qpts*1, &true_force); + CeedVectorCreate(ceed, num_elem * num_qpts * (dim + 1), &true_vec); + CeedVectorCreate(ceed, num_elem * num_qpts * 1, &true_force); // Create the q-function that sets up the RHS and true solution - CeedQFunctionCreateInterior(ceed, 1, problem_data->true_solution, - problem_data->true_solution_loc, &qf_true); + CeedQFunctionCreateInterior(ceed, 1, problem_data->true_solution, problem_data->true_solution_loc, &qf_true); CeedQFunctionSetContext(qf_true, problem_data->true_qfunction_ctx); CeedQFunctionContextDestroy(&problem_data->true_qfunction_ctx); CeedQFunctionAddInput(qf_true, "x", num_comp_x, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_true, "true force", 1, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_true, "true solution", dim+1, CEED_EVAL_NONE); + CeedQFunctionAddOutput(qf_true, "true solution", dim + 1, CEED_EVAL_NONE); // Create the operator that builds the RHS and true solution - CeedOperatorCreate(ceed, qf_true, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_true); + CeedOperatorCreate(ceed, qf_true, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_true); if (problem_data->has_ts) { double final_time = app_ctx->t_final; - CeedOperatorContextGetFieldLabel(op_true, "final_time", - &app_ctx->ctx_residual_ut->final_time_label); - CeedOperatorContextSetDouble(op_true, - app_ctx->ctx_residual_ut->final_time_label, &final_time); + CeedOperatorContextGetFieldLabel(op_true, "final_time", &app_ctx->ctx_residual_ut->final_time_label); + CeedOperatorContextSetDouble(op_true, app_ctx->ctx_residual_ut->final_time_label, &final_time); } - CeedOperatorSetField(op_true, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_true, "true force", ceed_data->elem_restr_p_i, - CEED_BASIS_COLLOCATED, true_force); - CeedOperatorSetField(op_true, "true solution", ceed_data->elem_restr_U_i, - CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_true, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_true, "true force", ceed_data->elem_restr_p_i, CEED_BASIS_COLLOCATED, true_force); + CeedOperatorSetField(op_true, "true solution", ceed_data->elem_restr_U_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); // Setup true solution - CeedOperatorApply(op_true, ceed_data->x_coord, true_vec, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(op_true, ceed_data->x_coord, true_vec, CEED_REQUEST_IMMEDIATE); // --------------------------------------------------------------------------- // Setup initial conditions @@ -385,25 +328,19 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, CeedQFunction qf_rhs_u0; CeedOperator op_rhs_u0; // Create the q-function that sets up the RHS - CeedQFunctionCreateInterior(ceed, 1, problem_data->rhs_u0, - problem_data->rhs_u0_loc, &qf_rhs_u0); + CeedQFunctionCreateInterior(ceed, 1, problem_data->rhs_u0, problem_data->rhs_u0_loc, &qf_rhs_u0); CeedQFunctionSetContext(qf_rhs_u0, problem_data->rhs_u0_qfunction_ctx); CeedQFunctionContextDestroy(&problem_data->rhs_u0_qfunction_ctx); CeedQFunctionAddInput(qf_rhs_u0, "weight", 1, CEED_EVAL_WEIGHT); CeedQFunctionAddInput(qf_rhs_u0, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_rhs_u0, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_rhs_u0, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddOutput(qf_rhs_u0, "rhs_u0", dim, CEED_EVAL_INTERP); // Create the operator that builds the RHS - CeedOperatorCreate(ceed, qf_rhs_u0, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_rhs_u0); - CeedOperatorSetField(op_rhs_u0, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_rhs_u0, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_u0, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_u0, "rhs_u0", ceed_data->elem_restr_u0, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_rhs_u0, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_rhs_u0); + CeedOperatorSetField(op_rhs_u0, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_rhs_u0, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_rhs_u0, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_rhs_u0, "rhs_u0", ceed_data->elem_restr_u0, ceed_data->basis_u, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in setup-ts.c ceed_data->qf_rhs_u0 = qf_rhs_u0; @@ -413,54 +350,40 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, // --------------------------------------------------------------------------- CeedQFunction qf_ics_u; CeedOperator op_ics_u; - CeedQFunctionCreateInterior(ceed, 1, problem_data->ics_u, - problem_data->ics_u_loc, &qf_ics_u); + CeedQFunctionCreateInterior(ceed, 1, problem_data->ics_u, problem_data->ics_u_loc, &qf_ics_u); CeedQFunctionAddInput(qf_ics_u, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_ics_u, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_ics_u, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_ics_u, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_ics_u, "v", dim, CEED_EVAL_INTERP); // Create the operator that builds the initial conditions - CeedOperatorCreate(ceed, qf_ics_u, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_ics_u); - CeedOperatorSetField(op_ics_u, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_ics_u, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_ics_u, "u", ceed_data->elem_restr_u0, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_ics_u, "v", ceed_data->elem_restr_u0, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_ics_u, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_ics_u); + CeedOperatorSetField(op_ics_u, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_ics_u, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_ics_u, "u", ceed_data->elem_restr_u0, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_ics_u, "v", ceed_data->elem_restr_u0, ceed_data->basis_u, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in setup-ts.c ceed_data->qf_ics_u = qf_ics_u; ceed_data->op_ics_u = op_ics_u; // -- Operator action variables: we use them in setup-ts.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, &ceed_data->u0_ceed, - NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, &ceed_data->v0_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, &ceed_data->u0_ceed, NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, &ceed_data->v0_ceed, NULL); // --------------------------------------------------------------------------- // Setup RHS for p field // --------------------------------------------------------------------------- CeedQFunction qf_rhs_p0; CeedOperator op_rhs_p0; // Create the q-function that sets up the RHS - CeedQFunctionCreateInterior(ceed, 1, problem_data->rhs_p0, - problem_data->rhs_p0_loc, &qf_rhs_p0); + CeedQFunctionCreateInterior(ceed, 1, problem_data->rhs_p0, problem_data->rhs_p0_loc, &qf_rhs_p0); CeedQFunctionAddInput(qf_rhs_p0, "weight", 1, CEED_EVAL_WEIGHT); CeedQFunctionAddInput(qf_rhs_p0, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_rhs_p0, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_rhs_p0, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddOutput(qf_rhs_p0, "rhs_p0", 1, CEED_EVAL_INTERP); // Create the operator that builds the RHS - CeedOperatorCreate(ceed, qf_rhs_p0, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_rhs_p0); - CeedOperatorSetField(op_rhs_p0, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_rhs_p0, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_p0, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_p0, "rhs_p0", ceed_data->elem_restr_p0, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_rhs_p0, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_rhs_p0); + CeedOperatorSetField(op_rhs_p0, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_rhs_p0, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_rhs_p0, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_rhs_p0, "rhs_p0", ceed_data->elem_restr_p0, ceed_data->basis_p, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in setup-ts.c ceed_data->qf_rhs_p0 = qf_rhs_p0; @@ -470,55 +393,43 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, // --------------------------------------------------------------------------- CeedQFunction qf_ics_p; CeedOperator op_ics_p; - CeedQFunctionCreateInterior(ceed, 1, problem_data->ics_p, - problem_data->ics_p_loc, &qf_ics_p); + CeedQFunctionCreateInterior(ceed, 1, problem_data->ics_p, problem_data->ics_p_loc, &qf_ics_p); CeedQFunctionAddInput(qf_ics_p, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_ics_p, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_ics_p, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_ics_p, "p", 1, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_ics_p, "q", 1, CEED_EVAL_INTERP); // Create the operator that builds the initial conditions - CeedOperatorCreate(ceed, qf_ics_p, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_ics_p); - CeedOperatorSetField(op_ics_p, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_ics_p, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_ics_p, "p", ceed_data->elem_restr_p0, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_ics_p, "q", ceed_data->elem_restr_p0, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_ics_p, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_ics_p); + CeedOperatorSetField(op_ics_p, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_ics_p, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_ics_p, "p", ceed_data->elem_restr_p0, ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_ics_p, "q", ceed_data->elem_restr_p0, ceed_data->basis_p, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in setup-ts.c ceed_data->qf_ics_p = qf_ics_p; ceed_data->op_ics_p = op_ics_p; // -- Operator action variables: we use them in setup-ts.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, &ceed_data->p0_ceed, - NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, &ceed_data->q0_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, &ceed_data->p0_ceed, NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, &ceed_data->q0_ceed, NULL); } // --------------------------------------------------------------------------- // Persistent libCEED vectors // --------------------------------------------------------------------------- // -- Operator action variables: we use them in setup-solvers.c/setup-ts.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->x_ceed, - NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->y_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->x_ceed, NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->y_ceed, NULL); // -- Operator action variables: we use them in setup-ts.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->x_t_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->x_t_ceed, NULL); // Local residual evaluator // --------------------------------------------------------------------------- // Create the QFunction and Operator that computes the residual of the PDE. // --------------------------------------------------------------------------- // -- QFunction - CeedQFunctionCreateInterior(ceed, 1, problem_data->residual, - problem_data->residual_loc, &qf_residual); + CeedQFunctionCreateInterior(ceed, 1, problem_data->residual, problem_data->residual_loc, &qf_residual); CeedQFunctionSetContext(qf_residual, problem_data->residual_qfunction_ctx); CeedQFunctionContextDestroy(&problem_data->residual_qfunction_ctx); CeedQFunctionAddInput(qf_residual, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_residual, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_residual, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_residual, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_residual, "div_u", 1, CEED_EVAL_DIV); CeedQFunctionAddInput(qf_residual, "p", 1, CEED_EVAL_INTERP); @@ -532,41 +443,28 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, CeedQFunctionAddOutput(qf_residual, "q", 1, CEED_EVAL_INTERP); // -- Operator - CeedOperatorCreate(ceed, qf_residual, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_residual); + CeedOperatorCreate(ceed, qf_residual, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_residual); if (problem_data->has_ts) { - //double t = app_ctx->ctx_residual_ut->t; - CeedOperatorContextGetFieldLabel(op_residual, "time", - &app_ctx->ctx_residual_ut->solution_time_label); - //CeedOperatorContextGetFieldLabel(op_residual, "time_step", - // &app_ctx->ctx_residual_ut->timestep_label); - //CeedOperatorContextSetDouble(op_residual, - // app_ctx->ctx_residual_ut->solution_time_label, &t); + // double t = app_ctx->ctx_residual_ut->t; + CeedOperatorContextGetFieldLabel(op_residual, "time", &app_ctx->ctx_residual_ut->solution_time_label); + // CeedOperatorContextGetFieldLabel(op_residual, "time_step", + // &app_ctx->ctx_residual_ut->timestep_label); + // CeedOperatorContextSetDouble(op_residual, + // app_ctx->ctx_residual_ut->solution_time_label, &t); } - CeedOperatorSetField(op_residual, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_residual, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_residual, "u", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "div_u", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "p", ceed_data->elem_restr_p, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "true force", ceed_data->elem_restr_p_i, - CEED_BASIS_COLLOCATED, true_force); - CeedOperatorSetField(op_residual, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_residual, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_residual, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_residual, "u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "div_u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "p", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "true force", ceed_data->elem_restr_p_i, CEED_BASIS_COLLOCATED, true_force); + CeedOperatorSetField(op_residual, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); if (problem_data->has_ts) { - CeedOperatorSetField(op_residual, "p_t", ceed_data->elem_restr_p, - ceed_data->basis_p, ceed_data->x_t_ceed); + CeedOperatorSetField(op_residual, "p_t", ceed_data->elem_restr_p, ceed_data->basis_p, ceed_data->x_t_ceed); } - CeedOperatorSetField(op_residual, "v", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "div_v", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_residual, "q", ceed_data->elem_restr_p, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "v", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "div_v", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_residual, "q", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_residual = qf_residual; ceed_data->op_residual = op_residual; @@ -574,53 +472,42 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, // --------------------------------------------------------------------------- // Add Pressure boundary condition. See setup-boundary.c // --------------------------------------------------------------------------- - //DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm); + // DMAddBoundariesPressure(ceed, ceed_data, app_ctx, problem_data, dm); // Local jacobian evaluator // --------------------------------------------------------------------------- // Create the QFunction and Operator that computes the jacobian of the PDE. // --------------------------------------------------------------------------- // -- QFunction - CeedQFunctionCreateInterior(ceed, 1, problem_data->jacobian, - problem_data->jacobian_loc, &qf_jacobian); + CeedQFunctionCreateInterior(ceed, 1, problem_data->jacobian, problem_data->jacobian_loc, &qf_jacobian); CeedQFunctionSetContext(qf_jacobian, problem_data->jacobian_qfunction_ctx); CeedQFunctionContextDestroy(&problem_data->jacobian_qfunction_ctx); CeedQFunctionAddInput(qf_jacobian, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_jacobian, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_jacobian, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_jacobian, "du", dim, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_jacobian, "div_du", 1, CEED_EVAL_DIV); CeedQFunctionAddInput(qf_jacobian, "dp", 1, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_jacobian, "x", num_comp_x, CEED_EVAL_INTERP); - //CeedQFunctionAddInput(qf_jacobian, "u", dim, CEED_EVAL_INTERP); - //CeedQFunctionAddInput(qf_jacobian, "p", 1, CEED_EVAL_INTERP); + // CeedQFunctionAddInput(qf_jacobian, "u", dim, CEED_EVAL_INTERP); + // CeedQFunctionAddInput(qf_jacobian, "p", 1, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_jacobian, "dv", dim, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_jacobian, "div_dv", 1, CEED_EVAL_DIV); CeedQFunctionAddOutput(qf_jacobian, "dq", 1, CEED_EVAL_INTERP); // -- Operator - CeedOperatorCreate(ceed, qf_jacobian, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_jacobian); - CeedOperatorSetField(op_jacobian, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_jacobian, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_jacobian, "du", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "div_du", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "dp", ceed_data->elem_restr_p, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "x", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - //CeedOperatorSetField(op_jacobian, "u", ceed_data->elem_restr_u, - // ceed_data->basis_u, CEED_VECTOR_ACTIVE); - //CeedOperatorSetField(op_jacobian, "p", ceed_data->elem_restr_p, - // ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "dv", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "div_dv", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_jacobian, "dq", ceed_data->elem_restr_p, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_jacobian, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_jacobian); + CeedOperatorSetField(op_jacobian, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_jacobian, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_jacobian, "du", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "div_du", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "dp", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + // CeedOperatorSetField(op_jacobian, "u", ceed_data->elem_restr_u, + // ceed_data->basis_u, CEED_VECTOR_ACTIVE); + // CeedOperatorSetField(op_jacobian, "p", ceed_data->elem_restr_p, + // ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "dv", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "div_dv", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_jacobian, "dq", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_jacobian = qf_jacobian; ceed_data->op_jacobian = op_jacobian; @@ -629,65 +516,49 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, // Setup Error Qfunction // --------------------------------------------------------------------------- // Create the q-function that sets up the error - CeedQFunctionCreateInterior(ceed, 1, problem_data->error, - problem_data->error_loc, &qf_error); + CeedQFunctionCreateInterior(ceed, 1, problem_data->error, problem_data->error_loc, &qf_error); CeedQFunctionSetContext(qf_error, problem_data->error_qfunction_ctx); CeedQFunctionContextDestroy(&problem_data->error_qfunction_ctx); CeedQFunctionAddInput(qf_error, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_error, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_error, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_error, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddInput(qf_error, "p", 1, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_error, "true solution", dim+1, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_error, "error", dim+1, CEED_EVAL_NONE); + CeedQFunctionAddInput(qf_error, "true solution", dim + 1, CEED_EVAL_NONE); + CeedQFunctionAddOutput(qf_error, "error", dim + 1, CEED_EVAL_NONE); // Create the operator that builds the error - CeedOperatorCreate(ceed, qf_error, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_error); - CeedOperatorSetField(op_error, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_error, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_error, "u", ceed_data->elem_restr_u, - ceed_data->basis_u, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_error, "p", ceed_data->elem_restr_p, - ceed_data->basis_p, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_error, "true solution", ceed_data->elem_restr_U_i, - CEED_BASIS_COLLOCATED, true_vec); - CeedOperatorSetField(op_error, "error", ceed_data->elem_restr_U_i, - CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_error, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_error); + CeedOperatorSetField(op_error, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_error, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_error, "u", ceed_data->elem_restr_u, ceed_data->basis_u, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_error, "p", ceed_data->elem_restr_p, ceed_data->basis_p, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_error, "true solution", ceed_data->elem_restr_U_i, CEED_BASIS_COLLOCATED, true_vec); + CeedOperatorSetField(op_error, "error", ceed_data->elem_restr_U_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in matops.c ceed_data->qf_error = qf_error; ceed_data->op_error = op_error; if (app_ctx->view_solution) { // -- Post processing - PetscCall( CreateRestrictionFromPlex(ceed, dm_H1, height, domain_label, - value, &ceed_data->elem_restr_u_H1) ); + PetscCall(CreateRestrictionFromPlex(ceed, dm_H1, height, domain_label, value, &ceed_data->elem_restr_u_H1)); // --------------------------------------------------------------------------- // Setup RHS for post processing // --------------------------------------------------------------------------- // -- Operator action variables: we use them in post-processing.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->u_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u, &ceed_data->u_ceed, NULL); CeedQFunction qf_rhs_H1; CeedOperator op_rhs_H1; // Create the q-function that sets up the RHS - CeedQFunctionCreateInterior(ceed, 1, problem_data->post_rhs, - problem_data->post_rhs_loc, &qf_rhs_H1); + CeedQFunctionCreateInterior(ceed, 1, problem_data->post_rhs, problem_data->post_rhs_loc, &qf_rhs_H1); CeedQFunctionAddInput(qf_rhs_H1, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_rhs_H1, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_rhs_H1, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_rhs_H1, "u_post", dim, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_rhs_H1, "rhs_post", dim, CEED_EVAL_INTERP); // Create the operator that builds the RHS - CeedOperatorCreate(ceed, qf_rhs_H1, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_rhs_H1); - CeedOperatorSetField(op_rhs_H1, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_rhs_H1, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_H1, "u_post", ceed_data->elem_restr_u, - ceed_data->basis_u, ceed_data->u_ceed); - CeedOperatorSetField(op_rhs_H1, "rhs_post", ceed_data->elem_restr_u_H1, - ceed_data->basis_x, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_rhs_H1, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_rhs_H1); + CeedOperatorSetField(op_rhs_H1, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_rhs_H1, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_rhs_H1, "u_post", ceed_data->elem_restr_u, ceed_data->basis_u, ceed_data->u_ceed); + CeedOperatorSetField(op_rhs_H1, "rhs_post", ceed_data->elem_restr_u_H1, ceed_data->basis_x, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in post-processing.c ceed_data->qf_rhs_H1 = qf_rhs_H1; ceed_data->op_rhs_H1 = op_rhs_H1; @@ -696,33 +567,23 @@ PetscErrorCode SetupLibceed(DM dm, DM dm_u0, DM dm_p0, DM dm_H1, // --------------------------------------------------------------------------- CeedQFunction qf_post_mass; CeedOperator op_post_mass; - CeedQFunctionCreateInterior(ceed, 1, problem_data->post_mass, - problem_data->post_mass_loc, &qf_post_mass); + CeedQFunctionCreateInterior(ceed, 1, problem_data->post_mass, problem_data->post_mass_loc, &qf_post_mass); CeedQFunctionAddInput(qf_post_mass, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddInput(qf_post_mass, "dx", dim*dim, CEED_EVAL_GRAD); + CeedQFunctionAddInput(qf_post_mass, "dx", dim * dim, CEED_EVAL_GRAD); CeedQFunctionAddInput(qf_post_mass, "u", dim, CEED_EVAL_INTERP); CeedQFunctionAddOutput(qf_post_mass, "v", dim, CEED_EVAL_INTERP); // Create the operator that builds the initial conditions - CeedOperatorCreate(ceed, qf_post_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, - &op_post_mass); - CeedOperatorSetField(op_post_mass, "weight", CEED_ELEMRESTRICTION_NONE, - ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_post_mass, "dx", ceed_data->elem_restr_x, - ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_post_mass, "u", ceed_data->elem_restr_u_H1, - ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_post_mass, "v", ceed_data->elem_restr_u_H1, - ceed_data->basis_x, CEED_VECTOR_ACTIVE); + CeedOperatorCreate(ceed, qf_post_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_post_mass); + CeedOperatorSetField(op_post_mass, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); + CeedOperatorSetField(op_post_mass, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + CeedOperatorSetField(op_post_mass, "u", ceed_data->elem_restr_u_H1, ceed_data->basis_x, CEED_VECTOR_ACTIVE); + CeedOperatorSetField(op_post_mass, "v", ceed_data->elem_restr_u_H1, ceed_data->basis_x, CEED_VECTOR_ACTIVE); // -- Save libCEED data to apply operator in post-processing.c ceed_data->qf_post_mass = qf_post_mass; ceed_data->op_post_mass = op_post_mass; // -- Operator action variables: we use them in post-processing.c - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u_H1, - &ceed_data->up_ceed, - NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u_H1, - &ceed_data->vp_ceed, - NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u_H1, &ceed_data->up_ceed, NULL); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u_H1, &ceed_data->vp_ceed, NULL); } // -- Cleanup CeedVectorDestroy(&true_vec); diff --git a/examples/Hdiv-mixed/src/setup-matops.c b/examples/Hdiv-mixed/src/setup-matops.c index 619b189f20..d0ea7662aa 100644 --- a/examples/Hdiv-mixed/src/setup-matops.c +++ b/examples/Hdiv-mixed/src/setup-matops.c @@ -1,59 +1,49 @@ #include "../include/setup-matops.h" + #include "../include/setup-libceed.h" // ----------------------------------------------------------------------------- // Apply the local action of a libCEED operator and store result in PETSc vector // i.e. compute A X = Y // ----------------------------------------------------------------------------- -PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, - OperatorApplyContext op_apply_ctx) { +PetscErrorCode ApplyLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx) { PetscFunctionBeginUser; // Zero target vector - PetscCall( VecZeroEntries(Y) ); + PetscCall(VecZeroEntries(Y)); // Sum into target vector - PetscCall( ApplyAddLocalCeedOp(X, Y, op_apply_ctx) ); + PetscCall(ApplyAddLocalCeedOp(X, Y, op_apply_ctx)); PetscFunctionReturn(0); } -PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y, - OperatorApplyContext op_apply_ctx) { - +PetscErrorCode ApplyAddLocalCeedOp(Vec X, Vec Y, OperatorApplyContext op_apply_ctx) { PetscScalar *x, *y; PetscMemType x_mem_type, y_mem_type; PetscFunctionBeginUser; // Global-to-local - PetscCall( DMGlobalToLocal(op_apply_ctx->dm, X, INSERT_VALUES, - op_apply_ctx->X_loc) ); + PetscCall(DMGlobalToLocal(op_apply_ctx->dm, X, INSERT_VALUES, op_apply_ctx->X_loc)); // Setup libCEED vectors - PetscCall( VecGetArrayReadAndMemType(op_apply_ctx->X_loc, - (const PetscScalar **)&x, - &x_mem_type) ); - PetscCall( VecGetArrayAndMemType(op_apply_ctx->Y_loc, &y, &y_mem_type) ); - CeedVectorSetArray(op_apply_ctx->x_ceed, MemTypeP2C(x_mem_type), - CEED_USE_POINTER, x); - CeedVectorSetArray(op_apply_ctx->y_ceed, MemTypeP2C(y_mem_type), - CEED_USE_POINTER, y); + PetscCall(VecGetArrayReadAndMemType(op_apply_ctx->X_loc, (const PetscScalar **)&x, &x_mem_type)); + PetscCall(VecGetArrayAndMemType(op_apply_ctx->Y_loc, &y, &y_mem_type)); + CeedVectorSetArray(op_apply_ctx->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x); + CeedVectorSetArray(op_apply_ctx->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y); // Apply libCEED operator - CeedOperatorApply(op_apply_ctx->op_apply, op_apply_ctx->x_ceed, - op_apply_ctx->y_ceed, CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(op_apply_ctx->op_apply, op_apply_ctx->x_ceed, op_apply_ctx->y_ceed, CEED_REQUEST_IMMEDIATE); // Restore PETSc vectors CeedVectorTakeArray(op_apply_ctx->x_ceed, MemTypeP2C(x_mem_type), NULL); CeedVectorTakeArray(op_apply_ctx->y_ceed, MemTypeP2C(y_mem_type), NULL); - PetscCall( VecRestoreArrayReadAndMemType(op_apply_ctx->X_loc, - (const PetscScalar **)&x) ); - PetscCall( VecRestoreArrayAndMemType(op_apply_ctx->Y_loc, &y) ); + PetscCall(VecRestoreArrayReadAndMemType(op_apply_ctx->X_loc, (const PetscScalar **)&x)); + PetscCall(VecRestoreArrayAndMemType(op_apply_ctx->Y_loc, &y)); // Local-to-global - PetscCall( DMLocalToGlobal(op_apply_ctx->dm, op_apply_ctx->Y_loc, ADD_VALUES, - Y) ); + PetscCall(DMLocalToGlobal(op_apply_ctx->dm, op_apply_ctx->Y_loc, ADD_VALUES, Y)); PetscFunctionReturn(0); }; diff --git a/examples/Hdiv-mixed/src/setup-solvers.c b/examples/Hdiv-mixed/src/setup-solvers.c index 3ea1f631f1..3fef27c924 100644 --- a/examples/Hdiv-mixed/src/setup-solvers.c +++ b/examples/Hdiv-mixed/src/setup-solvers.c @@ -1,52 +1,49 @@ #include "../include/setup-solvers.h" -#include "../include/setup-matops.h" + #include "../include/setup-libceed.h" +#include "../include/setup-matops.h" #include "petscvec.h" // ----------------------------------------------------------------------------- // Setup operator context data // ----------------------------------------------------------------------------- -PetscErrorCode SetupJacobianOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - VecType vec_type, - OperatorApplyContext ctx_jacobian) { +PetscErrorCode SetupJacobianOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, VecType vec_type, OperatorApplyContext ctx_jacobian) { PetscFunctionBeginUser; ctx_jacobian->dm = dm; - PetscCall( DMCreateLocalVector(dm, &ctx_jacobian->X_loc) ); - PetscCall( VecDuplicate(ctx_jacobian->X_loc, &ctx_jacobian->Y_loc) ); - ctx_jacobian->x_ceed = ceed_data->x_ceed; - ctx_jacobian->y_ceed = ceed_data->y_ceed; - ctx_jacobian->ceed = ceed; + PetscCall(DMCreateLocalVector(dm, &ctx_jacobian->X_loc)); + PetscCall(VecDuplicate(ctx_jacobian->X_loc, &ctx_jacobian->Y_loc)); + ctx_jacobian->x_ceed = ceed_data->x_ceed; + ctx_jacobian->y_ceed = ceed_data->y_ceed; + ctx_jacobian->ceed = ceed; ctx_jacobian->op_apply = ceed_data->op_jacobian; ctx_jacobian->vec_type = vec_type; PetscFunctionReturn(0); } -PetscErrorCode SetupResidualOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - OperatorApplyContext ctx_residual) { +PetscErrorCode SetupResidualOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_residual) { PetscFunctionBeginUser; ctx_residual->dm = dm; - PetscCall( DMCreateLocalVector(dm, &ctx_residual->X_loc) ); - PetscCall( VecDuplicate(ctx_residual->X_loc, &ctx_residual->Y_loc) ); - ctx_residual->x_ceed = ceed_data->x_ceed; - ctx_residual->y_ceed = ceed_data->y_ceed; - ctx_residual->ceed = ceed; + PetscCall(DMCreateLocalVector(dm, &ctx_residual->X_loc)); + PetscCall(VecDuplicate(ctx_residual->X_loc, &ctx_residual->Y_loc)); + ctx_residual->x_ceed = ceed_data->x_ceed; + ctx_residual->y_ceed = ceed_data->y_ceed; + ctx_residual->ceed = ceed; ctx_residual->op_apply = ceed_data->op_residual; PetscFunctionReturn(0); } -PetscErrorCode SetupErrorOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, - OperatorApplyContext ctx_error) { +PetscErrorCode SetupErrorOperatorCtx(DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_error) { PetscFunctionBeginUser; ctx_error->dm = dm; - PetscCall( DMCreateLocalVector(dm, &ctx_error->X_loc) ); - PetscCall( VecDuplicate(ctx_error->X_loc, &ctx_error->Y_loc) ); - ctx_error->x_ceed = ceed_data->x_ceed; - ctx_error->y_ceed = ceed_data->y_ceed; - ctx_error->ceed = ceed; + PetscCall(DMCreateLocalVector(dm, &ctx_error->X_loc)); + PetscCall(VecDuplicate(ctx_error->X_loc, &ctx_error->Y_loc)); + ctx_error->x_ceed = ceed_data->x_ceed; + ctx_error->y_ceed = ceed_data->y_ceed; + ctx_error->ceed = ceed; ctx_error->op_apply = ceed_data->op_error; PetscFunctionReturn(0); @@ -60,10 +57,10 @@ PetscErrorCode ApplyMatOp(Mat A, Vec X, Vec Y) { PetscFunctionBeginUser; - PetscCall( MatShellGetContext(A, &op_apply_ctx) ); + PetscCall(MatShellGetContext(A, &op_apply_ctx)); // libCEED for local action of residual evaluator - PetscCall( ApplyLocalCeedOp(X, Y, op_apply_ctx) ); + PetscCall(ApplyLocalCeedOp(X, Y, op_apply_ctx)); PetscFunctionReturn(0); }; @@ -77,12 +74,12 @@ PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx_residual) { PetscFunctionBeginUser; // Use computed BCs - //PetscCall( DMPlexInsertBoundaryValues(ctx->dm, PETSC_TRUE, + // PetscCall( DMPlexInsertBoundaryValues(ctx->dm, PETSC_TRUE, // ctx->X_loc, // 1.0, NULL, NULL, NULL) ); // libCEED for local action of residual evaluator - PetscCall( ApplyLocalCeedOp(X, Y, ctx) ); + PetscCall(ApplyLocalCeedOp(X, Y, ctx)); PetscFunctionReturn(0); }; @@ -90,8 +87,7 @@ PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx_residual) { // ----------------------------------------------------------------------------- // Jacobian setup // ----------------------------------------------------------------------------- -PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, - void *ctx_jacobian) { +PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, void *ctx_jacobian) { OperatorApplyContext ctx = (OperatorApplyContext)ctx_jacobian; PetscFunctionBeginUser; @@ -99,10 +95,9 @@ PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, PetscCall(DMCreateMatrix(ctx->dm, &A)); // Assemble matrix analytically PetscCount num_entries; - CeedInt *rows, *cols; + CeedInt *rows, *cols; CeedVector coo_values; - CeedOperatorLinearAssembleSymbolic(ctx->op_apply, &num_entries, &rows, - &cols); + CeedOperatorLinearAssembleSymbolic(ctx->op_apply, &num_entries, &rows, &cols); PetscCall(MatSetPreallocationCOO(A, num_entries, rows, cols)); free(rows); free(cols); @@ -113,16 +108,16 @@ PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, PetscCall(MatSetValuesCOO(A, values, ADD_VALUES)); CeedVectorRestoreArrayRead(coo_values, &values); MatView(A, PETSC_VIEWER_STDOUT_WORLD); - //CeedVectorView(coo_values, "%12.8f", stdout); + // CeedVectorView(coo_values, "%12.8f", stdout); CeedVectorDestroy(&coo_values); - PetscCall( MatDestroy(&A) ); + PetscCall(MatDestroy(&A)); // J_pre might be AIJ (e.g., when using coloring), so we need to assemble it - PetscCall( MatAssemblyBegin(J_pre, MAT_FINAL_ASSEMBLY) ); - PetscCall( MatAssemblyEnd(J_pre, MAT_FINAL_ASSEMBLY) ); + PetscCall(MatAssemblyBegin(J_pre, MAT_FINAL_ASSEMBLY)); + PetscCall(MatAssemblyEnd(J_pre, MAT_FINAL_ASSEMBLY)); if (J != J_pre) { - PetscCall( MatAssemblyBegin(J, MAT_FINAL_ASSEMBLY) ); - PetscCall( MatAssemblyEnd(J, MAT_FINAL_ASSEMBLY) ); + PetscCall(MatAssemblyBegin(J, MAT_FINAL_ASSEMBLY)); + PetscCall(MatAssemblyEnd(J, MAT_FINAL_ASSEMBLY)); } PetscFunctionReturn(0); }; @@ -130,57 +125,51 @@ PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, // --------------------------------------------------------------------------- // Setup Solver // --------------------------------------------------------------------------- -PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, - SNES snes, KSP ksp, Vec *U) { - - PetscInt U_l_size, U_g_size; +PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp, Vec *U) { + PetscInt U_l_size, U_g_size; PetscFunctionBeginUser; // Create global unknown solution U - PetscCall( VecGetSize(*U, &U_g_size) ); + PetscCall(VecGetSize(*U, &U_g_size)); // Local size for matShell - PetscCall( VecGetLocalSize(*U, &U_l_size) ); + PetscCall(VecGetLocalSize(*U, &U_l_size)); Vec R; - PetscCall( VecDuplicate(*U, &R) ); + PetscCall(VecDuplicate(*U, &R)); // --------------------------------------------------------------------------- // Setup SNES // --------------------------------------------------------------------------- // Operator Mat mat_jacobian; - PetscCall( SNESSetDM(snes, app_ctx->ctx_jacobian->dm) ); + PetscCall(SNESSetDM(snes, app_ctx->ctx_jacobian->dm)); // -- Form Action of Jacobian on delta_u - PetscCall( MatCreateShell(app_ctx->comm, U_l_size, U_l_size, U_g_size, - U_g_size, app_ctx->ctx_jacobian, &mat_jacobian) ); - PetscCall( MatShellSetOperation(mat_jacobian, MATOP_MULT, - (void (*)(void))ApplyMatOp) ); - PetscCall( MatShellSetVecType(mat_jacobian, app_ctx->ctx_jacobian->vec_type) ); + PetscCall(MatCreateShell(app_ctx->comm, U_l_size, U_l_size, U_g_size, U_g_size, app_ctx->ctx_jacobian, &mat_jacobian)); + PetscCall(MatShellSetOperation(mat_jacobian, MATOP_MULT, (void (*)(void))ApplyMatOp)); + PetscCall(MatShellSetVecType(mat_jacobian, app_ctx->ctx_jacobian->vec_type)); // Set SNES residual evaluation function - PetscCall( SNESSetFunction(snes, R, SNESFormResidual, - app_ctx->ctx_residual) ); + PetscCall(SNESSetFunction(snes, R, SNESFormResidual, app_ctx->ctx_residual)); // -- SNES Jacobian - PetscCall( SNESSetJacobian(snes, mat_jacobian, mat_jacobian, - SNESFormJacobian, app_ctx->ctx_jacobian) ); + PetscCall(SNESSetJacobian(snes, mat_jacobian, mat_jacobian, SNESFormJacobian, app_ctx->ctx_jacobian)); // Setup KSP - PetscCall( KSPSetFromOptions(ksp) ); + PetscCall(KSPSetFromOptions(ksp)); // Default to critical-point (CP) line search (related to Wolfe's curvature condition) SNESLineSearch line_search; - PetscCall( SNESGetLineSearch(snes, &line_search) ); - PetscCall( SNESLineSearchSetType(line_search, SNESLINESEARCHCP) ); - PetscCall( SNESSetFromOptions(snes) ); + PetscCall(SNESGetLineSearch(snes, &line_search)); + PetscCall(SNESLineSearchSetType(line_search, SNESLINESEARCHCP)); + PetscCall(SNESSetFromOptions(snes)); // Solve - PetscCall( VecSet(*U, 0.0)); - PetscCall( SNESSolve(snes, NULL, *U)); + PetscCall(VecSet(*U, 0.0)); + PetscCall(SNESSolve(snes, NULL, *U)); // Free PETSc objects - PetscCall( MatDestroy(&mat_jacobian) ); - PetscCall( VecDestroy(&R) ); + PetscCall(MatDestroy(&mat_jacobian)); + PetscCall(VecDestroy(&R)); PetscFunctionReturn(0); }; @@ -188,65 +177,57 @@ PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, // ----------------------------------------------------------------------------- // This function calculates the L2 error in the final solution // ----------------------------------------------------------------------------- -PetscErrorCode ComputeL2Error(CeedData ceed_data, AppCtx app_ctx, Vec U, - CeedScalar *l2_error_u, CeedScalar *l2_error_p) { +PetscErrorCode ComputeL2Error(CeedData ceed_data, AppCtx app_ctx, Vec U, CeedScalar *l2_error_u, CeedScalar *l2_error_p) { PetscScalar *x; PetscMemType mem_type; - CeedVector collocated_error; + CeedVector collocated_error; PetscFunctionBeginUser; CeedInt dim, num_elem, num_qpts; - PetscCall( DMGetDimension(app_ctx->ctx_error->dm, &dim) ); + PetscCall(DMGetDimension(app_ctx->ctx_error->dm, &dim)); CeedBasisGetNumQuadraturePoints(ceed_data->basis_u, &num_qpts); num_elem = ceed_data->num_elem; - CeedVectorCreate(app_ctx->ctx_error->ceed, num_elem*num_qpts*(dim+1), - &collocated_error); + CeedVectorCreate(app_ctx->ctx_error->ceed, num_elem * num_qpts * (dim + 1), &collocated_error); // Global-to-local - PetscCall( DMGlobalToLocal(app_ctx->ctx_error->dm, U, INSERT_VALUES, - app_ctx->ctx_error->X_loc) ); + PetscCall(DMGlobalToLocal(app_ctx->ctx_error->dm, U, INSERT_VALUES, app_ctx->ctx_error->X_loc)); // Setup CEED vector - PetscCall( VecGetArrayAndMemType(app_ctx->ctx_error->X_loc, &x, &mem_type) ); - CeedVectorSetArray(app_ctx->ctx_error->x_ceed, MemTypeP2C(mem_type), - CEED_USE_POINTER, - x); + PetscCall(VecGetArrayAndMemType(app_ctx->ctx_error->X_loc, &x, &mem_type)); + CeedVectorSetArray(app_ctx->ctx_error->x_ceed, MemTypeP2C(mem_type), CEED_USE_POINTER, x); // Apply CEED operator - CeedOperatorApply(app_ctx->ctx_error->op_apply, app_ctx->ctx_error->x_ceed, - collocated_error, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(app_ctx->ctx_error->op_apply, app_ctx->ctx_error->x_ceed, collocated_error, CEED_REQUEST_IMMEDIATE); // Restore PETSc vector CeedVectorTakeArray(app_ctx->ctx_error->x_ceed, MemTypeP2C(mem_type), NULL); - PetscCall( VecRestoreArrayReadAndMemType(app_ctx->ctx_error->X_loc, - (const PetscScalar **)&x) ); + PetscCall(VecRestoreArrayReadAndMemType(app_ctx->ctx_error->X_loc, (const PetscScalar **)&x)); // Compute L2 error for each field - CeedInt cent_qpts = num_qpts / 2; - CeedVector collocated_error_u, collocated_error_p; - const CeedScalar *E_U; // to store total error - CeedInt length_u, length_p; + CeedInt cent_qpts = num_qpts / 2; + CeedVector collocated_error_u, collocated_error_p; + const CeedScalar *E_U; // to store total error + CeedInt length_u, length_p; length_p = num_elem; - length_u = num_elem*num_qpts*dim; + length_u = num_elem * num_qpts * dim; CeedScalar e_u[length_u], e_p[length_p]; CeedVectorCreate(app_ctx->ctx_error->ceed, length_p, &collocated_error_p); CeedVectorCreate(app_ctx->ctx_error->ceed, length_u, &collocated_error_u); // E_U is ordered as [p_0,u_0/.../p_n,u_n] for 0 to n elements // For each element p_0 size is num_qpts, and u_0 is dim*num_qpts CeedVectorGetArrayRead(collocated_error, CEED_MEM_HOST, &E_U); - for (CeedInt n=0; n < num_elem; n++) { - for (CeedInt i=0; i < 1; i++) { - CeedInt j = i + n*1; - CeedInt k = cent_qpts + n*num_qpts*(dim+1); - e_p[j] = E_U[k]; + for (CeedInt n = 0; n < num_elem; n++) { + for (CeedInt i = 0; i < 1; i++) { + CeedInt j = i + n * 1; + CeedInt k = cent_qpts + n * num_qpts * (dim + 1); + e_p[j] = E_U[k]; } } - for (CeedInt n=0; n < num_elem; n++) { - for (CeedInt i=0; i < dim*num_qpts; i++) { - CeedInt j = i + n*num_qpts*dim; - CeedInt k = num_qpts + i + n*num_qpts*(dim+1); - e_u[j] = E_U[k]; + for (CeedInt n = 0; n < num_elem; n++) { + for (CeedInt i = 0; i < dim * num_qpts; i++) { + CeedInt j = i + n * num_qpts * dim; + CeedInt k = num_qpts + i + n * num_qpts * (dim + 1); + e_u[j] = E_U[k]; } } diff --git a/examples/Hdiv-mixed/src/setup-ts.c b/examples/Hdiv-mixed/src/setup-ts.c index 24aaec705d..e93bca2495 100644 --- a/examples/Hdiv-mixed/src/setup-ts.c +++ b/examples/Hdiv-mixed/src/setup-ts.c @@ -1,29 +1,28 @@ #include "../include/setup-ts.h" -#include "../include/setup-matops.h" + +#include + +#include "../include/post-processing.h" #include "../include/setup-libceed.h" +#include "../include/setup-matops.h" #include "../include/setup-solvers.h" -#include "../include/post-processing.h" #include "ceed/ceed.h" #include "petscerror.h" #include "petscsystypes.h" -#include - // ----------------------------------------------------------------------------- // Setup operator context data for initial condition, u field // ----------------------------------------------------------------------------- -PetscErrorCode SetupResidualOperatorCtx_U0(MPI_Comm comm, DM dm_u0, Ceed ceed, - CeedData ceed_data, - OperatorApplyContext ctx_initial_u0) { +PetscErrorCode SetupResidualOperatorCtx_U0(MPI_Comm comm, DM dm_u0, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_initial_u0) { PetscFunctionBeginUser; ctx_initial_u0->comm = comm; - ctx_initial_u0->dm = dm_u0; - PetscCall( DMCreateLocalVector(dm_u0, &ctx_initial_u0->X_loc) ); - PetscCall( VecDuplicate(ctx_initial_u0->X_loc, &ctx_initial_u0->Y_loc) ); - ctx_initial_u0->x_ceed = ceed_data->u0_ceed; - ctx_initial_u0->y_ceed = ceed_data->v0_ceed; - ctx_initial_u0->ceed = ceed; + ctx_initial_u0->dm = dm_u0; + PetscCall(DMCreateLocalVector(dm_u0, &ctx_initial_u0->X_loc)); + PetscCall(VecDuplicate(ctx_initial_u0->X_loc, &ctx_initial_u0->Y_loc)); + ctx_initial_u0->x_ceed = ceed_data->u0_ceed; + ctx_initial_u0->y_ceed = ceed_data->v0_ceed; + ctx_initial_u0->ceed = ceed; ctx_initial_u0->op_apply = ceed_data->op_ics_u; PetscFunctionReturn(0); @@ -32,18 +31,16 @@ PetscErrorCode SetupResidualOperatorCtx_U0(MPI_Comm comm, DM dm_u0, Ceed ceed, // ----------------------------------------------------------------------------- // Setup operator context data for initial condition, p field // ----------------------------------------------------------------------------- -PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm_p0, Ceed ceed, - CeedData ceed_data, - OperatorApplyContext ctx_initial_p0) { +PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm_p0, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_initial_p0) { PetscFunctionBeginUser; ctx_initial_p0->comm = comm; - ctx_initial_p0->dm = dm_p0; - PetscCall( DMCreateLocalVector(dm_p0, &ctx_initial_p0->X_loc) ); - PetscCall( VecDuplicate(ctx_initial_p0->X_loc, &ctx_initial_p0->Y_loc) ); - ctx_initial_p0->x_ceed = ceed_data->p0_ceed; - ctx_initial_p0->y_ceed = ceed_data->q0_ceed; - ctx_initial_p0->ceed = ceed; + ctx_initial_p0->dm = dm_p0; + PetscCall(DMCreateLocalVector(dm_p0, &ctx_initial_p0->X_loc)); + PetscCall(VecDuplicate(ctx_initial_p0->X_loc, &ctx_initial_p0->Y_loc)); + ctx_initial_p0->x_ceed = ceed_data->p0_ceed; + ctx_initial_p0->y_ceed = ceed_data->q0_ceed; + ctx_initial_p0->ceed = ceed; ctx_initial_p0->op_apply = ceed_data->op_ics_p; PetscFunctionReturn(0); @@ -52,19 +49,18 @@ PetscErrorCode SetupResidualOperatorCtx_P0(MPI_Comm comm, DM dm_p0, Ceed ceed, // ----------------------------------------------------------------------------- // Setup operator context data for Residual of Richard problem // ----------------------------------------------------------------------------- -PetscErrorCode SetupResidualOperatorCtx_Ut(MPI_Comm comm, DM dm, Ceed ceed, - CeedData ceed_data, OperatorApplyContext ctx_residual_ut) { +PetscErrorCode SetupResidualOperatorCtx_Ut(MPI_Comm comm, DM dm, Ceed ceed, CeedData ceed_data, OperatorApplyContext ctx_residual_ut) { PetscFunctionBeginUser; ctx_residual_ut->comm = comm; - ctx_residual_ut->dm = dm; - PetscCall( DMCreateLocalVector(dm, &ctx_residual_ut->X_loc) ); - PetscCall( VecDuplicate(ctx_residual_ut->X_loc, &ctx_residual_ut->Y_loc) ); - PetscCall( VecDuplicate(ctx_residual_ut->X_loc, &ctx_residual_ut->X_t_loc) ); - ctx_residual_ut->x_ceed = ceed_data->x_ceed; + ctx_residual_ut->dm = dm; + PetscCall(DMCreateLocalVector(dm, &ctx_residual_ut->X_loc)); + PetscCall(VecDuplicate(ctx_residual_ut->X_loc, &ctx_residual_ut->Y_loc)); + PetscCall(VecDuplicate(ctx_residual_ut->X_loc, &ctx_residual_ut->X_t_loc)); + ctx_residual_ut->x_ceed = ceed_data->x_ceed; ctx_residual_ut->x_t_ceed = ceed_data->x_t_ceed; - ctx_residual_ut->y_ceed = ceed_data->y_ceed; - ctx_residual_ut->ceed = ceed; + ctx_residual_ut->y_ceed = ceed_data->y_ceed; + ctx_residual_ut->ceed = ceed; ctx_residual_ut->op_apply = ceed_data->op_residual; PetscFunctionReturn(0); @@ -73,318 +69,279 @@ PetscErrorCode SetupResidualOperatorCtx_Ut(MPI_Comm comm, DM dm, Ceed ceed, // ----------------------------------------------------------------------------- // Create global initial conditions vector // ----------------------------------------------------------------------------- -PetscErrorCode CreateInitialConditions(CeedData ceed_data, AppCtx app_ctx, - VecType vec_type, Vec U) { - +PetscErrorCode CreateInitialConditions(CeedData ceed_data, AppCtx app_ctx, VecType vec_type, Vec U) { PetscFunctionBeginUser; // ---------------------------------------------- // Create local rhs for u field // ---------------------------------------------- - Vec rhs_u_loc; + Vec rhs_u_loc; PetscScalar *ru; PetscMemType ru_mem_type; - PetscCall( DMCreateLocalVector(app_ctx->ctx_initial_u0->dm, &rhs_u_loc) ); - PetscCall( VecZeroEntries(rhs_u_loc) ); - PetscCall( VecGetArrayAndMemType(rhs_u_loc, &ru, &ru_mem_type) ); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, - &ceed_data->rhs_u0_ceed, - NULL); - CeedVectorSetArray(ceed_data->rhs_u0_ceed, MemTypeP2C(ru_mem_type), - CEED_USE_POINTER, ru); + PetscCall(DMCreateLocalVector(app_ctx->ctx_initial_u0->dm, &rhs_u_loc)); + PetscCall(VecZeroEntries(rhs_u_loc)); + PetscCall(VecGetArrayAndMemType(rhs_u_loc, &ru, &ru_mem_type)); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_u0, &ceed_data->rhs_u0_ceed, NULL); + CeedVectorSetArray(ceed_data->rhs_u0_ceed, MemTypeP2C(ru_mem_type), CEED_USE_POINTER, ru); // Apply operator to create RHS for u field - CeedOperatorApply(ceed_data->op_rhs_u0, ceed_data->x_coord, - ceed_data->rhs_u0_ceed, CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(ceed_data->op_rhs_u0, ceed_data->x_coord, ceed_data->rhs_u0_ceed, CEED_REQUEST_IMMEDIATE); // ---------------------------------------------- // Create global rhs for u field // ---------------------------------------------- Vec rhs_u0; CeedVectorTakeArray(ceed_data->rhs_u0_ceed, MemTypeP2C(ru_mem_type), NULL); - PetscCall( VecRestoreArrayAndMemType(rhs_u_loc, &ru) ); - PetscCall( DMCreateGlobalVector(app_ctx->ctx_initial_u0->dm, &rhs_u0) ); - PetscCall( VecZeroEntries(rhs_u0) ); - PetscCall( DMLocalToGlobal(app_ctx->ctx_initial_u0->dm, rhs_u_loc, ADD_VALUES, - rhs_u0) ); + PetscCall(VecRestoreArrayAndMemType(rhs_u_loc, &ru)); + PetscCall(DMCreateGlobalVector(app_ctx->ctx_initial_u0->dm, &rhs_u0)); + PetscCall(VecZeroEntries(rhs_u0)); + PetscCall(DMLocalToGlobal(app_ctx->ctx_initial_u0->dm, rhs_u_loc, ADD_VALUES, rhs_u0)); // ---------------------------------------------- // Solve for U0, M*U0 = rhs_u0 // ---------------------------------------------- Vec U0; - PetscCall( DMCreateGlobalVector(app_ctx->ctx_initial_u0->dm, &U0) ); - PetscCall( VecZeroEntries(U0) ); + PetscCall(DMCreateGlobalVector(app_ctx->ctx_initial_u0->dm, &U0)); + PetscCall(VecZeroEntries(U0)); PetscInt U0_g_size, U0_l_size; - PetscCall( VecGetSize(U0, &U0_g_size) ); + PetscCall(VecGetSize(U0, &U0_g_size)); // Local size for matShell - PetscCall( VecGetLocalSize(U0, &U0_l_size) ); + PetscCall(VecGetLocalSize(U0, &U0_l_size)); // Operator Mat mat_ksp_u0; // -- Form Action of residual on u - PetscCall( MatCreateShell(app_ctx->comm, U0_l_size, U0_l_size, U0_g_size, - U0_g_size, app_ctx->ctx_initial_u0, &mat_ksp_u0) ); - PetscCall( MatShellSetOperation(mat_ksp_u0, MATOP_MULT, - (void (*)(void))ApplyMatOp) ); - PetscCall( MatShellSetVecType(mat_ksp_u0, vec_type) ); + PetscCall(MatCreateShell(app_ctx->comm, U0_l_size, U0_l_size, U0_g_size, U0_g_size, app_ctx->ctx_initial_u0, &mat_ksp_u0)); + PetscCall(MatShellSetOperation(mat_ksp_u0, MATOP_MULT, (void (*)(void))ApplyMatOp)); + PetscCall(MatShellSetVecType(mat_ksp_u0, vec_type)); KSP ksp_u0; - PetscCall( KSPCreate(app_ctx->comm, &ksp_u0) ); - PetscCall( KSPSetOperators(ksp_u0, mat_ksp_u0, mat_ksp_u0) ); - PetscCall( KSPSetFromOptions(ksp_u0) ); - PetscCall( KSPSetUp(ksp_u0) ); - PetscCall( KSPSolve(ksp_u0, rhs_u0, U0) ); + PetscCall(KSPCreate(app_ctx->comm, &ksp_u0)); + PetscCall(KSPSetOperators(ksp_u0, mat_ksp_u0, mat_ksp_u0)); + PetscCall(KSPSetFromOptions(ksp_u0)); + PetscCall(KSPSetUp(ksp_u0)); + PetscCall(KSPSolve(ksp_u0, rhs_u0, U0)); // ---------------------------------------------- // Create local rhs for p field // ---------------------------------------------- - Vec rhs_p_loc; + Vec rhs_p_loc; PetscScalar *rp; PetscMemType rp_mem_type; - PetscCall( DMCreateLocalVector(app_ctx->ctx_initial_p0->dm, &rhs_p_loc) ); - PetscCall( VecZeroEntries(rhs_p_loc) ); - PetscCall( VecGetArrayAndMemType(rhs_p_loc, &rp, &rp_mem_type) ); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, - &ceed_data->rhs_p0_ceed, - NULL); - CeedVectorSetArray(ceed_data->rhs_p0_ceed, MemTypeP2C(rp_mem_type), - CEED_USE_POINTER, rp); + PetscCall(DMCreateLocalVector(app_ctx->ctx_initial_p0->dm, &rhs_p_loc)); + PetscCall(VecZeroEntries(rhs_p_loc)); + PetscCall(VecGetArrayAndMemType(rhs_p_loc, &rp, &rp_mem_type)); + CeedElemRestrictionCreateVector(ceed_data->elem_restr_p0, &ceed_data->rhs_p0_ceed, NULL); + CeedVectorSetArray(ceed_data->rhs_p0_ceed, MemTypeP2C(rp_mem_type), CEED_USE_POINTER, rp); // Apply operator to create RHS for p field - CeedOperatorApply(ceed_data->op_rhs_p0, ceed_data->x_coord, - ceed_data->rhs_p0_ceed, CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(ceed_data->op_rhs_p0, ceed_data->x_coord, ceed_data->rhs_p0_ceed, CEED_REQUEST_IMMEDIATE); // ---------------------------------------------- // Create global rhs for p field // ---------------------------------------------- Vec rhs_p0; CeedVectorTakeArray(ceed_data->rhs_p0_ceed, MemTypeP2C(rp_mem_type), NULL); - PetscCall( VecRestoreArrayAndMemType(rhs_p_loc, &rp) ); - PetscCall( DMCreateGlobalVector(app_ctx->ctx_initial_p0->dm, &rhs_p0) ); - PetscCall( VecZeroEntries(rhs_p0) ); - PetscCall( DMLocalToGlobal(app_ctx->ctx_initial_p0->dm, rhs_p_loc, ADD_VALUES, - rhs_p0) ); + PetscCall(VecRestoreArrayAndMemType(rhs_p_loc, &rp)); + PetscCall(DMCreateGlobalVector(app_ctx->ctx_initial_p0->dm, &rhs_p0)); + PetscCall(VecZeroEntries(rhs_p0)); + PetscCall(DMLocalToGlobal(app_ctx->ctx_initial_p0->dm, rhs_p_loc, ADD_VALUES, rhs_p0)); // ---------------------------------------------- // Solve for P0, M*P0 = rhs_p0 // ---------------------------------------------- Vec P0; - PetscCall( DMCreateGlobalVector(app_ctx->ctx_initial_p0->dm, &P0) ); - PetscCall( VecZeroEntries(P0) ); + PetscCall(DMCreateGlobalVector(app_ctx->ctx_initial_p0->dm, &P0)); + PetscCall(VecZeroEntries(P0)); PetscInt P0_g_size, P0_l_size; - PetscCall( VecGetSize(P0, &P0_g_size) ); + PetscCall(VecGetSize(P0, &P0_g_size)); // Local size for matShell - PetscCall( VecGetLocalSize(P0, &P0_l_size) ); + PetscCall(VecGetLocalSize(P0, &P0_l_size)); // Operator Mat mat_ksp_p0; // -- Form Action of residual on u - PetscCall( MatCreateShell(app_ctx->comm, P0_l_size, P0_l_size, P0_g_size, - P0_g_size, app_ctx->ctx_initial_p0, &mat_ksp_p0) ); - PetscCall( MatShellSetOperation(mat_ksp_p0, MATOP_MULT, - (void (*)(void))ApplyMatOp) ); - PetscCall( MatShellSetVecType(mat_ksp_p0, vec_type) ); + PetscCall(MatCreateShell(app_ctx->comm, P0_l_size, P0_l_size, P0_g_size, P0_g_size, app_ctx->ctx_initial_p0, &mat_ksp_p0)); + PetscCall(MatShellSetOperation(mat_ksp_p0, MATOP_MULT, (void (*)(void))ApplyMatOp)); + PetscCall(MatShellSetVecType(mat_ksp_p0, vec_type)); KSP ksp_p0; - PetscCall( KSPCreate(app_ctx->comm, &ksp_p0) ); - PetscCall( KSPSetOperators(ksp_p0, mat_ksp_p0, mat_ksp_p0) ); - PetscCall( KSPSetFromOptions(ksp_p0) ); - PetscCall( KSPSetUp(ksp_p0) ); - PetscCall( KSPSolve(ksp_p0, rhs_p0, P0) ); + PetscCall(KSPCreate(app_ctx->comm, &ksp_p0)); + PetscCall(KSPSetOperators(ksp_p0, mat_ksp_p0, mat_ksp_p0)); + PetscCall(KSPSetFromOptions(ksp_p0)); + PetscCall(KSPSetUp(ksp_p0)); + PetscCall(KSPSolve(ksp_p0, rhs_p0, P0)); // ---------------------------------------------- // Create final initial conditions U // ---------------------------------------------- // Global-to-local for U0, P0 - PetscCall( DMGlobalToLocal(app_ctx->ctx_initial_u0->dm, U0, INSERT_VALUES, - app_ctx->ctx_initial_u0->X_loc) ); - PetscCall( DMGlobalToLocal(app_ctx->ctx_initial_p0->dm, P0, INSERT_VALUES, - app_ctx->ctx_initial_p0->X_loc) ); + PetscCall(DMGlobalToLocal(app_ctx->ctx_initial_u0->dm, U0, INSERT_VALUES, app_ctx->ctx_initial_u0->X_loc)); + PetscCall(DMGlobalToLocal(app_ctx->ctx_initial_p0->dm, P0, INSERT_VALUES, app_ctx->ctx_initial_p0->X_loc)); // Get array u0,p0 const PetscScalar *u0, *p0; - PetscCall( VecGetArrayRead(app_ctx->ctx_initial_u0->X_loc, &u0) ); - PetscCall( VecGetArrayRead(app_ctx->ctx_initial_p0->X_loc, &p0) ); + PetscCall(VecGetArrayRead(app_ctx->ctx_initial_u0->X_loc, &u0)); + PetscCall(VecGetArrayRead(app_ctx->ctx_initial_p0->X_loc, &p0)); // Get array of local vector U = [p,u] PetscScalar *u; - PetscInt U_l_size; - PetscCall( VecGetLocalSize(U, &U_l_size) ); - PetscCall( VecZeroEntries(app_ctx->ctx_residual_ut->X_loc) ); - PetscCall( VecGetArray(app_ctx->ctx_residual_ut->X_loc, &u) ); - for (PetscInt i = 0; inum_elem; i++) { + PetscInt U_l_size; + PetscCall(VecGetLocalSize(U, &U_l_size)); + PetscCall(VecZeroEntries(app_ctx->ctx_residual_ut->X_loc)); + PetscCall(VecGetArray(app_ctx->ctx_residual_ut->X_loc, &u)); + for (PetscInt i = 0; i < ceed_data->num_elem; i++) { u[i] = p0[i]; } - for (PetscInt i = ceed_data->num_elem; inum_elem]; + for (PetscInt i = ceed_data->num_elem; i < U_l_size; i++) { + u[i] = u0[i - ceed_data->num_elem]; } - PetscCall( VecRestoreArray(app_ctx->ctx_residual_ut->X_loc, &u) ); - PetscCall( VecRestoreArrayRead(app_ctx->ctx_initial_p0->X_loc, &p0) ); - PetscCall( VecRestoreArrayRead(app_ctx->ctx_initial_u0->X_loc, &u0) ); - PetscCall( DMLocalToGlobal(app_ctx->ctx_residual_ut->dm, - app_ctx->ctx_residual_ut->X_loc, - ADD_VALUES, U) ); + PetscCall(VecRestoreArray(app_ctx->ctx_residual_ut->X_loc, &u)); + PetscCall(VecRestoreArrayRead(app_ctx->ctx_initial_p0->X_loc, &p0)); + PetscCall(VecRestoreArrayRead(app_ctx->ctx_initial_u0->X_loc, &u0)); + PetscCall(DMLocalToGlobal(app_ctx->ctx_residual_ut->dm, app_ctx->ctx_residual_ut->X_loc, ADD_VALUES, U)); // Clean up - PetscCall( VecDestroy(&rhs_u_loc) ); - PetscCall( VecDestroy(&rhs_u0) ); - PetscCall( VecDestroy(&U0) ); - PetscCall( VecDestroy(&rhs_p_loc) ); - PetscCall( VecDestroy(&rhs_p0) ); - PetscCall( VecDestroy(&P0) ); - PetscCall( MatDestroy(&mat_ksp_p0) ); - PetscCall( MatDestroy(&mat_ksp_u0) ); - PetscCall( KSPDestroy(&ksp_p0) ); - PetscCall( KSPDestroy(&ksp_u0) ); + PetscCall(VecDestroy(&rhs_u_loc)); + PetscCall(VecDestroy(&rhs_u0)); + PetscCall(VecDestroy(&U0)); + PetscCall(VecDestroy(&rhs_p_loc)); + PetscCall(VecDestroy(&rhs_p0)); + PetscCall(VecDestroy(&P0)); + PetscCall(MatDestroy(&mat_ksp_p0)); + PetscCall(MatDestroy(&mat_ksp_u0)); + PetscCall(KSPDestroy(&ksp_p0)); + PetscCall(KSPDestroy(&ksp_u0)); PetscFunctionReturn(0); - } -PetscErrorCode TSFormIResidual(TS ts, PetscReal time, Vec X, Vec X_t, Vec Y, - void *ctx_residual_ut) { - OperatorApplyContext ctx = (OperatorApplyContext)ctx_residual_ut; - const PetscScalar *x, *x_t; - PetscScalar *y; - PetscMemType x_mem_type, x_t_mem_type, y_mem_type; +PetscErrorCode TSFormIResidual(TS ts, PetscReal time, Vec X, Vec X_t, Vec Y, void *ctx_residual_ut) { + OperatorApplyContext ctx = (OperatorApplyContext)ctx_residual_ut; + const PetscScalar *x, *x_t; + PetscScalar *y; + PetscMemType x_mem_type, x_t_mem_type, y_mem_type; PetscFunctionBeginUser; // Update time dependent data - if(ctx->t != time) { - CeedOperatorContextSetDouble(ctx->op_apply, - ctx->solution_time_label, &time); + if (ctx->t != time) { + CeedOperatorContextSetDouble(ctx->op_apply, ctx->solution_time_label, &time); ctx->t = time; } - //PetscScalar dt; - //PetscCall( TSGetTimeStep(ts, &dt) ); - //if (ctx->dt != dt) { - // CeedOperatorContextSetDouble(ctx->op_apply, - // ctx->timestep_label, &dt); - // ctx->dt = dt; - //} - // Global-to-local - PetscCall( DMGlobalToLocal(ctx->dm, X, INSERT_VALUES, ctx->X_loc) ); - PetscCall( DMGlobalToLocal(ctx->dm, X_t, INSERT_VALUES, ctx->X_t_loc) ); + // PetscScalar dt; + // PetscCall( TSGetTimeStep(ts, &dt) ); + // if (ctx->dt != dt) { + // CeedOperatorContextSetDouble(ctx->op_apply, + // ctx->timestep_label, &dt); + // ctx->dt = dt; + // } + // Global-to-local + PetscCall(DMGlobalToLocal(ctx->dm, X, INSERT_VALUES, ctx->X_loc)); + PetscCall(DMGlobalToLocal(ctx->dm, X_t, INSERT_VALUES, ctx->X_t_loc)); // Place PETSc vectors in CEED vectors - PetscCall( VecGetArrayReadAndMemType(ctx->X_loc, &x, &x_mem_type) ); - PetscCall( VecGetArrayReadAndMemType(ctx->X_t_loc, &x_t, &x_t_mem_type) ); - PetscCall( VecGetArrayAndMemType(ctx->Y_loc, &y, &y_mem_type) ); - CeedVectorSetArray(ctx->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, - (PetscScalar *)x); - CeedVectorSetArray(ctx->x_t_ceed, MemTypeP2C(x_t_mem_type), - CEED_USE_POINTER, (PetscScalar *)x_t); + PetscCall(VecGetArrayReadAndMemType(ctx->X_loc, &x, &x_mem_type)); + PetscCall(VecGetArrayReadAndMemType(ctx->X_t_loc, &x_t, &x_t_mem_type)); + PetscCall(VecGetArrayAndMemType(ctx->Y_loc, &y, &y_mem_type)); + CeedVectorSetArray(ctx->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, (PetscScalar *)x); + CeedVectorSetArray(ctx->x_t_ceed, MemTypeP2C(x_t_mem_type), CEED_USE_POINTER, (PetscScalar *)x_t); CeedVectorSetArray(ctx->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y); // Apply CEED operator - CeedOperatorApply(ctx->op_apply, ctx->x_ceed, ctx->y_ceed, - CEED_REQUEST_IMMEDIATE); + CeedOperatorApply(ctx->op_apply, ctx->x_ceed, ctx->y_ceed, CEED_REQUEST_IMMEDIATE); // Restore vectors CeedVectorTakeArray(ctx->x_ceed, MemTypeP2C(x_mem_type), NULL); CeedVectorTakeArray(ctx->x_t_ceed, MemTypeP2C(x_t_mem_type), NULL); CeedVectorTakeArray(ctx->y_ceed, MemTypeP2C(y_mem_type), NULL); - PetscCall( VecRestoreArrayReadAndMemType(ctx->X_loc, &x) ); - PetscCall( VecRestoreArrayReadAndMemType(ctx->X_t_loc, &x_t) ); - PetscCall( VecRestoreArrayAndMemType(ctx->Y_loc, &y) ); + PetscCall(VecRestoreArrayReadAndMemType(ctx->X_loc, &x)); + PetscCall(VecRestoreArrayReadAndMemType(ctx->X_t_loc, &x_t)); + PetscCall(VecRestoreArrayAndMemType(ctx->Y_loc, &y)); // Local-to-Global - PetscCall( VecZeroEntries(Y) ); - PetscCall( DMLocalToGlobal(ctx->dm, ctx->Y_loc, ADD_VALUES, Y) ); + PetscCall(VecZeroEntries(Y)); + PetscCall(DMLocalToGlobal(ctx->dm, ctx->Y_loc, ADD_VALUES, Y)); PetscFunctionReturn(0); } -PetscErrorCode WriteOutput(Vec U, PetscInt steps, - PetscScalar time, AppCtx app_ctx) { - char output_filename[PETSC_MAX_PATH_LEN]; +PetscErrorCode WriteOutput(Vec U, PetscInt steps, PetscScalar time, AppCtx app_ctx) { + char output_filename[PETSC_MAX_PATH_LEN]; PetscViewer viewer_p, viewer_u; PetscMPIInt rank; PetscFunctionBeginUser; // Create output directory MPI_Comm_rank(app_ctx->comm, &rank); - if (!rank) {PetscCall( PetscMkdir(app_ctx->output_dir) );} + if (!rank) { + PetscCall(PetscMkdir(app_ctx->output_dir)); + } // Build file name - PetscCall( PetscSNPrintf(output_filename, sizeof output_filename, - "%s/richard_pressure-%03" PetscInt_FMT ".vtu", - app_ctx->output_dir, - steps) ); - PetscCall(PetscViewerVTKOpen(app_ctx->comm, output_filename, - FILE_MODE_WRITE, &viewer_p)); + PetscCall(PetscSNPrintf(output_filename, sizeof output_filename, "%s/richard_pressure-%03" PetscInt_FMT ".vtu", app_ctx->output_dir, steps)); + PetscCall(PetscViewerVTKOpen(app_ctx->comm, output_filename, FILE_MODE_WRITE, &viewer_p)); PetscCall(VecView(U, viewer_p)); PetscCall(PetscViewerDestroy(&viewer_p)); // Project velocity to H1 - Vec U_H1; // velocity in H1 space for post-processing - PetscCall( DMCreateGlobalVector(app_ctx->ctx_H1->dm, &U_H1) ); - PetscCall( ProjectVelocity(app_ctx, U, &U_H1) ); + Vec U_H1; // velocity in H1 space for post-processing + PetscCall(DMCreateGlobalVector(app_ctx->ctx_H1->dm, &U_H1)); + PetscCall(ProjectVelocity(app_ctx, U, &U_H1)); // Build file name - PetscCall( PetscSNPrintf(output_filename, sizeof output_filename, - "%s/richard_velocity-%03" PetscInt_FMT ".vtu", - app_ctx->output_dir, - steps) ); - PetscCall(PetscViewerVTKOpen(app_ctx->comm, output_filename, - FILE_MODE_WRITE, &viewer_u)); + PetscCall(PetscSNPrintf(output_filename, sizeof output_filename, "%s/richard_velocity-%03" PetscInt_FMT ".vtu", app_ctx->output_dir, steps)); + PetscCall(PetscViewerVTKOpen(app_ctx->comm, output_filename, FILE_MODE_WRITE, &viewer_u)); PetscCall(VecView(U_H1, viewer_u)); PetscCall(PetscViewerDestroy(&viewer_u)); - PetscCall( VecDestroy(&U_H1) ); + PetscCall(VecDestroy(&U_H1)); PetscFunctionReturn(0); } // User provided TS Monitor -PetscErrorCode TSMonitorRichard(TS ts, PetscInt steps, PetscReal time, - Vec U, void *ctx) { - AppCtx app_ctx = (AppCtx)ctx; +PetscErrorCode TSMonitorRichard(TS ts, PetscInt steps, PetscReal time, Vec U, void *ctx) { + AppCtx app_ctx = (AppCtx)ctx; PetscFunctionBeginUser; // Print every 'output_freq' steps - if (app_ctx->output_freq <= 0 - || steps % app_ctx->output_freq != 0) - PetscFunctionReturn(0); + if (app_ctx->output_freq <= 0 || steps % app_ctx->output_freq != 0) PetscFunctionReturn(0); - PetscCall( WriteOutput(U, steps, time, app_ctx) ); + PetscCall(WriteOutput(U, steps, time, app_ctx)); PetscFunctionReturn(0); } // TS: Create, setup, and solve -PetscErrorCode TSSolveRichard(CeedData ceed_data, AppCtx app_ctx, - TS ts, Vec *U) { - TSAdapt adapt; +PetscErrorCode TSSolveRichard(CeedData ceed_data, AppCtx app_ctx, TS ts, Vec *U) { + TSAdapt adapt; PetscFunctionBeginUser; - PetscCall( TSSetDM(ts, app_ctx->ctx_residual_ut->dm) ); - PetscCall( TSSetType(ts, TSBDF) ); - PetscCall( TSSetIFunction(ts, NULL, TSFormIResidual, - app_ctx->ctx_residual_ut) ); - - PetscCall( TSSetMaxTime(ts, app_ctx->t_final) ); - PetscCall( TSSetExactFinalTime(ts, TS_EXACTFINALTIME_STEPOVER) ); - PetscCall( TSSetTimeStep(ts, 1.e-2) ); - PetscCall( TSGetAdapt(ts, &adapt) ); - PetscCall( TSAdaptSetStepLimits(adapt, 1.e-12, 1.e2) ); - PetscCall( TSSetFromOptions(ts) ); + PetscCall(TSSetDM(ts, app_ctx->ctx_residual_ut->dm)); + PetscCall(TSSetType(ts, TSBDF)); + PetscCall(TSSetIFunction(ts, NULL, TSFormIResidual, app_ctx->ctx_residual_ut)); + + PetscCall(TSSetMaxTime(ts, app_ctx->t_final)); + PetscCall(TSSetExactFinalTime(ts, TS_EXACTFINALTIME_STEPOVER)); + PetscCall(TSSetTimeStep(ts, 1.e-2)); + PetscCall(TSGetAdapt(ts, &adapt)); + PetscCall(TSAdaptSetStepLimits(adapt, 1.e-12, 1.e2)); + PetscCall(TSSetFromOptions(ts)); app_ctx->ctx_residual_ut->t = -1.0; - //ceed_data->ctx_residual_ut->dt = -1.0; + // ceed_data->ctx_residual_ut->dt = -1.0; if (app_ctx->view_solution) { - PetscCall( TSMonitorSet(ts, TSMonitorRichard, app_ctx, NULL) ); + PetscCall(TSMonitorSet(ts, TSMonitorRichard, app_ctx, NULL)); } // Solve PetscScalar start_time; - PetscCall( TSGetTime(ts, &start_time) ); + PetscCall(TSGetTime(ts, &start_time)); PetscCall(TSSetTime(ts, start_time)); PetscCall(TSSetStepNumber(ts, 0)); - PetscCall( PetscBarrier((PetscObject) ts) ); - PetscCall( TSSolve(ts, *U) ); + PetscCall(PetscBarrier((PetscObject)ts)); + PetscCall(TSSolve(ts, *U)); - PetscScalar final_time; - PetscCall( TSGetSolveTime(ts, &final_time) ); + PetscScalar final_time; + PetscCall(TSGetSolveTime(ts, &final_time)); app_ctx->t_final = final_time; PetscFunctionReturn(0); } - // -----------------------------------------------------------------------------