在使用codedFixedValue边界条件时,如何获得网格中心坐标?
-
大家好,我在学习一个
shotSleeveModeling
的动网格案例,几何模型如下,运动边界为movingWalls
;我采用
codedFixedValue
边界条件,实现了movingWalls
边界的往复运动,pointDisplacement
和dynamicMeshDict
文件的部分内容如下://pointDisplacement boundaryField { "(outlet|fixedWalls)" { type fixedValue; value uniform (0 0 0); } movingWalls { type codedFixedValue; value uniform (0 0 0); name name_of_BC; code #{ //const fvPatch & boundaryPatch = patch(); //const Patch & boundaryPatch = patch(); //const vectorField & Cf = boundaryPatch.Cf(); vectorField & field = *this; scalar U_0 = 0.1, p_r = 0.03; scalar t = this->db().time().value(); forAll(field, faceI) { //const scalar x = boundaryPatch.Cf()[faceI][0]; //const scalar y = boundaryPatch.Cf()[faceI][1]; //const scalar z = boundaryPatch.Cf()[faceI][2]; field[faceI].x() = 0; field[faceI].y() = 0; field[faceI].z() = U_0*sin(t); //field[faceI].z() = U_0*sin(t)*pow(field[faceI].y(),2)/(p_r*p_r); } #}; } slipWalls { type calculated; } frontAndBack { //type empty; type calculated; } }
//dynamicMeshDict dynamicFvMesh dynamicMotionSolverFvMesh; motionSolverLibs ( "libfvMotionSolvers.so" ); motionSolver displacementLayeredMotion; cellZone movingCells; displacementLayeredMotionCoeffs { regions { movingCells { interpolationScheme linear; boundaryField { movingFaces { type follow; } boundaryMovingFixed { type fixedValue; value uniform (0 0 0); } } } } }
movingWalls
边界的往复运动如下图所示:在实现往复运动的基础上,我想让
movingWalls
沿y
轴方向从中间到两边的网格运动速度递减,呈一个抛物线型,因此我需要获得网格中心坐标;首先,我在
pointDisplacement->movingWalls->code#{ #}
中增加如下语句,会报错:const fvPatch & boundaryPatch = patch();
不过按照提示将上述语句中的
fvPatch
改成Patch
,就可以解决错误了。但是当我在
pointDisplacement->movingWalls->code#{ #}
中再增加如下语句,用来获得网格中心坐标时,也会报错:const vectorField & Cf = boundaryPatch.Cf(); //网格中心
报错内容为:
/mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement.boundaryField.movingWalls:40:52: error: ‘const Patch’ {aka ‘const class Foam::pointPatch’} has no member named ‘Cf’
我用了OpenFOAM9和OpenFOAM v2112,都会出错。按照提示,应该是
Patch
下面没有Cf
这个成员,但是我看了很多教程获取网格坐标都是用的Cf
。我卡在这很久了,都不知道要怎么修改,希望有知道的大神能指导下,多谢!!! -
@李东岳 李老师好!
OpenFOAM我刚开始学,所以不是很懂,不知道您说的是不是这样使用,可以获得网格x方向的坐标:forAll(field, faceI) { const scalar x = mesh.Cf().boundaryField()[faceI][0]; field[faceI].x() = 0; field[faceI].y() = 0; field[faceI].z() = U_0*sin(t); }
在这样使用时会报错:
error: ‘mesh’ was not declared in this scope
请问这是为什么。
-
@李东岳 请问李老师,
codedFixedValue
边界条件在U
文件和pointDisplacement
文件中获得网格坐标的方法是不是不通用,同样的代码,如:type codedFixedValue; value uniform (0 0 0); name name_of_BC; code #{ const Patch& boundaryPatch = patch(); const vectorField& Cf = patch().Cf(); #};
在
U
文件里可以使用,在pointDisplacement
文件里就会出错。出错内容如下:
Create time Create mesh for time = 0 Selecting dynamicFvMesh dynamicMotionSolverFvMesh Selecting motion solver: displacementLayeredMotion Using dynamicCode for codedFixedValue name_of_BC at line 32 in "/mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls" Creating new library in "dynamicCode/name_of_BC/platforms/linux64GccDPInt32Opt/lib/libname_of_BC_2749dd0d9becc7c4794a34f8159e9b4cbe66efce.so" "/home/dyfluid/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codedFixedValuePointPatchFieldTemplate.C" "/mnt/hgfs/share/shotSleeveModeling3/dynamicCode/name_of_BC/codedFixedValuePointPatchFieldTemplate.C" "/home/dyfluid/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codedFixedValuePointPatchFieldTemplate.H" "/mnt/hgfs/share/shotSleeveModeling3/dynamicCode/name_of_BC/codedFixedValuePointPatchFieldTemplate.H" Invoking "wmake -s libso /mnt/hgfs/share/shotSleeveModeling3/dynamicCode/name_of_BC" wmake libso /mnt/hgfs/share/shotSleeveModeling3/dynamicCode/name_of_BC ln: ./lnInclude ln: failed to create symbolic link './codedFixedValuePointPatchFieldTemplate.C': Operation not supported ln: failed to create symbolic link './codedFixedValuePointPatchFieldTemplate.H': Operation not supported wmkdep: codedFixedValuePointPatchFieldTemplate.C Ctoo: codedFixedValuePointPatchFieldTemplate.C /mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls: In member function ‘virtual void Foam::name_of_BCFixedValuePointPatchVectorField::updateCoeffs()’: /mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls:39:45: error: ‘const class Foam::pointPatch’ has no member named ‘Cf’ /mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls:37:14: warning: unused variable ‘boundaryPatch’ [-Wunused-variable] /mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls:39:32: warning: unused variable ‘Cf’ [-Wunused-variable] make: *** [/home/dyfluid/OpenFOAM/OpenFOAM-9/wmake/rules/General/transform:26: Make/linux64GccDPInt32Opt/codedFixedValuePointPatchFieldTemplate.o] Error 1 --> FOAM FATAL IO ERROR: Failed wmake "dynamicCode/name_of_BC/platforms/linux64GccDPInt32Opt/lib/libname_of_BC_2749dd0d9becc7c4794a34f8159e9b4cbe66efce.so" file: /mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls from line 32 to line 36. From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const in file db/dynamicLibrary/codedBase/codedBase.C at line 209. FOAM exiting
其中最关键的感觉是这几处:
ln: failed to create symbolic link './codedFixedValuePointPatchFieldTemplate.C': Operation not supported ln: failed to create symbolic link './codedFixedValuePointPatchFieldTemplate.H': Operation not supported
/mnt/hgfs/share/shotSleeveModeling3/0/pointDisplacement/boundaryField/movingWalls:39:45: error: ‘const class Foam::pointPatch’ has no member named ‘Cf’
在
U
文件使用上述代码,只会出现第一处提示,不会出现第二处错误。 -
const fvMesh& mesh = refCast<const fvMesh>(this->db());
赋值建议采用
operator==(field);
具体可以参考codedFixedValuePointPatchField.H的注释
Example: movingWall { type codedFixedValue; value uniform 0; name rampedFixedValue; // name of generated bc code #{ operator== ( vector(0,0,1) *min(10, 0.1*this->db().time().value()) ); #}; // codeInclude //#{ // #include "fvCFD.H" //#}; // codeOptions //#{ // -I$(LIB_SRC)/finiteVolume/lnInclude //#}; }
-
pointMotionU
和pointDisplacement
这些控制动网格节点的边界条件文件的数据类型是pointVectorField
,对应的patch类是Foam::pointPatch
而不是Foam::fvPatch
,这应该就是报错的根本原因。我的思路如下:
// 获取pointPatch的ID,它和相同边界上的fvPatch的ID是一致的 label patchIndex = patch().index(); // 在objectRegistry随意获取一个存在的物理场 const volScalarField & p ( this->db().objectRegistry::lookupObject<volScalarField>("p"); ); // 从上述物理场中访问fvMesh中的体心/面心场 const vectorField& Cfp = p.mesh().Cf().boundaryField()[patchIndex];