コード例 #1
0
ファイル: exercise_1.cpp プロジェクト: cvejoski/CUDALab
void print_2D_view(tensor<T, M>& a) {
	for (unsigned int i = 0; i<a.shape(0); i++){
		for (unsigned int j = 0; j<a.shape(1); j++)
			cout<<a(i, j)<<" ";
		cout<<endl;
	}
}
コード例 #2
0
void update(int value){
	reduce(&P_odd,even_to_odd);
	P_odd.normalize();
	reduce(&P_even,odd_to_even);
	P_even.normalize(); 	
	glutPostRedisplay();
	glutTimerFunc(2, tick, 0);
};
コード例 #3
0
void time_step(){
	reduce(&P_odd,even_to_odd);
	P_odd.normalize();
	drift(&P_odd, &N_tensor, 1000);
	reduce(&P_even,odd_to_even);
	P_even.normalize(); 	
	drift(&P_even, &N_tensor, 1000);
};
コード例 #4
0
ファイル: curand_dlibapi.cpp プロジェクト: 20337112/dlib
        void curand_generator::
        fill_uniform (
            tensor& data
        )
        {
            if (data.size() == 0)
                return;

            CHECK_CURAND(curandGenerateUniform((curandGenerator_t)handle, data.device(), data.size()));
        }
コード例 #5
0
ファイル: tensor.hpp プロジェクト: boostorg/ublas
	tensor (const tensor<value_type, other_layout> &other)
		: tensor_expression_type<self_type> ()
		, extents_ (other.extents())
		, strides_ (other.extents())
		, data_    (other.extents().product())
	{
		copy(this->rank(), this->extents().data(),
				 this->data(), this->strides().data(),
				 other.data(), other.strides().data());
	}
コード例 #6
0
ファイル: exercise_1.cpp プロジェクト: cvejoski/CUDALab
void print_3D_view(tensor<T, M>& a) {
	for (unsigned int k = 0; k<a.shape(0); k++) {
		cout<<"dimension 0: "<<k<<endl;
		for (unsigned int i = 0; i<a.shape(1); i++){
			for (unsigned int j = 0; j<a.shape(2); j++)
				cout<<a(k, i, j)<<" ";
			cout<<endl;
		}
	}
}
コード例 #7
0
Foam::vector Foam::finiteRotation::eulerAngles(const tensor& rotT)
{
    // Create a vector containing euler angles (x = roll, y = pitch, z = yaw)
    vector eulerAngles;

    scalar& rollAngle = eulerAngles.x();
    scalar& pitchAngle = eulerAngles.y();
    scalar& yawAngle = eulerAngles.z();

    // Calculate roll angle
    rollAngle = atan2(rotT.yz(), rotT.zz());

    // Use mag to avoid negative value due to round-off
    // HJ, 24/Feb/2016
    // Bugfix: sqr. SS, 18/Apr/2016
    const scalar c2 = sqrt(sqr(rotT.xx()) + sqr(rotT.xy()));

    // Calculate pitch angle
    pitchAngle = atan2(-rotT.xz(), c2);

    const scalar s1 = sin(rollAngle);
    const scalar c1 = cos(rollAngle);

    // Calculate yaw angle
    yawAngle = atan2(s1*rotT.zx() - c1*rotT.yx(), c1*rotT.yy() - s1*rotT.zy());

    return eulerAngles;
}
コード例 #8
0
ファイル: entropy.hpp プロジェクト: e-thereal/capputils
float entropy(const tensor<float, dim, device>& tensor, float totalSum = 1.f) {
  if (totalSum == 1.f) {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float(), 0.f, thrust::plus<float>());
  } else {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float_norm(totalSum), 0.f, thrust::plus<float>());
  }
}
コード例 #9
0
ファイル: SurfaceMesh.cpp プロジェクト: ctlee/gamer
Vector getNormalFromTangent(const tensor<double, 3, 2> tangent)
{
    Vector xp;
    // upper right...
    xp[0] = -tangent.get(1, 2);  // x
    xp[1] = tangent.get(0, 2);   // y
    xp[2] = -tangent.get(0, 1);  // z
    // lower left...
    // xp[0] = tangent.get(2,1);
    // xp[1] = -tangent.get(2,0);
    // xp[2] = tangent.get(1,0);
    return xp;
}
コード例 #10
0
ファイル: entropy.hpp プロジェクト: e-thereal/capputils
double entropy(const tensor<double, dim, device>& tensor, double totalSum = 1.0) {
  if (totalSum == 1.0) {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_double(), 0.0, thrust::plus<double>());
  } else {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_double_norm(totalSum), 0.0, thrust::plus<double>());
  }
}
コード例 #11
0
ファイル: tensor_tools.cpp プロジェクト: markpp/MTB
    void log10 (
        tensor& dest,
        const tensor& src
    )
    {
        DLIB_CASSERT(dest.size() == src.size());

#ifdef DLIB_USE_CUDA
        cuda::log10(dest,src);
#else
        dest = log10(mat(src));
#endif
    }
コード例 #12
0
ファイル: curand_dlibapi.cpp プロジェクト: 20337112/dlib
        void curand_generator::
        fill_gaussian (
            tensor& data,
            float mean,
            float stddev
        )
        {
            if (data.size() == 0)
                return;

            CHECK_CURAND(curandGenerateNormal((curandGenerator_t)handle, 
                                        data.device(),
                                        data.size(),
                                        mean,
                                        stddev));
        }
コード例 #13
0
ファイル: isoSurface.C プロジェクト: BarisCumhur/OpenFOAM-dev
bool Foam::isoSurface::noTransform(const tensor& tt) const
{
    return
        (mag(tt.xx()-1) < mergeDistance_)
     && (mag(tt.yy()-1) < mergeDistance_)
     && (mag(tt.zz()-1) < mergeDistance_)
     && (mag(tt.xy()) < mergeDistance_)
     && (mag(tt.xz()) < mergeDistance_)
     && (mag(tt.yx()) < mergeDistance_)
     && (mag(tt.yz()) < mergeDistance_)
     && (mag(tt.zx()) < mergeDistance_)
     && (mag(tt.zy()) < mergeDistance_);
}
コード例 #14
0
ファイル: tensor_tools.cpp プロジェクト: markpp/MTB
    void scale_rows (
        tensor& out,
        const tensor& m,
        const tensor& v
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m));
        DLIB_CASSERT(is_vector(v));
        if (m.size() == 0 && v.size() == 0)
            return;
        DLIB_CASSERT(m.size() != 0);
        DLIB_CASSERT(m.num_samples() == v.size());

#ifdef DLIB_USE_CUDA
        cuda::scale_rows(out, m, v);
#else
        out = scale_rows(mat(m), mat(v));
#endif
    }
コード例 #15
0
ファイル: field.cpp プロジェクト: gravmath/Projects
//******************************************************************************
//Name:  GetInterpTensor                                                       *
//                                                                             *
//Purpose:  get the interpolated tensor at an arbitrary position               *
//                                                                             *
//Takes: pointer to the position as packed in a tensor                         *
//******************************************************************************
tensor field::GetInterpTensor(tensor &pos)
{
   double position[3];
   tensor ret_val;

   for(int i = 0; i < 3; i++)  position[i] = pos.Val(i);

   ret_val <= GetInterpTensor(position);

   return ret_val;
}
コード例 #16
0
ファイル: tensor_tools.cpp プロジェクト: markpp/MTB
    void scale_columns (
        tensor& out,
        const tensor& m,
        const tensor& v
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m));
        DLIB_CASSERT(is_vector(v));
        if (m.size() == 0 && v.size() == 0)
            return;
        DLIB_CASSERT(m.size() != 0);
        DLIB_CASSERT(m.size()/m.num_samples() == v.size());

#ifdef DLIB_USE_CUDA
        cuda::scale_columns(out, m, v);
#else
        DLIB_CASSERT(false, "shouldn't be called right now");
        out = scale_columns(mat(m), mat(v));
#endif
    }
コード例 #17
0
ファイル: field.cpp プロジェクト: gravmath/Projects
//******************************************************************************
//Name:  SetTensor                                                             *
//                                                                             *
//Purpose:  Set the tensor portion of the field                                *
//                                                                             *
//Takes: takes a position in tensor form and the address of the tensor         *
//******************************************************************************
void field::SetTensor(const tensor &pos, const tensor &rval)
{

   int i;
   double position[3];

   for( i = 0; i < 3; i++) position[i] = pos.Val(i);

   SetTensor(position, rval);

}
コード例 #18
0
void Foam::myVelocityFvPatchVectorField::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    // Variablen/ Felder
    const volVectorField& u = db().lookupObject<volVectorField>("u");
    //fvPatchVectorField& u_b = *this;
    tmp<vectorField> tu_b = *this;
    vectorField& u_b = tu_b();

    const tmp<vectorField> tn = this->patch().nf();
    const vectorField& n = tn();

    tmp<volTensorField> tGradU = fvc::grad(u);
    const volTensorField gradU = tGradU();
    tmp<vectorField> tD = patch().delta();
    const vectorField& D = tD();
    const labelList& bcs = patch().faceCells();

    for(int i=0; i<patch().size(); i++) {

        const label bc = bcs[i];
        const vector normal = n[i];
        const tensor Jac_u = gradU[bc];
        const vector u_bc = u[bc];
        const vector Di = D[i];

        vector u_b_extrapolated;

        u_b_extrapolated.component(0) = u_bc.component(0) +
                                        Jac_u.component(tensor::XX) * Di.component(0) +
                                        Jac_u.component(tensor::XY) * Di.component(1) +
                                        Jac_u.component(tensor::XZ) * Di.component(2);

        u_b_extrapolated.component(1) = u_bc.component(1) +
                                        Jac_u.component(tensor::YX) * Di.component(0) +
                                        Jac_u.component(tensor::YY) * Di.component(1) +
                                        Jac_u.component(tensor::YZ) * Di.component(2);

        u_b_extrapolated.component(2) = u_bc.component(2) +
                                        Jac_u.component(tensor::ZX) * Di.component(0) +
                                        Jac_u.component(tensor::ZY) * Di.component(1) +
                                        Jac_u.component(tensor::ZZ) * Di.component(2);

        u_b[i] = u_b_extrapolated - (u_b_extrapolated & normal) * normal;

    }

    //Info << u_b << endl;

    fixedValueFvPatchVectorField::updateCoeffs();     // updated_ = true

}
コード例 #19
0
ファイル: field.cpp プロジェクト: gravmath/Projects
//******************************************************************************
//Name:  SetTensor                                                             *
//                                                                             *
//Purpose:  Set the tensor portion of the field                                *
//                                                                             *
//Takes: takes a pointer to a position array and the address of the tensor     *
//******************************************************************************
void field::SetTensor(int *indices, const tensor &rval)
{
   int *index;
	int *r_index;
	int i, j, temp;
	double value;

//Error check
	if( rval.p->num_indices != (p->num_indices - 3) )
		error("SetTensor error:","cannot assign the tensor to a field point");

	for(i = 3; i < p->num_indices; i++)
	{
	  if( rval.p->range[i-3] != p->range[i] )
		  error("SetTensor error:","cannot assign the tensor to a field point");
	}

//set up the index array that indexes into the field and set the specified position
	index = new int[p->num_indices];
   for( i = 0; i < 3; i++) index[i] = indices[i];

//set up the index array that indexes into the rval tensor
	r_index = new int[rval.p->num_indices];

//set the field
	for(i = 0; i < rval.p->product; i++)
	{
		//pack the r_index array (see tensor::Contract)
		temp = 0;
		for(j = 0; j < rval.p->num_indices - 1; j++)
		{
		  r_index[j] = (i - i%rval.p->scales[j] - temp)/rval.p->scales[j];
		  temp += r_index[j] * rval.p->scales[j];
		}

		r_index[j] = (i - temp)/rval.p->scales[j];

		//complete the index array with the tensor indices
		for(j = 3; j < p->num_indices; j++) index[j] = r_index[j - 3];

      value = rval.Val(r_index);

      //put the rval tensors value into the field at specified position
      Set(value,index);
	}

  //Clean up
  delete [] index;
  delete [] r_index;

}
コード例 #20
0
ファイル: field.cpp プロジェクト: gravmath/Projects
//******************************************************************************
//Name:  GetTensor                                                             *
//                                                                             *
//Purpose:  get the tensor portion of the field given the position             *
//                                                                             *
//Takes: position stored as a tensor                                           *
//******************************************************************************
tensor field::GetTensor(const tensor &pos)
{

   int i;
   double position[3];

   tensor temp;

   for( i = 0; i < 3; i++ ) position[i] = pos.Val(i);

   temp <= GetTensor(position);

   return temp;
}
コード例 #21
0
ファイル: tensor_tools.cpp プロジェクト: markpp/MTB
    void scale_rows2 (
        float beta, 
        tensor& out,
        const tensor& m1,
        const tensor& m2,
        const tensor& v1,
        const tensor& v2
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m1));
        DLIB_CASSERT(have_same_dimensions(out,m2));
        DLIB_CASSERT(have_same_dimensions(v1,v2));
        DLIB_CASSERT(is_vector(mat(v1))); 
        DLIB_CASSERT(v1.size() == m1.num_samples());

#ifdef DLIB_USE_CUDA
        cuda::scale_rows2(beta, out, m1, m2, v1, v2);
#else
        if (beta == 0)
            out = scale_rows(mat(m1) - scale_rows(mat(m2),mat(v1)), mat(v2));
        else
            out = beta*mat(out) + scale_rows(mat(m1) - scale_rows(mat(m2),mat(v1)), mat(v2));
#endif
    }
コード例 #22
0
Foam::scalar Foam::finiteRotation::rotAngle(const tensor& rotT)
{
    // Alternative formulation: Daniel Schmode, 15/Feb/2009
    scalar x = rotT.zy() - rotT.yz();
    scalar y = rotT.xz() - rotT.zx();
    scalar z = rotT.yx() - rotT.xy();

    scalar r = hypot(x, hypot(y, z));
    scalar t = tr(rotT);

    return atan2(r, t - 1);
}
コード例 #23
0
//- evaluate gradients needed for optimisation
void surfaceOptimizer::evaluateGradients
(
    const scalar& K,
    vector& gradF,
    tensor& gradGradF
) const
{
    gradF = vector::zero;
    gradGradF = tensor::zero;

    tensor gradGradLt(tensor::zero);
    gradGradLt.xx() = 4.0;
    gradGradLt.yy() = 4.0;

    forAll(trias_, triI)
    {
        const point& p0 = pts_[trias_[triI][0]];
        const point& p1 = pts_[trias_[triI][1]];
        const point& p2 = pts_[trias_[triI][2]];

        if( magSqr(p1 - p2) < VSMALL ) continue;

        const scalar LSqrTri
        (
            magSqr(p0 - p1) +
            magSqr(p2 - p0)
        );

        const scalar Atri =
            0.5 *
            (
                (p1.x() - p0.x()) * (p2.y() - p0.y()) -
                (p2.x() - p0.x()) * (p1.y() - p0.y())
            );

        const scalar stab = sqrt(sqr(Atri) + K);

        const scalar Astab = Foam::max(ROOTVSMALL, 0.5 * (Atri + stab));

        const vector gradAtri
        (
            0.5 * (p1.y() - p2.y()),
            0.5 * (p2.x() - p1.x()),
            0.0
        );

        const vector gradAstab = 0.5 * (gradAtri + Atri * gradAtri / stab);

        const tensor gradGradAstab =
            0.5 *
            (
                (gradAtri * gradAtri) / stab -
                sqr(Atri) * (gradAtri * gradAtri) / pow(stab, 3)
            );

        const vector gradLt(4.0 * p0 - 2.0 * p1 - 2.0 * p2);

        //- calculate the gradient
        const scalar sqrAstab = sqr(Astab);
        gradF += gradLt / Astab - (LSqrTri * gradAstab) / sqrAstab;

        //- calculate the second gradient
        gradGradF +=
            gradGradLt / Astab -
            twoSymm(gradLt * gradAstab) / sqrAstab -
            gradGradAstab * LSqrTri / sqrAstab +
            2.0 * LSqrTri * (gradAstab * gradAstab) / (sqrAstab * Astab);
    }

    //- stabilise diagonal terms
    if( mag(gradGradF.xx()) < VSMALL ) gradGradF.xx() = VSMALL;
    if( mag(gradGradF.yy()) < VSMALL ) gradGradF.yy() = VSMALL;
}
コード例 #24
0
ファイル: exercise_1.cpp プロジェクト: cvejoski/CUDALab
tensor<T, M> add_for(tensor<T, M>& a, tensor<T, M>& b) {
	tensor<T, M> result(extents[a.size()]);
	for (unsigned int i=0; i<a.size(); i++)
		result[i] = a[i] + b[i];
	return result;
}
コード例 #25
0
ファイル: exercise_1.cpp プロジェクト: cvejoski/CUDALab
tensor<T, M> add_apply(tensor<T, M>& a, tensor<T, M>& b) {
	tensor<T, M> result(extents[a.size()]);
	apply_binary_functor(result, a, b, BF_ADD);
	return result;
}
コード例 #26
0
ファイル: tensor.hpp プロジェクト: marcinlos/iga-ads
void zero(tensor<T, Rank>& tensor) {
    tensor.fill_with_zeros();
}
Foam::porosityZone::porosityZone
(
    const word& name,
    const fvMesh& mesh,
    const dictionary& dict
)
:
    name_(name),
    mesh_(mesh),
    dict_(dict),
    cellZoneID_(mesh_.cellZones().findZoneID(name)),

#if EXTBRANCH==1
    coordSys_(dict, mesh),
#elif OFPLUSBRANCH==1
    coordSys_(mesh, dict),
#else
    #if OFVERSION<230
        coordSys_(dict, mesh),
    #else
        coordSys_(mesh, dict),
    #endif
#endif

//#if OFVERSION<230 || EXTBRANCH == 1
//    coordSys_(dict, mesh),
//#else
//    coordSys_(mesh, dict),
//#endif

    porosity_( readScalar( dict_.lookup("porosity") ) ),
    addedMassCoeff_( readScalar( dict_.lookup("gammaAddedMass") ) ),
    D_("D", dimensionSet(0, -2, 0, 0, 0), tensor::zero),
    F_("F", dimensionSet(0, -1, 0, 0, 0), tensor::zero)
{
    Info<< "Creating porous zone: " << name_ << endl;

    autoPtr<Foam::porosityCoefficient> pcPtr( Foam::porosityCoefficient::New( dict ) );

    bool foundZone = (cellZoneID_ != -1);
    reduce(foundZone, orOp<bool>());

    if (!foundZone && Pstream::master())
    {
        FatalErrorIn
        (
            "Foam::porosityZone::porosityZone"
            "(const fvMesh&, const word&, const dictionary&)"
        )   << "cannot find porous cellZone " << name_
            << exit(FatalError);
    }

    // porosity
    if (porosity_ <= 0.0 || porosity_ > 1.0)
    {
        FatalIOErrorIn
        (
                "Foam::porosityZone::porosityZone"
                "(const fvMesh&, const word&, const dictionary&)",
                dict_
        )
        << "out-of-range porosity value " << porosity_
        << exit(FatalIOError);
    }

    // local-to-global transformation tensor
#if EXTBRANCH==1
    const tensor& E = coordSys_.R();
#elif OFPLUSBRANCH==1
    const tensor E = coordSys_.R().R();
#else
    #if OFVERSION<230
        const tensor& E = coordSys_.R();
    #else
        const tensor E = coordSys_.R().R();
    #endif
#endif

    dimensionedVector d( pcPtr->linearCoefficient() );

    if (D_.dimensions() != d.dimensions())
    {
        FatalIOErrorIn
        (
            "Foam::porosityZone::porosityZone"
            "(const fvMesh&, const word&, const dictionary&)",
            dict_
        )   << "incorrect dimensions for d: " << d.dimensions()
        << " should be " << D_.dimensions()
        << exit(FatalIOError);
    }

    checkNegativeResistance(d);

    D_.value().xx() = d.value().x();
    D_.value().yy() = d.value().y();
    D_.value().zz() = d.value().z();
    D_.value() = (E & D_ & E.T()).value();


    dimensionedVector f( pcPtr->quadraticCoefficient() );

    if (F_.dimensions() != f.dimensions())
    {
        FatalIOErrorIn
        (
            "Foam::porosityZone::porosityZone"
            "(const fvMesh&, const word&, const dictionary&)",
            dict_
        )   << "incorrect dimensions for f: " << f.dimensions()
        << " should be " << F_.dimensions()
        << exit(FatalIOError);
    }

    checkNegativeResistance(f);

    F_.value().xx() = 0.5 * f.value().x();
    F_.value().yy() = 0.5 * f.value().y();
    F_.value().zz() = 0.5 * f.value().z();
    F_.value() = (E & F_ & E.T()).value();

    // it is an error not to define anything
    if
    (
        magSqr(D_.value()) <= VSMALL
     && magSqr(F_.value()) <= VSMALL
    )
    {
        FatalIOErrorIn
        (
            "Foam::porosityZone::porosityZone"
            "(const fvMesh&, const word&, const dictionary&)",
            dict_
        )   << "neither powerLaw (C0/C1) "
               "nor Darcy-Forchheimer law (d/f) specified"
            << exit(FatalIOError);
    }
}
コード例 #28
0
void Foam::momentOfInertia::massPropertiesSolid
(
    const pointField& pts,
    const triFaceList& triFaces,
    scalar density,
    scalar& mass,
    vector& cM,
    tensor& J
)
{
    // Reimplemented from: Wm4PolyhedralMassProperties.cpp
    // File Version: 4.10.0 (2009/11/18)

    // Geometric Tools, LC
    // Copyright (c) 1998-2010
    // Distributed under the Boost Software License, Version 1.0.
    // http://www.boost.org/LICENSE_1_0.txt
    // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt

    // Boost Software License - Version 1.0 - August 17th, 2003

    // Permission is hereby granted, free of charge, to any person or
    // organization obtaining a copy of the software and accompanying
    // documentation covered by this license (the "Software") to use,
    // reproduce, display, distribute, execute, and transmit the
    // Software, and to prepare derivative works of the Software, and
    // to permit third-parties to whom the Software is furnished to do
    // so, all subject to the following:

    // The copyright notices in the Software and this entire
    // statement, including the above license grant, this restriction
    // and the following disclaimer, must be included in all copies of
    // the Software, in whole or in part, and all derivative works of
    // the Software, unless such copies or derivative works are solely
    // in the form of machine-executable object code generated by a
    // source language processor.

    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
    // NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
    // ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR
    // OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
    // USE OR OTHER DEALINGS IN THE SOFTWARE.

    const scalar r6 = 1.0/6.0;
    const scalar r24 = 1.0/24.0;
    const scalar r60 = 1.0/60.0;
    const scalar r120 = 1.0/120.0;

    // order:  1, x, y, z, x^2, y^2, z^2, xy, yz, zx
    scalarField integrals(10, 0.0);

    forAll(triFaces, i)
    {
        const triFace& tri(triFaces[i]);

        // vertices of triangle i
        vector v0 = pts[tri[0]];
        vector v1 = pts[tri[1]];
        vector v2 = pts[tri[2]];

        // cross product of edges
        vector eA = v1 - v0;
        vector eB = v2 - v0;
        vector n = eA ^ eB;

        // compute integral terms
        scalar tmp0, tmp1, tmp2;

        scalar f1x, f2x, f3x, g0x, g1x, g2x;

        tmp0 = v0.x() + v1.x();
        f1x = tmp0 + v2.x();
        tmp1 = v0.x()*v0.x();
        tmp2 = tmp1 + v1.x()*tmp0;
        f2x = tmp2 + v2.x()*f1x;
        f3x = v0.x()*tmp1 + v1.x()*tmp2 + v2.x()*f2x;
        g0x = f2x + v0.x()*(f1x + v0.x());
        g1x = f2x + v1.x()*(f1x + v1.x());
        g2x = f2x + v2.x()*(f1x + v2.x());

        scalar f1y, f2y, f3y, g0y, g1y, g2y;

        tmp0 = v0.y() + v1.y();
        f1y = tmp0 + v2.y();
        tmp1 = v0.y()*v0.y();
        tmp2 = tmp1 + v1.y()*tmp0;
        f2y = tmp2 + v2.y()*f1y;
        f3y = v0.y()*tmp1 + v1.y()*tmp2 + v2.y()*f2y;
        g0y = f2y + v0.y()*(f1y + v0.y());
        g1y = f2y + v1.y()*(f1y + v1.y());
        g2y = f2y + v2.y()*(f1y + v2.y());

        scalar f1z, f2z, f3z, g0z, g1z, g2z;

        tmp0 = v0.z() + v1.z();
        f1z = tmp0 + v2.z();
        tmp1 = v0.z()*v0.z();
        tmp2 = tmp1 + v1.z()*tmp0;
        f2z = tmp2 + v2.z()*f1z;
        f3z = v0.z()*tmp1 + v1.z()*tmp2 + v2.z()*f2z;
        g0z = f2z + v0.z()*(f1z + v0.z());
        g1z = f2z + v1.z()*(f1z + v1.z());
        g2z = f2z + v2.z()*(f1z + v2.z());

        // update integrals
        integrals[0] += n.x()*f1x;
        integrals[1] += n.x()*f2x;
        integrals[2] += n.y()*f2y;
        integrals[3] += n.z()*f2z;
        integrals[4] += n.x()*f3x;
        integrals[5] += n.y()*f3y;
        integrals[6] += n.z()*f3z;
        integrals[7] += n.x()*(v0.y()*g0x + v1.y()*g1x + v2.y()*g2x);
        integrals[8] += n.y()*(v0.z()*g0y + v1.z()*g1y + v2.z()*g2y);
        integrals[9] += n.z()*(v0.x()*g0z + v1.x()*g1z + v2.x()*g2z);
    }

    integrals[0] *= r6;
    integrals[1] *= r24;
    integrals[2] *= r24;
    integrals[3] *= r24;
    integrals[4] *= r60;
    integrals[5] *= r60;
    integrals[6] *= r60;
    integrals[7] *= r120;
    integrals[8] *= r120;
    integrals[9] *= r120;

    // mass
    mass = integrals[0];

    // center of mass
    cM = vector(integrals[1], integrals[2], integrals[3])/mass;

    // inertia relative to origin
    J.xx() = integrals[5] + integrals[6];
    J.xy() = -integrals[7];
    J.xz() = -integrals[9];
    J.yx() = J.xy();
    J.yy() = integrals[4] + integrals[6];
    J.yz() = -integrals[8];
    J.zx() = J.xz();
    J.zy() = J.yz();
    J.zz() = integrals[4] + integrals[5];

    // inertia relative to center of mass
    J -= mass*((cM & cM)*I - cM*cM);

    // Apply density
    mass *= density;
    J *= density;
}
コード例 #29
0
ファイル: triad.C プロジェクト: OpenFOAM/OpenFOAM-dev
Foam::triad::triad(const tensor& t)
{
    x() = t.x();
    y() = t.y();
    z() = t.z();
}
コード例 #30
0
ファイル: triad.C プロジェクト: OpenFOAM/OpenFOAM-dev
void Foam::triad::operator=(const tensor& t)
{
    x() = t.x();
    y() = t.y();
    z() = t.z();
}