| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <stk_io/StkMeshIoBroker.hpp> |
| 36 |
|
| 37 |
#include <stk_mesh/base/BulkData.hpp> |
| 38 |
#include <stk_mesh/base/MetaData.hpp> |
| 39 |
#include <stk_mesh/base/Field.hpp> |
| 40 |
#include <stk_mesh/base/Bucket.hpp> |
| 41 |
#include <stk_mesh/base/Selector.hpp> |
| 42 |
#include <stk_mesh/base/GetEntities.hpp> // for get_selected_entities |
| 43 |
#include <stk_mesh/base/FieldBLAS.hpp> |
| 44 |
|
| 45 |
#include <stk_util/parallel/ParallelReduce.hpp> |
| 46 |
#ifdef STK_HAS_MPI |
| 47 |
#include "mpi.h" |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <gtest/gtest.h> |
| 51 |
#include <string> |
| 52 |
#include <complex> |
| 53 |
#include <vector> |
| 54 |
#include <limits> |
| 55 |
#include <sstream> |
| 56 |
|
| 57 |
template<class A> |
| 58 |
struct BLASFixture { |
| 59 |
|
| 60 |
A initial_value1; |
| 61 |
A initial_value2; |
| 62 |
A initial_value3; |
| 63 |
unsigned int numEntitiesUniversal; |
| 64 |
unsigned int numEntitiesOwned; |
| 65 |
unsigned int numEntitiesGlobal; |
| 66 |
stk::io::StkMeshIoBroker * stkMeshIoBroker; |
| 67 |
stk::mesh::BulkData * stkMeshBulkData; |
| 68 |
stk::mesh::Field<A> * field1; |
| 69 |
stk::mesh::FieldBase * fieldBase1; |
| 70 |
stk::mesh::Field<A> * field2; |
| 71 |
stk::mesh::FieldBase * fieldBase2; |
| 72 |
stk::mesh::Field<A> * field3; |
| 73 |
stk::mesh::FieldBase * fieldBase3; |
| 74 |
|
| 75 |
stk::mesh::Part * pPartA; |
| 76 |
stk::mesh::Part * pPartB; |
| 77 |
unsigned int numPartAEntitiesOwned; |
| 78 |
unsigned int numPartBEntitiesOwned; |
| 79 |
unsigned int numPartAEntitiesGlobal; |
| 80 |
unsigned int numPartBEntitiesGlobal; |
| 81 |
|
| 82 |
BLASFixture(const A init1, const A init2 = A(), const A init3 = A()); |
| 83 |
~BLASFixture(); |
| 84 |
|
| 85 |
}; |
| 86 |
|
| 87 |
template<class A> |
| 88 |
BLASFixture<A>::BLASFixture(const A init1, const A init2, const A init3) |
| 89 |
{ |
| 90 |
initial_value1 = init1; |
| 91 |
initial_value2 = init2; |
| 92 |
initial_value3 = init3; |
| 93 |
|
| 94 |
MPI_Comm my_comm = MPI_COMM_WORLD; |
| 95 |
|
| 96 |
const double fractionToPartA = 0.3; |
| 97 |
const double fractionToPartB = 0.3; |
| 98 |
|
| 99 |
const unsigned int meshSizeX = 1; |
| 100 |
const unsigned int meshSizeY = 4; |
| 101 |
const unsigned int meshSizeZ = 4; |
| 102 |
|
| 103 |
stkMeshIoBroker = new stk::io::StkMeshIoBroker(my_comm); |
| 104 |
stk::io::StkMeshIoBroker & io = *stkMeshIoBroker; |
| 105 |
std::ostringstream osstr; |
| 106 |
osstr << "generated:" << meshSizeX << "x" << meshSizeY << "x" << meshSizeZ; |
| 107 |
io.add_mesh_database(osstr.str(), stk::io::READ_MESH); |
| 108 |
io.create_input_mesh(); |
| 109 |
stk::mesh::MetaData &meta_data = io.meta_data(); |
| 110 |
|
| 111 |
field1 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field1"); |
| 112 |
stk::mesh::put_field_on_mesh(*field1,field1->mesh_meta_data().universal_part(),&initial_value1); |
| 113 |
fieldBase1 = field1; |
| 114 |
|
| 115 |
field2 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field2"); |
| 116 |
stk::mesh::put_field_on_mesh(*field2,field2->mesh_meta_data().universal_part(),&initial_value2); |
| 117 |
fieldBase2 = field2; |
| 118 |
|
| 119 |
field3 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field3"); |
| 120 |
stk::mesh::put_field_on_mesh(*field3,field3->mesh_meta_data().universal_part(),&initial_value3); |
| 121 |
fieldBase3 = field3; |
| 122 |
|
| 123 |
io.populate_bulk_data(); |
| 124 |
stkMeshBulkData = &io.bulk_data(); |
| 125 |
|
| 126 |
pPartA = &meta_data.declare_part( "PartA" , stk::topology::NODE_RANK ); |
| 127 |
pPartB = &meta_data.declare_part( "PartB" , stk::topology::NODE_RANK ); |
| 128 |
|
| 129 |
std::vector<stk::mesh::Entity> entities; |
| 130 |
stk::mesh::get_selected_entities(meta_data.locally_owned_part(), stkMeshBulkData->buckets(stk::topology::NODE_RANK), entities); |
| 131 |
|
| 132 |
stkMeshBulkData->modification_begin(); |
| 133 |
size_t numToPartA = entities.size() * fractionToPartA; |
| 134 |
for (unsigned int i=0; i<numToPartA; i++) |
| 135 |
stkMeshBulkData->change_entity_parts(entities[i],stk::mesh::ConstPartVector{pPartA}); |
| 136 |
size_t numToPartB = entities.size() * fractionToPartB; |
| 137 |
for (unsigned int i=numToPartA; i<numToPartA+numToPartB; i++) |
| 138 |
stkMeshBulkData->change_entity_parts(entities[i],stk::mesh::ConstPartVector{pPartB}); |
| 139 |
stkMeshBulkData->modification_end(); |
| 140 |
|
| 141 |
|
| 142 |
numEntitiesUniversal=0; |
| 143 |
unsigned int numPartAEntitiesUniversal = 0; |
| 144 |
numPartAEntitiesOwned = 0; |
| 145 |
unsigned int numPartBEntitiesUniversal = 0; |
| 146 |
numPartBEntitiesOwned = 0; |
| 147 |
|
| 148 |
unsigned int numPartlessEntities = 0; |
| 149 |
numEntitiesOwned = 0; |
| 150 |
|
| 151 |
const stk::mesh::BucketVector & nodeBuckets = stkMeshBulkData->get_buckets(stk::topology::NODE_RANK, meta_data.universal_part()); |
| 152 |
for(const stk::mesh::Bucket *bucket : nodeBuckets) { |
| 153 |
const unsigned bucketSize = bucket->size(); |
| 154 |
numEntitiesUniversal += bucketSize; |
| 155 |
|
| 156 |
if (bucket->owned()) { |
| 157 |
numEntitiesOwned += bucketSize; |
| 158 |
if (bucket->member(*pPartA)) { |
| 159 |
numPartAEntitiesOwned += bucketSize; |
| 160 |
} |
| 161 |
if (bucket->member(*pPartB)) { |
| 162 |
numPartBEntitiesOwned += bucketSize; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
if (bucket->member(*pPartA)) { |
| 167 |
numPartAEntitiesUniversal += bucketSize; |
| 168 |
} |
| 169 |
if (bucket->member(*pPartB)) { |
| 170 |
numPartBEntitiesUniversal += bucketSize; |
| 171 |
} |
| 172 |
bool haveABEntities = bucket->member(*pPartA) && bucket->member(*pPartB); |
| 173 |
EXPECT_TRUE( !haveABEntities); |
| 174 |
if (!bucket->member(*pPartA) && !bucket->member(*pPartB)) { |
| 175 |
numPartlessEntities += bucketSize; |
| 176 |
} |
| 177 |
} |
| 178 |
EXPECT_EQ(numEntitiesUniversal, numPartAEntitiesUniversal+numPartBEntitiesUniversal+numPartlessEntities); |
| 179 |
|
| 180 |
numEntitiesGlobal = 0; |
| 181 |
numPartAEntitiesGlobal = 0; |
| 182 |
numPartBEntitiesGlobal = 0; |
| 183 |
stk::all_reduce_sum(stkMeshBulkData->parallel(),&numEntitiesOwned ,&numEntitiesGlobal ,1u); |
| 184 |
stk::all_reduce_sum(stkMeshBulkData->parallel(),&numPartAEntitiesOwned,&numPartAEntitiesGlobal,1u); |
| 185 |
stk::all_reduce_sum(stkMeshBulkData->parallel(),&numPartBEntitiesOwned,&numPartBEntitiesGlobal,1u); |
| 186 |
EXPECT_EQ(numEntitiesGlobal, (meshSizeX+1) * (meshSizeY+1) * (meshSizeZ+1)); |
| 187 |
} |
| 188 |
|
| 189 |
template<class A> |
| 190 |
BLASFixture<A>::~BLASFixture() { |
| 191 |
delete stkMeshIoBroker; |
| 192 |
} |
| 193 |
|
| 194 |
template<class Scalar> |
| 195 |
void testFieldValidation(BLASFixture<Scalar> & Fixture, Scalar val1, Scalar val2, Scalar val3, double tol=1.0e-5) |
| 196 |
{ |
| 197 |
const stk::mesh::Selector selector = stk::mesh::selectField(*Fixture.field1); |
| 198 |
testFieldValidation(Fixture,val1,val2,val3,selector,tol); |
| 199 |
} |
| 200 |
|
| 201 |
template<class Scalar> |
| 202 |
void testFieldValidation(BLASFixture<Scalar> & Fixture, Scalar val1, Scalar val2, Scalar val3, stk::mesh::Selector selector, double tol=1.0e-5) |
| 203 |
{ |
| 204 |
const stk::mesh::BucketVector& buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(),selector); |
| 205 |
for(size_t j = 0; j < buckets.size(); j++) { |
| 206 |
const stk::mesh::Bucket& bucket = *buckets[j]; |
| 207 |
for(size_t i=0; i<bucket.size(); i++) { |
| 208 |
Scalar* field_value1 = reinterpret_cast<Scalar*>(stk::mesh::field_data(*Fixture.field1, bucket[i])); |
| 209 |
EXPECT_NEAR(val1,*field_value1,tol); |
| 210 |
|
| 211 |
Scalar* field_value2 = reinterpret_cast<Scalar*>(stk::mesh::field_data(*Fixture.field2, bucket[i])); |
| 212 |
EXPECT_NEAR(val2,*field_value2,tol); |
| 213 |
|
| 214 |
Scalar* field_value3 = reinterpret_cast<Scalar*>(stk::mesh::field_data(*Fixture.field3, bucket[i])); |
| 215 |
EXPECT_NEAR(val3,*field_value3,tol); |
| 216 |
} |
| 217 |
|
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
template<class Scalar> |
| 222 |
void testFieldValidation(BLASFixture<std::complex<Scalar> > & Fixture, |
| 223 |
std::complex<Scalar> val1, std::complex<Scalar> val2, std::complex<Scalar> val3, |
| 224 |
stk::mesh::Selector selector, double tol=1.0e-5) |
| 225 |
{ |
| 226 |
const stk::mesh::BucketVector& buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(),selector); |
| 227 |
for(size_t j = 0; j < buckets.size(); j++) { |
| 228 |
const stk::mesh::Bucket& bucket = *buckets[j]; |
| 229 |
for(size_t i=0; i<bucket.size(); i++) { |
| 230 |
std::complex<Scalar>* field_value1 = reinterpret_cast<std::complex<Scalar>* >(stk::mesh::field_data(*Fixture.field1, bucket[i])); |
| 231 |
EXPECT_LT(std::abs(val1-*field_value1),tol); |
| 232 |
|
| 233 |
std::complex<Scalar>* field_value2 = reinterpret_cast<std::complex<Scalar>* >(stk::mesh::field_data(*Fixture.field2, bucket[i])); |
| 234 |
EXPECT_LT(std::abs(val2-*field_value2),tol); |
| 235 |
|
| 236 |
std::complex<Scalar>* field_value3 = reinterpret_cast<std::complex<Scalar>* >(stk::mesh::field_data(*Fixture.field3, bucket[i])); |
| 237 |
EXPECT_LT(std::abs(val3-*field_value3),tol); |
| 238 |
} |
| 239 |
|
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
template<class Scalar> |
| 244 |
void test_axpy(const Scalar alpha,const Scalar initial1,const Scalar initial2) |
| 245 |
{ |
| 246 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 247 |
|
| 248 |
stk::mesh::field_axpy(alpha,*Fixture.field1,*Fixture.field2); |
| 249 |
testFieldValidation(Fixture,initial1,alpha*initial1+initial2,Scalar()); |
| 250 |
stk::mesh::field_axpy(alpha,*Fixture.fieldBase1,*Fixture.fieldBase2); |
| 251 |
testFieldValidation(Fixture,initial1,alpha*initial1*Scalar(2)+initial2,Scalar()); |
| 252 |
} |
| 253 |
|
| 254 |
TEST(FieldBLAS,axpy_double) |
| 255 |
{ |
| 256 |
const double initial1 = 4.27; |
| 257 |
const double initial2 = -3.73; |
| 258 |
const double alpha = 7.11; |
| 259 |
test_axpy(alpha,initial1,initial2); |
| 260 |
} |
| 261 |
|
| 262 |
TEST(FieldBLAS,axpy_float) |
| 263 |
{ |
| 264 |
const float initial1 = 1.2; |
| 265 |
const float initial2 = -3.1; |
| 266 |
const float alpha = 4.1; |
| 267 |
test_axpy(alpha,initial1,initial2); |
| 268 |
} |
| 269 |
|
| 270 |
TEST(FieldBLAS,axpy_complex) |
| 271 |
{ |
| 272 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 273 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 274 |
const std::complex<double> alpha = std::complex<double>(-3.11,2.00); |
| 275 |
test_axpy(alpha,initial1,initial2); |
| 276 |
} |
| 277 |
|
| 278 |
TEST(FieldBLAS,axpy_int) |
| 279 |
{ |
| 280 |
const int initial1 = 4; |
| 281 |
const int initial2 = -3; |
| 282 |
const int alpha = 7; |
| 283 |
test_axpy(alpha,initial1,initial2); |
| 284 |
} |
| 285 |
|
| 286 |
template<class Scalar> |
| 287 |
void test_axpby(const Scalar alpha, const Scalar initial1, const Scalar beta, const Scalar initial2) |
| 288 |
{ |
| 289 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 290 |
|
| 291 |
stk::mesh::field_axpby(alpha,*Fixture.field1,beta,*Fixture.field2); |
| 292 |
testFieldValidation(Fixture,initial1,alpha*initial1+beta*initial2,Scalar()); |
| 293 |
|
| 294 |
stk::mesh::field_axpby(alpha,*Fixture.fieldBase1,beta,*Fixture.fieldBase2); |
| 295 |
testFieldValidation(Fixture,initial1,alpha*initial1*Scalar(2)+beta*initial2,Scalar()); |
| 296 |
} |
| 297 |
|
| 298 |
TEST(FieldBLAS,axpby_double) |
| 299 |
{ |
| 300 |
const double initial1 = 4.27; |
| 301 |
const double initial2 = -3.73; |
| 302 |
const double alpha = 7.11; |
| 303 |
const double beta = 1.0; |
| 304 |
test_axpby(alpha,initial1,beta,initial2); |
| 305 |
} |
| 306 |
|
| 307 |
TEST(FieldBLAS,axpby_float) |
| 308 |
{ |
| 309 |
const float initial1 = 1.2; |
| 310 |
const float initial2 = -3.1; |
| 311 |
const float alpha = 4.1; |
| 312 |
const float beta = 1.0; |
| 313 |
test_axpby(alpha,initial1,beta,initial2); |
| 314 |
} |
| 315 |
|
| 316 |
TEST(FieldBLAS,axpby_complex) |
| 317 |
{ |
| 318 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 319 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 320 |
const std::complex<double> alpha = std::complex<double>(-3.11,2.00); |
| 321 |
const std::complex<double> beta = std::complex<double>(1.0,0.0); |
| 322 |
test_axpby(alpha,initial1,beta,initial2); |
| 323 |
} |
| 324 |
|
| 325 |
template<class Scalar> |
| 326 |
void test_axpy_selector(Scalar initial1,Scalar initial2,Scalar alpha_1,Scalar alpha_2,Scalar alpha_all) |
| 327 |
{ |
| 328 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 329 |
|
| 330 |
stk::mesh::field_axpy(alpha_1,*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA)); |
| 331 |
testFieldValidation(Fixture,initial1,alpha_1*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 332 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 333 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 334 |
|
| 335 |
stk::mesh::field_axpy(alpha_2,*Fixture.fieldBase1,*Fixture.fieldBase2,stk::mesh::Selector(*Fixture.pPartB)); |
| 336 |
testFieldValidation(Fixture,initial1,alpha_1*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 337 |
testFieldValidation(Fixture,initial1,alpha_2*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 338 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 339 |
|
| 340 |
stk::mesh::field_axpy(alpha_all,*Fixture.field1,*Fixture.field2); |
| 341 |
testFieldValidation(Fixture,initial1,(alpha_1+alpha_all)*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 342 |
testFieldValidation(Fixture,initial1,(alpha_2+alpha_all)*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 343 |
testFieldValidation(Fixture,initial1,alpha_all*initial1+initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 344 |
} |
| 345 |
|
| 346 |
TEST(FieldBLAS,axpy_selector_double) |
| 347 |
{ |
| 348 |
const double initial1 = 4.27; |
| 349 |
const double initial2 = -3.73; |
| 350 |
|
| 351 |
const double alpha_1 = 7.11; |
| 352 |
const double alpha_2 = 4.05; |
| 353 |
const double alpha_all = -2.04; |
| 354 |
|
| 355 |
test_axpy_selector(initial1,initial2,alpha_1,alpha_2,alpha_all); |
| 356 |
} |
| 357 |
|
| 358 |
TEST(FieldBLAS,axpy_selector_float) |
| 359 |
{ |
| 360 |
const float initial1 = 4.2; |
| 361 |
const float initial2 = -3.7; |
| 362 |
|
| 363 |
const float alpha_1 = 7.1; |
| 364 |
const float alpha_2 = 4.7; |
| 365 |
const float alpha_all = -2.3; |
| 366 |
|
| 367 |
test_axpy_selector(initial1,initial2,alpha_1,alpha_2,alpha_all); |
| 368 |
} |
| 369 |
|
| 370 |
TEST(FieldBLAS,axpy_selector_complex) |
| 371 |
{ |
| 372 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 373 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 374 |
|
| 375 |
const std::complex<double> alpha_1 = std::complex<double>(7.11,-42.1); |
| 376 |
const std::complex<double> alpha_2 = std::complex<double>(4.05,7.22); |
| 377 |
const std::complex<double> alpha_all = std::complex<double>(-2.04,3.14); |
| 378 |
|
| 379 |
test_axpy_selector(initial1,initial2,alpha_1,alpha_2,alpha_all); |
| 380 |
} |
| 381 |
|
| 382 |
TEST(FieldBLAS,axpy_selector_int) |
| 383 |
{ |
| 384 |
const int initial1 = 4; |
| 385 |
const int initial2 = -3; |
| 386 |
|
| 387 |
const int alpha_1 = 7; |
| 388 |
const int alpha_2 = 5; |
| 389 |
const int alpha_all = -2; |
| 390 |
|
| 391 |
test_axpy_selector(initial1,initial2,alpha_1,alpha_2,alpha_all); |
| 392 |
} |
| 393 |
|
| 394 |
template<class Scalar> |
| 395 |
void test_copy(const Scalar initial1,const Scalar initial2,const Scalar initial3) |
| 396 |
{ |
| 397 |
BLASFixture<Scalar> Fixture (initial1,initial2,initial3); |
| 398 |
|
| 399 |
stk::mesh::field_copy(*Fixture.field1,*Fixture.field2); |
| 400 |
testFieldValidation(Fixture,initial1,initial1,initial3); |
| 401 |
|
| 402 |
stk::mesh::field_copy(*Fixture.field3,*Fixture.field1); |
| 403 |
testFieldValidation(Fixture,initial3,initial1,initial3); |
| 404 |
} |
| 405 |
|
| 406 |
TEST(FieldBLAS,copy_double) |
| 407 |
{ |
| 408 |
const double initial1 = 4.27; |
| 409 |
const double initial2 = -3.73; |
| 410 |
const double initial3 = 82.47; |
| 411 |
|
| 412 |
test_copy(initial1,initial2,initial3); |
| 413 |
} |
| 414 |
|
| 415 |
TEST(FieldBLAS,copy_float) |
| 416 |
{ |
| 417 |
const float initial1 = 4.2; |
| 418 |
const float initial2 = -3.7; |
| 419 |
const float initial3 = 82.4; |
| 420 |
|
| 421 |
test_copy(initial1,initial2,initial3); |
| 422 |
} |
| 423 |
|
| 424 |
TEST(FieldBLAS,copy_complex) |
| 425 |
{ |
| 426 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 427 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 428 |
const std::complex<double> initial3 = std::complex<double>(82.21,71.23); |
| 429 |
|
| 430 |
test_copy(initial1,initial2,initial3); |
| 431 |
} |
| 432 |
|
| 433 |
TEST(FieldBLAS,copy_int) |
| 434 |
{ |
| 435 |
const int initial1 = 4; |
| 436 |
const int initial2 = -3; |
| 437 |
const int initial3 = 2; |
| 438 |
|
| 439 |
test_copy(initial1,initial2,initial3); |
| 440 |
} |
| 441 |
|
| 442 |
template<class Scalar> |
| 443 |
void test_copy_selector(Scalar initial1,Scalar initial2) |
| 444 |
{ |
| 445 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 446 |
|
| 447 |
stk::mesh::field_copy(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA)); |
| 448 |
testFieldValidation(Fixture,initial1,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 449 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 450 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 451 |
|
| 452 |
stk::mesh::field_copy(*Fixture.fieldBase2,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 453 |
testFieldValidation(Fixture,initial1,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 454 |
testFieldValidation(Fixture,initial2,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 455 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 456 |
|
| 457 |
stk::mesh::field_copy(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 458 |
testFieldValidation(Fixture,initial1,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 459 |
testFieldValidation(Fixture,initial2,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 460 |
testFieldValidation(Fixture,initial1,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 461 |
} |
| 462 |
|
| 463 |
TEST(FieldBLAS,copy_selector_double) |
| 464 |
{ |
| 465 |
const double initial1 = 4.27; |
| 466 |
const double initial2 = -3.73; |
| 467 |
|
| 468 |
test_copy_selector(initial1,initial2); |
| 469 |
} |
| 470 |
|
| 471 |
TEST(FieldBLAS,copy_selector_float) |
| 472 |
{ |
| 473 |
const float initial1 = 4.2; |
| 474 |
const float initial2 = -3.7; |
| 475 |
|
| 476 |
test_copy_selector(initial1,initial2); |
| 477 |
} |
| 478 |
|
| 479 |
TEST(FieldBLAS,copy_selector_complex) |
| 480 |
{ |
| 481 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 482 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 483 |
|
| 484 |
test_copy_selector(initial1,initial2); |
| 485 |
} |
| 486 |
|
| 487 |
TEST(FieldBLAS,copy_selector_int) |
| 488 |
{ |
| 489 |
const int initial1 = 4; |
| 490 |
const int initial2 = -3; |
| 491 |
|
| 492 |
test_copy_selector(initial1,initial2); |
| 493 |
} |
| 494 |
|
| 495 |
template<class Scalar> |
| 496 |
void test_product(const Scalar initial1, const Scalar initial2, const Scalar initial3) |
| 497 |
{ |
| 498 |
BLASFixture<Scalar> Fixture (initial1, initial2, initial3); |
| 499 |
testFieldValidation(Fixture, |
| 500 |
Scalar(pow(initial1,1))*Scalar(pow(initial2,0))*Scalar(pow(initial3,0)), |
| 501 |
Scalar(pow(initial1,0))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)), |
| 502 |
Scalar(pow(initial1,0))*Scalar(pow(initial2,0))*Scalar(pow(initial3,1)),1.0e-1); |
| 503 |
|
| 504 |
stk::mesh::field_product(*Fixture.field1,*Fixture.field2,*Fixture.field3); |
| 505 |
testFieldValidation(Fixture, |
| 506 |
Scalar(pow(initial1,1))*Scalar(pow(initial2,0))*Scalar(pow(initial3,0)), |
| 507 |
Scalar(pow(initial1,0))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)), |
| 508 |
Scalar(pow(initial1,1))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)),1.0e-1); |
| 509 |
|
| 510 |
stk::mesh::field_product(*Fixture.field3,*Fixture.field1,*Fixture.field1); |
| 511 |
testFieldValidation(Fixture, |
| 512 |
Scalar(pow(initial1,2))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)), |
| 513 |
Scalar(pow(initial1,0))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)), |
| 514 |
Scalar(pow(initial1,1))*Scalar(pow(initial2,1))*Scalar(pow(initial3,0)),1.0e-1); |
| 515 |
} |
| 516 |
|
| 517 |
TEST(FieldBLAS,product_double) |
| 518 |
{ |
| 519 |
const double initial1 = 4.27; |
| 520 |
const double initial2 = -3.73; |
| 521 |
const double initial3 = 28.12; |
| 522 |
|
| 523 |
test_product(initial1,initial2,initial3); |
| 524 |
} |
| 525 |
|
| 526 |
TEST(FieldBLAS,product_float) |
| 527 |
{ |
| 528 |
const float initial1 = 4.2; |
| 529 |
const float initial2 = -3.7; |
| 530 |
const float initial3 = 28.1; |
| 531 |
|
| 532 |
test_product(initial1,initial2,initial3); |
| 533 |
} |
| 534 |
|
| 535 |
TEST(FieldBLAS,product_complex) |
| 536 |
{ |
| 537 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 538 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 539 |
const std::complex<double> initial3 = std::complex<double>(1.28,3.11); |
| 540 |
|
| 541 |
test_product(initial1,initial2,initial3); |
| 542 |
} |
| 543 |
|
| 544 |
TEST(FieldBLAS,product_int) |
| 545 |
{ |
| 546 |
const int initial1 = 4; |
| 547 |
const int initial2 = -3; |
| 548 |
const int initial3 = 1; |
| 549 |
|
| 550 |
test_product(initial1,initial2,initial3); |
| 551 |
} |
| 552 |
|
| 553 |
template<class Scalar> |
| 554 |
void test_product_selector(Scalar initial1,Scalar initial2) |
| 555 |
{ |
| 556 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 557 |
|
| 558 |
stk::mesh::field_product(*Fixture.field1,*Fixture.field2,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA)); |
| 559 |
testFieldValidation(Fixture,initial1,initial1*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 560 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 561 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 562 |
|
| 563 |
stk::mesh::field_product(*Fixture.fieldBase2,*Fixture.fieldBase1,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 564 |
testFieldValidation(Fixture,initial1,initial1*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 565 |
testFieldValidation(Fixture,initial1*initial2,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 566 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 567 |
|
| 568 |
stk::mesh::field_product(*Fixture.field1,*Fixture.field2,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 569 |
stk::mesh::field_product(*Fixture.field1,*Fixture.field2,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 570 |
testFieldValidation(Fixture,initial1,initial1*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 571 |
testFieldValidation(Fixture,initial1*initial2,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 572 |
testFieldValidation(Fixture,initial1,Scalar(pow(initial1,2))*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 573 |
} |
| 574 |
|
| 575 |
TEST(FieldBLAS,product_selector_double) |
| 576 |
{ |
| 577 |
const double initial1 = 4.27; |
| 578 |
const double initial2 = -3.73; |
| 579 |
|
| 580 |
test_product_selector(initial1,initial2); |
| 581 |
} |
| 582 |
|
| 583 |
TEST(FieldBLAS,product_selector_float) |
| 584 |
{ |
| 585 |
const float initial1 = 4.2; |
| 586 |
const float initial2 = -3.7; |
| 587 |
|
| 588 |
test_product_selector(initial1,initial2); |
| 589 |
} |
| 590 |
|
| 591 |
TEST(FieldBLAS,product_selector_complex) |
| 592 |
{ |
| 593 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 594 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 595 |
|
| 596 |
test_product_selector(initial1,initial2); |
| 597 |
} |
| 598 |
|
| 599 |
TEST(FieldBLAS,product_selector_int) |
| 600 |
{ |
| 601 |
const int initial1 = 4; |
| 602 |
const int initial2 = -3; |
| 603 |
|
| 604 |
test_product_selector(initial1,initial2); |
| 605 |
} |
| 606 |
|
| 607 |
template<class Scalar> |
| 608 |
void test_dot(const Scalar initial1,const Scalar initial2,const double TOL = 0.5) |
| 609 |
{ |
| 610 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 611 |
|
| 612 |
Scalar field_result = stk::mesh::field_dot(*Fixture.field1,*Fixture.field2); |
| 613 |
EXPECT_LT(std::abs(field_result-initial1*initial2*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 614 |
|
| 615 |
Scalar fieldBase_result; |
| 616 |
stk::mesh::field_dot(fieldBase_result,*Fixture.fieldBase1,*Fixture.fieldBase2); |
| 617 |
EXPECT_LT(std::abs(fieldBase_result-initial1*initial2*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 618 |
} |
| 619 |
|
| 620 |
TEST(FieldBLAS,dot_double) |
| 621 |
{ |
| 622 |
const double initial1 = 4.27; |
| 623 |
const double initial2 = -3.73; |
| 624 |
test_dot(initial1,initial2); |
| 625 |
} |
| 626 |
|
| 627 |
TEST(FieldBLAS,dot_float) |
| 628 |
{ |
| 629 |
const float initial1 = 4.2; |
| 630 |
const float initial2 = -3.7; |
| 631 |
test_dot(initial1,initial2); |
| 632 |
} |
| 633 |
|
| 634 |
TEST(FieldBLAS,dot_complex) |
| 635 |
{ |
| 636 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 637 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 638 |
test_dot(initial1,initial2); |
| 639 |
} |
| 640 |
|
| 641 |
TEST(FieldBLAS,dot_int) |
| 642 |
{ |
| 643 |
const int initial1 = 4; |
| 644 |
const int initial2 = -3; |
| 645 |
test_dot(initial1,initial2); |
| 646 |
} |
| 647 |
|
| 648 |
template<class Scalar> |
| 649 |
void test_dot_selector(Scalar initial1,Scalar initial2,const double TOL = 1.0e-1) |
| 650 |
{ |
| 651 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 652 |
|
| 653 |
Scalar resultA=stk::mesh::field_dot(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA)); |
| 654 |
EXPECT_LT(std::abs(initial1*initial2*Scalar(Fixture.numPartAEntitiesGlobal)-resultA),TOL); |
| 655 |
|
| 656 |
Scalar resultB; |
| 657 |
stk::mesh::field_dot(resultB,*Fixture.fieldBase2,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 658 |
EXPECT_LT(std::abs(initial1*initial2*Scalar(Fixture.numPartBEntitiesGlobal)-resultB),TOL); |
| 659 |
|
| 660 |
Scalar resultABc=stk::mesh::field_dot(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 661 |
EXPECT_LT(std::abs(initial1*initial2*Scalar(Fixture.numEntitiesGlobal-Fixture.numPartAEntitiesGlobal-Fixture.numPartBEntitiesGlobal)-resultABc),TOL); |
| 662 |
} |
| 663 |
|
| 664 |
TEST(FieldBLAS,dot_selector_double) |
| 665 |
{ |
| 666 |
const double initial1 = 4.27; |
| 667 |
const double initial2 = -3.73; |
| 668 |
|
| 669 |
test_dot_selector(initial1,initial2); |
| 670 |
} |
| 671 |
|
| 672 |
TEST(FieldBLAS,dot_selector_float) |
| 673 |
{ |
| 674 |
const float initial1 = 4.2; |
| 675 |
const float initial2 = -3.7; |
| 676 |
|
| 677 |
test_dot_selector(initial1,initial2); |
| 678 |
} |
| 679 |
|
| 680 |
TEST(FieldBLAS,dot_selector_complex) |
| 681 |
{ |
| 682 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 683 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 684 |
|
| 685 |
test_dot_selector(initial1,initial2); |
| 686 |
} |
| 687 |
|
| 688 |
TEST(FieldBLAS,dot_selector_int) |
| 689 |
{ |
| 690 |
const int initial1 = 4; |
| 691 |
const int initial2 = -3; |
| 692 |
|
| 693 |
test_dot_selector(initial1,initial2); |
| 694 |
} |
| 695 |
|
| 696 |
template<class Scalar> |
| 697 |
void test_scale(const Scalar alpha,const Scalar initial1) |
| 698 |
{ |
| 699 |
BLASFixture<Scalar> Fixture (initial1,initial1); |
| 700 |
|
| 701 |
stk::mesh::field_scale(alpha,*Fixture.field1); |
| 702 |
stk::mesh::field_scale(alpha,*Fixture.fieldBase2); |
| 703 |
testFieldValidation(Fixture,alpha*initial1,alpha*initial1,Scalar()); |
| 704 |
} |
| 705 |
|
| 706 |
TEST(FieldBLAS,scale_double) |
| 707 |
{ |
| 708 |
const double alpha = 4.27; |
| 709 |
const double initial1 = -3.73; |
| 710 |
test_scale(alpha,initial1); |
| 711 |
} |
| 712 |
|
| 713 |
TEST(FieldBLAS,scale_float) |
| 714 |
{ |
| 715 |
const float alpha = 4.2; |
| 716 |
const float initial1 = -3.7; |
| 717 |
test_scale(alpha,initial1); |
| 718 |
} |
| 719 |
|
| 720 |
TEST(FieldBLAS,scale_complex) |
| 721 |
{ |
| 722 |
const std::complex<double> alpha = std::complex<double>(4.11,-7.63); |
| 723 |
const std::complex<double> initial1 = std::complex<double>(-7.21,-1.23); |
| 724 |
test_scale(alpha,initial1); |
| 725 |
} |
| 726 |
|
| 727 |
TEST(FieldBLAS,scale_int) |
| 728 |
{ |
| 729 |
const int alpha = 4; |
| 730 |
const int initial1 = -3; |
| 731 |
test_scale(alpha,initial1); |
| 732 |
} |
| 733 |
|
| 734 |
template<class Scalar> |
| 735 |
void test_scale_selector(Scalar alpha,Scalar initial1,Scalar initial2) |
| 736 |
{ |
| 737 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 738 |
|
| 739 |
stk::mesh::field_scale(alpha,*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)); |
| 740 |
testFieldValidation(Fixture,alpha*initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 741 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 742 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 743 |
|
| 744 |
stk::mesh::field_scale(alpha,*Fixture.fieldBase2,stk::mesh::Selector(*Fixture.pPartB)); |
| 745 |
testFieldValidation(Fixture,alpha*initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 746 |
testFieldValidation(Fixture,initial1,alpha*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 747 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 748 |
|
| 749 |
stk::mesh::field_scale(alpha,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 750 |
testFieldValidation(Fixture,alpha*initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 751 |
testFieldValidation(Fixture,initial1,alpha*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 752 |
testFieldValidation(Fixture,initial1,alpha*initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 753 |
} |
| 754 |
|
| 755 |
TEST(FieldBLAS,scale_selector_double) |
| 756 |
{ |
| 757 |
const double initial1 = 4.27; |
| 758 |
const double initial2 = -3.73; |
| 759 |
|
| 760 |
const double alpha = 2.13; |
| 761 |
|
| 762 |
test_scale_selector(alpha,initial1,initial2); |
| 763 |
} |
| 764 |
|
| 765 |
TEST(FieldBLAS,scale_selector_float) |
| 766 |
{ |
| 767 |
const float initial1 = 4.2; |
| 768 |
const float initial2 = -3.7; |
| 769 |
|
| 770 |
const float alpha = 7.21; |
| 771 |
|
| 772 |
test_scale_selector(alpha,initial1,initial2); |
| 773 |
} |
| 774 |
|
| 775 |
TEST(FieldBLAS,scale_selector_complex) |
| 776 |
{ |
| 777 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 778 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 779 |
|
| 780 |
const std::complex<double> alpha = -4.2; |
| 781 |
|
| 782 |
test_scale_selector(alpha,initial1,initial2); |
| 783 |
} |
| 784 |
|
| 785 |
TEST(FieldBLAS,scale_selector_int) |
| 786 |
{ |
| 787 |
const int initial1 = 4; |
| 788 |
const int initial2 = -3; |
| 789 |
|
| 790 |
const int alpha = 2; |
| 791 |
|
| 792 |
test_scale_selector(alpha,initial1,initial2); |
| 793 |
} |
| 794 |
|
| 795 |
template<class Scalar> |
| 796 |
void test_fill(const Scalar alpha,const Scalar initial1) |
| 797 |
{ |
| 798 |
BLASFixture<Scalar> Fixture (initial1,initial1); |
| 799 |
|
| 800 |
stk::mesh::field_fill(alpha,*Fixture.field1); |
| 801 |
stk::mesh::field_fill(alpha,*Fixture.fieldBase2); |
| 802 |
testFieldValidation(Fixture,alpha,alpha,Scalar()); |
| 803 |
} |
| 804 |
|
| 805 |
template<class Scalar> |
| 806 |
void test_fill_many(const Scalar alpha,const Scalar initial1) |
| 807 |
{ |
| 808 |
BLASFixture<Scalar> Fixture (initial1,initial1,initial1); |
| 809 |
|
| 810 |
stk::mesh::field_fill(alpha,{Fixture.fieldBase1, Fixture.fieldBase2, Fixture.fieldBase3}); |
| 811 |
testFieldValidation(Fixture,alpha,alpha,alpha); |
| 812 |
} |
| 813 |
|
| 814 |
TEST(FieldBLAS,fill_double) |
| 815 |
{ |
| 816 |
const double alpha = 4.27; |
| 817 |
const double initial1 = -3.73; |
| 818 |
test_fill(alpha,initial1); |
| 819 |
} |
| 820 |
|
| 821 |
TEST(FieldBLAS,fill_many_double) |
| 822 |
{ |
| 823 |
const double alpha = 4.27; |
| 824 |
const double initial1 = -3.73; |
| 825 |
test_fill_many(alpha,initial1); |
| 826 |
} |
| 827 |
|
| 828 |
TEST(FieldBLAS,fill_float) |
| 829 |
{ |
| 830 |
const float alpha = 4.2; |
| 831 |
const float initial1 = -3.7; |
| 832 |
test_fill(alpha,initial1); |
| 833 |
} |
| 834 |
|
| 835 |
TEST(FieldBLAS,fill_float_many) |
| 836 |
{ |
| 837 |
const float alpha = 4.2; |
| 838 |
const float initial1 = -3.7; |
| 839 |
test_fill_many(alpha,initial1); |
| 840 |
} |
| 841 |
|
| 842 |
TEST(FieldBLAS,fill_complex) |
| 843 |
{ |
| 844 |
const std::complex<double> alpha = std::complex<double>(4.11,-7.63); |
| 845 |
const std::complex<double> initial1 = std::complex<double>(-7.21,-1.23); |
| 846 |
test_fill(alpha,initial1); |
| 847 |
} |
| 848 |
|
| 849 |
TEST(FieldBLAS,fill_complex_many) |
| 850 |
{ |
| 851 |
const std::complex<double> alpha = std::complex<double>(4.11,-7.63); |
| 852 |
const std::complex<double> initial1 = std::complex<double>(-7.21,-1.23); |
| 853 |
test_fill_many(alpha,initial1); |
| 854 |
} |
| 855 |
|
| 856 |
TEST(FieldBLAS,fill_int) |
| 857 |
{ |
| 858 |
const int alpha = 4; |
| 859 |
const int initial1 = -3; |
| 860 |
test_fill(alpha,initial1); |
| 861 |
} |
| 862 |
|
| 863 |
TEST(FieldBLAS,fill_int_many) |
| 864 |
{ |
| 865 |
const int alpha = 4; |
| 866 |
const int initial1 = -3; |
| 867 |
test_fill_many(alpha,initial1); |
| 868 |
} |
| 869 |
|
| 870 |
template<class Scalar> |
| 871 |
void test_fill_selector(Scalar alpha,Scalar initial1,Scalar initial2) |
| 872 |
{ |
| 873 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 874 |
|
| 875 |
stk::mesh::field_fill(alpha,*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)); |
| 876 |
testFieldValidation(Fixture,alpha,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 877 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 878 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 879 |
|
| 880 |
stk::mesh::field_fill(alpha,*Fixture.fieldBase2,stk::mesh::Selector(*Fixture.pPartB)); |
| 881 |
testFieldValidation(Fixture,alpha,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 882 |
testFieldValidation(Fixture,initial1,alpha,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 883 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 884 |
|
| 885 |
stk::mesh::field_fill(Scalar(0.0),*Fixture.fieldBase1); |
| 886 |
testFieldValidation(Fixture,Scalar(0.0),initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 887 |
testFieldValidation(Fixture,Scalar(0.0),alpha,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 888 |
testFieldValidation(Fixture,Scalar(0.0),initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 889 |
|
| 890 |
stk::mesh::field_fill(alpha,*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 891 |
testFieldValidation(Fixture,Scalar(0.0),initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 892 |
testFieldValidation(Fixture,Scalar(0.0),alpha,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 893 |
testFieldValidation(Fixture,alpha,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 894 |
} |
| 895 |
|
| 896 |
TEST(FieldBLAS,fill_selector_double) |
| 897 |
{ |
| 898 |
const double initial1 = 4.27; |
| 899 |
const double initial2 = -3.73; |
| 900 |
|
| 901 |
const double alpha = 2.13; |
| 902 |
|
| 903 |
test_fill_selector(alpha,initial1,initial2); |
| 904 |
} |
| 905 |
|
| 906 |
TEST(FieldBLAS,fill_selector_float) |
| 907 |
{ |
| 908 |
const float initial1 = 4.2; |
| 909 |
const float initial2 = -3.7; |
| 910 |
|
| 911 |
const float alpha = 7.21; |
| 912 |
|
| 913 |
test_fill_selector(alpha,initial1,initial2); |
| 914 |
} |
| 915 |
|
| 916 |
TEST(FieldBLAS,fill_selector_complex) |
| 917 |
{ |
| 918 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 919 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 920 |
|
| 921 |
const std::complex<double> alpha = -4.2; |
| 922 |
|
| 923 |
test_fill_selector(alpha,initial1,initial2); |
| 924 |
} |
| 925 |
|
| 926 |
TEST(FieldBLAS,fill_selector_int) |
| 927 |
{ |
| 928 |
const int initial1 = 4; |
| 929 |
const int initial2 = -3; |
| 930 |
const int alpha = 2; |
| 931 |
|
| 932 |
test_fill_selector(alpha,initial1,initial2); |
| 933 |
} |
| 934 |
|
| 935 |
template<class Scalar> |
| 936 |
void test_swap(const Scalar initial1, const Scalar initial2, const Scalar initial3) |
| 937 |
{ |
| 938 |
BLASFixture<Scalar> Fixture (initial1, initial2, initial3); |
| 939 |
|
| 940 |
stk::mesh::field_swap(*Fixture.field1,*Fixture.field3); |
| 941 |
testFieldValidation(Fixture,initial3,initial2,initial1); |
| 942 |
|
| 943 |
stk::mesh::field_swap(*Fixture.field1,*Fixture.field2); |
| 944 |
testFieldValidation(Fixture,initial2,initial3,initial1); |
| 945 |
} |
| 946 |
|
| 947 |
TEST(FieldBLAS,swap_double) |
| 948 |
{ |
| 949 |
const double initial1 = 4.27; |
| 950 |
const double initial2 = -3.73; |
| 951 |
const double initial3 = 1.12; |
| 952 |
|
| 953 |
test_swap(initial1,initial2,initial3); |
| 954 |
} |
| 955 |
|
| 956 |
TEST(FieldBLAS,swap_float) |
| 957 |
{ |
| 958 |
const float initial1 = 4.2; |
| 959 |
const float initial2 = -3.7; |
| 960 |
const float initial3 = 1.1; |
| 961 |
|
| 962 |
test_swap(initial1,initial2,initial3); |
| 963 |
} |
| 964 |
|
| 965 |
TEST(FieldBLAS,swap_complex) |
| 966 |
{ |
| 967 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 968 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 969 |
const std::complex<double> initial3 = std::complex<double>(-2.71,1.12); |
| 970 |
|
| 971 |
test_swap(initial1,initial2,initial3); |
| 972 |
} |
| 973 |
|
| 974 |
TEST(FieldBLAS,swap_int) |
| 975 |
{ |
| 976 |
const int initial1 = 4; |
| 977 |
const int initial2 = -3; |
| 978 |
const int initial3 = 7; |
| 979 |
|
| 980 |
test_swap(initial1,initial2,initial3); |
| 981 |
} |
| 982 |
|
| 983 |
template<class Scalar> |
| 984 |
void test_swap_selector(Scalar initial1,Scalar initial2) |
| 985 |
{ |
| 986 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 987 |
|
| 988 |
stk::mesh::field_swap(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA)); |
| 989 |
testFieldValidation(Fixture,initial2,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 990 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 991 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 992 |
|
| 993 |
stk::mesh::field_swap(*Fixture.fieldBase2,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 994 |
testFieldValidation(Fixture,initial2,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 995 |
testFieldValidation(Fixture,initial2,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 996 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 997 |
|
| 998 |
stk::mesh::field_swap(*Fixture.fieldBase2,*Fixture.fieldBase1); |
| 999 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 1000 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 1001 |
testFieldValidation(Fixture,initial2,initial1,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1002 |
|
| 1003 |
stk::mesh::field_swap(*Fixture.field1,*Fixture.field2,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1004 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA)); |
| 1005 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartB)); |
| 1006 |
testFieldValidation(Fixture,initial1,initial2,Scalar(),stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1007 |
} |
| 1008 |
|
| 1009 |
TEST(FieldBLAS,swap_selector_double) |
| 1010 |
{ |
| 1011 |
const double initial1 = 4.27; |
| 1012 |
const double initial2 = -3.73; |
| 1013 |
|
| 1014 |
test_swap_selector(initial1,initial2); |
| 1015 |
} |
| 1016 |
|
| 1017 |
TEST(FieldBLAS,swap_selector_float) |
| 1018 |
{ |
| 1019 |
const float initial1 = 4.2; |
| 1020 |
const float initial2 = -3.7; |
| 1021 |
|
| 1022 |
test_swap_selector(initial1,initial2); |
| 1023 |
} |
| 1024 |
|
| 1025 |
TEST(FieldBLAS,swap_selector_complex) |
| 1026 |
{ |
| 1027 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 1028 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 1029 |
|
| 1030 |
test_swap_selector(initial1,initial2); |
| 1031 |
} |
| 1032 |
|
| 1033 |
TEST(FieldBLAS,swap_selector_int) |
| 1034 |
{ |
| 1035 |
const int initial1 = 4; |
| 1036 |
const int initial2 = -3; |
| 1037 |
|
| 1038 |
test_swap_selector(initial1,initial2); |
| 1039 |
} |
| 1040 |
|
| 1041 |
template<class Scalar> |
| 1042 |
void test_nrm2(const Scalar initial1,const Scalar initial2,const double TOL = 1.0e-1) |
| 1043 |
{ |
| 1044 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 1045 |
|
| 1046 |
Scalar field_result1 = stk::mesh::field_nrm2(*Fixture.field1); |
| 1047 |
EXPECT_LT(std::abs(field_result1-Scalar(sqrt(std::abs(initial1)*std::abs(initial1)*double(Fixture.numEntitiesGlobal)))),TOL); |
| 1048 |
Scalar field_result2 = stk::mesh::field_nrm2(*Fixture.field2); |
| 1049 |
EXPECT_LT(std::abs(field_result2-Scalar(sqrt(std::abs(initial2)*std::abs(initial2)*double(Fixture.numEntitiesGlobal)))),TOL); |
| 1050 |
|
| 1051 |
Scalar fieldBase_result1; |
| 1052 |
stk::mesh::field_nrm2(fieldBase_result1,*Fixture.fieldBase1); |
| 1053 |
EXPECT_LT(std::abs(fieldBase_result1-Scalar(sqrt(std::abs(initial1)*std::abs(initial1)*double(Fixture.numEntitiesGlobal)))),TOL); |
| 1054 |
Scalar fieldBase_result2; |
| 1055 |
stk::mesh::field_nrm2(fieldBase_result2,*Fixture.fieldBase2); |
| 1056 |
EXPECT_LT(std::abs(fieldBase_result2-Scalar(sqrt(std::abs(initial2)*std::abs(initial2)*double(Fixture.numEntitiesGlobal)))),TOL); |
| 1057 |
} |
| 1058 |
|
| 1059 |
TEST(FieldBLAS,nrm2_double) |
| 1060 |
{ |
| 1061 |
const double initial1 = 4.27; |
| 1062 |
const double initial2 = -3.73; |
| 1063 |
test_nrm2(initial1,initial2); |
| 1064 |
} |
| 1065 |
|
| 1066 |
TEST(FieldBLAS,nrm2_float) |
| 1067 |
{ |
| 1068 |
const float initial1 = 4.2; |
| 1069 |
const float initial2 = -3.7; |
| 1070 |
test_nrm2(initial1,initial2); |
| 1071 |
} |
| 1072 |
|
| 1073 |
TEST(FieldBLAS,nrm2_complex) |
| 1074 |
{ |
| 1075 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 1076 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 1077 |
test_nrm2(initial1,initial2); |
| 1078 |
} |
| 1079 |
|
| 1080 |
TEST(FieldBLAS,nrm2_int) |
| 1081 |
{ |
| 1082 |
const int initial1 = 4; |
| 1083 |
const int initial2 = -3; |
| 1084 |
test_nrm2(initial1,initial2,5); |
| 1085 |
} |
| 1086 |
|
| 1087 |
template<class Scalar> |
| 1088 |
void test_nrm2_selector(Scalar initial1,Scalar initial2,const double TOL = 1.0e-1) |
| 1089 |
{ |
| 1090 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 1091 |
|
| 1092 |
Scalar resultA=stk::mesh::field_nrm2(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1093 |
EXPECT_LT(std::abs(Scalar(std::abs(initial1)*sqrt(Scalar(Fixture.numPartAEntitiesGlobal)))-resultA),TOL); |
| 1094 |
|
| 1095 |
Scalar resultB; |
| 1096 |
stk::mesh::field_nrm2(resultB,*Fixture.fieldBase2,stk::mesh::Selector(*Fixture.pPartB)); |
| 1097 |
EXPECT_LT(std::abs(Scalar(std::abs(initial2)*sqrt(Scalar(Fixture.numPartBEntitiesGlobal)))-resultB),TOL); |
| 1098 |
|
| 1099 |
Scalar resultABc=stk::mesh::field_nrm2(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1100 |
EXPECT_LT(std::abs(Scalar(std::abs(initial1)*sqrt(Scalar(Fixture.numEntitiesGlobal-Fixture.numPartAEntitiesGlobal-Fixture.numPartBEntitiesGlobal)))-resultABc),TOL); |
| 1101 |
} |
| 1102 |
|
| 1103 |
TEST(FieldBLAS,nrm2_selector_double) |
| 1104 |
{ |
| 1105 |
const double initial1 = 4.27; |
| 1106 |
const double initial2 = -3.73; |
| 1107 |
|
| 1108 |
test_nrm2_selector(initial1,initial2); |
| 1109 |
} |
| 1110 |
|
| 1111 |
TEST(FieldBLAS,nrm2_selector_float) |
| 1112 |
{ |
| 1113 |
const float initial1 = 4.2; |
| 1114 |
const float initial2 = -3.7; |
| 1115 |
|
| 1116 |
test_nrm2_selector(initial1,initial2); |
| 1117 |
} |
| 1118 |
|
| 1119 |
TEST(FieldBLAS,nrm2_selector_complex) |
| 1120 |
{ |
| 1121 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 1122 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 1123 |
|
| 1124 |
test_nrm2_selector(initial1,initial2); |
| 1125 |
} |
| 1126 |
|
| 1127 |
TEST(FieldBLAS,nrm2_selector_int) |
| 1128 |
{ |
| 1129 |
const int initial1 = 4; |
| 1130 |
const int initial2 = -3; |
| 1131 |
|
| 1132 |
test_nrm2_selector(initial1,initial2,5); |
| 1133 |
} |
| 1134 |
|
| 1135 |
template<class Scalar> |
| 1136 |
void test_asum(const Scalar initial1,const Scalar initial2,const double TOL = 1.0e-1) |
| 1137 |
{ |
| 1138 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 1139 |
|
| 1140 |
Scalar field_result1 = stk::mesh::field_asum(*Fixture.field1); |
| 1141 |
EXPECT_LT(std::abs(field_result1-std::abs(initial1)*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 1142 |
Scalar field_result2 = stk::mesh::field_asum(*Fixture.field2); |
| 1143 |
EXPECT_LT(std::abs(field_result2-std::abs(initial2)*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 1144 |
|
| 1145 |
Scalar fieldBase_result1; |
| 1146 |
stk::mesh::field_asum(fieldBase_result1,*Fixture.fieldBase1); |
| 1147 |
EXPECT_LT(std::abs(fieldBase_result1-std::abs(initial1)*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 1148 |
Scalar fieldBase_result2; |
| 1149 |
stk::mesh::field_asum(fieldBase_result2,*Fixture.fieldBase2); |
| 1150 |
EXPECT_LT(std::abs(fieldBase_result2-std::abs(initial2)*Scalar(Fixture.numEntitiesGlobal)),TOL); |
| 1151 |
} |
| 1152 |
|
| 1153 |
TEST(FieldBLAS,asum_double) |
| 1154 |
{ |
| 1155 |
const double initial1 = 4.27; |
| 1156 |
const double initial2 = -3.73; |
| 1157 |
test_asum(initial1,initial2); |
| 1158 |
} |
| 1159 |
|
| 1160 |
TEST(FieldBLAS,asum_float) |
| 1161 |
{ |
| 1162 |
const float initial1 = 4.2; |
| 1163 |
const float initial2 = -3.7; |
| 1164 |
test_asum(initial1,initial2); |
| 1165 |
} |
| 1166 |
|
| 1167 |
TEST(FieldBLAS,asum_complex) |
| 1168 |
{ |
| 1169 |
const std::complex<double> initial1 = std::complex<double>(4.11,-7.63); |
| 1170 |
const std::complex<double> initial2 = std::complex<double>(-7.21,-1.23); |
| 1171 |
test_asum(initial1,initial2); |
| 1172 |
} |
| 1173 |
|
| 1174 |
TEST(FieldBLAS,asum_int) |
| 1175 |
{ |
| 1176 |
const int initial1 = 4; |
| 1177 |
const int initial2 = -3; |
| 1178 |
test_asum(initial1,initial2); |
| 1179 |
} |
| 1180 |
|
| 1181 |
template<class Scalar> |
| 1182 |
void test_asum_selector(Scalar initial1,Scalar initial2,const double TOL = 1.0e-1) |
| 1183 |
{ |
| 1184 |
BLASFixture<Scalar> Fixture (initial1,initial2); |
| 1185 |
|
| 1186 |
Scalar resultA=stk::mesh::field_asum(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1187 |
EXPECT_LT(std::abs(std::abs(initial1)*Scalar(Fixture.numPartAEntitiesGlobal)-resultA),TOL); |
| 1188 |
|
| 1189 |
Scalar resultB; |
| 1190 |
stk::mesh::field_asum(resultB,*Fixture.fieldBase2,stk::mesh::Selector(*Fixture.pPartB)); |
| 1191 |
EXPECT_LT(std::abs(std::abs(initial2)*Scalar(Fixture.numPartBEntitiesGlobal)-resultB),TOL); |
| 1192 |
|
| 1193 |
Scalar resultABc=stk::mesh::field_asum(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1194 |
EXPECT_LT(std::abs(std::abs(initial1)*Scalar(Fixture.numEntitiesGlobal-Fixture.numPartAEntitiesGlobal-Fixture.numPartBEntitiesGlobal)-resultABc),TOL); |
| 1195 |
} |
| 1196 |
|
| 1197 |
TEST(FieldBLAS,asum_selector_double) |
| 1198 |
{ |
| 1199 |
const double initial1 = 4.27; |
| 1200 |
const double initial2 = -3.73; |
| 1201 |
|
| 1202 |
test_asum_selector(initial1,initial2); |
| 1203 |
} |
| 1204 |
|
| 1205 |
TEST(FieldBLAS,asum_selector_float) |
| 1206 |
{ |
| 1207 |
const float initial1 = 4.2; |
| 1208 |
const float initial2 = -3.7; |
| 1209 |
|
| 1210 |
test_asum_selector(initial1,initial2); |
| 1211 |
} |
| 1212 |
|
| 1213 |
TEST(FieldBLAS,asum_selector_complex) |
| 1214 |
{ |
| 1215 |
const std::complex<double> initial1 = std::complex<double>(4.27,2.1); |
| 1216 |
const std::complex<double> initial2 = std::complex<double>(-3.73,1.04); |
| 1217 |
|
| 1218 |
test_asum_selector(initial1,initial2); |
| 1219 |
} |
| 1220 |
|
| 1221 |
TEST(FieldBLAS,asum_selector_int) |
| 1222 |
{ |
| 1223 |
const int initial1 = 4; |
| 1224 |
const int initial2 = -3; |
| 1225 |
|
| 1226 |
test_asum_selector(initial1,initial2); |
| 1227 |
} |
| 1228 |
|
| 1229 |
template<class Scalar> |
| 1230 |
void test_amax(Scalar low_val,Scalar high_val) |
| 1231 |
{ |
| 1232 |
BLASFixture<Scalar> Fixture (low_val,low_val); |
| 1233 |
|
| 1234 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1235 |
const stk::mesh::BucketVector buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1236 |
metaData.universal_part() & |
| 1237 |
stk::mesh::selectField(*Fixture.field1) & |
| 1238 |
metaData.locally_owned_part()); |
| 1239 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1240 |
stk::mesh::Bucket & b = *buckets[buckets.size()/3u]; |
| 1241 |
Scalar * x = (Scalar*)stk::mesh::field_data(*Fixture.field1, b); |
| 1242 |
x[b.size()/3u]=high_val*std::abs(low_val/high_val)+Scalar(high_val-high_val*std::abs(low_val/high_val))*MPI_frac; |
| 1243 |
|
| 1244 |
Scalar field_result = stk::mesh::field_amax(*Fixture.field1); |
| 1245 |
EXPECT_EQ(field_result,std::abs(high_val)); |
| 1246 |
|
| 1247 |
Scalar fieldBase_result; |
| 1248 |
stk::mesh::field_amax(fieldBase_result,*Fixture.fieldBase1); |
| 1249 |
EXPECT_EQ(fieldBase_result,std::abs(high_val)); |
| 1250 |
} |
| 1251 |
|
| 1252 |
TEST(FieldBLAS,amax_double) |
| 1253 |
{ |
| 1254 |
const double low_val = 2.73; |
| 1255 |
const double high_val = -10.27; |
| 1256 |
test_amax(low_val,high_val); |
| 1257 |
} |
| 1258 |
|
| 1259 |
TEST(FieldBLAS,amax_float) |
| 1260 |
{ |
| 1261 |
const float low_val = 3.7; |
| 1262 |
const float high_val = -10.2; |
| 1263 |
test_amax(low_val,high_val); |
| 1264 |
} |
| 1265 |
|
| 1266 |
TEST(FieldBLAS,amax_complex) |
| 1267 |
{ |
| 1268 |
const std::complex<double> low_val = std::complex<double>(-1.11,-2.63); |
| 1269 |
const std::complex<double> high_val = std::complex<double>(-100.21,-250.23); |
| 1270 |
test_amax(low_val,high_val); |
| 1271 |
} |
| 1272 |
|
| 1273 |
TEST(FieldBLAS,amax_int) |
| 1274 |
{ |
| 1275 |
const int low_val = 2; |
| 1276 |
const int high_val = -10; |
| 1277 |
test_amax(low_val,high_val); |
| 1278 |
} |
| 1279 |
|
| 1280 |
template<class Scalar> |
| 1281 |
void test_amax_selector(Scalar low_value,Scalar high_valueA,Scalar high_valueAB,Scalar high_valueABc,const double TOL = 1.0e-1) |
| 1282 |
{ |
| 1283 |
BLASFixture<Scalar> Fixture (low_value,low_value); |
| 1284 |
|
| 1285 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1286 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1287 |
|
| 1288 |
Scalar tmp_result; |
| 1289 |
|
| 1290 |
const stk::mesh::BucketVector bucketsA = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1291 |
stk::mesh::Selector(*Fixture.pPartA) & |
| 1292 |
metaData.locally_owned_part()); |
| 1293 |
stk::mesh::Bucket & bA = *bucketsA[bucketsA.size()/3]; |
| 1294 |
Scalar* xA = (Scalar*)stk::mesh::field_data(*Fixture.field1, bA); |
| 1295 |
xA[bA.size()/3u]=high_valueA*std::abs(low_value/high_valueA)+Scalar(high_valueA-high_valueA*std::abs(low_value/high_valueA))*MPI_frac; |
| 1296 |
|
| 1297 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1298 |
EXPECT_LT(std::abs(std::abs(high_valueA)-tmp_result),TOL); |
| 1299 |
EXPECT_LT(std::abs(std::abs(low_value)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1300 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1301 |
EXPECT_LT(std::abs(std::abs(high_valueA)-tmp_result),TOL); |
| 1302 |
EXPECT_LT(std::abs(std::abs(low_value)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement())),TOL); |
| 1303 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1); |
| 1304 |
EXPECT_LT(std::abs(std::abs(high_valueA)-tmp_result),TOL); |
| 1305 |
|
| 1306 |
const stk::mesh::BucketVector bucketsB = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1307 |
stk::mesh::Selector(*Fixture.pPartB) & |
| 1308 |
metaData.locally_owned_part()); |
| 1309 |
stk::mesh::Bucket & bB = *bucketsB[bucketsB.size()/3]; |
| 1310 |
Scalar* xB = (Scalar*)stk::mesh::field_data(*Fixture.field1, bB); |
| 1311 |
xB[bB.size()/3u]=high_valueAB*std::abs(low_value/high_valueAB)+Scalar(high_valueAB-high_valueAB*std::abs(low_value/high_valueAB))*MPI_frac; |
| 1312 |
|
| 1313 |
EXPECT_LT(std::abs(std::abs(high_valueA)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA))),TOL); |
| 1314 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1315 |
EXPECT_LT(std::abs(std::abs(high_valueAB)-tmp_result),TOL); |
| 1316 |
EXPECT_LT(std::abs(std::abs(high_valueAB)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1317 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1318 |
EXPECT_LT(std::abs(std::abs(low_value)-tmp_result),TOL); |
| 1319 |
EXPECT_LT(std::abs(std::abs(high_valueAB)-stk::mesh::field_amax(*Fixture.field1)),TOL); |
| 1320 |
|
| 1321 |
const stk::mesh::BucketVector bucketsABc = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1322 |
stk::mesh::Selector(*Fixture.pPartA).complement() & |
| 1323 |
stk::mesh::Selector(*Fixture.pPartB).complement() & |
| 1324 |
metaData.locally_owned_part()); |
| 1325 |
stk::mesh::Bucket & bABc = *bucketsABc[bucketsABc.size()/3]; |
| 1326 |
Scalar* xABc = (Scalar*)stk::mesh::field_data(*Fixture.field1, bABc); |
| 1327 |
xABc[bABc.size()/3u]=high_valueABc*std::abs(low_value/high_valueABc)+Scalar(high_valueABc-high_valueABc*std::abs(low_value/high_valueABc))*MPI_frac; |
| 1328 |
|
| 1329 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1330 |
EXPECT_LT(std::abs(std::abs(high_valueA)-tmp_result),TOL); |
| 1331 |
EXPECT_LT(std::abs(std::abs(high_valueAB)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1332 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1333 |
EXPECT_LT(std::abs(std::abs(high_valueAB)-tmp_result),TOL); |
| 1334 |
EXPECT_LT(std::abs(std::abs(high_valueABc)-stk::mesh::field_amax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement())),TOL); |
| 1335 |
stk::mesh::field_amax(tmp_result,*Fixture.fieldBase1); |
| 1336 |
EXPECT_LT(std::abs(std::abs(high_valueABc)-tmp_result),TOL); |
| 1337 |
} |
| 1338 |
|
| 1339 |
TEST(FieldBLAS,amax_selector_double) |
| 1340 |
{ |
| 1341 |
const double low_value = 1.27; |
| 1342 |
const double high_valueA = -3.73; |
| 1343 |
const double high_valueAB = -4.43; |
| 1344 |
const double high_valueABc = -5.03; |
| 1345 |
|
| 1346 |
test_amax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1347 |
} |
| 1348 |
|
| 1349 |
TEST(FieldBLAS,amax_selector_float) |
| 1350 |
{ |
| 1351 |
const float low_value = 1.3; |
| 1352 |
const float high_valueA = -3.7; |
| 1353 |
const float high_valueAB = -4.4; |
| 1354 |
const float high_valueABc = -5.0; |
| 1355 |
|
| 1356 |
test_amax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1357 |
} |
| 1358 |
|
| 1359 |
TEST(FieldBLAS,amax_selector_complex) |
| 1360 |
{ |
| 1361 |
const std::complex<double> low_value = std::complex<double>(0.51,0.32); |
| 1362 |
const std::complex<double> high_valueA = std::complex<double>(-3.73,4.04); |
| 1363 |
const std::complex<double> high_valueAB = std::complex<double>(4.95,-5.12); |
| 1364 |
const std::complex<double> high_valueABc = std::complex<double>(-6.03,6.11); |
| 1365 |
|
| 1366 |
test_amax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1367 |
} |
| 1368 |
|
| 1369 |
TEST(FieldBLAS,amax_selector_int) |
| 1370 |
{ |
| 1371 |
const int low_value = 1; |
| 1372 |
const int high_valueA = -3; |
| 1373 |
const int high_valueAB = -4; |
| 1374 |
const int high_valueABc = -5; |
| 1375 |
|
| 1376 |
test_amax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1377 |
} |
| 1378 |
|
| 1379 |
template<class Scalar> |
| 1380 |
void test_eamax(Scalar low_val,Scalar high_val) |
| 1381 |
{ |
| 1382 |
BLASFixture<Scalar> Fixture (low_val,low_val); |
| 1383 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1384 |
const stk::mesh::BucketVector buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1385 |
metaData.universal_part() & |
| 1386 |
stk::mesh::selectField(*Fixture.field1) & |
| 1387 |
metaData.locally_owned_part()); |
| 1388 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1389 |
stk::mesh::Bucket & b = *buckets[buckets.size()/3u]; |
| 1390 |
Scalar * x = (Scalar*)stk::mesh::field_data(*Fixture.field1, b); |
| 1391 |
x[b.size()/3u]=high_val*std::abs(low_val/high_val)+Scalar(high_val-high_val*std::abs(low_val/high_val))*MPI_frac; |
| 1392 |
|
| 1393 |
stk::mesh::Entity field_result = stk::mesh::field_eamax(*Fixture.field1); |
| 1394 |
EXPECT_EQ(MPI_frac==1.0,field_result.is_local_offset_valid()); |
| 1395 |
if (field_result.is_local_offset_valid()) { EXPECT_EQ(*stk::mesh::field_data(*Fixture.field1,field_result),high_val); } |
| 1396 |
|
| 1397 |
stk::mesh::Entity fieldBase_result=stk::mesh::field_eamax(*Fixture.fieldBase1); |
| 1398 |
EXPECT_EQ(MPI_frac==1.0,fieldBase_result.is_local_offset_valid()); |
| 1399 |
if (fieldBase_result.is_local_offset_valid()) { EXPECT_EQ(*stk::mesh::field_data(*Fixture.field1,fieldBase_result),high_val); } |
| 1400 |
} |
| 1401 |
|
| 1402 |
TEST(FieldBLAS,eamax_double) |
| 1403 |
{ |
| 1404 |
const double low_val = 2.731; |
| 1405 |
const double high_val = -10.27; |
| 1406 |
test_eamax(low_val,high_val); |
| 1407 |
} |
| 1408 |
|
| 1409 |
TEST(FieldBLAS,eamax_float) |
| 1410 |
{ |
| 1411 |
const float low_val = 3.7; |
| 1412 |
const float high_val = -10.2; |
| 1413 |
test_eamax(low_val,high_val); |
| 1414 |
} |
| 1415 |
|
| 1416 |
TEST(FieldBLAS,eamax_complex) |
| 1417 |
{ |
| 1418 |
const std::complex<double> low_val = std::complex<double>(-1.11,-2.63); |
| 1419 |
const std::complex<double> high_val = std::complex<double>(-100.21,-250.23); |
| 1420 |
test_eamax(low_val,high_val); |
| 1421 |
} |
| 1422 |
|
| 1423 |
TEST(FieldBLAS,eamax_int) |
| 1424 |
{ |
| 1425 |
const int low_val = 2; |
| 1426 |
const int high_val = -10; |
| 1427 |
test_eamax(low_val,high_val); |
| 1428 |
} |
| 1429 |
|
| 1430 |
template<class Scalar> |
| 1431 |
void test_eamax_selector(Scalar low_value,Scalar high_valueA,Scalar high_valueAB,Scalar high_valueABc,const double TOL = 1.0e-3) |
| 1432 |
{ |
| 1433 |
BLASFixture<Scalar> Fixture (low_value,low_value); |
| 1434 |
|
| 1435 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1436 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1437 |
stk::mesh::Entity tmp_result; |
| 1438 |
|
| 1439 |
const stk::mesh::BucketVector bucketsA = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1440 |
stk::mesh::Selector(*Fixture.pPartA) & |
| 1441 |
metaData.locally_owned_part()); |
| 1442 |
stk::mesh::Bucket & bA = *bucketsA[bucketsA.size()/3]; |
| 1443 |
Scalar* xA = (Scalar*)stk::mesh::field_data(*Fixture.field1, bA); |
| 1444 |
xA[bA.size()/3u]=high_valueA*std::abs(low_value/high_valueA)+Scalar(high_valueA-high_valueA*std::abs(low_value/high_valueA))*MPI_frac; |
| 1445 |
|
| 1446 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1447 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1448 |
|
| 1449 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1450 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1451 |
|
| 1452 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1453 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1454 |
|
| 1455 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1456 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1457 |
|
| 1458 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1); |
| 1459 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1460 |
|
| 1461 |
const stk::mesh::BucketVector bucketsB = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1462 |
stk::mesh::Selector(*Fixture.pPartB) & |
| 1463 |
metaData.locally_owned_part()); |
| 1464 |
stk::mesh::Bucket & bB = *bucketsB[bucketsB.size()/3]; |
| 1465 |
Scalar* xB = (Scalar*)stk::mesh::field_data(*Fixture.field1, bB); |
| 1466 |
xB[bB.size()/3]=high_valueAB*std::abs(low_value/high_valueAB)+Scalar(high_valueAB-high_valueAB*std::abs(low_value/high_valueAB))*MPI_frac; |
| 1467 |
|
| 1468 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1469 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1470 |
|
| 1471 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1472 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1473 |
|
| 1474 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1475 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1476 |
|
| 1477 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1478 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1479 |
|
| 1480 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1); |
| 1481 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1482 |
|
| 1483 |
const stk::mesh::BucketVector bucketsABc = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1484 |
stk::mesh::Selector(*Fixture.pPartA).complement() & |
| 1485 |
stk::mesh::Selector(*Fixture.pPartB).complement() & |
| 1486 |
metaData.locally_owned_part()); |
| 1487 |
stk::mesh::Bucket & bABc = *bucketsABc[bucketsABc.size()/3]; |
| 1488 |
Scalar* xABc = (Scalar*)stk::mesh::field_data(*Fixture.field1, bABc); |
| 1489 |
xABc[bABc.size()/3]=high_valueABc*std::abs(low_value/high_valueABc)+Scalar(high_valueABc-high_valueABc*std::abs(low_value/high_valueABc))*MPI_frac; |
| 1490 |
|
| 1491 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1492 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1493 |
|
| 1494 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1495 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1496 |
|
| 1497 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1498 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1499 |
|
| 1500 |
tmp_result = stk::mesh::field_eamax(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1501 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueABc-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1502 |
|
| 1503 |
tmp_result = stk::mesh::field_eamax(*Fixture.fieldBase1); |
| 1504 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_valueABc-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1505 |
} |
| 1506 |
|
| 1507 |
TEST(FieldBLAS,eamax_selector_double) |
| 1508 |
{ |
| 1509 |
const double low_value = 1.27; |
| 1510 |
const double high_valueA = -3.73; |
| 1511 |
const double high_valueAB = -4.43; |
| 1512 |
const double high_valueABc = -5.03; |
| 1513 |
|
| 1514 |
test_eamax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1515 |
} |
| 1516 |
|
| 1517 |
TEST(FieldBLAS,eamax_selector_float) |
| 1518 |
{ |
| 1519 |
const float low_value = 1.3; |
| 1520 |
const float high_valueA = -3.7; |
| 1521 |
const float high_valueAB = -4.4; |
| 1522 |
const float high_valueABc = -5.0; |
| 1523 |
|
| 1524 |
test_eamax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1525 |
} |
| 1526 |
|
| 1527 |
TEST(FieldBLAS,eamax_selector_complex) |
| 1528 |
{ |
| 1529 |
const std::complex<double> low_value = std::complex<double>(0.51,0.32); |
| 1530 |
const std::complex<double> high_valueA = std::complex<double>(-3.73,4.04); |
| 1531 |
const std::complex<double> high_valueAB = std::complex<double>(4.95,-5.12); |
| 1532 |
const std::complex<double> high_valueABc = std::complex<double>(-6.03,6.11); |
| 1533 |
|
| 1534 |
test_eamax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1535 |
} |
| 1536 |
|
| 1537 |
TEST(FieldBLAS,eamax_selector_int) |
| 1538 |
{ |
| 1539 |
const int low_value = 1; |
| 1540 |
const int high_valueA = -3; |
| 1541 |
const int high_valueAB = -4; |
| 1542 |
const int high_valueABc = -5; |
| 1543 |
|
| 1544 |
test_eamax_selector(low_value,high_valueA,high_valueAB,high_valueABc); |
| 1545 |
} |
| 1546 |
|
| 1547 |
template<class Scalar> |
| 1548 |
void test_amin(Scalar low_val,Scalar high_val,const double TOL = 1.0e-5) |
| 1549 |
{ |
| 1550 |
BLASFixture<Scalar> Fixture (high_val,high_val); |
| 1551 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1552 |
const stk::mesh::BucketVector buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1553 |
metaData.universal_part() & |
| 1554 |
stk::mesh::selectField(*Fixture.field1) & |
| 1555 |
metaData.locally_owned_part()); |
| 1556 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1557 |
stk::mesh::Bucket & b = *buckets[buckets.size()/3u]; |
| 1558 |
Scalar * x = (Scalar*)stk::mesh::field_data(*Fixture.field1, b); |
| 1559 |
x[b.size()/3u]=low_val*std::abs(high_val/low_val)+Scalar(low_val-low_val*std::abs(high_val/low_val))*MPI_frac; |
| 1560 |
|
| 1561 |
Scalar field_result = stk::mesh::field_amin(*Fixture.field1); |
| 1562 |
EXPECT_LT(std::abs(field_result-std::abs(low_val)),TOL); |
| 1563 |
|
| 1564 |
Scalar fieldBase_result; |
| 1565 |
stk::mesh::field_amin(fieldBase_result,*Fixture.field1); |
| 1566 |
EXPECT_LT(std::abs(fieldBase_result-std::abs(low_val)),TOL); |
| 1567 |
} |
| 1568 |
|
| 1569 |
TEST(FieldBLAS,amin_double) |
| 1570 |
{ |
| 1571 |
const double low_val = 2.73; |
| 1572 |
const double high_val = -10.27; |
| 1573 |
test_amin(low_val,high_val); |
| 1574 |
} |
| 1575 |
|
| 1576 |
TEST(FieldBLAS,amin_float) |
| 1577 |
{ |
| 1578 |
const float low_val = 3.7; |
| 1579 |
const float high_val = -10.2; |
| 1580 |
test_amin(low_val,high_val); |
| 1581 |
} |
| 1582 |
|
| 1583 |
TEST(FieldBLAS,amin_complex) |
| 1584 |
{ |
| 1585 |
const std::complex<double> low_val = std::complex<double>(-1.11,-2.63); |
| 1586 |
const std::complex<double> high_val = std::complex<double>(-100.21,-250.23); |
| 1587 |
test_amin(low_val,high_val); |
| 1588 |
} |
| 1589 |
|
| 1590 |
TEST(FieldBLAS,amin_int) |
| 1591 |
{ |
| 1592 |
const int low_val = 2; |
| 1593 |
const int high_val = -10; |
| 1594 |
test_amin(low_val,high_val); |
| 1595 |
} |
| 1596 |
|
| 1597 |
template<class Scalar> |
| 1598 |
void test_amin_selector(Scalar high_value,Scalar low_valueA,Scalar low_valueAB,Scalar low_valueABc,const double TOL = 1.0e-1) |
| 1599 |
{ |
| 1600 |
BLASFixture<Scalar> Fixture (high_value,high_value); |
| 1601 |
|
| 1602 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1603 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1604 |
|
| 1605 |
Scalar tmp_result; |
| 1606 |
|
| 1607 |
const stk::mesh::BucketVector bucketsA = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1608 |
stk::mesh::Selector(*Fixture.pPartA) & |
| 1609 |
metaData.locally_owned_part()); |
| 1610 |
stk::mesh::Bucket & bA = *bucketsA[bucketsA.size()/3]; |
| 1611 |
Scalar* xA = (Scalar*)stk::mesh::field_data(*Fixture.field1, bA); |
| 1612 |
xA[bA.size()/3u]=low_valueA*std::abs(high_value/low_valueA)+Scalar(low_valueA-low_valueA*std::abs(high_value/low_valueA))*MPI_frac; |
| 1613 |
|
| 1614 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1615 |
EXPECT_LT(std::abs(std::abs(low_valueA)-tmp_result),TOL); |
| 1616 |
EXPECT_LT(std::abs(std::abs(high_value)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1617 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1618 |
EXPECT_LT(std::abs(std::abs(low_valueA)-tmp_result),TOL); |
| 1619 |
EXPECT_LT(std::abs(std::abs(high_value)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement())),TOL); |
| 1620 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1); |
| 1621 |
EXPECT_LT(std::abs(std::abs(low_valueA)-tmp_result),TOL); |
| 1622 |
|
| 1623 |
const stk::mesh::BucketVector bucketsB = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1624 |
stk::mesh::Selector(*Fixture.pPartB) & |
| 1625 |
metaData.locally_owned_part()); |
| 1626 |
stk::mesh::Bucket & bB = *bucketsB[bucketsB.size()/3]; |
| 1627 |
Scalar* xB = (Scalar*)stk::mesh::field_data(*Fixture.field1, bB); |
| 1628 |
xB[bB.size()/3u]=low_valueAB*std::abs(high_value/low_valueAB)+Scalar(low_valueAB-low_valueAB*std::abs(high_value/low_valueAB))*MPI_frac; |
| 1629 |
|
| 1630 |
EXPECT_LT(std::abs(std::abs(low_valueA)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA))),TOL); |
| 1631 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1632 |
EXPECT_LT(std::abs(std::abs(low_valueAB)-tmp_result),TOL); |
| 1633 |
EXPECT_LT(std::abs(std::abs(low_valueAB)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1634 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1635 |
EXPECT_LT(std::abs(std::abs(high_value)-tmp_result),TOL); |
| 1636 |
EXPECT_LT(std::abs(std::abs(low_valueAB)-stk::mesh::field_amin(*Fixture.field1)),TOL); |
| 1637 |
|
| 1638 |
const stk::mesh::BucketVector bucketsABc = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1639 |
stk::mesh::Selector(*Fixture.pPartA).complement() & |
| 1640 |
stk::mesh::Selector(*Fixture.pPartB).complement() & |
| 1641 |
metaData.locally_owned_part()); |
| 1642 |
stk::mesh::Bucket & bABc = *bucketsABc[bucketsABc.size()/3]; |
| 1643 |
Scalar* xABc = (Scalar*)stk::mesh::field_data(*Fixture.field1, bABc); |
| 1644 |
xABc[bABc.size()/3u]=low_valueABc*std::abs(high_value/low_valueABc)+Scalar(low_valueABc-low_valueABc*std::abs(high_value/low_valueABc))*MPI_frac; |
| 1645 |
|
| 1646 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1647 |
EXPECT_LT(std::abs(std::abs(low_valueA)-tmp_result),TOL); |
| 1648 |
EXPECT_LT(std::abs(std::abs(low_valueAB)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB))),TOL); |
| 1649 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1650 |
EXPECT_LT(std::abs(std::abs(low_valueAB)-tmp_result),TOL); |
| 1651 |
EXPECT_LT(std::abs(std::abs(low_valueABc)-stk::mesh::field_amin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement())),TOL); |
| 1652 |
stk::mesh::field_amin(tmp_result,*Fixture.fieldBase1); |
| 1653 |
EXPECT_LT(std::abs(std::abs(low_valueABc)-tmp_result),TOL); |
| 1654 |
} |
| 1655 |
|
| 1656 |
TEST(FieldBLAS,amin_selector_double) |
| 1657 |
{ |
| 1658 |
const double high_value = -6.27; |
| 1659 |
const double low_valueA = 5.73; |
| 1660 |
const double low_valueAB = 4.43; |
| 1661 |
const double low_valueABc = 3.03; |
| 1662 |
|
| 1663 |
test_amin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1664 |
} |
| 1665 |
|
| 1666 |
TEST(FieldBLAS,amin_selector_float) |
| 1667 |
{ |
| 1668 |
const float high_value = -6.3; |
| 1669 |
const float low_valueA = 5.7; |
| 1670 |
const float low_valueAB = 4.4; |
| 1671 |
const float low_valueABc = 3.1; |
| 1672 |
|
| 1673 |
test_amin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1674 |
} |
| 1675 |
|
| 1676 |
TEST(FieldBLAS,amin_selector_complex) |
| 1677 |
{ |
| 1678 |
const std::complex<double> high_value = std::complex<double>(7.51,-8.32); |
| 1679 |
const std::complex<double> low_valueA = std::complex<double>(-6.73,6.04); |
| 1680 |
const std::complex<double> low_valueAB = std::complex<double>(4.95,-5.12); |
| 1681 |
const std::complex<double> low_valueABc = std::complex<double>(-4.03,4.11); |
| 1682 |
|
| 1683 |
test_amin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1684 |
} |
| 1685 |
|
| 1686 |
TEST(FieldBLAS,amin_selector_int) |
| 1687 |
{ |
| 1688 |
const int high_value = -6; |
| 1689 |
const int low_valueA = 5; |
| 1690 |
const int low_valueAB = 4; |
| 1691 |
const int low_valueABc = 3; |
| 1692 |
|
| 1693 |
test_amin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1694 |
} |
| 1695 |
|
| 1696 |
template<class Scalar> |
| 1697 |
void test_eamin(Scalar low_val,Scalar high_val,const double TOL = 1.5e-4) |
| 1698 |
{ |
| 1699 |
BLASFixture<Scalar> Fixture (high_val,high_val); |
| 1700 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1701 |
const stk::mesh::BucketVector buckets = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1702 |
metaData.universal_part() & |
| 1703 |
stk::mesh::selectField(*Fixture.field1) & |
| 1704 |
metaData.locally_owned_part()); |
| 1705 |
double MPI_frac = double(stk::parallel_machine_rank(Fixture.stkMeshBulkData->parallel())+1)/double(stk::parallel_machine_size(Fixture.stkMeshBulkData->parallel())); |
| 1706 |
stk::mesh::Bucket & b = *buckets[buckets.size()/3u]; |
| 1707 |
Scalar * x = (Scalar*)stk::mesh::field_data(*Fixture.field1, b); |
| 1708 |
x[b.size()/3u]=low_val*std::abs(high_val/low_val)+Scalar(low_val-low_val*std::abs(high_val/low_val))*MPI_frac; |
| 1709 |
|
| 1710 |
stk::mesh::Entity field_result = stk::mesh::field_eamin(*Fixture.field1); |
| 1711 |
if (field_result.is_local_offset_valid()) { EXPECT_LT(std::abs(*stk::mesh::field_data(*Fixture.field1,field_result)-low_val),TOL); } |
| 1712 |
|
| 1713 |
stk::mesh::Entity fieldBase_result=stk::mesh::field_eamin(*Fixture.fieldBase1); |
| 1714 |
if (fieldBase_result.is_local_offset_valid()) { EXPECT_LT(std::abs(*stk::mesh::field_data(*Fixture.field1,fieldBase_result)-low_val),TOL); } |
| 1715 |
} |
| 1716 |
|
| 1717 |
TEST(FieldBLAS,eamin_double) |
| 1718 |
{ |
| 1719 |
const double low_val = 2.73; |
| 1720 |
const double high_val = -10.27; |
| 1721 |
test_eamin(low_val,high_val); |
| 1722 |
} |
| 1723 |
|
| 1724 |
TEST(FieldBLAS,eamin_float) |
| 1725 |
{ |
| 1726 |
const float low_val = 3.7; |
| 1727 |
const float high_val = -10.2; |
| 1728 |
test_eamin(low_val,high_val); |
| 1729 |
} |
| 1730 |
|
| 1731 |
TEST(FieldBLAS,eamin_complex) |
| 1732 |
{ |
| 1733 |
const std::complex<double> low_val = std::complex<double>(-1.11,-2.63); |
| 1734 |
const std::complex<double> high_val = std::complex<double>(-100.21,-250.23); |
| 1735 |
test_eamin(low_val,high_val); |
| 1736 |
} |
| 1737 |
|
| 1738 |
TEST(FieldBLAS,eamin_int) |
| 1739 |
{ |
| 1740 |
const int low_val = 2; |
| 1741 |
const int high_val = -10; |
| 1742 |
test_eamin(low_val,high_val); |
| 1743 |
} |
| 1744 |
|
| 1745 |
template<class Scalar> |
| 1746 |
void test_eamin_selector(Scalar high_value,Scalar low_valueA,Scalar low_valueAB,Scalar low_valueABc,const double TOL = 1.0e-1) |
| 1747 |
{ |
| 1748 |
BLASFixture<Scalar> Fixture (high_value,high_value); |
| 1749 |
|
| 1750 |
const stk::mesh::MetaData &metaData = Fixture.stkMeshBulkData->mesh_meta_data(); |
| 1751 |
double MPI_frac = double(Fixture.stkMeshBulkData->parallel_rank()+1)/double(Fixture.stkMeshBulkData->parallel_size()); |
| 1752 |
stk::mesh::Entity tmp_result; |
| 1753 |
|
| 1754 |
const stk::mesh::BucketVector bucketsA = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1755 |
stk::mesh::Selector(*Fixture.pPartA) & |
| 1756 |
metaData.locally_owned_part()); |
| 1757 |
stk::mesh::Bucket & bA = *bucketsA[bucketsA.size()/3u]; |
| 1758 |
Scalar* xA = (Scalar*)stk::mesh::field_data(*Fixture.field1, bA); |
| 1759 |
Scalar temp = low_valueA*std::abs(high_value/low_valueA); |
| 1760 |
xA[bA.size()/3u]=temp+Scalar(low_valueA-temp)*MPI_frac; |
| 1761 |
|
| 1762 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1763 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1764 |
|
| 1765 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1766 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1767 |
|
| 1768 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1769 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1770 |
|
| 1771 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1772 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1773 |
|
| 1774 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1); |
| 1775 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1776 |
|
| 1777 |
const stk::mesh::BucketVector bucketsB = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1778 |
stk::mesh::Selector(*Fixture.pPartB) & |
| 1779 |
metaData.locally_owned_part()); |
| 1780 |
stk::mesh::Bucket & bB = *bucketsB[bucketsB.size()/3]; |
| 1781 |
Scalar* xB = (Scalar*)stk::mesh::field_data(*Fixture.field1, bB); |
| 1782 |
xB[bB.size()/3]=low_valueAB*std::abs(high_value/low_valueAB)+Scalar(low_valueAB-low_valueAB*std::abs(high_value/low_valueAB))*MPI_frac; |
| 1783 |
|
| 1784 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1785 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1786 |
|
| 1787 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1788 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1789 |
|
| 1790 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1791 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1792 |
|
| 1793 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1794 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(high_value-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1795 |
|
| 1796 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1); |
| 1797 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1798 |
|
| 1799 |
const stk::mesh::BucketVector bucketsABc = Fixture.stkMeshBulkData->get_buckets(Fixture.field1->entity_rank(), |
| 1800 |
stk::mesh::Selector(*Fixture.pPartA).complement() & |
| 1801 |
stk::mesh::Selector(*Fixture.pPartB).complement() & |
| 1802 |
metaData.locally_owned_part()); |
| 1803 |
stk::mesh::Bucket & bABc = *bucketsABc[bucketsABc.size()/3]; |
| 1804 |
Scalar* xABc = (Scalar*)stk::mesh::field_data(*Fixture.field1, bABc); |
| 1805 |
xABc[bABc.size()/3]=low_valueABc*std::abs(high_value/low_valueABc)+Scalar(low_valueABc-low_valueABc*std::abs(high_value/low_valueABc))*MPI_frac; |
| 1806 |
|
| 1807 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)); |
| 1808 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueA-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1809 |
|
| 1810 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartB)); |
| 1811 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1812 |
|
| 1813 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1,stk::mesh::Selector(*Fixture.pPartA)|stk::mesh::Selector(*Fixture.pPartB)); |
| 1814 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueAB-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1815 |
|
| 1816 |
tmp_result = stk::mesh::field_eamin(*Fixture.field1,stk::mesh::Selector(*Fixture.pPartA).complement()&stk::mesh::Selector(*Fixture.pPartB).complement()); |
| 1817 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueABc-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1818 |
|
| 1819 |
tmp_result = stk::mesh::field_eamin(*Fixture.fieldBase1); |
| 1820 |
if (tmp_result.is_local_offset_valid()) { EXPECT_LT(std::abs(low_valueABc-*stk::mesh::field_data(*Fixture.field1,tmp_result)),TOL); } |
| 1821 |
} |
| 1822 |
|
| 1823 |
TEST(FieldBLAS,eamin_selector_double) |
| 1824 |
{ |
| 1825 |
const double high_value = -6.27; |
| 1826 |
const double low_valueA = 5.73; |
| 1827 |
const double low_valueAB = 4.43; |
| 1828 |
const double low_valueABc = 3.03; |
| 1829 |
|
| 1830 |
test_eamin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1831 |
} |
| 1832 |
|
| 1833 |
TEST(FieldBLAS,eamin_selector_float) |
| 1834 |
{ |
| 1835 |
const float high_value = -6.3; |
| 1836 |
const float low_valueA = 5.7; |
| 1837 |
const float low_valueAB = 4.4; |
| 1838 |
const float low_valueABc = 3.1; |
| 1839 |
|
| 1840 |
test_eamin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1841 |
} |
| 1842 |
|
| 1843 |
TEST(FieldBLAS,eamin_selector_complex) |
| 1844 |
{ |
| 1845 |
const std::complex<double> high_value = std::complex<double>(7.51,-8.32); |
| 1846 |
const std::complex<double> low_valueA = std::complex<double>(-6.73,6.04); |
| 1847 |
const std::complex<double> low_valueAB = std::complex<double>(4.95,-5.12); |
| 1848 |
const std::complex<double> low_valueABc = std::complex<double>(-4.03,4.11); |
| 1849 |
|
| 1850 |
test_eamin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1851 |
} |
| 1852 |
|
| 1853 |
TEST(FieldBLAS,eamin_selector_int) |
| 1854 |
{ |
| 1855 |
const int high_value = -6; |
| 1856 |
const int low_valueA = 5; |
| 1857 |
const int low_valueAB = 4; |
| 1858 |
const int low_valueABc = 3; |
| 1859 |
|
| 1860 |
test_eamin_selector(high_value,low_valueA,low_valueAB,low_valueABc); |
| 1861 |
} |
| 1862 |
|
| 1863 |
template<class A> |
| 1864 |
struct BLASFixture3d { |
| 1865 |
|
| 1866 |
A* init1; |
| 1867 |
A* init2; |
| 1868 |
A* init3; |
| 1869 |
|
| 1870 |
stk::io::StkMeshIoBroker * stkMeshIoBroker; |
| 1871 |
stk::mesh::BulkData * stkMeshBulkData; |
| 1872 |
stk::mesh::Field<A> * field1; |
| 1873 |
stk::mesh::FieldBase * fieldBase1; |
| 1874 |
stk::mesh::Field<A> * field2; |
| 1875 |
stk::mesh::FieldBase * fieldBase2; |
| 1876 |
stk::mesh::Field<A> * field3; |
| 1877 |
stk::mesh::FieldBase * fieldBase3; |
| 1878 |
|
| 1879 |
unsigned int numEntitiesOwned; |
| 1880 |
unsigned int numEntitiesUniversal; |
| 1881 |
unsigned int numEntitiesGlobal; |
| 1882 |
|
| 1883 |
BLASFixture3d(A* init1_input, A* init2_input, A* init3_input); |
| 1884 |
~BLASFixture3d(); |
| 1885 |
}; |
| 1886 |
|
| 1887 |
template<class A> |
| 1888 |
BLASFixture3d<A>::BLASFixture3d(A* init1_input, A* init2_input, A* init3_input) |
| 1889 |
{ |
| 1890 |
init1=init1_input; |
| 1891 |
init2=init2_input; |
| 1892 |
init3=init3_input; |
| 1893 |
|
| 1894 |
const unsigned int meshSizeX = 1; |
| 1895 |
const unsigned int meshSizeY = 1; |
| 1896 |
const unsigned int meshSizeZ = 4; |
| 1897 |
|
| 1898 |
MPI_Comm my_comm = MPI_COMM_WORLD; |
| 1899 |
stkMeshIoBroker = new stk::io::StkMeshIoBroker(my_comm); |
| 1900 |
stk::io::StkMeshIoBroker & io = *stkMeshIoBroker; |
| 1901 |
std::ostringstream osstr; |
| 1902 |
osstr<<"generated:"<<meshSizeX<<"x"<<meshSizeY<<"x"<<meshSizeZ; |
| 1903 |
io.add_mesh_database(osstr.str(), stk::io::READ_MESH); |
| 1904 |
io.create_input_mesh(); |
| 1905 |
stk::mesh::MetaData &meta_data = io.meta_data(); |
| 1906 |
|
| 1907 |
field1 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field1"); |
| 1908 |
stk::mesh::put_field_on_mesh(*field1, field1->mesh_meta_data().universal_part(), 3, init1); |
| 1909 |
fieldBase1 = field1; |
| 1910 |
|
| 1911 |
field2 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field2"); |
| 1912 |
stk::mesh::put_field_on_mesh(*field2, field2->mesh_meta_data().universal_part(), 3, init2); |
| 1913 |
fieldBase2 = field2; |
| 1914 |
|
| 1915 |
field3 = &meta_data.declare_field<A>(stk::topology::NODE_RANK, "field3"); |
| 1916 |
stk::mesh::put_field_on_mesh(*field3, field3->mesh_meta_data().universal_part(), 3, init3); |
| 1917 |
fieldBase3 = field3; |
| 1918 |
|
| 1919 |
io.populate_bulk_data(); // THIS IS THE SLOW LINE |
| 1920 |
stkMeshBulkData = &io.bulk_data(); |
| 1921 |
|
| 1922 |
numEntitiesOwned = 0; |
| 1923 |
numEntitiesUniversal = 0; |
| 1924 |
const stk::mesh::BucketVector & buckets = stkMeshBulkData->get_buckets(stk::topology::NODE_RANK, meta_data.universal_part()); |
| 1925 |
for(const stk::mesh::Bucket *bucket : buckets) { |
| 1926 |
numEntitiesUniversal += bucket->size(); |
| 1927 |
if (bucket->owned()) |
| 1928 |
numEntitiesOwned += bucket->size(); |
| 1929 |
} |
| 1930 |
|
| 1931 |
numEntitiesGlobal = 0; |
| 1932 |
stk::all_reduce_sum(stkMeshBulkData->parallel(),&numEntitiesOwned,&numEntitiesGlobal,1u); |
| 1933 |
EXPECT_EQ(numEntitiesGlobal, (meshSizeX+1) * (meshSizeY+1) * (meshSizeZ+1)); |
| 1934 |
} |
| 1935 |
|
| 1936 |
template<class A> |
| 1937 |
BLASFixture3d<A>::~BLASFixture3d() { |
| 1938 |
delete stkMeshIoBroker; |
| 1939 |
} |
| 1940 |
|
| 1941 |
template<class A> |
| 1942 |
bool test3dfield(const stk::mesh::Field<A> & field,const A* expected_value,const double tol=1.5e-3) |
| 1943 |
{ |
| 1944 |
bool result=true; |
| 1945 |
const stk::mesh::BucketVector& buckets_init = field.get_mesh().get_buckets(field.entity_rank(),field.mesh_meta_data().universal_part() & stk::mesh::selectField(field)); |
| 1946 |
for(size_t j = 0; j < buckets_init.size(); j++) { |
| 1947 |
const stk::mesh::Bucket& bucket = *buckets_init[j]; |
| 1948 |
for(size_t i=0; i<bucket.size(); i++) { |
| 1949 |
A* field_value = reinterpret_cast<A*>(stk::mesh::field_data(field,bucket[i])); |
| 1950 |
if (result) { |
| 1951 |
for (unsigned int k=0;k<3u;k++) { |
| 1952 |
EXPECT_NEAR(expected_value[k],field_value[k],tol); |
| 1953 |
if (std::abs(expected_value[k]-field_value[k])>tol) result=false; |
| 1954 |
} |
| 1955 |
} |
| 1956 |
} |
| 1957 |
} |
| 1958 |
return result; |
| 1959 |
} |
| 1960 |
|
| 1961 |
template<class A> |
| 1962 |
bool test3dfield(const stk::mesh::Field<std::complex<A>> & field, |
| 1963 |
const std::complex<A>* expected_value, const double tol=1.5e-3) |
| 1964 |
{ |
| 1965 |
bool result=true; |
| 1966 |
const stk::mesh::BucketVector& buckets_init = field.get_mesh().get_buckets(field.entity_rank(),field.mesh_meta_data().universal_part() & stk::mesh::selectField(field)); |
| 1967 |
for(size_t j = 0; j < buckets_init.size(); j++) { |
| 1968 |
const stk::mesh::Bucket& bucket = *buckets_init[j]; |
| 1969 |
for(size_t i=0; i<bucket.size(); i++) { |
| 1970 |
std::complex<A>* field_value = reinterpret_cast<std::complex<A>*>(stk::mesh::field_data(field,bucket[i])); |
| 1971 |
if (result) { |
| 1972 |
for (unsigned int k=0;k<3u;k++) { |
| 1973 |
EXPECT_LT(std::abs(expected_value[k]-field_value[k]),tol); |
| 1974 |
if (std::abs(expected_value[k]-field_value[k])>tol) result=false; |
| 1975 |
} |
| 1976 |
} |
| 1977 |
} |
| 1978 |
} |
| 1979 |
return result; |
| 1980 |
} |
| 1981 |
|
| 1982 |
template<class Scalar> |
| 1983 |
void test_coordinate_axpy(BLASFixture3d<Scalar> &fixture,const Scalar alpha) |
| 1984 |
{ |
| 1985 |
Scalar result2 [3]; |
| 1986 |
for (int i=0;i<3;i++) result2[i]=fixture.init1[i]*alpha+fixture.init2[i]; |
| 1987 |
Scalar result3 [3]; |
| 1988 |
for (int i=0;i<3;i++) result3[i]=fixture.init1[i]*alpha+fixture.init3[i]; |
| 1989 |
|
| 1990 |
stk::mesh::field_axpy(alpha,*fixture.field1,*fixture.field2); |
| 1991 |
stk::mesh::field_axpy(alpha,*fixture.fieldBase1,*fixture.fieldBase3); |
| 1992 |
|
| 1993 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init1)); |
| 1994 |
EXPECT_TRUE(test3dfield(*fixture.field2,result2)); |
| 1995 |
EXPECT_TRUE(test3dfield(*fixture.field3,result3)); |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
TEST(FieldBLAS,coordinate_axpy_double) |
| 2000 |
{ |
| 2001 |
const double alpha = 4.11; |
| 2002 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2003 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2004 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2005 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2006 |
test_coordinate_axpy<double>(fixture,alpha); |
| 2007 |
} |
| 2008 |
|
| 2009 |
TEST(FieldBLAS,coordinate_axpy_float) |
| 2010 |
{ |
| 2011 |
const float alpha = 4.1; |
| 2012 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2013 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2014 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2015 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2016 |
test_coordinate_axpy<float>(fixture,alpha); |
| 2017 |
} |
| 2018 |
|
| 2019 |
TEST(FieldBLAS,coordinate_axpy_complex) |
| 2020 |
{ |
| 2021 |
const std::complex<double> alpha = std::complex<double>(4.11,-32.1); |
| 2022 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2023 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2024 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2025 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2026 |
|
| 2027 |
test_coordinate_axpy<std::complex<double> >(fixture,alpha); |
| 2028 |
} |
| 2029 |
|
| 2030 |
TEST(FieldBLAS,coordinate_axpy_int) |
| 2031 |
{ |
| 2032 |
const int alpha = 4; |
| 2033 |
int init1 [3] = {4,1,-2}; |
| 2034 |
int init2 [3] = {3,4,11}; |
| 2035 |
int init3 [3] = {8,-7,3}; |
| 2036 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2037 |
|
| 2038 |
test_coordinate_axpy<int>(fixture,alpha); |
| 2039 |
} |
| 2040 |
|
| 2041 |
template<class Scalar> |
| 2042 |
void test_coordinate_copy(BLASFixture3d<Scalar> &fixture) |
| 2043 |
{ |
| 2044 |
stk::mesh::field_copy(*fixture.field1,*fixture.field2); |
| 2045 |
stk::mesh::field_copy(*fixture.fieldBase3,*fixture.fieldBase1); |
| 2046 |
|
| 2047 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init3)); |
| 2048 |
EXPECT_TRUE(test3dfield(*fixture.field2,fixture.init1)); |
| 2049 |
EXPECT_TRUE(test3dfield(*fixture.field3,fixture.init3)); |
| 2050 |
} |
| 2051 |
|
| 2052 |
|
| 2053 |
TEST(FieldBLAS,coordinate_copy_double) |
| 2054 |
{ |
| 2055 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2056 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2057 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2058 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2059 |
test_coordinate_copy<double>(fixture); |
| 2060 |
} |
| 2061 |
|
| 2062 |
TEST(FieldBLAS,coordinate_copy_float) |
| 2063 |
{ |
| 2064 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2065 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2066 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2067 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2068 |
test_coordinate_copy<float>(fixture); |
| 2069 |
} |
| 2070 |
|
| 2071 |
TEST(FieldBLAS,coordinate_copy_complex) |
| 2072 |
{ |
| 2073 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2074 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2075 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2076 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2077 |
|
| 2078 |
test_coordinate_copy<std::complex<double> >(fixture); |
| 2079 |
} |
| 2080 |
|
| 2081 |
TEST(FieldBLAS,coordinate_copy_int) |
| 2082 |
{ |
| 2083 |
int init1 [3] = {4,1,-2}; |
| 2084 |
int init2 [3] = {3,4,11}; |
| 2085 |
int init3 [3] = {8,-7,3}; |
| 2086 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2087 |
|
| 2088 |
test_coordinate_copy<int>(fixture); |
| 2089 |
} |
| 2090 |
|
| 2091 |
template<class Scalar> |
| 2092 |
void test_coordinate_product(BLASFixture3d<Scalar> &fixture) |
| 2093 |
{ |
| 2094 |
Scalar result3 [3]; |
| 2095 |
for (int i=0;i<3;i++) result3[i]=fixture.init1[i]*fixture.init2[i]; |
| 2096 |
Scalar result2 [3]; |
| 2097 |
for (int i=0;i<3;i++) result2[i]=fixture.init1[i]*result3[i]; |
| 2098 |
|
| 2099 |
stk::mesh::field_product(*fixture.field1,*fixture.field2,*fixture.field3); |
| 2100 |
stk::mesh::field_product(*fixture.fieldBase3,*fixture.fieldBase1,*fixture.fieldBase2); |
| 2101 |
|
| 2102 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init1)); |
| 2103 |
EXPECT_TRUE(test3dfield(*fixture.field2,result2)); |
| 2104 |
EXPECT_TRUE(test3dfield(*fixture.field3,result3)); |
| 2105 |
} |
| 2106 |
|
| 2107 |
|
| 2108 |
TEST(FieldBLAS,coordinate_product_double) |
| 2109 |
{ |
| 2110 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2111 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2112 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2113 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2114 |
test_coordinate_product<double>(fixture); |
| 2115 |
} |
| 2116 |
|
| 2117 |
TEST(FieldBLAS,coordinate_product_float) |
| 2118 |
{ |
| 2119 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2120 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2121 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2122 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2123 |
test_coordinate_product<float>(fixture); |
| 2124 |
} |
| 2125 |
|
| 2126 |
TEST(FieldBLAS,coordinate_product_complex) |
| 2127 |
{ |
| 2128 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2129 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2130 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2131 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2132 |
|
| 2133 |
test_coordinate_product<std::complex<double> >(fixture); |
| 2134 |
} |
| 2135 |
|
| 2136 |
TEST(FieldBLAS,coordinate_product_int) |
| 2137 |
{ |
| 2138 |
int init1 [3] = {4,1,-2}; |
| 2139 |
int init2 [3] = {3,4,11}; |
| 2140 |
int init3 [3] = {8,-7,3}; |
| 2141 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2142 |
|
| 2143 |
test_coordinate_product<int>(fixture); |
| 2144 |
} |
| 2145 |
|
| 2146 |
template<class Scalar> |
| 2147 |
void test_coordinate_dot(BLASFixture3d<Scalar> &fixture,const double tol=1.5e-3) |
| 2148 |
{ |
| 2149 |
Scalar expected_result12(0.0); |
| 2150 |
for (int i=0;i<3;i++) expected_result12+=fixture.init1[i]*fixture.init2[i]; |
| 2151 |
Scalar expected_result23(0.0); |
| 2152 |
for (int i=0;i<3;i++) expected_result23+=fixture.init2[i]*fixture.init3[i]; |
| 2153 |
|
| 2154 |
Scalar field_result = stk::mesh::field_dot(*fixture.field1,*fixture.field2); |
| 2155 |
EXPECT_NEAR(field_result,expected_result12*Scalar(fixture.numEntitiesGlobal),tol); |
| 2156 |
|
| 2157 |
Scalar fieldBase_result; |
| 2158 |
stk::mesh::field_dot(fieldBase_result,*fixture.fieldBase2,*fixture.fieldBase3); |
| 2159 |
EXPECT_NEAR(fieldBase_result,expected_result23*Scalar(fixture.numEntitiesGlobal),tol); |
| 2160 |
} |
| 2161 |
|
| 2162 |
template<class Scalar> |
| 2163 |
void test_coordinate_dot(BLASFixture3d<std::complex<Scalar> > &fixture,const double tol=1.5e-3) |
| 2164 |
{ |
| 2165 |
std::complex<Scalar> result=std::complex<Scalar>(0.0); |
| 2166 |
for (int i=0;i<3;i++) result+=fixture.init1[i]*fixture.init2[i]; |
| 2167 |
std::complex<Scalar> result2=std::complex<Scalar>(0.0); |
| 2168 |
for (int i=0;i<3;i++) result2+=fixture.init2[i]*fixture.init3[i]; |
| 2169 |
|
| 2170 |
EXPECT_LT(std::abs(stk::mesh::field_dot(*fixture.field1,*fixture.field2)-result*Scalar(fixture.numEntitiesGlobal)),tol); |
| 2171 |
std::complex<Scalar> tmp; |
| 2172 |
stk::mesh::field_dot(tmp,*fixture.fieldBase2,*fixture.fieldBase3); |
| 2173 |
EXPECT_LT(std::abs(tmp-result2*Scalar(fixture.numEntitiesGlobal)),tol); |
| 2174 |
} |
| 2175 |
|
| 2176 |
TEST(FieldBLAS,coordinate_dot_double) |
| 2177 |
{ |
| 2178 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2179 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2180 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2181 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2182 |
test_coordinate_dot(fixture); |
| 2183 |
} |
| 2184 |
|
| 2185 |
TEST(FieldBLAS,coordinate_dot_float) |
| 2186 |
{ |
| 2187 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2188 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2189 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2190 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2191 |
test_coordinate_dot(fixture,0.5); |
| 2192 |
} |
| 2193 |
|
| 2194 |
TEST(FieldBLAS,coordinate_dot_complex) |
| 2195 |
{ |
| 2196 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2197 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2198 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2199 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2200 |
|
| 2201 |
test_coordinate_dot(fixture); |
| 2202 |
} |
| 2203 |
|
| 2204 |
TEST(FieldBLAS,coordinate_dot_int) |
| 2205 |
{ |
| 2206 |
int init1 [3] = {4,1,-2}; |
| 2207 |
int init2 [3] = {3,4,11}; |
| 2208 |
int init3 [3] = {8,-7,3}; |
| 2209 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2210 |
|
| 2211 |
test_coordinate_dot(fixture); |
| 2212 |
} |
| 2213 |
|
| 2214 |
template<class Scalar> |
| 2215 |
void test_coordinate_scale(BLASFixture3d<Scalar> &fixture,const Scalar alpha) |
| 2216 |
{ |
| 2217 |
Scalar result2 [3]; |
| 2218 |
for (int i=0;i<3;i++) result2[i]=fixture.init2[i]*alpha; |
| 2219 |
Scalar result3 [3]; |
| 2220 |
for (int i=0;i<3;i++) result3[i]=fixture.init3[i]*alpha; |
| 2221 |
|
| 2222 |
stk::mesh::field_scale(alpha,*fixture.field2); |
| 2223 |
stk::mesh::field_scale(alpha,*fixture.fieldBase3); |
| 2224 |
|
| 2225 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init1)); |
| 2226 |
EXPECT_TRUE(test3dfield(*fixture.field2,result2)); |
| 2227 |
EXPECT_TRUE(test3dfield(*fixture.field3,result3)); |
| 2228 |
} |
| 2229 |
|
| 2230 |
|
| 2231 |
TEST(FieldBLAS,coordinate_scale_double) |
| 2232 |
{ |
| 2233 |
const double alpha = 4.11; |
| 2234 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2235 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2236 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2237 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2238 |
|
| 2239 |
test_coordinate_scale<double>(fixture,alpha); |
| 2240 |
} |
| 2241 |
|
| 2242 |
TEST(FieldBLAS,coordinate_scale_float) |
| 2243 |
{ |
| 2244 |
const float alpha = 4.1; |
| 2245 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2246 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2247 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2248 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2249 |
|
| 2250 |
test_coordinate_scale<float>(fixture,alpha); |
| 2251 |
} |
| 2252 |
|
| 2253 |
TEST(FieldBLAS,coordinate_scale_complex) |
| 2254 |
{ |
| 2255 |
const std::complex<double> alpha = std::complex<double>(4.11,-32.1); |
| 2256 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2257 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2258 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2259 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2260 |
|
| 2261 |
test_coordinate_scale<std::complex<double> >(fixture,alpha); |
| 2262 |
} |
| 2263 |
|
| 2264 |
TEST(FieldBLAS,coordinate_scale_int) |
| 2265 |
{ |
| 2266 |
const int alpha = 4; |
| 2267 |
int init1 [3] = {4,1,-2}; |
| 2268 |
int init2 [3] = {3,4,11}; |
| 2269 |
int init3 [3] = {8,-7,3}; |
| 2270 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2271 |
|
| 2272 |
test_coordinate_scale<int>(fixture,alpha); |
| 2273 |
} |
| 2274 |
|
| 2275 |
template<class Scalar> |
| 2276 |
void test_coordinate_fill(BLASFixture3d<Scalar> &fixture,const Scalar alpha) |
| 2277 |
{ |
| 2278 |
Scalar alpha_list [3] = {alpha,alpha,alpha}; |
| 2279 |
stk::mesh::field_fill(alpha,*fixture.field2); |
| 2280 |
stk::mesh::field_fill(alpha,*fixture.fieldBase3); |
| 2281 |
|
| 2282 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init1)); |
| 2283 |
EXPECT_TRUE(test3dfield(*fixture.field2,alpha_list)); |
| 2284 |
EXPECT_TRUE(test3dfield(*fixture.field3,alpha_list)); |
| 2285 |
} |
| 2286 |
|
| 2287 |
|
| 2288 |
TEST(FieldBLAS,coordinate_fill_double) |
| 2289 |
{ |
| 2290 |
const double alpha = 4.11; |
| 2291 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2292 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2293 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2294 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2295 |
test_coordinate_fill<double>(fixture,alpha); |
| 2296 |
} |
| 2297 |
|
| 2298 |
TEST(FieldBLAS,coordinate_fill_float) |
| 2299 |
{ |
| 2300 |
const float alpha = 4.1; |
| 2301 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2302 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2303 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2304 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2305 |
test_coordinate_fill<float>(fixture,alpha); |
| 2306 |
} |
| 2307 |
|
| 2308 |
TEST(FieldBLAS,coordinate_fill_complex) |
| 2309 |
{ |
| 2310 |
const std::complex<double> alpha = std::complex<double>(4.11,-32.1); |
| 2311 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2312 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2313 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2314 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2315 |
|
| 2316 |
test_coordinate_fill<std::complex<double> >(fixture,alpha); |
| 2317 |
} |
| 2318 |
|
| 2319 |
TEST(FieldBLAS,coordinate_fill_int) |
| 2320 |
{ |
| 2321 |
const int alpha = 4; |
| 2322 |
int init1 [3] = {4,1,-2}; |
| 2323 |
int init2 [3] = {3,4,11}; |
| 2324 |
int init3 [3] = {8,-7,3}; |
| 2325 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2326 |
|
| 2327 |
test_coordinate_fill<int>(fixture,alpha); |
| 2328 |
} |
| 2329 |
|
| 2330 |
template<class Scalar> |
| 2331 |
void test_coordinate_fill_component(BLASFixture3d<Scalar> &fixture,const Scalar* alpha) |
| 2332 |
{ |
| 2333 |
stk::mesh::field_fill_component(alpha,*fixture.field2); |
| 2334 |
stk::mesh::field_fill_component(alpha,*fixture.fieldBase3); |
| 2335 |
|
| 2336 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init1)); |
| 2337 |
EXPECT_TRUE(test3dfield(*fixture.field2,alpha)); |
| 2338 |
EXPECT_TRUE(test3dfield(*fixture.field3,alpha)); |
| 2339 |
} |
| 2340 |
|
| 2341 |
|
| 2342 |
TEST(FieldBLAS,coordinate_fill_component_double) |
| 2343 |
{ |
| 2344 |
double alpha [3] = {4.11,2.11,-3.12}; |
| 2345 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2346 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2347 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2348 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2349 |
test_coordinate_fill_component<double>(fixture,alpha); |
| 2350 |
} |
| 2351 |
|
| 2352 |
TEST(FieldBLAS,coordinate_fill_component_float) |
| 2353 |
{ |
| 2354 |
float alpha [3] = {4.1,2.1,-3.1}; |
| 2355 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2356 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2357 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2358 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2359 |
test_coordinate_fill_component<float>(fixture,alpha); |
| 2360 |
} |
| 2361 |
|
| 2362 |
TEST(FieldBLAS,coordinate_fill_component_complex) |
| 2363 |
{ |
| 2364 |
std::complex<double> alpha [3] = {std::complex<double>(4.11,-3.1),std::complex<double>(2.17,-0.25),std::complex<double>(7.14,-38.1)}; |
| 2365 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.13),std::complex<double>(-2.13,4.11)}; |
| 2366 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.24),std::complex<double>(11.27,4.21)}; |
| 2367 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2368 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2369 |
|
| 2370 |
test_coordinate_fill_component<std::complex<double> >(fixture,alpha); |
| 2371 |
} |
| 2372 |
|
| 2373 |
TEST(FieldBLAS,coordinate_fill_component_int) |
| 2374 |
{ |
| 2375 |
int alpha [3] = {2,-3,6}; |
| 2376 |
int init1 [3] = {4,1,-2}; |
| 2377 |
int init2 [3] = {3,4,11}; |
| 2378 |
int init3 [3] = {8,-7,3}; |
| 2379 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2380 |
|
| 2381 |
test_coordinate_fill_component<int>(fixture,alpha); |
| 2382 |
} |
| 2383 |
|
| 2384 |
template<class Scalar> |
| 2385 |
void test_coordinate_swap(BLASFixture3d<Scalar> &fixture) |
| 2386 |
{ |
| 2387 |
stk::mesh::field_swap(*fixture.field1,*fixture.field2); |
| 2388 |
stk::mesh::field_swap(*fixture.fieldBase3,*fixture.fieldBase1); |
| 2389 |
|
| 2390 |
EXPECT_TRUE(test3dfield(*fixture.field1,fixture.init3)); |
| 2391 |
EXPECT_TRUE(test3dfield(*fixture.field2,fixture.init1)); |
| 2392 |
EXPECT_TRUE(test3dfield(*fixture.field3,fixture.init2)); |
| 2393 |
} |
| 2394 |
|
| 2395 |
TEST(FieldBLAS,coordinate_swap_double) |
| 2396 |
{ |
| 2397 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2398 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2399 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2400 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2401 |
test_coordinate_swap<double>(fixture); |
| 2402 |
} |
| 2403 |
|
| 2404 |
TEST(FieldBLAS,coordinate_swap_float) |
| 2405 |
{ |
| 2406 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2407 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2408 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2409 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2410 |
test_coordinate_swap<float>(fixture); |
| 2411 |
} |
| 2412 |
|
| 2413 |
TEST(FieldBLAS,coordinate_swap_complex) |
| 2414 |
{ |
| 2415 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2416 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2417 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2418 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2419 |
|
| 2420 |
test_coordinate_swap<std::complex<double> >(fixture); |
| 2421 |
} |
| 2422 |
|
| 2423 |
TEST(FieldBLAS,coordinate_swap_int) |
| 2424 |
{ |
| 2425 |
int init1 [3] = {4,1,-2}; |
| 2426 |
int init2 [3] = {3,4,11}; |
| 2427 |
int init3 [3] = {8,-7,3}; |
| 2428 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2429 |
|
| 2430 |
test_coordinate_swap<int>(fixture); |
| 2431 |
} |
| 2432 |
|
| 2433 |
template<class Scalar> |
| 2434 |
void test_coordinate_nrm2(BLASFixture3d<Scalar> &fixture,const double tol=1.5e-3) |
| 2435 |
{ |
| 2436 |
double result1 = 0.0; |
| 2437 |
for (int i=0; i<3; i++) result1+=pow(std::abs(fixture.init1[i]),2); |
| 2438 |
result1=sqrt(result1); |
| 2439 |
double result2=0.0; |
| 2440 |
for (int i=0; i<3; i++) result2+=pow(std::abs(fixture.init2[i]),2); |
| 2441 |
result2=sqrt(result2); |
| 2442 |
|
| 2443 |
EXPECT_LT(std::abs(stk::mesh::field_nrm2(*fixture.field1)-Scalar(result1*sqrt(double(fixture.numEntitiesGlobal)))),tol); |
| 2444 |
Scalar tmp; |
| 2445 |
stk::mesh::field_nrm2(tmp,*fixture.fieldBase2); |
| 2446 |
EXPECT_LT(std::abs(tmp-Scalar(result2*sqrt(double(fixture.numEntitiesGlobal)))),tol); |
| 2447 |
} |
| 2448 |
|
| 2449 |
TEST(FieldBLAS,coordinate_nrm2_double) |
| 2450 |
{ |
| 2451 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2452 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2453 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2454 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2455 |
test_coordinate_nrm2<double>(fixture); |
| 2456 |
} |
| 2457 |
|
| 2458 |
TEST(FieldBLAS,coordinate_nrm2_float) |
| 2459 |
{ |
| 2460 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2461 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2462 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2463 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2464 |
test_coordinate_nrm2<float>(fixture,0.5); |
| 2465 |
} |
| 2466 |
|
| 2467 |
TEST(FieldBLAS,coordinate_nrm2_complex) |
| 2468 |
{ |
| 2469 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2470 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2471 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2472 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2473 |
|
| 2474 |
test_coordinate_nrm2<std::complex<double> >(fixture); |
| 2475 |
} |
| 2476 |
|
| 2477 |
TEST(FieldBLAS,coordinate_nrm2_int) |
| 2478 |
{ |
| 2479 |
int init1 [3] = {4,1,-2}; |
| 2480 |
int init2 [3] = {3,4,11}; |
| 2481 |
int init3 [3] = {8,-7,3}; |
| 2482 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2483 |
|
| 2484 |
test_coordinate_nrm2<int>(fixture,2); |
| 2485 |
} |
| 2486 |
|
| 2487 |
template<class Scalar> |
| 2488 |
void test_coordinate_asum(BLASFixture3d<Scalar> &fixture,const double tol=1.5e-3) |
| 2489 |
{ |
| 2490 |
Scalar result1(0.0); |
| 2491 |
for (int i=0;i<3;i++) result1+=std::abs(fixture.init1[i]); |
| 2492 |
Scalar result2(0.0); |
| 2493 |
for (int i=0;i<3;i++) result2+=std::abs(fixture.init2[i]); |
| 2494 |
|
| 2495 |
EXPECT_LT(std::abs(stk::mesh::field_asum(*fixture.field1)-result1*Scalar(fixture.numEntitiesGlobal)),tol); |
| 2496 |
Scalar tmp; |
| 2497 |
stk::mesh::field_asum(tmp,*fixture.fieldBase2); |
| 2498 |
EXPECT_LT(std::abs(tmp-result2*Scalar(fixture.numEntitiesGlobal)),tol); |
| 2499 |
} |
| 2500 |
|
| 2501 |
|
| 2502 |
TEST(FieldBLAS,coordinate_asum_double) |
| 2503 |
{ |
| 2504 |
double init1 [3] = {4.21,1.23,-2.13}; |
| 2505 |
double init2 [3] = {1.32,4.17,11.27}; |
| 2506 |
double init3 [3] = {0.24,-7.11,3.21}; |
| 2507 |
BLASFixture3d<double> fixture (init1,init2,init3); |
| 2508 |
test_coordinate_asum<double>(fixture); |
| 2509 |
} |
| 2510 |
|
| 2511 |
TEST(FieldBLAS,coordinate_asum_float) |
| 2512 |
{ |
| 2513 |
float init1 [3] = {4.2,1.2,-2.1}; |
| 2514 |
float init2 [3] = {1.3,4.1,11.2}; |
| 2515 |
float init3 [3] = {0.2,-7.1,3.2}; |
| 2516 |
BLASFixture3d<float> fixture (init1,init2,init3); |
| 2517 |
test_coordinate_asum<float>(fixture,0.5); |
| 2518 |
} |
| 2519 |
|
| 2520 |
TEST(FieldBLAS,coordinate_asum_complex) |
| 2521 |
{ |
| 2522 |
std::complex<double> init1 [3] = {std::complex<double>(4.21,0.24),std::complex<double>(1.23,-0.1),std::complex<double>(-2.13,4.11)}; |
| 2523 |
std::complex<double> init2 [3] = {std::complex<double>(1.32,23.1),std::complex<double>(4.17,-0.2),std::complex<double>(11.27,4.21)}; |
| 2524 |
std::complex<double> init3 [3] = {std::complex<double>(0.24,-1.22),std::complex<double>(-7.11,42.1),std::complex<double>(3.21,7.11)}; |
| 2525 |
BLASFixture3d<std::complex<double> > fixture (init1,init2,init3); |
| 2526 |
|
| 2527 |
test_coordinate_asum<std::complex<double> >(fixture); |
| 2528 |
} |
| 2529 |
|
| 2530 |
TEST(FieldBLAS,coordinate_asum_int) |
| 2531 |
{ |
| 2532 |
int init1 [3] = {4,1,-2}; |
| 2533 |
int init2 [3] = {3,4,11}; |
| 2534 |
int init3 [3] = {8,-7,3}; |
| 2535 |
BLASFixture3d<int> fixture (init1,init2,init3); |
| 2536 |
|
| 2537 |
test_coordinate_asum<int>(fixture); |
| 2538 |
} |