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?
Posted 21 feb 2010, 20:52 GMT-5 RF & Microwave Engineering Version 3.5a 9 Replies
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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
Please login with a confirmed email address before reporting spam
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
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
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
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
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
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.
Suggested Content
- KNOWLEDGE BASE My Flux Calculation Seems Wrong
- KNOWLEDGE BASE "Data access entity removed" occurs in my application
- FORUM How to access global functions defined in COMSOL with matlab?
- BLOG How to Use the Boundary Element Method in Acoustics Modeling
- KNOWLEDGE BASE The Magnetic and Electric Fields Interface with Electrical Circuit Gives an Unexpected Error for Transient Studies