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

converting double to volScalarField

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

Reply
 
LinkBack Thread Tools Display Modes
Old   August 7, 2013, 10:39
Default converting double to volScalarField
  #1
New Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 25
Rep Power: 4
zcarral is on a distinguished road
I need to convert a “double” variable “P” to a “volScalarField” variable “source”.

This is part of my code:


57 volScalarField source=P.value();
58 volScalarField x = mesh.C().component(vector::X);
59 forAll(source,i)
60 {
61 if (x[i] < 0.1) source[i]=P.value();
62 else source[i] = 0;
63 }


When I compile, line 61 is Ok. Nevertheless, I have the following error in line 57:



oFoam.C:57: error: conversion from ‘double’ to non-scalar type ‘Foam::volScalarField’ requested




I tried to change line 57 to “volScalarField source=P;” but I have the same error.

Last edited by zcarral; August 8, 2013 at 03:50.
zcarral is offline   Reply With Quote

Old   August 7, 2013, 12:55
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Pennsylvania, United States
Posts: 101
Rep Power: 6
adhiraj is on a distinguished road
I am not sure you can convert a double to a volScalarField. The latter is more than just an array of doubles.
If you want to assign a value to all elements of "source", you are better off using a "forAll" loop.
Line 61 does not flag an error because the operator[] on a volScalarField returns a scalar, and a scalar can be cast to double.
adhiraj is offline   Reply With Quote

Old   August 8, 2013, 03:50
Default
  #3
New Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 25
Rep Power: 4
zcarral is on a distinguished road
I need to define the variable "source". I also tried this text in line 57:


57 volScalarField source;


But I have the following error:


oFoam.C:57: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField()’
zcarral is offline   Reply With Quote

Old   August 8, 2013, 04:47
Default goal?
  #4
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 345
Rep Power: 10
romant is on a distinguished road
What is your goal?

One way to do this is to create a field with only ones inside and the multiply the field by the value from your double P.
__________________
~roman
romant is offline   Reply With Quote

Old   August 8, 2013, 06:20
Default
  #5
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
Also look into funkySetFields
Bernhard is offline   Reply With Quote

Old   August 8, 2013, 06:27
Default
  #6
New Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 25
Rep Power: 4
zcarral is on a distinguished road
Dear Romant, I agree that your idea is the solution. But I want to know if there is a more elegant form to convert a double to a volScalarField.

Dear Bernhard. FunkySetFields is a possibility. It has the inconvenience that it need to be installed.
zcarral is offline   Reply With Quote

Reply

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
New densitybased solver AeroFoam giulio_romanelli OpenFOAM Running, Solving & CFD 39 October 8, 2013 03:37
Continuing User Defined Real Gas Model issues aeroman FLUENT 2 October 22, 2010 16:28
Parallel User Defined Real Gas Model aeroman FLUENT 3 October 21, 2010 16:04
Missing math.h header Travis FLUENT 4 January 15, 2009 12:48
REAL GAS UDF brian FLUENT 6 September 11, 2006 09:23


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