Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all 399 articles
Browse latest View live

Extracting a table from a Comsol using Matlab livelink

$
0
0
Hello,
I am having troubles in accessing a table that is created in comsol model using matlab livelink. When I use this command

a = 120;
b = 100;
d = 100;
model = waterDropsInOil(a,b,d);
tabl = mphtable(model, 'tbl1');

tabl.data turns to be just a 1xN row matrix instead of being MxN matrix that I had in Comsol model.

tabl.data
ans =
45.7100 -0.0000 -0.0000 0.0000

Here I attach the Comsol model (www.dropbox.com/s/cjb353c0h5jx1rf/3WaterDropsInOil.mph) and its Matlab code (www.dropbox.com/s/9fs68wx1omslymp/waterDropsInOil.m).

Does anybody know what I am doing wrong please?

Thanks

MATLAB LiveLink

$
0
0
Hey there,

I am using LiveLink MATLAB but when running my model, the notice "Undefined function or variable 'mphopen'" is emerged on the command window. However, I have set up the file "domain_activation_llmatlab" in the MATLAB path. could it be some problem related to LiveLinke? How could I find it that my COMSOL 5.2a can LiveLink to the MATLAM R2016a.
this is one of the comsol's sample problems (www.comsol.com/model/domain-ac...ivation-and-deactivation-12060). I, however, cannot do this. what do you suggest. the MATLAB code is as follows:
------------------
model = mphopen('domain_activation_llmatlab');
domInd = [2,3,5,4];
ht = model.physics('ht');
for i = 1:8
k = mod(i,4);
if k == 0
k = 4;
end
ht.selection.set([1 domInd(k)]);
ht.feature('init2').selection.set(domInd(k));
model.study('std1').run;
if i==1
cpt1 = model.result.dataset.create('cpt1', 'CutPoint3D');
cpt1.set('pointx', '0 L/2 L');
cpt1.set('pointy', '0 L/2 L');
cpt1.set('pointz', 'L/10');
pg1 = model.result.create('pg1', 'PlotGroup1D');
pg1.set('data', 'cpt1');
ptgr1 = pg1.feature.create('ptgr1', 'PointGraph');
ptgr1.set('legend', 'on');
pg2 = model.result.create('pg2', 'PlotGroup3D');
surf1 = pg2.feature.create('surf1', 'Surface');
surf1.set('rangecoloractive', 'on');
surf1.set('rangecolormax', '336');
surf1.set('rangecolormin', '293.15');
ht.feature('init1').set('T', 1, 'T');
v1 = model.sol('sol1').feature('v1');
v1.set('initsol', 'sol1');
end
figure(1)
mphplot(model,'pg1','rangenum',1)
hold on
figure(2)
subplot(4,2,i)
pg2.setIndex('looplevel','25',0);
mphplot(model,'pg2');
time = mphglobal(model,'t','solnum','end');
model.param.set('t0',time);
disp(sprintf('End of iteration No.%d',i));
end
----------------------

Some one can HELP? A COMSOL3.3 model cannot to be used in COMSOL5.2 ?~~

$
0
0
Hello everyone,
I 'm using COMSOL5.2 to simulate a project. Now I meet a problem.
My mentor is using a old version: COMSOL3.3. I want to use his model in my COMSOL5.2, but it says they are not compatible. I read the COMSOL help document and know that a COMSOL 3.5 can be imported into COMSOL5.2 but what if a COMSOL3.3 model?
Now I don't know how to solve the problem and I haven't found some documents about it. It really trouble me for a long time, so I think maybe some people here can help me with it.
Thanks for all of you in advance.
Dustin

Creating Geometry with Loop in COMSOL with MATLAB

$
0
0
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

Errors when computing the interpolation function

$
0
0
Greetings, COMSOL user.

I have experiencing problems when computing a COMSOL + MATLAB code. The error that occurs (with or without MATLAB) is linked to Interpolation function #1 (int1). The error message says the following:

Messages:
The following feature has encountered a problem

The following feature has encountered a problem

The following feature has encountered a problem:

Failed to evaluate variable.
- Variable: int1
- Geometry: 1
- Domain: 1
I have right paths to the interpolation function which is a .txt file. I have two more functions, but I have no problems with them.

I appreciate if somebody could give some advice.

Thanks

Error while using mphinterp function

$
0
0
Dear All,

please help me regarding mphinterp function.....

while using,

coordinate=[29970,10080]'
'' electric_field=mphinterp(model,'(es.Ey*es.ny)','coord',coordinate)''
in comsol 5.0 with matlab, i am always encountered with the error message

Error using mphinterp
mphinterp : Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: Failed to evaluate
expression
(rethrown as com.comsol.util.exceptions.FlException)
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
Failed to evaluate expression

Failed to evaluate expression

Cannot evaluate expression.

Undefined variable.
- Variable: comp1.es.ny
- Geometry: geom1
- Domain: 2

Failed to evaluate expression.
- Expression: real((comp1.es.Ey*comp1.es.ny))

Failed to evaluate expression.
- Expression: real(comp1.es.Ey*comp1.es.ny)

Error in Plea_Linepractice60micW_1micro_final29_2dModel (line
239)
electric_field=mphinterp(model,'(es.Ey*es.ny)','coord',coordinate)

Matlab, parametric sweep and plotting

$
0
0
Hi,

I'm running my comsol model with livelink for matlab but I cannot succeed the plotting...

model.sol('sol1').create('t1', 'Time');
model.sol('sol1').feature('t1').set('tlist', 'range(0,solution_time/300,solution_time)');

model.batch('p1').set('pname', {'L'});
model.batch('p1').set('plistarr', {'range(0.18,0.01,0.22)'});

as you can see I run a parametric sweep on a transient study.

mphplot(model,'pg1') show me the plot at the last time and for the last parameter L(5)=0.22,


How can I plot, for example, at half time and for L(2)=0.19 ??


I spent two hours with mphevaluate and other tools but cannot manage to print something, and for sure it's not so hard, but a little help would be greatly appreciated.

Cheers,
Irene

How to simulate correctly the time-dependent problem in Comsol-Simulink environment?

$
0
0
I am trying to simulate the time-dependent problem in Comsol-Simulink. Two variables on every simulation step are entered into the S-function. On every simulation step the Comsol model integrated into the S-function executed and solved through the LiveLink mechanism. In Comsol model I need to use time-dependent solver.

It seems like on every Simulink simulation step, Comsol model in executed and calculated the number of simulation steps specified by the time-dependent solver, while the input variables are constant during this process. As I understand, I have to save somehow the solution of the Comsol model on every simulation step, and this solution should be used as an initial condition for the next step. Could someone help me to understand how to conduct simulation like this correctly. Thank you in advance.

Variable modifications between solution iterations

$
0
0
I'm developing a transient model using the Livelink interface. The model first calculates an initial solution for the first time window, then I would like to modify the state variable values due to some external disturbance using MATLAB, then proceed to rerun the model for the next time window using the newly adjusted values of some of the variables, but the other variables should be retained from the previous solution iteration.

When I prescribe the use of the previous solution for subsequent iterations as:

model.sol('sol1').feature('v1').set('initmethod', 'sol');
model.sol('sol1').feature('v1').set('initsol', 'sol1');

it seems that the specification of initial conditions through either

model.variable('var15').set('X0', num2str(X0));

or

model.init('init4').set('position',num2str(X0));

are ignored completely and the unchanged values from the previous solution are retained. Is there a plausible method to effectively update some of the variables this way? Perhaps by modifying the dataset of the previous solution?

Thanks.

Speed of solver decreases in a parametric loop MATLAB

$
0
0
Hey all,

I am new to comsol. I need to study effect of a parameter in a eigenfrequency problem. In MATLAB, I solve the problem for each value of the parameter (say for eg say some geometric parameter). As the parameter progresses, I observe that the speed of the computation decreases. I am using COMSOL 4.2 a with MATLAB R2016.

Can anyone tell me the cause of it and suggest any solution to maintain atleast a constant speed of the solver as the parameter progress ?

Any tips in increasing the speed of the solver are also welcome.

Thanks in advance

--
Tarkes

Exporting COMSOL data into MATLAB

$
0
0
Hi there,

I am new to COMSOL and currently running a very basic simulation adding strain to a 2D custom geometry. I am just wondering how i would go about exporting the post processed stress map (the von Mises stress value at each point of the mesh) into MATLAB. Is there a way to achieve this?

Thanks in advance

Now available: COMSOL 5.2a Update 2

$
0
0
Hello,

I'm pleased to announce that COMSOL 5.2a update 2 is now available for download.

This is a quick installation to keep your software current and stable. It applies to version 5.2a of COMSOL Multiphysics and Application Builder, COMSOL Server, COMSOL Client, and several add-on products.

Featured enhancements include:
- Up to 10 x performance improvement for handling of large models, including faster selections, virtual geometry operations, and meshing, as compared to version 5.1 and earlier versions.
- Support for macOS™ Sierra.
- New Rotordynamics Module is available as an optional add-on to the Structural Mechanics Module.
- Stability improvements for all products.

To download the update and see more details, visit:
www.comsol.com/product-update/5.2a

Update 2 is included in the latest version 5.2a of the software available for download at:
www.comsol.com/product-download

Enjoy!
Valerio

--
Valerio Marra, PhD
Marketing Director
COMSOL, Inc.
+1-781-273-3322
valerio@comsol.com

Where to find more documentation about physics interfaces for use in Livelink for Matlab

$
0
0
I have recently started working with the livelink for Comsol in Matlab. I was able to get things working with the help of the programming reference manual, the introduction to livelink for matlab and livelink for matlab user guide. However I cannot find much information about the commands for specific physics interfaces. Does anybody know where to find this?

For example I tried to apply a voltage to a terminal in a electrostatics simulation with the code below, but this code does not apply any voltage to the simulation. I guess that I have to set the terminal type to voltage first, but I cannot find any information on which command I should use in any of the three manuals.

es = model.physics.create('es','Electrostatics','geom1');
model.physics('es').create('ter1', 'Terminal', 2);
model.physics('es').feature('ter1').selection.set(3);
model.physics('es').feature('ter1').set('V0', '1');

Who can help me out?

ID of physics in Livelink for matlab

$
0
0
Hi,

Where can I find the ID of a physics feature? I for example want to make a prescribed displacement in Comsol. Usually it works to just make 'Terminal' of a terminal, but I tried 'PrescribedDisplacement' but it doesn't work, so I guess it is called differently. If I try for example a 'BodyLoad' it does work.

model.physics('mech').create('fixedCond','PrescribedDisplacement',2);
gives:
Unknown feature ID: PrescribedDisplacement

I looked in the comsol programming reference, the introduction to livelink and the livelink for matlab reference guid, but wasn't able to find anything. I also looked with the MPHnavigator in the physics object, but this wasn't usefull either.

Does anybody know where to find this?

Assigning materials to domains from MATLAB

$
0
0
Dear COMSOL experts,

I am wondering how to assign materials to domains from a matlab script. For example, I create a block "my_block" with

>> model.geom('geom1').feature.create('my_block', 'Block');
>> ... % define the properties of block here

Then I create a material called "superconductor" with

>> model.material.create('superconductor');

Now, if I assign the "my_block" to material "superconductor" through COMSOL GUI and save the result as m file, the assignment will look like this:

>> model.material('superconductor').selection.set([1]);

How do I find out programatically the correspondence between "my_block" and the number 1 that I need to specify as the parameter to the last command.

Thanks in advance,
Andrey

Overlap of Spatially Separated Quantities in Livelink

$
0
0
I want to calculate the modes of an array of weakly-coupled optical resonators by a tight binding method. The individual resonators making up my system are cylindrical, so I calculate their modes utilising a fast axisymmetric simulation.

To determine the frequency shift of these modes in a 2D resonator array I want to integrate numerically the overlap between the fields at points separated by multiples of a set distance a. The products I want to integrate are of form E(x,y,z) E(x-a,y,z), E(x,y,z) E(x+a,y,z) and similar. Is there a facility to do this kind of integration in the livelink module?

Exporting Comsol data to Matlab?

$
0
0
Hello everybody,

I want to postprocess Comsol data in Matlab. Since Ascii files blow up in size and I get "out of memory error", I'm looking for some other way. I've no experience with Comsol-Matlab interface and it seems to me that this interface is not working in my system.

Could someone please tell me, how to export Postprocessing data in some Matlab-compatible format (not Ascii)?

I've converted a Comsol model (after executing) into an m-file and wanted to run it in Matlab (running separately from Comsol) but Matlab is probably not able to read the flbinaryfile (*.mphm). Any suggestion, what could be wrong here?

Thanks.
Daniel

Inverse Heat Conduction to find thermal conductivity

$
0
0
Hello everybody. I'm a Comsol user (basic level) and I want to obtain numerically the thermal conductivity of a material, knowing boundary heat flux and temperature values in several points. I've read other discussion about it but I can't really find how I have to do. I've read about several possibilities:
1. Optimization module (I haven't it);
2. Definition of a weak function containing the difference between measured values and numerical solution of temperature;
3. Implementation of algorithm in Matlab.

What is the best one?
I can open Comsol file with Matlab but I don't know how to move inside the script.
Could someone be more precise in explaining possibility 2 and 3?

Thanks for your help,

Giovanni

Solidworks import via CAD Import Module

$
0
0
Hi Folks,

It seems as though the CAD Import module cannot import Solidworks 2016 files, but LiveLink for SolidWorks can... is that a correct understanding?

I am just about to have my SolidWorks installation updated, but won't go for SolidWorks 2016 if the CAD Import Module does not support SolidWorks 2016 yet... (I do not have the LiveLink for SolidWorks module).

Could someone confirm the above?

Thanks in advance!

Mark

p.s. I have Comsol 5.2.0.220

p.p.s. The reason I ask is because there is ambiguity in the Product System Requirements, both the CAD Import module and the LiveLink for SolidWorks tables indicate support only up to SolidWorks 2015, yet the text in the LiveLink product page indicates support for SolidWorks 2016. Clarification greatly appreciated...

mphglobal with Matlab returning multiple values

$
0
0
Hi there,
I was using mphglobal successfully to pull parameters from my comsol model but now I have an issue. I made some changes to my model such as changing the mesh and adding some more variables and now when I try to pull out parameters with mphglobal it will return the value 41 times. So instead of returning a double, it returns a 41x1 array of identical doubles. Any idea what is going on?

Thanks,
Bryan
Viewing all 399 articles
Browse latest View live


Latest Images