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

Inconsistency between 'mphinterp' and 'mphplot'

$
0
0
Hello,

I am having an issue with the MATLAB-Livelink function 'mphinterp'. What I am basically trying to do is plot 2D slice plots of data from the model solution. I am operating on solutions from different steps in a parametric sweep, so I need to save data from evaluated expressions at each step. The 'mphplot' command successfully plots the slice plots in MATLAB that resemble the 3D slice plot feature in COMSOL. However, since the generated MATLAB plot only contains colordata and not the actual data, I want to extract the mesh from the MATLAB plot and use 'mphinterp' to get at the actual data at each vertex in the 2D mesh. When I do this, and replot in MATLAB, the resulting plot looks ok within each domain, but near the boundaries, the values calculated from 'mphinterp' are not consistent with values derived from 'mphplot', and results in pixelated artifacts along the domain boundaries. The attached figures demonstrate this inconsistency. These figures were generated by plotting only the vertex 'markers' in MATLAB. The vertex coordinates are identical, but the derived values are different. I am confused as to why 'mphinterp' is giving different results using the same mesh that is generated from 'mphplot'. I can produce a similar inconsistency in COMSOL by comparing a 3D Plot Group->Slice (1 quick plane at z = 0) and a 2D Plot Group->Surface from a Cut-Plane dataset generated at z = 0, for example. These plots should be identical, but they are not. The former shows a smooth transition at the boundaries (similar to 'mphplot' output) and the latter is heavily distorted near the boundary edges (similar to 'mphinterp' output). Am I missing something? Should I not get the same result from 'mphinterp' when using an identical mesh generated from 'mphplot'? If not, then how can I access the underlying data that 'mphplot' interpolates from the model solution?

Thank you for any assistance.

Correct syntax for creating domain selection in the JAVA Api?

$
0
0
I am trying to follow the busbar tutorial using Comsol + Matlab.

To create a variable representing multiple boundaries to avoid redundancy the following code is given:

<code>
sel1 = model.selection.create('sel1');
sel1.set([2 3 4 5 6 7]);
sel1.name('Ti bolts');
</code>

Matlab returns the following error:

Error using busbar (line 54)
Java exception occurred:
Exception:
java.lang.IllegalArgumentException: Illegal input vector
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
Illegal input vector

Line 54 refers to the second line of code.
Any one knows what the issue may be with the syntax if that's the problem?

Thank you,
Kayode

Same model, different solutions?

$
0
0
Hello, Community,

I'm doing phase change simulation with phase change HT module. Currently I have a problem with COMSOL:

The same model gives different results in different runs!

I use Matlab Livelink to read the solution in each run and compare the difference between two runs.

What I did in Matlab is:

% load model
Comsol_model2 = mphload(Model.mph);
% Run the Temperature model
Comsol_model2.sol('sol2').runAll;
% get model values
Temp2=mpheval(Comsol_model2,{'T2'});
Comsol_T2=Temp2.d1; % Temperature Variables
Comsol_Px2=Temp2.p(1,:); % x coordinate
Comsol_Py2=Temp2.p(2,:); % y coordinate

Comparing the above 3 variables in two simulation runs, the x and y coordinate values are exactly the same but the temperature variable varies randomly in each simulation. I expect the same solution of temperature from each simulation runs if the model is the same.

So can anyone here help me to explain this weird problem?

Usage of set method in LiveLink for MATLAB

$
0
0
Hi,
I am tying to understand the heat_transient_axi example to export state space matrices to MATLAB from COMSOL. The following lines are from the example

model = mphload('heat_transient_axi');

"Create a parameter T0 that is set as external temperature"

model.param.set('Tinput','1000[degC]');
model.physics('ht').feature('temp1').set('T0',1,'Tinput');

After that there are errors in the example as pointed out here: www.comsol.com/community/forums/general/thread/36587/

Correcting the error the fixed MATLAB code to be run (for the probe mod1.ppb1) is:
M = mphstate(model,'sol1','out',{'Mc' 'MA' 'MB' 'C' 'D' 'x0'},'input','Tinput', 'output', 'mod1.ppb1');

When this model is opened in comsol I can see that 'temp1' refers to a temperature boundary condition imposed on the model and is given by the equation 'T=T0'

So by the line
model.physics('ht').feature('temp1').set('T0',1,'Tinput');
are we setting T0=Tinput=1000[degc]? And what does the 1 do among the arguments for 'set' method ('T0',1,'Tinput')?

And is the input to the system this temperature boundary condition T0?

How to find entities of expelicit selection in the Work plane of a 3D model (API model)

$
0
0
Hi
I have created a geometry in the work plane of a 3D geometry (which is obviously in 2D mode at this stage).
and i have created explicit selection feature and set the selection object as well. when I try to read the entities associated to it, I get nothing. My code is working in the 2D model but for 3D model it is not working.

my code is :

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
import com.comsol.model.*
import com.comsol.model.util.*

model = ModelUtil.create('Model');

model.modelNode.create('comp1');

model.geom.create('geom1', 3);
model.geom('geom1').lengthUnit([native2unicode(hex2dec({'00' 'b5'}), 'unicode') 'm']);
model.geom('geom1').feature.create('wp1', 'WorkPlane');
model.geom('geom1').feature('wp1').geom.feature.create('r1', 'Rectangle');
model.geom('geom1').feature('wp1').geom.feature.create('r2', 'Rectangle');
model.geom('geom1').feature('wp1').geom.feature.create('r3', 'Rectangle');
model.geom('geom1').feature('wp1').geom.feature.create('r4', 'Rectangle');
model.geom('geom1').feature('wp1').geom.feature.create('r5', 'Rectangle');
model.geom('geom1').feature('wp1').geom.feature.create('dif1', 'Difference');
model.geom('geom1').feature('wp1').geom.feature.create('sel1', 'ExplicitSelection');
model.geom('geom1').feature('wp1').geom.feature('r1').set('size', {'110' '85'});
model.geom('geom1').feature('wp1').geom.feature('r1').set('pos', {'0' '0'});
model.geom('geom1').feature('wp1').geom.feature('r2').set('size', {'25' '25'});
model.geom('geom1').feature('wp1').geom.feature('r2').set('pos', {'95' '60'});
model.geom('geom1').feature('wp1').geom.feature('r3').set('size', {'15' '25'});
model.geom('geom1').feature('wp1').geom.feature('r3').set('pos', {'-5' '55'});
model.geom('geom1').feature('wp1').geom.feature('r4').set('size', {'50' '25'});
model.geom('geom1').feature('wp1').geom.feature('r4').set('pos', {'-10' '0'});
model.geom('geom1').feature('wp1').geom.feature('r5').set('size', {'50' '50'});
model.geom('geom1').feature('wp1').geom.feature('r5').set('pos', {'70' '-20'});
model.geom('geom1').feature('wp1').geom.feature('dif1').selection('input2').set({'r2' 'r3' 'r4' 'r5'});
model.geom('geom1').feature('wp1').geom.feature('dif1').selection('input').set({'r1'});
model.geom('geom1').feature('wp1').geom.feature('sel1').selection('selection').init;
model.geom('geom1').feature('wp1').geom.feature('sel1').selection('selection').set({'dif1'});
model.geom('geom1').run;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5



if i try to get the entities of "sel1" by :
model.geom('geom1').feature('wp1').geom.selection('sel1').entities(2)

it gives me empty output while the JAVA object contents the "dif1" object ... i really appropriate if you can help me to find a way to solve this problem?

PS. i am using Matlab live link

state space export

$
0
0
Hi,

I'm trying to export a state space model for the microresistor beam example. Can anyone tell me how to export a state space model of the displacement as a function of temperature? A tutorial in 4.1 would also be helpful.

Thanks

[Q] a functional MATLAB file based on COMSOL parametric model

$
0
0
Hi
I’m new to COMSOL and for now using COMSOL 4.2 with MATLAB 2010b, trying to build a CFD model of a PEM fuel cell in COMSOL and optimize it’s channel parameters using MATLAB. As you know, to use MATLAB optimization methods, we need a parametric function of the model, for example, for the fuel cell, I need a functional M.File for output voltage, which is a function of Length, width and height of the channels.
I did some initial experiment with the first demo of COMSOL, the busbar, it’s easy to export the model to MATLAB and work with it, but it’s based on specific value for every parameter not a variable
can someone please explain me how to create a model base on some variable not a specific value. Unfortunately, I didn’t manage to find a demo or tutorial on it.
Many thanks in advance

script for exporting deformed geom from livlink matlab ?

$
0
0
Hi all,

In GUI, I could remesh the deformed configuration from the results dataset, and from there i could export to a new geometry (xx.mphbin). But how can i do the same from matlab livelink ?

I wrote, "model.result.dataset('dset3').createDeformedConfig('deform1', 'mesh2');", but what could be the next lines in the script for exporting to a new geometry file ? Of course I tried to do it from GUI and then save model as m-file to see the script for exporting, but it didn't show anything equivalent java or matlab command for 'exporting to file' action.

Any help is appreciated ! Thanks.

/Krishna

Matlab function

$
0
0
Hello,
I have a problem with importing matlab-functions in comsol (version 4.3b in Linux). After I have inserted the function name, variables and the range, I get the following error-message: "Matlab function is not found: ..." (see attached file). Maybe the path to the matlab-functions is wrong, can you please help me with this?

Rotordynamics, eigenvalues and frequency domain

$
0
0
Hi everybody,
I have two questions about rotordynamics modelling.

First of all, I'm modelling a rotor using a parametric sweep on angular velocity to find its eigenvalues.
After that I would like to extract the system matrices (in LiveLink with Matlab) using the command "mphmatrix", but the damping matrix (which includes the gyroscopic matrix) varies with the angular velocity of the rotor.
So, how can I extract system matrices for a certain step of the parametric sweep? (or for every step of the sweep, it's the same!)

My second question is related with rotordynamics too.
I would like to perform a frequency response analysis of a rotor. In my model the rotor is modelled with beams and the bearings with the Lubrication shell interface. There are also some ODEs so I substituted the time derivatives with i*2*pi*freq and -(2*pi*freq)^2.
The problem is that in this way the ODEs generate an error like this:

Undefined value found.
- Detail: Undefined value found in the stiffness matrix.
There are 1547 equations giving NaN/Inf in the matrix rows for the variable mod1.pf.
at coordinates: (-0.0799129,0.00534406,0), (-0.0768651,0.0223399,0), (-0.0788467,0.0139241,0), (-0.0702572,0.0382926,0), (-0.0739908,0.0304943,0), ...
There are 6 equations giving NaN/Inf in the matrix rows for the variable mod1.thx.
at coordinates: (0,0,0), (0,0,-0.07), (0,0,-0.14), (0,0,-1.3), (0,0,-1.37), ...
There are 6 equations giving NaN/Inf in the matrix rows for the variable mod1.thy.
at coordinates: (0,0,0), (0,0,-0.07), (0,0,-0.14), (0,0,-1.3), (0,0,-1.37), ...
There are 6 equations giving NaN/Inf in the matrix rows for the variable mod1.thz.
at coordinates: (0,0,0), (0,0,-0.07), (0,0,-0.14), (0,0,-1.3), (0,0,-1.37), ...
There are 1 equations giving NaN/Inf in the matrix rows for the variable mod1.tilt1.
at coordinates: (0,0,0), ...
There are 1 equations giving NaN/Inf in the matrix rows for the variable mod1.tilt1B.
at coordinates: (0,0,0), ...
There are 1 equations giving NaN/Inf in the matrix rows for the variable mod1.tilt2.
at coordinates: (0,0,0), ...
..................

I made a simple check about ODE in frequency domain: I modelled (with ODE interface) the frequency response of a 1D mass-spring model, and all work well!
My rotor model is quite complex because there are three physics involved; in particular I think the problem could be in the non linearity of the Lubrication shell Interface used to model the bearings.
Any advice?

Thanks a lot

Best regards
Daniele

problem with convert image to geometry with the function mphimage2geom in Matlab LiveLink

$
0
0
hello,

i was very happy to find that with the function 'mphimage2geom' provided in Matlab LiveLink it's possible to convert a grey scale image into geometry. It's quite cool. A comsol model can be generated with the function. then physics can be assigned to the geometry in the comsol model. But now my problem is that the functions sometime works, sometimes not.

Details about my problem: 2 images are attached here. the image named 'test_original.tif' can be directly converted into geometry without any problem. but with the image 'test_processed.tif' in which the empty space is filled in ImageJ , it doesn't work anymore. Matlab gives error message on matrix dimension problem. But the image dimension was not changed at all. Can someone help to explain where it goes wrong? Has anyone had this problem before?

Thank you!

Chunyan

Uploading to MATLAB

$
0
0
Hi,

This is probably a very basic question, but I would like to try working with the livelink to MATLAB and was following the instructions for how to load my model into MATLAB but MATLAB does not seem to recognize the file. I used the format:

model = mphload('file name')

which I believe is the correct form, but I keep getting the following error:

Error using mphload (line 88)
The file "simple richards plus thermal.mph" could not be found

Is is possible my .mph files are saved in a location that MATLAB can't or won't access? Is there a particular way I should be saving all my models?

Thanks,
Shoshana

access eigenmode displacement for mesh nodes?

$
0
0
Hi!

This is my first post to this forum.

I have a simple mechanical structure (say, a clamped clamped beam) where I have been trying to extract, via LiveLink, the displacements for the actual mesh nodes, for a given eigenmode. I have been able to obtain the interpolated values using "Eval", but I would rather just access the x and y displacements for the original nodes.

Here is my code:

model.result().numerical().create('ss1','Eval');
model.result().numerical('ss1').set('expr','u');
ue = model.result.numerical('ss1').getData();
model.result().numerical('ss1').set('expr','v');
ve = model.result.numerical('ss1').getData();

I am quite new to the live link syntax and such, so I think I need some expert advice! Thanks!

Solidworks COMSOL fluid flow (air) simulation

$
0
0
Hi everyone,

I was wondering if anyone here knows if COMSOL can simulate Solidworks models straight from import. Here's the scenario:
1. import solidworks model of a pipe with a hollow x-diameter
2. using COMSOL, simulate an air flow through the pipe at y-pressure at the inlet

Based on what I've read in online tutorials, all examples require a 'solid' geometry of the flow area in question. Thus, this would require me to modify the model to make the inside diameter a solid.

Is it possible to model fluid flow while keeping the original solidworks model design (i.e. flow inside the hollow pipe)? It doesn't seem practical to always modify my models to make them 'solids' in order to run COMSOL fluid simulations. For instance, what happens if I have a SolidWorks model of the capillaries in the lung (i.e. many, many branches) and I wanted to simulate the air flow through it using COMSOL? It would be impractical to modify the entire system to make it solid capillaries.

Thank you in advance.
Regards.

Simulation time does not scale with processor

$
0
0
Hello all,

Just as a preface, I do not have significant experience with Comsol in general, and the bulk of my manipulations are occurring within Matlab, but my question is of a general sort.

I am running simulations in Comsol, though Matlab, of a two dimensional silica wedge with azimuthal symmetry at various radii for the purpose of obtaining the form of the mode profiles and various properties related to loss, dispersion, etc, within with wedge for an arbitrarily sized ring resonator.

The Matlab code that I'm using to run the simulation simply controls the inputs into Comsol, and does not do any real computation itself.

My situation is this:
I had previously been running the simulations on a laptop with an i7-2720QM (quad core) CPU which CPU-Z shows clocking up at 3GHz, and has 8GB of RAM.

I recently built a new computer with an i7-4930K (hex core) which clocked out of the box to about 3.7GHz, and I further OCed to 4.4GHz. It has 32GB of RAM.

In both cases, Comsol is not using all of the RAM, since each individual simulation isn't very big (it takes 30-60 seconds to complete), I just have to do a lot of them back to back.

Both machines are running Comsol 4.4 and a 64-bit OS, the laptop is Windows 7 with Matlab R2011a, and the desktop is Windows 8.1 with Matlab R2014a.

Even straight out of the box, the new CPU should be about 2.5-3x more powerful than the laptop CPU in terms of simply cores and clock speed (in reality it scales even higher). However, the speed at which it runs the simulations was only about 25% faster. Furthermore, after I overclocked the CPU, the speed of the simulations scaled almost perfectly with the increased clock speed, becoming about 50% faster than the laptop overall.

So essentially, my issue is that the simulation speed scaled horribly with the switch to a more powerful processor, but perfectly with the clock speed of the processor itself.

I should also add that I monitored the total CPU usage during runs for both cases, and for both machines, Comsol consistently made use of 50-60% of the processing power during computation, so it is not as if the new chip just isn't being utilized effectively.

I apologize if I have not provided sufficient information, and if more specifics on the simulation itself are required, I can try to obtain them from the person who wrote it.

Is there any particular reason for the speed to scale so horribly, such as bad support for Ivy-E chips?

Any and all insight is appreciated.

Java API - InputMatrix

$
0
0
Hallo everyone,
I try to solve simple heat transfer problem and I would like to change stiffness matrix in my simulation. I tried to use function InputMatrix which is available in Java API interface. But I have problems with the control of this feature. I manage to input the members of the matrix into the InputMatrix feature but I do not know how to solve the problem with this feature (if it is necessary to include component Variables, etc.)
Thank you.
Regards,
Ilona Skarydova.

how to connect comsol to matlab.

$
0
0
Hi. My comsol version is 3.5a and matlab is R2012a.

I made a M-file through comsol. And I tried to open it in matlab.
But it didnt work. So i wonder what the problem is.

When i ran m-file in matlab i showed this message.

>> comsol
Undefined function 'flclear' for input arguments of type 'char'.

Error in comsol (line 4)
flclear fem

>>

I don't know the reason. But i think i have to make something about program in M-file, right??

If you know how to do in this case, let me know.

Thanks.

Value type of the control variable in the Optimization interface through LiveLink for Matlab

$
0
0
Dear all,

I'm working with the optimization interface through LiveLink for Matlab. I would like to know how to specify the value type of the control variable.

The dependent variables in my problem are complex; and in the L2 norm of the misfit function I use the abs value of them. The control variable is real.
In the Optimization Module User's Guide/ Theory for the sensitivity interface/Issues to consider Regarding the Objective Function there is some comment on complex-valued objective functions: 'Sensitivity analysis can be applied only when the objective function is a real-valued differentiable function of the control variables.' ; I suppose this also applies when using the optimization interface; and they recommend to treat the real and imaginary part separately if this is not the case (the objective function is not real-valued differentiable).
Following these issues, I split the real and imaginary parts:

model.sol('sol1').feature('st1').set('splitcomplex​', 'on');

and I also specify the complex character of the dependent variables,

model.physics('pde1_1').prop('ShapeProperty').set(​'valueType', 1, 'complex');

But then a complex character is also applied to the control variable.
If I use the same command to specify the real character of the control variable: model.physics('opt1').feature('cvar1').set('valueType', 1, 'real'); the Livelink for Matlab does not recognize it. Is there some command to specify the value type of the control variable?

Thank you.

Inconsistency between 'mphinterp' and 'mphplot'

$
0
0
Hello,

I am having an issue with the MATLAB-Livelink function 'mphinterp'. What I am basically trying to do is plot 2D slice plots of data from the model solution. I am operating on solutions from different steps in a parametric sweep, so I need to save data from evaluated expressions at each step. The 'mphplot' command successfully plots the slice plots in MATLAB that resemble the 3D slice plot feature in COMSOL. However, since the generated MATLAB plot only contains colordata and not the actual data, I want to extract the mesh from the MATLAB plot and use 'mphinterp' to get at the actual data at each vertex in the 2D mesh. When I do this, and replot in MATLAB, the resulting plot looks ok within each domain, but near the boundaries, the values calculated from 'mphinterp' are not consistent with values derived from 'mphplot', and results in pixelated artifacts along the domain boundaries. The attached figures demonstrate this inconsistency. These figures were generated by plotting only the vertex 'markers' in MATLAB. The vertex coordinates are identical, but the derived values are different. I am confused as to why 'mphinterp' is giving different results using the same mesh that is generated from 'mphplot'. I can produce a similar inconsistency in COMSOL by comparing a 3D Plot Group->Slice (1 quick plane at z = 0) and a 2D Plot Group->Surface from a Cut-Plane dataset generated at z = 0, for example. These plots should be identical, but they are not. The former shows a smooth transition at the boundaries (similar to 'mphplot' output) and the latter is heavily distorted near the boundary edges (similar to 'mphinterp' output). Am I missing something? Should I not get the same result from 'mphinterp' when using an identical mesh generated from 'mphplot'? If not, then how can I access the underlying data that 'mphplot' interpolates from the model solution?

Thank you for any assistance.

Correct syntax for creating domain selection in the JAVA Api?

$
0
0
I am trying to follow the busbar tutorial using Comsol + Matlab.

To create a variable representing multiple boundaries to avoid redundancy the following code is given:

<code>
sel1 = model.selection.create('sel1');
sel1.set([2 3 4 5 6 7]);
sel1.name('Ti bolts');
</code>

Matlab returns the following error:

Error using busbar (line 54)
Java exception occurred:
Exception:
java.lang.IllegalArgumentException: Illegal input vector
(rethrown as com.comsol.util.exceptions.FlException)
Messages:
Illegal input vector

Line 54 refers to the second line of code.
Any one knows what the issue may be with the syntax if that's the problem?

Thank you,
Kayode
Viewing all 2194 articles
Browse latest View live


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