请教各位前辈一个简单的编程问题。我先用topoSet在网格中创建内部cellZone,名称为interior。现在想对interior每个网格体心的U赋值,代码如下:
label patchID = mesh.cellZones().findZoneID("interior");
const labelList cells = mesh.cellZones()[patchID];
forAll(cells, i)
{
label celli = cells[i];
U[celli] = vector(0.1, 0.1, 0.1);
}
如果是边界,一般可以写成引用的方式:
label patchID = mesh.boundaryMesh().findPatchID("inlet");
vectorField& patchField = U.boundaryFieldRef()[patchID];
以上方式是可以实现赋值,想问的问题是:
(1)内部cellZone是否可以类似写成引用的形式,再对patchField赋值?类似边界场写成以下形式会报错,但不知道怎么修改:
label patchID = mesh.cellZones().findZoneID("interior");
vectorField& patchField = U.primitiveFieldRef()[patchID];
报错如下:
error: invalid initialization of reference of type 'Foam::vectorField&' {aka 'Foam::Field<Foam::Vector<double> >&'} from expression of type 'Foam::Vector<double>'
180 | vectorField& patchField = U.primitiveFieldRef()[patchID];
|
(2)U[celli]和U.primitiveField()[celli]这两者有无区别?测试效果好像是一样的
forAll(cells, i)
{
label celli = cells[i];
U[celli] = vector(0.1, 0.1, 0.1);
U.primitiveField()[celli] = vector(0.1, 0.1, 0.1);
}