|
[Sponsors] |
February 16, 2011, 10:16 |
User Defined Function in OF
|
#1 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
Hi!!
I have to implement a UDF in OF that i have used in Fluent. the problem, as you know, is that in OF there isn't an "interface" as in Fluent. Can you help me?? I'm new with programming in OpenFoam |
|
February 16, 2011, 10:37 |
UDF basically can't
|
#2 |
Member
Charlie
Join Date: Dec 2010
Location: USA
Posts: 85
Rep Power: 16 |
Bsically, the UDF in fluent can't be used directly in OF.
You need to modify the source code to accomplish what you need. After modifying the code, you need to compile it. Zhen |
|
February 16, 2011, 10:54 |
|
#3 | |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
Quote:
where may i put the file??? |
||
February 16, 2011, 11:00 |
|
#4 |
Member
Charlie
Join Date: Dec 2010
Location: USA
Posts: 85
Rep Power: 16 |
you would like to put the new file inside a new folder in the opt/openfoam1.7.x/application/solvers/...
and when you compile the new file, in the Make folder you can define a keyword to call for it, for example you can refer to the incompressible/channelFoam/Make/files to learn how they do it. To answer how to call it, in the work directiory, under 'system' folder, you can put the keyword in the right place to call for the application you defined. Hope this helps! Zhen |
|
February 16, 2011, 11:58 |
|
#5 |
Member
Sebastian Lang
Join Date: Aug 2009
Posts: 47
Rep Power: 17 |
Hi salvoblack,
OpenFOAM also provides special folders for self-programmed utilities. For example $FOAM_USER_APPBIN is a place where you can put your own executable files. This is a standard search-path for OpenFOAM, what means that you can execute the programs you put in $FOAM_USER_APPBIN directly from the case-folders you work in. In this way, your own executables can be used as the standard OpenFOAM executables, i.e. blockMesh, icoFoam etc. In fact, those utilities and solvers are nothing but executable files which lie in the $FOAM_APPBIN folder. Hope this helps for the general understanding. If you want to do some special things during a simulation, my way would be to take the solver you want to use, copy its source-folders from $WM_PROJECT_DIR/solvers to the $FOAM_APP directory and edit the source codes on this copy. Of course, you have to change the name of the source-code etc. to distinguish your executable from the original one later on. Thats the general way so far, at least my general way ;-) Hope that helped, greetings Sebastian |
|
February 16, 2011, 13:36 |
|
#6 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
Suppose I know the transition point, which I call x_tr.
which file should I change to require that 1) if x <x_tr then I can impose nut = 0; 2) if x> x_tr then I can say that nut! = 0?? |
|
February 16, 2011, 14:51 |
|
#7 |
Member
Sebastian Lang
Join Date: Aug 2009
Posts: 47
Rep Power: 17 |
Hi salvoblack,
mhm, I think you want it a bit too fast... First question is: which solver do you want to use? You need the whole source code for the solver. All the solver-codes are located in folder $WM_PROJECT_DIR/solvers. I did something similar some time ago: I changed the boundary condition during simulation depending on a scalar value in a patch face. What I did was something like Code:
forAll(scalarField1.boundaryField,I) if (scalarField1.boundaryField[I] < 1) scalarField2.boundaryField[I] = 5 What you see in this example, too, is that OpenFOAM programming is based on object-orientation. scalarField1 and scalarField2 might be objects of the class volScalarField and this field's method boundaryField returns all the patch values related to this volScalarField. Maybe you know that, as you already have experience with programming UDF's. But I think the UDF's of Fluent are written in C, aren't they? Well, OpenFOAM uses C++ which is related to C, but I don't think you will have a lot of fun with OpenFOAM-customizing if you are not aware of basic object-oriented concepts and the syntax of C++, of course. If you need more explanations, could you then please tell something about your experiences in programming and object-orientation? That makes it easier to help you, because we could leave out the basic things, if you already know about object-orientation for example. Feel free to ask again! Greetings Sebastian |
|
February 17, 2011, 04:55 |
|
#8 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
Hi Sebastian,
thank you for the quick reply. Unfortunately no, I'm not very familiar with programming in C + + and especially with the object-orientation. My UDF in Fluent is very simple and I think I will have many difficulties to implement it in OF. However I wanted to ask, since I want to use as simpleFoam solver, could you tell me which file I have to go change to force the change of nuts depending on the value of x (with respect to the transition)?? |
|
February 17, 2011, 09:53 |
|
#9 |
Member
Sebastian Lang
Join Date: Aug 2009
Posts: 47
Rep Power: 17 |
Hi salvoblack,
first of all, I have to apologize, because I told you a wrong folder: The solver codes are located in $WM_PROJECT_DIR/applications/solvers and not in $WM_PROJECT_DIR/solvers as I said in my former posts. I think you know about the environmental variables, do you? All parts of paths I write which start with a $-sign a environmental variables. For example $HOME is the path of your home dictionary /home/username/. Alright, I'll try to give you a step-by-step guide. All the codes I use have to be executed in the terminal: First of all, create your folder for self-compiled applications with Code:
mkdir -p $FOAM_USER_APPBIN Code:
cp -r $WM_PROJECT_DIR/applications/solvers/incompressible/simpleFoam $FOAM_RUN/../applications Code:
cd $FOAM_RUN/../applications -change the directory-name of your copied simpleFoam-sourcecodes to a name you want, for example MODsimpleFoam for modified simpleFoam -go into the renamed directory and do Code:
wclean -go into the Make subfolder -edit the textfile named 'files' and change the first word (it should be 'simpleFoam.C') to the name you decided for the solver (for example 'MODsimpleFoam.C') -two lines under that in the 'files'-textfile, you find this: EXE = $(FOAM_APPBIN)/simpleFoam -edit that and change it to EXE = $(FOAM_USER_APPBIN)/MODsimpleFoam this line says how your executable will be named after compilation and where it will be located. Here you see:the original simpleFoam is a standard-solver of OpenFOAM and therefore is stored in $FOAM_APPBIN. The customized solver will be your own, so don't store it inside the standard-folders, because you will get messed up later on if you don't seperate customized and standard-utilities. To avoid this confusion, your solver will be located in $FOAM_USER_APPBIN, from which it can be started from every directory you want, because it belongs to the standard-searchpaths of OpenFOAM. So, now your ready to edit the major-sourcecode MODsimpleFoam.C: You should try to understand the solving-procedure first, before you change anything. Your modifications should be placed in this file, but I am sorry that I can't tell you in detail what you have to change by now. After you did your modifications, you can compile the solver with Code:
wmake I hope you are able to create your customized solver by now. If I can help you again, just ask here, but I think you will at least have to learn some basic terminology of object-orientation, because almost the whole solver is written with constructors and methods of classes. You should at least invest some time and learn the meaning of these elements of object-orientation. I don't think you will be successful in creating a modified solver if you don't know the basics, because everything in OpenFOAM is based on this stuff. Good luck! Greetings Sebastian |
|
February 17, 2011, 10:04 |
|
#10 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
thank you very much for your help, you were very kind!!!
now i'll try to study something about the programming of c++. thanks a lot!! |
|
March 6, 2011, 05:50 |
|
#11 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
Hello everyone. I urgently need help.
I'm trying, as mentioned in previous posts, to amend the komega SST turbulence model. I want to do is to impose the transition point so as to put nut = 0 when the flow is laminar. I should change this part of the program // Re-calculate viscosity nut_ = a1_*k_/max(a1_*omega_, F2()*sqrt(S2)); nut_.correctBoundaryConditions(); how can I change the program to change the x coordinate, in order to fix the transition point? |
|
March 7, 2011, 07:28 |
|
#12 |
Member
Join Date: Oct 2010
Location: Naples
Posts: 50
Rep Power: 16 |
any suggestions???
|
|
April 29, 2018, 17:30 |
equation of motion
|
#13 |
Member
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9 |
Hello
Can you help if possible. I want to move a solid cylinder by applying force on it. I have modeled that system as spring mass with zero damping. when the applied force is zero, the system is governed by the following equation: (simple harmonic motion) mx"+w^2 x =0 I have solved that ODE using RK5order and have c++ program. what i want to ask is how can i use OpenFoam solver(simpleFoam or any you may recommande) to add a forcing term on it and see the results(displacement with respect to time). mx"+w^2 x =F How to modify simpleFoam.c to connect it with my c++ function and solve for displacement for different force input. would appreciate your answer! Regard! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
ParaView for OF-1.6-ext | Chrisi1984 | OpenFOAM Installation | 0 | December 31, 2010 07:42 |
return more than one value from a user function | Benny | CFX | 0 | July 18, 2008 11:00 |
User defined function - CO level | hari | FLUENT | 0 | October 24, 2007 01:11 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 07:27 |
Help: user defined function | alice | FLUENT | 3 | December 13, 2000 01:10 |