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

How to modify vectorField in runtime

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Carlen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 7, 2015, 03:43
Question How to modify vectorField in runtime
  #1
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Hi Foamers,

I am now facing a problem with respect to the use of vectorIOField.
My solver needs to read such a Field when it's changed during the simulation.
I used:
Code:
positionsFile_(this->coeffDict().lookup("positionsFile")),
    positions_
    (
        IOobject
        (
            positionsFile_,
            owner.db().time().constant(),
            owner.mesh(),
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    ),
However, it does not read the modified vectorField because vectorIOField does not support automatic rereading. How can I make it runtime modifiable?

I appreciate your help.

carlen
turbobluestreak likes this.
Carlen is offline   Reply With Quote

Old   April 12, 2015, 16:16
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
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
Quick answer: See this post of mine: http://www.cfd-online.com/Forums/ope...tml#post513974 - post #5
wyldckat is offline   Reply With Quote

Old   April 12, 2015, 21:12
Default
  #3
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Hi bruno,
I read you post and now my code looks like this
Code:
const word positionsFile_ = this->coeffDict().lookup("positionsFile");
        IOdictionary Positions
        (
            IOobject
            (
                positionsFile_,
                this->owner.db().time().constant(),
                this->owner.mesh(),
                IOobject::MUST_READ_IF_MODIFIED,
                IOobject::NO_WRITE
            )
        );

        vectorField positions_ = Positions.lookup("CloudPositions");
It seems that the above code can update the posistions_ at every timestep, but the updated value is not used when I integrate this piece of code in ManualInjection Model and it gives me an error just before ";" in the following code.
Code:
template<class CloudType>
Foam::label Foam::carlenManualInjection<CloudType>::parcelsToInject
(
    const scalar time0,
    const scalar time1
)
{
    if ((time0 >= 0.0) && (time0 < duration_))
    {
        const word positionsFile_ = this->coeffDict().lookup("positionsFile");
        IOdictionary Positions
        (
            IOobject
            (
                positionsFile_,
                this->owner.db().time().constant(),
                this->owner.mesh(),
                IOobject::MUST_READ_IF_MODIFIED,
                IOobject::NO_WRITE
            )
        );

        vectorField positions_ = Positions.lookup("CloudPositions");
        return positions_.size();
        //Info << "positions_.size(): " << positions_.size() << endl;
    }
    else
    {
        return 0;
    }
}
Code:
error: invalid use of member function (did you forget the ‘()’ ?)
Any idea how I can solve this problem?

Thank you in advance,
Carlen
Carlen is offline   Reply With Quote

Old   April 19, 2015, 14:04
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
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 Carlen,

My guess is that the error you're looking at is actually something that happens as a consequence of an earlier error message.

Uhm.. I tested this just now and I got the same error message, without any previous errors... well this is certainly weird...

OK, I reproduced the error because I used this:
Code:
    vectorField positions_();
    Info << positions_.size();
This is because the first line actually defines a function and not a variable. If I do this:
Code:
    vectorField positions_;
    Info << positions_.size();
I no longer get an error message.

Therefore, my guess is that the error message you've gotten is actually pointing to another line!?

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   April 22, 2015, 00:06
Default
  #5
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Hi Bruno,
Thanks for your reply.
I wasnt pointing to any line in my code. I double checked my code and it does not seem to be wrong. Any idea how to solve this problem?

Best regards,
carlen
Carlen is offline   Reply With Quote

Old   April 22, 2015, 01:51
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Can you please tell us what is this in both cases? Well, it is clear that in the second case it is carlenManualInjection class. Has it got owner property? Or is it a method?
alexeym is offline   Reply With Quote

Old   April 22, 2015, 02:30
Default
  #7
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Hi Alex,
I wrote this injector based on MaunalInjection. What I did is basically using an IOdictionary to read positions, diameters and velocities of particles from file.
Code:
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

template<class CloudType>
Foam::carlenManualInjection<CloudType>::carlenManualInjection
(
    const dictionary& dict,
    CloudType& owner,
    const word& modelName
)
:
    InjectionModel<CloudType>(dict, owner, modelName, typeName),
    positionsFile_(this->coeffDict().lookup("positionsFile")),
    Positions
    (
        IOobject
        (
            positionsFile_,
            owner.db().time().constant(),
            owner.mesh(),
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    ),
    positions_(Positions.lookup("CloudPositions")),

    injectorCells_(positions_.size(), -1),
    injectorTetFaces_(positions_.size(), -1),
    injectorTetPts_(positions_.size(), -1),

    diametersFile_(this->coeffDict().lookup("diametersFile")),
    Diameters
    (
        IOobject
        (
            diametersFile_,
            owner.db().time().constant(),
            owner.mesh(),
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    ),
    diameters_(Diameters.lookup("CloudDiameters")),

    velocitiesFile_(this->coeffDict().lookup("velocitiesFile")),
    Velocities
    (
        IOobject
        (
            velocitiesFile_,
            owner.db().time().constant(),
            owner.mesh(),
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    ),
    velocities_(Velocities.lookup("CloudVelocities")),

    duration_(readScalar(this->coeffDict().lookup("duration"))),
    ignoreOutOfBounds_
    (
        this->coeffDict().lookupOrDefault("ignoreOutOfBounds", false)
    )

{
    updateMesh();
    
    duration_ = owner.db().time().userTimeToTime(duration_);//Injecting parcels at every timestep
  
    // Determine volume of particles to inject
    this->volumeTotal_ = sum(pow3(diameters_))*pi/6.0;
}
I want to write an injector allowing me to inject new particles at every timestep based on properties provided in the constant directory. These properties are updated at every timestep. So far I am able to use the READ_IF_MODIFIED option and you can see that properties are read at every timestep,
Code:
regIOobject::readIfModified() : 
    Re-reading object sprayCloudPositions from file "/home/carlen/OpenFOAM/carlen-2.3.1/carlenVOFLPT/run/VOFLPT/constant/Secondary/sprayCloudPositions"
regIOobject::readIfModified() : 
    Re-reading object sprayCloudVelocities from file "/home/carlen/OpenFOAM/carlen-2.3.1/carlenVOFLPT/run/VOFLPT/constant/Secondary/sprayCloudVelocities"
regIOobject::readIfModified() : 
    Re-reading object sprayCloudDiameters from file "/home/carlen/OpenFOAM/carlen-2.3.1/carlenVOFLPT/run/VOFLPT/constant/Secondary/sprayCloudDiameters"
Courant Number mean: 2.4615003e-07 max: 0.0014217271
Courant Number mean: 3.7985957e-06 max: 3.924e-06
Max Courant Number: 0.0014217271
deltaT = 0.0001
Time = 0.0002

MULES: Solving for alpha.water
Liquid phase volume fraction = 4.6875e-05  Min(alpha1) = 0  Min(alpha2) = 0
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for T, Initial residual = 1.5245762e-07, Final residual = 2.5596714e-13, No Iterations 1
min(T) 300
GAMG:  Solving for p_rgh, Initial residual = 0.85150808, Final residual = 0.0021843274, No Iterations 3
max(U) 1.3741028
min(p_rgh) 99764.018
GAMGPCG:  Solving for p_rgh, Initial residual = 0.079965064, Final residual = 5.2407171e-08, No Iterations 5
max(U) 0.17640096
min(p_rgh) 99987.999

Solving 3-D cloud sprayCloud
Cloud: sprayCloud
    Current number of parcels       = 0
    Current mass in system          = 0
    Linear momentum                 = (0 0 0)
   |Linear momentum|                = 0
    Linear kinetic energy           = 0
    model1:
        number of parcels added     = 0
        mass introduced             = 0
    Parcels absorbed into film      = 0
    New film detached parcels       = 0
    Parcel fate (number, mass)
      - escape                      = 0, 0
      - stick                       = 0, 0
    Temperature min/max             = 0, 0
    Mass transfer phase change      = 0
    D10, D32, Dmax (mu)             = 0, 0, 0
    Liquid penetration 95% mass (m) = 0

diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for Ux, Initial residual = 1, Final residual = 3.8920766e-09, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 1, Final residual = 4.420232e-09, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 1, Final residual = 3.9743131e-09, No Iterations 2
DILUPBiCG:  Solving for O2, Initial residual = 0.00083242377, Final residual = 4.3944334e-08, No Iterations 1
DILUPBiCG:  Solving for H2O, Initial residual = 0, Final residual = 0, No Iterations 0
DILUPBiCG:  Solving for h, Initial residual = 0.00059659358, Final residual = 1.245717e-08, No Iterations 1
T gas min/max   = 300, 300
GAMG:  Solving for p, Initial residual = 0.99999999, Final residual = 0.050075538, No Iterations 1
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 9.8099024e-08, global = -2.729417e-16, cumulative = -2.729417e-16
GAMG:  Solving for p, Initial residual = 0.024331341, Final residual = 1.2388827e-07, No Iterations 4
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 9.8098944e-08, global = -2.7209419e-16, cumulative = -5.4503589e-16
smoothSolver:  Solving for epsilon, Initial residual = 0.058494388, Final residual = 1.5872662e-10, No Iterations 2
smoothSolver:  Solving for k, Initial residual = 1, Final residual = 4.525064e-09, No Iterations 2
ExecutionTime = 347.26 s
but particles are not injected. How can I solve this problem? Or please kindly tell me if you know another approach as to how to write a time dependent injector.

Thank you very much for you time.

Best,
carlen
Carlen is offline   Reply With Quote

Old   April 22, 2015, 02:46
Default
  #8
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Anyone who knows how to solve this problem, please, help me out. I have stuck here for one week.

Thank you in advance,
carlen
Carlen is offline   Reply With Quote

Old   April 23, 2015, 02:06
Default
  #9
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

I am not quite sure if I get right what you are doing. So here are my questions:

1. Is it standard solver or your own?

2. If you have something that generates sprayCloud* files on every time step, why this thing can not just call a carlenManualInjection class method with content of the files as a parameters?

3. This is in fact commentary, not a question. As the files are re-read by regIOobject class, you can look at the implementation of this functionality in the class. Or even add regIOobject to the base classes of your class and override read and readIfModified methods.
alexeym is offline   Reply With Quote

Old   April 23, 2015, 09:01
Default
  #10
Member
 
Join Date: Jul 2012
Posts: 67
Rep Power: 13
Carlen is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Hi,

I am not quite sure if I get right what you are doing. So here are my questions:

1. Is it standard solver or your own?

2. If you have something that generates sprayCloud* files on every time step, why this thing can not just call a carlenManualInjection class method with content of the files as a parameters?

3. This is in fact commentary, not a question. As the files are re-read by regIOobject class, you can look at the implementation of this functionality in the class. Or even add regIOobject to the base classes of your class and override read and readIfModified methods.
I am using my own solver and the carlenManualInjection is written based on ManualInjection model. I have figured out a nasty solution for my problem, which is to update the posistions_, diameters_ and velocities in every member function. It works now but I am wondering if there are more elegant solutions.

Thank you very much for your help Alex.

Best,
carlen
Carlen is offline   Reply With Quote

Old   October 12, 2016, 08:34
Default
  #11
Member
 
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 12
ali.m.1 is on a distinguished road
Hi Carlen

I think I'm doing something fairly similar to you, except rather than making my own injection model, I've just modified 'kinematicLookupTableInjection'. I've added another column to the lookupTable, and it works fine: however the injector only reads the file when initialising the solution.
How did you make the injector re-read the dictionaries?

Code:
template<class CloudType>
Foam::label Foam::KinematicLookupTableInjection<CloudType>::parcelsToInject
(
     scalar time0, //was const
     scalar time1   //was const
)
{
    scalar parcelsToInject = 0;
    if ((time0 >= 0.0) && (time0 < duration_))
    {

       // return floor(injectorCells_.size()*(time1 - time0)*parcelsPerSecond_);
        forAll(injectors_, i)
        {
        parcelsToInject += injectors_[i].numParticles();
        }

    Info<< "Time1 = " << time1 << nl << endl;
    Info<< "Time0 = " << time0 << nl << endl;
    Info<< "parcelsToInject = " << parcelsToInject << nl << endl;
    }

        return parcelsToInject; 

}
Above is the way I define 'parcelsToInject'. numParticles() is the last column in the lookupTable. The info statement "parcelsToInject" never changes, even although the lookupTable changes every timestep.

Any suggestions are appreciated, I've been stuck on this for weeks.
ali.m.1 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 set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 06:09
Problem in3D model processing mebinitap OpenFOAM 2 December 12, 2014 04:40
[Other] Modify mesh runtime Daniele111 OpenFOAM Meshing & Mesh Conversion 8 December 19, 2010 15:43
how can i modify boundaryPatch value at runtime nt31921a OpenFOAM Programming & Development 2 October 28, 2010 21:10
Modify my mesh runtime Daniele111 OpenFOAM Running, Solving & CFD 0 October 9, 2010 07:23


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