Esempio n. 1
0
int main (int argc, char** argv)
{
	libMesh::init (argc, argv);
	{
		std::cout << "Running " << argv[0];
		for (int i=1; i<argc; i++)
			std::cout << " " << argv[i];
		std::cout << std::endl << std::endl;

        config.load();
        config.print();

		PerfLog perf("Main Program");
		perf.start_event("program init");
		Mesh mesh (config.dim);
		MeshData mesh_data(mesh);
		//mesh_data.activate();
		mesh_data.enable_compatibility_mode();

		mesh.read("tmp/in.xda",&mesh_data);
        mesh.find_neighbors();
		//mesh_data.read("data.xta");
		//mesh.print_info();

		EquationSystems equation_systems (mesh,&mesh_data);
        LinearImplicitSystem & eigen_system =
	    	equation_systems.add_system<LinearImplicitSystem> ("Poisson");
	    	//equation_systems.add_system<EigenSystem> ("Poisson");
		equation_systems.get_system("Poisson").add_variable("u", FIRST);
		equation_systems.get_system("Poisson").attach_assemble_function (assemble_poisson);
        unsigned int nev = config.eigs;
        equation_systems.parameters.set<unsigned int>("eigenpairs")    = nev;
        equation_systems.parameters.set<unsigned int>("basis vectors") = nev*3;
//        eigen_system.eigen_solver-> set_eigensolver_type(ARNOLDI);
        //eigen_system.eigen_solver-> set_eigensolver_type(SUBSPACE);
        //eigen_system.eigen_solver-> set_eigensolver_type(POWER);
//        eigen_system.eigen_solver-> set_eigensolver_type(LANCZOS);
//        eigen_system.set_eigenproblem_type(GHEP);
//        eigen_system.eigen_solver->set_position_of_spectrum(SMALLEST_MAGNITUDE);
        //eigen_system.eigen_solver->set_position_of_spectrum(LARGEST_MAGNITUDE);
        equation_systems.parameters.set<Real>("linear solver tolerance") = 
            pow(TOLERANCE, 5./3.);
        equation_systems.parameters.set<unsigned int>
	        ("linear solver maximum iterations") = 1000;
		equation_systems.init();
		//equation_systems.print_info();
		perf.stop_event("program init");

        if (config.assemble) {
            assemble_poisson(equation_systems, "Poisson");
        }
        if (!config.printlog) perf.clear();
	}
	return libMesh::close();
}
Mesh MeshFactory::createBillboardMesh() {
    vector<GLfloat> vertices = {
        -0.5f,  0.5f, 0.0f, 0.0f, 0.0f,
         0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
        -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
         0.5f, -0.5f, 0.0f, 1.0f, 1.0f
     };

     vector<GLuint> elements = {
         2, 1, 0,
         1, 2, 3
     };

     MeshData mesh_data(vertices, elements);
     Mesh billboard_mesh(mesh_data, billboard_mesh_vertex_specification);
     return billboard_mesh;
}
Mesh MeshFactory::createFlatMesh() {
    vector<GLfloat> vertices = {
             -1.0f,  1.0f,  0.0f, 1.0f,
             -1.0f, -1.0f,  0.0f, 0.0f,
              1.0f,  1.0f,  1.0f, 1.0f,
              1.0f, -1.0f,  1.0f, 0.0f,

    };

    vector<GLuint> elements = {
            0, 1, 2,
            1, 3, 2,
    };

    MeshData mesh_data(vertices, elements);
    Mesh flat_mesh(mesh_data, flat_mesh_vertex_specification);
    return flat_mesh;
}
Esempio n. 4
0
	Buffer compile_collider(const char* json, CompileOptions& opts)
	{
		TempAllocator4096 ta;
		JsonObject obj(ta);
		sjson::parse(json, obj);

		DynamicString type(ta);
		sjson::parse_string(obj["shape"], type);

		ColliderType::Enum st = shape_type_to_enum(type.c_str());
		RESOURCE_COMPILER_ASSERT(st != ColliderType::COUNT
			, opts
			, "Unknown shape type: '%s'"
			, type.c_str()
			);

		ColliderDesc cd;
		cd.type        = st;
		cd.shape_class = sjson::parse_string_id(obj["class"]);
		cd.material    = sjson::parse_string_id(obj["material"]);
		cd.local_tm    = MATRIX4X4_IDENTITY;
		cd.size        = 0;

		DynamicString scene(ta);
		DynamicString name(ta);
		sjson::parse_string(obj["scene"], scene);
		sjson::parse_string(obj["name"], name);
		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH, scene.c_str(), opts);
		scene += "." RESOURCE_EXTENSION_MESH;

		Buffer file = opts.read(scene.c_str());
		JsonObject json_mesh(ta);
		JsonObject geometries(ta);
		JsonObject nodes(ta);
		JsonObject node(ta);
		sjson::parse(file, json_mesh);
		sjson::parse(json_mesh["geometries"], geometries);
		sjson::parse(json_mesh["nodes"], nodes);
		sjson::parse(nodes[name.c_str()], node);
		const char* mesh = geometries[name.c_str()];

		Matrix4x4 matrix_local = sjson::parse_matrix4x4(node["matrix_local"]);
		cd.local_tm = matrix_local;

		Array<Vector3> mesh_data(default_allocator());

		switch (cd.type)
		{
			case ColliderType::SPHERE:      compile_sphere(mesh, cd); break;
			case ColliderType::CAPSULE:     compile_capsule(mesh, cd); break;
			case ColliderType::BOX:         compile_box(mesh, cd); break;
			case ColliderType::CONVEX_HULL: compile_convex_hull(mesh, mesh_data); break;
			case ColliderType::MESH:
			case ColliderType::HEIGHTFIELD:
			{
				RESOURCE_COMPILER_ASSERT(false, opts, "Not implemented yet");
				break;
			}
		}

		cd.size = sizeof(Vector3)*array::size(mesh_data);

		Buffer buf(default_allocator());
		array::push(buf, (char*)&cd, sizeof(cd));

		if (array::size(mesh_data))
			array::push(buf, (char*)array::begin(mesh_data), sizeof(Vector3)*array::size(mesh_data));

		return buf;
	}