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

Take the surface average on the outlet and inlet boundaries

$
0
0
Dear All,
I am trying to create a loop in MATLAB to control my COMSOL simulation. I am not good at using the COMSOL operators. Can any one tell me how to take the average of my variables at the boundary within the loop. For instance, I need to calculate the difference of my inlet and outlet concentrations within the loop.


.
Regards

COMSOL Mutiphysics and External MATLAB function

$
0
0
Dear All,

I am using COMSOL Multiphysics(version 5.2) for solving the models(time dependent) which calls external MATLAB functions. The objective of external MATLAB functions is to resolve ODE and give a return value to COMSOL.

I would like to know how I can solve ODE externally through MATLAB for the COMSOL model?

Thanks,
Krushna

Problems syncing geometry using livelink for autocad

$
0
0
I am trying to build a simple 3D model in Autocad (for simplicity's sake, assume a cube). However, objects can not be parametrized in 3D, so I am confused as to how I am supposed to access dimensions after a 3D object has been built in order to run parameter sweeps when I link it with COMSOL.

Is there a way to livelink a 2D drawing in COMSOL?

Thanks!

Automatically import parameters and export simulation data

$
0
0
Hi! I'd like to do the following. I would like my Comsol model to automatically import simulation parameters (e.g. geometrical dimensions, charge density on a surface, etc.), run an auxiliary sweep and then automatically export the values of a variable for all steps of the sweep. This would be very useful, because I can run Comsol in batch mode but not Matlab.

(As an alternative, if someone can tell me how to run Matlab with Comsol on a linux machine in batch mode, I'm also happy, actually happier than with the previous solution.)

Possibility to import a 2D CAD file to COMSOL?

$
0
0
Hello,

I am running the last version of COMSOL (4.3b). I tried to import a 2D CAD file to COMSOL but failed to do so! Generally, is it possible to import a 2D CAD file to COMSOL or only 3D files? If so, through which format?

Your prompt reply will be greatly appreciated!

Many thanks in advance,

Afshin

Parallel computing MatLab Comsol

$
0
0
Hi,

I am using Comsol 4.3 with Livelink for Matlab. I run an optimization code in Matlab where i call Comsol to perform frequency response simulations. Now i would like to start two parallel frequency response simulations that are independent of each other from my Matlab code.
My approach so far has been to open another Matlab worker by using matlabpool and parfor. However, only one of the Matlab workers are then connected to Comsol. Is it possible to perform parallel computing in Comsol when using the Matlab livelink?

//Anders

Singularity error

$
0
0
Hi,
when I use Matlab to run the COMSOL simulation, I am getting the error :
Repeated error test failures. May have reached a singularity.
But when I directly use COMSOL to run the simulation, it works fine.
Any suggestion? Thanks in advance.

Hi

$
0
0
I modeled a geometry in matlab, can any one tell me how to import that geometry to comsol

using stored solution in a matlab loop

$
0
0
Dear all
I am simulating a multiphysics problem which combines electric current with heat transfer, for multiple pulses .
I am trying to use a stored solution as an initial value for the proceeding MATLAB loops in order to see temperature accumulation. Is there a new command for using a stored solution in COMSOL 4.4? . I know there is an available command in COMSOL 3.5 "asseminit", is there a replacing command ?
Thanks for your help

Calling a Matlab function from within Comsol

$
0
0
I would like to call a Matlab function from within Comsol, and run across the error:

Failed to load library.
- Error: dlopen(/Applications/COMSOL41/lib/maci64/flmatlab.dylib, 5): Library not loaded: @loader_path/libeng.dylib
Referenced from: /Applications/COMSOL41/lib/maci64/flmatlab.dylib
Reason: image not found

I have the library on my computer (a Mac) in /Applications/MATLAB_R2011b.app/bin/maci64/libeng.dylib , but do not know how to check or set @loader_path.

As a simple example of how to get this error is to write a Matlab function:

function output=disp(x)
output=x;

and insert it into Comsol as a displacement boundary condition.

Any ideas?

Teresa

COMSOL cannot load MATLAB (on Ubuntu 12.04 and Debian 7.7)

$
0
0
Dear all,

I recently experienced a serious problem when trying to use MATLAB functions in COMSOL on Linux computers, where COMSOL needs to call a MATLAB command line.

I use COMSOL 4.4 and MATLAB R2013b.

I both tried that on a workstation with Ubuntu 12.04 and a server with Debian 7.7.
Models and MATLAB functions where tested on a PC with Windows 7 before and worked.

When trying to run them (actually when trying to run any function that needs to call MATLAB), I get the following error:
-----------------------------------------------------------------------------
The following feature has encountered a problem:

Failure loading MATLAB libraries. This model requires that MATLAB is available.
- Library: csmatlab.so
- Error: libeng.so: cannot open shared object file: No such file or directory
-----------------------------------------------------------------------------

Both libraries, csmatlab.so and libeng.so, are on the system. libeng.so is also in the directory of the MATLAB installation that is set in COMSOL, namely /usr/local/MATLAB/R2013b (and there within /bin/glnxa64/libeng.so).

Calling COMSOL servers from MATLAB works perfectly fine on this systems (to the best of my knowledge and experience).

So did anyone else get this error and is there a solution for that problem?

Thanks already in advance for your help.

Best,
Hannes

MATLAB parfor and Comsol server

$
0
0
Hi,
I want to speed up my computations using the parfor loop in MATLAB (from Parallel Computing Toolbox). I run this on a Linux machine. My code so far:

system('killall -9 comsollauncher java'); % kill previous running Comsol server instances to prevent port assignment problems
pool = parpool('local',2); % open local pool with two Workers
parfor i=1:5 % set this to 2 iterations (=number of workers in pool) and it will work
comsolPort = 2036+i; % set unique port
system( ['comsol -np 1 server -port ',num2str(comsolPort), ' &'] ); % start a Comsol server
pause( 6 ) % give Comsol server time to start up
testfun(comsolPort) % function connects to the given Comsol server using mphstart(comsolPort), does some Comsol stuff and later disconnects
end
delete(pool); %close pool

Using 2 workers the code works if parfor makes only 2 iterations. But if there are more iterations mphstart() cannot connect to the given Comsol server throwing:

"Error using mphstart (line 152) A connection to Comsol could not be established. Please check that a Comsol Server is started prior to calling mphstart"

although a new server is definitely running on the given port. This might be related to how the MATLAB job scheduler works. But I have no idea why and how to fix this. Having only as many parfor iterations as workers in the pool is not optimal, because I have to run far more cases than there are CPUs/workers on my machine. Do you have any suggestions how to make this work?

Thank you and best regards,
Chris

MATLAB Parallel Toolbox parfor: using mphstart() more than once

$
0
0
Hi,
my problem is that a MATLAB instance refuses to use mphstart() more than once in its lifetime.
I need to reconnect because I want to use the MATLAB Parallel Computing Toolbox with parfor to run lots of Comsol models in parallel. Unfortunately if a MATLAB worker is re-assigned with a new Comsol task, it cannot connect to a Comsol server although its workspace is cleared completely.
Has anyone an explaination for this or knows how to fix this?
Best,
Chris

Domain number Assignment

$
0
0
Dear All,
I wrote a code for my comsol multiphysics problem using comsol livelink matlab. The code is working and producing desired geometry but there is problem regarding domain number as comsol assign domain number itself .

Is there any way to assign domain number of one's need while working in comsol livelink matlab .

Please suggest some solution.

-----------------------
Asha Sharma

How to extract many coordinates in geometry?

$
0
0
Hi, I'm trying to extract the coordinates of several points and more importantly, I need to assign their coordinates as a variable.

Let's simplify it.
There is a random function (has a value between 0 and 1) and i'd like to find where(value>=0.9) and their coordinates and finally want to assign as variable.

1. coordinates of several points.
2. set up a new variable with their coordinates.

How could it be possible? I've been working for a month.
any suggestion would be thankful and whether it need to use livelink or not doesn't matter

Best regards.

Comsol with matlab error on HPC cluster

$
0
0
Dear All,

I run my comsol models with matlab on HPC cluster which have CentOS Linux installed on it. I use the following command for starting Comsol server on HPC

comsol mphserver &

This command starts Comsol server successfully but when I start connecting matlab to it by the following commmand:

matlab -nodesktop -nosplash -r "mphstart; mymfile.m; exit",

there appears an error which say: "Comsol server must run before calling mphstart", while I am sure about starting Comsol server, even when I try to start Comsol with Matlab by the command:

comsol mphserver matlab

server starts and runs Matlab but a confusing java error occurred and further processing is blocked.
FYI, I use Comsol version 5.3, It is interesting to inform you that everything is OK on my laptop with Windows 7. These errors occurs when I try to perform my simulations on HPC.

Any suggestions and helps are appreciated, Thanks,

Data from a cut line with Livelink Matlab

$
0
0
Hello,

I'm studing an optical waveguide in Comsol.
I have defined a cut line 2D to observe the electric field z-component along the width of the waveguide.
Then I have used the livelink matlab command:

mphinterp(model,{'real(ewfd.Ez)'},'dataset','cln1','Solnum','5')

to retrieve the same electric field z-component and plot the corresponding profile.
I have almost the same plot as in Comsol but there are some supplementary points that give the plot a saw tooth like profile.
If I export the data from Comsol into a file and use them to plot the field, I have the same smooth plot as in Comsol but I don't want to loose time exporting the data like this.

What are those supplementary points given by mphinterp? What is the good way to directly retrieve data from a cut line to avoid them?

Thanks in advance!

Cyclic symmetry with LiveLink MATLAB

$
0
0
Dear, all

Hi, I'm trying to extract the result from structural frequency response with MATLAB.
The model I used is a quarter of PMSM stator, and I applied the cyclic symmetry condition in the solid mechanics physics.

I need the displacement, velocity or acceleration on the surface of the full stator model because the following step will be the acoustic analysis with BEM.

Although it can be visualized with sector 3D feature, however, I don't get how it be extracted with LiveLink MATLAB for full model.

Is anyone can give tips or help?

Increase stiffness by adding more stiffer material in optimization

$
0
0
Please, find the matlab code below. I have a 2D model. The base material (mat1) has the young modulus (E1) of 1 and poisson ratio of 0.3. The compliance is 52.79. In order to reduce the compliance (increase the stiffness) of the model, I added a strip of material (mat2) which young modulus (E2) is 5 and poisson ratio equals 0.3. This reduces the compliance of my model to 50.23. I want to run an optimization using the livelink to add more mat2 to my model in order to minimize the compliance further to 43. How can I use mat2 as the design variable? Thank you

% Matlab code
%.................................................................................

function f = two_materials
%
% two_materials.m
%
% Model exported on Sep 3 2017, 06:19 by COMSOL 5.2.1.152.

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

model = ModelUtil.create('Model');

model.modelPath('C:\Users\sayinde\Dropbox\demo for diff materials');

model.label('two_materials.mph');

model.comments(['Untitled\n\n']);

model.modelNode.create('comp1');

model.geom.create('geom1', 2);

model.mesh.create('mesh1', 'geom1');

model.geom('geom1').create('b1', 'BezierPolygon');
model.geom('geom1').feature('b1').set('p', {'-1.5' '-1.5' '-0.5' '-0.5' '0.6' '0.6' '-1.5'; ...
'0.7' '-0.3' '-0.3' '-0.1' '-0.1' '0.7' '0.7'});
model.geom('geom1').feature('b1').set('w', {'1' '1' '1' '1' '1' '1' '1' '1' '1' '1' ...
'1' '1'});
model.geom('geom1').feature('b1').set('degree', {'1' '1' '1' '1' '1' '1'});
model.geom('geom1').create('b2', 'BezierPolygon');
model.geom('geom1').feature('b2').set('p', {'-1.3' '-1.3' '-0.9' '-0.9' '-1.3'; '0.3' '0.5' '0.5' '0.3' '0.3'});
model.geom('geom1').feature('b2').set('w', {'1' '1' '1' '1' '1' '1' '1' '1'});
model.geom('geom1').feature('b2').set('degree', {'1' '1' '1' '1'});
model.geom('geom1').run;
model.geom('geom1').run('fin');

model.material.create('mat1', 'Common', 'comp1');
model.material.create('mat2', 'Common', 'comp1');
model.material('mat1').selection.set([1]);
model.material('mat1').propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');
model.material('mat2').selection.set([2]);
model.material('mat2').propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');

model.physics.create('solid', 'SolidMechanics', 'geom1');
model.physics('solid').create('fix1', 'Fixed', 1);
model.physics('solid').feature('fix1').selection.set([1]);
model.physics('solid').create('pl1', 'PointLoad', 0);
model.physics('solid').feature('pl1').selection.set([9]);

model.view('view1').axis.set('abstractviewrratio', '0.17300830781459808');
model.view('view1').axis.set('abstractviewlratio', '-0.055711157619953156');
model.view('view1').axis.set('abstractviewxscale', '0.005181347019970417');
model.view('view1').axis.set('abstractviewbratio', '-0.4787564277648926');
model.view('view1').axis.set('xmax', '0.6794240474700928');
model.view('view1').axis.set('xmin', '-1.5255756378173828');
model.view('view1').axis.set('abstractviewyscale', '0.005181347019970417');
model.view('view1').axis.set('ymax', '0.9334676861763');
model.view('view1').axis.set('ymin', '-0.8447578549385071');
model.view('view1').axis.set('abstractviewtratio', '0.20518136024475098');

model.material('mat1').label('E=1 poison =0.3');
model.material('mat1').propertyGroup('Enu').set('youngsmodulus', '1');
model.material('mat1').propertyGroup('Enu').set('poissonsratio', '0.3');
model.material('mat2').label('E=5 poison=0.3');
model.material('mat2').propertyGroup('Enu').set('youngsmodulus', '5');
model.material('mat2').propertyGroup('Enu').set('poissonsratio', '0.3');

model.physics('solid').feature('pl1').set('Fp', {'0'; '-1'; '0'});

model.mesh('mesh1').run;

model.study.create('std1');
model.study('std1').create('stat', 'Stationary');

model.sol.create('sol1');
model.sol('sol1').study('std1');
model.sol('sol1').attach('std1');
model.sol('sol1').create('st1', 'StudyStep');
model.sol('sol1').create('v1', 'Variables');
model.sol('sol1').create('s1', 'Stationary');
model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled');
model.sol('sol1').feature('s1').feature.remove('fcDef');

model.result.create('pg1', 'PlotGroup2D');
model.result('pg1').create('surf1', 'Surface');
model.result('pg1').feature('surf1').create('def', 'Deform');

model.sol('sol1').attach('std1');
model.sol('sol1').runAll;

model.result('pg1').label('Stress (solid)');
model.result('pg1').feature('surf1').set('descr', 'von Mises stress');
model.result('pg1').feature('surf1').set('unit', 'N/m^2');
model.result('pg1').feature('surf1').set('expr', 'solid.mises');
model.result('pg1').feature('surf1').set('resolution', 'normal');
model.result('pg1').feature('surf1').feature('def').set('scale', '0.002963085086206459');
model.result('pg1').feature('surf1').feature('def').set('scaleactive', false);

model.sol('sol1').study('std1');

model.study('std1').feature('stat').set('notlistsolnum', 1);
model.study('std1').feature('stat').set('notsolnum', '1');
model.study('std1').feature('stat').set('listsolnum', 1);
model.study('std1').feature('stat').set('solnum', '1');

model.sol('sol1').feature.remove('s1');
model.sol('sol1').feature.remove('v1');
model.sol('sol1').feature.remove('st1');
model.sol('sol1').create('st1', 'StudyStep');
model.sol('sol1').feature('st1').set('study', 'std1');
model.sol('sol1').feature('st1').set('studystep', 'stat');
model.sol('sol1').create('v1', 'Variables');
model.sol('sol1').feature('v1').set('control', 'stat');
model.sol('sol1').create('s1', 'Stationary');
model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled');
model.sol('sol1').feature('s1').feature('fc1').set('termonres', 'auto');
model.sol('sol1').feature('s1').feature('fc1').set('reserrfact', 1000);
model.sol('sol1').feature('s1').feature('fc1').set('linsolver', 'dDef');
model.sol('sol1').feature('s1').feature('fc1').set('termonres', 'auto');
model.sol('sol1').feature('s1').feature('fc1').set('reserrfact', 1000);
model.sol('sol1').feature('s1').feature.remove('fcDef');
model.sol('sol1').attach('std1');
model.sol('sol1').runAll;

model.result('pg1').run;

FA = mphmatrix(model, 'sol1', 'out', {'K','E'});
K = FA.K; % stiffness vector
% solve directly from constrained matrices
MA = mphmatrix(model ,'sol1','Out', {'Kc','Lc','Null','ud','uscale'},'initmethod','sol','initsol','zero');
Uc = MA.Null*(MA.Kc\MA.Lc);
U0 = Uc+MA.ud;
U1 = U0.*MA.uscale;
compliance = U1'*K*U1; % u is the global displacement I want to use to compute the compliance
assignin('base','compliance',compliance)

f = compliance;

mphgeom(model)

end


Import a matrix from mpheval operator.

$
0
0
Hi, I'd like to ask a question!

I got the matrix (V=mpheval(model,'V')) using the Livelink.
and I modified value of some points in V matrix.
But when I import to COMSOL, It didn't be reflected.

If you have any experience or helps could you give me any suggestion?

Viewing all 2194 articles
Browse latest View live