// constructor from data void NewtonEulerDSTest::testBuildNewtonEulerDS1() { std::cout << "--> Test: constructor 1." <<std::endl; SP::NewtonEulerDS ds(new NewtonEulerDS(q0, velocity0, mass, inertia )); double time = 1.5; ds->initialize(time); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1A : ", Type::value(*ds) == Type::NewtonEulerDS, true); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1B : ", ds->number() == 0, true); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->dimension() == 6, true); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->getqDim() == 7, true); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->scalarMass() == mass, true); SP::SimpleMatrix massMatrix(new SimpleMatrix(6,6)); massMatrix->setValue(0, 0, mass); massMatrix->setValue(1, 1, mass); massMatrix->setValue(2, 2, mass); Index dimIndex(2); dimIndex[0] = 3; dimIndex[1] = 3; Index startIndex(4); startIndex[0] = 0; startIndex[1] = 0; startIndex[2] = 3; startIndex[3] = 3; setBlock(inertia, massMatrix, dimIndex, startIndex); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", *(ds->mass()) == *(massMatrix), true); CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->computeKineticEnergy() == 595.0, true); std::cout << "--> Constructor 1 test ended with success." <<std::endl; }
//! @brief Assemblies in M the matrix being passed as parameter //! multiplied by the fact parameter. int XC::BandArpackSOE::addM(const Matrix &m, const ID &id, double fact) { bool retval= 0; //Added by LCPT. if(fact!=0.0) { const int idSize = id.Size(); // check that m and id are of same size if(idSize != m.noRows() && idSize != m.noCols()) { std::cerr << "BandArpackSOE::addM(); Matrix and ID not of similar sizes\n"; retval= -1; } else { resize_mass_matrix_if_needed(size); int col= 0, row= 0; if(fact==1.0) { for(int i=0; i<idSize; i++) for(int j=0; j<idSize; j++) { col= id(i); row = id(j); massMatrix(row,col)+= m(i,j); } } else { for(int i=0; i<idSize; i++) for(int j=0; j<idSize; j++) { col= id(i); row = id(j); massMatrix(row,col)+= m(i,j)*fact; } } } } //Added by LCPT ends. retval= this->addA(m, id, -shift); return retval; }
void dgDynamicBody::SetMassMatrix (dgFloat32 mass, const dgMatrix& inertia) { dgVector II; m_principalAxis = inertia; m_principalAxis.EigenVectors (II); dgMatrix massMatrix (dgGetIdentityMatrix()); massMatrix[0][0] = II[0]; massMatrix[1][1] = II[1]; massMatrix[2][2] = II[2]; dgBody::SetMassMatrix (mass, massMatrix); }
PyObject* MassMatrix(double t, double *x, double *p) { PyObject *OutObj = NULL; PyObject *MassOut = NULL; double *mmactual = NULL, **mmtemp = NULL; int i, n; _init_numpy(); if( (gIData == NULL) || (gIData->isInitBasic == 0) || (gIData->hasMass == 0) ) { Py_INCREF(Py_None); return Py_None; } else if( (gIData->nExtInputs > 0) && (gIData->isInitExtInputs == 0) ) { Py_INCREF(Py_None); return Py_None; } else { OutObj = PyTuple_New(1); assert(OutObj); n = gIData->phaseDim; mmactual = (double *)PyMem_Malloc(n*n*sizeof(double)); assert(mmactual); mmtemp = (double **)PyMem_Malloc(n*sizeof(double *)); assert(mmtemp); for( i = 0; i < n; i++ ) { mmtemp[i] = mmactual + n * i; } if( gIData->nExtInputs > 0 ) { FillCurrentExtInputValues( gIData, t ); } /* Assume massMatrix is returned in column-major format */ massMatrix(gIData->phaseDim, gIData->paramDim, t, x, p, mmtemp, gIData->extraSpaceSize, gIData->gExtraSpace, gIData->nExtInputs, gIData->gCurrentExtInputVals); PyMem_Free(mmtemp); npy_intp dims[2] = {gIData->phaseDim, gIData->phaseDim}; MassOut = PyArray_SimpleNewFromData(2, dims, NPY_DOUBLE, mmactual); if(MassOut) { PyArray_UpdateFlags((PyArrayObject *)MassOut, NPY_ARRAY_CARRAY | NPY_ARRAY_OWNDATA); PyTuple_SetItem(OutObj, 0, PyArray_Transpose((PyArrayObject *)MassOut, NULL)); return OutObj; } else { PyMem_Free(mmactual); Py_INCREF(Py_None); return Py_None; } } }
/* Phase space dim n, pointer to mass array write location am, int mass matrix lower bandwidth lmas, double real-valued parameters rpar int int-valued parameters ipar */ void vfieldmas(int *n, double *am, int *lmas, double *rpar, int *ipar, double *t, double *x) { double **f = NULL; setMassPtrs(gIData, am); f = gIData->gMassPtrs; FillCurrentExtInputValues(gIData, *t); massMatrix(*n, (unsigned) gIData->paramDim, *t, x, rpar, f, (unsigned) gIData->extraSpaceSize, gIData->gExtraSpace, (unsigned) gIData->nExtInputs, gIData->gCurrentExtInputVals); }
NOX::Abstract::Group::ReturnType LOCA::LAPACK::Group::computeComplex(double frequency) { string callingFunction = "LOCA::LAPACK::computeComplex()"; #ifdef HAVE_TEUCHOS_COMPLEX NOX::Abstract::Group::ReturnType finalStatus; freq = frequency; // Compute Jacobian finalStatus = computeJacobian(); globalData->locaErrorCheck->checkReturnType(finalStatus, callingFunction); // Compute Mass matrix bool res = locaProblemInterface.computeShiftedMatrix(0.0, 1.0, xVector, shiftedSolver.getMatrix()); // Compute complex matrix NOX::LAPACK::Matrix<double>& jacobianMatrix = jacSolver.getMatrix(); NOX::LAPACK::Matrix<double>& massMatrix = shiftedSolver.getMatrix(); NOX::LAPACK::Matrix< std::complex<double> >& complexMatrix = complexSolver.getMatrix(); int n = jacobianMatrix.numRows(); for (int j=0; j<n; j++) { for (int i=0; i<n; i++) { complexMatrix(i,j) = std::complex<double>(jacobianMatrix(i,j), frequency*massMatrix(i,j)); } } if (finalStatus == NOX::Abstract::Group::Ok && res) isValidComplex = true; if (res) return finalStatus; else return NOX::Abstract::Group::Failed; #else globalData->locaErrorCheck->throwError( callingFunction, "TEUCHOS_COMPLEX must be enabled for complex support! Reconfigure with -D Teuchos_ENABLE_COMPLEX"); return NOX::Abstract::Group::BadDependency; #endif }
vector< vector<double> > twoDFluxMatrix3(unsigned N)///Note the syntax is very much different from the 1-D one as taking the computational grid as an input would be a very hefty task. { vector< vector< double > > FluxMatrix; vector <double> Nodes = lobattoNodes(N+1);///N+1 as the N+1 nodes will give me a polynomial of degree 'N'. vector < vector < double > > F = fluxMatrix(Nodes); vector < vector < double > > M = massMatrix(Nodes); unsigned i1,i2,j1,j2;///These would be the counter for the loops. FluxMatrix = zeros((N+1)*(N+1),(N+1)*(N+1)); i1=i2=N; for(j1=0;j1<=N;j1++) for(j2=0;j2<=N;j2++) FluxMatrix[i1*(N+1)+j1][i2*(N+1)+j2] = F[i1][i2]*M[j1][j2]; return FluxMatrix; }