/*
================
idCollisionModelManagerLocal::ParseCollisionModel
================
*/
cm_model_t* idCollisionModelManagerLocal::ParseCollisionModel( idLexer* src )
{

	cm_model_t* model;
	idToken token;
	
	if( numModels >= MAX_SUBMODELS )
	{
		common->Error( "LoadModel: no free slots" );
		return NULL;
	}
	model = AllocModel();
	models[numModels ] = model;
	numModels++;
	// parse the file
	src->ExpectTokenType( TT_STRING, 0, &token );
	model->name = token;
	src->ExpectTokenString( "{" );
	while( !src->CheckTokenString( "}" ) )
	{
	
		src->ReadToken( &token );
		
		if( token == "vertices" )
		{
			ParseVertices( src, model );
			continue;
		}
		
		if( token == "edges" )
		{
			ParseEdges( src, model );
			continue;
		}
		
		if( token == "nodes" )
		{
			src->ExpectTokenString( "{" );
			model->node = ParseNodes( src, model, NULL );
			src->ExpectTokenString( "}" );
			continue;
		}
		
		if( token == "polygons" )
		{
			ParsePolygons( src, model );
			continue;
		}
		
		if( token == "brushes" )
		{
			ParseBrushes( src, model );
			continue;
		}
		
		src->Error( "ParseCollisionModel: bad token \"%s\"", token.c_str() );
	}
	// calculate edge normals
	checkCount++;
	CalculateEdgeNormals( model, model->node );
	// get model bounds from brush and polygon bounds
	CM_GetNodeBounds( &model->bounds, model->node );
	// get model contents
	model->contents = CM_GetNodeContents( model->node );
	// total memory used by this model
	model->usedMemory = model->numVertices * sizeof( cm_vertex_t ) +
						model->numEdges * sizeof( cm_edge_t ) +
						model->polygonMemory +
						model->brushMemory +
						model->numNodes * sizeof( cm_node_t ) +
						model->numPolygonRefs * sizeof( cm_polygonRef_t ) +
						model->numBrushRefs * sizeof( cm_brushRef_t );
						
	return model;
}
Beispiel #2
0
int rechenraum::compute(const char *)
{

    coDoPolygons *poly;
    int i;

    char name[256];

//   fprintf(stderr, "rechenraum::compute(const char *) entering... \n");

#ifdef USE_STARTFILE
    char buf[256];
    Covise::getname(buf, startFile->getValue());
//   fprintf(stderr, "rechenraum::param = ReadGeometry(%s) ...", buf);
#endif
    if (model != NULL)
        FreeModel(model);
    model = AllocModel();

#ifdef USE_STARTFILE
    ReadStartfile(buf, model);
#else
    GetParamsFromControlPanel(model);
#endif

    if (!model)
    {
        sendError("Please select a parameter file first!!");
        return FAIL;
    }

    //// Cover plugin information object is created here
    createFeedbackObjects();

    /////////////////////////////
    // create geometry for COVISE
    if ((ci = CreateGeometry4Covise(model)))
    {
        //      fprintf(stderr, "rechenraum::compute(const char *): Geometry created\n");

        poly = new coDoPolygons(surface->getObjName(),
                                ci->p->nump,
                                ci->p->x, ci->p->y, ci->p->z,
                                ci->vx->num, ci->vx->list,
                                ci->pol->num, ci->pol->list);
        poly->addAttribute("MATERIAL", "metal metal.30");
        poly->addAttribute("vertexOrder", "1");
        surface->setCurrentObject(poly);
    }
    else
        fprintf(stderr, "Error in CreateGeometry4Covise (%s, %d)\n", __FILE__, __LINE__);

    //////////////// This creates the volume grid ////////////////////

    ////////////////////////
    // if button is pushed --> create computation grid
    if (p_makeGrid->getValue())
    {
        int size[2];

        if (p_lockmakeGrid->getValue() == 0)
            p_makeGrid->setValue(0); // push off button

        if (model == NULL)
        {
            sendError("Cannot create grid because model is NULL!");
            return (1);
        }
        model->spacing = p_gridSpacing->getValue();
        model->BCFile = p_BCFile->getValue();

        if ((rg = CreateRechGrid(model)) == NULL)
        {
            fprintf(stderr, "Error in CreateRechGrid!\n");
            return -1;
        }

        rg->bc_inval = 100;
        rg->bc_outval = 200;

        //      fprintf(stderr, "rechenraum: Grid created\n");

        coDoUnstructuredGrid *unsGrd = new coDoUnstructuredGrid(grid->getObjName(), // name of USG object
                                                                rg->e->nume, // number of elements
                                                                8 * rg->e->nume, // number of connectivities
                                                                rg->p->nump, // number of coordinates
                                                                1); // does type list exist?

        int *elem, *conn, *type;
        float *xc, *yc, *zc;
        unsGrd->getAddresses(&elem, &conn, &xc, &yc, &zc);
        unsGrd->getTypeList(&type);

        //      printf("nelem  = %d\n", rg->e->nume);
        //      printf("nconn  = %d\n", 8*rg->e->nume);
        //      printf("nccord = %d\n", rg->p->nump);

        int **GgridConn = rg->e->e;
        for (i = 0; i < rg->e->nume; i++)
        {
            *elem = 8 * i;
            elem++;

            *conn = (*GgridConn)[0];
            conn++;
            *conn = (*GgridConn)[1];
            conn++;
            *conn = (*GgridConn)[2];
            conn++;
            *conn = (*GgridConn)[3];
            conn++;
            *conn = (*GgridConn)[4];
            conn++;
            *conn = (*GgridConn)[5];
            conn++;
            *conn = (*GgridConn)[6];
            conn++;
            *conn = (*GgridConn)[7];
            conn++;

            *type = TYPE_HEXAGON;
            type++;

            GgridConn++;
        }

        // copy geometry coordinates to unsgrd
        memcpy(xc, rg->p->x, rg->p->nump * sizeof(float));
        memcpy(yc, rg->p->y, rg->p->nump * sizeof(float));
        memcpy(zc, rg->p->z, rg->p->nump * sizeof(float));

        // no blades
        // no periodic mesh
        // no rotating mesh
        // ...
        unsGrd->addAttribute("number_of_blades", "0");
        unsGrd->addAttribute("periodic", "0");
        unsGrd->addAttribute("rotating", "0");
        unsGrd->addAttribute("revolutions", "0");
        unsGrd->addAttribute("walltext", "");
        unsGrd->addAttribute("periotext", "");

        // set out port
        grid->setCurrentObject(unsGrd);

        // boundary condition lists
        // 1. Cells at walls
        poly = new coDoPolygons(bcwall->getObjName(),
                                rg->p->nump,
                                rg->p->x, rg->p->y, rg->p->z,
                                rg->bcwall->num, rg->bcwall->list,
                                rg->bcwallpol->num, rg->bcwallpol->list);
        //poly->addAttribute("MATERIAL","metal metal.30");
        poly->addAttribute("vertexOrder", "1");
        bcwall->setCurrentObject(poly);

        // 2. Cells at outlet
        poly = new coDoPolygons(bcout->getObjName(),
                                rg->p->nump,
                                rg->p->x, rg->p->y, rg->p->z,
                                rg->bcout->num, rg->bcout->list,
                                rg->bcoutpol->num, rg->bcoutpol->list);
        //poly->addAttribute("MATERIAL","metal metal.30");
        poly->addAttribute("vertexOrder", "1");
        bcout->setCurrentObject(poly);

        // 3. Cells at inlet
        poly = new coDoPolygons(bcin->getObjName(),
                                rg->p->nump,
                                rg->p->x, rg->p->y, rg->p->z,
                                rg->bcin->num, rg->bcin->list,
                                rg->bcinpol->num, rg->bcinpol->list);
        //poly->addAttribute("MATERIAL","metal metal.30");
        poly->addAttribute("vertexOrder", "1");
        bcin->setCurrentObject(poly);

        /*
std::vector<int> checkbcs_vl;
std::vector<int> checkbcs_pl;  
for (i=0;i<rg->bcinpol->num;i++)
{
   if (rg->bcin_type[i]==107)
   {
      fprintf(stderr,"%d: %d %d %d %d %d\n",i,rg->bcin->list[4*i+0],rg->bcin->list[4*i+1],rg->bcin->list[4*i+2],rg->bcin->list[4*i+3],rg->bcin_type[i]);
      checkbcs_pl.push_back(checkbcs_vl.size());
      checkbcs_vl.push_back(rg->bcin->list[4*i+0]);
      checkbcs_vl.push_back(rg->bcin->list[4*i+1]);
      checkbcs_vl.push_back(rg->bcin->list[4*i+2]);
      checkbcs_vl.push_back(rg->bcin->list[4*i+3]);
   }
}
poly = new coDoPolygons(bccheck->getObjName(),
                        rg->p->nump,
                        rg->p->x, rg->p->y, rg->p->z,                       
                        checkbcs_vl.size(), &checkbcs_vl[0],
                        checkbcs_pl.size(), &checkbcs_pl[0]);
bccheck->setCurrentObject(poly);
*/

        // we had several additional info, we should send to the
        // Domaindecomposition:
        //   0. number of columns per info
        //   1. type of node
        //   2. type of element
        //   3. list of nodes with bc (a node may appear more than one time)
        //   4. corresponding type to 3.
        //   5. wall
        //   6. balance
        //   7. pressure
        //   8. NULL

        coDistributedObject *partObj[10];
        int *data;
        float *bPtr;
        const char *basename = boco->getObjName();

        //   0. number of columns per info
        sprintf(name, "%s_colinfo", basename);
        size[0] = 6;
        size[1] = 0;
        coDoIntArr *colInfo = new coDoIntArr(name, 1, size);
        data = colInfo->getAddress();
        data[0] = RG_COL_NODE; // (=2)
        data[1] = RG_COL_ELEM; // (=2)
        data[2] = RG_COL_DIRICLET; // (=2)
        data[3] = RG_COL_WALL; // (=6)
        data[4] = RG_COL_BALANCE; // (=6)
        data[5] = RG_COL_PRESS; // (=6)
        partObj[0] = colInfo;

        //   1. type of node
        sprintf(name, "%s_nodeinfo", basename);
        size[0] = RG_COL_NODE;
        size[1] = rg->p->nump;
        coDoIntArr *nodeInfo = new coDoIntArr(name, 2, size);
        data = nodeInfo->getAddress();
        for (i = 0; i < rg->p->nump; i++)
        {
            *data++ = i + 1; // may be, that we later do it really correct
            *data++ = 0; // same comment ;-)
        }
        partObj[1] = nodeInfo;

        //   2. type of element
        sprintf(name, "%s_eleminfo", basename);
        size[0] = 2;
        size[1] = rg->e->nume * RG_COL_ELEM; // uwe: hier wird 4*nume allociert aber nur 2*nume mit Werten gefuellt
        coDoIntArr *elemInfo = new coDoIntArr(name, 2, size);
        data = elemInfo->getAddress();
        for (i = 0; i < rg->e->nume; i++)
        {
            *data++ = i + 1; // may be, that we later do it really corect
            *data++ = 0; // same comment ;-)
        }
        partObj[2] = elemInfo;

        //   3. list of nodes with bc (a node may appear more than one time)
        //      and its types
        sprintf(name, "%s_diricletNodes", basename);
        int num_diriclet = rg->bcin_nodes.size();

        size[0] = RG_COL_DIRICLET;
        size[1] = 5 * (num_diriclet);
        coDoIntArr *diricletNodes = new coDoIntArr(name, 2, size);
        data = diricletNodes->getAddress();

        //   4. corresponding value to 3.
        sprintf(name, "%s_diricletValue", basename);
        coDoFloat *diricletValues = new coDoFloat(name, 5 * num_diriclet);
        diricletValues->getAddress(&bPtr);

        for (i = 0; i < rg->bcin_nodes.size(); i++)
        {
            *data++ = rg->bcin_nodes[i] + 1; // node-number
            *data++ = 1; // type of node
            *bPtr++ = rg->bcin_velos[5 * i + 0]; // u

            *data++ = rg->bcin_nodes[i] + 1; // node-number
            *data++ = 2; // type of node
            *bPtr++ = rg->bcin_velos[5 * i + 1]; // v

            *data++ = rg->bcin_nodes[i] + 1; // node-number
            *data++ = 3; // type of node
            *bPtr++ = rg->bcin_velos[5 * i + 2]; // w

            *data++ = rg->bcin_nodes[i] + 1; // node-number
            *data++ = 4; // type of node
            *bPtr++ = rg->bcin_velos[5 * i + 4]; // epsilon

            *data++ = rg->bcin_nodes[i] + 1; // node-number
            *data++ = 5; // type of node
            *bPtr++ = rg->bcin_velos[5 * i + 3]; // k

            //*data++ = rg->bcin_nodes->list[i]+1;     // node-number
            //*data++ = 6;                             // type of node
            //*bPtr++ = 0.0;                           // temperature = 0.
        }

        partObj[3] = diricletNodes;
        partObj[4] = diricletValues;

        //   5. wall
        sprintf(name, "%s_wallValue", basename);
        coDoFloat *wallValues = new coDoFloat(name, rg->bcwallvol->num);
        wallValues->getAddress(&bPtr);
        size[0] = RG_COL_WALL;
        size[1] = rg->bcwallpol->num;
        sprintf(name, "%s_wall", basename);
        coDoIntArr *faces = new coDoIntArr(name, 2, size);
        data = faces->getAddress();
        for (i = 0; i < rg->bcwallpol->num; i++) // Achtung bcwall->pol->num != bcwall->vol->num
        {
            *data++ = rg->bcwall->list[4 * i + 0] + 1;
            *data++ = rg->bcwall->list[4 * i + 1] + 1;
            *data++ = rg->bcwall->list[4 * i + 2] + 1;
            *data++ = rg->bcwall->list[4 * i + 3] + 1;
            *data++ = rg->bcwallvol->list[i] + 1;
            *data++ = 55; // wall: moving | standing. here: always standing!
            *data++ = 0;
        }
        partObj[5] = faces;

        //   6. balance
        sprintf(name, "%s_balance", basename);
        size[0] = RG_COL_BALANCE;
        size[1] = rg->bcinvol.size() + rg->bcoutvol->num;

        coDoIntArr *balance = new coDoIntArr(name, 2, size);
        data = balance->getAddress();
        for (i = 0; i < rg->bcinvol.size(); i++)
        {
            /*
   if (rg->bcin_type[i]==107)
   {
      fprintf(stderr,"balance107 %d: %d %d %d %d %d\n",i,rg->bcin->list[4*i+0],rg->bcin->list[4*i+1],rg->bcin->list[4*i+2],rg->bcin->list[4*i+3],rg->bcin_type[i]);
   }
*/
            *data++ = rg->bcin->list[4 * i + 0] + 1;
            *data++ = rg->bcin->list[4 * i + 1] + 1;
            *data++ = rg->bcin->list[4 * i + 2] + 1;
            *data++ = rg->bcin->list[4 * i + 3] + 1;
            *data++ = rg->bcinvol[i] + 1;
            //*data++ = rg->bc_inval;
            *data++ = rg->bcin_type[i];
            *data++ = 0;
        }

        for (i = 0; i < rg->bcoutvol->num; i++)
        {
            *data++ = rg->bcout->list[4 * i + 0] + 1;
            *data++ = rg->bcout->list[4 * i + 1] + 1;
            *data++ = rg->bcout->list[4 * i + 2] + 1;
            *data++ = rg->bcout->list[4 * i + 3] + 1;
            *data++ = rg->bcoutvol->list[i] + 1;
            //*data++ = rg->bc_outval;
            *data++ = rg->bcout_type[i];
            *data++ = 0;
        }
        partObj[6] = balance;

        //  7. pressure bc: outlet elements
        sprintf(name, "%s_pressElems", basename);
        size[0] = 6;
        size[1] = 0;
        coDoIntArr *pressElems = new coDoIntArr(name, 2, size);
        data = pressElems->getAddress();

        //  8. pressure bc: value for outlet elements
        sprintf(name, "%s_pressVal", basename);
        coDoFloat *pressValues
            = new coDoFloat(name, 0);
        pressValues->getAddress(&bPtr);

        partObj[7] = pressElems;
        partObj[8] = NULL;

        coDoSet *set = new coDoSet((char *)basename, (coDistributedObject **)partObj);

        boco->setCurrentObject(set);

        float *xinp = new float[rg->bcin_nodes.size()];
        float *yinp = new float[rg->bcin_nodes.size()];
        float *zinp = new float[rg->bcin_nodes.size()];
        for (i = 0; i < rg->bcin_nodes.size(); i++)
        {
            xinp[i] = rg->p->x[rg->bcin_nodes[i]];
            yinp[i] = rg->p->y[rg->bcin_nodes[i]];
            zinp[i] = rg->p->z[rg->bcin_nodes[i]];
        }
        coDoPoints *in_points;
        in_points = new coDoPoints(inpoints->getObjName(), rg->bcin_nodes.size(), xinp, yinp, zinp);
        inpoints->setCurrentObject(in_points);

        coDoFloat *in_types;
        in_types = new coDoFloat(intypes->getObjName(), rg->bcin_type2.size(), &rg->bcin_type2[0]);
        intypes->setCurrentObject(in_types);

        /*
      float *xairp = new float[rg->bcair_nodes->num];
      float *yairp = new float[rg->bcair_nodes->num];
      float *zairp = new float[rg->bcair_nodes->num];
      for (i=0;i<rg->bcair_nodes->num;i++)
      {
         xairp[i]=rg->p->x[rg->bcair_nodes->list[i]];
         yairp[i]=rg->p->y[rg->bcair_nodes->list[i]];
         zairp[i]=rg->p->z[rg->bcair_nodes->list[i]];
      }

      coDoPoints *air_points;
      air_points = new coDoPoints(airpoints->getObjName(), rg->bcair_nodes->num, xairp, yairp, zairp);
      airpoints->setCurrentObject(air_points);

      float *xvenp = new float[rg->bcven_nodes->num];
      float *yvenp = new float[rg->bcven_nodes->num];
      float *zvenp = new float[rg->bcven_nodes->num];
      for (i=0;i<rg->bcven_nodes->num;i++)
      {
         xvenp[i]=rg->p->x[rg->bcven_nodes->list[i]];
         yvenp[i]=rg->p->y[rg->bcven_nodes->list[i]];
         zvenp[i]=rg->p->z[rg->bcven_nodes->list[i]];
      }
      coDoPoints *ven_points;
      ven_points = new coDoPoints(venpoints->getObjName(), rg->bcven_nodes->num, xvenp, yvenp, zvenp);
      venpoints->setCurrentObject(ven_points);
*/
        const char *geofile = p_geofile->getValue();
        const char *rbfile = p_rbfile->getValue();

        if (p_createGeoRbFile->getValue())
        {
            CreateGeoRbFile(rg, geofile, rbfile);
        }
    }

    ///////////////////////// Free everything ////////////////////////////////

    return SUCCESS;
}