/*----------------------------------------------------------------------* | mwgee 08/05| | 2D case: | | this method evaluates the function | | F(eta) = ( Ni * xis - xm ) dot g(xi) | | with Ni shape functions of slave segment | | xm nodal coords of master node | | xs nodal coords of slave nodes on segment | | njs nodal outward normal of nodes xs (slave side) | *----------------------------------------------------------------------*/ double MOERTEL::Projector::evaluate_F_2D_SegmentOrthogonal(MOERTEL::Node& node, MOERTEL::Segment& seg, double eta, double &gap) { // check the type of function on the segment // Here, we need 1D functions set as function id 0 MOERTEL::Function::FunctionType type = seg.FunctionType(0); if (type != MOERTEL::Function::func_Linear1D) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_F_2D_SegmentOrthogonal:\n" << "***ERR*** function is of wrong type\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } // evaluate the first function set on segment at eta int nsnode = seg.Nnode(); double val[100]; seg.EvaluateFunction(0,&eta,val,nsnode,NULL); // get nodal coords and normals of slave nodes and interpolate them double Nx[2]; Nx[0] = Nx[1] = 0.0; MOERTEL::Node** snodes = seg.Nodes(); if (!snodes) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_F_2D_SegmentOrthogonal:\n" << "***ERR*** segment " << seg.Id() << " ptr to it's nodes is zero\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } for (int i=0; i<nsnode; ++i) { const double* X = snodes[i]->X(); Nx[0] += val[i]*X[0]; Nx[1] += val[i]*X[1]; } // subtract xm from interpolated coords Nx const double* X = node.X(); Nx[0] -= X[0]; Nx[1] -= X[1]; // evaluate the metric of the segment in point xi double g[2]; seg.Metric(&eta,g,NULL); // calculate F double F = Nx[0]*g[0] + Nx[1]*g[1]; gap = (Nx[0] * g[0] + Nx[1] * g[1]); // gap = ((Nx[0] - X[0]) * g[0] + (Nx[1] - X[1]) * g[1]) // / sqrt(g[0] * g[0] + g[1] * g[1]); // ||gap|| cos theta return F; }
/*----------------------------------------------------------------------* | mwgee 08/05| | 2D case: | | this method evaluates the function | | gradF(eta) = | | ( Ni,eta * xis ) * ( Ni,eta * xis ) | | with Ni,eta derivative of shape functions of segment | | Ni,Nj shape functions of segment | | xis nodal coords of segment's nodes i (slave side) | *----------------------------------------------------------------------*/ double MOERTEL::Projector::evaluate_gradF_2D_SegmentOrthogonal_to_g( MOERTEL::Node& node, MOERTEL::Segment& seg, double eta, double* g) { // check the type of function on the segment // Here, we need 1D functions set as function id 0 MOERTEL::Function::FunctionType type = seg.FunctionType(0); if (type != MOERTEL::Function::func_Linear1D) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_gradF_2D_SegmentOrthogonal_to_g:\n" << "***ERR*** function is of wrong type\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } // evaluate function and derivatives of the first function set on segment at eta int nmnode = seg.Nnode(); double deriv[200]; seg.EvaluateFunction(0,&eta,NULL,nmnode,deriv); // intermediate data: // Nxeta = Ni,eta * xi // get nodal coords and normals of nodes and interpolate them double Nxeta[2]; Nxeta[0] = Nxeta[1] = 0.0; MOERTEL::Node** mnodes = seg.Nodes(); if (!mnodes) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_gradF_2D_SegmentOrthogonal_to_g:\n" << "***ERR*** segment " << seg.Id() << " ptr to it's nodes is zero\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } for (int i=0; i<nmnode; ++i) { const double* X = mnodes[i]->X(); Nxeta[0] += deriv[i]*X[0]; Nxeta[1] += deriv[i]*X[1]; } // calculate gradF double gradF = Nxeta[0]*g[0] + Nxeta[1]*g[1]; return gradF; }
/*----------------------------------------------------------------------* | project nodes master to slave along slave cont. normal field | *----------------------------------------------------------------------*/ bool MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField() { if (!IsComplete()) { std::stringstream oss; oss << "***ERR*** MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField:\n" << "***ERR*** Complete() not called on interface " << Id() << "\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } if (!lComm()) return true; int mside = MortarSide(); int sside = OtherSide(mside); // iterate over all nodes of the master side and project those belonging to me std::map<int,Teuchos::RCP<MOERTEL::Node> >::iterator mcurr; for (mcurr=rnode_[mside].begin(); mcurr!=rnode_[mside].end(); ++mcurr) { Teuchos::RCP<MOERTEL::Node> mnode = mcurr->second; if (NodePID(mnode->Id()) != lComm()->MyPID()) continue; const double* mx = mnode->X(); double mindist = 1.0e+20; Teuchos::RCP<MOERTEL::Node> closenode = Teuchos::null; // find a node on the slave side that is closest to me std::map<int,Teuchos::RCP<MOERTEL::Node> >::iterator scurr; for (scurr=rnode_[sside].begin(); scurr!=rnode_[sside].end(); ++scurr) { Teuchos::RCP<MOERTEL::Node> snode = scurr->second; const double* sx = snode->X(); // build distance | snode->X() - mnode->X() | double dist = 0.0; for (int i=0; i<3; ++i) dist += (mx[i]-sx[i])*(mx[i]-sx[i]); dist = sqrt(dist); if (dist < mindist) { mindist = dist; closenode = snode; } } if (closenode == Teuchos::null) { std::stringstream oss; oss << "***ERR*** MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField:\n" << "***ERR*** Weired: for master node " << mnode->Id() << " no closest master node found\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } #if 0 cout << "snode " << *mnode; cout << "closenode " << *closenode; #endif // get segments attached to closest node closenode int nseg = closenode->Nseg(); MOERTEL::Segment** segs = closenode->Segments(); // create a projection operator MOERTEL::Projector projector(IsOneDimensional(),OutLevel()); // loop these segments and find best projection double bestdist[2]; const double tol = 0.2; double bestgap = 0.0, gap; bestdist[0] = bestdist[1] = 1.0e+20; MOERTEL::Segment* bestseg = NULL; for (int i=0; i<nseg; ++i) { // project the master node on the slave segment along the segments interpolated normal field double xi[2]; xi[0] = xi[1] = 0.0; projector.ProjectNodetoSegment_SegmentNormal(*mnode,*(segs[i]),xi,gap); // check whether xi is better then previous projections if (IsOneDimensional()) { if (abs(xi[0]) < abs(bestdist[0])) { bestdist[0] = xi[0]; bestdist[1] = xi[1]; bestseg = segs[i]; bestgap = gap; } } else { double third = 1./3.; // it's 'inside' with some tolerance if ( xi[0]<=1.+tol && xi[1]<=abs(1.-xi[0])+tol && xi[0]>=0.-tol && xi[1]>=0.-tol ) { // it's better in both directions if ( sqrt((xi[0]-third)*(xi[0]-third)) < sqrt((bestdist[0]-third)*(bestdist[0]-third)) && sqrt((xi[1]-third)*(xi[1]-third)) < sqrt((bestdist[1]-third)*(bestdist[1]-third)) ) { bestdist[0] = xi[0]; bestdist[1] = xi[1]; bestseg = segs[i]; bestgap = gap; } //it's better in one direction and 'in' in the other else if ( (sqrt((xi[0]-third)*(xi[0]-third))<sqrt((bestdist[0]-third)*(bestdist[0]-third)) && xi[1]<=abs(1.-xi[0])+tol && xi[1]>=0.-tol ) || (sqrt((xi[1]-third)*(xi[1]-third))<sqrt((bestdist[1]-third)*(bestdist[1]-third)) && xi[0]<=1.+tol && xi[0]>=0.-tol ) ) { bestdist[0] = xi[0]; bestdist[1] = xi[1]; bestseg = segs[i]; bestgap = gap; } } } } // for (int i=0; i<nseg; ++i) // check whether the bestseg/bestdist are inside that segment // (with some tolerance of 20%) bool ok = false; if (IsOneDimensional()) { if (abs(bestdist[0]) < 1.1) ok = true; } else { if (bestdist[0]<=1.+tol && bestdist[1]<=abs(1.-bestdist[0])+tol && bestdist[0]>=0.-tol && bestdist[1]>=0.-tol) ok = true; } if (ok) // the projection is good { // build the interpolated normal and overwrite the mnode normal with -n int nsnode = bestseg->Nnode(); MOERTEL::Node** snodes = bestseg->Nodes(); std::vector<double> val(nsnode); bestseg->EvaluateFunction(0,bestdist,&val[0],nsnode,NULL); double NN[3]; NN[0] = NN[1] = NN[2] = 0.0; for (int i=0; i<nsnode; ++i) { const double* N = snodes[i]->N(); for (int j=0; j<3; ++j) NN[j] -= val[i]*N[j]; } val.clear(); mnode->SetN(NN); // create projected node and store it in mnode MOERTEL::ProjectedNode* pnode = new MOERTEL::ProjectedNode(*mnode,bestdist,bestseg); mnode->SetProjectedNode(pnode); mnode->SetGap(bestgap); } else // this mnode does not have a valid projection { if (OutLevel()>6) cout << "MOERTEL: ***WRN***: Projection m->s: Node " << mnode->Id() << " does not have projection\n"; mnode->SetProjectedNode(NULL); } } // for (scurr=rnode_[mside].begin(); scurr!=rnode_[mside].end(); ++scurr) // loop all master nodes again and make the projection and the new normal redundant int bsize = 7*rnode_[mside].size(); std::vector<double> bcast(bsize); for (int proc=0; proc<lComm()->NumProc(); ++proc) { int blength = 0; if (proc==lComm()->MyPID()) { for (mcurr=rnode_[mside].begin(); mcurr!=rnode_[mside].end(); ++mcurr) { Teuchos::RCP<MOERTEL::Node> mnode = mcurr->second; if (proc != NodePID(mnode->Id())) continue; // cannot have a projection on a node i don't own Teuchos::RCP<MOERTEL::ProjectedNode> pnode = mnode->GetProjectedNode(); if (pnode == Teuchos::null) continue; // this node does not have a projection const double* xi = pnode->Xi(); const double* N = mnode->N(); bcast[blength] = (double)pnode->Id(); ++blength; if (pnode->Segment()) bcast[blength] = (double)pnode->Segment()->Id(); else bcast[blength] = -0.1; ++blength; bcast[blength] = xi[0]; ++blength; bcast[blength] = xi[1]; ++blength; bcast[blength] = N[0]; ++blength; bcast[blength] = N[1]; ++blength; bcast[blength] = N[2]; ++blength; bcast[blength] = pnode->Gap(); ++blength; } if (blength > bsize) { std::stringstream oss; oss << "***ERR*** MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField:\n" << "***ERR*** Overflow in communication buffer occured\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } } lComm()->Broadcast(&blength,1,proc); lComm()->Broadcast(&bcast[0],blength,proc); if (proc!=lComm()->MyPID()) { int i; for (i=0; i<blength;) { int nid = (int)bcast[i]; ++i; double sid = bcast[i]; ++i; double* xi = &bcast[i]; ++i; ++i; double* n = &bcast[i]; ++i; ++i; ++i; double gap = bcast[i]; ++i; Teuchos::RCP<MOERTEL::Node> mnode = GetNodeView(nid); Teuchos::RCP<MOERTEL::Segment> seg = Teuchos::null; if (sid != -0.1) seg = GetSegmentView((int)sid); if (mnode == Teuchos::null) { std::stringstream oss; oss << "***ERR*** MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField:\n" << "***ERR*** Cannot get view of node\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } mnode->SetN(n); MOERTEL::ProjectedNode* pnode = new MOERTEL::ProjectedNode(*mnode,xi,seg.get()); mnode->SetProjectedNode(pnode); mnode->SetGap(gap); } if (i != blength) { std::stringstream oss; oss << "***ERR*** MOERTEL::Interface::ProjectNodes_MastertoSlave_NormalField:\n" << "***ERR*** Mismatch in dimension of recv buffer\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } } } // for (int proc=0; proc<lComm()->NumProc(); ++proc) bcast.clear(); return true; }
/*----------------------------------------------------------------------* | mwgee 07/05| | 2D case: | | this method evaluates the function | | gradF(eta) = | | ( Ni,eta * xis ) * ( Nj nyjs ) | | + ( Ni * xis - xm ) * ( Nj,eta * nyjs) | | - ( Ni,eta * yis ) * ( Nj nxjs ) | | - ( Ni * yis - ym ) * ( Nj,eta * nxjs) | | with Ni,eta derivative of shape functions of segment | | Ni,Nj shape functions of segment | | xis,yis nodal coords of segment's nodes i (slave side) | | xm,ym nodal coords of master node | | nxjs,nyjs outward normals of node j (slave side) | *----------------------------------------------------------------------*/ double MOERTEL::Projector::evaluate_gradF_2D_SegmentNormal(MOERTEL::Node& node, MOERTEL::Segment& seg, double eta) { // check the type of function on the segment // Here, we need 1D functions set as function id 0 MOERTEL::Function::FunctionType type = seg.FunctionType(0); if (type != MOERTEL::Function::func_Linear1D) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_gradF_2D_SegmentNormal:\n" << "***ERR*** function is of wrong type\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } // evaluate function and derivatives of the first function set on segment at eta int nsnode = seg.Nnode(); double val[100]; double deriv[200]; seg.EvaluateFunction(0,&eta,val,nsnode,deriv); // several intermediate data: // Nx = Ni * xi // Nxeta = Ni,eta * xi // NN = Nj * nj // NNeta = Nj,eta * nj // get nodal coords and normals of nodes and interpolate them double Nx[2]; Nx[0] = Nx[1] = 0.0; double Nxeta[2]; Nxeta[0] = Nxeta[1] = 0.0; double NN[2]; NN[0] = NN[1] = 0.0; double NNeta[2]; NNeta[0] = NNeta[1] = 0.0; MOERTEL::Node** snodes = seg.Nodes(); if (!snodes) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_gradF_2D_SegmentNormal:\n" << "***ERR*** segment " << seg.Id() << " ptr to it's nodes is zero\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } for (int i=0; i<nsnode; ++i) { const double* X = snodes[i]->X(); Nx[0] += val[i]*X[0]; Nx[1] += val[i]*X[1]; Nxeta[0] += deriv[i]*X[0]; Nxeta[1] += deriv[i]*X[1]; const double* N = snodes[i]->N(); NN[0] += val[i]*N[0]; NN[1] += val[i]*N[1]; NNeta[0] += deriv[i]*N[0]; NNeta[1] += deriv[i]*N[1]; } // get master node coords const double* xm = node.X(); // calculate gradF double gradF = Nxeta[0]*NN[1] + (Nx[0] - xm[0])*NNeta[1] - Nxeta[1]*NN[0] - (Nx[1] - xm[1])*NNeta[0]; return gradF; }
/*----------------------------------------------------------------------* | mwgee 07/05| | modded gah 07/2010 | | 2D case: | | this function evaluates the function | | F(eta) = ( Ni * xim - xs ) cross ns , | | with Ni shape functions of segment | | xim nodal coords of segment's nodes (master side) | | xs nodal coords of node (slave side) | | ns outward normal of node (slave side) | *----------------------------------------------------------------------*/ double MOERTEL::Projector::evaluate_F_2D_NodalNormal(MOERTEL::Node& node, MOERTEL::Segment& seg, double eta, double &gap) { // check the type of function on the segment // Here, we need 1D functions set as function id 0 MOERTEL::Function::FunctionType type = seg.FunctionType(0); if (type != MOERTEL::Function::func_Linear1D) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_F_2D_NodalNormal:\n" << "***ERR*** function is of wrong type\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } // evaluate the first function set on segment at eta int nmnode = seg.Nnode(); double val[100]; seg.EvaluateFunction(0,&eta,val,nmnode,NULL); // get nodal coords of nodes and interpolate them double Nx[2]; Nx[0] = Nx[1] = 0.0; MOERTEL::Node** mnodes = seg.Nodes(); if (!mnodes) { std::stringstream oss; oss << "***ERR*** MOERTEL::Projector::evaluate_F_2D_NodalNormal:\n" << "***ERR*** segment " << seg.Id() << " ptr to it's nodes is zero\n" << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n"; throw ReportError(oss); } // Here, Nx[0] and Nx[1] are the coordinates of the guess at the root for (int i=0; i<nmnode; ++i) { const double* X = mnodes[i]->X(); Nx[0] += val[i]*X[0]; Nx[1] += val[i]*X[1]; } // subtract xs (Coordinates of the slave node) const double* X = node.X(); Nx[0] -= X[0]; Nx[1] -= X[1]; // get the normal of node const double* n = node.N(); // calculate F double F = Nx[0]*n[1] - Nx[1]*n[0]; gap = Nx[0] * n[0] + Nx[1] * n[1]; // Do we need to divide by the length of the normal??? GAH // // gap = (Nx[0] * n[0] + Nx[1] * n[1]) // / sqrt(n[0] * n[0] + n[1] * n[1]); // ||gap|| cos theta #if 0 std::cout << "node " << node.Id() << " seg " << seg.Id() << " n[0] " << n[0] << " n[1] " << n[1] << std::endl; std::cout << "X[0] " << X[0] << " X[1] " << X[1] << std::endl; std::cout << "Nx[0] " << Nx[0] << " Nx[1] " << Nx[1] << " gap " << gap << std::endl; std::cout << "norm " << sqrt(n[0] * n[0] + n[1] * n[1]) << std::endl; #endif return F; }