# 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: 15 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: 15 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: 273 Rep Power: 18 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: 15 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