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

Solving a Poisson equation with a source term

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 28, 2024, 16:11
Default Solving a Poisson equation with a source term
  #1
New Member
 
Nils Tilton
Join Date: Aug 2024
Posts: 8
Rep Power: 2
NilsTilton is on a distinguished road
Dear OpenFoam community,

As part of my learning OpenFoam, I am trying to solve a 2D Poisson equation of the form \nabla^2 T = sin(x)*sin(y) using the laplacianFoam solver. I have already experimented extensively with solving the simpler Laplace equation \nabla^2 T=0. I consulted the header file for laplacianFoam, and it states that it solves a PDE of the form

fvm::ddt(T) - fvm:: laplacian(DT , T) == fvModels.source(T)

I then searched for what little documentation I could find on fvModels, and I decided to prescribe the source term using the codedFvModel. From the header file for that, my understanding is I need to add a file named "fvModels" in the constant subdirectory. I wrote the file shown below, and added it to the constant directory. However, from the output, it seems the file is not being read, and the source term is not being implemented. When I run laplacianFoam I see the text "No finite volume options present" appear at one point. I believe this has to do with the fact source terms used to be applied using fvOptions. Does anyone have any suggestions? Thanks!

FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvModels;
}

PoissonSource
{
type coded;
selectionMode all;
field T;

codeAddSup
#{
Pout<< "**codeAddSup**" << endl;

// get cell volume
const scalarField& V = mesh().V();

// access eon.source()
scalarField& f = eqn.source();

// get the x and y coordinates of the cell centroids
scalarField x(mesh_.C()&vector(1,0,0));
scalarField y(mesh_.C()&vector(0,1,0));

// compute the source term
f += Foam::sin(x)*Foam::sin(y)*V;

#};


}
NilsTilton is offline   Reply With Quote

Old   August 28, 2024, 22:17
Default
  #2
New Member
 
Nils Tilton
Join Date: Aug 2024
Posts: 8
Rep Power: 2
NilsTilton is on a distinguished road
Just as an additional update, I searched the tutorials folder using the "find" command for any file named fvModels as well as any instance of the text "fvModels," and it returned zero instances.
NilsTilton is offline   Reply With Quote

Old   August 28, 2024, 23:03
Default
  #3
New Member
 
Nils Tilton
Join Date: Aug 2024
Posts: 8
Rep Power: 2
NilsTilton is on a distinguished road
And as another update: I am able to get the source term if I use the following fvOptions file in the constant folder. I am confused, because I did find other posts where people successfully used fvModels to add source terms to laplacianFoam. Anyone have any ideas? Is there something wrong with my OpenFOAM install?

PoissonSource
{

type scalarCodedSource;
name Tsource;
selectionMode all;

scalarCodedSourceCoeffs
{

selectionMode all;
fields (T);

codeInclude
#{
#};

codeCorrect
#{
Pout<<"**codeCorrect**" << endl;
#};

codeAddSup
#{

const scalarField& V = mesh_.V();
scalarField& TSource = eqn.source();
scalarField x(mesh_.C()&vector(1,0,0));
scalarField y(mesh_.C()&vector(0,1,0));

TSource += Foam::sin(x)*Foam::sin(y)*V;

#};

codeConstrain
#{
Pout<<"**codeConstrain**" << endl;
#};
}

}
NilsTilton is offline   Reply With Quote

Reply

Tags
fvmodel, openfoam, source terms


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] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
chtMultiRegionSimpleFoam turbulent case Aditya Patil OpenFOAM Running, Solving & CFD 6 April 24, 2017 23:13
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 03:20
Cannot run the code properly: very large time step continuity error crst15 OpenFOAM Running, Solving & CFD 9 December 14, 2014 19:17
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 06:24


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