13 #include <stk_linsys/DofMapper.hpp> 15 #include <stk_mesh/base/FieldData.hpp> 16 #include <stk_mesh/base/Selector.hpp> 17 #include <stk_mesh/base/GetBuckets.hpp> 19 #include <stk_linsys/ImplDetails.hpp> 26 m_fei_vecspace(new fei::VectorSpace(comm)),
27 m_reverse_mappings_enabled(create_reverse_mappings),
28 m_fei_reversemap(NULL)
34 delete m_fei_reversemap;
39 void throw_fei_err(
const std::string& mesg,
int err)
41 std::ostringstream osstr;
43 std::string str = osstr.str();
44 throw std::runtime_error(str);
52 stk_classic::mesh::EntityRank ent_type,
55 int idType =
static_cast<int>(ent_type);
57 m_fei_vecspace->defineIDTypes( 1, &idType );
61 const std::vector<stk_classic::mesh::Bucket*>& all_buckets = mesh_bulk.
buckets(ent_type);
62 std::vector<stk_classic::mesh::Bucket*> buckets;
65 bool already_declared_fei_field =
false;
67 for(
size_t i=0; i<buckets.size(); ++i) {
72 if (!already_declared_fei_field) {
73 int field_size = field.max_size(ent_type);
74 m_fei_vecspace->defineFields(1, &field_id, &field_size);
75 already_declared_fei_field =
true;
78 std::vector<int> ids(buckets[i]->size());
80 stk_classic::mesh::Bucket::iterator
81 iter = buckets[i]->begin(), iter_end = buckets[i]->end();
85 for(; iter != iter_end; ++iter) {
90 int err = m_fei_vecspace->addDOFs(field_id, idType, num_ids, &ids[0]);
91 if (err != 0) throw_fei_err(
"stk_classic::linsys::DofMapper::add_dof_mappings ERROR: fei::VectorSpace::addDOFs returned error-code=",err);
94 std::vector<int> shared_ids;
95 std::vector<int> sharing_procs;
97 const std::vector<stk_classic::mesh::Entity*>& entity_comm = mesh_bulk.
entity_comm();
98 for(
size_t i=0; i<entity_comm.size(); ++i) {
107 for (
size_t j = 0 ; j < ec.size() ; ++j ) {
109 sharing_procs.push_back(ec[j].proc);
113 if (shared_ids.size() > 0) {
114 std::vector<int> num_sharing_procs_per_id(shared_ids.size(), 1);
116 int err = m_fei_vecspace->initSharedIDs(shared_ids.size(), idType,
117 &shared_ids[0], &num_sharing_procs_per_id[0],
119 if (err != 0) throw_fei_err(
"stk_classic::linsys::DofMapper::add_dof_mappings ERROR: fei::VectorSpace::initSharedIDs returned error-code=",err);
126 int err = m_fei_vecspace->initComplete();
127 if (err != 0) throw_fei_err(
"stk_classic::linsys::DofMapper::finalize ERROR: fei::VectorSpace::initComplete returned error-code=",err);
129 if (m_reverse_mappings_enabled) {
130 delete m_fei_reversemap;
131 m_fei_reversemap =
new fei::ReverseMapper(*m_fei_vecspace);
143 stk_classic::mesh::EntityId ent_id,
145 int offset_into_field)
147 int err = 0, index = 0;
152 err = m_fei_vecspace->getGlobalIndex(ent_type, int_id, field_id, index);
153 if (err != 0) throw_fei_err(
"fei::VectorSpace::getGlobalIndex error=",err);
156 std::ostringstream msg;
157 msg <<
"stk_classic::linsys::DofMapper::get_global_index ERROR: " 158 <<
"fei::VectorSpace::getGlobalIndex returned error-code ("<<err
159 <<
") or threw exception, probably meaning that the entity with type="<<ent_type<<
" and id=" 160 << ent_id<<
" was not found.";
161 std::string str = msg.str();
162 throw std::runtime_error(str);
165 return index + offset_into_field;
170 stk_classic::mesh::EntityRank& ent_type,
171 stk_classic::mesh::EntityId& ent_id,
173 int& offset_into_field)
const 175 if (!m_reverse_mappings_enabled || m_fei_reversemap == NULL) {
176 std::ostringstream msg;
177 msg <<
"stk_classic::linsys::DofMapper::get_dof ERROR: " 178 <<
"either reverse-mappings are disabled or DofMapper::finalize hasn't " 179 <<
"been called yet.";
180 std::string str = msg.str();
181 throw std::runtime_error(str);
184 fei::EqnRecord eqrec = m_fei_reversemap->getEqnRecord(global_index);
186 ent_type = eqrec.IDType;
188 offset_into_field = eqrec.offset;
unsigned field_data_size(const FieldBase &f, const Bucket &k)
Size, in bytes, of the field data for each entity.
const stk_classic::mesh::FieldBase * get_field(const FieldIdMap &field_id_map, int field_id)
Field base class with an anonymous data type and anonymous multi-dimension.
PairIterEntityComm sharing() const
Parallel processes which share this entity.
const std::vector< Entity * > & entity_comm() const
All entities with communication information.
void get_dof(int global_index, stk_classic::mesh::EntityRank &ent_type, stk_classic::mesh::EntityId &ent_id, const stk_classic::mesh::FieldBase *&field, int &offset_into_field) const
This is a class for selecting buckets based on a set of meshparts and set logic.
const std::vector< Bucket * > & buckets(EntityRank rank) const
Query all buckets of a given entity rank.
int entityid_to_int(stk_classic::mesh::EntityId id)
int get_field_id(const stk_classic::mesh::FieldBase &field) const
bool field_data_valid(const FieldBase &f, const Bucket &k, unsigned ord, const char *required_by)
Check for existence of field data.
Manager for an integrated collection of entities, entity relations, and buckets of field data...
void add_dof_mappings(const stk_classic::mesh::BulkData &mesh_bulk, const stk_classic::mesh::Selector &selector, stk_classic::mesh::EntityRank ent_type, const stk_classic::mesh::FieldBase &field)
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
int map_field_to_int(FieldIdMap &field_id_map, const stk_classic::mesh::FieldBase &field)
int query_field_to_int_mapping(const FieldIdMap &field_id_map, const stk_classic::mesh::FieldBase &field)
AllSelectedBucketsRange get_buckets(const Selector &selector, const BulkData &mesh)
EntityRank entity_rank() const
The rank of this entity.
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
int get_global_index(stk_classic::mesh::EntityRank ent_type, stk_classic::mesh::EntityId ent_id, stk_classic::mesh::FieldBase &field, int offset_into_field=0)
DofMapper(MPI_Comm comm, bool create_reverse_mappings=true)