Type mismatch: Assigning a scalar to a Field<Type> inside templated BC code
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 Code:
template<class Type> Code:
template<class Type> 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> Code:
error: no match for ‘operator=’ (operand types are ‘Foam::Field<Foam::Tensor<double> >’ and ‘const Foam::Field<double>’) 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); |
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. |
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 |
All times are GMT -4. The time now is 01:25. |