|
[Sponsors] |
New BoundaryCondition: how to modify a single component of a field? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 26, 2012, 14:35 |
New BoundaryCondition: how to modify a single component of a field?
|
#1 |
New Member
Lucio Cardillo
Join Date: Apr 2012
Posts: 5
Rep Power: 14 |
hello,
I need to make for a simulation a new type of boundary condition. This is my first attempt of programming with openFoam and I'm able to realize a time varying boundary condition starting from oscillatingFixedValueFvPatchField file. As in oscillatingBC the field varies with time and it is great for a single component field, such as the pressure p. But if I want to vary only a single component of a velocity field for example, I didn't understand how I can do that. I Understood that the field class belongs from List class, and so I tried with a for cycle and edit one by one all the elements of the list (field), but if I try to reach the x() y() or z() method of the single element I get an error because only the vector class have these method.. so how I can reach this method and vary single component of element of the field list? best regards and sorry for my bad english Lucio |
|
April 26, 2012, 14:50 |
|
#2 |
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17 |
Hi Lucio
All BCs in OF are templated, which means they work for scalars, vectors and tensors in the same fashion. If you elaborate more on your problem, maybe you'll receive better answers! The cyclic BC will apply the same calculation to all elements of your variable (e.g. a Vector). If you need to make a BC that works only for one component of a vector, you may consider using codedFixedValue, groovyBC or change the patch from inside the solver. Regards, Hisham |
|
April 27, 2012, 13:00 |
|
#3 |
New Member
Lucio Cardillo
Join Date: Apr 2012
Posts: 5
Rep Power: 14 |
thank you very much for the reply! However I reach up a solution with this function in my new BC timeVaryingVelocityComponent
Code:
template<class Type> Field<Type> timeVaryingVelocityComponentFvPatchField<Type>::modRefValue() { Field<Type> copy_(refValue_); List<scalar> l_(refValue_.size()); direction d(component_); List< typename Field<Type>::cmptType> Comp_(copy_.component(d)); label k(searchMax()); for (label i=0; i<l_.size(); i++) { l_[i]=Comp_[i]*currentScale(Comp_[k]); } copy_.replace(d,l_); return copy_; } In this code I modified only the single component (indicated by the int value component_) and I leave untouched the other.. and finally the function searchMax that give the index of the field that points to biggest value between the single component field: Code:
template <class Type> label timeVaryingVelocityComponentFvPatchField<Type>::searchMax() { label maxIndex(0); direction d(component_); List< typename Field<Type>::cmptType > Comp_refValue_.component(d)); for (label i=0; i<refValue_.size(); i++) { if (Comp_[i]>=Comp_[maxIndex]) maxIndex=i; } return maxIndex; } critiques & suggestions are always welcome Best regards, Lucio |
|
April 28, 2012, 11:22 |
|
#4 |
New Member
Lucio Cardillo
Join Date: Apr 2012
Posts: 5
Rep Power: 14 |
Hello!
I don't know why, but for parallel application this construct works fine: Code:
template<class Type> Field<Type> timeVaryingVelocityComponentFvPatchField<Type>::modRefValue() { Field<Type> copy_(refValue_); List<scalar> l_(refValue_.size()); direction d(component_); List< typename Field<Type>::cmptType> Comp_(copy_.component(d)); label k(searchMax()); for (label i=0; i<l_.size(); i++) { l_[i]=Comp_[i]*currentScale(Comp_[k]); } copy_.replace(d,l_); return copy_; } but this other gives me always Fatal error from first iteration! Code:
template<class Type> Field<Type> timeVaryingVelocityComponentFvPatchField<Type>::modRefValue() { Field<Type> copy_(refValue_); List<scalar> l_(refValue_.size()); direction d(component_); List< typename Field<Type>::cmptType> Comp_(copy_.component(d)); label k(searchMax()); //************modified part************************\\ scalar curr_(currentScale(Comp_[k])); //************************************************\\ for (label i=0; i<l_.size(); i++) { //****************modified part**********************\\ l_[i]=Comp_[i]*curr_; //*************************************************\\ } copy_.replace(d,l_); return copy_; } can anybody give me some explanation? Regard, Lucio |
|
August 28, 2012, 17:48 |
|
#5 |
New Member
|
Standard C++ notes:
1- Make sure that the "currentScale(...)" you invoke returns a scalar 2- Try the parallelized "forAll(...,...)" instead of the classic "for(i=0;...;i++)" |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
Tangential component of gradient of scalar field at surface | tehache | OpenFOAM Running, Solving & CFD | 5 | July 4, 2013 08:13 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |
how 2 freeze 1 phase flow field & start lagrangian | KK | CFX | 5 | February 14, 2008 17:48 |
Diffusion component at inlet | Balaji | FLUENT | 2 | August 8, 2005 08:37 |