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

How export data using MATLAB Link?

$
0
0
Hi All
I need information, how I can export data by vertex using MATLAB?
Before solve my problem, first I obtain information about mesh:

nElem = model.mesh('mesh1').getNumElem;
nVertex = model.mesh('mesh1').getNumVertex;
Vertex = model.mesh('mesh1').getVertex();
Elem = model.mesh( 'mesh1').getElem('tri');

After solve problem:
model.study('std1').run;
I would like to want obtain set of data (some expression) in each of these vertex.

I dont want to use the export function
model.result.export('data1').set('filename', {NameFile});
model.result.export('data1').run;

because it generates its own mesh.

Regards

LiveLink for Matlab_Magnetic Buoyancy Force_Complicated force equation

$
0
0
Hi there!

I am trying to simulate the transport of non magnetic particles using ferrofluids and magnetic fields.
I have simulated the magnetic field, and I have now to do the particle tracing.

Because they are non-magnetic particles (polysterene), I guess I can't use charged particle tracing module.
I think i would then have to use the mathematical particle tracing.
Is that right?

Then I wanted to ask about the magnetic buoyancy force that are having an influence on my particles.
Its expression depends on the magnetization and the gradient of the magnetic field strength. This gives me really complicated equations
How could I integrate them? I saw that LiveLink for Matlab could help me with this, is that right?

Thank you for your time!

Cheers

Antoine

load two models in the Matlab Livelink

$
0
0
Hello;

I am new in Comsol and Matlab Livelink. my question is how can I load two models in Matlab Livelink? For example I try to run the following sample code, but it generates error which I am unable solve. I do appreciate any suggestion.

model1 = mphload('...\mymodel.mph');
model2 = mphload('...\mymodel.mph');
model1.param.set('a','5.0');
model2.param.set('a','0.2');
model1.sol('sol1').run;
model2.sol('sol1').run;

How to Generate Smooth Molecular Surface with COMSOL

$
0
0
Hello folks,

I have COMSOL 4.3a and LiveLink for Matlab with me. And I have constructed a protein subunit of about 1000 atoms based on the coordinate data in the PDB file. I simulated each atom as a sphere . Recently I am trying to create a smooth surface to cover the whole molecular atoms that I have already constructed. I hope the surface could be tangent to the outside atoms and be smooth enough ( just like the pic attached). This is quite hard for me because COMSOL seems not that good at generating complex geometry. So could anyone give any suggestion?

Problem of using femtime() in COMSOL 3.5a

$
0
0
Hello all,

I use femtime() in matlab to solve a dynamic FE problem as follow:

fem.sol = femtime(fem,'Tlist',tspan);
where tspan is an equally distributed time list. tspan = [t0,t1,t2,...tn].

Now, I am trying to break this long time list into a for-loop

for ii = 1:length(tspan)
u0 = fem.sol.u(:,end);
u_dot0 = fem.sol.u(:,end);
fem_temp = fem;
fem_temp.sol = femsol({u0 u_do0},'tlist',tspan(ii-1));
fem_temp = femtime(fem_temp,'init',u0,[tspan(ii-1) tspan(ii)]);
fem.sol = femsol({[fem.sol.u fem_temp.sol.u(:,end)] [fem.sol.ut fem_temp.sol.ut(:,end)},'tlist',[fem.time.tlist tspan(ii)]);
end

However, the for-loop is not equivalent to the original command, because I get totally different results for the same input.

Is it the correct to add initial conditions like this? How to add initial velocity to femtime()?

Thanks

Dan

Execute COMSOL Ribbon buttons with VBA

$
0
0
Does anyone know if there is a way to execute COMSOL ribbon buttons (for example, it 'clicks' the mesh button or it clicks plot group and selects the correct plot)? Basically, what I doing is creating VBA macro buttons that when clicked will say, do update all, click compute, and then click on the appropriate plot group. Thereby saving the user (who does not know COMSOL in any capacitance) from dealing with the ribbon.

Judging from VBA code, it should be something along the lines of (I think): ribbon.button_name.execute. Any help is appreciated

How to duplicate solution in Matlab

$
0
0
Hi all,

I am now using the COMSOL Livelink for Matlab. I create two solutions whose soltags are 'sol1' and 'sol2' respectively. I want to copy the solution from 'sol1' to 'sol2'.

Here is what I am doing:

[u udot] = mphgetu(model,'soltag','sol1');
model.sol('sol2').setU(u);
model.sol('sol2').set('tlist',tstr); % where tstr is the time list string of 'sol1'
model.sol('sol2').createSolution;


My questions are:
a) How to copy the velocity components in sol1 to sol2?
b) Are there any fast or efficient ways to duplicate solution?


Thanks a lot

Dan

recover matrix

$
0
0
hello everyone

I made a resolution a PDE on COMSOL and I would like to to recover the resolution matrix using Matlab.

is that possible?

thank you for your help

Convergence plots

$
0
0
Does anyone know if it is possible to show a convergence plot during a livelink with Matlab? I'm using version 4.4 and matlab R2013a.

Thanks

Solving memory intensive model

$
0
0
Solving 3D problem with a better mesh has become an issue for my model. I am always getting out of memory errors. I was wondering if It is possible to extract the matrices and solve it with , for example, Matlab using a reduced order method to reduce computation time. It would be really helpful if someone can provide some information regarding that.

mpheval command

$
0
0
Dear all,


I have got some questions regarding the mpheval command, which are not very clear in the documentation.

There is a model file, that I export to matlab, that contains 2 studies, with a parametric sweep and a transient solver in each of the two studies.

The mpheval command does not like the parameter 'dataset', solution [number whatever].
It won't find any of the solution datasets, that are defined in the Model file itself.
There is one solution data set for the first study and one for the second.
My most important issue is: how can I address the results of the two different studies of the model file?

An other question is the 'solnum' parameter. With this I can obviously define the time step number.
E.g. 'solnum', 10 would give the data of the 10th time step.
So why is there also a parameter 't' in the mpheval? And what happens, if I use both in one call of mpheval with contradicting values.
E.g. 'solnum', 10 (the 10th time step, eg. t=1000) and 't', 2000 in one call?
Will it then return data from t=1000 or t=2000?
At least it does not give an error message, which is strange to me.



Thanks a lot for any answers,
Juergen

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.

Creating solution objects and assigning values from MATLAB in COMSOL 4 (similar to femsol)

$
0
0
Hello,

I am trying to adapt from COMSOL 3.5a to COMSOL 4, and so far, the biggest functionality that I miss while using the MATLAB connection is the following:

I want to be able to create solution objects and assign these solution objects to fem's, so that I can use COMSOL solvers to process the dataset I want, or more importantly, to be able to plot those datasets.

I was able to do this by using the following command in COMSOL 3.5:

fem.sol = femsol(u,'tlist',tlist)

where the solution data set I want to have in fem is present in u. In other words, I was able to manipulate the doffs by manipulating u. Is there a corresponding functionality in COMSOL 4?

Thanks in advance.

Can we impose a MINIMUM STEPSIZE AS A STOP CONDITION?

$
0
0
I loop thousands of transient simulations in matlab and I can't find a solver setting that will stop the solver when the step size becomes very small (history of the stepsize in log file) and the simulation becomes a terrible waste of time.

Is there a way to impose a low limit on the stepsize of the solver? I tried various Stop expressions with no success (ex. stepsize-1)...

Anyone knows how to do that?

Thanks,
Frank

accessing MATLAB global variables when running models in MATLAB

$
0
0
I have defined an external function in matlab that I use in my Comsol/Matlab livelink model to set a volume heat source, let's call this function my_heat(x,y,z), where x,y,z are comsol spatial variables.
Everything works fine with this (comsol passes x,y,z vectors and matlab returns heat source values based on this, and the model is set up and solved)

Now, I tried to use some global MATLAB variables within the 'my_heat' function. When I run function in MATLAB the variables and their values are accessible in 'my_heat'. However, when the same function is called by COMSOL as part of setting the physics, it seems 'my_heat' does not recognize these variables.

I think I know what the problem is, but don't know the solution to it:

When the model is run from Matlab, Comsol seem to open another instance of MATLAB (as manifested by a second command window). This seems like the place where all the Comsol/Matlab interfacing happens. No wonder that in this new instance of Matlab, the information about any global variables in the main Matlab window is missing.
Any ideas on how to 'pass' all the info from the main Matlab window to this auxiliary one?

Thanks,

Robert

P.S.: On an unrelated note, I discovered that by typing 'clear functions' in this new matlab window, I can have comsol get the updated version of any edits to my matlab fuinctions. Without this, comsol only has the first version of external functions. Typing 'clear functrions' in the main matlab window doesn't maker any difference.


Getting derived values into matlab variables

$
0
0
Hello!

I have some trouble getting the value of an average operator into a matlab variable when using comsol through matlab.

What I get when I translate the model into an .m file is this:

model.result.numerical.create('av2', 'AvSurface');
model.result.numerical('av2').selection.all;
model.result.numerical('av2').selection.set([2]);
model.result.numerical('av2').set('expr', 'sqrt((mfnc.Br*d(mfnc.Br,r)+mfnc.Bphi*(1/r)*d(mfnc.Br,phi)+mfnc.Bz*d(mfnc.Br,z))^2+(mfnc.Br*d(mfnc.Bphi,r)+mfnc.Bphi*(1/r)*d(mfnc.Bphi,phi)+mfnc.Bz*d(mfnc.Bphi,z))^2+(mfnc.Br*d(mfnc.Bz,r)+mfnc.Bphi*(1/r)*d(mfnc.Bz,phi)+mfnc.Bz*d(mfnc.Bz,z))^2)');

What I want to do is get the value of 'av2' into a matlab variable. I tried using mpheval and mphglobal but it didnt work, not sure if I am using them right. Does anyone have any ideas?

Thanks in advance!

LocalSelectionImpl/set error when using mphinterp

$
0
0
This is not a question, rather documentation for anyone who might encounter the same problem in the future.

I followed these steps:
1. Build a model.
2. Delete everything non-essential.
3. File -> Reset History
4. File -> Save As Model M-File...
5. Opened the m-file and added a few commands at the end to post-process the results. Including a call to mphinterp(..).
6. Ran it using a command like
comsolserver matlab "tbc_test, exit" -mlroot "C:\Program Files\MATLAB\R2012a" -np 6 -Dcs.ckl -nodesktop

7. Received the following error:



Error using com.comsol.model.impl.LocalSelectionImpl/set
Java exception occurred:
Exception:
java.lang.NullPointerException
(rethrown as com.comsol.util.exceptions.FlException)
Messages:



Stack trace:

at com.comsol.model.internal.impl.SelectionImpl.a(Unknown Source)

at com.comsol.model.internal.impl.SelectionImpl$a.a(Unknown Source)

at com.comsol.model.internal.impl.SelectionImpl$a.execute(Unknown Source)

at com.comsol.model.clientserver.ClientManagerImpl$e.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)


Error in C:\Programs\COMSOL42a\mli\mphinterp.p>mphinterp (line 153)


Error in tbc_test (line 192)
[t, unit] = mphinterp(model, ...



Solution: to avoid this happening, a "Solution 1" under "Data Sets" under "Results" should still be present when saving the model as an M-file. I had deleted it before saving, and this, somehow, lead to the error message above.

How I figured it out:
• Started COMSOL with MATLAB, copied-and-pasted the contents of the M-file (except the function header) into it. This way I could experiment with mphinterp(..) without having to run the model from the command line every time I change something.
• Made a very simple model, and experimented with it. Figured out that the difference was the presence of "model.result.dataset.remove('dset1');" in the original M-file.
• This took a long time because of the unhelpful error message and no access to the source.

COMSOL with Matlab syntaxis (plotting and extraction datas while optimization solving)

$
0
0
hello.

I'm trying to make belows these days.
First, I've opened a 'Topology Optimization of a Loaded Knee Structure' from the model library that is aleady exist. And I clicked 'reset history' then saved as model M-file to extraction. I turn off the COMSOL and run COMSOL with Matlab for using the M-file what I extracted.
Now I can do some implement on COMSOL with Matlab except COMSOL Multiphysics. But I couldn't use so many commanders freely still. Of course nowdays I'm studying through pdf files which are 'COMSOL Java API Reference Guide' and 'Live Link For MATLAB Users Guide', etc.

my questions:

<1> How do I plot while solving on COMSOL with Matlab?
--> I can only do optimal plotting (just single picture) when entire loops or iterations end. (by using the 'mphplot' syntax)
--> I saw some syntaxis 'PlotWhileSolving' or just 'Plot' which are marked on pdf files, but it hadn't possible.
--> I want to plot while solving on not COMSOL Multiphysic but COMSOL with Matlab, I mean using the Matlab 'figure' or 'window'.

<2> I want to extract datas that are objective function, design variables and sensitivity vlause... something that... each iteration on COMSOL with Matlab. could you teach me a class or structure syntax?


I'll wait good news. (I attached all files)
Best Regards.

handling interpolation function on Matlab environment

$
0
0
Hi.

i usually do turn on the check box 'use space coordinates as arguments' to interpolate functions on GUI environment.

But, i encountered situation about disappearing messages on Matlab environment.
you guys see what i takling with 2 pictures i added below.

please comments me how to activate the 'check box comment' on COMSOL with Matlab environment.


best regards.

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
Viewing all 2194 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>