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

How to write a vector into a file in volVectorField type

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By alexeym
  • 1 Post By alexeym

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 3, 2015, 02:52
Default How to write a vector into a file in volVectorField type
  #1
Member
 
methma Rajamuni
Join Date: Jul 2015
Location: Victoria, Australia
Posts: 40
Rep Power: 11
meth is on a distinguished road
Hi,

I am new to OpenFOAM. Currently I am working on implementing a new solver. Inside this solver I am calculating a value in each time step and create a vector, y2, from that. Now I want to write that vector as a volVectorField together with the time into a dictionary. Can you please help me to do this with your ideas and/or references.

Thank you

Methma
meth is offline   Reply With Quote

Old   November 3, 2015, 03:38
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

1. Create volVectorField (let us call it myLovelyVectorField further) with NO_READ and AUTO_WRITE flags (see for example pressure field in interFoam, $FOAM_APP/solvers/multiphase/interFoam/createFields.H, keep in mind pressure is scalar, you need vector).

2. Calculated y2, assign y2 to created volVectorField. Either using myLovelyVectorField.internalField() = y2, if your y2 is simple vector, or myLovelyVectorField = y2, if your y2 is dimensioned vector (you can find examples of assignment in different solvers, for example in alphaEnq.H of the same interFoam).
meth likes this.
alexeym is offline   Reply With Quote

Old   November 3, 2015, 18:40
Default
  #3
Member
 
methma Rajamuni
Join Date: Jul 2015
Location: Victoria, Australia
Posts: 40
Rep Power: 11
meth is on a distinguished road
Hi Alexey Matveichev,

Thank you for your reply It help me a lot.

I have another question for you.

In my solver I am calculating motion of a solid sphere due to the fluid, and y2 is the displacement vector of the sphere. It is simply a vector calculate in each time step, I recently realised that it's not a volVectorFeild. What I need to do is write a file in the following format
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.1                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      solidDisplacementData;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solidDis
{
    t150 		(0 1 0);
    t151		(0 2 0);
    t152		(0 3 0);
    t153		(0 4 0);

}
with time index in first column and the vector y2 in the second column, which can read by the OpenFOAM.

Can you please give your ideas and references to do this?


Best,

Methma

Last edited by meth; November 3, 2015 at 21:03.
meth is offline   Reply With Quote

Old   November 5, 2015, 06:19
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

The way you store y2 should be solely defined by the purpose of y2. Here is code snippet, which writes vectors in constant/solidDisplacementDict file:

Code:
#include "fvCFD.H"

using namespace Foam;

int main(int argc, char *argv[])
{
# include "setRootCase.H"

# include "createTime.H"
# include "createMesh.H"

  IOdictionary test
   (IOobject
    ("solidDisplacementDict",
     runTime.constant(),
     runTime));

  vector v(vector::zero);

  dictionary t("values");
  t.add<vector>(runTime.timeName(), v);
  test.set("solidDisplacement", t);
  static_cast<regIOobject*>(&test)->write();

  while (runTime.loop())
    {
      v.x() += 1.0;

      test.subDict("solidDisplacement").add<vector>(runTime.timeName(), v);
      static_cast<regIOobject*>(&test)->write();
    }

  return 0;
}
It produces dictionary (I have dt=0.005 in controlDict):

Code:
solidDisplacement
{
    0               ( 0 0 0 );
    0.005           ( 1 0 0 );
    0.01            ( 2 0 0 );
    0.015           ( 3 0 0 );
    0.02            ( 4 0 0 );
    0.025           ( 5 0 0 );
    0.03            ( 6 0 0 );
    0.035           ( 7 0 0 );
    0.04            ( 8 0 0 );
    ...
}
If you need this vector for boundary condition (your other posts suggest it), you can calculate y2, and then insert directly (well, not quite, you need to do certain transformations to the vector) into velocity (or other) equation matrix.

If you need to visualize this vector, save it as volVectorField, this is the easiest way.
meth likes this.
alexeym is offline   Reply With Quote

Old   June 8, 2018, 04:58
Default Solid motion
  #5
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
Hello Foamers,


I want to simulate the motion of cylinder when hydrodynamic forces apply.
so far, i have modeled its motion with undamped free vibration equation (x"+w^2 x=0), i solved it with Runge kutter 5th order to find the displacement X at each time step(C++ codes).


Now i consider the center of the cylinder as vector y(0,x,0), each time step the center chamges as x changes. the radius is 0.05

Can you help to know how this can be achieved in any solver?
Ben UWIHANGANYE is offline   Reply With Quote

Old   June 8, 2018, 05:22
Default
  #6
Member
 
methma Rajamuni
Join Date: Jul 2015
Location: Victoria, Australia
Posts: 40
Rep Power: 11
meth is on a distinguished road
Hi Ben,

In this case, you can use either a dynamic mesh technique to update the deformed mesh according to the new position of the cylinder or can solve the fully coupled fluid-solid system by modelling the cylinder in a reference frame attached to the centre of the cylinder. The second method is far more efficient than the first one and can apply for a single body FSI problem. If you are interested on the second method, you can read my paper, 'Transversely flow-induced vibration of a sphere' https://www.cambridge.org/core/journ...A9BAC7A505CB35

Best,
Methma
meth is offline   Reply With Quote

Old   June 8, 2018, 06:22
Default
  #7
Member
 
Ben 017
Join Date: Nov 2017
Posts: 70
Rep Power: 9
Ben UWIHANGANYE is on a distinguished road
Quote:
Originally Posted by meth View Post
Hi Ben,

In this case, you can use either a dynamic mesh technique to update the deformed mesh according to the new position of the cylinder or can solve the fully coupled fluid-solid system by modelling the cylinder in a reference frame attached to the centre of the cylinder. The second method is far more efficient than the first one and can apply for a single body FSI problem. If you are interested on the second method, you can read my paper, 'Transversely flow-induced vibration of a sphere' https://www.cambridge.org/core/journ...A9BAC7A505CB35

Best,
Methma





Thank you,



I have read a bit your approach in that paper.
May you share the used FSI solver(vivicoFoam).
I may start from there and know how to handle my case.


i would appreciate your support!



Best regard!


Ben
Ben UWIHANGANYE is offline   Reply With Quote

Reply

Tags
openfoam


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
[Helyx OS] Helyx-OS (GUI for SnappyHexMesh elvis OpenFOAM Community Contributions 210 January 30, 2017 19:57
Error during initialization of "rhoSimpleFoam" kornickel OpenFOAM Running, Solving & CFD 8 September 17, 2013 06:37
[swak4Foam] build problem swak4Foam OF 2.2.0 mcathela OpenFOAM Community Contributions 14 April 23, 2013 14:59
[swak4Foam] Air Conditioned room groovyBC Sebaj OpenFOAM Community Contributions 7 October 31, 2012 15:16
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 12:46


All times are GMT -4. The time now is 16:02.