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

Reading time dependent rotating magnetic field (volVectorField) for MHD solver

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 10, 2020, 06:53
Default Reading time dependent rotating magnetic field (volVectorField) for MHD solver
  #1
New Member
 
Krishna
Join Date: Oct 2016
Posts: 12
Rep Power: 9
kavatar is on a distinguished road
Hello All,

I am developing a Magneto-hydrodynamic (MHD) solver which reads an externally applied rotating magnetic field (RMF). The magnetic field complete one rotation in one second.

I have generated the rotating magnetic field data for one second using a third party software and stored the field distribution at discrete times in time directories/folders. i.e. 0/0.1/0.2/………0.9/1.

(Point-1:- For time 0 to 1 second)) Now I want to use this magnetic field such that, between time 0 and 0.1 solver uses data stored in 0 directory and between time 0.1 and 0.2 solver uses data stored in 0.1 directory and so on.

(Point-2:- For time >1 second) And since magnetic field is rotating, it repeats after one second so between time 1 and 1.1 solver should use magnetic field stored in directory 0 and between time 1.1 and 1.2 solver should use field stored in directory 0.1. And so on….

Solution for Point 1:- I could perform calculation for time<1 second (Point 1) by below mentioned piece of code written in solver (not in the createFields file). And it works fine within this time interval.

IOobject BHeader
(
"B0",
runTime.timeName(),
mesh,
IOobject::NO_READ
);

if (BHeader.typeHeaderOk<volVectorField>(true))
{
volVectorField BNew
(
IOobject
(
"B0",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);

B0 = BNew;
}

Here B0 is original volumeVectorField stored at 0 and is declared in createFields. As solver reaches a particular time it search for the folder with timeName and check if it contains the field B0. If the folder contains the field it will replace the original B0 with BNew.

Now my question is for time>1 (Point-2) i.e. At time 1.1, I want to read the variable stored in folder/directory 0.1 and similarly at time 1.2 read variable stored in folder 0.2 and so on. Can anyone help me with this point?

(I can perform the calculation by making folder named 1.1, 1.2, 1.3 and so on. And the solver will read the field just like it read for time<1. But, I don’t want to do this since my simulation will run for almost 300 seconds and for that I will have to make so many folders)

Thanks in advance
kavatar is offline   Reply With Quote

Old   December 11, 2020, 01:55
Default
  #2
New Member
 
Krishna
Join Date: Oct 2016
Posts: 12
Rep Power: 9
kavatar is on a distinguished road
Hello,

I solved this problem on my own with following steps:

- scalar A=float value of time
- label B=int value of time
- scalar C=A-B;
- string D=std::to_string(C);

This will give me the value between 0 to 1 for current time.

I stored the files in a folder named "B" and read them from that folder at every time step using the code:

IOobject BHeader
(
D,
"B",
mesh,
IOobject::NO_READ
);

if (BHeader.typeHeaderOk<volVectorField>(true))
{
volVectorField BNew
(
IOobject
(
D,
"B",
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);

B0 = BNew;
}

Thanks !!
kavatar is offline   Reply With Quote

Reply

Tags
magnetohydrodynamics, reading data, rotating magnetic fields, time dependent input

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
OpenFOAM floating point Error upuli OpenFOAM Programming & Development 5 June 20, 2016 03:19
Floating point exception error lpz_michele OpenFOAM Running, Solving & CFD 53 October 19, 2015 02:50
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 02:58
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07


All times are GMT -4. The time now is 07:30.