介绍 comsol 其中两种几何选择,球选择和框选择。
球选择
根据圆心和半径选择几何对象
/**
* geom_select
*/
String SELECT_NAMED_FORMAT = "%s_%s";
/**
* 半径
*/
private static final double R = 1E-8;
public String createSelect(int entityDim, GeomSequence geom, String selectTag, double x, double y, double z) {
// 创建球选择
GeomFeature geomFeature = geom.create(selectTag, ComsolConstants.BallSelection);
// 设置几何实体层
geomFeature.set("entitydim", entityDim);
// 设置球心坐标
geomFeature.set("posx", x);
geomFeature.set("posy", y);
geomFeature.set("posz", z);
// 设置半径
geomFeature.set("r", R);
return String.format(SELECT_NAMED_FORMAT, geom.tag(), selectTag);
}
框选择
根据最大坐标和最小坐标框选对象
/**
* geom_select
*/
String SELECT_NAMED_FORMAT = "%s_%s";
/**
* 最小差值
*/
private static final double MIN = 0.00001;
public GeomFeature createSelect(int entityDim, GeomSequence geom, String boxSelectTag, double x, double y, double z) {
// 创建框选择
GeomFeature geomFeature = geom.create(boxSelectTag, ComsolConstants.BoxSelection);
// 设置几何实体层
geomFeature.set("entitydim", entityDim);
// 设置框区域
geomFeature.set("xmin", x - MIN);
geomFeature.set("xmax", x + MIN);
geomFeature.set("ymin", y - MIN);
geomFeature.set("ymax", y + MIN);
geomFeature.set("zmin", z - MIN);
geomFeature.set("zmax", z + MIN);
return geomFeature;
}
Demo
// 创建材料 mat1
Material material = model.material().create("mat1");
// 创建球选择
BallSelect ballSelect = new BallSelect();
String selectTag = ballSelect.selectTag();
String named = ballSelect.createSelect(3, geom, selectTag, 0.1, 0.1, 0.1);
// 材料 mat1 使用球选择 选择对象
material.selection().named(named);