CFD Online URL
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

how to change a volScalarField in bc?

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

Like Tree6Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   January 5, 2012, 12:19
Default how to change a volScalarField in bc?
  #1
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
I need to add a source term in the time loop, which is calculated in one of my boundary conditions.

First I defined the following field in createFields.H:
Code:
 Info<< "Creating field sourceH\n" << endl;
    volScalarField sourceH
    (
        IOobject
        (
            "sourceH",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
         Hclip/dim_s*0
    );
It is set to zero by "Hclip/dim_s*0" in the beginning and should be changed/updated in a specific boundary condition.

But how can I change the values of the field in the bc???

I tried the following:
Code:
scalarField sourceH = patch().lookupPatchField<volScalarField, scalar>("sourceH").patchInternalField();
scalar groundArea = 1.0; 
scalarField srcH = (HU.boundaryField()[patchNr]&n)/groundArea;
scalar cellSource = (gSum(srcH))/patch().size();
 for (int celli = 0; celli <= patch().size(); celli++) 
      {
       sourceH[celli]=cellSource;
      }
But "sourceH" is still zero...
Katl is offline   Reply With Quote

Old   January 5, 2012, 13:40
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
This type of issue has come up a few times before. The problem is access: the boundary condition only has const access to anything it looks up through the objectRegistry, and private data it creates cannot be accessed at the top level because the solver uses fvPatchField as an interface.

Does your solver need to change it? If not, the solution is fairly simple. Instead of creating the source term at the top level, give it to your custom bc. Then use objectRegistry::lookupObject to find it in your solver.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 6, 2012, 09:34
Default
  #3
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
Thanks David for your explanations!
The solver doesn't have change the scalarField, but just adding it as a source term.
To make sure I got you right:
Did you mean to calculate a scalarField sourceH in my boundary condition and the call it in the solver by something like:
Code:
const GeometricField<scalar, fvPatchField, volMesh>& Hquelle = objectRegistry::lookupObject<GeometricField<scalar, fvPatchField, volMesh> >("sourceH");
and add Hquelle as the source term?

I'm not really sure about this or in general how to directly call the scalarField from the bc in the solver....
Katl is offline   Reply With Quote

Old   January 6, 2012, 13:37
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
Very close. Instead of objectRegistry::lookupObject... use the name of the objectRegistry sourceH is registered to... you'll probably put it in the mesh, just like nearly everything else:

Code:
const volScalarField& Hquelle
(
    mesh.lookupObject<volScalarField>("sourceH")
);
And you have to make sure that your boundary condition has already created this sourceH object before the solver tries looking it up. So, make sourceH a member of your custom boundary condition, and initialize (to zero) it in all of the constructors.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 10, 2012, 09:28
Default creating Field
  #5
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
I have still problems with creating the volScalarField in my BC:
I tried it like this:

in the header file:
Code:
class abflussWehrDS
:
public
{
volScalarField sourceH_;
...
which gives me an error, that the field sourceH has an incomplete type

in the .C file:
Code:
Foam::
abflussWehrDS::
abflussWehrDS
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(p, iF),
    HName_("H"),
    HUName_("HU"),
    sourceH_
(
  IOobject
 (
   "sourceH",
   runTime_.timeName(),
   mesh,
   IOobject::NO_READ,
   IOobject::AUTO_WRITE
  ),
    mesh,
    dimensionedScalar("zero", dimensionSet(0,1,-1,0,0,0,0), 0.0),
    "abflussWehrDS"
)
{}
Foam::
abflussWehrDS::
abflussWehrDS
(
    const abflussWehrDS& ptf,
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
    HName_(ptf.HName_),
    HUName_(ptf.HUName_),
    sonderBw_(ptf.sonderBw_),
    USpatch_(ptf.USpatch_)
    //sourceH_(ptf.sourceH_)
{}


Foam::
abflussWehrDS::
abflussWehrDS
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchField<vector>(p, iF, dict),
    HName_("H"),
    HUName_("HU"),
    sonderBw_(readScalar(dict.lookup("sonderBw"))),
    USpatch_(readScalar(dict.lookup("USpatch")))
//    sourceH_("sourceH")
{

    if (dict.found("H"))
    {
        dict.lookup("H") >> HName_;
    }
    if (dict.found("HU"))
    {
        dict.lookup("HU") >> HUName_;
    }
    if (dict.found("sourceH"))
    {
        dict.lookup("sourceH") >> sourceH_;
    }
}

Foam::
abflussWehrDS::
abflussWehrDS
(
    const abflussWehrDS& ptf
)
:
    fixedValueFvPatchField<vector>(ptf),
    HName_(ptf.HName_),
    HUName_(ptf.HUName_),
    sourceH_(ptf.sourceH_)
{}


Foam::
abflussWehrDS::
abflussWehrDS
(
    const abflussWehrDS& ptf,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(ptf, iF),
    HName_(ptf.HName_),
    HUName_(ptf.HUName_),
    sourceH_(ptf.sourceH_)
{}
giving me the following errors:
Code:
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:52: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:57: error: ‘runTime_’ was not declared in this scope
abflussWehrDS.C:58: error: ‘mesh’ was not declared in this scope
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::fvPatchFieldMapper&)’:
abflussWehrDS.C:84: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:84: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::dictionary&)’:
abflussWehrDS.C:102: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:115: error: ‘sourceH_’ was not declared in this scope
abflussWehrDS.C: In copy constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&)’:
abflussWehrDS.C:131: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:131: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:148: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:148: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In member function ‘virtual void Foam::abflussWehrDS::updateCoeffs()’:
abflussWehrDS.C:251: error: ‘sourceH’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/abflussWehrDS.o] Fehler 1
I guess I have to include some files. But if I include createTime.H and createMesh.H it still wouldn't work.
Katl is offline   Reply With Quote

Old   January 10, 2012, 12:33
Default
  #6
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
"does not have any field named sourceH_"

This is your first problem. It looks like your header file has problems... but you have only quoted a portion of it.

Code:
class abflussWehrDS
:
public <<-- public what?
{
volScalarField sourceH_;
...
It looks like you want to define what objects it inherits, but left them out. Use either:

Code:
class myClass
{
    // define myClass
};
or
Code:
class myClass
:
    public baseClass1,
    public baseClass2
{
    // define myClass
};
... or did you misquote your code?
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 11, 2012, 08:09
Default misquote
  #7
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
Sorry. You're right! I left something out in my quotation:


Code:
class abflussWehrDS
:
    public fixedValueFvPatchVectorField    
{
    volScalarField sourceH_;
    word HName_;
    word HUName_;
...
It worked fine with all the other variables, like HName_, that's why I don't understand that it has a problem with the volScalarField.
Katl is offline   Reply With Quote

Old   January 11, 2012, 14:38
Default
  #8
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
There is probably an error where it complains in the header file that it doesn't know what volScalarField means. This could be an #include problem, or circular dependency.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 19, 2012, 11:26
Default
  #9
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
I tried to to solve this problem by adding
Code:
fixedValueFvPatchScalarField
as a second baseClass, like David mentioned. But all I got was an enormous amount of errors....

any other solutions to my initial problem? or is there still a possibility to do it this way?????

thanks in advance!!!!
Katl is offline   Reply With Quote

Old   January 19, 2012, 11:38
Default
  #10
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
What are your errors?
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 19, 2012, 12:09
Default
  #11
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
HTML Code:
abflussWehrDS.H:85: error: field ‘sourceH_’ has incomplete type
abflussWehrDS.H:131: error: invalid covariant return type for ‘virtual Foam::tmp<Foam::fvPatchField<Foam::Vector<double> > > Foam::abflussWehrDS::clone() const’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.H:96: error:   overriding ‘Foam::tmp<Foam::fvPatchField<Type> > Foam::fixedValueFvPatchField<Type>::clone() const [with Type = double]’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:54: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:59: error: request for member ‘db’ is ambiguous
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fvPatchField.C:158: error: candidates are: const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fvPatchField.C:158: error:                 const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const [with Type = Foam::Vector<double>]
abflussWehrDS.C:60: error: request for member ‘db’ is ambiguous
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fvPatchField.C:158: error: candidates are: const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fvPatchField.C:158: error:                 const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const [with Type = Foam::Vector<double>]
abflussWehrDS.C:64: error: ‘mesh’ was not declared in this scope
abflussWehrDS.C:67: error: no matching function for call to ‘Foam::fixedValueFvPatchField<double>::fixedValueFvPatchField()’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:87: note: candidates are: Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:76: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:66: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::fvPatchFieldMapper&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:53: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:41: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::fvPatchFieldMapper&)’:
abflussWehrDS.C:86: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:86: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C:86: error: no matching function for call to ‘Foam::fixedValueFvPatchField<double>::fixedValueFvPatchField()’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:87: note: candidates are: Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:76: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:66: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::fvPatchFieldMapper&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:53: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:41: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::dictionary&)’:
abflussWehrDS.C:104: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:105: error: expected identifier before ‘{’ token
abflussWehrDS.C:105: error: expected `(' before ‘{’ token
abflussWehrDS.C:105: error: no matching function for call to ‘Foam::fixedValueFvPatchField<double>::fixedValueFvPatchField()’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:87: note: candidates are: Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:76: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:66: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::fvPatchFieldMapper&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:53: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:41: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
abflussWehrDS.C:117: error: ‘sourceH_’ was not declared in this scope
abflussWehrDS.C: In copy constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&)’:
abflussWehrDS.C:133: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:133: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C:126: warning: base class ‘class Foam::fixedValueFvPatchField<double>’ should be explicitly initialized in the copy constructor
abflussWehrDS.C:133: error: no matching function for call to ‘Foam::fixedValueFvPatchField<double>::fixedValueFvPatchField()’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:87: note: candidates are: Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:76: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:66: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::fvPatchFieldMapper&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:53: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:41: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:150: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:150: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C:150: error: no matching function for call to ‘Foam::fixedValueFvPatchField<double>::fixedValueFvPatchField()’
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:87: note: candidates are: Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:76: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:66: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fixedValueFvPatchField<Type>&, const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::fvPatchFieldMapper&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:53: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
/home/h17_2/student2/OpenFOAM/OpenFOAM-1.5/src/finiteVolume/lnInclude/fixedValueFvPatchField.C:41: note:                 Foam::fixedValueFvPatchField<Type>::fixedValueFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&) [with Type = double]
Katl is offline   Reply With Quote

Old   January 19, 2012, 17:13
Default
  #12
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
"abflussWehrDS.H:85: error: field ‘sourceH_’ has incomplete type"

This is an #include problem. Either you didn't include the correct files that gives you the full definition of volScalarField, or you have circular dependency among your include files. The first option is likely, as volScalarField needs at least two files - the file that gives you the typedef volScalarField, and the one with the full definition.

I strongly dislike these kinds of problems.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 20, 2012, 09:21
Default
  #13
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
I tried it by including
Code:
#include "fvPatchFields.H"
#include "fixedValueFvPatchFields.H"
and with:
Code:
class abflussWehrDS
:
    public fixedValueFvPatchVectorField  
{
    // Private data

    word HName_;
    word HUName_;
    int sonderBw_;
    int USpatch_;
    volScalarField sourceH_;
    
public:

   //- Runtime type information
   TypeName("abflussWehrDS");
....
But the problem is still not solved:
Code:
abflussWehrDS.H:84: error: field ‘sourceH_’ has incomplete type
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:54: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::fvPatchFieldMapper&)’:
abflussWehrDS.C:86: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:86: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::fvPatch&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&, const Foam::dictionary&)’:
abflussWehrDS.C:104: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:117: error: ‘sourceH_’ was not declared in this scope
abflussWehrDS.C: In copy constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&)’:
abflussWehrDS.C:133: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:133: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In constructor ‘Foam::abflussWehrDS::abflussWehrDS(const Foam::abflussWehrDS&, const Foam::DimensionedField<Foam::Vector<double>, Foam::volMesh>&)’:
abflussWehrDS.C:150: error: class ‘Foam::abflussWehrDS’ does not have any field named ‘sourceH_’
abflussWehrDS.C:150: error: ‘const class Foam::abflussWehrDS’ has no member named ‘sourceH_’
abflussWehrDS.C: In member function ‘virtual void Foam::abflussWehrDS::updateCoeffs()’:
abflussWehrDS.C:251: error: ‘sourceH’ was not declared in this scope
abflussWehrDS.C:253: error: ‘sourceH’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/abflussWehrDS.o] Fehler 1
How can I find out which files are missing?
Katl is offline   Reply With Quote

Old   January 26, 2012, 11:05
Default
  #14
Senior Member
 
Francois
Join Date: Jun 2010
Location: Netherlands
Posts: 102
Rep Power: 6
Fransje is on a distinguished road
Quote:
Originally Posted by marupio View Post
This type of issue has come up a few times before. The problem is access: the boundary condition only has const access to anything it looks up through the objectRegistry, and private data it creates cannot be accessed at the top level because the solver uses fvPatchField as an interface.

Does your solver need to change it? If not, the solution is fairly simple. Instead of creating the source term at the top level, give it to your custom bc. Then use objectRegistry::lookupObject to find it in your solver.
Dear Kathrin, dear David,

The problem of creating the source term / a variable in the boundary condition for use in the main solver, is that if you don't add it correctly to the database, it will be deleted out of it as soon as the fvPatchField is destroyed. This means, as soon as you exit the boundary condition code.

Anyways, the solution is quite simple. Let's say you want to store a scalarList in the database, for use anywhere (in the bc, the solver, etc) you would do:

Code:
scalarList your_scalar_list;

mesh.thisDb().store
(
    new IOList<scalar>
    (
        IOobject
        (
            "the_database_name_of_var",
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        your_scalar_list
    )
);
Checking it out will be done in the usual way:
Code:
const IOList<scalar>& dbScalarList
                = mesh.thisDb().lookupObject< IOList<scalar> >("the_database_name_of_var");

scalarList your_scalar_list = dbScalarList;
You could also use const scalarList& straight away as type, but the reason I use an IOList<scalar> is for the next step. Because once you've use your variable and updated it, you can now update it's value in the database (!!! This, although it theoretically is of const type, hence not modifiable !!!).
You would do this using the following (perfectly legal) C++ trick:
Code:
const_cast<IOList<scalar>& >( dbScalarList ) = your_updated_scalar_list ;
I hope this helps!

Kind regards,

Francois
caduqued, marupio and vitors like this.
Fransje is offline   Reply With Quote

Old   January 26, 2012, 11:10
Default
  #15
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 396
Rep Power: 11
marupio is on a distinguished road
Using const_cast is cheating!
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 26, 2012, 14:42
Default
  #16
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by marupio View Post
Using const_cast is cheating!
"The first rule of the const_cast-club is: 'Don't talk about the const_cast!'"
gschaider is offline   Reply With Quote

Old   January 27, 2012, 11:32
Default
  #17
Senior Member
 
Francois
Join Date: Jun 2010
Location: Netherlands
Posts: 102
Rep Power: 6
Fransje is on a distinguished road
Quote:
Originally Posted by gschaider View Post
"The first rule of the const_cast-club is: 'Don't talk about the const_cast!'"
He he he!
Cheating..? Perhaps.. But most importantly: It works!
caduqued and Katl like this.
Fransje is offline   Reply With Quote

Old   January 29, 2012, 10:25
Default Thanks!!
  #18
New Member
 
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 5
Katl is on a distinguished road
Thank you all for your help. The const_cast works

But I have one more question:
Is it also possible to do this for a volScalarField. I could only find IOField<scalar>. Or is it possible to convert a scalarField into a volScalarField, which would also be sufficient.
Katl is offline   Reply With Quote

Old   January 31, 2012, 13:06
Smile
  #19
Senior Member
 
Francois
Join Date: Jun 2010
Location: Netherlands
Posts: 102
Rep Power: 6
Fransje is on a distinguished road
Well, actually, it has been a while since I implemented this hack, but if I recall properly, the store() function can store any pointer to an IOobject.

So, since your volScalarField is already an IOobject, what you are trying to do should be very simple to do:
Code:
// with your_volScalarField created as it normally would be

mesh.thisDb().store
(
    new volScalarField
    (
        your_volScalarField
    )
);
And obviously you would do your const_cast with:
Code:
// with dbVolScalarField retrieved earlier from your database using lookupObject<volScalarField>()

const_cast<volScalarField& >( dbVolScalarField ) = your_updated_volScalarField ;
Kind regards,

Francois.
Katl likes this.
Fransje is offline   Reply With Quote

Old   January 31, 2012, 16:51
Default
  #20
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 251
Blog Entries: 5
Rep Power: 10
tomislav_maric is on a distinguished road
From

OpenFOAM-1.6-ext/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity

comes:

Code:
void parabolicVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    // Get range and orientation
    boundBox bb(patch().patch().localPoints(), true);

    vector ctr = 0.5*(bb.max() + bb.min());

    const vectorField& c = patch().Cf();

    // Calculate local 1-D coordinate for the parabolic profile
    scalarField coord = 2*((c - ctr) & y_)/((bb.max() - bb.min()) & y_);

    vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord)));
}
This is called upcasting in C++: stripping the inherited object to the base class. All bcs are hidden *fields. No need for *_cast magic.

Just so you don't miss it , the key line is
Code:
vectorField::operator=  blah blah
, this converts "this" (the class, in this case parabolicBlah...) to a vectorField.

T.

Last edited by tomislav_maric; January 31, 2012 at 17:01. Reason: upcast, downcast...
tomislav_maric 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
Solid/liquid phase change fabian_roesler OpenFOAM 10 December 24, 2012 07:37
Change cell zone index/thread during simulation neilduffy1024 FLUENT 0 January 17, 2011 10:40
Is there a way to change the name a volScalarField liu OpenFOAM Running, Solving & CFD 2 October 18, 2007 18:49
no enthalpy change across the momentum source Atit Koonsrisuk CFX 2 December 19, 2005 03:33
Multicomponent fluid Andrea CFX 2 October 11, 2004 06:12


All times are GMT -4. The time now is 09:39.