CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to change a volScalarField in bc? (http://www.cfd-online.com/Forums/openfoam-programming-development/95866-how-change-volscalarfield-bc.html)

Katl January 5, 2012 12:19

how to change a volScalarField in bc?
 
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...

marupio January 5, 2012 13:40

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.

Katl January 6, 2012 09:34

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....

marupio January 6, 2012 13:37

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.

Katl January 10, 2012 09:28

creating Field
 
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.

marupio January 10, 2012 12:33

"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?

Katl January 11, 2012 08:09

misquote
 
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.

marupio January 11, 2012 14:38

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.

Katl January 19, 2012 11:26

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!!!!

marupio January 19, 2012 11:38

What are your errors?

Katl January 19, 2012 12:09

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]


marupio January 19, 2012 17:13

"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.

Katl January 20, 2012 09:21

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?

Fransje January 26, 2012 11:05

Quote:

Originally Posted by marupio (Post 338029)
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

marupio January 26, 2012 11:10

Using const_cast is cheating!

gschaider January 26, 2012 14:42

Quote:

Originally Posted by marupio (Post 341309)
Using const_cast is cheating!

"The first rule of the const_cast-club is: 'Don't talk about the const_cast!'"

Fransje January 27, 2012 11:32

Quote:

Originally Posted by gschaider (Post 341348)
"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! :)

Katl January 29, 2012 10:25

Thanks!!
 
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.

Fransje January 31, 2012 13:06

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.

tomislav_maric January 31, 2012 16:51

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.


All times are GMT -4. The time now is 08:49.