Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: add basis transformation procedure #984

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions interface/ceed-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,28 +1231,30 @@ int CeedBasisDestroy(CeedBasis *basis) {

@ref Utility
**/
int CeedHaleTrefethenStripMap(CeedInt Q, CeedInt rho, CeedScalar *g, CeedScalar *g_prime) {
CeedScalar tau, d, C, PI2, PI = 4.0*atan(1.0);
int CeedHaleTrefethenStripMap(CeedInt Q, CeedScalar rho, CeedScalar *g, CeedScalar *g_prime) {
Copy link
Member

Choose a reason for hiding this comment

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

This still isn't a function $g(s)$ as we've discussed. You'll need to take const CeedScalar *s as an argument, then write g[i] as a function of s[i].
image

CeedScalar i, tau, d, C, PI2, PI = 4.0*atan(1.0);
CeedScalar u[Q];
tau = PI / log(rho);
d = .5 + 1. / (exp(tau * PI) + 1.0)
PI2 = PI / 2.0;
// u = asin(s)
for (int i = 0; i < Q; i++) {
u = (PI * i) / Q;
u[i] = (asin(PI) * i) / Q;
// Unscaled function of u
g_u = log(1.0 + exp(-tau * (PI2 + u))) - log(1.0 + exp(-tau * (PI2 - u))) + d * tau * u;
g_prime_u = 1.0 / (exp(tau * (PI2 + u)) + 1) + 1.0 / (exp(tau * (PI2 - u)) + 1) - d;
// Normalizing factor and scaled function
C = 1.0 / g_u;
g = C * g_u;
g_prime = -tau * C ;
g_u[i] = log(1.0 + exp(-tau * (PI2 + u[i]))) - log(1.0 + exp(-tau * (PI2 - u[i]))) + d * tau * u[i];
g_prime_u[i] = 1.0 / (exp(tau * (PI2 + u[i])) + 1) + 1.0 / (exp(tau * (PI2 - u[i])) + 1) - d;
// Normalizing factor and scaled function of s
C = 1.0 / log(1.0 + exp(-tau * (PI2 + PI2))) - log(1.0 + exp(-tau * (PI2 - PI2))) + d * tau * PI2;
g[i] = C * g_u[i];
g_prime[i] = -tau * C / sqrt(1.0 - sin(u[i]) * sin(u[i])) * g_prime_u[u[i]];
}
return CEED_ERROR_SUCCESS;
}

/**
@brief Transform quadrature by applying a smooth mapping = (g, g_prime)

@param Q Number of quadarture points
@param Q Number of quadrature points
Copy link
Member

Choose a reason for hiding this comment

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

In general, every argument has to be documented. I don't know what you intend this function to do; maybe it can be deleted or maybe it needs to take a CeedBasis as input and create a CeedBasis as output.


@return An error code: 0 - success, otherwise - failure

Expand All @@ -1264,10 +1266,19 @@ int CeedTransformQuadrature(CeeddInt Q, CeedScalar *q_weight_1d) {
if (!q_weight_1d)
points = Q;
else
points = Q;
weights = q_weight_1d;
points = Q;
weights = q_weight_1d;
}

m_points = ; // apply map g on quadrature points
if (q_weight_1d) {
m_weights = ; //apply derivative of map g on quadrature weights evaluated at quadrature points
m_points = ;
m_weights = ;
}
else {
m_points = ;
}
return CEED_ERROR_SUCCESS;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/t333-basis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// @file
/// Test that Hale-Trefethen transform works
/// \test Test that Hale-Trefethen transform works
#include <ceed.h>
#include <math.h>

int main(int argc, char **argv) {
Ceed ceed;
CeedInt Q = 16;
CeedScalar rho;
CeedScalar *g, *g_prime;

CeedHaleTrefethenStripMap();
Copy link
Member

Choose a reason for hiding this comment

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

We talked about checking by spot-checking accuracy relative to figure 7.1a. How would you test that? Take 20-point Gauss quadrature and integrate the function, then transform the quadrature points and weights, and integrate that way in $[-1, 1]$. The second should be more accurate.

image



CeedDestroy(&ceed);
return 0;
}
16 changes: 16 additions & 0 deletions tests/t334-basis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// @file
/// Test that quadrature formula is transformed
/// \test Test that quadrature formula is transformed
#include <ceed.h>

int main(int argc, char **argv) {
Ceed ceed;
CeedInt Q = 16;
CeedScalar *q_weight_1d;
CeedBasis basis;

CeedTransformQuadrature();

CeedDestroy(&ceed)
return 0;
}