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 the "spatial at" function to extract a value at a particular point

Please login with a confirmed email address before reporting spam

I need to write a COMSOL expression to extract a result value at particular spatial coordinates from one study, so that the result can be used as input to another study.

I am trying to implement coupling between physics domains where the coupling is only understood empirically. The empirical model predicts the boundary conditions of physics B based on evaluating a particular result component (in this case a strain component) of physics A at a particular set of coordinates.

It looks like I should be able to use the "spatial at" function, but the documentation is a bit sparse.

The only example I can find is from page 227 of the COMSOL 5.0 reference guide, and it is largely unexplained:
root.comp1.at1(0,y,dom)
the digit after the 'at' is the dimensionality of the domain being evaluated over. In my case I am looking at a point, so that should be zero, correct? I am operating in 3-space so it should be something like
... scope.at0(xcoord,ycoord,zcoord, expr)

I am at a loss for understanding exactly how you define the scope? What exactly is root? Is it an alias for the root of the ModelBuilder tree?




3 Replies Last Post 2015年2月13日 GMT-5 10:19
Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 2015年2月13日 GMT-5 09:11
Hi Stephen,

Yes, it seems that you are on the right track. You can use at0 to evaluate an expression at a point if the source geometry has a vertex in that point, and the syntax will then be something like

comp1.at0(xcoord, ycoord, zcoord, expr)

where the expression expr typically also uses a component scope such as comp1.solid.mises.

You are right about root: it represents the top level of the model tree (the root node), but because you are always inside the root node, the root. prefix is not needed so you can just skip it.

Thanks for your input. We will improve and extend the documentation for this operator in the next version.

Best regards,
Magnus Ringh, COMSOL
Hi Stephen, Yes, it seems that you are on the right track. You can use at0 to evaluate an expression at a point if the source geometry has a vertex in that point, and the syntax will then be something like comp1.at0(xcoord, ycoord, zcoord, expr) where the expression expr typically also uses a component scope such as comp1.solid.mises. You are right about root: it represents the top level of the model tree (the root node), but because you are always inside the root node, the root. prefix is not needed so you can just skip it. Thanks for your input. We will improve and extend the documentation for this operator in the next version. Best regards, Magnus Ringh, COMSOL

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 2015年2月13日 GMT-5 10:09

Yes, it seems that you are on the right track. You can use at0 to evaluate an expression at a point if the source geometry has a vertex in that point, and the syntax will then be something like

Hmm. Making sure the geometry has a vertex at that point sounds tricky, and also potentially fragile with respect to remeshing.

I could use Matlab to find the nearest vertex point between the meshing and study evaluation phases, but I'd like to avoid that because then my model would not be fully operable except when run with Matlab.

Would it be possible to use ballavg() or perhaps centroid() to obtain an expression that can be evaluated at any point, not just a vertex?

Alternatively is there any way to find the nearest vertex point to a given set of coordinates?
[QUOTE] Yes, it seems that you are on the right track. You can use at0 to evaluate an expression at a point if the source geometry has a vertex in that point, and the syntax will then be something like [/QUOTE] Hmm. Making sure the geometry has a vertex at that point sounds tricky, and also potentially fragile with respect to remeshing. I could use Matlab to find the nearest vertex point between the meshing and study evaluation phases, but I'd like to avoid that because then my model would not be fully operable except when run with Matlab. Would it be possible to use ballavg() or perhaps centroid() to obtain an expression that can be evaluated at any point, not just a vertex? Alternatively is there any way to find the nearest vertex point to a given set of coordinates?

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 2015年2月13日 GMT-5 10:19
Hi again,

I still think "spatial at" can work. If the source geometry is a 3D domain, then you should be able to use comp1.at3 if the expression that you want to evaluate is defined in the volume (domain), which it usually is. Another option is to insert points in the geometry to create vertices where you want to sample values from that component, but doing so, as you mentioned, can also affect the meshing.

Best regards,
Magnus Ringh, COMSOL
Hi again, I still think "spatial at" can work. If the source geometry is a 3D domain, then you should be able to use comp1.at3 if the expression that you want to evaluate is defined in the volume (domain), which it usually is. Another option is to insert points in the geometry to create vertices where you want to sample values from that component, but doing so, as you mentioned, can also affect the meshing. Best regards, Magnus Ringh, COMSOL

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.