|
[Sponsors] |
One dimensional array in OF21(Segmentation fault (core dumped)) |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 195
Rep Power: 5 ![]() |
Hello all
I am defining a one dimensional parameter which has 2 million elements; Code:
int nCounter = U.size(); Info << "1" << endl; scalar AAAA[nCounter]; for(int i=0; i<nCounter; i++) { AAAA[i] = 0;} Code:
1 Segmentation fault (core dumped) |
|
![]() |
![]() |
![]() |
![]() |
#2 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 195
Rep Power: 5 ![]() |
I afraid that maybe i counter goes beyond the limits so I change it to
Code:
for(int i=1 i<100; i++) { AAAA[i] = 0;} Thanks, Farzad Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,554
Rep Power: 36 ![]() ![]() |
I don't understand the source of your error, but there is no reason to be using raw C arrays instead of an OpenFOAM list or even a std vector. Give the following a try:
Code:
scalarField AAA(U.size()); for (label i=0; i < AAA.size(); ++i) { AAA[i] = 0; } Code:
scalarField AAA(U.size(), Zero); |
|
![]() |
![]() |
![]() |
![]() |
#4 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 195
Rep Power: 5 ![]() |
Thanks a lot for your advice. I did it like this as you said and it works;
Code:
int nCounter = U.size(); scalarField AAA(nCounter); and since I need it to set zero every time step, I set it zero like this every time step; Code:
for(int i=0; i<nCounter; i++) {AAA[i] = 0;} Thanks, Farzad Quote:
|
||
![]() |
![]() |
![]() |
![]() |
#5 | |
Member
Join Date: Jan 2022
Location: Germany
Posts: 70
Rep Power: 3 ![]() |
Quote:
You can either use the vectorized method to make the for loop obsolete (but I think the compiler automatically using SIMD and might be that an overloaded operator[] will prohibit this operation) or I know for the GeometricField<T> class there is an overloaded operator= which sets the whole Field with a particular value. Since GeometricField is inhereting from Field class (if you go for Field<scalar>) I think there should be something similiar Code:
AAA[:] = 0 //vectorized // works at least for GeometricField<T> AAA = dimensionedScalar(dimless, 0.0) //sets .ref and .boundaryFieldRed to 0 |
||
![]() |
![]() |
![]() |
Tags |
array, error, fault, of21, segmentation |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] Paraview segmentation fault core dumped | GLfast80 | ParaView | 0 | March 13, 2021 12:53 |
Segmentation fault (core dumped) | prashantgoel | CONVERGE | 2 | May 26, 2020 12:48 |
SU2-7.0.1 on ubuntu 18.04 | hyunko | SU2 Installation | 7 | March 16, 2020 04:37 |
Segmentation fault (core dumped) | Sugajen | OpenFOAM Running, Solving & CFD | 1 | August 2, 2017 12:06 |
solving a conduction problem in FLUENT using UDF | Avin2407 | Fluent UDF and Scheme Programming | 1 | March 13, 2015 02:02 |