|
[Sponsors] |
April 15, 2016, 06:32 |
How to go through every element of a field?
|
#1 | |
New Member
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10 |
Hello Dear Foamers~!
In my project i want to define a complex source field. For example, I want solve the equation: Code:
volScalarField p; volScalarField sourceField; solve( fvm::laplacian( p ) == sourceField ) Quote:
1. one field of every cell center's position must be obtained, that can be achieved by: Code:
volVectorField centerPostions = mesh.C(); Code:
for(i = first_element_index, i <= last_element_index, i++) { sourceField.element(i) = sin( centerPosition.element(i).x() ) * ..... } I am open for every advices! Thanks very much! |
||
April 15, 2016, 07:52 |
One possible way?
|
#2 |
New Member
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10 |
As every field can be seen as UList<Type>, so it comes to me that if method inside the class template can help.
|
|
April 15, 2016, 08:29 |
|
#3 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30 |
You are looking "forAll" (search the forum for this keyword).
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
April 16, 2016, 03:40 |
Problem almost solved!
|
#4 | |
New Member
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10 |
Thank you very much for your response!
After searching and studying the threads of the forum with key word "forAll". I have got the basic understanding of the macro "forAll". What's more, I have developed my own "manual" method in order to scan a field: Code:
Foam::vector * i; Foam::label j = 0; volVectorField position = mesh.C(); Info << "\n the first method of scanning the field " << endl; for ( i = position.begin(); i <= position.end(); i++) { Info << "\n the cell " << j << "'s position is " << position[j] << endl; j++; if (j == 5) { break; } } Info<< "\n the second method of scanning the field " << endl; j = 0; forAll( position, elmtID ){ Info << "\n the cell " << elmtID << "'s position is " << position[elmtID] << endl; j++; if (j == 5) { break; } } Quote:
|
||
Tags |
programming, user code |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
funkySetBoundaryFields - Manipulation of existing field | jhertel | OpenFOAM Pre-Processing | 16 | May 18, 2020 07:32 |
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL | AndoniBM | OpenFOAM Running, Solving & CFD | 2 | March 25, 2015 19:44 |
Problems creating a volScalarField with expressionField function-object | zfaraday | OpenFOAM Running, Solving & CFD | 2 | January 12, 2015 08:49 |
New BoundaryCondition: how to modify a single component of a field? | look86 | OpenFOAM Programming & Development | 4 | August 28, 2012 17:48 |
Demagnetization field | jan0385 | ANSYS | 0 | April 12, 2012 10:09 |