void STKConnManager<GO>::applyInterfaceConditions() { elmtToAssociatedElmts_.resize(elements_->size()); for (std::size_t i = 0; i < sidesetsToAssociate_.size(); ++i) { std::vector<stk_classic::mesh::Entity*> sides; stkMeshDB_->getAllSides(sidesetsToAssociate_[i], sides); sidesetYieldedAssociations_[i] = ! sides.empty(); for (std::vector<stk_classic::mesh::Entity*>::const_iterator si = sides.begin(); si != sides.end(); ++si) { const stk_classic::mesh::Entity* const side = *si; const stk_classic::mesh::PairIterRelation relations = side->relations(stkMeshDB_->getElementRank()); if (relations.size() != 2) { // If relations.size() != 2 for one side in the sideset, then it's true // for all, including the first. TEUCHOS_ASSERT(si == sides.begin()); sidesetYieldedAssociations_[i] = false; break; } const std::size_t ea_id = getElementIdx(*elements_, relations[0].entity()), eb_id = getElementIdx(*elements_, relations[1].entity()); elmtToAssociatedElmts_[ea_id].push_back(eb_id); elmtToAssociatedElmts_[eb_id].push_back(ea_id); } } }
void STKConnManager<GO>::applyInterfaceConditions() { std::vector<std::string> sideset_names; stkMeshDB_->getSidesetNames(sideset_names); for (std::vector<std::string>::const_iterator ssni = sideset_names.begin(); ssni != sideset_names.end(); ++ssni) { std::vector<stk_classic::mesh::Entity*> sides; stkMeshDB_->getMySides(*ssni, sides); for (std::vector<stk_classic::mesh::Entity*>::const_iterator si = sides.begin(); si != sides.end(); ++si) { const stk_classic::mesh::Entity* const side = *si; const stk_classic::mesh::PairIterRelation relations = side->relations(stkMeshDB_->getElementRank()); if (relations.size() != 2) continue; const std::size_t ea_id = getElementIdx(*elements_, relations[0].entity()), eb_id = getElementIdx(*elements_, relations[1].entity()); elmtToInterfaceElmt_[ea_id] = eb_id; elmtToInterfaceElmt_[eb_id] = ea_id; } } }
bool helperSubDim(const stk_classic::mesh::Entity& child_element, stk_classic::mesh::FieldBase *field, const mesh::BulkData& bulkData) { EXCEPTWATCH; const CellTopologyData * const child_cell_topo_data = stk_classic::percept::PerceptMesh::get_cell_topology(child_element); CellTopology child_cell_topo(child_cell_topo_data); int child_cell_dimension = child_cell_topo.getDimension(); int meta_dimension = mesh::fem::FEMMetaData::get_meta_data(mesh::fem::FEMMetaData::get(bulkData)).get_spatial_dimension(); // for now, only allow face (or edge) VERIFY_OP_ON(child_cell_dimension, ==, meta_dimension - 1, "Dimensions don't match"); VectorFieldType& coord_field = *(mesh::fem::FEMMetaData::get(bulkData)).get_field<VectorFieldType>("coordinates"); // FIXME for fields not on a Node unsigned nDOF = m_nDOFs; unsigned nCells = PerceptMesh::size1(child_element); m_count_elems += nCells; typedef IntrepidManager IM; unsigned cubDegree = m_cubDegree; const stk_classic::mesh::PairIterRelation parent_elements = child_element.relations(child_element.entity_rank() + 1); VERIFY_OP_ON(parent_elements.size(), ==, 1, "cant find parent"); const stk_classic::mesh::Entity& element = *parent_elements[0].entity(); unsigned i_face = parent_elements[0].identifier(); const CellTopologyData * const cell_topo_data = stk_classic::percept::PerceptMesh::get_cell_topology(element); CellTopology cell_topo(cell_topo_data); int cell_dimension = cell_topo.getDimension(); VERIFY_OP_ON(cell_dimension, ==, meta_dimension , "Dimensions don't match"); IM im(Elements_Tag(nCells), cell_topo, cubDegree); IM imChild(Elements_Tag(nCells), child_cell_topo, cubDegree); unsigned numCubPoints_child = imChild.m_cub->getNumPoints(); im.m_Cub_Points_Tag = Cub_Points_Tag(numCubPoints_child); if (0) { std::cout << "numCubPoints_child= " << numCubPoints_child << " parent rank= " << element.entity_rank() << " parent topo= " << cell_topo.getName() << std::endl; } // FIXME im.m_DOFs_Tag.num = m_nDOFs; // FIXME // _c suffix is for the child (face) element IM::Jacobian J (im); IM::FaceNormal fn (im); //IM::JacobianDet dJ (im); IM::CubaturePoints xi (im); IM::CubaturePoints xi_c (imChild); IM::CellWorkSet cn (im); IM::CubatureWeights wt (im); IM::CubatureWeights wt_c (imChild); IM::PhysicalCoords pc (im); IM::IntegrandValues iv (im); IM::IntegrandValuesDOF ivD (im); IM::Integral Io (im); IM::Bases Nb (im); IM::WeightedMeasure wXfn (im); IM::FieldValues fv (im); imChild.m_cub->getCubature(xi_c, wt_c); unsigned spaceDim = im.m_Spatial_Dim_Tag.num; PerceptMesh::fillCellNodes(element, &coord_field, cn, spaceDim); // get parent cell integration points // Map Gauss points on quad to reference face: paramGaussPoints -> refGaussPoints Intrepid::CellTools<double>::mapToReferenceSubcell(xi, xi_c, 2, i_face, cell_topo); // FIXME magic // get jacobian J(xi, cn, cell_topo); //dJ(J); //shards::ArrayVector<double, shards::NaturalOrder, Elements_Tag, Cub_Points_Tag > fn_Norm; // FIXME //fn(J, i_face, cell_topo); MDArray J_mda; J.copyTo(J_mda); MDArray fn_mda(im.m_Elements_Tag.num, numCubPoints_child, spaceDim); Intrepid::CellTools<double>::getPhysicalFaceNormals(fn_mda, J_mda, i_face, cell_topo); /// get norm of fn for (int icell = 0; icell < im.m_Elements_Tag.num; icell++) { for (int ipt = 0; ipt < (int)numCubPoints_child; ipt++) { double sum = 0.0; for (int i = 0; i < (int)spaceDim; i++) { sum += square(fn_mda(icell, ipt, i)); } wXfn(icell, ipt) = std::sqrt(sum) * wt_c(ipt); } } if (0) { using namespace shards; //std::cout << "dJ= \n" << dJ << std::endl; std::cout << "wXfn= \n" << wXfn << std::endl; std::cout << "xi= \n" << xi << std::endl; std::cout << "wt= \n" << wt << std::endl; std::cout << "cn= \n" << cn << std::endl; Util::setDoPause(true); Util::pause(true); } // get physical coordinates at integration points pc(cn, xi); // get bases #if 1 // FIXME MDArray xi_mda; xi.copyTo(xi_mda); Nb(element, xi_mda); #else Nb(element, xi); #endif // apply integrand (right now we have MDArray hard-coded... FIXME - templatize on its type) // it should look like this (one instead of multiple lines): #if 0 m_integrand(pc, v); #else MDArray pc_mda; pc.copyTo(pc_mda); std::vector<int> ivDims; ivD.dimensions( ivDims); /// NOTE: m_integrand requires the ranks of in/out MDArrays to be such that out_rank >= in_rank /// Thus, we use IntegrandValuesDOF with [DOF] = 1, and then copy the result to IntegrandValues /// which does not have the additional rightmost DOF index (Intrepid doesn't have the concept of /// DOF's, it works on scalars only for the integration routines, or at least that's how I understand /// it currently. // create an array that stk_classic::percept::Function will like to hold the results ivDims[ivDims.size()-1] = m_nDOFs; MDArray iv_mda ( Teuchos::Array<int>(ivDims.begin(), ivDims.end())); if (m_turboOpt == TURBO_ELEMENT || m_turboOpt == TURBO_BUCKET) { m_integrand(pc_mda, iv_mda, element, xi_mda); } else { m_integrand(pc_mda, iv_mda); } // now, copy from the results to an array that Intrepid::integrate will like #endif for (unsigned iDof = 0; iDof < nDOF; iDof++) { iv.copyFrom(im, iv_mda, iDof); // get the integral if (m_accumulation_type == ACCUMULATE_SUM) { Io(iv, wXfn, Intrepid::COMP_BLAS); } //optional design: // // Io(integrand(pc_mda, v), wXdJ(w, dJ(J(xi, c, cell_topo)), Intrepid::COMP_BLAS); for (unsigned iCell = 0; iCell < nCells; iCell++) { // if (Util::getFlag(0)) // { // std::cout << "tmp Io(iCell)= " << Io(iCell) << std::endl; // Util::pause(true, "Io(iCell)"); // } if (m_accumulation_type == ACCUMULATE_SUM) { m_accumulation_buffer[iDof] += Io(iCell); } else if (m_accumulation_type == ACCUMULATE_MAX) { double valIo = 0.0; for (int ivpts = 0; ivpts < iv.dimension(1); ivpts++) { valIo = std::max(valIo, iv((int)iCell, ivpts)); } //std::cout << "m_accumulation_buffer[iDof] = " << m_accumulation_buffer[iDof] << " valIO= " << valIo << std::endl; m_accumulation_buffer[iDof] = std::max(m_accumulation_buffer[iDof], valIo); } } } return false; }
void Colorer:: color(percept::PerceptMesh& eMesh, unsigned * elementType, stk_classic::mesh::PartVector* fromParts, stk_classic::mesh::FieldBase *element_color_field) { const unsigned MAX_COLORS=1000; vector< ColorerNodeSetType > node_colors(MAX_COLORS+1); ColorerElementSetType all_elements; mesh::Selector selector(eMesh.get_fem_meta_data()->universal_part()); if (fromParts) { if (0) { std::cout << "tmp Colorer::color fromParts= " << *fromParts << std::endl; std::cout << "tmp Colorer::color elementType= " << *elementType << std::endl; for (unsigned i_part = 0; i_part < fromParts->size(); i_part++) { std::cout << "tmp Colorer::color i_part = " << i_part << " fromParts= " << (*fromParts)[i_part]->name() << std::endl; } } selector = mesh::selectUnion(*fromParts); } stk_classic::mesh::BulkData& bulkData = *eMesh.get_bulk_data(); unsigned ncolor = 0; int nelem = 0; unsigned num_max_colors = MAX_COLORS; if (m_noColoring) num_max_colors = 1; m_element_colors = vector< ColorerSetType > (num_max_colors+1); for (unsigned icolor = 0; icolor < num_max_colors; icolor++) { int num_colored_this_pass = 0; for (unsigned irank = 0; irank < m_entityRanks.size(); irank++) { const vector<stk_classic::mesh::Bucket*> & buckets = bulkData.buckets( m_entityRanks[irank] ); for ( vector<stk_classic::mesh::Bucket*>::const_iterator k = buckets.begin() ; k != buckets.end() ; ++k ) { if (selector(**k)) { stk_classic::mesh::Bucket & bucket = **k ; bool doThisBucket = true; const CellTopologyData * const bucket_cell_topo_data = stk_classic::percept::PerceptMesh::get_cell_topology(bucket); shards::CellTopology topo(bucket_cell_topo_data); if (elementType && (topo.getKey() != *elementType)) { doThisBucket = false; } if (0 && doThisBucket) { std::cout << "tmp color = " << icolor << " bucket topo name= " << topo.getName() << " key= " << topo.getKey() << " elementType= " << (elementType? *elementType : 0) << " doThisBucket= " << doThisBucket << std::endl; } if (doThisBucket) { const unsigned num_elements_in_bucket = bucket.size(); nelem += num_elements_in_bucket; for (unsigned iElement = 0; iElement < num_elements_in_bucket; iElement++) { stk_classic::mesh::Entity& element = bucket[iElement]; if (0) std::cout << "tmp color = " << icolor << " bucket topo name= " << topo.getName() << " key= " << topo.getKey() << " elementId = " << element.identifier() << " element = " << element << std::endl; stk_classic::mesh::EntityId elem_id = element.identifier(); if (!m_noColoring && contains(all_elements, elem_id)) continue; bool none_in_this_color = true; static std::vector<stk_classic::mesh::EntityId> node_ids(100); unsigned num_node = 0; if (!m_noColoring) { const stk_classic::mesh::PairIterRelation elem_nodes = element.relations( stk_classic::mesh::fem::FEMMetaData::NODE_RANK ); num_node = elem_nodes.size(); node_ids.reserve(num_node); for (unsigned inode=0; inode < num_node; inode++) { stk_classic::mesh::Entity & node = *elem_nodes[ inode ].entity(); stk_classic::mesh::EntityId nid = node.identifier(); node_ids[inode] = nid; if (contains(node_colors[icolor], nid)) { none_in_this_color = false; break; } } } if (none_in_this_color) { ++num_colored_this_pass; if (element_color_field) { double *fdata = stk_classic::mesh::field_data( *static_cast<const percept::ScalarFieldType *>(element_color_field) , element ); fdata[0] = double(icolor); } #if STK_ADAPT_COLORER_SET_TYPE_USE_VECTOR m_element_colors[icolor].push_back(&element); #else m_element_colors[icolor].insert(&element); #endif if (!m_noColoring) { all_elements.insert(elem_id); for (unsigned inode=0; inode < num_node; inode++) { node_colors[icolor].insert(node_ids[inode]); } } } } // elements in bucket } // doThisBucket } // selection } // buckets } // irank if (0 == num_colored_this_pass) { break; } ++ncolor; if (ncolor == num_max_colors-1) { throw std::runtime_error("broken algorithm in mesh colorer"); } } // icolor //std::cout << "tmp ncolor = " << ncolor << " nelem= " << nelem << std::endl; m_element_colors.resize(ncolor); }