|
[Sponsors] |
Type mismatch: Assigning a scalar to a Field<Type> inside templated BC code |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 23, 2016, 11:09 |
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 |
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; } Code:
template<class Type> class uniformJumpFvPatchField : public fixedJumpFvPatchField<Type> { protected: // Protected data //- "jump" table autoPtr<Function1<Type>> jumpTable_; Code:
template<class Type> class fixedJumpFvPatchField : public jumpCyclicFvPatchField<Type> { protected: // Protected data //- "jump" field Field<Type> jump_; 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; } 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. |
|
August 25, 2017, 15:06 |
|
#2 |
Senior Member
Peter Baskovich
Join Date: Jul 2014
Posts: 127
Rep Power: 12 |
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. |
|
August 28, 2017, 02:25 |
|
#3 |
New Member
Karl Lindqvist
Join Date: Jul 2012
Posts: 21
Rep Power: 14 |
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 |
|
|
|
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 |