CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Trying to integrate using snGrad(). Need some help (http://www.cfd-online.com/Forums/openfoam-programming-development/126513-trying-integrate-using-sngrad-need-some-help.html)

MechBoom November 18, 2013 12:12

Trying to integrate using snGrad(). Need some help
 
I am in desperate need of some help with a bit of code I'm trying to implement. I know what I need to do but so far I've been unable to code it properly! I've been struggling with this for almost 3 weeks now to no avail!! :mad:

So, here's my problem. I'm trying to find the corona current surrounding a wire in a duct. To do this I need to integrate over the surface of the wire. Inside of this integral I also need the surface normal vector of the E-field. Here's the code I have so far:

Code:

   
60    volVectorField E("E",-fvc::grad(phi)); //Solve For E-Field//
61   
62    //Calculating the Corona Current
63   
64    label patchID = mesh.boundaryMesh().findPatchID("wire");
65    const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
66    const surfaceScalarField dl = mesh.magSf();
67       
68    scalar coronaI = 0.0;   
69    forAll (cPatch, i)
70  {
71    coronaI += -rho*k*snGrad(E)[i]*dl.boundaryField()[patchID][i];
72    }

This code is inside the electrostaticFoam solver, this is the solver I'm modifying for my problem. Here is the current error I'm encountering:
Code:

Tester.C:71:44: error: no match for ‘operator[]’ in ‘Foam::fvc::snGrad(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = Foam::Vector<double>]()[i]’
I know that I'm not properly calling the snGrad() function but, I don't know how to do it the right way! I'm thinking that the coronaI needs to be a dimensioned scalar too, but who knows!! I'm so very frustrated with this problem right now.

This is a 2D problem by the way. So the magSf() should return my differential length of each cell.

Any help is very appreciated and much needed!!

Linse November 18, 2013 15:50

Trying to integrate using snGrad(). Need some help
 
Dear Terry,

1.) Could you please try to change the name of your thread to something more narrative about the problem? Ideally what solver you are modifying? Unfortunately by now many people ignore threads of which the name doesn't clearly state the problem.

2.) Could you please attach the error logs you received concerning the compilation of the code? "wmake code.C &> log.error" should do the trick...

3.) Unfortunately I do not know the coding in OF well enough for such questions...

Regards,
Bernhard

MechBoom November 18, 2013 18:19

Bernhard,

Thanks for your help, I've edited the post but I can't seem to change the visible title in the forum, so I just started a new thread. Hopefully, that's ok. I don't want to clog up the forum with uneeded posts!

wyldckat November 19, 2013 18:01

Greetings to all!

@MechBoom:
Quote:

Originally Posted by MechBoom (Post 462451)
Thanks for your help, I've edited the post but I can't seem to change the visible title in the forum, so I just started a new thread. Hopefully, that's ok. I don't want to clog up the forum with uneeded posts!

If you check the forum rules - http://www.cfd-online.com/Forums/misc.php?do=showrules - you'll find this one:
Quote:

6. Do not post the same message in more than one forum. If your message could be posted in several forums please pick the most relevant forum and post the message only there. If you have posted your question in the wrong place please contact a Forum Moderator to have it moved.
I've removed the excess posts/threads and moved the original one to the programming sub-forum.


As for the original question, a few quick suggestions:
Best regards,
Bruno


All times are GMT -4. The time now is 16:29.