CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Using source term in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mirko

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 21, 2011, 16:22
Default Using source term in OpenFOAM
  #1
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
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 steady-state 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);
volScalarField y = U.mesh().C() & vector(0,1,0);
fvVectorMatrix UEqn
(
      fvm::laplacian(U) == 50 * (x + y)
);
UEqn.solve();
but, this throws error during compilation, where the error says something like
"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.
user369 is offline   Reply With Quote

Old   April 22, 2011, 08:32
Default
  #2
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
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 is offline   Reply With Quote

Old   April 22, 2011, 13:51
Default
  #3
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
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);
volScalarField y = U.mesh().C() & vector(0,1,0);
dimensionedScalar fifty
(
    "fifty",
    dimensionSet(0, -2, -1, 0, 0, 0 ,0),
    50.0
);
fvVectorMatrix UEqn
(
    fvm::laplacian(U) == (fifty * (x + y)) * vector(1,0,0)
);
Now, the code compiles and runs without error.

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
(
    fvm::laplacian(U) == (exp(fifty * (x + y))) * vector(1,0,0)
);
Code:
--> FOAM FATAL ERROR: 
Argument of trancendental function not dimensionless

    From function trans(const dimensionSet& ds)
    in file dimensionSet/dimensionSet.C at line 370.
What is the correct way to take exponential of the coordinates?

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.
user369 is offline   Reply With Quote

Old   April 22, 2011, 15:51
Default
  #4
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
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 is offline   Reply With Quote

Old   April 22, 2011, 16:59
Default
  #5
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
Cyp,
My governing eqn. is a second order pde of the form

Laplacian(phi) = exp(fifty * (x + y))

where, x and y are the co-ordinates 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);
        volScalarField y = U.mesh().C() & vector(0,1,0);
Is my way of extracting the coordinates wrong? I tried to print the extracted values and they match the actual coordinates of my mesh cell centers.

Thank you
user369 is offline   Reply With Quote

Old   April 25, 2011, 08:56
Default
  #6
Senior Member
 
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 17
mirko is on a distinguished road
Quote:
Originally Posted by user369 View Post
Cyp,
My governing eqn. is a second order pde of the form

Laplacian(phi) = exp(fifty * (x + y))

where, x and y are the co-ordinates 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);
        volScalarField y = U.mesh().C() & vector(0,1,0);
Is my way of extracting the coordinates wrong? I tried to print the extracted values and they match the actual coordinates of my mesh cell centers.

Thank you
Can you define `fifty' as inverse meters?
mm.abdollahzadeh likes this.
mirko is offline   Reply With Quote

Old   April 25, 2011, 13:51
Default
  #7
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
Thanks Mirko.. taking the fifty as inverse meters worked.
user369 is offline   Reply With Quote

Old   April 25, 2011, 14:33
Default
  #8
Senior Member
 
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 17
mirko is on a distinguished road
Quote:
Originally Posted by user369 View Post
Thanks Mirko.. taking the fifty as inverse meters worked.
Now, let me ask you for a favor:

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
mirko is offline   Reply With Quote

Old   April 25, 2011, 14:53
Default
  #9
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
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..
Attached Files
File Type: gz testFoam.tar.gz (730 Bytes, 162 views)
user369 is offline   Reply With Quote

Old   April 25, 2011, 19:13
Default
  #10
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
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 x-coordinate 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.
user369 is offline   Reply With Quote

Old   April 26, 2011, 09:42
Default
  #11
Senior Member
 
Mirko Vukovic
Join Date: Mar 2009
Posts: 159
Rep Power: 17
mirko is on a distinguished road
Quote:
Originally Posted by user369 View Post
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 x-coordinate 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.
I think that you will need to write your own boundary condition. The procedure should be similar to that of copying and modifying an OF solver.

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
mirko is offline   Reply With Quote

Old   April 26, 2011, 11:01
Default
  #12
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 21
Bernhard is on a distinguished road
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 hard-coded the source term in your solver, but that really makes your solver case-specific, which is usually unwanted. You can also easily define a field (see createFields), which you use as a source term. This source-field can then be set in your case-directory 0/. (using funkySetFields)

By the way, funkySetFields and groovyBC are combined in swak4Foam.
Bernhard is offline   Reply With Quote

Old   April 26, 2011, 15:45
Default
  #13
New Member
 
Join Date: Apr 2011
Posts: 7
Rep Power: 15
user369 is on a distinguished road
Mirko and Bernhard,
Thank you very much for the reply..

I will look into the swak4Foam library...
user369 is offline   Reply With Quote

Old   August 7, 2011, 08:51
Default Dear user369
  #14
Senior Member
 
Join Date: Jun 2011
Posts: 163
Rep Power: 14
mechy is on a distinguished road
Quote:
Originally Posted by user369 View Post
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..

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
mechy is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
Large source term in species equation MACFD FLUENT 4 January 4, 2011 14:16
[Gmsh] Compiling gmshFoam with OpenFOAM-1.5 BlGene OpenFOAM Meshing & Mesh Conversion 10 August 6, 2009 04:26
gradient source term UDF ak6g08 Fluent UDF and Scheme Programming 0 July 9, 2009 06:37
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 03:43


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