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

Initialization of U by code

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 19, 2009, 09:09
Default
  #21
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Sorry for the late reply, I've been really busy!
I'm not sure why you're getting the behaviour that you observe. Possibly U has gone out of scope or something? The write() function just writes the current U field to the 0/U file.
I'd probably need to see it for myself, feel free to post your files in a tarball and I can take a quick look.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   October 20, 2009, 21:31
Default
  #22
Senior Member
 
santiagomarquezd's Avatar
 
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24
santiagomarquezd will become famous soon enough
Thanks Laurence for your attention even with all your work. Well, this is the code:

Code:
// Velocity field initialization

// Angular velocity
scalar omega=2000;

// Maximum velocity en parabolic profile
scalar Vmax=2.0;

// Tube radius
scalar tubeR=0.05;

// Cell centroid coordinates
const volVectorField& centres = mesh.C();

// Coordinate system origin
point origin(0, 0, 0);

// Axis of rotation
vector axis(0, 0, 1);

// Force arm calculation
vectorField palanca;

palanca = centres.internalField() - ((centres.internalField()-origin) & axis)*axis;


// Parabolic velocity field calculation
scalarField zComp=Vmax*(1-sqr(mag(palanca)/tubeR));

// Option with rotation and the parabolic
// Rotation
U.internalField()=omega*(axis^palanca);
// Parabolic in z direction
U.internalField().replace(vector::Z,zComp);

// Write to /0/U
U.write();
The sequence of includes is that follows:

Code:
#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"

#   include "USetUp.H"
(mine is the last one, added in scalarTransportFoam.C)

As you can see, after rewriting in memory the U vector field I call the .write() method to write the field to the hard disk. The problem is that if you run the code once, the initializated U field doesn't remain in memory, i.e. the advection equation is solved with another field, maybe zero, I don't
know. But, in the other hand, if you run the code some steps, then stop it and run it again with the /0/U recently written things go well.

That's all. Regards.
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D.
Research Scientist
Research Center for Computational Methods (CIMEC) - CONICET/UNL
Tel: 54-342-4511594 Int. 7032
Colectora Ruta Nac. 168 / Paraje El Pozo
(3000) Santa Fe - Argentina.
http://www.cimec.org.ar
santiagomarquezd is offline   Reply With Quote

Old   October 21, 2009, 07:00
Default
  #23
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
This worried me slightly, so I took a look, and I think I've figured it out.

The scalar transport equation takes phi as the coefficient in fvm::div, not U. So you have overwritten U, but now you have to recreate the flux.

So just put
Code:
#include "createPhi.H"
below
Code:
#include "USetUp.H"
Hope that's the problem.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   December 11, 2009, 15:09
Default
  #24
Senior Member
 
santiagomarquezd's Avatar
 
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24
santiagomarquezd will become famous soon enough
Laurence, I've been working in another things last months but I've returned to this problem. Your suggestion was right, FOAM was assembling the flux with the original U not with the one calculated by my code. I had to put the

Code:
#include "createPhi.H"
below

Code:
#include "USetUp.H"
Nevertheless it is necessary to comment the original invocation of createPhi.H file in createFields.H because the

Code:
#ifndef createPhi_H
clause within createPhi.H. As you know, this line impedes that definition can be repeated.

Regards.
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D.
Research Scientist
Research Center for Computational Methods (CIMEC) - CONICET/UNL
Tel: 54-342-4511594 Int. 7032
Colectora Ruta Nac. 168 / Paraje El Pozo
(3000) Santa Fe - Argentina.
http://www.cimec.org.ar
santiagomarquezd is offline   Reply With Quote

Old   December 29, 2013, 17:06
Default
  #25
Member
 
Tony
Join Date: Nov 2013
Posts: 35
Rep Power: 13
wzx1989221 is on a distinguished road
Dear Santiago,

I am struggling with getting a parabolic internal field for pipe flow in openfoam and I've found your post very useful.
Could you please give me some hints on the line "U.internalField()=omega*(axis^palanca);" ?
Another silly question, where shall I put the code, in 0/U or somewhere else? Do I need to derive my own solver for it?
I really appreciate your reply. Thank you very much.

Best regards,
Tony

Last edited by wzx1989221; December 30, 2013 at 08:29.
wzx1989221 is offline   Reply With Quote

Old   January 2, 2014, 19:30
Default
  #26
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

FYI for future readers: Tony's question has been in essence answered here: http://www.cfd-online.com/Forums/ope...tml#post468380


@Tony: Regarding your question about Santiago's implementation: from what I can figure out from the first few posts, it seems that he created a variant of the solver scalarTransportFoam and added a new header file that includes the code discussed in this thread.

It takes a while to explain it in more detail, so I suggest that you have a look at the following tutorials, in order to get a bit more perspective into the details:
In fact, you'll see that those two tutorials are similar to each other, since the first one implements the explanation given in the second one.


Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   January 2, 2014, 20:09
Default
  #27
Member
 
Tony
Join Date: Nov 2013
Posts: 35
Rep Power: 13
wzx1989221 is on a distinguished road
Hi, Bruno

Thank you very much for the information. I will have a look at that and get back to you if I have further questions.

Best regards,
Tony
wzx1989221 is offline   Reply With Quote

Reply

Tags
set up fields, vector manipulation


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
From 2D compressible code to 3D code David Liu Main CFD Forum 22 June 26, 2012 18:59
code initialization - exclude pressure edna Siemens 0 January 29, 2008 11:56
CFD code structure (F90) ma Main CFD Forum 4 January 10, 2005 21:47
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 16:56
State of the art in CFD technology Juan Carlos GARCIA SALAS Main CFD Forum 39 November 1, 1999 15:34


All times are GMT -4. The time now is 21:12.