240 TEUCHOS_TEST_FOR_EXCEPTION( outBlockMV->getNumVectors()>1, std::runtime_error,
"BCBuilder::setRHS() only for getNumVectors == 1.");
246 for (
int block = 0; block < outBlockMV->size(); block++) {
248 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
249 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
250 int dim = vecDomain_.at(loc)->getDimension();
251 int dofs = vecDofs_.at(loc);
253 result.resize(dofs,0.);
254 point.resize(dim,0.);
256 resultPtr_ = Teuchos::rcp(
new vec_dbl_Type(dofs,0.));
257 pointPtr_ = Teuchos::rcp(
new vec_dbl_Type(dim,0.));
259 Teuchos::ArrayRCP<SC> valuesRHS = outBlockMV->getBlock(block)->getDataNonConst(0);
260 Teuchos::ArrayRCP<SC> valuesSubstract = substractBlockMV->getBlock(block)->getDataNonConst(0);
262 for (
int i = 0 ; i < bcFlags->size(); i++) {
263 int flag = bcFlags->at(i);
265 if (!vecBCType_.at(loc).compare(
"Dirichlet") ||
266 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
267 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
268 !vecBCType_.at(loc).compare(
"Dirichlet_Z")||
269 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
270 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
271 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")) {
272 if (!vecExternalSol_[loc].is_null()) {
273 std::string type =
"BCMinusVec";
277 for (
int d=0; d < dim; d++) {
278 point.at(d) = vecPoints->at(i).at(d);
280 for (
int d=0; d < dofs; d++) {
281 result.at(d) = vecPoints->at(i).at(d);
283 vecBC_func_.at(loc)(&point.at(0), &result.at(0), t, &(vecBC_Parameters_.at(loc).at(0)));
285 for (UN j=0; j<outBlockMV->getNumVectors(); j++) {
286 Teuchos::ArrayRCP<SC> values = outBlockMV->getBlock(block)->getDataNonConst(j);
287 Teuchos::ArrayRCP<const SC> substractValues = substractBlockMV->getBlock(block)->getData(j);
288 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
289 for (
int dd=0; dd < dofs; dd++)
290 values[ dofs * i + dd ] = result.at(dd) - substractValues[ dofs * i + dd ];
292 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
293 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
295 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
296 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
298 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
299 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
301 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
302 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
303 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
305 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
306 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
307 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
309 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
310 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
311 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
320 for (
int i=0; i<vecBCType_.size(); i++) {
321 if( vecBCType_.at(i) ==
"Neumann" && vecBlockID_.at(i)==block){
322 DomainPtr_Type domain = vecDomain_.at(i);
323 FEFacPtr_Type feFactory = Teuchos::rcp(
new FEFac_Type() );
324 feFactory->addFE(domain);
326 std::vector<SC> funcParameter(3 , 0.);
327 funcParameter[1] = t;
328 funcParameter[2] = vecFlag_.at(i);
329 int dim = domain->getDimension();
330 int dofs = vecDofs_.at(i);
331 MultiVectorPtr_Type a;
332 MultiVectorPtr_Type aUnique;
334 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldRepeated() ) );
335 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldUnique() ) );
336 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Vector", vecBC_func_.at(i), funcParameter );
339 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapRepeated() ) );
340 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapUnique() ) );
341 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Scalar", vecBC_func_.at(i), funcParameter );
343 aUnique->exportFromVector( a,
false,
"Add" );
344 MultiVectorPtr_Type mv = outBlockMV->getBlockNonConst(block);
345 mv->update(1.,*aUnique,1.);
346 MultiVectorPtr_Type mvMinus = substractBlockMV->getBlockNonConst(block);
347 mv->update(-1.,*mvMinus,1.);
359 TEUCHOS_TEST_FOR_EXCEPTION( outBlockMV->getNumVectors()>1, std::runtime_error,
"BCBuilder::setRHS() only for getNumVectors == 1.");
361 for (
int block = 0; block < outBlockMV->size(); block++) {
363 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
364 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
365 int dim = vecDomain_.at(loc)->getDimension();
366 int dofs = vecDofs_.at(loc);
368 result.resize(dofs,0.);
369 point.resize(dim,0.);
371 resultPtr_ = Teuchos::rcp(
new vec_dbl_Type(dofs,0.));
372 pointPtr_ = Teuchos::rcp(
new vec_dbl_Type(dim,0.));
374 Teuchos::ArrayRCP<SC> valuesRHS = outBlockMV->getBlock(block)->getDataNonConst(0);
375 Teuchos::ArrayRCP<SC> valuesSubstract = substractBlockMV->getBlock(block)->getDataNonConst(0);
376 for (
int i = 0 ; i < bcFlags->size(); i++) {
377 int flag = bcFlags->at(i);
379 if (!vecBCType_.at(loc).compare(
"Dirichlet") ||
380 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
381 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
382 !vecBCType_.at(loc).compare(
"Dirichlet_Z") ||
383 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
384 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
385 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")) {
386 if (!vecExternalSol_[loc].is_null()) {
387 std::string type =
"VecMinusBC";
391 for (
int d=0; d < dim; d++) {
392 point.at(d) = vecPoints->at(i).at(d);
394 for (
int d=0; d < dofs; d++) {
395 result.at(d) = vecPoints->at(i).at(d);
397 vecBC_func_.at(loc)(&point.at(0), &result.at(0), t, &(vecBC_Parameters_.at(loc).at(0)));
399 for (UN j=0; j<outBlockMV->getNumVectors(); j++) {
400 Teuchos::ArrayRCP<SC> values = outBlockMV->getBlock(block)->getDataNonConst(j);
401 Teuchos::ArrayRCP<const SC> substractValues = substractBlockMV->getBlock(block)->getData(j);
402 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
403 for (
int dd=0; dd < dofs; dd++)
404 values[ dofs * i + dd ] = substractValues[ dofs * i + dd ] - result.at(dd);
406 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
407 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
409 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
410 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
412 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
413 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
415 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
416 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
417 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
419 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
420 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
421 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
423 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
424 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
425 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
434 for (
int i=0; i<vecBCType_.size(); i++) {
435 if( vecBCType_.at(i) ==
"Neumann" && vecBlockID_.at(i)==block){
436 DomainPtr_Type domain = vecDomain_.at(i);
437 FEFacPtr_Type feFactory = Teuchos::rcp(
new FEFac_Type() );
438 feFactory->addFE(domain);
440 std::vector<SC> funcParameter(3 , 0.);
441 funcParameter[1] = t;
442 funcParameter[2] = vecFlag_.at(i);
443 int dim = domain->getDimension();
444 int dofs = vecDofs_.at(i);
445 MultiVectorPtr_Type a;
446 MultiVectorPtr_Type aUnique;
448 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldRepeated() ) );
449 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldUnique() ) );
450 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Vector", vecBC_func_.at(i), funcParameter );
453 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapRepeated() ) );
454 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapUnique() ) );
455 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Scalar", vecBC_func_.at(i), funcParameter );
457 aUnique->exportFromVector( a,
false,
"Add" );
458 MultiVectorPtr_Type mv = outBlockMV->getBlockNonConst(block);
459 mv->update(1.,*aUnique,1.);
460 MultiVectorPtr_Type mvMinus = substractBlockMV->getBlockNonConst(block);
461 mv->update(1.,*mvMinus,-1.);
471 for (
int block = 0; block < blockMV->size(); block++) {
473 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
474 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
475 int dim = vecDomain_.at(loc)->getDimension();
476 int dofs = vecDofs_.at(loc);
478 result.resize(dofs,0.);
480 for (
int i = 0 ; i < bcFlags->size(); i++) {
481 int flag = bcFlags->at(i);
483 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ||
484 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
485 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
486 !vecBCType_.at(loc).compare(
"Dirichlet_Z") ||
487 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
488 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
489 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")
492 for (UN j=0; j<blockMV->getNumVectors(); j++) {
493 Teuchos::ArrayRCP<SC> values = blockMV->getBlock(block)->getDataNonConst(j);
494 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
495 for (
int dd=0; dd < dofs; dd++)
496 values[ dofs * i + dd ] = result[dd];
498 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
499 values[ dofs * i + 0 ] = result[0];
501 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
502 values[ dofs * i + 1 ] = result[1];
504 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
505 values[ dofs * i + 2 ] = result[2];
507 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
508 values[ dofs * i + 0 ] = result[0];
509 values[ dofs * i + 1 ] = result[1];
511 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
512 values[ dofs * i + 0 ] = result[0];
513 values[ dofs * i + 2 ] = result[2];
515 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
516 values[ dofs * i + 1 ] = result[1];
517 values[ dofs * i + 2 ] = result[2];
596 UN numBlocks = blockMatrix->size();
598 for (UN blockRow = 0; blockRow < numBlocks; blockRow++) {
600#ifdef BCBuilder_TIMER
601 Teuchos::TimeMonitor SetSystemRowMonitor(*SetSystemRowTimer_);
603 bool boolBlockHasDirichlet =
false;
606#ifdef BCBuilder_TIMER
607 Teuchos::TimeMonitor BlockRowHasDirichletMonitor(*BlockRowHasDirichletTimer_);
613 if (boolBlockHasDirichlet){
614 for (UN blockCol = 0; blockCol < numBlocks ; blockCol++) {
615 if (blockMatrix->blockExists(blockRow, blockCol)) {
616 MatrixPtr_Type matrix = blockMatrix->getBlock(blockRow, blockCol);
618 }
else if (blockRow == blockCol) {
625 const auto it = std::find(this->vecBlockID_.begin(), this->vecBlockID_.end(), blockRow);
626 std::cout <<
" loc " << loc <<
" it - something " << it - this->vecBlockID_.begin() << std::endl;
627 auto matrixMap = this->vecDomain_.at(loc)->getMapUnique();
629 auto tpetraMatrix = Teuchos::rcp(
new Tpetra::CrsMatrix<SC,LO,GO,NO>(matrixMap->getTpetraMap(), matrixMap->getTpetraMap(), 1));
631 MatrixPtr_Type matrix = Teuchos::rcp(
new Matrix_Type(tpetraMatrix));
634 Teuchos::Array<LO> colIndex(1, 0);
635 Teuchos::Array<SC> val(1, Teuchos::ScalarTraits<SC>::zero());
636 for (
auto i = 0; i < matrixMap->getNodeNumElements(); i++) {
639 matrix->insertLocalValues(i, colIndex, val);
641 matrix->fillComplete(matrixMap, matrixMap);
643 blockMatrix->addBlock(matrix, blockRow, blockCol);
653 matrix->resumeFill();
655 UN dofsPerNode = vecDofs_.at(loc);
656 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
658 for (LO i=0; i<bcFlags->size(); i++) {
659 int flag = bcFlags->at(i);
663 if(
findFlag(flag, blockRow, locThisFlag) ){
665 if( !vecBCType_.at(locThisFlag).compare(
"Dirichlet") ||
666 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X") ||
667 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y") ||
668 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Z") ||
669 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Y") ||
670 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Z") ||
671 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y_Z") )
682 matrix->fillComplete( matrix->getMap(
"domain"), matrix->getMap(
"range") );
688 Teuchos::ArrayView<const SC> valuesOld;
689 Teuchos::ArrayView<const LO> indices;
691 MapConstPtr_Type colMap = matrix->getMap(
"col");
692 LO localDof = (LO) (dofsPerNode * localNode);
693 for (UN dof=0; dof<dofsPerNode; dof++) {
694 if ( vecBCType_.at(loc) ==
"Dirichlet" ||
695 (vecBCType_.at(loc) ==
"Dirichlet_X" && dof==0 ) ||
696 (vecBCType_.at(loc) ==
"Dirichlet_Y" && dof==1 ) ||
697 (vecBCType_.at(loc) ==
"Dirichlet_Z" && dof==2 ) ||
698 (vecBCType_.at(loc) ==
"Dirichlet_X_Y" && dof!=2 )||
699 (vecBCType_.at(loc) ==
"Dirichlet_X_Z" && dof!=1 )||
700 (vecBCType_.at(loc) ==
"Dirichlet_Y_Z" && dof!=0 )
703 GO globalDof = matrix->getMap()->getGlobalElement( localDof );
704 matrix->getLocalRowView(localDof, indices, valuesOld);
705 Teuchos::Array<SC> values( valuesOld.size(), Teuchos::ScalarTraits<SC>::zero() );
707 for (UN j=0; j<indices.size() && !setOne; j++) {
708 if ( colMap->getGlobalElement( indices[j] ) == globalDof ){
709 values[j] = Teuchos::ScalarTraits<SC>::one();
713 matrix->replaceLocalValues(localDof, indices(), values());