- 积分
- 15
- 注册时间
- 2011-4-2
- 仿真币
-
- 最后登录
- 1970-1-1
|
本帖最后由 TBE_Legend 于 2013-7-10 14:09 编辑
建立几何体,本例简单介绍如何运用CwM画几何实体
目的:在一个方形阵列中每个单元画三个半径随机的圆。
效果:
实现方法:- % This is a script for Comsol(4.x) with Matlab.
- % It product random radius circles inside a square box array.
- %
- % Copyright to mxio at Shanghai University.
- %
- % mxio
- % 10,July,2013
- import com.comsol.model.*
- import com.comsol.model.util.*
- model = ModelUtil.create('Model');
- model.modelNode.create('mod1');
- model.geom.create('geom1', 2);
- % Model Parameters
- rd_seed = rng('shuffle'); % random number seed
- sq_length = 1; % square length
- sq_posx = 0; % square position x
- sq_posy = 0; % square position y
- sq_disx = 1.5; % square displacement x
- sq_disy = 1.5; % square displacement y
- sq_numx = 5; % square number x
- sq_numy = 5; % square number y
- sq_num = sq_numx * sq_numy; % square number total
- cl_num = 3; % circle number inside the square
- cl_radius_normal = sq_length * 0.45; % circle radius : half for the maximum
- co_min = 0.2; % random number must be > co_min
- %------------------------------------------------------------------------------------------------------------
- idx = 1; % index for square
- idx2 = 1; % index for circle
- for i = 1: sq_numx
- for j = 1:sq_numy
- sq_name = ['sq',num2str(idx)];
- model.geom('geom1').feature.create(sq_name, 'Square');
- model.geom('geom1').feature(sq_name).set('base', 'center');
- model.geom('geom1').feature(sq_name).set('size', num2str(sq_length));
- model.geom('geom1').feature(sq_name).setIndex('pos', num2str(sq_posx + (i-1)*sq_disx), 0);
- model.geom('geom1').feature(sq_name).setIndex('pos', num2str(sq_posx + (j-1)*sq_disy), 1);
- for k = 1:cl_num
- cl_name = ['c', num2str(idx2)];
- co_rand = rand();
- while co_rand < co_min
- co_rand = rand();
- end
- cl_radius = cl_radius_normal * co_rand;
- model.geom('geom1').feature.create(cl_name, 'Circle');
- model.geom('geom1').feature(cl_name).set('r', num2str(cl_radius));
- model.geom('geom1').feature(cl_name).setIndex('pos', num2str(sq_posx + (i-1)*sq_disx), 0);
- model.geom('geom1').feature(cl_name).setIndex('pos', num2str(sq_posx + (j-1)*sq_disy), 1);
- idx2 = idx2 +1;
- end
- idx = idx + 1;
- end
- end
- model.geom('geom1').runAll;
- %------------------------------------------------------------------------------------------------------------
- mphsave(model,'rand_circle')
复制代码 mixo
2013.7.10
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
评分
-
2
查看全部评分
-
|