|
[Sponsors] |
August 7, 2013, 10:39 |
converting double to volScalarField
|
#1 |
Member
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14 |
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. |
|
August 7, 2013, 12:55 |
|
#2 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
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. |
|
August 8, 2013, 03:50 |
|
#3 |
Member
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14 |
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()’ |
|
August 8, 2013, 04:47 |
goal?
|
#4 |
Senior Member
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 21 |
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 |
|
August 8, 2013, 06:20 |
|
#5 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Also look into funkySetFields
|
|
August 8, 2013, 06:27 |
|
#6 |
Member
Zacarias Carral
Join Date: Sep 2012
Posts: 35
Rep Power: 14 |
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. |
|
November 8, 2017, 11:54 |
|
#7 |
New Member
Joanne
Join Date: Aug 2017
Location: Ireland
Posts: 6
Rep Power: 9 |
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? |
|
|
|
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 |