CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Unable to read all cell centers in OF v2.4 (https://www.cfd-online.com/Forums/openfoam-pre-processing/220169-unable-read-all-cell-centers-v2-4-a.html)

Saketh Bharadwaj August 27, 2019 10:00

Unable to read all cell centers in OF v2.4
 
Hi,


In my user-defined energy source file, I am trying to read the cellCenters of the mesh using the command "const vectorField& C = mesh_.C().internalField();" As next step I want to check if the cell center is in particular location. If yes I will introduce energy source into that cell. But for some reason that command does not function properly. It gives only 490 cell center points when I have 6174 points. It would of great help for me if you can identify the issue. Thank you.



sourceRegionNew.clear();
sourceRegionNew.set(new cellSet(mesh(), "sourceRegionRefine", IOobject::NO_READ, IOobject::AUTO_WRITE));
scalar cur_time = mesh().time().value();

if (cur_time <= 5e-8) {

const scalarField& V = mesh_.V();
//const vectorField& C = mesh_.C().internalField();
const volVectorField& C = mesh_.C();

scalarField& hSource = eqn.source();

scalar len = 0.00025;

scalar W_pm = 1.0*s_efficiency;
scalar power = W_pm*len;
scalarList power_actual(1, 0.0);
scalarList total_volume(1, 0.0);
scalarList x_max(1, 0.0);
scalar E = 0.000017;
scalar L_s = 0.0005;
scalar r_0 = 0.00005;
scalar r_02 = r_0 * r_0;
scalar preExpConst = E/L_s/r_02/M_PI;

forAll(C, i) {
vector s_off = C[i];
scalar x = s_off.x();
Info << PV(s_off) << endl;

if ((x > 0.0003) && (x < 0)) {
Info << "offset X " << endl;
vector s_off1 = C[i] - s_origin;
scalar r2 = s_off1.x()*s_off1.x() + s_off1.y()*s_off1.y() + s_off1.z()*s_off1.z();
sourceRegionNew().set(i);
Info << "3 directions checked and source found" << endl;

scalar cellPow = W_pm*V[i]*preExpConst*exp(-1*pow((sqrt(r2)/r_0),8))/cur_time;
Info << "calculating cellPow and preExpConst " << PV(cellPow) << PV(preExpConst) << endl;
hSource[i] -= cellPow;

power_actual[0] += cellPow;
total_volume[0] += V[i];
if (s_off.x() > x_max[0])
x_max[0] = s_off.x();
}
}

}


All times are GMT -4. The time now is 10:37.