Beispiel #1
0
void test_smooth_r4<float_type>::test()
{
    // place particles along the x-axis within one half of the box,
    // put every second particle at the origin
    unsigned int npart = particle->nparticle();
    vector_type dx(0);
    dx[0] = box->edges()(0, 0) / npart / 2;

    std::vector<vector_type> r_list(particle->nparticle());
    std::vector<unsigned int> species(particle->nparticle());
    for (unsigned int k = 0; k < r_list.size(); ++k) {
        r_list[k] = (k % 2) ? k * dx : vector_type(0);
        species[k] = (k < npart_list[0]) ? 0U : 1U;  // set particle type for a binary mixture
    }
    BOOST_CHECK( set_position(*particle, r_list.begin()) == r_list.end() );
    BOOST_CHECK( set_species(*particle, species.begin()) == species.end() );

    // read forces and other stuff from device
    std::vector<float> en_pot(particle->nparticle());
    BOOST_CHECK( get_potential_energy(*particle, en_pot.begin()) == en_pot.end() );

    std::vector<vector_type> f_list(particle->nparticle());
    BOOST_CHECK( get_force(*particle, f_list.begin()) == f_list.end() );

    float const eps = std::numeric_limits<float>::epsilon();

    for (unsigned int i = 0; i < npart; ++i) {
        unsigned int type1 = species[i];
        unsigned int type2 = species[(i + 1) % npart];
        vector_type r = r_list[i] - r_list[(i + 1) % npart];
        vector_type f = f_list[i];

        // reference values from host module
        host_float_type fval, en_pot_;
        host_float_type rr = inner_prod(r, r);
        std::tie(fval, en_pot_) = (*host_potential)(rr, type1, type2);

        if (rr < host_potential->rr_cut(type1, type2)) {
            double rcut = host_potential->r_cut(type1, type2);
            // the GPU force module stores only a fraction of these values
            en_pot_ /= 2;

            // the first term is from the smoothing, the second from the potential
            // (see lennard_jones.cpp from unit tests)
            float const tolerance = 8 * eps * (1 + rcut/(rcut - std::sqrt(rr))) + 10 * eps;

            BOOST_CHECK_SMALL(norm_inf(fval * r - f), std::max(norm_inf(fval * r), 1.f) * tolerance * 2);
            BOOST_CHECK_CLOSE_FRACTION(en_pot_, en_pot[i], 2 * tolerance);
        }
        else {
            // when the distance is greater than the cutoff
            // set the force and the pair potential to zero
            fval = en_pot_ = 0;
            BOOST_CHECK_SMALL(norm_inf(f), eps);
            BOOST_CHECK_SMALL(en_pot[i], eps);
        }
    }
}
Beispiel #2
0
Datei: fmt.c Projekt: Sciumo/f2c
static const char *f_s(const char *s, int curloc)
{
	skip(s);
	if(*s++!='(')
	{
		return(NULL);
	}
	if(f__parenlvl++ ==1) f__revloc=curloc;
	if(op_gen(RET1,curloc,0,0)<0 ||
		(s=f_list(s))==NULL)
	{
		return(NULL);
	}
	skip(s);
	return(s);
}
Beispiel #3
0
static char *
f_s(unit *ftnunit, char *s, int curloc)
{
   skip (s);
   if (*s++ != '(') {
      return (NULL);
   }
   if (ftnunit->parenlvl++ == 1)
      ftnunit->revloc = curloc;
   if (op_gen (ftnunit, RET, curloc, 0, 0) < 0 ||
       (s = f_list (ftnunit, s)) == NULL) {
      return (NULL);
   }
   skip (s);
   return (s);
}
Beispiel #4
0
const char *
f_s(const char *s, int curloc)
{
  skip(s);
  if (*s++ != '(')
    return NULL;

  if (f__parenlvl++ == 1)
    f__revloc=curloc;

  if ((op_gen(RET1, curloc, 0, 0) < 0) || ((s = f_list(s)) == NULL))
    return NULL;

  skip(s);

  return(s);
}
Beispiel #5
0
bool CamalPaveDriver::prepareCGMEvaluator()
{
	//
	// we will have to mesh every geo edge separately, and we have to ensure that the number of mesh edges
	// for a face is even.
	// pretty tough to do. Initially, we have to decide loops, number of edges on each face, etc
	// first build
	//int err;
	// get the triangles and the vertices from moab set

	/*iBase_EntityHandle *triangles = NULL;
	int triangles_alloc = 0;
	iBase_EntityHandle *vert_adj = NULL;
	int vert_adj_alloc = 0, vert_adj_size;
	int numTriangles;
	int * offsets = NULL, offsets_alloc = 0, indices_size;
	int * indices = NULL, indices_alloc = 0, offsets_size;
	iMesh_getAdjEntIndices(_meshIface, _set, iBase_FACE, iMesh_TRIANGLE,
			iBase_VERTEX, &triangles, &triangles_alloc, &numTriangles,
			&vert_adj, &vert_adj_alloc, &vert_adj_size, &indices,
			&indices_alloc, &indices_size, &offsets, &offsets_alloc,
			&offsets_size, &err);
	ERRORR("Couldn't get connectivity for triangles.", 1);*/

	MBRange triangles;
	MBErrorCode rval = _mb->get_entities_by_type( 0 /* root set, as above, we know */,
											   MBTRI, triangles);
	// get all the nodes
	MBRange vertices;
	rval = _mb->get_adjacencies(triangles, 0, false, vertices, MBInterface::UNION);

	// first, create CubitPointData list, from the coordinates in one array
	/* get the coordinates in one array */

	/*int vert_coords_alloc = 0, vertex_coord_size;
	double * xyz = NULL;
	iMesh_getVtxArrCoords(_meshIface, vert_adj, vert_adj_size,
			iBase_INTERLEAVED, &xyz, &vert_coords_alloc, &vertex_coord_size,
			&err);
	ERRORR("Couldn't get coordinates for vertices.", 1);*/

	// here, we use Cholla from CGM
	// we need to replace it with something equivalent, but simpler
	// the first try would be some tags in MOAB
	// create the cubit point data
	// initialize CGM
	AppUtil::instance()->startup(0, NULL);
	CGMApp::instance()->startup(0, NULL);

	// Initialize the GeometryTool
	GeometryQueryTool *gqt = GeometryQueryTool::instance();
	FacetModifyEngine *fme = FacetModifyEngine::instance();

	int vert_adj_size =  vertices.size();
	int numTriangles = triangles.size();
	DLIList<CubitFacet*> f_list(numTriangles);
	DLIList<CubitPoint*> p_list(vert_adj_size);
	double * xyz = new double [3*vert_adj_size];
	rval = _mb->  get_coords(vertices, xyz);
	//std::map<MBEntityHandle, CubitPoint *> mapPoints;
	//MBRange::iterator it = vertices.begin();
	for (int i = 0; i < vert_adj_size; i++/*, it++*/) {
		double * pCoord = &xyz[3 * i];
		CubitPointData * newPoint = new CubitPointData(pCoord[0], pCoord[1],
				pCoord[2]);
		p_list.append(newPoint);
		//mapPoints[*it] = newPoint;// or maybe we should use finding the index in MBRange??
	}

	// yes
	// define all the triangles, to see what we have
	for (MBRange::iterator it = triangles.begin(); it!=triangles.end(); it++) {
		MBEntityHandle tri = *it;
		int nnodes;
		const MBEntityHandle * conn3;//
		_mb->get_connectivity(tri, conn3, nnodes);
		assert(nnodes == 3);
		int vtri[3];// indices for triangles
		int ii = 0;
		for (ii = 0; ii < 3; ii++)
			vtri[ii] = vertices.index(conn3[ii]); // vtri[ii] = indices[offsets[j] + ii];
		CubitFacetData * triangle = new CubitFacetData(p_list[vtri[0]],
				p_list[vtri[1]], p_list[vtri[2]]);
		f_list.append(triangle);
	}

	DLIList<LoopSM*> my_loops;

	DLIList<Surface*> surf_list;
	CubitStatus result;
	//double angle = 0.01;// very small, negligible; is this radians or degrees?
	result = fme->build_facet_surface(NULL, f_list, p_list, _angle, 4, true,
			false, surf_list);

	if (surf_list.size() == 0 || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based surfaces.\n");
		return result;
	} else
		PRINT_INFO("Constructed %d surfaces.\n", surf_list.size());

	//Now build the shell.  If we had it set up right this would be
	//in a loop.  We need to store list of DLBlockSurfaceLists on each
	//blockvolumemesh to store the shell information.  But that will
	//be saved for later.
	ShellSM *shell_ptr;
	result = fme->make_facet_shell(surf_list, shell_ptr);

	if (shell_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based shell entity.\n");
		return result;
	}
#if 1
	DLIList<ShellSM*> shell_list;
	shell_list.append(shell_ptr);
	Lump *lump_ptr;
	result = fme->make_facet_lump(shell_list, lump_ptr);

	if (lump_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based lump entity.\n");
		return result;
	}
	DLIList<Lump*> lump_list;
	lump_list.append(lump_ptr);

	BodySM *bodysm_ptr;
	Body *body_ptr;
	result = fme->make_facet_body(lump_list, bodysm_ptr);

	body_ptr = GeometryQueryTool::instance()->make_Body(bodysm_ptr);

	if (body_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based body entity.\n");
		return result;
	}

	if (!body_ptr) {
		exit(1);
	}

	PRINT_INFO("Body successfully created.\n");
#endif
	PRINT_INFO("Number of vertices = %d\n", gqt->num_ref_vertices());
	PRINT_INFO("Number of edges = %d\n", gqt->num_ref_edges());
	PRINT_INFO("Number of faces = %d\n", gqt->num_ref_faces());

	// print vertex positions
	DLIList<RefVertex*> verts;
	gqt->ref_vertices(verts);

	int i;
	for (i = 0; i < verts.size(); i++) {
		RefVertex * vert = verts[i];
		CubitVector coords = vert->coordinates();
		PRINT_INFO("Vertex %d: %4.2f, %4.2f, %4.2f.\n", vert->id(), coords.x(),
				coords.y(), coords.z());
	}
	// print edges and faces

	DLIList<RefEdge*> refEdges;
	gqt->ref_edges(refEdges);

	for (i = 0; i < refEdges.size(); i++) {
		RefEdge * edg = refEdges[i];
		PRINT_INFO("Edge %d: %d %d\n", edg->id(), edg->start_vertex()->id(), edg->end_vertex ()->id() );
	}

	DLIList<RefFace*> refFaces;
	gqt->ref_faces(refFaces);

	for (i = 0; i < refFaces.size(); i++) {
		RefFace * face = refFaces[i];
		DLIList<  Loop * >  loop_list  ;
		face->ordered_loops (loop_list ) ;
		DLIList<  RefEdge  * > ordered_edge_list;
		loop_list[0]->ordered_ref_edges  (ordered_edge_list);

		//DLIList<  RefVertex* >  *listV = ref_vert_loop_list[0];
		PRINT_INFO("face %d: loop 0 size %d\n", face->id(),  ordered_edge_list.size() );
		for (int j=0; j<ordered_edge_list.size(); j++)
		{
			PRINT_INFO("  %d", ordered_edge_list[j]->id() );
		}
		PRINT_INFO("\n");
	}
	return true;
}