首页 > 解决方案 > 我怎么能在我的 C 代码中包含这个 C++ 函数

问题描述

我有以下 C 函数,它是用 C 编写的代码的一部分。

void pusher(int part, int ntime,long double x[3], long double v[3], long double E[3], long double B[3], long double Vth, long double c2, long double x_new[3], long double v_new[3]){

   long double x_mid[3];
   long double upart_new[3];

    // half time-step for Euler step
     long double dth = 0.5*dt;
    
    // position x_{i+1/2} at time t_{i+1/2} + dt/2 (1st-order Euler scheme)
    for(int i=0;i<3;i++){
        x_mid[i] = x[i] + v[i]*dth;
    }
 
   // TO DO: Get E, B at new position 

   /* I want to add the Cpp function at this point in the code. */
   
  // interpolate_fields();
    

   // 'Kick' particle (update velocity) based on the chosen integrator
    switch(pusher_name) {
    case 1 :
        Vay(v, E, B, c2, upart_new);
        break;
        
    case 0  :
        Boris_relativ(v, E, B, c2, upart_new);
        break; 
             
    }

    long double gL_new = gamma_u(upart_new, c2);
    // full position update at t_{i+1} = t_{i+1/2} + dt/2 = t_i + dt
   for(int i=0;i<3;i++){
        v_new[i]  = upart_new[i]/gL_new; 
        x_new[i]  = x_mid[i] + v_new[i]*dth;
        
   }

}

我还有以下 Cpp 函数,我想在代码中的指定点包含它。为避免在问题中包含 Cpp 代码,我已在此处上传文件:

https://www.dropbox.com/s/vbsxme9vozci4tz/ba_interp3.cpp?dl=0

这可能吗?

关于我如何做到这一点的任何建议?

标签: c++cfunction

解决方案


推荐阅读