CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Solving PDE (https://www.cfd-online.com/Forums/openfoam-solving/170497-solving-pde.html)

cute May 2, 2016 18:20

Solving PDE
 
1 Attachment(s)
Hi,

I would like to solve a PDE equation (see attached picture).
Can any one explain, how to write this equation in openfoam format? I have seen some equations in user guide but not similar to this.

Is there any test case in tutorial that I can use to solve this equation.

Thanks

cute May 4, 2016 08:21

Does anyone has any comment on my problem?

jherb May 4, 2016 09:32

For what does the D() stand? div? But isn't X scalar?

cute May 4, 2016 09:59

D is a function of X where X is a scalar quantity.

jherb May 4, 2016 11:47

I haven't tried it, but it sould be something like:
Code:

for (some loop) {
    volScalarField DX("DX", D(X));
    solve(fvm::ddt(X) == fvm::laplacian(DX, X) + k*X);
}

You have to somehow determine, if X converges, because for the calculation of DX the values of X from the previous iteration are used. Perhaps you also have to add some kind of underrelaxation.

This also might help: https://openfoamwiki.net/index.php/Contrib_potentialWaveFoam
https://www.openacoustics.org/svn-re...ntialWaveFoam/
(even though, you have a first time derivative and not a second one)

cute May 4, 2016 12:47

Thanks for the reply.
I am new in openfoam and will take time to understand and implement as you suggested.

If I define D(X) = X^2, can I rewrite the code as:

for (some loop) {
solve(fvm::ddt(X) == fvm::laplacian(X^2, X) + k*X);
}

If you can also explain volScalarField, would be easy to understand. I was searching but did not find any explanation.

jherb May 4, 2016 15:10

If you are new to OpenFOAM then you should better read some (/a lot) of documentation/tutorials. I am afraid but you wont be able to program your own solver without a least some understanding about how OpenFOAM works (e.g. definition of fields, implicit/explicit discretization etc.). Here are some links to start with:
http://www.tfd.chalmers.se/~hani/kur...ngTutorial.pdf
http://www.sourceflux.de/blog/101-th...ting-openfoam/
http://www.openfoam.org/features/creating-solvers.php

cute May 4, 2016 16:14

You are right. I am reading all these for one month and have some understanding but sometime it is difficult to find explanation. I have gone through many documentations and have gone through the links you provided. I go over these documentation whenever I need too and still many of the things are unexplained.

Thanks for your suggestion. I will let you know, if I get stuck.

cute May 6, 2016 23:21

I tried the code as suggested above

for (some loop) {
volScalarField DX("DX", X*X);
solve(fvm::ddt(X) == fvm::laplacian(DX, X) + k*X);
}

I am getting Fatal error:
keyword laplacian(DX, X) is undefined in dictionary ......./fvSchemes.laplacianSchemes.

How to fix this error?

cute May 6, 2016 23:38

PLEASE READ MY PREVIOUS POST THEN RED THIS ONE.

I added laplacian(DX,T) Gauss linear corrected; in fvSchemes then I am getting the following errors:


--> FOAM FATAL ERROR:

[X[3 -11 0 0 0 0 0] ] + [X[1 -3 0 0 0 0 0] ]

From function void Foam::checkMethod(const Foam::fvMatrix<Type>&, const Foam:: DimensionedField<Type, Foam::volMesh>&, const char*) [with Type = double]
in file /opt/OpenFOAM/OpenFOAM-v3.0+/src/finiteVolume/lnInclude/fvMatrix.C at line 1298.

FOAM aborting

#0 Foam::error:: printStack(Foam::Ostream&) in "/opt/OpenFOAM/OpenFOAM-v3.0+/platforms/linux64Gcc48DPInt32Opt/lib/libOpenFOAM.so"
#1 Foam::error::abort() in "/opt/OpenFOAM/OpenFOAM-v3.0+/platforms/linux64Gcc48DPInt32Opt/lib/libOpenFOAM.so"
#2 void Foam::checkMethod<double>(Foam::fvMatrix<double> const&, Foam:: DimensionedField<double, Foam::volMesh> const&, char const*) in "/home/nasim/OpenFOAM/nasim-v3.0+/platforms/linux64Gcc48DPInt32Opt/bin/diffusionFoam"
#3 ? in "/home/nasim/OpenFOAM/nasim-v3.0+/platforms/linux64Gcc48DPInt32Opt/bin/diffusionFoam"
#4 ? in "/home/nasim/OpenFOAM/nasim-v3.0+/platforms/linux64Gcc48DPInt32Opt/bin/diffusionFoam"
#5 __libc_start_main in "/lib64/libc.so.6"
#6 ? in "/home/nasim/OpenFOAM/nasim-v3.0+/platforms/linux64Gcc48DPInt32Opt/bin/diffusionFoam"
Aborted (core dumped)

jherb May 7, 2016 17:48

Have a look in createFields.H of the solver(s) of OpenFOAM. There you can see how a field with a dimension is created. Then assign the correct dimension to the field DX (so that the both terms on the right hand side of your equation have the same dimensions). What is the dimension of X?

cute May 7, 2016 18:04

Thanks jHerb, There was a problem with dimension and has been corrected. Now my simulations are running.
Thanks for all the help. If I encounter other problems, I will post here.

I have one more question. I am solving a simple system whose exact solution does exit. Is there any facility/tool that I could verify my simulations with exact solution. For example, can I integrate my PDE in openfoam and visualize the solution in paraFoam?

jherb May 7, 2016 18:47

Can't you just load your case with paraview/paraFoam? It should offer you the fields of your solution (so probably) X and DX to view on your grid.

Also there are probes, to write the results of the fields for selected points in a directory call postprocessing.

Another idea: You can create an addition field and use it to store the exact solution of the equation. Then you can also view this field in paraview. Either there with a filter or directly in your solver you can create yet another field to store the differences between your numerical and the exact solutions.

Just for curiosity: Can you post some screenshots of paraview, if you succeeded.

cute May 8, 2016 05:57

I can use paraFoam to view the fields and there is no problem. But how can I calculate the results for exact solution.

For example, if I have a function that represent exact solution as W=X(t, x,y) where t is time and x, y are spatial coordinates. How can I store the functional values for various time in their respective directories using t as simulation timestep and x and y as grid points?

jherb May 9, 2016 17:34

In paraview there are filters which can do what you want: Try the the calculator filter to do calculate the theoretical result: https://itk.org/Wiki/ParaView/Users_...ers#Calculator
http://www.paraview.org/Wiki/Beginni...culator_filter
or perhaps also the python calculator:
http://www.vtk.org/Wiki/Python_Calculator

see also http://scicomp.stackexchange.com/que...red-in-two-dif

cute May 9, 2016 18:08

Thanks alot and really appreciate your help. I will try this very soon.


All times are GMT -4. The time now is 15:52.