@李东岳 感谢李老师的解答!老师,我用的也是openfoam8,截取代码的时候没全截取给您带来误解了,抱歉。我是将代码添加在了writePositions()函数的最前面,如下:
void Foam::functionObjects::movingInterfaceHeight::writePositions() { scalar time = time_.value(); locations_[0][0] = 0.5 + 0.001*sin(5.3*time); locations_[0][1] = 0; locations_[0][2] = 0.5; const uniformDimensionedVectorField& g = mesh_.lookupObject<uniformDimensionedVectorField>("g"); const vector gHat = g.value()/mag(g.value()); const volScalarField& alpha = mesh_.lookupObject<volScalarField>(alphaName_); autoPtr<interpolation<scalar>> interpolator ( interpolation<scalar>::New(interpolationScheme_, alpha) );writePositions()函数下,最前面的两行即为添加的代码,后来我将整个interfaceHeight工具的代码复制了重新构建了一个“movingInterfaceHeight”工具,重新编译后问题解决了。
按照老师您说的,将其添加在const point p = locations_[li] - gHat*hIL的定义中存在一定的问题:
// Position of the interface const point p = locations_[li] - gHat*hIL;其中的locations_[li]为三维坐标点,point p = locations_[li] - gHat*hIL对xyz坐标均进行了计算,按照我的简谐运动规律$\lambda=0.001sin(5.0498t)$,仅x坐标发生改变,y与z应在坐标不变的情况下完成```point p``的计算,是否可以修改成以下代码:
// Position of the interface const point p = locations_[li]; //首先定义一个point p scalar time = time_.value(); //分别对p的xyz坐标进行计算 p.x() = 0.5 + 0.001*sin(5.0498*time) - gHat*hIL; p.y() = 0 - gHat*hIL; p.z() = 0.5 - gHat*hIL;感谢李老师指导!