comsol使用APP开发器建立随机生成的圆柱空隙,但是出现以下错误,param显示未被定义
以下为建立孔隙的comsol代码:
model.component("comp1").geom("geom1").selection().remove("csel1");
model.component("comp1").geom("geom1").feature().clear();
model.component("comp1").geom("geom1").designBooleans(true);
model.component("comp1").geom("geom1").repairTolType("auto");
int NUMBER_OF_HOLES = 80; // 孔隙数量
double MIN_DISTANCE = 0.5; // 孔隙之间最小距离
double MAX_TRIES = 1000; // 最大尝试次数
double hx, hy, hz, hr = 0.0; // 孔隙位置及半径初始化
double FLAT_HEIGHT = 0.35; // 板厚
double FLAT_LENGTH = 0.25; // 板长
double FLAT_WIDTH = 8; // 板宽
model.component("comp1").geom("geom1").lengthUnit("mm");
model.component("comp1").geom("geom1").autoBuildNew(false);
model.component("comp1").geom("geom1").autoRebuild("off");
model.component("comp1").geom("geom1").selection().create("csel1", "CumulativeSelection");
model.component("comp1").geom("geom1").create("blk1", "Block");
model.component("comp1").geom("geom1").feature("blk1").set("size", new double[]{FLAT_LENGTH, FLAT_WIDTH, FLAT_HEIGHT});
model.component("comp1").geom("geom1").run("blk1");
int ind = 0;
while (ind < NUMBER_OF_HOLES)
{
hx = hr+Math.random()*(FLAT_LENGTH-2*hr);
hy = hr+Math.random()*(FLAT_WIDTH-2*hr);
hz = Math.random()*0;
hr = 0.02; // 孔隙半径
boolean isValidHole = true;
int tries = 0;
while (isValidHole && tries < MAX_TRIES)
{
// Check if the current hole overlaps with any previous hole
isValidHole = true;
int holeInd = 0;
while (holeInd < ind && isValidHole) {
double dx = hx-model.component("comp1").geom("geom1").feature("cyl"+holeInd).param("pos").getReal(0);
double dy = hy-model.component("comp1").geom("geom1").feature("cyl"+holeInd).param("pos").getReal(1);
double dz = hy-model.component("comp1").geom("geom1").feature("cyl"+holeInd).param("pos").getReal(2);
double distance = Math.sqrt(dx*dx+dy*dy+dz*dz);
isValidHole = (distance > MIN_DISTANCE);
holeInd++;
}
// If the current hole is valid, create it and exit the loop
if (isValidHole) {
model.component("comp1").geom("geom1").create("cyl"+ind, "Cylinder");
model.component("comp1").geom("geom1").feature("cyl"+ind).set("pos", new double[]{hx, hy, hz});
model.component("comp1").geom("geom1").feature("cyl"+ind).set("r", hr);
model.component("comp1").geom("geom1").feature("cyl"+ind).set("h", FLAT_HEIGHT);
}
}
}
在comsol中报错为The method param(string) is undefined for the type GeomFeature,请问有人清楚发生错误的原因是什么吗