Ejemplo n.º 1
0
int OPS_PFEMElement2D(Domain& theDomain, const ID& elenodes, ID& eletags)
{
    int numdata = OPS_GetNumRemainingInputArgs();
    if(numdata < 4) {
	opserr<<"WARNING: insufficient number of arguments\n";
	return 0;
    }

    // rho, mu, b1, b2, (thickness, kappa, lumped)
    numdata = OPS_GetNumRemainingInputArgs();
    if(numdata > 7) numdata = 7;
    double data[7] = {0,0,0,0,1.0,-1,1};
    if(OPS_GetDoubleInput(&numdata,data) < 0) return 0;

    // create elements
    ElementIter& theEles = theDomain.getElements();
    Element* theEle = theEles();
    int currTag = 0;
    if (theEle != 0) {
	currTag = theEle->getTag();
    }

    eletags.resize(elenodes.Size()/3);

    for (int i=0; i<eletags.Size(); i++) {
	theEle = new PFEMElement2D(--currTag,elenodes(3*i),elenodes(3*i+1),elenodes(3*i+2),
				   data[0],data[1],data[2],data[3],data[4],data[5],data[6]);
	if (theEle == 0) {
	    opserr<<"WARNING: run out of memory for creating element\n";
	    return -1;
	}
	if (theDomain.addElement(theEle) == false) {
	    opserr<<"WARNING: failed to add element to domain\n";
	    delete theEle;
	    return -1;
	}
	eletags(i) = currTag;
    }

    return 0;
}
Ejemplo n.º 2
0
int OPS_TriReMesh(Domain& domain, int ndf)
{
    if (OPS_GetNumRemainingInputArgs() < 3) {
	opserr<<"WARNING: want alpha? numfreeregions? rtag1? ... numfixregions? rtag1? ...\n";
	return -1;
    }

    int num = 1;
    double alpha;
    if (OPS_GetDoubleInput(&num,&alpha) < 0) {
	opserr<<"WARNING: failed to read alpha\n";
	return -1;
    }

    int numfreeregions;
    if (OPS_GetIntInput(&num,&numfreeregions) < 0) {
	opserr<<"WARNING: failed to read number of regions to be remeshed\n";
	return -1;
    }
    if (numfreeregions < 1) {
	opserr << "WARNING: numfreeregions < 1\n";
	return -1;
    }
    
    if (OPS_GetNumRemainingInputArgs() < numfreeregions+1) {
	opserr<<"WARNING: insufficient args for free regions\n";
	return -1;
    }

    ID rtagsfree(numfreeregions);
    if (OPS_GetIntInput(&numfreeregions, &rtagsfree(0)) < 0) {
	opserr<<"WARNING: failed to read region tags\n";
	return -1;
    }

    ID rtagsfix;
    if (OPS_GetNumRemainingInputArgs() > 0) {
	int numfixregions;
	if (OPS_GetIntInput(&num,&numfixregions) < 0) {
	    opserr<<"WARNING: failed to read number of regions to be fixed\n";
	    return -1;
	}
	
	if (numfixregions > 0) {
	    if (OPS_GetNumRemainingInputArgs() < numfixregions) {
		opserr<<"WARNING: insufficient args for fixed regions\n";
		return -1;
	    }
	    
	    rtagsfix.resize(numfixregions);
	    if (OPS_GetIntInput(&numfixregions, &rtagsfix(0)) < 0) {
		opserr<<"WARNING: failed to read region tags\n";
		return -1;
	    }
	}
    }


    // element args
    if (OPS_GetNumRemainingInputArgs() == 0) {
	opserr<<"WARNING: element args are not given\n";
	return -1;
    }

    TriMesh mesh(domain,ndf);

    return mesh.mesh(alpha,rtagsfree,rtagsfix);
}
Ejemplo n.º 3
0
int
TriMesh::mesh(double alpha, const ID& rtags2, const ID& rtags)
{
    // get all regions
    int numregions = rtags.Size()+rtags2.Size();
    int numpoints = 0;
    std::vector<MeshRegion*> regions(numregions);
    for(int i=0; i<rtags.Size(); i++) {
	MeshRegion* region = theDomain->getRegion(rtags(i));
	if(region == 0) {
	    opserr<<"WARNING: region "<<rtags(i)<<" is not defined\n";
	    return -1;
	}
	numpoints += region->getNodes().Size();
	regions[i] = region;
    }
    for(int i=0; i<rtags2.Size(); i++) {
	MeshRegion* region = theDomain->getRegion(rtags2(i));
	if(region == 0) {
	    opserr<<"WARNING: region "<<rtags2(i)<<" is not defined\n";
	    return -1;
	}
	numpoints += region->getNodes().Size();
	regions[i+rtags.Size()] = region;

	// remove elements
	const ID& eles = region->getExtraEles();
	for (int j=0; j<eles.Size(); j++) {
	    Element* ele = theDomain->removeElement(eles(j));
	    if (ele != 0) {
		delete ele;
	    }
	}

    }

    // get all points
    ID ptreg(0,numpoints), ptnode(0,numpoints);
    for(int i=0; i<numregions; i++) {
	const ID& nodes = regions[i]->getNodes();
	for(int j=0; j<nodes.Size(); j++) {
	    int index = ptreg.Size();
	    ptreg[index] = i;
	    ptnode[index] = nodes(j);
	}
    }

    // calling mesh generator
    TriangleMeshGenerator gen;
    for(int i=0; i<ptnode.Size(); i++) {
	// get node
	Node* theNode = theDomain->getNode(ptnode(i));
	if(theNode == 0) {
	    opserr<<"WARNING: node "<<ptnode(i)<<" is not defined\n";
	    return -1;
	}
	const Vector& crds = theNode->getCrds();
	const Vector& disp = theNode->getTrialDisp();
	if(crds.Size() < 2 || disp.Size() < 2) {
	    opserr<<"WARNING: ndm < 2 or ndf < 2\n";
	    return -1;
	}
	
	// add point
	gen.addPoint(crds(0)+disp(0), crds(1)+disp(1));
    }

    // meshing
    gen.remesh(alpha);

    // get elenodes
    std::vector<ID> regelenodes(rtags2.Size());
    for(int i=0; i<gen.getNumTriangles(); i++) {
	int p1,p2,p3;
	gen.getTriangle(i,p1,p2,p3);

	// if all connected to fixed regions
	int numfix = rtags.Size();
	if(ptreg(p1)<numfix && ptreg(p2)<numfix && ptreg(p3)<numfix) {
	    continue;
	}
	
	// which region it belongs to
	int reg = ptreg(p1);
	if(reg<numfix || (reg>ptreg(p2) && ptreg(p2)>=numfix)) reg = ptreg(p2);
	if(reg<numfix || (reg>ptreg(p3) && ptreg(p3)>=numfix)) reg = ptreg(p3);
	reg -= numfix;

	// elenodes
	int index = regelenodes[reg].Size();
	regelenodes[reg][index++] = ptnode(p1);
	regelenodes[reg][index++] = ptnode(p2);
	regelenodes[reg][index++] = ptnode(p3);
    }

    // all elenodes
    ID allelenodes;
    for(int i=0; i<(int)regelenodes.size(); i++) {
	int num = allelenodes.Size();
	int num1 = regelenodes[i].Size();
	allelenodes.resize(num+num1);
	for (int j=0; j<num1; j++) {
	    allelenodes(num+j) = regelenodes[i](j);
	}
    }

    // create elements
    std::string eletype = OPS_GetString();
    ID eletags;
    if (eletype=="PFEMElement2D") {
	if (OPS_PFEMElement2D(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}
    } else if (eletype=="PFEMElement2DQuasi") {
	if (OPS_PFEMElement2DCompressible(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}
    } else if (eletype=="PFEMElement2DBubble") {
	if (OPS_PFEMElement2DBubble(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}

    }  else if (eletype=="tri31") {
	if (OPS_Tri31(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}

    } else {
	opserr<<"WARNING: element "<<eletype.c_str()<<" can't be used for tri mesh at this time\n";
	return -1;
    }

    // add to region
    int num = 0;

    for(int i=rtags.Size(); i<numregions; i++) {
	int num1 = regelenodes[i-rtags.Size()].Size()/3;
	ID eletag(num1);
	for (int j=0; j<num1; j++) {
	    eletag(j) = eletags(num+j);
	}
	num += num1;
	regions[i]->setExtraEles(eletag);
    }
    return 0;
}
Ejemplo n.º 4
0
int OPS_ElasticBeam2d(Domain& theDomain, const ID& elenodes, ID& eletags)
{
    if(OPS_GetNumRemainingInputArgs() < 4) {
	opserr<<"insufficient arguments:A,E,Iz,transfTag\n";
	return -1;
    }

    // inputs: 
    double data[3];
    int numData = 3;
    if(OPS_GetDoubleInput(&numData,&data[0]) < 0) return -1;

    numData = 1;
    int transfTag;
    if(OPS_GetIntInput(&numData,&transfTag) < 0) return -1;
    
    // options
    double mass = 0.0, alpha=0.0, depth=0.0;
    int cMass = 0;
    while(OPS_GetNumRemainingInputArgs() > 0) {
	std::string type = OPS_GetString();
	if(type == "-alpha") {
	    if(OPS_GetNumRemainingInputArgs() > 0) {
		if(OPS_GetDoubleInput(&numData,&alpha) < 0) return -1;
	    }
	} else if(type == "-depth") {
	    if(OPS_GetNumRemainingInputArgs() > 0) {
		if(OPS_GetDoubleInput(&numData,&depth) < 0) return -1;
	    }

	} else if(type == "-mass") {
	    if(OPS_GetNumRemainingInputArgs() > 0) {
		if(OPS_GetDoubleInput(&numData,&mass) < 0) return -1;
	    }
	} else if(type == "-cMass") {
	    cMass = 1;
	}
    }

    // check transf
    CrdTransf* theTransf = OPS_getCrdTransf(transfTag);
    if(theTransf == 0) {
	opserr<<"coord transfomration not found\n";
	return -1;
    }

    // create elements
    ElementIter& theEles = theDomain.getElements();
    Element* theEle = theEles();
    int currTag = 0;
    if (theEle != 0) {
	currTag = theEle->getTag();
    }
    eletags.resize(elenodes.Size()/2);
    for (int i=0; i<elenodes.Size()/2; i++) {
	theEle = new ElasticBeam2d(--currTag,data[0],data[1],data[2],elenodes(2*i),elenodes(2*i+1),
				   *theTransf,alpha,depth,mass,cMass);
	if (theEle == 0) {
	    opserr<<"WARING: run out of memory for creating element\n";
	    return -1;
	}
	if (theDomain.addElement(theEle) == false) {
	    opserr<<"WARNING: failed to add element to domain\n";
	    delete theEle;
	    return -1;
	}
	eletags(i) = currTag;
    }

    return 0;
}
Ejemplo n.º 5
0
int OPS_Tri31(Domain& theDomain, const ID& elenodes, ID& eletags)
{
    // get inputs
    int numRemainingInputArgs = OPS_GetNumRemainingInputArgs();
    if (numRemainingInputArgs < 3) {
	opserr << "Invalid #args, want: thk? type? matTag? <pressure? rho? b1? b2?>\n";
	return -1;
    }

    int matID;
    double thk;
    char *theType;
    double dData[4];
    dData[0] = 0.0;
    dData[1] = 0.0;
    dData[2] = 0.0;
    dData[3] = 0.0;
 
    int numData = 1;
    if (OPS_GetDoubleInput(&numData, &thk) != 0) {
	opserr << "WARNING invalid thickness data: element Tri31 \n";
	return -1;
    }

    theType = (char*)OPS_GetString();
  
    numData = 1;
    if (OPS_GetIntInput(&numData, &matID) != 0) {
	opserr << "WARNING invalid integer data: element Tri31\n";
	return -1;
    }
  
    NDMaterial *theMaterial = OPS_getNDMaterial(matID);
    if (theMaterial == 0) {
	opserr << "WARNING element Tri31 \n";
	opserr << " Material: " << matID << "not found\n";
	return -1;
    }
  
    if (OPS_GetNumRemainingInputArgs() >= 4) {
	numData = 4;
	if (OPS_GetDoubleInput(&numData, &dData[0]) != 0) {
	    opserr << "WARNING invalid optional data: element Tri31\n";
	    return -1;
	}
    }

    // create elements
    ElementIter& theEles = theDomain.getElements();
    Element* theEle = theEles();
    int currTag = 0;
    if (theEle != 0) {
	currTag = theEle->getTag();
    }

    eletags.resize(elenodes.Size()/3);

    for (int i=0; i<eletags.Size(); i++) {
	theEle = new Tri31(--currTag,elenodes(3*i),elenodes(3*i+1),elenodes(3*i+2),
			   *theMaterial, theType, thk,
			   dData[0], dData[1], dData[2], dData[3]);
	if (theEle == 0) {
	    opserr<<"WARNING: run out of memory for creating element\n";
	    return -1;
	}
	if (theDomain.addElement(theEle) == false) {
	    opserr<<"WARNING: failed to add element to domain\n";
	    delete theEle;
	    return -1;
	}
	eletags(i) = currTag;
    }
  
    return 0;
}