|
[Sponsors] |
April 28, 2010, 06:55 |
Access particle data from functionObject
|
#1 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
Is there a way to access particle data from a functionObject? The standard way of accessing a field or a mesh in a functionObject is with this code:
Code:
const volVectorField& velocity = obr_.lookupObject<volVectorField>("U"); const fvMesh& mesh=refCast<const fvMesh>(obr_); Code:
const passiveParticleCloud myCloud = obr_.lookupObject<passiveParticleCloud>("kinematicCloud1"); Code:
/home/cedric/OpenFOAM/OpenFOAM-1.6.x/src/lagrangian/basic/lnInclude/passiveParticleCloud.H: In member function ‘virtual void Foam::patchParticleFunctionObject::write()’: /home/cedric/OpenFOAM/OpenFOAM-1.6.x/src/lagrangian/basic/lnInclude/passiveParticleCloud.H:58: fout: ‘Foam::passiveParticleCloud::passiveParticleCloud(const Foam::passiveParticleCloud&)’ is private Is there a public access function for lagrangian data? |
|
April 28, 2010, 11:08 |
|
#2 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
The reason why is does not work is due to following code in passiveParticleCloud.H
Code:
//- Disallow default bitwise copy construct passiveParticleCloud(const passiveParticleCloud&); //- Disallow default bitwise assignment void operator=(const passiveParticleCloud&); Code:
const passiveParticleCloud& myCloud = obr_.lookupObject<passiveParticleCloud>("kinematicCloud1"); |
|
April 28, 2010, 11:25 |
|
#3 |
Senior Member
Jiang
Join Date: Oct 2009
Location: Japan
Posts: 186
Rep Power: 17 |
Dear Cedric,
Could you give me some idea how to make my own functionObject ? Because nobody can help me. my purpose is to extract a plane data of internal domain in every time step, and save to disk. I noticed "surfaces functionObject" can do the similar thing, so I want to modify surfaces functionObject. I found it belongs to sampling,So I copy src/sampling directory to another position. I changed the libsampling.so to libmysampling.so in sampling\sampledSurface\sampledSurfaces, I found 2 places had name "surfaces", *.H file: public: //- Runtime type information TypeName("surfaces"); *.C file: PtrList<sampledSurface> newList ( dict.lookup("surfaces"), sampledSurface::iNew(mesh_) ); I changed these "surfaces" to "mysurfaces", and compiled, no problem. but when I used, had the following mistake, Starting time loop --> FOAM Warning : From function dlLibraryTable:pen(const dictionary& dict, const word& libsEntry, const TablePtr tablePtr) in file lnInclude/dlLibraryTableTemplates.C at line 68 library "libmysampling.so" did not introduce any new entries Unknown function type mysurfaces Valid functions are : 5 ( surfaces fieldAverage fieldMinMax sets probes ) From function functionObject::New(const word& name, const Time&, const dictionary&) in file db/functionObjects/functionObject/functionObject.C at line 89. FOAM exiting It seems that my modified name haven't been registed in functionObject. Could you give me some help ? I just want to copy the original sampling functionObject ,and modify "surfaces" functionObject to "mysurfaces" functionObject . Thanks. |
|
April 29, 2010, 05:00 |
|
#4 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
It is not nice to hijack someones thread.
I don't even understand your problem. You don't have to make a new functionObject as the surfaces functionObject can do everything that you want. Just put this in your controlDict: Code:
functions { type surfaces; functionObjectLibs ("libsampling.so"); surfaceFormat raw; interpolationScheme cellPointFace; fields ( p // define the fields you want to monitor U ); surfaces ( newPlane { type plane; basepoint (0 0 0); // coordinates of basepoint of the plane normalVector (0 1 0); // coordinates of the normal vector of the plane } ); } Code:
existingPatch { type patch; patchName wall; // name of an existing patch triangulate false; } |
|
April 29, 2010, 07:45 |
|
#5 | |
Member
Johan Spång
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 35
Rep Power: 17 |
Code:
const passiveParticleCloud& myCloud = obr_.lookupObject<passiveParticleCloud>("kinematicCloud1"); Quote:
Why convert it to a passiveParticleCloud at all? if you are using uncoupledKinematicParcelFoam then a functionObject having this code will access the cloud... Code:
const kinematicCloud& abstractBase = obr_.lookupObject<kinematicCloud> ("kinematicCloud"); passiveParticleCloud * pointer = (passiveParticleCloud*) &abstractBase; Info <<"testing access from functionObject" << endl; pointer -> info(); Info <<"done testing.." << endl; Regards /Johan Last edited by josp; April 29, 2010 at 08:12. |
||
April 29, 2010, 08:11 |
|
#6 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
The object is indeed a basicKinematicCloud, but the functionObject should work for any type of Cloud. The runtime error I get is:
Code:
--> FOAM FATAL ERROR: lookup of kinematicCloud1 from objectRegistry region0 successful but it is not a Cloud<passiveParticle>, it is a Cloud<basicKinematicParcel> From function objectRegistry::lookupObject<Type>(const word&) const in file /home/cedric/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 121. FOAM aborting #0 Foam::error::printStack(Foam::Ostream&) in "/home/cedric/OpenFOAM/OpenFOAM-1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #1 Foam::error::abort() in "/home/cedric/OpenFOAM/OpenFOAM-1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #2 Foam::Ostream& Foam::operator<< <Foam::error>(Foam::Ostream&, Foam::errorManip<Foam::error>) in "/home/cedric/OpenFOAM/cedric-1.6.x/applications/bin/linux64GccDPOpt/pimpleLagrangianFoam" #3 Foam::passiveParticleCloud const& Foam::objectRegistry::lookupObject<Foam::passiveParticleCloud>(Foam::word const&) const in "/home/cedric/OpenFOAM/cedric-1.6.x/lib/linux64GccDPOpt/libsimpleFunctionObjects.so" #4 Foam::patchParticleFunctionObject::write() in "/home/cedric/OpenFOAM/cedric-1.6.x/lib/linux64GccDPOpt/libsimpleFunctionObjects.so" #5 Foam::simpleFunctionObject::execute() in "/home/cedric/OpenFOAM/cedric-1.6.x/lib/linux64GccDPOpt/libsimpleFunctionObjects.so" #6 Foam::functionObjectList::execute() in "/home/cedric/OpenFOAM/OpenFOAM-1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #7 Foam::Time::operator++() in "/home/cedric/OpenFOAM/OpenFOAM-1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #8 main in "/home/cedric/OpenFOAM/cedric-1.6.x/applications/bin/linux64GccDPOpt/pimpleLagrangianFoam" #9 __libc_start_main in "/lib/libc.so.6" #10 _start at /build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:116 Code:
const basicKinematicCloud& myCloud = obr_.lookupObject<basicKinematicCloud>("kinematicCloud1"); or to const kinematicCloud& myCloud = obr_.lookupObject<kinematicCloud>("kinematicCloud1"); or to const Cloud& myCloud = obr_.lookupObject<Cloud>("kinematicCloud1"); Code:
patch/patchParticleFunctionObject/patchParticleFunctionObject.C: In member function ‘virtual void Foam::patchParticleFunctionObject::write()’: patch/patchParticleFunctionObject/patchParticleFunctionObject.C:78: fout: expected initializer before ‘&’ token Code:
const passiveParticleCloud& myCloud = obr_.lookupObject<basicKinematicCloud>("kinematicCloud1"); Code:
patch/patchParticleFunctionObject/patchParticleFunctionObject.C: In member function ‘virtual void Foam::patchParticleFunctionObject::write()’: patch/patchParticleFunctionObject/patchParticleFunctionObject.C:78: fout: ‘basicKinematicCloud’ was not declared in this scope patch/patchParticleFunctionObject/patchParticleFunctionObject.C:78: fout: no matching function for call to ‘Foam::objectRegistry::lookupObject(Foam::word&) const’ Code:
EXE_INC = \ ... -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/intermediate/lnInclude LIB_LIBS = \ ... -llagrangian \ -llagrangianIntermediate |
|
April 29, 2010, 08:22 |
|
#7 |
Member
Johan Spång
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 35
Rep Power: 17 |
Code:
patch/patchParticleFunctionObject/patchParticleFunctionObject.C: In member function ‘virtual void Foam::patchParticleFunctionObject::write()’: patch/patchParticleFunctionObject/patchParticleFunctionObject.C:78: fout: ‘basicKinematicCloud’ was not declared in this scope patch/patchParticleFunctionObject/patchParticleFunctionObject.C:78: fout: no matching function for call to ‘Foam::objectRegistry::lookupObject(Foam::word&) const’ But I doubt that will help for what you are trying to do. Sorry, I have no more ideas now except for the casting example in my previous post. /Johan |
|
April 29, 2010, 09:23 |
|
#8 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
Thank you for your effort! Indeed, I forgot to include kinematicParticle.H. Now I can read in a kinematicCloud with:
Code:
const kinematicCloud& myCloud = obr_.lookupObject<kinematicCloud>("kinematicCloud1"); For a more general approach, I can read in all sorts of Clouds with the code: Code:
const passiveParticleCloud myCloud(mesh, "kinematicCloud1"); |
|
April 29, 2010, 11:33 |
|
#9 |
Member
Johan Spång
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 35
Rep Power: 17 |
I think these are two completely different things. If you construct a passiveParticleCloud from file it just reads the few basic things that is required to represent the all types of clouds and particles, ignoring the rest.
I don't think you can arbitrarily convert different cloud types just by casting. Sure, if one is the base-class of the other it should work (polymorphism). Also remember that most things uses templates. For instance you can access Code:
basicKinematicCloud * q; q->size(); //ok q->Foam::Cloud<basicKinematicParcel>::size(); //ok rho() is introduced in the kinematicCloud to return the volScalarField rho. It can be called from q directly but not when using q as its sub-class: Code:
q->rho(); //ok q->Foam::Cloud<basicKinematicParcel >::rho(); //Will not compile since rho() not defined in Cloud<particleType>. Code:
const kinematicCloud& a = obr_.lookupObject<kinematicCloud> ("kinematicCloud"); basicKinematicCloud * q = (basicKinematicCloud*) &a; passiveParticleCloud * w = (passiveParticleCloud*) &a; Info << q->size() << endl; // gives correct number, in my case 100 Info << w->size() << endl; // compiles, runs and returns garbage!, in my case 1351820000 Code:
const kinematicCloud& a = obr_.lookupObject<kinematicCloud> ("kinematicCloud"); basicKinematicCloud * q = (basicKinematicCloud*) &a; forAllIter(basicKinematicCloud, *q, pIter) { Info << pIter().position() << endl; } (0.0283602845304 0.0234627817678 0.0360479880876) (-0.0332881768715 0.00226135358128 0.0628545323643) (-0.0187156570622 -0.0364530494542 0.0683987321281) (-0.0204049351688 -0.0250428155967 0.05823746172) (0.0287147114221 -0.0221560052747 0.0358643420419) /Johan |
|
April 30, 2010, 04:54 |
|
#10 |
Member
Cedric Van Holsbeke
Join Date: Dec 2009
Location: Belgium
Posts: 81
Rep Power: 17 |
I understand your explaination and your suggestion works. Thank you very much!
|
|
July 21, 2011, 13:03 |
Changing particle properties
|
#11 |
New Member
Kelvin Loh
Join Date: Mar 2009
Posts: 25
Rep Power: 17 |
Hi Johan and Cedric,
I have a query about the method that you're using to loop over the parcels, can I use it to modify the properties of the parcels? Also I have some issues with this snippet: Code:
const kinematicCloud& a = obr_.lookupObject<kinematicCloud> ("kinematicCloud"); basicKinematicCloud * q = (basicKinematicCloud*) &a; forAllIter(basicKinematicCloud, *q, pIter) { Info << pIter().position() << endl; } Any idea why the problem arises? Attached is the source of the main solver. Thank you. Regards, Kelvin |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
DPM UDF particle position using the macro P_POS(p)[i] | dm2747 | FLUENT | 0 | April 17, 2009 02:29 |
UDF Data Access Macro | Woo Meng Wai | FLUENT | 0 | November 6, 2007 21:23 |
how to output particle trajectory coordinate data | steven | CFX | 0 | July 13, 2006 18:49 |
Saving particle (DPM) data to file? | Philip | FLUENT | 2 | June 12, 2006 02:41 |
How to update polyPatchbs localPoints | liu | OpenFOAM Running, Solving & CFD | 6 | December 30, 2005 18:27 |