请教:关于动网格中使用interfaceHeight工具监测波高的问题
-
前辈老师们好!最近在做液舱晃荡相关模拟,想使用OpenFOAM自带的interfaceHeight工具进行波高的监测,但该工具定义的监测点无法跟随动网格的运动而运动。
举例说明:假如需要监测液舱舱壁处某位置的波高,由于舱壁是运动的,因此监测点需要跟随舱壁一起运动,因此目前的想法是修改interfaceHeight工具的代码,使得监测点能够以跟动网格同样的规律运动起来。
interfaceHeight.H定义的监测点坐标为:
//- List of locations to report the height at List<point> locations_;
以线性简谐运动网格oscillatingLinearMotion为例,其控制运动的部分代码如下:
Foam::solidBodyMotionFunctions::oscillatingLinearMotion::transformation() const { scalar t = time_.value(); const vector displacement = amplitude_*sin(omega_*t); …… }
设定振幅与频率,使得液舱以如下规律做横向振荡运动:
\begin{equation}
\lambda=0.001sin(5.0498t)
\end{equation}
要使监测点以同样的规律运动起来,在振幅与频率已知的情况下,则需要获取时间t,因此仿造动网格文件获取时间的方式,在interfaceHeight.C中修改监测点坐标代码如下,拟监测随体坐标上(0.5,0,0.5)处的波高:void Foam::functionObjects::interfaceHeight::writePositions() { scalar time = time_.value(); locations_[0][0] = 0.5 + 0.001*sin(5.0498*time); locations_[0][1] = 0; locations_[0][2] = 0.5; …… }
其余部分均未改变,但在编译时报错:
movingInterfaceHeight.C:(.text+0x1f30): multiple definition of `non-virtual thunk to Foam::functionObjects::interfaceHeight::write()'; /home/user/OpenFOAM/OpenFOAM-8/platforms/linux64GccDPInt32Opt/src/functionObjects/field/interfaceHeight/interfaceHeight.o:interfaceHeight.C:(.text+0x1f00): first defined here collect2: error: ld returned 1 exit status make: *** [/home/user/OpenFOAM/OpenFOAM-8/wmake/makefiles/general:169:/home/user/OpenFOAM/OpenFOAM-8/platforms/linux64GccDPInt32Opt/lib/libfieldFunctionObjects.so] 错误 1
想请教前辈老师们,这种错误该如何解决呢?这么修改使得监测点动起来的方式正确吗?感谢前辈老师们的解答!
-
openfoam-8里面怎么跟你的区别这么大,我的interfaceHeight是这样的:
// Write out if (Pstream::master()) { // Interface heights above the boundary and location const scalar hIB = liquid_ ? sumLengthAlpha : sumLength - sumLengthAlpha; const scalar hIL = hIB - hLB; // Position of the interface const point p = locations_[li] - gHat*hIL; const Foam::Omanip<int> w = valueWidth(1); file(fileID::heightFile) << w << hIB << w << hIL; file(fileID::positionFile) << '(' << w << p.x() << w << p.y() << valueWidth() << p.z() << ") "; }
按照你的思路,你把你的代码加到
const point p = locations_[li] - gHat*hIL;
这个的定义里面不可以么?:scalar time = time_.value(); const point p = 0.5 + 0.001*sin(5.0498*time) - gHat*hIL;
-
@李东岳 感谢李老师的解答!老师,我用的也是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;
感谢李老师指导!