CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Constructing vector from three scalars (https://www.cfd-online.com/Forums/openfoam-solving/128953-constructing-vector-three-scalars.html)

mayank.dce2k7 January 24, 2014 15:37

Constructing vector from three scalars
 
Hi Foamers,

I have a simple question.....I have a vector defined as below:

const vector& r=p.position();

I have two components found as below:

scalar e= r.x(); scalar c=r.y();

I want to define a vector such that:

vector f= (e c 0);

where e & c are x-component and y-component respectively.......

I have tried tons of combination but I am getting error. I am not good as C++ so please help.....

Regards,
Mayank

Lieven January 24, 2014 15:59

Hi Mayank,

Simply try
Code:

vector f(e,c,0);
Cheers,

L

mayank.dce2k7 January 27, 2014 17:00

Thanks a lot Lieven.

I have an additional question:

since vector r=p.position(); its each component will have dimension 'meters'. Will my vector f(e,c,o) will also have dimensions of 'meters' and what will be the units associated with scalar e,c? ALso, if they are all unit less then how can I associate proper units with them?

lixx January 27, 2014 21:45

Quote:

Originally Posted by mayank.dce2k7 (Post 472031)
Thanks a lot Lieven.

I have an additional question:

since vector r=p.position(); its each component will have dimension 'meters'. Will my vector f(e,c,o) will also have dimensions of 'meters' and what will be the units associated with scalar e,c? ALso, if they are all unit less then how can I associate proper units with them?

What you need are dimensionedVector and dimensionedScalar.

mayank.dce2k7 January 28, 2014 00:08

Lixx, thanks for the reply.

Ya, you are right. I tried but couldn't get it right.Is there a simple way in which I can define vectors and scalars with their dimensions for immediate use in same file? I just want to use it in one file in lagrangian particle force library and then compile it.

Lieven January 28, 2014 01:21

Hi Mayank,

To construct a dimensionedScalar and dimensionedVector:
Code:

    dimensionedScalar scalarTest("s",dimLength,1.0);
    dimensionedVector vectorTest("v",dimLength,vector(1,1,1));

In your case, you could therefore write something like
Code:

dimensionedVector f("f",dimLength,vector(r.x(),r.y(),0));
But I'm wondering if the position() routine does not return a dimensionedVector directly. If that's the case you can write something as:
Code:

dimensionedVector f = p.position();
f.component(Vector::Z) = 0;

Cheers,

Lieven

mayank.dce2k7 January 28, 2014 01:49

Thanks Lieven. I'll give it a shot and let u know.

"dimLength" is for length in case one has to define velocity then what will be the replacement of "dimLength"?

lixx January 28, 2014 02:36

Quote:

Originally Posted by mayank.dce2k7 (Post 472070)
Thanks Lieven. I'll give it a shot and let u know.

"dimLength" is for length in case one has to define velocity then what will be the replacement of "dimLength"?

You can refer to $src/OpenFOAM/dimensionSet/dimensionSets.H, where $src means the src directory in your OpenFOAM installation.

Code:

extern const dimensionSet dimless;

extern const dimensionSet dimMass;
extern const dimensionSet dimLength;
extern const dimensionSet dimTime;
extern const dimensionSet dimTemperature;

extern const dimensionSet dimArea;
extern const dimensionSet dimVolume;
extern const dimensionSet dimVol;

extern const dimensionSet dimDensity;
extern const dimensionSet dimForce;
extern const dimensionSet dimEnergy;
extern const dimensionSet dimPower;

extern const dimensionSet dimVelocity;
extern const dimensionSet dimAcceleration;
extern const dimensionSet dimPressure;

In your case you should use 'dimVelocity'.

mayank.dce2k7 January 28, 2014 16:07

Thank you guys for your help. I tested what u guys suggested.

I tried something like this:

Code:

// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class CloudType>
Foam::forceSuSp Foam::newForce<CloudType>::calcNonCoupled
(
    const typename CloudType::parcelType& p,
    const scalar dt,
    const scalar mass,
    const scalar Re,
    const scalar muc
) const
{
    forceSuSp value(vector::zero, 0.0);
dimensionedVector D("D", dimForce, vector(1.0,0,0)); 
 
   
 
    value.Su() = D;

    return value;
}

I made sure that I assign 'value.Su()' a vector with dimension that of force but when I compiled the library i got these error messages:

Making dependency list for source file parcels/derived/basicReactingMultiphaseParcel/makeBasicReactingMultiphaseParcelSubmodels.C
Making dependency list for source file parcels/derived/basicReactingParcel/makeBasicReactingParcelSubmodels.C
Making dependency list for source file parcels/derived/basicThermoParcel/makeBasicThermoParcelSubmodels.C
Making dependency list for source file parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C
Making dependency list for source file parcels/derived/basicKinematicParcel/makeBasicKinematicParcelSubmodels.C
SOURCE=parcels/derived/basicKinematicParcel/makeBasicKinematicParcelSubmodels.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam211/src/finiteVolume/lnInclude -I/opt/openfoam211/src/meshTools/lnInclude -I/opt/openfoam211/src/lagrangian/basic/lnInclude -I/opt/openfoam211/src/lagrangian/distributionModels/lnInclude -I/opt/openfoam211/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam211/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam211/src/thermophysicalModels/properties/liquidProperties/lnInclude -I/opt/openfoam211/src/thermophysicalModels/properties/liquidMixtureProperties/lnInclude -I/opt/openfoam211/src/thermophysicalModels/properties/solidProperties/lnInclude -I/opt/openfoam211/src/thermophysicalModels/properties/solidMixtureProperties/lnInclude -I/opt/openfoam211/src/thermophysicalModels/reactionThermo/lnInclude -I/opt/openfoam211/src/thermophysicalModels/SLGThermo/lnInclude -I/opt/openfoam211/src/thermophysicalModels/radiationModels/lnInclude -I/opt/openfoam211/src/turbulenceModels -I/opt/openfoam211/src/transportModels/ -I/opt/openfoam211/src/transportModels/incompressible/lnInclude/ -I/opt/openfoam211/src/turbulenceModels/incompressible/turbulenceModel/lnInclude -I/opt/openfoam211/src/turbulenceModels/incompressible/RAS/lnInclude -I/opt/openfoam211/src/turbulenceModels/LES/LESdeltas/lnInclude -I/opt/openfoam211/src/turbulenceModels/incompressible/LES/lnInclude -I/opt/openfoam211/src/regionModels/regionModel/lnInclude -I/opt/openfoam211/src/regionModels/surfaceFilmModels/lnInclude -I/opt/openfoam211/src/dynamicFvMesh/lnInclude -I/opt/openfoam211/src/sampling/lnInclude -IlnInclude -I. -I/opt/openfoam211/src/OpenFOAM/lnInclude -I/opt/openfoam211/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/makeBasicKinematicParcelSubmodels.o
In file included from lnInclude/newForce.H:125:0,
from lnInclude/makeParcelForces.H:39,
from parcels/derived/basicKinematicParcel/makeBasicKinematicParcelSubmodels.C:31:
lnInclude/newForce.C: In member function ‘Foam::forceSuSp Foam::newForce<CloudType>::calcNonCoupled(const typename CloudType::parcelType&, Foam::scalar, Foam::scalar, Foam::scalar, Foam::scalar) const [with CloudType = Foam::KinematicCloud<Foam::Cloud<Foam::KinematicPa rcel<Foam::particle> > >, typename CloudType::parcelType = Foam::KinematicParcel<Foam::particle>, Foam::scalar = double]’:
parcels/derived/basicKinematicParcel/makeBasicKinematicParcelSubmodels.C:49:1: instantiated from here
lnInclude/newForce.C:82:5: error: no match for ‘operator=’ in ‘value.Foam::forceSuSp::Su() = D’
lnInclude/newForce.C:82:5: note: candidate is:
/opt/openfoam211/src/OpenFOAM/lnInclude/Vector.H:58:7: note: Foam::Vector<double>& Foam::Vector<double>::operator=(const Foam::Vector<double>&)
/opt/openfoam211/src/OpenFOAM/lnInclude/Vector.H:58:7: note: no known conversion for argument 1 from ‘Foam::dimensionedVector {aka Foam::dimensioned<Foam::Vector<double> >}’ to ‘const Foam::Vector<double>&’
make: *** [Make/linux64GccDPOpt/makeBasicKinematicParcelSubmodels.o] Error 1
mayank@mayank-Precision-WorkStation-T3400:~/OpenFOAM/mayank-2.1.1/platforms/linux64GccDPOpt/src/lagrangian/incompressible/intermediate$


All times are GMT -4. The time now is 08:48.