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

3D equation, loading values for variable Cp from txt file with time-value columns

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AJAY BHANDARI

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 29, 2015, 07:42
Default 3D equation, loading values for variable Cp from txt file with time-value columns
  #1
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi all,

I think my problem is similar as described above. I have to input a time varying variable Cp whose value is changing with time not space. I have 32 time points and 32 values of Cp. these values are listed in a text file and i have to read it from there..

Basically i am simulating a convection diffusion equation . I am pasting the code for better understanding...

solve
(
fvm::ddt(C)
+ (1/por)*fvm::div(phi, C)
- fvm::laplacian(D, C)
+ fvm::Sp((ktrans/por), C)
+ fvm::Sp((lfc/por)*(p-lp), C)
==
(ktrans*Cp)

);

In here Cp term (basically its concentration in moles) on RHS is time varying and changing for 32 time points.
My problem is how i enter the time varying values of Cp as i am simulating this eqn for 32 time points to get C at each time point (total time 128 seconds with time difference of 4 sec so total 32 time points). I have list of 32 values of Cp for 32 time points... How I enter them for each time point?? or how i read my text file. I am pasting my text file also for better understanding..
time(sec) concentration(moles)
4 0.0
8 0.0
12 0.0
16 0.0
20 0.0
24 0.10108117
28 1.0127527
32 2.0
36 1.557599
40 1.131114
44 1.1927048
48 1.289628
52 1.295573
56 1.140025
60 1.038649
64 1.0607834
68 1.1071031
72 1.0575966
76 1.0918694
80 1.0274673
84 1.005336
88 0.9897777
92 0.93968034
96 0.932393
100 0.8909937
104 0.93785316
108 0.8845323
112 0.91211754
116 1.0066646
120 0.92081094

Any help will be appreciated...

Regards
Ajay
AJAY BHANDARI is offline   Reply With Quote

Old   December 29, 2015, 08:01
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
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 Ajay,

I've moved your post from the other thread: http://www.cfd-online.com/Forums/ope...ampledict.html - to this new one, since the problems are somewhat different.

The first problem is determining if you are solving a 0D or a 1D equation. I ask this because this affects how the "Cp" field is provided, as well as the other fields, such as C and D.

Therefore, please provide more details about the case set-up you have. I ask this because the "Cp" field should either be:
  1. Using a boundary condition that allows for this field change;
  2. or perhaps it's best to use a "swakExpression" (you will need to install swak4Foam for this) to modify the field based on the txt file.
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   December 29, 2015, 11:49
Post
  #3
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi,

Thanks bruno for your quick reply.. Regarding your questions..

I am simulating a body tissue which is basically porous media. The above equation is basically a 3D equation means i am simulating C (concentration in tissue) in 3D. It is a volScalarField.

D is diffusion constant and its value is 1e-09 and is uniform all over the mesh.
ktrans and por are permeability coefficient and porosity which is non uniform and has been input on each cell in mesh.
Mesh is rectangular with 45,30,10 cells in x,y,z directions respectively.
pressure and velocity have been solved earlier by continuity and momentum equations.
Now problem is that i am simulating the above equation for 30 time steps starting from 0 to 120 sec at interval of 4 sec. And at each time step Cp(concentration in capillaries) term is changing and i have a list of values which i have already mentioned above. I just want to read this text file and update Cp term at each time step to calculate C at each time step.

Hope you understand

Regards
Ajay
AJAY BHANDARI is offline   Reply With Quote

Old   December 29, 2015, 12:27
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
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
Hi Ajay,

Without a working code to work on, I'll have to rely on a few quick notes:
  1. Based on the code from the boundary condition "uniformFixedValueFvPatchField" ("src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue"), the following chunks of code will be needed:
    Code:
    autoPtr<DataEntry<Type> > uniformValue_;
    
    uniformValue_(DataEntry<Type>::New("uniformValue", dict))
    {
        const scalar t = this->db().time().timeOutputValue();
        fvPatchField<Type>::operator==(uniformValue_->value(t));
  2. From "applications/utilities/preProcessing/dsmcInitialise/dsmcInitialise.C":
    Code:
        IOdictionary dsmcInitialiseDict
        (
            IOobject
            (
                "dsmcInitialiseDict",
                mesh.time().system(),
                mesh,
                IOobject::MUST_READ_IF_MODIFIED,
                IOobject::NO_WRITE
            )
        );
  3. Putting things together in code:
    1. In the creation section:
      Code:
      IOdictionary cpDict
      (
          IOobject
          (
              "cpDict",
              mesh.time().constant(),
              mesh,
              IOobject::MUST_READ,
              IOobject::NO_WRITE
          )
      );
      
      
      autoPtr<DataEntry<scalar> > cpValue(DataEntry<scalar>::New("cpValue", cpDict));
    2. In the calculation section, before using "Cp":
      Code:
      Cp = cpValue->value(mesh.time().timeOutputValue()));
  4. The following files are examples that this code should be able to process:
    1. The dictionary file "constant/cpDict" with the data settings:
      Code:
      cpValue     tableFile;       
      cpValueCoeffs       
      {       
          fileName     "$FOAM_CASE/myDataFile"
          outOfBounds  clamp;       
      }
      Note: The solver will complain about the missing header in this file, which is just a matter of copy-pasting the stuff it tells you into the beginning of this file.
    2. The file "myDataFile" should be placed in the base case folder and is based on your text file, but reformatted like this:
      Code:
      (
        (4 0.0)
        (8 0.0)
        (12 0.0)
        (16 0.0)
        (20 0.0)
        (24 0.10108117)
        (28 1.0127527)
        (32 2.0)
        (36 1.557599)
        (40 1.131114)
        (44 1.1927048)
        (48 1.289628)
        (52 1.295573)
        (56 1.140025)
        (60 1.038649)
        (64 1.0607834)
        (68 1.1071031)
        (72 1.0575966)
        (76 1.0918694)
        (80 1.0274673)
        (84 1.005336)
        (88 0.9897777)
        (92 0.93968034)
        (96 0.932393)
        (100 0.8909937)
        (104 0.93785316)
        (108 0.8845323)
        (112 0.91211754)
        (116 1.0066646)
        (120 0.92081094)
      );
      Source: http://www.cfd-online.com/Forums/ope...tml#post350763 post #2
Don't forget to build the solver again. With any luck, this works at first try... but I doubt it, since I didn't have a base work code to work with.


Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   December 30, 2015, 01:38
Post
  #5
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi bruno,

Thanks for your help. I did exactly as you have mentioned. I built the solver again. Solver was compiled succesfully. But when i am running the case Its giving following error..
Code:
    
--> FOAM FATAL ERROR: 
Different dimensions for =
     dimensions : [0 0 0 0 1 0 0] = [0 0 0 0 0 0 0]


    From function dimensionSet::operator=(const dimensionSet&) const
    in file dimensionSet/dimensionSet.C at line 171.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::abort() at ??:?
#2  Foam::dimensionSet::operator=(Foam::dimensionSet const&) const at ??:?
#3  ? at ??:?
#4  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#5  ? at ??:?
Aborted (core dumped)

I have checked all the dimensions twice.. I don't know where is the error now. But i think error is in this line
Code:
              
Cp = cpValue->value(mesh.time().timeOutputValue()));
Because It compiled succesfully without any dimension error when i was doing it previously without this method but obviously results were not correct.. Please suggest...

Regards
Ajay
AJAY BHANDARI is offline   Reply With Quote

Old   December 30, 2015, 07:43
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
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
Hi Ajay,

Quote:
Originally Posted by AJAY BHANDARI View Post
Because It compiled succesfully without any dimension error when i was doing it previously without this method but obviously results were not correct.. Please suggest...
Even if it compiles, it doesn't mean it will run properly .

Knowing how you defined the Cp variable would make it easier to give a proper solution.
Either way, the problem is that it cannot be a "scalar", it has to be "dimensionedScalar"... let me see if I can find an example in OpenFOAM's code... here's a command that helps find several examples:
Code:
find $FOAM_UTILITIES $FOAM_SOLVERS -name "*.[CH]" -type f | xargs grep dimensionedScalar
Drawing from a few files, something like this might work:
Code:
dimensionedScalar Cp("Cp", dimEnergy/dimTemperature, 0.0);
dimensionedScalar Cp("Cp", dimensionSet(0, 2, -1 , 0, 0), 0.0);
Note: These are just examples. I didn't go check what units are "Cp" meant to be .

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   December 30, 2015, 11:53
Post
  #7
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi bruno,

I didn't get it means you are saying that in createfields.h file i replace this
Code:
    Info<< "Reading field Cp\n" << endl;
    volScalarField Cp
    (
        IOobject
        (
            "Cp",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
by this
Code:
dimensionedScalar Cp("Cp", dimensionSet(0 0 0 0 1 0 0), 0.0);
or where i should put the above line of code in my case??
AJAY BHANDARI is offline   Reply With Quote

Old   December 30, 2015, 12:40
Post
  #8
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi bruno,

I have done the following changes in createFields,h


Code:
   IOdictionary cpDict
   (
      IOobject
      (
           "cpDict",
          mesh.time().constant(),
          mesh,
          IOobject::MUST_READ,
          IOobject::NO_WRITE
      )
   );


autoPtr<DataEntry<scalar> > cpValue(DataEntry<scalar>::New("cpValue", cpDict));
    

    dimensionedScalar Cp  
    (
          cpDict.lookup("Cp")
    );
and in constant cpDict file

Code:
Cp        Cp    [0 0 0 0 1 0 0]    0;

cpValue     tableFile;       
cpValueCoeffs       
{       
    fileName     "$FOAM_CASE/myDataFile"
    outOfBounds  clamp;       
}
myDataFile has been put in a folder in case according to same format..
Solver is compiling but again case is not running and now error is

Code:
--> FOAM FATAL IO ERROR: 
error in IOstream "/home/ajay/OpenFOAM/ajay-2.4.0/run/tutorials/incompressible/porousSimpleFoam/cncrnozeroporositytime/myDataFile" for operation operator>>(Istream&, List<T>&) : reading first token

file: /home/ajay/OpenFOAM/ajay-2.4.0/run/tutorials/incompressible/porousSimpleFoam/cncrnozeroporositytime/myDataFile at line 1.

    From function IOstream::fatalCheck(const char*) const
    in file db/IOstreams/IOstreams/IOstream.C at line 114.

FOAM exiting
I am not understanding now. Is something wrong with myDataFile format. Please suggest..

Regards
Ajay

Last edited by wyldckat; December 31, 2015 at 07:34. Reason: fixed broken end code marker
AJAY BHANDARI is offline   Reply With Quote

Old   December 31, 2015, 08:03
Default
  #9
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
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
Hi Ajay,

That is very strange.... why did you try those lines of code that are not exactly as the examples I had given?

The following should work:
Code:
   IOdictionary cpDict
   (
      IOobject
      (
           "cpDict",
          mesh.time().constant(),
          mesh,
          IOobject::MUST_READ,
          IOobject::NO_WRITE
      )
   );


autoPtr<DataEntry<scalar> > cpValue(DataEntry<scalar>::New("cpValue", cpDict));
    
dimensionedScalar Cp("Cp", dimensionSet(0, 0, 0, 0, 1, 0, 0), 0.0);
And then when updating the value:
Code:
Cp = cpValue->value(mesh.time().timeOutputValue());
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   January 1, 2016, 02:13
Post
  #10
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi bruno,

FIrst a very happy new year to you..

I have done the same thing many times. i Have used the same code as you described above and compiled but again the error is same

Code:
   Different dimensions for =
     dimensions : [0 0 0 0 1 0 0] = [0 0 0 0 0 0 0]


    From function dimensionSet::operator=(const dimensionSet&) const
    in file dimensionSet/dimensionSet.C at line 171.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::abort() at ??:?
#2  Foam::dimensionSet::operator=(Foam::dimensionSet const&) const at ??:?
#3  ? at ??:?
#4  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#5  ? at ??:?
Aborted (core dumped)
I have checked my case many times for dimensions . I have created dictionary in createFields.h I have created cpdict in constant and created myDataFile in case according to same format.. about updating Cp values in calculation section i have done it before using Cp.
Code:
    Cp = cpValue->value(mesh.time().timeOutputValue());

                  solve
                  (
                         fvm::ddt(C) 
                       + (1/por)*fvm::div(phi, C) 
                       - fvm::laplacian(D, C) 
                       + fvm::Sp((ktrans/por), C) 
                       + fvm::Sp((lfc/por)*(p-lp), C) 
                      == 
                        (ktrans*Cp)

                 );
I am not clear about one thing why in error its not mentioning which dimensions are wrong or where is the error now...

Regards
Ajay
AJAY BHANDARI is offline   Reply With Quote

Old   January 1, 2016, 04:20
Post
  #11
Member
 
AJAY BHANDARI
Join Date: Jul 2015
Location: INDIA
Posts: 57
Rep Power: 11
AJAY BHANDARI is on a distinguished road
Hi bruno,

Mission accomplished. There was minor error . Instead of this
Code:
Cp = cpValue->value(mesh.time().timeOutputValue());
It should be
Code:
Cp.value() = cpValue->value(mesh.time().timeOutputValue());
It ran.. Thanks for the help and happy new year....
wyldckat likes this.
AJAY BHANDARI is offline   Reply With Quote

Old   January 1, 2016, 06:16
Default
  #12
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
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
Hi Ajay,

I'm glad you managed to figure it out! I only did a quick test yesterday and it seemed to have worked for me, but I didn't do much more testing with it.

And a Happy New Year!
Best regards,
Bruno
wyldckat is offline   Reply With Quote

Reply


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
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 09:46
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 07:42
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 06:18
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 08:56
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57


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