MEField<> *FieldReg::RegisterField(const std::string &name, const MEFamily &mef, UInt obj_type, const Context &ctxt, UInt dim, bool out, bool interp, const _fieldTypeBase &ftype) { if (is_committed) Throw() << "FieldReg is already committed when registering:" << name; FMapType::iterator fi = fmap.lower_bound(name); MEField<> *nf; if (fi == fmap.end() || fi->first != name) { // Create the new field nf = new MEField<>(name, mef, obj_type, ctxt, dim, out, interp, ftype); fmap.insert(fi, std::make_pair(name, nf)); Fields.push_back(nf); } else { // Check. If specs match, then just return the fields, otherwise // throw error. nf = fi->second; // TODO: a more thourough check of specs (context, etc...) if (obj_type != nf->ObjType() || dim != nf->dim()) Throw() << "MEField name:" << name << " already registered, with different specs"; } return nf; }
// MEField<SField> specialization MEField<SField>::MEField(MEField<_field> &rhs) : MEFieldBase(rhs.name(), rhs.GetMEFamily(), rhs.ObjType(), rhs.GetContext(), rhs.dim(), false, false, rhs.FType()), primaryfield(NULL), f(rhs), dof_buffer(0) { primaryfield = new SField(*rhs.Getfield()); MEFieldBase::ordinal = rhs.ordinal; }
BBox::BBox(const MEField<> &coords, const MeshDB &mesh) : isempty(false) { dim = mesh.spatial_dim(); for (UInt i =0; i < dim; i++) { min[i] = std::numeric_limits<double>::max(); max[i] = -std::numeric_limits<double>::max(); } // Loop nodes MeshDB::const_iterator ni = mesh.node_begin(), ne = mesh.node_end(); for (; ni != ne; ni++) { const double *coord = coords.data(*ni); for (UInt i = 0; i < dim; i++) { if (coord[i] < min[i]) min[i] = coord[i]; if (coord[i] > max[i]) max[i] = coord[i]; } } }
void IWeights::Prune(const Mesh &mesh, const MEField<> &mask) { WeightMap::iterator wi = begin_row(), we = end_row(), wn; for (; wi != we;) { wn = wi; ++wn; UInt gid = wi->first.id; Mesh::MeshObjIDMap::const_iterator mi = mesh.map_find(MeshObj::NODE, gid); ThrowRequire(mi != mesh.map_end(MeshObj::NODE)); double *mval = mask.data(*mi); if (*mval < 0.5 || !GetMeshObjContext(*mi).is_set(Attr::OWNED_ID)) weights.erase(wi); wi = wn; } }
BBox::BBox(const MEField<> &coords, const MeshObj &obj, double normexp) : isempty(false) { if (obj.get_type() != MeshObj::ELEMENT) Throw() << "Not able to create BBOx for non element"; const MeshObjTopo &topo = *GetMeshObjTopo(obj); const UInt npe = topo.num_nodes; dim = topo.spatial_dim; // Is a shell? TODO expand shell in normal directions if (topo.spatial_dim != topo.parametric_dim) { // Shell, expand by normexp in normal direction for (UInt i =0; i < dim; i++) { min[i] = std::numeric_limits<double>::max(); max[i] = -std::numeric_limits<double>::max(); } double nr[3]; MasterElement<> *me = GetME(coords, obj)(METraits<>()); std::vector<double> cd(3*me->num_functions()); GatherElemData<>(*me, coords, obj, &cd[0]); double pc[] = {0,0}; const Mapping<> *mp = GetMapping(obj)(MPTraits<>()); mp->normal(1,&cd[0], &pc[0], &nr[0]); double ns = std::sqrt(nr[0]*nr[0]+nr[1]*nr[1]+nr[2]*nr[2]); // Only normalize if bigger than 0.0 if (ns >1.0E-19) { nr[0] /= ns; nr[1] /= ns; nr[2] /= ns; } else { nr[0] =0.0; nr[1] =0.0; nr[2] =0.0; } /* if (obj.get_id() == 2426) { std::cout << "elem 2426 coords:"; std::copy(&cd[0], &cd[0] + 3*me->num_functions(), std::ostream_iterator<double>(std::cout, " ")); std::cout << std::endl; }*/ // Get cell diameter double diam = 0; for (UInt n = 1; n < me->num_functions(); n++) { double dist = std::sqrt( (cd[0]-cd[3*n])*(cd[0]-cd[3*n]) + (cd[1]-cd[3*n+1])*(cd[1]-cd[3*n+1]) + (cd[2]-cd[3*n+2])*(cd[2]-cd[3*n+2])); if (dist > diam) diam = dist; } normexp *= diam; for (UInt n = 0; n < npe; n++) { for (UInt j = 0; j < dim; j++) { double lm; if ((lm = (cd[n*dim + j] + normexp*nr[j])) < min[j]) min[j] = lm; if ((lm =(cd[n*dim + j] - normexp*nr[j])) < min[j]) min[j] = lm; if ((lm=(cd[n*dim + j] + normexp*nr[j])) > max[j]) max[j] = lm; if ((lm=(cd[n*dim + j] - normexp*nr[j])) > max[j]) max[j] = lm; } } // for n } else { // Good old fashioned element for (UInt i =0; i < dim; i++) { min[i] = std::numeric_limits<double>::max(); max[i] = -std::numeric_limits<double>::max(); } // Loop the nodes for (UInt n = 0; n < topo.num_nodes; n++) { const MeshObj &node = *(obj.Relations[n].obj); const double *coord = coords.data(node); for (UInt j = 0; j < dim; j++) { if (coord[j] < min[j]) min[j] = coord[j]; if (coord[j] > max[j]) max[j] = coord[j]; } } } // nonshell }
extern "C" void FTN(c_esmc_getlocalcoords)(Mesh **meshpp, double *nodeCoord, int *rc) { try { Mesh *meshp = *meshpp; ThrowRequire(meshp); Mesh &mesh = *meshp; // Initialize the parallel environment for mesh (if not already done) { int localrc; int rc; ESMCI::Par::Init("MESHLOG", false /* use log */,VM::getCurrent(&localrc)->getMpi_c()); if (ESMC_LogDefault.MsgFoundError(localrc,ESMF_ERR_PASSTHRU,NULL)) throw localrc; // bail out with exception } // Get some info int sdim=mesh.spatial_dim(); int num_nodes = mesh.num_nodes(); MEField<> *coords = mesh.GetCoordField(); // Make a map between data index and associated node pointer std::vector<std::pair<int,MeshObj *> > index_to_node; index_to_node.reserve(num_nodes); // iterate through local nodes collecting indices and node pointers Mesh::iterator ni = mesh.node_begin(), ne = mesh.node_end(); for (; ni != ne; ++ni) { MeshObj &node = *ni; if (!GetAttr(node).is_locally_owned()) continue; int idx = node.get_data_index(); index_to_node.push_back(std::make_pair(idx,&node)); } // Sort by data index std::sort(index_to_node.begin(), index_to_node.end()); // Load coords in order of index int nodeCoordPos=0; for (UInt i = 0; i < index_to_node.size(); ++i) { MeshObj &node = *(index_to_node[i].second); // Copy coords into output array double *c = coords->data(node); for (int j=0; j<sdim; j++) { nodeCoord[nodeCoordPos]=c[j]; nodeCoordPos++; } } } catch(std::exception &x) { // catch Mesh exception return code if (x.what()) { ESMC_LogDefault.MsgFoundError(ESMC_RC_INTNRL_BAD, x.what(), rc); } else { ESMC_LogDefault.MsgFoundError(ESMC_RC_INTNRL_BAD, "UNKNOWN", rc); } return; }catch(int localrc){ // catch standard ESMF return code ESMC_LogDefault.MsgFoundError(localrc, ESMF_ERR_PASSTHRU, rc); return; } catch(...){ ESMC_LogDefault.MsgFoundError(ESMC_RC_INTNRL_BAD, "- Caught unknown exception", rc); return; } // Set return code if (rc!=NULL) *rc = ESMF_SUCCESS; }