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

Implementation of sigmoid function

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 15, 2020, 06:03
Default Implementation of sigmoid function
  #1
New Member
 
Join Date: May 2020
Location: India
Posts: 4
Rep Power: 5
Action.Kamen is on a distinguished road
Hello Foamers ,


I am trying to implement sigmoid function in OpenFOAM-v1912 using

Foam::exp() and Foam::pow().



Code:
volScalarField tmpVar = nGAGR*scalar(-1) + averageGAR;
Code:
sigmoidGAGR=Foam::pow((1+Foam::exp(tmpVar)),-1);





here nGAGR and averageGAGR both are dimensionless volScalarField. But the code wont work and stops at the second line.


What am I doing wrong here, or is there any other way to implement sigmoid function.
Action.Kamen is offline   Reply With Quote

Old   August 15, 2020, 15:56
Default
  #2
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
Hi,

- What is the error?
- Sigmoid function is a generic name, which expression you try to code?
- If the value of "tmpVar" becomes very large, the computation of "exp" function may throw floating point overflow error.
HPE is offline   Reply With Quote

Old   August 16, 2020, 06:47
Default
  #3
New Member
 
Join Date: May 2020
Location: India
Posts: 4
Rep Power: 5
Action.Kamen is on a distinguished road
Hi HPE,


- There is no error displayed in the terminal, the simulation just stops after first time-interval. But when I comment out the line the simulation starts running (and does not stops ).


- Sigmoid function : The basic idea to use sigmoid function is that to take in some large number and pump out result that is either 0 or 1(or something in between). Here nGAGR is the order of 10^11 and averageGAR is in the order of 10^6.



- Value should not be a problem since machine I'm using is a 64-bit one, and the macros DBL_MIN and DBL_MAX give the ranges as 2.22507e-308 and 1.79769e+308 respectively. And the range I'm working with is around 10^-8 to 10^11.


The thing I want to do is basically assign 0s and 1s all over my mesh into volScalarField. There are two regions in the mesh one where nGAGR is around 10^11 and other where nGAGR is around 10^-8. Now that could have been easily achieved by looping all over the mesh and using if else. But I have a quite large mesh and deltaT is pretty small 10^-5. And what I learned from scientific computing course is that if/else and loops are lot slower than compared to mathematical statements. So I'm trying to implement sigmoid function


PS : I have attached image of the sigmoid function which I want to implement
Attached Images
File Type: gif CodeCogsEqn.gif (1.5 KB, 1 views)
Action.Kamen is offline   Reply With Quote

Reply

Tags
foam::exp, foam::pow, scalar, sigmoid, volscalarfield


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
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 07:15
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 01:27
channelFoam for a 3D pipe AlmostSurelyRob OpenFOAM 3 June 24, 2011 13:06
latest OpenFOAM-1.6.x from git failed to compile phsieh2005 OpenFOAM Bugs 25 February 9, 2010 04:37
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23


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