Setup of file U
Hello,
for my computations I need to precribe the velocity U by using simple functions for each of the three components (Ux, Uy, Uz). The functions should be applied to all six patches that are used and they look like following: Ux = 2 + x^2 Uy = 2(z-x)y Uz = 2 - z^2 To set these values to U I tried to write an application named setU, where the different functions are set to the three components of U. It did compile without giving an error message, but when I ran the applications the values were not set in U, so the file and the values did not change. But for example when I describe U by the expression U=omega ^ mesh.C() with dimensionedVector omega ( "omega", dimensionSet(0, 0, -1, 0, 0), vector(0, 0, 1000) ); and uncomment the three other lines, it works and the results of U = omega ^ mesh.C() are written to the six patches in the file U. But I need to calculate the components of U by the given three functions, so can anyone tell me how it is possible to evaluate the function in each cell and then write the results to the file U? ----------------------------------- setU ------------------------------------------------------------------ #include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" // Get times list instantList Times = runTime.times(); // set startTime and endTime depending on -time and -latestTime options # include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); # include "createMesh.H" for (label i=startTime; i<endTime; i++) { runTime.setTime(Times[i], i); Info<< "Time = " << runTime.timeName() << endl; mesh.readUpdate(); # include "createFields.H" //U = omega ^ mesh.C(); U.component(0) = 2 * factor + sqr(mesh.C().component(0)); U.component(1) = 2 * (mesh.C().component(2)-mesh.C().component(0)) * mesh.C().component(1); U.component(2) = 2 * factor - sqr(mesh.C().component(2)); U.write(); } Info<< "End\n" << endl; return(0); } ------------------------------------------------- U ------------------------------------------------------ FoamFile { version 2.0; format ascii; class volVectorField; location "0"; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { inside { type patch; value uniform (0 0 0); } outside { type patch; value uniform (0 0 0); } bottom { type patch; value uniform (0 0 0); } top { type patch; value uniform (0 0 0); } theta { type patch; value uniform (0 0 0); } theta1 { type patch; value uniform (0 0 0); } } |
Looking at Doxygen;
http://foam.sourceforge.net/doc/Doxy...tricField.html it looks like component just returns a value and can't be overwritten. Use replace instead. |
Thanks for your reply. Now it works...
|
How to use 'replace' for scalar fields? E.g.,
volScalarField Q ( IOobject ( "Q", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); // ... Q.internalField()[mesh.findCell(point(0.01, 0.01, 0))].replace (0, 20.0); produces this error: icoTempFoam_src.C:80: error: request for member 'replace' in '((Foam::Field<double>*)Q.Foam::GeometricField<Typ e, PatchField, GeoMesh>::internalField [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]())->Foam::Field<double>::<anonymous>.Foam::List<doubl e>::<anonymous>.Foam::UList<T>::operator[] [with T = double](mesh.Foam::fvMesh::<anonymous>.Foam::polyMesh::<a nonymous>.Foam::primitiveMesh::findCell(((const Foam::point&)((const Foam::point*)(& Foam::Vector<double>(((const double&)((const double*)(&1.00000000000000002081668171172168513294 309377670288085938e-2))), ((const double&)((const double*)(&1.00000000000000002081668171172168513294 309377670288085938e-2))), ((const double&)((const double*)(&0.0)))))))))', which is of non-class type 'double' |
All times are GMT -4. The time now is 18:09. |