CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Type mismatch: Assigning a scalar to a Field<Type> inside templated BC code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 23, 2016, 11:09
Default Type mismatch: Assigning a scalar to a Field<Type> inside templated BC code
  #1
New Member
 
Karl Lindqvist
Join Date: Jul 2012
Posts: 21
Rep Power: 14
karlli is on a distinguished road
Dear all,
I am trying to implement a custom boundary condition based on the uniformJumpFvPatchField class. This is a cyclic boundary condition that applies a uniform (but possibly time-varying) jump across the cyclic patch pair. I want to assign my own jump value from inside the code, rather than from a BC dict, but have run into type conversion (?) problems.

Background:
Typical uniformJump usage:

Code:
    cyc_inlet
    {
        type            uniformJump;
        patchType       cyclic;
        jumpTable       constant -10;
        value           uniform 310;
    }
The uniformJump BC is derived from fixedJump, where the (time varying) jump is stored in a table (in uniformJumpFvPatchField.H):


Code:
template<class Type>
class uniformJumpFvPatchField
:
    public fixedJumpFvPatchField<Type>
{

protected:

    // Protected data

        //- "jump" table
        autoPtr<Function1<Type>> jumpTable_;
The jump itself is a field associated with the patch, which is inherited from the fixedJumpFvPatchField class:


Code:
template<class Type>
class fixedJumpFvPatchField
:
    public jumpCyclicFvPatchField<Type>
{

protected:

    // Protected data

        //- "jump" field
        Field<Type> jump_;
My attempt:
As a starting point for my custom BC I want to assign a scalar value from inside the code as the jump value, instead of the value given by the jumpTable. Later, this scalar will depend on time-varying computations on the patch. My attempt so far (original code commented) is:

Code:
template<class Type>
void Foam::bulkTempFvPatchField<Type>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    if (this->cyclicPatch().owner())
    {
//        this->jump_ = jumpTable_->value(this->db().time().value());
        
        scalar targetJump(400);
        Field<scalar> myJump(this->patch().size(),targetJump);
        
        this->jump_ = myJump;
    }
The idea was to create a scalar, assign it uniformly to a field, and then apply that field to jump_ (which also is of the Field type). In compiling, I run into the following error:

Code:
 error: no match for ‘operator=’ (operand types are ‘Foam::Field<Foam::Tensor<double> >’ and ‘const Foam::Field<double>’)
         this->jump_ = myJump;



Question:
I assume the error is related to the fact that the class is templated, and therefore need to work with all possible Type:s of Field. Is it possible to implement workaround where jump_ is set to an empty (or zero) Field for all Type:s except for Type being scalar? I have not been able to find the right C++ way to do this.
As an alternative, is there any way to redefine the class to only be a scalar boundary condition, despite the base class (fixedJumpFvPatchField) being templated? I have tried commenting out all template<class Type> lines and replacing Type with scalar, to no avail. The compiler then complains that the new class is not a template.

I realize this is more of a general C++ question rather than a specific OpenFOAM one, but I would still be useful to resolve it on this forum. I have not found any similar threads here so far.

Best regards,
Karl

EDIT: It IS possible to compile the BC as a scalar patch field by commenting out the following functions in the forward declaration files. This does however not solve my problem, since I then cannot use it (why?) on a cyclic patch.
makePatchFields(myBC);
template<class Type> class myBCFvPatchField;
makePatchTypeFieldTypedefs(myBC);

Last edited by karlli; September 23, 2016 at 12:16.
karlli is offline   Reply With Quote

Old   August 25, 2017, 15:06
Default
  #2
Senior Member
 
Peter Baskovich
Join Date: Jul 2014
Posts: 127
Rep Power: 12
pete20r2 is on a distinguished road
Hi karlii,
Did you ever get anywhere with this?
I am trying to modify uniformJump to maintain an average value, if you got these first steps working that would be cool.
pete20r2 is offline   Reply With Quote

Old   August 28, 2017, 02:25
Default
  #3
New Member
 
Karl Lindqvist
Join Date: Jul 2012
Posts: 21
Rep Power: 14
karlli is on a distinguished road
Peter,
Thank you for reminding me of this thread! I never managed to modify the cyclic boundary condition, but I have had good experiences with using/modifying the mapped and mappedField boundary conditions. They can be used to emulate a cyclic condition and have an option to set the area average value after mapping.

Regards,
Karl
karlli is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating point exception error lpz_michele OpenFOAM Running, Solving & CFD 53 October 19, 2015 03:50
Error during initialization of "rhoSimpleFoam" kornickel OpenFOAM Running, Solving & CFD 8 September 17, 2013 06:37
[swak4Foam] Air Conditioned room groovyBC Sebaj OpenFOAM Community Contributions 7 October 31, 2012 15:16
singularity? mihaipruna OpenFOAM Running, Solving & CFD 5 April 24, 2012 18:18
meshing F1 front wing Steve FLUENT 0 April 17, 2003 13:37


All times are GMT -4. The time now is 02:56.