我有一个有效的 C++ 函数:
/// Structure for surface nodes
// Each node has a current x- and y-position and a reference x- and y-position.
struct nstruct {
/// Constructor
node_struct() {
x = 0;
y = 0;
x_ref = 0;
y_ref = 0;
Ax = 0;
Ay = 0;
}
/// Elements
double x; // current x-position
double y; // current y-position
double x_ref; // reference x-position
double y_ref; // reference y-position
double Ax; // node (x-component)
double Ay; // node (y-component)
};
/// Structure for object
struct pstruct {
/// Constructor
pstruct() {
num_nodes = pnodes;
center.x;
center.y;
center.x_ref;
center.y_ref;;
node = new node_struct[num_nodes];
}
/// Elements
int num_nodes; // number of surface nodes
node_struct center; // center node
node_struct *node; // list of nodes
};
//
void Function(pstruct particle) {
for (int X = 0; X < Nx; ++X) {
for (int Y = 0; Y < Ny; ++Y) {
Ax[X][Y] = 0;
Ay[X][Y] = 0;
}
}
for (int n = 0; n < particle.num_nodes; ++n) {
int xStart = static_cast <int> (particle.node[n].x - 3.0);
int xEnd = static_cast <int> (particle.node[n].x + 3.0);
int yStart = static_cast <int> (particle.node[n].y - 3.0);
int yEnd = static_cast <int> (particle.node[n].y + 3.0);
for (int X = xStart; X < xEnd; ++X) {
for (int Y = yStart; Y <= yEnd; ++Y) {
**// here I want to use Lagrangian Interpolation**
const double xDistance = X - particle.node[n].x;
const double yDistance = Y - particle.node[n].y;
const double delta = dirac_4(xDistance, yDistance);
// dirac_4 : is Dirac Delta function
Ax[X][Y] += (particle.node[n].Ax * delta);
Ay[X][Y] += (particle.node[n].Ay * delta);
}
}
}
return;
}
它是一个沉浸式边界问题。我在对象(圆形或任何形状)、相应的加速度等上有拉格朗日点。我想做的是使用拉格朗日点的信息(在 pstruct 和 nstruct 中定义)在欧拉网格上插值流变量。我想使用拉格朗日插值而不是 dirac_4 函数来计算 Ax 和 Ay。在这种情况下,我将如何实现拉格朗日/多项式插值?
问候