|
[Sponsors] |
Any efficient way to set a field to ZERO or ONE without looping all cells? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 2, 2022, 02:25 |
Any efficient way to set a field to ZERO or ONE without looping all cells?
|
#1 |
Senior Member
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14 |
As the title says, without looping over all CFD cells, is there any way to set a scalar/vector field to a constant value?
For instance, if we want to reset some special Scalar/Vector volField to Zero at the beginning of every PISO loop, the straightforward method is: Code:
for (int cell_id=0; cell_id<Number_AllCells; cell_id++) { Scalar_volField [cell_id] = 0.0; Vector_volField [cell_id].x() = 0.0; Vector_volField [cell_id].y() = 0.0; Vector_volField [cell_id].z() = 0.0; } Code:
Scalar_volField = zeroField(); // oneField(); Vector_volField = zeroField(); // oneField(); |
|
February 2, 2022, 13:54 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
My first idea would be to look at the GeometricField header and see which assignment operators you find. Hint: around Lines 700 onwards you should find something. |
||
February 3, 2022, 00:53 |
|
#3 | |
Senior Member
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14 |
Quote:
Code:
myVolField = constVolField; Code:
// Member Operators // line 724 in GeometricField.H //- Return a const-reference to the dimensioned internal field // Useful in the formulation of source-terms for FV equations inline const Internal& operator()() const; void operator=(const GeometricField<Type, PatchField, GeoMesh>&); void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator=(const dimensioned<Type>&); void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator==(const dimensioned<Type>&); void operator+=(const GeometricField<Type, PatchField, GeoMesh>&); void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator-=(const GeometricField<Type, PatchField, GeoMesh>&); void operator-=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator*=(const GeometricField<scalar, PatchField, GeoMesh>&); void operator*=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&); void operator/=(const GeometricField<scalar, PatchField, GeoMesh>&); void operator/=(const tmp<GeometricField<scalar,PatchField,GeoMesh>>&); void operator+=(const dimensioned<Type>&); void operator-=(const dimensioned<Type>&); void operator*=(const dimensioned<scalar>&); void operator/=(const dimensioned<scalar>&); |
||
February 3, 2022, 13:11 |
|
#4 |
Senior Member
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 113
Rep Power: 5 |
Have you tried multiplying the field by 0? Then if you want to set it to one you can add one? I have done this a few times as a lazy way of initialising fields in post-processing tools.
|
|
February 3, 2022, 20:37 |
|
#5 |
Senior Member
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14 |
||
Tags |
fields, zerofield() |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Foam::error::PrintStack | almir | OpenFOAM Running, Solving & CFD | 92 | May 21, 2024 08:56 |
[surface handling] Decomposing Faces after Extrude2DMesh with autoPatch | JEBland | OpenFOAM Meshing & Mesh Conversion | 5 | December 6, 2021 08:28 |
overPimpleDyMFoam rotating airfoil startup problems | jantheron | OpenFOAM Running, Solving & CFD | 1 | May 20, 2020 05:55 |
[blockMesh] Create internal faces as patch in blockMesh | m.delta68 | OpenFOAM Meshing & Mesh Conversion | 14 | July 12, 2018 15:43 |
Ansys Licence Serve on Ubuntu 16.04 LTS | david.pasquale | ANSYS | 2 | January 20, 2017 12:52 |