|
[Sponsors] | |||||
|
|
|
#1 |
|
Member
Join Date: Oct 2011
Posts: 37
Rep Power: 16 ![]() |
Hello together
First sorry for creating a new thread but I could not find what I was looking for. I'm creating a new boundary and the boundary should be build up as templated version so to make it usable for any kind of quantity. The problem now is that I would like to do a coordinate transform to the velocity. Therefore I need to grab the internal field like Field<Type> iField = this->internalField(); In a next step I wanted to create a vectorField if "Type" is vector if(pTraits<Type>::rank ==1) { Field<vector> myField = iField; } As you may probably already notice this want work since iField is templated so it can't be given to a vector field since the compiler doesn't know that my if-statement only allows the operation if Type==vector. Has anybody an idea how to circumvent this problem? Many thanks Peter |
|
|
|
|
|
|
|
|
#2 | |
|
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 41 ![]() ![]() |
Quote:
You are correct. Since things are templated, you would normally not like that. What you need is a template specialization for the type vector that implements what you want. If you haven't worked with this before, it may take you a few attempts to get it going. The important points:
From the UList.H: Code:
inline const T& operator[](const label) const; Code:
namespace Foam
{
// Template specialization for bool
template<>
inline const bool& Foam::UList<bool>::operator[](const label i) const
{
...
}
} // end of namespace Foam
// const element access
template<class T>
inline const T& Foam::UList<T>::operator[](const label i) const
{
...
}
In your particular case, you can either specialize the entire method for various vector, or factor it out as a private method. In either case, you can view the specialization as being a compile-time version of an 'if' or a 'switch'. I hope this helps you get going. |
||
|
|
|
||
![]() |
| Tags |
| convert, template, type, vector |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to set periodic boundary conditions | Ganesh | FLUENT | 15 | November 18, 2020 07:09 |
| cast vector to Type | jordi.muela | OpenFOAM Programming & Development | 0 | May 31, 2012 04:42 |
| UDF for wall slipping | HFLUENT | Fluent UDF and Scheme Programming | 0 | April 27, 2011 13:03 |
| Errors running allwmake in OpenFOAM141dev with WM_COMPILE_OPTION%3ddebug | unoder | OpenFOAM Installation | 11 | January 30, 2008 21:30 |