CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How to divide a vectorfield by the magnitude if the vector can be zero

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 5, 2021, 18:24
Default How to divide a vectorfield by the magnitude if the vector can be zero
  #1
Member
 
Torsten Schenkel
Join Date: Jan 2014
Posts: 69
Rep Power: 12
tschenkel is on a distinguished road
Hello,

I am trying to do some postprocessing with normalised vectors. The vector can be zero, so the simple form:

Un = U/mag(U)


will break with segfault.


Un = U/(mag(U)+1e64)



doesn't work, because the dimensions won't match (1e-64) has dimension [0 0 0 ... 0]



Is there a trick to achieve that?


U is not the velocity, so a specific normalised velocity function wouldn't help. Would need to take any dimensionedVolVectorField.
tschenkel is offline   Reply With Quote

Old   October 6, 2021, 08:24
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
You should decide by a small dimensionized scalar. You can find an example here how to convert to dimensionless scalar in openfoam
mAlletto is offline   Reply With Quote

Old   October 6, 2021, 09:50
Default
  #3
Member
 
Torsten Schenkel
Join Date: Jan 2014
Posts: 69
Rep Power: 12
tschenkel is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
You should decide by a small dimensionized scalar. You can find an example here how to convert to dimensionless scalar in openfoam

Thanks, that's very helpful. I was starting to play around with .value() and .dimensions().

Good to know that that is the right path.
tschenkel is offline   Reply With Quote

Old   October 9, 2021, 06:09
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Need to check if the normalised(..) function works on GeometricFields or only on primitive fields, but could start looking there. It haves a check for ROOTVSMALL to protect the division.
olesen is offline   Reply With Quote

Old   October 9, 2021, 10:16
Default
  #5
Member
 
Torsten Schenkel
Join Date: Jan 2014
Posts: 69
Rep Power: 12
tschenkel is on a distinguished road
Quote:
Originally Posted by olesen View Post
Need to check if the normalised(..) function works on GeometricFields or only on primitive fields, but could start looking there. It haves a check for ROOTVSMALL to protect the division.

normalised() isn't defined for volVectorFields, it seems.
tschenkel is offline   Reply With Quote

Old   October 9, 2021, 10:19
Default SOLVED: create a dimensionedScalar for the very small value epsilon
  #6
Member
 
Torsten Schenkel
Join Date: Jan 2014
Posts: 69
Rep Power: 12
tschenkel is on a distinguished road
Code:
dimensionedScalar epsWSS = dimensionedScalar("epsWSS",WSS.dimensions(), 1e-64);

creates a very small scalar with dimension of the vector field, which can then be used as:


Code:
normalisedWSS = WSS / (mag(WSS)+epsWSS);
tschenkel is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Velocity Magnitude not showing results musa19 Tecplot 1 November 18, 2020 23:49
HronTurekFsi3 foam-extend3.1 Maimouna OpenFOAM Running, Solving & CFD 112 April 20, 2019 21:11
Magnitude of a tensor mmkr825 OpenFOAM Programming & Development 8 December 12, 2018 13:49
'cell relative: velocity magnitude' vs 'velocity magnitude' alpharays Main CFD Forum 2 June 18, 2015 07:24
Stresseq vs stress magnitude watashiwa OpenFOAM 1 October 14, 2010 12:02


All times are GMT -4. The time now is 23:43.