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

Division by zero exception - loop over scalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By l_r_mcglashan

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   August 6, 2013, 18:04
Default Division by zero exception - loop over scalarField
  #1
Member
 
Patrick Wollny
Join Date: Apr 2010
Posts: 58
Rep Power: 16
Pat84 is on a distinguished road
Hiho,

I´m programming a tool for the post processing in openFOAM.
In this code I divide a value by the denominator ( fvc::interpolate(T) - T_ref) which is a surfaceScalarField. To prevent the code from a division by zero, I do this:

Code:
surfaceScalarField dT = ( fvc::interpolate(T) - T_ref );
    
    forAll(dT.internalField(),i)
    {
      if(dT.internalField()[i] < 1e-10)
      {
        dT.internalField()[i] = 1e-10;
      }
    };
    
    forAll(dT.boundaryField(),patchi)
    {
      forAll(dT.boundaryField()[patchi],i)
      {
        if(dT.boundaryField()[patchi][i] < 1e-10)
        {
          dT.boundaryField()[patchi][i] = 1e-10;
        }
      };
    };
It is a very "unclean" solution which I'd like to replace. Is it possible to use only one loop over the whole surfaceScalarField (make no difference between the internal and boundary field)? And is it possible to use a pre defined value like "inf" for a value near zero?

Best regards,
Patrick
Pat84 is offline   Reply With Quote

 


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
[openSmoke] libOpenSMOKE Tobi OpenFOAM Community Contributions 562 January 25, 2023 09:21
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
[CAD formats] my stl surface is seen as just a line rcastilla OpenFOAM Meshing & Mesh Conversion 2 January 6, 2010 01:30
ScalarField division maka OpenFOAM Pre-Processing 2 August 27, 2007 05:10
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 15:57


All times are GMT -4. The time now is 06:47.