找回密码
 注册
Simdroid-非首页
查看: 959|回复: 12

[12.前后处理] COMSOL with MATLAB 应用实例(1)【天乐树】

[复制链接]
发表于 2013-7-10 10:42:16 | 显示全部楼层 |阅读模式 来自 上海
本帖最后由 TBE_Legend 于 2013-7-10 14:09 编辑

建立几何体,本例简单介绍如何运用CwM画几何实体
目的:在一个方形阵列中每个单元画三个半径随机的圆。
效果:

实现方法:
  1. % This is a script for Comsol(4.x) with Matlab.
  2. % It product random radius circles inside a square box array.
  3. %
  4. % Copyright to mxio at Shanghai University.
  5. %
  6. %                                                        mxio
  7. %                                                10,July,2013



  8. import com.comsol.model.*
  9. import com.comsol.model.util.*

  10. model = ModelUtil.create('Model');
  11. model.modelNode.create('mod1');
  12. model.geom.create('geom1', 2);

  13. % Model Parameters
  14. rd_seed = rng('shuffle');               % random number seed
  15. sq_length = 1;                          % square length
  16. sq_posx = 0;                            % square position x
  17. sq_posy = 0;                            % square position y
  18. sq_disx = 1.5;                          % square displacement x
  19. sq_disy = 1.5;                          % square displacement y
  20. sq_numx = 5;                            % square number x
  21. sq_numy = 5;                            % square number y
  22. sq_num = sq_numx * sq_numy;             % square number total

  23. cl_num = 3;                             % circle number inside the square
  24. cl_radius_normal = sq_length * 0.45;    % circle radius : half for the maximum
  25. co_min = 0.2;                           % random number must be > co_min
  26. %------------------------------------------------------------------------------------------------------------
  27. idx = 1;                                % index for square
  28. idx2 = 1;                               % index for circle
  29. for i = 1: sq_numx
  30.     for j = 1:sq_numy
  31.         sq_name = ['sq',num2str(idx)];
  32.         model.geom('geom1').feature.create(sq_name, 'Square');
  33.         model.geom('geom1').feature(sq_name).set('base', 'center');
  34.         model.geom('geom1').feature(sq_name).set('size', num2str(sq_length));
  35.         model.geom('geom1').feature(sq_name).setIndex('pos', num2str(sq_posx + (i-1)*sq_disx), 0);
  36.         model.geom('geom1').feature(sq_name).setIndex('pos', num2str(sq_posx + (j-1)*sq_disy), 1);
  37.             for k = 1:cl_num
  38.                 cl_name = ['c', num2str(idx2)];
  39.                 co_rand = rand();
  40.                 while co_rand < co_min
  41.                     co_rand = rand();
  42.                 end
  43.                 cl_radius = cl_radius_normal * co_rand;
  44.                 model.geom('geom1').feature.create(cl_name, 'Circle');
  45.                 model.geom('geom1').feature(cl_name).set('r', num2str(cl_radius));
  46.                 model.geom('geom1').feature(cl_name).setIndex('pos', num2str(sq_posx + (i-1)*sq_disx), 0);
  47.                 model.geom('geom1').feature(cl_name).setIndex('pos', num2str(sq_posx + (j-1)*sq_disy), 1);
  48.                 idx2 = idx2 +1;
  49.             end
  50.         idx = idx + 1;
  51.     end
  52. end
  53. model.geom('geom1').runAll;
  54. %------------------------------------------------------------------------------------------------------------

  55. mphsave(model,'rand_circle')
复制代码
mixo
2013.7.10

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

2

查看全部评分

发表于 2013-7-10 19:52:28 | 显示全部楼层 来自 北京
Simdroid开发平台
好东西  不过好像有些只有两个圆,如果根据随机数判断下,剔除这些就更完美了。
回复 不支持

使用道具 举报

 楼主| 发表于 2013-7-10 20:49:44 | 显示全部楼层 来自 上海
都是三环,只是半径相差不大而已。不知道应用背景的条件下,没必要写太复杂,只是拿来当教学案例罢了。。。。
回复 不支持

使用道具 举报

发表于 2013-12-4 21:48:01 | 显示全部楼层 来自 清华大学
mxio 发表于 2013-7-10 20:49
都是三环,只是半径相差不大而已。不知道应用背景的条件下,没必要写太复杂,只是拿来当教学案例罢了。。。 ...

太赞了!但是不知道效率如何,没有测试。我做复合材料模拟时需要很多小球(成千上万)随机分散在基体中,按此方法不知道会不会死掉。
回复 不支持

使用道具 举报

发表于 2013-12-25 20:21:53 | 显示全部楼层 来自 江苏
matlab不太会用
回复 不支持

使用道具 举报

发表于 2013-12-25 20:22:35 | 显示全部楼层 来自 江苏
matlab不太会用,
回复 不支持

使用道具 举报

发表于 2014-1-7 10:42:40 | 显示全部楼层 来自 福建厦门
好东西,学习学习
回复 不支持

使用道具 举报

发表于 2015-4-26 09:36:18 | 显示全部楼层 来自 江苏徐州
感谢分享,不错的
回复 不支持

使用道具 举报

发表于 2015-4-27 18:25:52 | 显示全部楼层 来自 陕西西安
不错,谢谢分享
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-26 14:16 , Processed in 0.041205 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表