|
[Sponsors] |
January 5, 2012, 12:19 |
how to change a volScalarField in bc?
|
#1 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
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 ); 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; } |
|
January 5, 2012, 13:40 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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 |
|
January 6, 2012, 09:34 |
|
#3 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
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"); I'm not really sure about this or in general how to directly call the scalarField from the bc in the solver.... |
|
January 6, 2012, 13:37 |
|
#4 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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") );
__________________
~~~ Follow me on twitter @DavidGaden |
|
January 10, 2012, 09:28 |
creating Field
|
#5 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
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_; ... 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_) {} 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 |
|
January 10, 2012, 12:33 |
|
#6 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
"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_; ... Code:
class myClass { // define myClass }; Code:
class myClass : public baseClass1, public baseClass2 { // define myClass };
__________________
~~~ Follow me on twitter @DavidGaden |
|
January 11, 2012, 08:09 |
misquote
|
#7 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
Sorry. You're right! I left something out in my quotation:
Code:
class abflussWehrDS : public fixedValueFvPatchVectorField { volScalarField sourceH_; word HName_; word HUName_; ... |
|
January 11, 2012, 14:38 |
|
#8 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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 |
|
January 19, 2012, 11:26 |
|
#9 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
I tried to to solve this problem by adding
Code:
fixedValueFvPatchScalarField any other solutions to my initial problem? or is there still a possibility to do it this way????? thanks in advance!!!! |
|
January 19, 2012, 11:38 |
|
#10 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
What are your errors?
__________________
~~~ Follow me on twitter @DavidGaden |
|
January 19, 2012, 12:09 |
|
#11 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
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] |
|
January 19, 2012, 17:13 |
|
#12 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
"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 |
|
January 20, 2012, 09:21 |
|
#13 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
I tried it by including
Code:
#include "fvPatchFields.H" #include "fixedValueFvPatchFields.H" Code:
class abflussWehrDS : public fixedValueFvPatchVectorField { // Private data word HName_; word HUName_; int sonderBw_; int USpatch_; volScalarField sourceH_; public: //- Runtime type information TypeName("abflussWehrDS"); .... 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 |
|
January 26, 2012, 11:05 |
|
#14 | |
Senior Member
Francois
Join Date: Jun 2010
Posts: 107
Rep Power: 21 |
Quote:
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 ) ); Code:
const IOList<scalar>& dbScalarList = mesh.thisDb().lookupObject< IOList<scalar> >("the_database_name_of_var"); scalarList your_scalar_list = dbScalarList; You would do this using the following (perfectly legal) C++ trick: Code:
const_cast<IOList<scalar>& >( dbScalarList ) = your_updated_scalar_list ; Kind regards, Francois |
||
January 26, 2012, 11:10 |
|
#15 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
Using const_cast is cheating!
__________________
~~~ Follow me on twitter @DavidGaden |
|
January 26, 2012, 14:42 |
|
#16 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
||
January 27, 2012, 11:32 |
|
#17 |
Senior Member
Francois
Join Date: Jun 2010
Posts: 107
Rep Power: 21 |
||
January 29, 2012, 10:25 |
Thanks!!
|
#18 |
New Member
Kathrin
Join Date: Nov 2011
Posts: 15
Rep Power: 15 |
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. |
|
January 31, 2012, 13:06 |
|
#19 |
Senior Member
Francois
Join Date: Jun 2010
Posts: 107
Rep Power: 21 |
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 ) ); Code:
// with dbVolScalarField retrieved earlier from your database using lookupObject<volScalarField>() const_cast<volScalarField& >( dbVolScalarField ) = your_updated_volScalarField ; Francois. |
|
January 31, 2012, 16:51 |
|
#20 |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
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))); } Just so you don't miss it , the key line is Code:
vectorField::operator= blah blah T. Last edited by tomislav_maric; January 31, 2012 at 17:01. Reason: upcast, downcast... |
|
|
|
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 |