converting double to volScalarField
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. |
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. |
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()’ |
goal?
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. |
Also look into funkySetFields
|
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. |
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? |
All times are GMT -4. The time now is 11:04. |