// @HEADER // ***************************************************************************** // Panzer: A partial differential equation assembly // engine for strongly coupled complex multiphysics systems // // Copyright 2011 NTESS and the Panzer contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "Thyra_VectorStdOps.hpp" #include "Thyra_ProductVectorSpaceBase.hpp" #include "Thyra_TpetraLinearOp.hpp" #include "Tpetra_CrsMatrix.hpp" namespace panzer { //! Make sure row and column spaces match up template bool BlockedTpetraLinearObjContainer:: checkCompatibility() const { using Thyra::VectorSpaceBase; using Teuchos::RCP; using Teuchos::null; bool x_matches=false, f_matches=false, dxdt_matches=false; if(get_A()!=null) { RCP > range = get_A()->range(); RCP > domain = get_A()->domain(); if(get_x()!=null) x_matches = range->isCompatible(*get_x()->space()); else x_matches = true; // nothing to compare if(get_dxdt()!=null) dxdt_matches = range->isCompatible(*get_dxdt()->space()); else dxdt_matches = true; // nothing to compare if(get_f()!=null) f_matches = range->isCompatible(*get_f()->space()); else f_matches = true; // nothing to compare } else if(get_x()!=null && get_dxdt()!=null) { f_matches = true; // nothing to compare f to x_matches = get_x()->space()->isCompatible(*get_dxdt()->space()); // dxdt and x are in the same space dxdt_matches = x_matches; } else { f_matches = x_matches = dxdt_matches = true; // nothing to compare to } return x_matches && dxdt_matches && f_matches; } template void BlockedTpetraLinearObjContainer:: initialize() { using Thyra::LinearOpBase; using Thyra::PhysicallyBlockedLinearOpBase; using Thyra::ProductVectorSpaceBase; using Teuchos::RCP; using Teuchos::rcp_dynamic_cast; if(get_x()!=Teuchos::null) Thyra::assign(x.ptr(),0.0); if(get_dxdt()!=Teuchos::null) Thyra::assign(get_dxdt().ptr(),0.0); if(get_f()!=Teuchos::null) Thyra::assign(get_f().ptr(),0.0); if(get_A()!=Teuchos::null) { RCP > Amat = rcp_dynamic_cast >(get_A(),true); RCP > range = Amat->productRange(); RCP > domain = Amat->productDomain(); // loop over block entries for(int i=0;inumBlocks();i++) { for(int j=0;jnumBlocks();j++) { RCP > block = Amat->getNonconstBlock(i,j); if(block!=Teuchos::null) { RCP > t_block = rcp_dynamic_cast >(block,true)->getTpetraOperator(); RCP map_i = t_block->getRangeMap(); RCP map_j = t_block->getDomainMap(); RCP > mat = rcp_dynamic_cast >(t_block,true); mat->resumeFill(); mat->setAllToScalar(0.0); mat->fillComplete(map_j,map_i); } } } } } template void BlockedTpetraLinearObjContainer:: initializeMatrix(ScalarT value) { using Thyra::LinearOpBase; using Thyra::PhysicallyBlockedLinearOpBase; using Thyra::ProductVectorSpaceBase; using Teuchos::RCP; using Teuchos::rcp_dynamic_cast; if(get_A()!=Teuchos::null) { RCP > Amat = rcp_dynamic_cast >(get_A(),true); RCP > range = Amat->productRange(); RCP > domain = Amat->productDomain(); // loop over block entries for(int i=0;inumBlocks();i++) { for(int j=0;jnumBlocks();j++) { RCP > block = Amat->getNonconstBlock(i,j); if(block!=Teuchos::null) { RCP > t_block = rcp_dynamic_cast >(block,true)->getTpetraOperator(); // why do I have to do this? RCP map_i = t_block->getRangeMap(); RCP map_j = t_block->getDomainMap(); RCP > mat = rcp_dynamic_cast >(t_block,true); mat->resumeFill(); mat->setAllToScalar(value); mat->fillComplete(map_j,map_i); } } } } } template void BlockedTpetraLinearObjContainer:: clear() { set_x(Teuchos::null); set_dxdt(Teuchos::null); set_f(Teuchos::null); set_A(Teuchos::null); } template void BlockedTpetraLinearObjContainer:: beginFill() { using Thyra::LinearOpBase; using Thyra::PhysicallyBlockedLinearOpBase; using Thyra::ProductVectorSpaceBase; using Teuchos::RCP; using Teuchos::rcp_dynamic_cast; if(get_A()!=Teuchos::null) { RCP > Amat = rcp_dynamic_cast >(get_A(),true); RCP > range = Amat->productRange(); RCP > domain = Amat->productDomain(); // loop over block entries for(int i=0;inumBlocks();i++) { for(int j=0;jnumBlocks();j++) { RCP > block = Amat->getNonconstBlock(i,j); if(block!=Teuchos::null) { RCP > t_block = rcp_dynamic_cast >(block,true)->getTpetraOperator(); RCP > mat = rcp_dynamic_cast >(t_block,true); mat->resumeFill(); } } } } } template void BlockedTpetraLinearObjContainer:: endFill() { using Thyra::LinearOpBase; using Thyra::PhysicallyBlockedLinearOpBase; using Thyra::ProductVectorSpaceBase; using Teuchos::RCP; using Teuchos::rcp_dynamic_cast; if(get_A()!=Teuchos::null) { RCP > Amat = rcp_dynamic_cast >(get_A(),true); RCP > range = Amat->productRange(); RCP > domain = Amat->productDomain(); // loop over block entries for(int i=0;inumBlocks();i++) { for(int j=0;jnumBlocks();j++) { RCP > block = Amat->getNonconstBlock(i,j); if(block!=Teuchos::null) { RCP > t_block = rcp_dynamic_cast >(block,true)->getTpetraOperator(); RCP map_i = t_block->getRangeMap(); RCP map_j = t_block->getDomainMap(); RCP > mat = rcp_dynamic_cast >(t_block,true); mat->fillComplete(map_j,map_i); } } } } } }