# Function returning uniform surfaceScalarField

 Register Blogs Members List Search Today's Posts Mark Forums Read

 June 22, 2012, 13:37 Function returning uniform surfaceScalarField #1 New Member   Lorenzo A. Ricciardi Join Date: Mar 2011 Posts: 27 Rep Power: 7 Hi Foamers, I've stumbled upon what I think is a simple yet annoying difficulty... I looked for answers on the forum, but to no use. I need to write a recursive function returning a surfaceScalarField. It has several arguments, one of which is a scalar, and when this scalar is "0", then the surfaceScalarField should be 1 everywhere. Don't know how to make it work, though... Edit: The function is this surfaceScalarField int_u (int n, surfaceScalarField l, surfaceScalarField U) { if (n == 0) return 1.0; if (n == 1) return U; return U*int_u(n-1,l,U)+(n-1)/(2*l)*int_u(n-2,l,U); } Last edited by lichmaster; June 22, 2012 at 13:39. Reason: completion of message

 June 22, 2012, 13:50 #2 New Member   Lorenzo A. Ricciardi Join Date: Mar 2011 Posts: 27 Rep Power: 7 Since one of the inputs is a surfaceScalarField l, a workaround is to return l/l (since l should be always positive), but I'd prefer a more efficient and robust solution

 June 22, 2012, 16:47 #3 Senior Member   Mahdi Hosseinali Join Date: Apr 2009 Location: NB, Canada Posts: 232 Rep Power: 10 First of all it's better to pass the fields by reference rather than by value, which means surfaceScalarField int_u (int n, surfaceScalarField& l, surfaceScalarField& U); What is your problem with the code?

 June 25, 2012, 03:46 #4 New Member   Lorenzo A. Ricciardi Join Date: Mar 2011 Posts: 27 Rep Power: 7 Thanks for the suggestion, I was planning to optimize the code later but this modification takes almost zero time. If you read the function I posted above, I need to return an uniform value when n is zero, and a calculated (nonuniform) value when is greater than zero. The problem is that i don't know how to cast the scalar 1.0 into the surfaceScalarField uniform 1.0. The line Code: `return 1.0` gives Code: `error: conversion from 'double' to non-scalar type "Foam::surfaceScalarField' requested"` I have bypassed it, for now, with a fake calculation "return l/l", since l should be always strictly positive, but for better efficiency and robustness I would like to know how to return (assign) an uniform surfaceScalarField.

 Tags surfacescalarfield, uniform

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post anand_30 OpenFOAM Meshing & Mesh Conversion 12 December 12, 2011 05:16 AlmostSurelyRob OpenFOAM 3 June 24, 2011 13:06 asaijo OpenFOAM Installation 9 April 6, 2011 12:21 antonio_ing OpenFOAM Running, Solving & CFD 5 September 16, 2010 02:31 ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50

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