本文整理汇总了C++中teuchos::Array::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::assign方法的具体用法?C++ Array::assign怎么用?C++ Array::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::Array
的用法示例。
在下文中一共展示了Array::assign方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parametricCenter
//---------------------------------------------------------------------------//
// Get the parameteric center of an entity.
void MoabEntityLocalMap::parametricCenter(
const Entity& entity,
Teuchos::Array<double>& center ) const
{
moab::EntityType moab_type = d_moab_mesh->get_moab()->type_from_handle(
MoabHelpers::extractEntity(entity) );
switch( moab_type )
{
case moab::MBTRI:
center.assign( 2, 1.0 / 3.0 );
break;
case moab::MBQUAD:
center.assign( 2, 0.0 );
break;
case moab::MBTET:
center.assign( 3, 1.0 / 6.0 );
break;
case moab::MBHEX:
center.assign( 3, 0.0 );
break;
default:
center.resize( 0 );
break;
}
}
示例2: entitySupportIds
//---------------------------------------------------------------------------//
// Given an entity, get the ids of its support locations
void LibmeshNodalShapeFunction::entitySupportIds(
const DataTransferKit::Entity& entity,
Teuchos::Array<DataTransferKit::SupportId>& support_ids ) const
{
// Node case.
if ( 0 == entity.topologicalDimension() )
{
DTK_CHECK( extractGeom<libMesh::Node>(entity)->valid_id() );
support_ids.assign( 1, extractGeom<libMesh::Node>(entity)->id() );
}
// Element case.
else
{
Teuchos::Ptr<libMesh::Elem> elem = extractGeom<libMesh::Elem>(entity);
int num_nodes = elem->n_nodes();
support_ids.resize( num_nodes );
for ( int n = 0; n < num_nodes; ++n )
{
DTK_CHECK( elem->get_node(n)->valid_id() );
support_ids[n] = elem->get_node(n)->id();
}
}
}
示例3: main
int main(int argc, char *argv[]) {
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
Kokkos::initialize();
// This little trick lets us print to std::cout only if
// a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
*outStream \
<< "===============================================================================\n" \
<< "| |\n" \
<< "| Unit Test (CubatureDirect,CubatureTensor,DefaultCubatureFactory) |\n" \
<< "| |\n" \
<< "| 1) Computing integrals of monomials on reference cells in 3D |\n" \
<< "| - using Level 2 BLAS - |\n" \
<< "| |\n" \
<< "| Questions? Contact Pavel Bochev ([email protected]) or |\n" \
<< "| Denis Ridzal ([email protected]). |\n" \
<< "| |\n" \
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \
<< "| |\n" \
<< "===============================================================================\n"\
<< "| TEST 1: integrals of monomials in 3D (Level 2 BLAS version) |\n"\
<< "===============================================================================\n";
// internal variables:
int errorFlag = 0;
int polyCt = 0;
int offset = 0;
Teuchos::Array< Teuchos::Array<double> > testInt;
Teuchos::Array< Teuchos::Array<double> > analyticInt;
Teuchos::Array<double> tmparray(1);
double reltol = 1.0e+04 * INTREPID_TOL;
int maxDeg[4];
int maxOffset[4];
int numPoly[4];
int numAnalytic[4];
// max polynomial degree tested, per cell type:
maxDeg[0] = INTREPID2_CUBATURE_TET_DEFAULT_MAX;
maxDeg[1] = 20; // can be as large as INTREPID2_CUBATURE_LINE_GAUSS_MAX, but runtime is excessive
maxDeg[2] = std::min(INTREPID2_CUBATURE_LINE_GAUSS_MAX, INTREPID2_CUBATURE_TRI_DEFAULT_MAX);
maxDeg[3] = std::min(INTREPID2_CUBATURE_LINE_GAUSS_MAX, INTREPID2_CUBATURE_LINE_GAUSSJACOBI20_MAX);
// max polynomial degree recorded in analytic comparison files, per cell type:
maxOffset[0] = INTREPID2_CUBATURE_TET_DEFAULT_MAX;
maxOffset[1] = INTREPID2_CUBATURE_LINE_GAUSS_MAX;
maxOffset[2] = std::min(INTREPID2_CUBATURE_LINE_GAUSS_MAX, INTREPID2_CUBATURE_TRI_DEFAULT_MAX);
maxOffset[3] = std::min(INTREPID2_CUBATURE_LINE_GAUSS_MAX, INTREPID2_CUBATURE_LINE_GAUSSJACOBI20_MAX);
for (int i=0; i<4; i++) {
numPoly[i] = (maxDeg[i]+1)*(maxDeg[i]+2)*(maxDeg[i]+3)/6;
}
for (int i=0; i<4; i++) {
numAnalytic[i] = (maxOffset[i]+1)*(maxOffset[i]+2)*(maxOffset[i]+3)/6;
}
// get names of files with analytic values
std::string basedir = "./data";
std::stringstream namestream[4];
std::string filename[4];
namestream[0] << basedir << "/TET_integrals" << ".dat";
namestream[0] >> filename[0];
namestream[1] << basedir << "/HEX_integrals" << ".dat";
namestream[1] >> filename[1];
namestream[2] << basedir << "/TRIPRISM_integrals" << ".dat";
namestream[2] >> filename[2];
namestream[3] << basedir << "/PYR_integrals" << ".dat";
namestream[3] >> filename[3];
// reference cells tested
shards::CellTopology cellType[] = {shards::getCellTopologyData< shards::Tetrahedron<> >(),
shards::getCellTopologyData< shards::Hexahedron<> >(),
shards::getCellTopologyData< shards::Wedge<> >(),
shards::getCellTopologyData< shards::Pyramid<> >() };
// format of data files with analytic values
TypeOfExactData dataFormat[] = {INTREPID2_UTILS_SCALAR, INTREPID_UTILS_FRACTION, INTREPID_UTILS_FRACTION, INTREPID_UTILS_FRACTION};
// compute and compare integrals
try {
for (int cellCt=0; cellCt < 4; cellCt++) {
testInt.assign(numPoly[cellCt], tmparray);
analyticInt.assign(numAnalytic[cellCt], tmparray);
*outStream << "\nIntegrals of monomials on a reference " << cellType[cellCt].getBaseCellTopologyData()->name << ":\n";
std::ifstream filecompare(&filename[cellCt][0]);
// compute integrals
for (int cubDeg=0; cubDeg <= maxDeg[cellCt]; cubDeg++) {
int numMonomials = (cubDeg+1)*(cubDeg+2)*(cubDeg+3)/6;
testInt[cubDeg].resize(numMonomials);
computeIntegral(testInt[cubDeg], cellType[cellCt], cubDeg);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[]) {
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
Kokkos::initialize();
// This little trick lets us print to std::cout only if
// a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
*outStream \
<< "===============================================================================\n" \
<< "| |\n" \
<< "| Unit Test (CubatureGenSparse) |\n" \
<< "| |\n" \
<< "| 1) Computing integrals of monomials on reference cells in 3D |\n" \
<< "| - using Level 2 BLAS - |\n" \
<< "| |\n" \
<< "| Questions? Contact Pavel Bochev ([email protected]), |\n" \
<< "| Denis Ridzal ([email protected]) or |\n" \
<< "| Matthew Keegan ([email protected]). |\n" \
<< "| |\n" \
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \
<< "| |\n" \
<< "===============================================================================\n"\
<< "| TEST 1: integrals of monomials in 3D (Level 2 BLAS version) using |\n"\
<< "| Generalized Sparse Grid Construction |\n"\
<< "===============================================================================\n";
// internal variables:
int errorFlag = 0;
int polyCt = 0;
int offset = 0;
Teuchos::Array< Teuchos::Array<double> > testInt;
Teuchos::Array< Teuchos::Array<double> > analyticInt;
Teuchos::Array<double> tmparray(1);
double reltol = 1.0e+04 * INTREPID_TOL;
int maxDeg = 20; // can be as large as INTREPID2_CUBATURE_SPARSE3D_GAUSS_MAX, but runtime is excessive
int maxOffset = INTREPID2_CUBATURE_LINE_GAUSS_MAX;
int numPoly = (maxDeg+1)*(maxDeg+2)*(maxDeg+3)/6;
int numAnalytic = (maxOffset+1)*(maxOffset+2)*(maxOffset+3)/6;
testInt.assign(numPoly, tmparray);
analyticInt.assign(numAnalytic, tmparray);
// get names of files with analytic values
std::string basedir = "./data";
std::stringstream namestream;
std::string filename;
namestream << basedir << "/HEX_integrals" << ".dat";
namestream >> filename;
// format of data files with analytic values
TypeOfExactData dataFormat = INTREPID_UTILS_FRACTION;
// compute and compare integrals
try {
*outStream << "\nIntegrals of monomials:\n";
std::ifstream filecompare(&filename[0]);
// compute integrals
for (int cubDeg=0; cubDeg <= maxDeg; cubDeg++) {
int numMonomials = (cubDeg+1)*(cubDeg+2)*(cubDeg+3)/6;
testInt[cubDeg].resize(numMonomials);
computeIntegral(testInt[cubDeg], cubDeg);
}
// get analytic values
if (filecompare.is_open()) {
getAnalytic(analyticInt, filecompare, dataFormat);
// close file
filecompare.close();
}
// perform comparison
for (int cubDeg=0; cubDeg <= maxDeg; cubDeg++) {
polyCt = 0;
offset = 0;
int oldErrorFlag = errorFlag;
for (int xDeg=0; xDeg <= cubDeg; xDeg++) {
for (int yDeg=0; yDeg <= cubDeg-xDeg; yDeg++) {
for (int zDeg=0; zDeg <= cubDeg-xDeg-yDeg; zDeg++) {
double abstol = ( analyticInt[polyCt+offset][0] == 0.0 ? reltol : std::fabs(reltol*analyticInt[polyCt+offset][0]) );
double absdiff = std::fabs(analyticInt[polyCt+offset][0] - testInt[cubDeg][polyCt]);
if (absdiff > abstol) {
*outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " integrating "
<< "x^" << std::setw(2) << std::left << xDeg << " * y^" << std::setw(2) << yDeg
<< " * z^" << std::setw(2) << zDeg << ":" << " "
<< std::scientific << std::setprecision(16)
<< testInt[cubDeg][polyCt] << " " << analyticInt[polyCt+offset][0] << " "
<< std::setprecision(4) << absdiff << " " << "<?" << " " << abstol << "\n";
errorFlag++;
*outStream << std::right << std::setw(118) << "^^^^---FAILURE!\n";
}
polyCt++;
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[]) {
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
// This little trick lets us print to std::cout only if
// a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
*outStream \
<< "===============================================================================\n" \
<< "| |\n" \
<< "| Unit Test (CubaturePolylib) |\n" \
<< "| |\n" \
<< "| 1) Computing integrals of monomials on reference cells in 1D |\n" \
<< "| |\n" \
<< "| Questions? Contact Pavel Bochev ([email protected]) or |\n" \
<< "| Denis Ridzal ([email protected]). |\n" \
<< "| |\n" \
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \
<< "| |\n" \
<< "===============================================================================\n"\
<< "| TEST 1: integrals of monomials in 1D |\n"\
<< "===============================================================================\n";
// internal variables:
int errorFlag = 0;
Teuchos::Array< Teuchos::Array<double> > testInt;
Teuchos::Array< Teuchos::Array<double> > analyticInt;
Teuchos::Array<double> tmparray(1);
double reltol = 1.0e+03 * INTREPID_TOL;
testInt.assign(INTREPID_CUBATURE_LINE_MAX+1, tmparray);
analyticInt.assign(INTREPID_CUBATURE_LINE_MAX+1, tmparray);
// open file with analytic values
std::string basedir = "./data";
std::stringstream namestream;
std::string filename;
namestream << basedir << "/EDGE_integrals" << ".dat";
namestream >> filename;
std::ifstream filecompare(&filename[0]);
*outStream << "\nIntegrals of monomials on a reference line (edge):\n";
// compute and compare integrals
try {
for (EIntrepidPLPoly poly_type=PL_GAUSS; poly_type <= PL_GAUSS_LOBATTO; poly_type++) {
// compute integrals
for (int cubDeg=0; cubDeg <= INTREPID_CUBATURE_LINE_MAX; cubDeg++) {
testInt[cubDeg].resize(cubDeg+1);
for (int polyDeg=0; polyDeg <= cubDeg; polyDeg++) {
testInt[cubDeg][polyDeg] = computeIntegral(cubDeg, polyDeg, poly_type);
}
}
// get analytic values
if (filecompare.is_open()) {
getAnalytic(analyticInt, filecompare);
// close file
filecompare.close();
}
// perform comparison
for (int cubDeg=0; cubDeg <= INTREPID_CUBATURE_LINE_MAX; cubDeg++) {
for (int polyDeg=0; polyDeg <= cubDeg; polyDeg++) {
double abstol = ( analyticInt[polyDeg][0] == 0.0 ? reltol : std::fabs(reltol*analyticInt[polyDeg][0]) );
double absdiff = std::fabs(analyticInt[polyDeg][0] - testInt[cubDeg][polyDeg]);
*outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " integrating "
<< "x^" << std::setw(2) << std::left << polyDeg << ":" << " "
<< std::scientific << std::setprecision(16) << testInt[cubDeg][polyDeg] << " " << analyticInt[polyDeg][0] << " "
<< std::setprecision(4) << absdiff << " " << "<?" << " " << abstol << "\n";
if (absdiff > abstol) {
errorFlag++;
*outStream << std::right << std::setw(104) << "^^^^---FAILURE!\n";
}
}
*outStream << "\n";
} // end for cubDeg
} // end for poly_type
}
catch (std::logic_error err) {
*outStream << err.what() << "\n";
errorFlag = -1;
};
if (errorFlag != 0)
std::cout << "End Result: TEST FAILED\n";
else
std::cout << "End Result: TEST PASSED\n";
// reset format state of std::cout
//.........这里部分代码省略.........
示例6: main
int main(int argc, char *argv[]) {
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
// This little trick lets us print to std::cout only if
// a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
*outStream \
<< "===============================================================================\n" \
<< "| |\n" \
<< "| Unit Test (CubatureDirect,CubatureTensor,DefaultCubatureFactory) |\n" \
<< "| |\n" \
<< "| 1) Computing integrals of monomials on reference cells in 2D |\n" \
<< "| |\n" \
<< "| Questions? Contact Pavel Bochev ([email protected]) or |\n" \
<< "| Denis Ridzal ([email protected]). |\n" \
<< "| |\n" \
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \
<< "| |\n" \
<< "===============================================================================\n"\
<< "| TEST 1: integrals of monomials in 2D |\n"\
<< "===============================================================================\n";
// internal variables:
int errorFlag = 0;
int polyCt = 0;
int offset = 0;
Teuchos::Array< Teuchos::Array<double> > testInt;
Teuchos::Array< Teuchos::Array<double> > analyticInt;
Teuchos::Array<double> tmparray(1);
double reltol = 1.0e+03 * INTREPID_TOL;
int maxDeg[2];
int numPoly[2];
maxDeg[0] = INTREPID_CUBATURE_TRI_DEFAULT_MAX;
maxDeg[1] = INTREPID_CUBATURE_LINE_GAUSS_MAX;
numPoly[0] = (INTREPID_CUBATURE_TRI_DEFAULT_MAX+1)*(INTREPID_CUBATURE_TRI_DEFAULT_MAX+2)/2;
numPoly[1] = (INTREPID_CUBATURE_LINE_GAUSS_MAX+1)*(INTREPID_CUBATURE_LINE_GAUSS_MAX+2)/2;
// get names of files with analytic values
std::string basedir = "./data";
std::stringstream namestream[2];
std::string filename[2];
namestream[0] << basedir << "/TRI_integrals" << ".dat";
namestream[0] >> filename[0];
namestream[1] << basedir << "/QUAD_integrals" << ".dat";
namestream[1] >> filename[1];
shards::CellTopology cellType[] = {shards::getCellTopologyData< shards::Triangle<> >(),
shards::getCellTopologyData< shards::Quadrilateral<> >()};
// compute and compare integrals
try {
for (int cellCt=0; cellCt < 2; cellCt++) {
testInt.assign(numPoly[cellCt], tmparray);
analyticInt.assign(numPoly[cellCt], tmparray);
*outStream << "\nIntegrals of monomials on a reference " << cellType[cellCt].getBaseCellTopologyData()->name << ":\n";
std::ifstream filecompare(&filename[cellCt][0]);
// compute integrals
for (int cubDeg=0; cubDeg <= maxDeg[cellCt]; cubDeg++) {
polyCt = 0;
testInt[cubDeg].resize((cubDeg+1)*(cubDeg+2)/2);
for (int xDeg=0; xDeg <= cubDeg; xDeg++) {
for (int yDeg=0; yDeg <= cubDeg-xDeg; yDeg++) {
testInt[cubDeg][polyCt] = computeIntegral(cellType[cellCt], cubDeg, xDeg, yDeg);
polyCt++;
}
}
}
// get analytic values
if (filecompare.is_open()) {
getAnalytic(analyticInt, filecompare);
// close file
filecompare.close();
}
// perform comparison
for (int cubDeg=0; cubDeg <= maxDeg[cellCt]; cubDeg++) {
polyCt = 0;
offset = 0;
for (int xDeg=0; xDeg <= cubDeg; xDeg++) {
for (int yDeg=0; yDeg <= cubDeg-xDeg; yDeg++) {
double abstol = ( analyticInt[polyCt+offset][0] == 0.0 ? reltol : std::fabs(reltol*analyticInt[polyCt+offset][0]) );
double absdiff = std::fabs(analyticInt[polyCt+offset][0] - testInt[cubDeg][polyCt]);
*outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " integrating "
<< "x^" << std::setw(2) << std::left << xDeg << " * y^" << std::setw(2) << yDeg << ":" << " "
<< std::scientific << std::setprecision(16) << testInt[cubDeg][polyCt] << " " << analyticInt[polyCt+offset][0] << " "
<< std::setprecision(4) << absdiff << " " << "<?" << " " << abstol << "\n";
if (absdiff > abstol) {
errorFlag++;
//.........这里部分代码省略.........