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.
Using variables to define material
Posted Dec 8, 2010, 7:32 p.m. EST Materials, Parameters, Variables, & Functions Version 4.1 9 Replies
Please login with a confirmed email address before reporting spam
The homogenous, time harmonic case of the wave equation is simply the Helmholtz equation, which is already built in COMSOL. This can be solved very nicely. Now, the problem is that I want to vary the absorption coefficient "a" according to the material of the regions I define. This will allow me to capture the effect of reflection/refraction under different geometries.
Unfortunately, unlike the pre-built physics models, there is no option "From material" for the absorption coefficient. I am only allowed to enter a constant or an expression. After reading through the documentation, I figured that I could put a variable there, and define the variable to be a different value depending on which domain it is in.
As simple as it sounds, I can't figure out how to do this. I understand that I should be able to write an "expression" by accessing the domain variables already defined, but I can't find any examples of this. The documentation is either woefully inadequate in this regard or I am just looking at the wrong place.
Any help will be greatly appreciated, especially if it has an example!
Please login with a confirmed email address before reporting spam
you can get material data by pointing directly to them with a mat1.rho or somethin like that, the difficulty is to identify the 1,2,3 and which material it is (check the tag number). Then you can multiply your exquation by a boolean (x<x0)
expression to add some particular property in space (check the doc on the level set method in fluidics) or add the T temperature dependance
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
Do you know if it is possible to write such an expression for existing boundaries? This would allow me to used more complicated boundaries (e.g. circular shaped ones).
For example, I hope to do write something like "(x,y) in domain1" that will return 1 if the coordinates (x,y) are in the domain and 0 otherwise.
Thanks!
John
Please login with a confirmed email address before reporting spam
if(dom==1,epsilonr_air,if(dom==2,epsilonr_container,epsilonr_ball) )
where we use a nested if statement to assign domain 1 the relative permitivity of espislonr_air, domain 2 epsilonr_container, and the remaining domain epsilonr_ball.
The key is the "dom" variable, which is used for inserting probes as well. The only reference I found of this in the documentation is in the "Summary of Common Predefined Variables" where it is lumped with a bunch of other variables under "Mesh Information".
Please login with a confirmed email address before reporting spam
After reading this thread and the documentation, I used the''dom'' variable conveniently in my 1D simulation in 4.0a.
But this variable could be either for a domain or for a boundary, as mentioned in the doc.
e.g. :
(dom==1)*alpha , the question is how could I know if this condition is evaluated for boundary 1 or domain 1 ? or both?
Thanks in advance !
Regards
--
Ali
Please login with a confirmed email address before reporting spam
there are a few concepts and implicit usage of references and variables that are essential to be able to use COMSOL efficiently. I find that these could be better explained, as it took me very long before I started to feel confortable, so I do understand your issue there :)
basically most variable depend on their context, such as spatial dimensions x,y,z or r,phi ... and the Entities (Domains, Boundaries, Edges or Points). "dom" is one of these variables, even an internal variable that takes the entity "ID" be it Domains, Boundaries Edges or Points. So you must ALWAYS check that when "dom" appears in a formula field are any entity clearly defined (by a selection such that of the Boundary conditions ) ?
its the same for "solid.rho" rho is depending on the "dom" of the domains as it might change from one material block to another material block (hence one should talk of "rho_i" for the "i" domains in a complex model. But rho might also change with position within a given material block (i.e.due to extreme pressures), or it changes with temperature ... hence in all generality one should write "solid.rho_i(x,y,z,T,...)". Then again T might well be T(x,y,z,...) and so on
Hope this helps on the way
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
However, my case is far simpler since I have only 4 intervals (adjacent and equal segments) in 1D, and I want to define a local variable and apply it to the first pair of segments and their extremities
Variable name: alpha
Expression : (dom==1 || dom==2)*(an expression)
After examining the results, the variable is successfully applied to the segments and the starting boundary of the first segment,
BUT the problem remains in the end point of segment 2 because it's common for segments 2 and 3, where the results show that it has been counted as a starting point for segment 3... So i don't know if a ''domain point probe'' would the trick
Excuse me if my explanation is not clear enough
Regards
Please login with a confirmed email address before reporting spam
I think I got the essentials from your explanations, such a simple geometry is good for the learning process (easier to go throuh all cases):
variant a) the lazy long path (?):
you define your 4 segments in the geometry, you set the "Geometry FInish" node to "Assembly" then normally when you go to the "material" or the "physics" nodes and look at the "Entity list" page, you will see 4 domains and 8 boundary points wheres at the domain intersections you have 2 overlapping boundaries each time.
You make an "identity pair" for all "pairs" for which you want to apply "continuity" under "Definitions - identity pair", under your "Physics" you add a "Pair - Continuity" and select in the list the identity pair. You should then remain with two boundaries, overlapping) where you apply your "fan effect" or equations to link velocity or whatever variable discontinuity you need.
variant b) the more rigurous:
you select the two -three adjacent domains/lines that have continuity between them and you apply the "Geometry - Compose object" on them to "group" them into one "Geoemtrical Object" with an interiour boundary, if your fan is in the middle you need to do this operation twice for the two objects to the left and the two to the right. If yo check your geometrical "Object" list you should end up with two Entities. Now you apply again "Finish - Assembly mode".
In this way you will also end up with 4 domains, but only 6 boundaris (points) whereas 2 are overlapping at the common intersection of the two previous "objects". In this way COMSOL looks after the continuity on the "interiour boundaries" for you and you have only to deal specifically with the two overlapping points do define some variables to link them together the way you want (or to apply specific Boundary physics on them)
I believe it is rather important to catch the concept of "Geometrical Objects" and "FEM Entities" in COMSOL. If you master this you get away with many frustrating subjects, and you quickly learn how to design/build very efficient geometries for your models in the COMSOL CAD environment. Particularly when you need to think meshing, and how to ease the meshing procedure, which is easy or impossible simply by cutting up your geometry in a clever way with a few extra internal boundaries, but that is another story. Try a search on the forum, I have discussed this several times here already ;)
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
I have problems to define a specific function G(x,y) involving an integral of the kind \int \int f(x+dest(x),y+dest(y))*f(x,y) dx dy.
Here f is 1 inside a domain and 0 else.
As a simple 2D example, assume I have a square domain [0,1]*[0,1] (here called “dom 1”).
I can calculate the area of dom 1 either as I) intop(1)=1 on dom 1, or as II) intop( (dom==1)*1)=1 on all domains.
Since it is important that all x,y values are considered in f(x+dest(x),y+dest(y)), I chose the second alternative II) above to procede.
Hence since f is 1 on dom 1 we have
\int \int f(x+dest(x),y+dest(y))*f(x,y) dx dy = \int \int f(x+dest(x),y+dest(y))*(dom==1) dx dy.
But now comes the tricky part, how do I write in Comsol that f(x+dest(x),y+dest(y)) = 1 only when x+dest(x),y+dest(y) \in dom 1 (else 0)?
I found something like:
(root.mod2.at2(x+dest(x),y+dest(y),dom) == 1
In the manual, but what is the “scope” etc here?
For example with dest(x)=2*dest(y)=1/4 the above example should give the answer G = 0.6563 (=21/32).
Trivially we also have for dest(x)=dest(y)=0, that G = intop((dom==1)*1)=1.
Cheers, Hans
Please login with a confirmed email address before reporting spam
I'm trying to define a new variable in two different materials (water S=1 and glass S=1.8), and to put it in an equation as, ht.S, so I expect Comsol to pick the data while calculating in glass or water, however it's not reading the new defined variable, it keeps giving error, but when I put the properties of material which was defined automatically, it doesn't have the same problem.
I would be really happy if you help me,
Thanks.
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
- BLOG How to Use State Variables in COMSOL Multiphysics®
- BLOG Computing Total Normal Flux on a Planar Surface
- FORUM Define function of multiple variables
-
KNOWLEDGE BASE
How can I see the equations COMSOL is defining?
How do I implement a user-defined Multiphysics coupling? - BLOG Simulating the Tunneling Current Across a Graded Heterojunction