CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

Function returning uniform surfaceScalarField

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

Reply
 
LinkBack Thread Tools Display Modes
Old   June 22, 2012, 13:37
Question Function returning uniform surfaceScalarField
  #1
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 6
lichmaster is on a distinguished road
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
lichmaster is offline   Reply With Quote

Old   June 22, 2012, 13:50
Default
  #2
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 6
lichmaster is on a distinguished road
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
lichmaster is offline   Reply With Quote

Old   June 22, 2012, 16:47
Default
  #3
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Posts: 124
Rep Power: 8
anishtain4 is on a distinguished road
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?
anishtain4 is offline   Reply With Quote

Old   June 25, 2012, 03:46
Default
  #4
New Member
 
Lorenzo A. Ricciardi
Join Date: Mar 2011
Posts: 27
Rep Power: 6
lichmaster is on a distinguished road
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.
lichmaster is offline   Reply With Quote

Reply

Tags
surfacescalarfield, uniform

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 12 December 12, 2011 05:16
channelFoam for a 3D pipe AlmostSurelyRob OpenFOAM 3 June 24, 2011 13:06
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
turbulent jet simulation antonio_ing OpenFOAM Running, Solving & CFD 5 September 16, 2010 02:31
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50


All times are GMT -4. The time now is 04:31.