|
[Sponsors] |
April 7, 2015, 03:43 |
How to modify vectorField in runtime
|
#1 |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
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 ) ), I appreciate your help. carlen |
|
April 12, 2015, 16:16 |
|
#2 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128 |
Quick answer: See this post of mine: http://www.cfd-online.com/Forums/ope...tml#post513974 - post #5
|
|
April 12, 2015, 21:12 |
|
#3 |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
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"); 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 ‘()’ ?) Thank you in advance, Carlen |
|
April 19, 2015, 14:04 |
|
#4 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128 |
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(); Code:
vectorField positions_; Info << positions_.size(); Therefore, my guess is that the error message you've gotten is actually pointing to another line!? Best regards, Bruno |
|
April 22, 2015, 00:06 |
|
#5 |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
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 |
|
April 22, 2015, 01:51 |
|
#6 |
Senior Member
|
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? |
|
April 22, 2015, 02:30 |
|
#7 |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
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; } 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 Thank you very much for you time. Best, carlen |
|
April 22, 2015, 02:46 |
|
#8 |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
Anyone who knows how to solve this problem, please, help me out. I have stuck here for one week.
Thank you in advance, carlen |
|
April 23, 2015, 02:06 |
|
#9 |
Senior Member
|
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. |
|
April 23, 2015, 09:01 |
|
#10 | |
Member
Join Date: Jul 2012
Posts: 67
Rep Power: 13 |
Quote:
Thank you very much for your help Alex. Best, carlen |
||
October 12, 2016, 08:34 |
|
#11 |
Member
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 12 |
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; } Any suggestions are appreciated, I've been stuck on this for weeks. |
|
|
|
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 |