268 TEUCHOS_TEST_FOR_EXCEPTION( outBlockMV->getNumVectors()>1, std::runtime_error,
"BCBuilder::setRHS() only for getNumVectors == 1.");
274 for (
int block = 0; block < outBlockMV->size(); block++) {
276 if (vecFlowRateBool_[loc]) {
277 this->determineVelocityForFlowrate(loc,t);
279 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
280 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
281 int dim = vecDomain_.at(loc)->getDimension();
282 int dofs = vecDofs_.at(loc);
284 result.resize(dofs,0.);
285 point.resize(dim,0.);
287 resultPtr_ = Teuchos::rcp(
new vec_dbl_Type(dofs,0.));
288 pointPtr_ = Teuchos::rcp(
new vec_dbl_Type(dim,0.));
290 Teuchos::ArrayRCP<SC> valuesRHS = outBlockMV->getBlock(block)->getDataNonConst(0);
291 Teuchos::ArrayRCP<SC> valuesSubstract = substractBlockMV->getBlock(block)->getDataNonConst(0);
293 for (
int i = 0 ; i < bcFlags->size(); i++) {
294 int flag = bcFlags->at(i);
296 if (!vecBCType_.at(loc).compare(
"Dirichlet") ||
297 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
298 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
299 !vecBCType_.at(loc).compare(
"Dirichlet_Z")||
300 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
301 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
302 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")) {
303 if (!vecExternalSol_[loc].is_null()) {
304 std::string type =
"BCMinusVec";
308 for (
int d=0; d < dim; d++) {
309 point.at(d) = vecPoints->at(i).at(d);
311 for (
int d=0; d < dofs; d++) {
312 result.at(d) = vecPoints->at(i).at(d);
314 vecBC_func_.at(loc)(&point.at(0), &result.at(0), t, &(vecBC_Parameters_.at(loc).at(0)));
316 for (UN j=0; j<outBlockMV->getNumVectors(); j++) {
317 Teuchos::ArrayRCP<SC> values = outBlockMV->getBlock(block)->getDataNonConst(j);
318 Teuchos::ArrayRCP<const SC> substractValues = substractBlockMV->getBlock(block)->getData(j);
319 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
320 for (
int dd=0; dd < dofs; dd++)
321 values[ dofs * i + dd ] = result.at(dd) - substractValues[ dofs * i + dd ];
323 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
324 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
326 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
327 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
329 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
330 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
332 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
333 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
334 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
336 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
337 values[ dofs * i + 0 ] = result.at(0) - substractValues[ dofs * i + 0 ];
338 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
340 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
341 values[ dofs * i + 1 ] = result.at(1) - substractValues[ dofs * i + 1 ];
342 values[ dofs * i + 2 ] = result.at(2) - substractValues[ dofs * i + 2 ];
351 for (
int i=0; i<vecBCType_.size(); i++) {
352 if( vecBCType_.at(i) ==
"Neumann" && vecBlockID_.at(i)==block){
353 DomainPtr_Type domain = vecDomain_.at(i);
354 FEFacPtr_Type feFactory = Teuchos::rcp(
new FEFac_Type() );
355 feFactory->addFE(domain);
357 std::vector<SC> funcParameter(3 , 0.);
358 funcParameter[1] = t;
359 funcParameter[2] = vecFlag_.at(i);
360 int dim = domain->getDimension();
361 int dofs = vecDofs_.at(i);
362 MultiVectorPtr_Type a;
363 MultiVectorPtr_Type aUnique;
365 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldRepeated() ) );
366 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldUnique() ) );
367 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Vector", vecBC_func_.at(i), funcParameter );
370 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapRepeated() ) );
371 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapUnique() ) );
372 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Scalar", vecBC_func_.at(i), funcParameter );
374 aUnique->exportFromVector( a,
false,
"Add" );
375 MultiVectorPtr_Type mv = outBlockMV->getBlockNonConst(block);
376 mv->update(1.,*aUnique,1.);
377 MultiVectorPtr_Type mvMinus = substractBlockMV->getBlockNonConst(block);
378 mv->update(-1.,*mvMinus,1.);
390 TEUCHOS_TEST_FOR_EXCEPTION( outBlockMV->getNumVectors()>1, std::runtime_error,
"BCBuilder::setRHS() only for getNumVectors == 1.");
392 for (
int block = 0; block < outBlockMV->size(); block++) {
394 if (vecFlowRateBool_[loc]) {
395 this->determineVelocityForFlowrate(loc,t);
397 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
398 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
399 int dim = vecDomain_.at(loc)->getDimension();
400 int dofs = vecDofs_.at(loc);
402 result.resize(dofs,0.);
403 point.resize(dim,0.);
405 resultPtr_ = Teuchos::rcp(
new vec_dbl_Type(dofs,0.));
406 pointPtr_ = Teuchos::rcp(
new vec_dbl_Type(dim,0.));
408 Teuchos::ArrayRCP<SC> valuesRHS = outBlockMV->getBlock(block)->getDataNonConst(0);
409 Teuchos::ArrayRCP<SC> valuesSubstract = substractBlockMV->getBlock(block)->getDataNonConst(0);
410 for (
int i = 0 ; i < bcFlags->size(); i++) {
411 int flag = bcFlags->at(i);
413 if (!vecBCType_.at(loc).compare(
"Dirichlet") ||
414 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
415 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
416 !vecBCType_.at(loc).compare(
"Dirichlet_Z") ||
417 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
418 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
419 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")) {
420 if (!vecExternalSol_[loc].is_null()) {
421 std::string type =
"VecMinusBC";
425 for (
int d=0; d < dim; d++) {
426 point.at(d) = vecPoints->at(i).at(d);
428 for (
int d=0; d < dofs; d++) {
429 result.at(d) = vecPoints->at(i).at(d);
431 vecBC_func_.at(loc)(&point.at(0), &result.at(0), t, &(vecBC_Parameters_.at(loc).at(0)));
433 for (UN j=0; j<outBlockMV->getNumVectors(); j++) {
434 Teuchos::ArrayRCP<SC> values = outBlockMV->getBlock(block)->getDataNonConst(j);
435 Teuchos::ArrayRCP<const SC> substractValues = substractBlockMV->getBlock(block)->getData(j);
436 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
437 for (
int dd=0; dd < dofs; dd++)
438 values[ dofs * i + dd ] = substractValues[ dofs * i + dd ] - result.at(dd);
440 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
441 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
443 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
444 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
446 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
447 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
449 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
450 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
451 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
453 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
454 values[ dofs * i + 0 ] = substractValues[ dofs * i + 0 ] - result.at(0);
455 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
457 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
458 values[ dofs * i + 1 ] = substractValues[ dofs * i + 1 ] - result.at(1);
459 values[ dofs * i + 2 ] = substractValues[ dofs * i + 2 ] - result.at(2);
468 for (
int i=0; i<vecBCType_.size(); i++) {
469 if( vecBCType_.at(i) ==
"Neumann" && vecBlockID_.at(i)==block){
470 DomainPtr_Type domain = vecDomain_.at(i);
471 FEFacPtr_Type feFactory = Teuchos::rcp(
new FEFac_Type() );
472 feFactory->addFE(domain);
474 std::vector<SC> funcParameter(3 , 0.);
475 funcParameter[1] = t;
476 funcParameter[2] = vecFlag_.at(i);
477 int dim = domain->getDimension();
478 int dofs = vecDofs_.at(i);
479 MultiVectorPtr_Type a;
480 MultiVectorPtr_Type aUnique;
482 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldRepeated() ) );
483 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapVecFieldUnique() ) );
484 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Vector", vecBC_func_.at(i), funcParameter );
487 a = Teuchos::rcp(
new MultiVector_Type ( domain->getMapRepeated() ) );
488 aUnique = Teuchos::rcp(
new MultiVector_Type ( domain->getMapUnique() ) );
489 feFactory->assemblySurfaceIntegralFlag( dim, domain->getFEType(), a,
"Scalar", vecBC_func_.at(i), funcParameter );
491 aUnique->exportFromVector( a,
false,
"Add" );
492 MultiVectorPtr_Type mv = outBlockMV->getBlockNonConst(block);
493 mv->update(1.,*aUnique,1.);
494 MultiVectorPtr_Type mvMinus = substractBlockMV->getBlockNonConst(block);
495 mv->update(1.,*mvMinus,-1.);
505 for (
int block = 0; block < blockMV->size(); block++) {
507 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
508 vec2D_dbl_ptr_Type vecPoints = vecDomain_.at(loc)->getPointsUnique();
509 int dim = vecDomain_.at(loc)->getDimension();
510 int dofs = vecDofs_.at(loc);
512 result.resize(dofs,0.);
514 for (
int i = 0 ; i < bcFlags->size(); i++) {
515 int flag = bcFlags->at(i);
517 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ||
518 !vecBCType_.at(loc).compare(
"Dirichlet_X") ||
519 !vecBCType_.at(loc).compare(
"Dirichlet_Y") ||
520 !vecBCType_.at(loc).compare(
"Dirichlet_Z") ||
521 !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ||
522 !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ||
523 !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z")
526 for (UN j=0; j<blockMV->getNumVectors(); j++) {
527 Teuchos::ArrayRCP<SC> values = blockMV->getBlock(block)->getDataNonConst(j);
528 if ( !vecBCType_.at(loc).compare(
"Dirichlet") ) {
529 for (
int dd=0; dd < dofs; dd++)
530 values[ dofs * i + dd ] = result[dd];
532 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X") ) {
533 values[ dofs * i + 0 ] = result[0];
535 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y") ) {
536 values[ dofs * i + 1 ] = result[1];
538 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Z") ) {
539 values[ dofs * i + 2 ] = result[2];
541 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Y") ) {
542 values[ dofs * i + 0 ] = result[0];
543 values[ dofs * i + 1 ] = result[1];
545 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_X_Z") ) {
546 values[ dofs * i + 0 ] = result[0];
547 values[ dofs * i + 2 ] = result[2];
549 else if ( !vecBCType_.at(loc).compare(
"Dirichlet_Y_Z") ) {
550 values[ dofs * i + 1 ] = result[1];
551 values[ dofs * i + 2 ] = result[2];
705 UN numBlocks = blockMatrix->size();
707 for (UN blockRow = 0; blockRow < numBlocks; blockRow++) {
709#ifdef BCBuilder_TIMER
710 Teuchos::TimeMonitor SetSystemRowMonitor(*SetSystemRowTimer_);
712 bool boolBlockHasDirichlet =
false;
715#ifdef BCBuilder_TIMER
716 Teuchos::TimeMonitor BlockRowHasDirichletMonitor(*BlockRowHasDirichletTimer_);
722 if (boolBlockHasDirichlet){
723 for (UN blockCol = 0; blockCol < numBlocks ; blockCol++) {
724 if (blockMatrix->blockExists(blockRow, blockCol)) {
725 MatrixPtr_Type matrix = blockMatrix->getBlock(blockRow, blockCol);
727 }
else if (blockRow == blockCol) {
734 auto matrixMap = this->vecDomain_.at(loc)->getMapUnique();
736 auto tpetraMatrix = Teuchos::rcp(
new Tpetra::CrsMatrix<SC,LO,GO,NO>(matrixMap->getTpetraMap(), matrixMap->getTpetraMap(), 1));
738 MatrixPtr_Type matrix = Teuchos::rcp(
new Matrix_Type(tpetraMatrix));
741 Teuchos::Array<LO> colIndex(1, 0);
742 Teuchos::Array<SC> val(1, Teuchos::ScalarTraits<SC>::zero());
743 for (
auto i = 0; i < matrixMap->getNodeNumElements(); i++) {
746 matrix->insertLocalValues(i, colIndex, val);
748 matrix->fillComplete(matrixMap, matrixMap);
750 blockMatrix->addBlock(matrix, blockRow, blockCol);
761 matrix->resumeFill();
763 UN dofsPerNode = vecDofs_.at(loc);
764 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
765 MapConstPtr_Type nodeMap = vecDomain_.at(loc)->getMapUnique();
767 for (LO i=0; i<bcFlags->size(); i++) {
768 int flag = bcFlags->at(i);
772 if(
findFlag(flag, blockRow, locThisFlag) ){
774 if( !vecBCType_.at(locThisFlag).compare(
"Dirichlet") ||
775 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X") ||
776 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y") ||
777 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Z") ||
778 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Y") ||
779 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Z") ||
780 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y_Z") )
791 matrix->fillComplete( matrix->getMap(
"domain"), matrix->getMap(
"range") );
798 Teuchos::ArrayView<const SC> valuesOld;
799 Teuchos::ArrayView<const LO> indices;
801 MapConstPtr_Type colMap = matrix->getMap(
"col");
802 LO localDof = (LO) (dofsPerNode * localNode);
803 for (UN dof=0; dof<dofsPerNode; dof++) {
804 if ( vecBCType_.at(loc) ==
"Dirichlet" ||
805 (vecBCType_.at(loc) ==
"Dirichlet_X" && dof==0 ) ||
806 (vecBCType_.at(loc) ==
"Dirichlet_Y" && dof==1 ) ||
807 (vecBCType_.at(loc) ==
"Dirichlet_Z" && dof==2 ) ||
808 (vecBCType_.at(loc) ==
"Dirichlet_X_Y" && dof!=2 )||
809 (vecBCType_.at(loc) ==
"Dirichlet_X_Z" && dof!=1 )||
810 (vecBCType_.at(loc) ==
"Dirichlet_Y_Z" && dof!=0 )
813 GO globalDof = matrix->getMap()->getGlobalElement( localDof );
814 matrix->getLocalRowView(localDof, indices, valuesOld);
816 for (UN j=0; j<indices.size(); j++) {
817 rowSum += abs(valuesOld[j]);
819 Teuchos::Array<SC> values( valuesOld.size(), Teuchos::ScalarTraits<SC>::zero() );
821 for (UN j=0; j<indices.size() && !setOne; j++) {
822 if ( colMap->getGlobalElement( indices[j] ) == globalDof ){
823 values[j] = valuesOld[j]*eps;
828 matrix->replaceLocalValues(localDof, indices(), values());
839 matrix->resumeFill();
841 UN dofsPerNode = vecDofs_.at(loc);
842 vec_int_ptr_Type bcFlags = vecDomain_.at(loc)->getBCFlagUnique();
844 for (LO i=0; i<bcFlags->size(); i++) {
845 int flag = bcFlags->at(i);
849 if(
findFlag(flag, blockRow, locThisFlag) ){
851 if( !vecBCType_.at(locThisFlag).compare(
"Dirichlet") ||
852 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X") ||
853 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y") ||
854 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Z") ||
855 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Y") ||
856 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_X_Z") ||
857 !vecBCType_.at(locThisFlag).compare(
"Dirichlet_Y_Z") )
868 matrix->fillComplete( matrix->getMap(
"domain"), matrix->getMap(
"range") );
874 Teuchos::ArrayView<const SC> valuesOld;
875 Teuchos::ArrayView<const LO> indices;
877 MapConstPtr_Type colMap = matrix->getMap(
"col");
878 LO localDof = (LO) (dofsPerNode * localNode);
879 for (UN dof=0; dof<dofsPerNode; dof++) {
880 if ( vecBCType_.at(loc) ==
"Dirichlet" ||
881 (vecBCType_.at(loc) ==
"Dirichlet_X" && dof==0 ) ||
882 (vecBCType_.at(loc) ==
"Dirichlet_Y" && dof==1 ) ||
883 (vecBCType_.at(loc) ==
"Dirichlet_Z" && dof==2 ) ||
884 (vecBCType_.at(loc) ==
"Dirichlet_X_Y" && dof!=2 )||
885 (vecBCType_.at(loc) ==
"Dirichlet_X_Z" && dof!=1 )||
886 (vecBCType_.at(loc) ==
"Dirichlet_Y_Z" && dof!=0 )
889 GO globalDof = matrix->getMap()->getGlobalElement( localDof );
890 matrix->getLocalRowView(localDof, indices, valuesOld);
891 Teuchos::Array<SC> values( valuesOld.size(), Teuchos::ScalarTraits<SC>::zero() );
893 for (UN j=0; j<indices.size() && !setOne; j++) {
894 if ( colMap->getGlobalElement( indices[j] ) == globalDof ){
895 values[j] = Teuchos::ScalarTraits<SC>::one();
899 matrix->replaceLocalValues(localDof, indices(), values());