Using source term in OpenFOAM
Hi,
I am new to CFD and OpenFOAM. I am trying to learn OpenFOAM and creating a simple problem and solve it using OpenFOAM. I would like to solve a steadystate 2d poisson problem, similar to Laplacian(U) = 50 * (x + y) where x and y are the coordinates of cell centers. I am not sure how to represent the source term in the OpenFOAM program. I have represented this equation in my solver application as Code:
volScalarField x = U.mesh().C() & vector(1,0,0); "note: no known conversion for argument 1 from ‘Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > >’ to ‘const Foam::instant&’" What is the right way to specify the source terms in the equation? Thanks in advance. 
Hi! and welcome on board ;)
your first error is obvious : You add x and y which are scalarFields whereas laplacian(U) is a vectorField ! You should define x and y as volVectorField ! Best, Cyp 
Cyp,
Thanks a lot for the reply.. I have modified the problem to convert the scalar to vector. Code:
volScalarField x = U.mesh().C() & vector(1,0,0); But, if I try to modify the source term to contain exponential, it compiles correctly, but fails to run with the following error: Code:
fvVectorMatrix UEqn Code:
> FOAM FATAL ERROR: Also, is the above method the right way to compute the source term for the equation, or are there any better ways to compute and pass it to the equation? Thank you. 
are you sure about your differential equation ? in my opinion, you have something wrong. indeed, the inside of exponential must be unitless! In the other side, your source term ought to have the same dimension than laplacian(U).

Cyp,
My governing eqn. is a second order pde of the form Laplacian(phi) = exp(fifty * (x + y)) where, x and y are the coordinates of the points on the 2D plate. x and y are actually dimensionless quantities I have used the following operations to extract these coordinates, which returns me a dimensional quantity in meters. Code:
volScalarField x = U.mesh().C() & vector(1,0,0); Thank you 
Quote:

Thanks Mirko.. taking the fifty as inverse meters worked. :)

Quote:
Would it be possible for you to package and post the solver files? I promise not to criticize the coding style and/or lack of comments;) 
1 Attachment(s)
Sure..
I have attached the solver files.. I am completely new to OpenFoam (this is my first code written in openfoam).. so the code is pretty immature and dumb.. I will also be happy to hear suggestions and better alternatives for the code.. 
Similar to the equation for the source term, I would also like to specify the equations for the boundary conditions, which depends on the coordinates of the cells, like,
boundary value at south edge is 100x; where x is the xcoordinate of the face center. Where should I specify those equations? Do I need to set the boundaryField type as "calculated" and specify the equations in the solver? or should I add the equations in the dictionary file itself? Thanks. 
Quote:
Note: to get the y coordinate, this should work: scalarField y = patch().Cf().component(1); Remember to compile it using `> wmake libso', not just `> wmake'. Good luck. Mirko 
For the boundary condition. It would save you a lot of time if you use the groovyBC library. You can use easy expressions for the value or the gradient of a variable at the boundary.
You now hardcoded the source term in your solver, but that really makes your solver casespecific, which is usually unwanted. You can also easily define a field (see createFields), which you use as a source term. This sourcefield can then be set in your casedirectory 0/. (using funkySetFields) By the way, funkySetFields and groovyBC are combined in swak4Foam. 
Mirko and Bernhard,
Thank you very much for the reply.. I will look into the swak4Foam library... 
Dear user369
Quote:
can you send me test case file for your solver? also I think it better that you specify the U as a scalar not vector why you specify U as a vector ? Best Regards 
All times are GMT 4. The time now is 00:44. 