Openfoam自定义边界条件


不知道为什么会出现这种情况,向大家请教一下

可以看一下constant/polymesh的边界条件与0文件下的边界条件是否对应

看了,是完全对应的

大小写是否一致呢?

大小写是一样的。

你把codestream的代码放出来。上面的图片你要截取错误信息,你上面只有一个警报和最终没有编译成功。所以没法解答。

给你一个我之前写过的例子参考一下(OpenFOAM-v2012的):

internalField		#codeStream
    {
	codeInclude
	#{
	    #include "fvCFD.H"
	#};

	codeOptions
	#{
	    -I$(LIB_SRC)/finiteVolume/lnInclude \
	    -I$(LIB_SRC)/meshTools/lnInclude
	#};

	codeLibs
	#{
	    -lmeshTools \
	    -lfiniteVolume
	#};

	code
	#{
	    const IOdictionary& d = static_cast<const IOdictionary&>(dict);
	    const fvMesh& mesh = refCast<const fvMesh>(d.db());

	    scalarField alpha(mesh.nCells(), 0.);

	    forAll(alpha, i)
	    {
		const scalar x = mesh.C()[i][0];
		const scalar y = mesh.C()[i][1];

		// if (y >= 2.1 + 0.1*Foam::pow(cos(constant::
		// 	mathematical::pi*x)*cos(constant::mathematical::pi*x), 2))
		if (y >= 2.0 + 0.05*cos(constant::
			mathematical::pi*2.0*x))
		{
		    alpha[i] = 1.;
		}
	    }

		// writeEntry(os, alpha); for OpenFOAM-v8
	    alpha.writeEntry("", os);
	#};
    };
2 个赞

写得太好了,太棒!

FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
inlet
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include “fvCFD.H”
#};

         codeOptions
         #{
              -I$(LIB_SRC)/finiteVolume/lnInclude \
              -I$(LIB_SRC)/meshTools/lnInclude
         #};
         
         codeLibs
         #{
              -lmeshTools \
              -lfiniteVolume
         #};
         
         code
         #{
              const IOdictionary& d = static_cast<const IOdictionary&>
              ( dict.parent().parent() );
              const fvMesh& mesh = refCast<const fvMesh>(d.db());
              const label id = mesh.boundary().findPatchID("inlet");
              const fvPatch& patch = mesh.boundary()[id];
  
              vectorField U(patch.size(), vector(0, 0, 0));
              const scalar pi = constant::mathematical::pi;
              const scalar U_0 = 0.5;
              const scalar D = 0.03;
              
              forAll(U,i)
              {
                   const scalar y = patch.Cf()[i][1];
                   U[i] = vector(U_0*(pow(y/D,1/7)), 0., 0.);
              }
              Info << patch.size() << endl;
              U.writeEntry(os, "", U);
          #};
     }
}

outlet
{
    type            fixedValue;
    value           uniform (0 0 0);
}

upperWall
{
    type            fixedValue;
    value           uniform (0 0 0);
}

lowerWall
{
    type            fixedValue;
    value           uniform (0 0 0);
}

frontWall
{
    type            fixedValue;
    value           uniform (0 0 0);
}
backWall
{
    type            fixedValue;
    value           uniform (0 0 0);
}
sphere
{
    type            fixedValue;
    value           uniform (0 0 0);
}

}

太感谢了,刚才我把我的代码发给你了 :grin:

你这样编译不过么?我扫了一遍貌似没有看到错误。

是的,一直不能成功 :pensive:

可能是不匹配的原因,你需要把错误信息放出来,不然只能猜。。比如你在db里面找的inlet边界,实际上你在polyMesh/boundary中定义的是Inlet,那就会出错。

image
我定义的是inlet :disappointed_relieved:

那我猜不出来了。。。你发个错误信息才能帮你呀

image
这个type fixedvalue 改成codedFixedValue试一下

1 个赞

试试这个,应该可以,不过你的pi没有用啊,我给注释了

    inlet
    {
        type            codedFixedValue;
        value           uniform (0 0 0);  //default value
        name            powvelocity;      //name of new BC type

        code
        #{
            const fvPatch &boundaryPatch = patch();
            const fvBoundaryMesh &boundaryMesh = boundaryPatch.boundaryMesh();
            const fvMesh &mesh = boundaryMesh.mesh();
            const fvPatchField<vector> &U =
                boundaryPatch.lookupPatchField<volVectorField, vector>("U");

            const vectorField FC = mesh.Cf();
            const scalarField y = FC&vector(0,1,0);
            
            vectorField U1 (U.size(), Zero);
            // const scalar pi = M_PI;
            const scalar U_0 = 0.5;
            const scalar D = 0.03;

            forAll(boundaryPatch, i)
            {
                U1[i] = vector(U_0*(pow(y[i]/D,1/7)), 0., 0.);
            }

            operator==(U1);
        #};
    }
1 个赞