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

converting double to volScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 7, 2013, 10:39
Default converting double to volScalarField
  #1
Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14
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: Karnataka, India
Posts: 187
Rep Power: 16
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
Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14
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: Eindhoven, NL
Posts: 374
Rep Power: 21
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: 22
Bernhard is on a distinguished road
Also look into funkySetFields
Bernhard is offline   Reply With Quote

Old   August 8, 2013, 06:27
Default
  #6
Member
 
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14
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

Old   November 8, 2017, 11:54
Default
  #7
New Member
 
Joanne
Join Date: Aug 2017
Location: Ireland
Posts: 6
Rep Power: 9
Joanne is on a distinguished road
Has anyone ever found a solution to this?

I want to define a field parameter that varies with time but using a double (runTime.value()) to calculate a volScalarField is proving to be problematic.

Any advice?
Joanne is offline   Reply With Quote

Reply


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
Continuing User Defined Real Gas Model issues aeroman FLUENT 6 April 8, 2016 04:34
New densitybased solver AeroFoam giulio_romanelli OpenFOAM Running, Solving & CFD 48 January 15, 2016 09:20
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 07:09
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 22:42.