Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

how to access variables in fem?

Please login with a confirmed email address before reporting spam

Hi all,

I am looking for some help in the post-processing regarding the following points:

1. Exchange the resutls stored in two varialbes (say CA1 and CA2) in fem0 after each transient run. how to do it?
2. Display all the values stored in CA1, CA2 in matlab window. what is the matlab command?

Please share your expertise.

Thanks in advance,
Vincent

9 Replies Last Post Jul 19, 2011, 3:21 a.m. EDT
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 22, 2010, 1:42 a.m. EST
Hi

it depends where the variables are defined in your model, take a read through the mlinterface.pdf this should help, and study the "_history.m" files, search for your variable, or save your model once as a "m" file and learn the structure.
It is not too obvious, but once you have understood the idea and logic, it's rather "easy"

Good luck
Ivar
Hi it depends where the variables are defined in your model, take a read through the mlinterface.pdf this should help, and study the "_history.m" files, search for your variable, or save your model once as a "m" file and learn the structure. It is not too obvious, but once you have understood the idea and logic, it's rather "easy" Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 27, 2010, 4:26 a.m. EST
Hi

I have located all my variables in fem.sol.u by assgining them different initial values.

However,

fem0.sol.u(17:120:28817,11)=fem0.sol.u(09:120:28809,11);
??? Access to an object's fields is only permitted within its methods.

is it possible to make private or protected object public?

Please share your expertise.

Thanks in advance!

Regards,

Vincent
Hi I have located all my variables in fem.sol.u by assgining them different initial values. However, fem0.sol.u(17:120:28817,11)=fem0.sol.u(09:120:28809,11); ??? Access to an object's fields is only permitted within its methods. is it possible to make private or protected object public? Please share your expertise. Thanks in advance! Regards, Vincent

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 28, 2010, 10:18 a.m. EST
...
...

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 28, 2010, 10:46 a.m. EST
Hi

I'm not familiar with that message, neither not really with replacing COMSOL solver output values, and something puzzles me, "fem0.sol.u" is for me the "output section" of the structure for solved data, and I'm not sure you can "write" into it, and not like that.

You have to get/find the "method" or rules for handling the objects inside that part of the "fem" structure and I'm not really the good person to talk to for that, but perhaps there is someone elso out there capable of explaining better, and who knows how to find the "rules"

Sorry I cannot do better
Ivar
Hi I'm not familiar with that message, neither not really with replacing COMSOL solver output values, and something puzzles me, "fem0.sol.u" is for me the "output section" of the structure for solved data, and I'm not sure you can "write" into it, and not like that. You have to get/find the "method" or rules for handling the objects inside that part of the "fem" structure and I'm not really the good person to talk to for that, but perhaps there is someone elso out there capable of explaining better, and who knows how to find the "rules" Sorry I cannot do better Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 7, 2010, 7:34 p.m. EDT
Hi,

I'm having a similar problem. I want to access the fem.sol.u and change its contents. Did you figure out any way for doing this??

please share!!

thank you
Hi, I'm having a similar problem. I want to access the fem.sol.u and change its contents. Did you figure out any way for doing this?? please share!! thank you

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 16, 2010, 11:51 a.m. EST
The fem.sol is a femsol type variable as so cannot be written to in the normal way like you would an array or cell.
From my investigations i think it is prop best to make a new fem.sol vairbale and place it in the fem structure.
If you access the COMSOL code in matlab you can find the femsol function which is used to create this variable type. I have not yet managed to make it totally work but i thought i would update you with a possible solution.

Or have you found a better wya of modifying the fem.sol?
The fem.sol is a femsol type variable as so cannot be written to in the normal way like you would an array or cell. From my investigations i think it is prop best to make a new fem.sol vairbale and place it in the fem structure. If you access the COMSOL code in matlab you can find the femsol function which is used to create this variable type. I have not yet managed to make it totally work but i thought i would update you with a possible solution. Or have you found a better wya of modifying the fem.sol?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 1, 2011, 4:04 a.m. EDT
Hi,

For just replacing the fem.sol.u with your own solution, it is possible to use the function femsol.
fem1=fem;
fem1.sol=femsol(AA);
where AA is your desired solution. I used this for eigenvalue analysis, when I wanted to replace the eigenmodes by one combination of two or three eigenmodes.

Hopefully this will help you!
Jan
Hi, For just replacing the fem.sol.u with your own solution, it is possible to use the function femsol. fem1=fem; fem1.sol=femsol(AA); where AA is your desired solution. I used this for eigenvalue analysis, when I wanted to replace the eigenmodes by one combination of two or three eigenmodes. Hopefully this will help you! Jan

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 18, 2011, 1:35 p.m. EDT
Hi,

I am having some trouble using the femsol command. I am using eigenmode analysis and each of my fem structures has two solutions, so fem1.sol.u will be a Nx2 array and so will fem2.sol.u. They both use exactly the same mesh. I want to replace the second column vector in fem1.sol.u with the first column vector in fem2.sol.u. I have tried just about everything. Here are a couple of them:

fem3 = fem1;
fem3.sol = femsol(fem1.sol.u(1), 'lambda', fem1.sol.lambda(1), fem2.sol.u(1), 'lambda', fem2.sol.lambda(1))
??? Error using ==> solproputil at 11
A property/value list must contain an even number of elements.
Error in ==> femsol.femsol at 62
prop=solproputil('femsol',varargin(2:end));

fem3.sol = femsol(fem1.sol.u(1), fem2.sol.u(1))
??? Error using ==> femsol.femsol at 112
Incorrect number of arguments or inappropriate argument type.

fem3.sol.u(:,2) = fem2.sol.u(:,1);
??? Access to an object's fields is only permitted within its methods.

Could someone please help me with this? So far I can only get femsol to work if I am replacing fem.sol.u with a single column vector, and not Nx2 array.
Hi, I am having some trouble using the femsol command. I am using eigenmode analysis and each of my fem structures has two solutions, so fem1.sol.u will be a Nx2 array and so will fem2.sol.u. They both use exactly the same mesh. I want to replace the second column vector in fem1.sol.u with the first column vector in fem2.sol.u. I have tried just about everything. Here are a couple of them: fem3 = fem1; fem3.sol = femsol(fem1.sol.u(1), 'lambda', fem1.sol.lambda(1), fem2.sol.u(1), 'lambda', fem2.sol.lambda(1)) ??? Error using ==> solproputil at 11 A property/value list must contain an even number of elements. Error in ==> femsol.femsol at 62 prop=solproputil('femsol',varargin(2:end)); fem3.sol = femsol(fem1.sol.u(1), fem2.sol.u(1)) ??? Error using ==> femsol.femsol at 112 Incorrect number of arguments or inappropriate argument type. fem3.sol.u(:,2) = fem2.sol.u(:,1); ??? Access to an object's fields is only permitted within its methods. Could someone please help me with this? So far I can only get femsol to work if I am replacing fem.sol.u with a single column vector, and not Nx2 array.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 19, 2011, 3:21 a.m. EDT
Hi,

As you use the same the same mesh, I will make the assumption that the data in fem.sol.u is the same, although I am not 100% sure. If I understand you correctly, you want to change one column in the fem.sol.u. Have you tried the following:

fem3=fem1;
% Create the new solution newfem:
newfem=zeros(length(fem1.sol.u),n);
for k=1:n
if k==2; newfem(:,k)=fem1.sol.u(:,k);
else newfem(:,k)=fem2.sol.u(:,k);end
end
% Save the new eigenvectors in the new fem structure
fem2.sol=femsol(newfem,'lambda',lambda);

Sincerely,
Jan
Hi, As you use the same the same mesh, I will make the assumption that the data in fem.sol.u is the same, although I am not 100% sure. If I understand you correctly, you want to change one column in the fem.sol.u. Have you tried the following: fem3=fem1; % Create the new solution newfem: newfem=zeros(length(fem1.sol.u),n); for k=1:n if k==2; newfem(:,k)=fem1.sol.u(:,k); else newfem(:,k)=fem2.sol.u(:,k);end end % Save the new eigenvectors in the new fem structure fem2.sol=femsol(newfem,'lambda',lambda); Sincerely, Jan

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.