9 #include <fei_iostream.hpp>
10 #include <fei_sstream.hpp>
11 #include <fei_DirichletBCManager.hpp>
12 #include <fei_DirichletBCRecord.hpp>
13 #include <fei_NodeDatabase.hpp>
14 #include <fei_EqnBuffer.hpp>
15 #include <fei_SharedPtr.hpp>
16 #include <fei_VectorSpace.hpp>
17 #include <fei_Matrix.hpp>
22 typedef std::vector<fei::DirichletBCRecord> DBCvec;
25 #define fei_file "fei_DirichletBCManager.cpp"
26 #include <fei_ErrMacros.hpp>
31 DirichletBCManager::getEqnNumber(
int IDType,
int ID,
int fieldID,
int offsetIntoField)
35 if (vecSpace_.get() != NULL) {
36 vecSpace_->getGlobalIndex(IDType, ID, fieldID, eqn);
39 if (structure_ == NULL) {
40 throw std::runtime_error(
"fei::DirichletBCManager has NULL SNL_FEI_Structure.");
46 throw std::runtime_error(
"fei::DirichletBCManager::getEqnNumber failed to get node.");
51 catch(std::runtime_error& exc) {
52 FEI_OSTRINGSTREAM osstr;
53 osstr <<
"fei::DirichletBCManager::finalizeBCEqns caught exception: "
54 << exc.what() <<
" BC IDType="<<IDType<<
", ID="<<ID
55 <<
", fieldID="<<fieldID;
60 return eqn + offsetIntoField;
64 DirichletBCManager::addBCRecords(
int numBCs,
69 const double* prescribedValues)
71 for(
int i=0; i<numBCs; ++i) {
72 int eqn = getEqnNumber(IDType, IDs[i], fieldID, offsetIntoField);
74 bc_map::iterator iter = bcs_.lower_bound(eqn);
76 if (iter == bcs_.end() || iter->first != eqn) {
77 bcs_.insert(iter, std::make_pair(eqn, prescribedValues[i]));
80 else iter->second = prescribedValues[i];
85 DirichletBCManager::addBCRecords(
int numBCs,
89 const int* offsetsIntoField,
90 const double* prescribedValues)
92 for(
int i=0; i<numBCs; ++i) {
93 int eqn = getEqnNumber(IDType, IDs[i], fieldID, offsetsIntoField[i]);
95 bc_map::iterator iter = bcs_.lower_bound(eqn);
97 if (iter == bcs_.end() || iter->first != eqn) {
98 bcs_.insert(iter, std::make_pair(eqn, prescribedValues[i]));
101 else iter->second = prescribedValues[i];
106 DirichletBCManager::finalizeBCEqns(
fei::Matrix& matrix,
107 bool throw_if_bc_slave_conflict)
110 bool haveSlaves = reducer.
get()!=NULL;
118 bc_map::iterator iter = bcs_.begin(), iter_end = bcs_.end();
120 for(; iter!=iter_end; ++iter) {
122 int eqn = iter->first;
125 if (reducer->isSlaveEqn(eqn)) {
126 if (throw_if_bc_slave_conflict) {
127 FEI_OSTRINGSTREAM osstr;
128 osstr <<
"fei BCManager::finalizeBCeqns ERROR, eqn="<<eqn
129 <<
" is both a BC eqn and slave-constraint eqn.";
130 throw std::runtime_error(osstr.str());
136 double* ptr = &iter->second;
138 CHK_ERR( matrix.
copyIn(1, &eqn, 1, &eqn, &ptr) );
146 DirichletBCManager::finalizeBCEqns(
EqnBuffer& bcEqns)
150 bc_map::iterator iter = bcs_.begin(), iter_end = bcs_.end();
152 for(; iter!=iter_end; ++iter) {
153 int eqn = iter->first;
154 double coef = iter->second;
156 CHK_ERR( bcEqns.
addEqn(eqn, &coef, &eqn, 1,
false) );
164 DirichletBCManager::getNumBCRecords()
const
170 DirichletBCManager::clearAllBCs()
int addEqn(int eqnNumber, const double *coefs, const int *indices, int len, bool accumulate, bool create_indices_union=false)
virtual fei::SharedPtr< fei::Reducer > getReducer()=0
bool getFieldEqnNumber(int fieldID, int &eqnNumber) const
virtual fei::SharedPtr< fei::MatrixGraph > getMatrixGraph() const =0
std::ostream & console_out()
virtual int copyIn(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, int format=0)=0
int getNodeWithID(GlobalID nodeID, const NodeDescriptor *&node) const