Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Creating Geometry with Loop in COMSOL with MATLAB
Posted 2017年1月16日 GMT-5 01:42 Interfacing, Geometry Version 5.2 4 Replies
Please login with a confirmed email address before reporting spam
Dear COMSOL Team,
I am interested in creating a geometry in COMSOL 5.2 which consists of many spheres with their radii varying in unique manner iterated in a loop (example, r(i+1) =r(i)+1). I am trying to create this using COMSOL with MATLAB platform but not able to achieve the result. I think that the problem is that the COMSOL variable of the geometry name is not getting updated in COMSOL. Below is the script that i am running in MATLAB window.
model = ModelUtil.create('Model2');
geom1 = model.geom.create('geom1', 3);
r=1;C1=1;C2=1;C3=1; %matlab variables
for j=1:1:10
model.param.set('r',r,'radius');
model.param.set('C1',C1,'coordinate of center');
model.param.set('C2',C2,'coordinate of center');
model.param.set('C3',C3,'coordinate of center');
geom1.feature.create('sphj','Sphere');
model.geom('geom1').feature('sphj').label('Sphere j');
model.geom('geom1').feature('sphj').set('r', r);
model.geom('geom1').feature('sphj').set('pos', {'C1' 'C2' 'C3'});
model.geom('geom1').run('sphj');
r=r+1;
C1=C1+1;
C2=C2+1;
C3=C3+1;
end
geom1.run;
mphgeom(model)
On running this code i could only get the first sphere made and the remaining sphere is not getting created. I am getting the below error:
Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
(rethrown as com.comsol.util.exceptions.FlException)
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
An object with the given name already exists
An object with the given name already exists
An object with the given name already exists.
- Tag: sphj
Stack trace:
at com.comsol.clientapi.engine.c.handleException(Unknown Source)
at com.comsol.client.interfaces.f$d.e(Unknown Source)
at com.comsol.client.interfaces.f.a(Unknown Source)
at com.comsol.client.interfaces.f.runAndWait(Unknown Source)
at com.comsol.clientapi.engine.APIEngine.runMethod(Unknown Source)
at com.comsol.clientapi.impl.GeomFeatureListClient.create(Unknown Source)
at com.comsol.clientapi.impl.GeomFeatureListClient.create(Unknown Source)
Caused by: Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
An object with the given name already exists
An object with the given name already exists.
- Tag: sphj
at com.comsol.clientapi.engine.c.handleException(Unknown Source)
at com.comsol.client.interfaces.f.a(Unknown Source)
at com.comsol.client.interfaces.f.processCommandAnswer(Unknown Source)
... 6 more
Caused by: Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
Messages:
An object with the given name already exists.
- Tag: sphj
at com.comsol.model.method.ModelEntityListMethod.checkContains(Unknown Source)
at com.comsol.model.method.GeomFeatureListMethod.createInternal(Unknown Source)
at com.comsol.model.method.GeomFeatureListMethod.create(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl.b(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl$1.a(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl$1.execute(Unknown Source)
at com.comsol.model.clientserver.ClientManager$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
----------------------------------------------------------------------------------------------------------
Could you please let me know how to overcome this issue.
With regards,
--
Uma Shankar
I am interested in creating a geometry in COMSOL 5.2 which consists of many spheres with their radii varying in unique manner iterated in a loop (example, r(i+1) =r(i)+1). I am trying to create this using COMSOL with MATLAB platform but not able to achieve the result. I think that the problem is that the COMSOL variable of the geometry name is not getting updated in COMSOL. Below is the script that i am running in MATLAB window.
model = ModelUtil.create('Model2');
geom1 = model.geom.create('geom1', 3);
r=1;C1=1;C2=1;C3=1; %matlab variables
for j=1:1:10
model.param.set('r',r,'radius');
model.param.set('C1',C1,'coordinate of center');
model.param.set('C2',C2,'coordinate of center');
model.param.set('C3',C3,'coordinate of center');
geom1.feature.create('sphj','Sphere');
model.geom('geom1').feature('sphj').label('Sphere j');
model.geom('geom1').feature('sphj').set('r', r);
model.geom('geom1').feature('sphj').set('pos', {'C1' 'C2' 'C3'});
model.geom('geom1').run('sphj');
r=r+1;
C1=C1+1;
C2=C2+1;
C3=C3+1;
end
geom1.run;
mphgeom(model)
On running this code i could only get the first sphere made and the remaining sphere is not getting created. I am getting the below error:
Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
(rethrown as com.comsol.util.exceptions.FlException)
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
An object with the given name already exists
An object with the given name already exists
An object with the given name already exists.
- Tag: sphj
Stack trace:
at com.comsol.clientapi.engine.c.handleException(Unknown Source)
at com.comsol.client.interfaces.f$d.e(Unknown Source)
at com.comsol.client.interfaces.f.a(Unknown Source)
at com.comsol.client.interfaces.f.runAndWait(Unknown Source)
at com.comsol.clientapi.engine.APIEngine.runMethod(Unknown Source)
at com.comsol.clientapi.impl.GeomFeatureListClient.create(Unknown Source)
at com.comsol.clientapi.impl.GeomFeatureListClient.create(Unknown Source)
Caused by: Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
An object with the given name already exists
An object with the given name already exists.
- Tag: sphj
at com.comsol.clientapi.engine.c.handleException(Unknown Source)
at com.comsol.client.interfaces.f.a(Unknown Source)
at com.comsol.client.interfaces.f.processCommandAnswer(Unknown Source)
... 6 more
Caused by: Exception:
com.comsol.util.exceptions.FlException: An object with the given name already exists
Messages:
An object with the given name already exists.
- Tag: sphj
at com.comsol.model.method.ModelEntityListMethod.checkContains(Unknown Source)
at com.comsol.model.method.GeomFeatureListMethod.createInternal(Unknown Source)
at com.comsol.model.method.GeomFeatureListMethod.create(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl.b(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl$1.a(Unknown Source)
at com.comsol.model.internal.impl.GeomFeatureListImpl$1.execute(Unknown Source)
at com.comsol.model.clientserver.ClientManager$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
----------------------------------------------------------------------------------------------------------
Could you please let me know how to overcome this issue.
With regards,
--
Uma Shankar
4 Replies Last Post 2017年1月17日 GMT-5 07:40