如何在openfoam中求解一元高次方程
-
如图
k1 k2 $We_0$ 都是常数,我想求解 $r_bu$原文中是这么说的
The solution was numerically calculated using the linear interpolation method.我使用了二分法求该方程,但是问题是现在不知道该如何将其放入CloudFunction中。
不知道哪里去define 一些东西。 -
#include <iostream> #include "fvCFD.H" #include <stdio.h> #include <math.h> using namespace std; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // long double f(float x){ long double f; f= 0.75/1.414*8.5*0.45*5.0 * pow(x,3) + pow(x,2) - 1.0; return f; } // Main program: int main() { long double x1,x2,x0,t,counter = 0.0; x1 = -10; x2 = 10; do{ x0=(x1+x2)/2.0; if( f(x0) * f(x1) > 0) { x1=x0; } else if (f(x0) * f(x1) < 0) { x2 = x0; } t =fabs( f(x0)); counter +=1; cout <<"Counter = "<< counter <<nl; cout <<"t = "<< t <<nl; if (counter > 100000) { break; } }while(t> 1e-5); cout<<"x0 = "<<x0<<nl; cout << " solution = " << x0<<nl; cout << "Hello World "<<nl; return 0; } // ************************************************************************* //
-
或者说有没有其他的解法?
例如该方法能不能解?
该如何修改该部分code呢??麻烦大佬指点 谢谢!
-
你的方程就是求$x^{3.5}+x^2-1=0$的根吧?
但是问题是现在不知道该如何将其放入CloudFunction中。
不知道哪里去define 一些东西。
你是要放在某个C程序里么还是什么地方?
-
放在lagrangian 下面的submodel中
-
求根可以直接写成任意一个rootFinding函数,可以放在任何subModels下面的.C文件里面?
-
@东岳 大哥,这对我来说有点超纲
-
求解该方程会在下面的这个class里面,但是我不知道在哪能定义f那个函数
template<class CloudType> void Foam::IVT41_StochasticDDCollModel<CloudType>::postMove ( parcelType& p, const label cellI, const scalar dt, const point&, bool& ) { //*code }
-
@东岳
上图的函数会在lagrangian/intermediate/submodel/CloudFunctionObjects 里,是自定义的一个模型 -
@东岳 是我着相了。。。我好傻,直接算就好了,干嘛搞一个class function。。。
scalar k1 = 8.5; scalar k2 = 0.45; scalar rbu_avg; scalar x0 = 0.0; scalar x2_rlarge = Dmax/2.0; scalar x1_rsmall = Dmin/2.0; scalar sat_counter = 0; scalar eps = 0.0; do { scalar x0 = (x2_rlarge + x1_rsmall) / 2.0; scalar x0_ytempavg = 0.75/sqrt(x0) * k1 *k2 * We0 * pow(x0,7.0/2.0) + pow(x0,2.0) - 1.0 ; scalar x2_ytemplarge = 0.75/sqrt(x2_rlarge) * k1 *k2 * We0 * pow(x2_rlarge,7.0/2.0) + pow(x2_rlarge,2.0) - 1.0 ; scalar x1_ytempsmall = 0.75/sqrt(x1_rsmall) * k1 *k2 * We0 * pow(x1_rsmall,7.0/2.0) + pow(x1_rsmall,2.0) - 1.0 ; if( x0_ytempavg * x1_ytempsmall > 0) { x1_rsmall=x0; } else if (x0_ytempavg * x1_ytempsmall < 0) { x2_rlarge = x0; } eps = fabs( x0_ytempavg); sat_counter +=1; if (sat_counter > 100000) { break; } }while(eps > 1e-6); rbu_avg = x0;
-
@星星星星晴 是的
-
@星星星星晴 老师您好,我遇到了和您一样的问题,但是我把您这段代码算下来,遇到了几个问题:
1.把这段代码放在OpenFOAM里的时候,会报错说重载的pow()模棱两可,“call of overloaded ‘pow(Foam::scalar&, Foam::scalar)’ is ambiguous”
2.我用这段代码计算一元高次方程时候总不收敛,请问您之前有这问题吗?
3.我也关注了您这篇帖子这部分内容,我看2007年的论文“A new predictive model for fragmenting and non-fragmenting binary droplet collisions”里说先把2.7次幂转换成4次幂和3次幂的两个方程,再用Runge-Kutta法进行了四次迭代,但是我没搞懂怎么用Runge-Kutta求解非微分方程,请问老师您后来尝试过用论文里的方法求解方程吗?或者对帖子里这段代码有什么改进吗? -
@jqbu 哎呀 难得有个同行,这部分后来我没用二分法
找到了一个 Newton-Raphson method iteration method。
可能是当年弄的时候有问题?我也忘了,有点久远。
反正我这边算起来还行,就再也没动过。 -
@jqbu 聊一下~ 你是哪个学校的啊?
-
老师好,我是天津大学的学生,请问老师方便留个邮箱后续沟通吗?
-
@星星星星晴 谢谢老师,我也尝试一下这个牛顿迭代法
-
@jqbu 好的,看我资料~
-
@jqbu m.sui20@foxmail.com 我记得之前资料能显示邮件的。。现在不知道怎么设置回去了
-
@jqbu 在 如何在openfoam中求解一元高次方程 中说:
会报错说重载的pow()模棱两可,“call of overloaded ‘pow(Foam::scalar&, Foam::scalar)’ is ambiguous”
用:
::pow()
或者Foam::pow