コード例 #1
0
ファイル: VTK2OGS.cpp プロジェクト: MichaelRink/ogs_ufz
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Converts VTK mesh into OGS mesh.", ' ', "0.1");
	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
	                                     "the name of the file containing the input mesh", true,
	                                     "", "file name of input mesh");
	cmd.add(mesh_in);
	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "file name of output mesh");
	cmd.add(mesh_out);
	cmd.parse(argc, argv);

	MeshLib::Mesh* mesh (FileIO::BoostVtuInterface::readVTUFile(mesh_in.getValue()));
	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());

	FileIO::Legacy::MeshIO meshIO;
	meshIO.setMesh(mesh);
	meshIO.writeToFile(mesh_out.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: RemiCannepin/ogs
int main(int argc, char* argv[])
{
#ifdef OGS_USE_OPENSG
	OSG::osgInit(argc, argv);
#endif
	LOGOG_INITIALIZE();
	logog::Cout* logogCout = new logog::Cout;
	BaseLib::LogogSimpleFormatter* formatter = new BaseLib::LogogSimpleFormatter;
	logogCout->SetFormatter(*formatter);
	QApplication a(argc, argv);
	QApplication::setApplicationName("OpenGeoSys - Data Explorer");
	QApplication::setApplicationVersion(QString(OGS_VERSION));
	QApplication::setOrganizationName("OpenGeoSys Community");
	QApplication::setOrganizationDomain("opengeosys.org");
	setlocale(LC_NUMERIC,"C");
	MainWindow* w = new MainWindow();
	w->setWindowTitle( w->windowTitle() + " - " + QString(OGS_VERSION_AND_PERSONS) + " - FirstFloor");
	w->show();
	int returncode = a.exec();
	delete w;
	delete formatter;
	delete logogCout;
	LOGOG_SHUTDOWN();
#ifdef OGS_USE_OPENSG
	OSG::osgExit();
#endif // OGS_USE_OPENSG

	return returncode;
}
コード例 #3
0
ファイル: MeshRead.cpp プロジェクト: Doublle/ogs
int main(int argc, char *argv[])
{
    LOGOG_INITIALIZE();
    BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
    logog::Cout *logogCout(new logog::Cout);
    logogCout->SetFormatter(*custom_format);

    TCLAP::CmdLine cmd("Simple mesh loading test", ' ', "0.1");

    // Define a value argument and add it to the command line.
    // A value arg defines a flag and a type of value that it expects,
    // such as "-m meshfile".
    TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"homer","string");

    // Add the argument mesh_arg to the CmdLine object. The CmdLine object
    // uses this Arg to parse the command line.
    cmd.add( mesh_arg );

    cmd.parse( argc, argv );

    std::string fname (mesh_arg.getValue());

#ifndef WIN32
    BaseLib::MemWatch mem_watch;
    unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif
    BaseLib::RunTime run_time;
    run_time.start();
    MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname);
#ifndef WIN32
    unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
//    std::cout << "mem for mesh: " << (mem_with_mesh - mem_without_mesh)/(1024*1024) << " MB" << std::endl;
    INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif

//    std::cout << "time for reading: " << run_time.elapsed() << " s" << std::endl;
    INFO ("time for reading: %f s", run_time.elapsed());

/*
    unsigned elem_id = 25000;
    const MeshLib::Element* e = mesh->getElement(elem_id);
    const std::size_t nElems = mesh->getNumberOfElements();
    for (unsigned i=0; i< e->getNumberOfNeighbors(); i++)
    {
        for (unsigned j=0; j< nElems; j++)
            if (mesh->getElement(j) == e->getNeighbor(i))
                std::cout << "neighbour of element " << elem_id << " : " << j << std::endl;
    }
*/

    delete mesh;
    delete logogCout;
    delete custom_format;
    LOGOG_SHUTDOWN();
}
コード例 #4
0
ファイル: NodeReordering.cpp プロジェクト: envinf/ogs
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logogCout = new logog::Cout;
	BaseLib::LogogSimpleFormatter* formatter = new BaseLib::LogogSimpleFormatter;
	logogCout->SetFormatter(*formatter);

	TCLAP::CmdLine cmd("Reordering of mesh nodes to make OGS Data Explorer 5 meshes compatible with OGS6.\n" \
	                   "Method 1 is the re-ordering between DataExplorer 5 and DataExplorer 6 meshes,\n" \
	                   "Method 2 is the re-ordering with and without InSitu-Lib in OGS6.",
	                   ' ', "0.1");
	TCLAP::UnlabeledValueArg<std::string> input_mesh_arg("input_mesh",
	                                                     "the name of the input mesh file",
	                                                     true, "", "oldmesh.msh");
	cmd.add(input_mesh_arg);
	TCLAP::UnlabeledValueArg<std::string> output_mesh_arg("output_mesh",
	                                                      "the name of the output mesh file",
	                                                      true, "", "newmesh.vtu");
	cmd.add(output_mesh_arg);
	TCLAP::ValueArg<int> method_arg("m", "method", "reordering method selection", false,  1, "value");

	cmd.add(method_arg);
	cmd.parse(argc, argv);

	MeshLib::Mesh* mesh (FileIO::readMeshFromFile(input_mesh_arg.getValue().c_str()));

	INFO("Reordering nodes... ");
	if (!method_arg.isSet() || method_arg.getValue() == 1)
		reorderNodes(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements()));
	else if (method_arg.getValue() == 2)
		reorderNodes2(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements()));
	else
	{
		ERR ("Unknown re-ordering method. Exit program...");
		return 1;
	}

	FileIO::VtuInterface writer(mesh);
	writer.writeToFile(output_mesh_arg.getValue().c_str());

	INFO("VTU file written.");

	delete formatter;
	delete logogCout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: Yonghui56/ogs6
int main(int argc, char* argv[])
{
#ifdef VTKOSGCONVERTER_FOUND
    OSG::osgInit(argc, argv);
#endif
#ifdef VTKFBXCONVERTER_FOUND
    InitializeSdkObjects(lSdkManager, lScene);
#endif

    auto myOutputWindow = vtkSmartPointer<VtkConsoleOutputWindow>::New();
    vtkOutputWindow::SetInstance(myOutputWindow);

    LOGOG_INITIALIZE();
    logog::Cout* logogCout = new logog::Cout;
    BaseLib::LogogSimpleFormatter* formatter = new BaseLib::LogogSimpleFormatter;
    logogCout->SetFormatter(*formatter);
    QApplication a(argc, argv);
    QApplication::setApplicationName("OpenGeoSys - Data Explorer");
    QApplication::setApplicationVersion(QString::fromStdString(
        BaseLib::BuildInfo::ogs_version));
    QApplication::setOrganizationName("OpenGeoSys Community");
    QApplication::setOrganizationDomain("opengeosys.org");
    setlocale(LC_NUMERIC,"C");
    QLocale::setDefault(QLocale::German);
    std::unique_ptr<MainWindow> w (new MainWindow());
    w->setWindowTitle( w->windowTitle() + " - " +
        QString::fromStdString(BaseLib::BuildInfo::git_describe));
    if (QCoreApplication::arguments().size()>1) {
        w->loadFileOnStartUp(QCoreApplication::arguments().at(1));
    }
    w->show();
    int returncode = a.exec();
    delete formatter;
    delete logogCout;
    LOGOG_SHUTDOWN();
#ifdef VTKFBXCONVERTER_FOUND
    DestroySdkObjects(lSdkManager, true);
#endif
#ifdef VTKOSGCONVERTER_FOUND
    OSG::osgExit();
#endif

    return returncode;
}
コード例 #6
0
ファイル: TIN2VTK.cpp プロジェクト: UFZ-MJ/ogs
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Converts TIN file into VTU file.", ' ', BaseLib::BuildInfo::git_describe);
	TCLAP::ValueArg<std::string> inArg("i", "input-tin-file",
	                                     "the name of the file containing the input TIN", true,
	                                     "", "string");
	cmd.add(inArg);
	TCLAP::ValueArg<std::string> outArg("o", "output-vtu-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "string");
	cmd.add(outArg);
	cmd.parse(argc, argv);

	INFO("reading the TIN file...");
	const std::string tinFileName(inArg.getValue());
	auto pnt_vec = std::unique_ptr<std::vector<GeoLib::Point*>>(
	    new std::vector<GeoLib::Point*>);
	GeoLib::PointVec point_vec("SurfacePoints", std::move(pnt_vec));
	std::unique_ptr<GeoLib::Surface> sfc(FileIO::TINInterface::readTIN(tinFileName, point_vec));
	if (!sfc)
		return 1;
	INFO("TIN read:  %d points, %d triangles", pnt_vec->size(), sfc->getNTriangles());

	INFO("converting to mesh data");
	std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::convertSurfaceToMesh(*sfc, BaseLib::extractBaseNameWithoutExtension(tinFileName), std::numeric_limits<double>::epsilon()));
	INFO("Mesh created: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());

	INFO("Write it into VTU");
	FileIO::VtuInterface writer(mesh.get());
	writer.writeToFile(outArg.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: WenjieXu/ogs
int main(int argc, char* argv[])
{
#ifdef VTKOSGCONVERTER_FOUND
    OSG::osgInit(argc, argv);
#endif
#ifdef VTKFBXCONVERTER_FOUND
    InitializeSdkObjects(lSdkManager, lScene);
#endif
    LOGOG_INITIALIZE();
    logog::Cout* logogCout = new logog::Cout;
    BaseLib::LogogSimpleFormatter* formatter = new BaseLib::LogogSimpleFormatter;
    logogCout->SetFormatter(*formatter);
    QApplication a(argc, argv);
    QApplication::setApplicationName("OpenGeoSys - Data Explorer");
    QApplication::setApplicationVersion(QString(OGS_VERSION));
    QApplication::setOrganizationName("OpenGeoSys Community");
    QApplication::setOrganizationDomain("opengeosys.org");
    setlocale(LC_NUMERIC,"C");
    QLocale::setDefault(QLocale::German);
    MainWindow* w = new MainWindow();
    w->setWindowTitle( w->windowTitle() + " - " + QString(OGS_VERSION_AND_PERSONS) + " - FirstFloor");
    w->show();
    int returncode = a.exec();
    delete w;
    delete formatter;
    delete logogCout;
    LOGOG_SHUTDOWN();
#ifdef VTKFBXCONVERTER_FOUND
    DestroySdkObjects(lSdkManager, true);
#endif
#ifdef VTKOSGCONVERTER_FOUND
    OSG::osgExit();
#endif

    return returncode;
}
コード例 #8
0
ファイル: MeshSearchTest.cpp プロジェクト: RemiCannepin/ogs
int main(int argc, char *argv[])
{
    LOGOG_INITIALIZE();
    logog::Cout* logog_cout (new logog::Cout);
    BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
    logog_cout->SetFormatter(*custom_format);

    TCLAP::CmdLine cmd("Simple mesh search test", ' ', "0.1");

    // Define a value argument and add it to the command line.
    // A value arg defines a flag and a type of value that it expects,
    // such as "-m meshfile".
    TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"test.msh","string");

    // Add the argument mesh_arg to the CmdLine object. The CmdLine object
    // uses this Arg to parse the command line.
    cmd.add( mesh_arg );

    TCLAP::ValueArg<unsigned> number_arg("n","number-of-test-points","the number of test points",true,10000,"positive number");
    cmd.add( number_arg );

    TCLAP::ValueArg<bool> contiguous_arg("c","use-contiguous-memory","use a contiguous memory for the test",false,true,"yes or no | 1 or 0");
    cmd.add( contiguous_arg );

    cmd.parse( argc, argv );

    std::string fname (mesh_arg.getValue());

    FileIO::MeshIO mesh_io;
#ifndef WIN32
    BaseLib::MemWatch mem_watch;
    unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
#endif
    BaseLib::RunTime run_time;
    run_time.start();
    MeshLib::Mesh* mesh (mesh_io.loadMeshFromFile(fname));
#ifndef WIN32
    unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
    INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
#endif
    run_time.stop();
    INFO ("time for reading: %f s", run_time.elapsed());

    // *** preparing test data
    std::vector<MeshLib::Node*> const& nodes(mesh->getNodes());
    std::vector<GeoLib::Point*> pnts_for_search;
    unsigned n(std::min(static_cast<unsigned>(nodes.size()), number_arg.getValue()));
    for (size_t k(0); k<n; k++) {
        pnts_for_search.push_back(new GeoLib::Point(nodes[k]->getCoords()));
    }

    std::vector<size_t> idx_found_nodes;
    testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes, contiguous_arg.getValue());

    for (size_t k(0); k<n; k++) {
        delete pnts_for_search[k];
    }

    delete mesh;
    delete custom_format;
    delete logog_cout;
    LOGOG_SHUTDOWN();
}
コード例 #9
0
ファイル: MoveMesh.cpp プロジェクト: LEONOB2014/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Moves the mesh nodes using the given displacement vector or if no displacement vector is given, moves the mesh nodes such that the centroid of the given mesh is in the origin.", ' ', "0.1");
	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m meshfile".
	TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"","string");

	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( mesh_arg );

	TCLAP::ValueArg<double> x_arg("x","x","displacement in x direction", false, 0.0,"floating point number");
	cmd.add(x_arg);
	TCLAP::ValueArg<double> y_arg("y","y","displacement in y direction", false, 0.0,"floating point number");
	cmd.add(y_arg);
	TCLAP::ValueArg<double> z_arg("z","z","displacement in z direction", false, 0.0,"floating point number");
	cmd.add(z_arg);

	TCLAP::ValueArg<std::string> mesh_out_arg("o","output-mesh","output mesh file", false, "", "string");
	cmd.add(mesh_out_arg);

	cmd.parse( argc, argv );

	std::string fname (mesh_arg.getValue());

	MeshLib::Mesh* mesh = FileIO::readMeshFromFile(fname);

	MeshLib::Node displacement(0.0, 0.0, 0.0);
	if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon()
		&& fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon()
		&& fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon()) {
		GeoLib::AABB<MeshLib::Node> aabb(mesh->getNodes().begin(), mesh->getNodes().end());
		displacement[0] = -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0])/2.0;
		displacement[1] = -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1])/2.0;
		displacement[2] = -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2])/2.0;
	} else {
		displacement[0] = x_arg.getValue();
		displacement[1] = y_arg.getValue();
		displacement[2] = z_arg.getValue();
	}

	INFO("translate model (%f, %f, %f).", displacement[0], displacement[1], displacement[2]);
	MeshLib::moveMeshNodes(
		mesh->getNodes().begin(),
		mesh->getNodes().end(),
		displacement);

	std::string out_fname(mesh_out_arg.getValue());
	if (out_fname.empty()) {
		out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
		out_fname += "_displaced.vtu";
	}

	FileIO::VtuInterface mesh_io(mesh);
	mesh_io.writeToFile(out_fname);

	delete mesh;
	delete logogCout;
	delete custom_format;
	LOGOG_SHUTDOWN();
}
コード例 #10
0
ファイル: removeMeshElements.cpp プロジェクト: WenjieXu/ogs
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "0.1");
	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
	                                     "the name of the file containing the input mesh", true,
	                                     "", "file name of input mesh");
	cmd.add(mesh_in);
	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "file name of output mesh");
	cmd.add(mesh_out);
	TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false);
	cmd.add(zveArg);
	TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type",
	                                      "element type to be removed", false, "element type");
	cmd.add(eleTypeArg);
	TCLAP::MultiArg<unsigned> matIDArg("m", "material-id",
	                                      "material id", false, "material id");
	cmd.add(matIDArg);
	cmd.parse(argc, argv);

	MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue()));
	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());

	// search elements IDs to be removed
	std::vector<std::size_t> vec_elementIDs_removed;
	if (zveArg.isSet()) {
		std::vector<std::size_t> vec_matched = searchByZeroContent(mesh->getElements());
		updateUnion(vec_matched, vec_elementIDs_removed);
		INFO("%d zero volume elements found.", vec_matched.size());
	}
	if (eleTypeArg.isSet()) {
		std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
		for (auto typeName : eleTypeNames) {
			MeshElemType type = String2MeshElemType(typeName);
			if (type == MeshElemType::INVALID) continue;
			std::vector<std::size_t> vec_matched = searchByElementType(mesh->getElements(), type);
			updateUnion(vec_matched, vec_elementIDs_removed);
			INFO("%d %s elements found.", vec_matched.size(), typeName.c_str());
		}
	}
	if (matIDArg.isSet()) {
		std::vector<unsigned> vec_matID = matIDArg.getValue();
		for (auto matID : vec_matID) {
			std::vector<std::size_t> vec_matched = searchByMaterialID(mesh->getElements(), matID);
			updateUnion(vec_matched, vec_elementIDs_removed);
			INFO("%d elements with material ID %d found.", vec_matched.size(), matID);
		}
	}

	// remove the elements
	INFO("Removing total %d elements...", vec_elementIDs_removed.size());
	std::vector<MeshLib::Element*> tmp_eles = excludeElements(mesh->getElements(), vec_elementIDs_removed);
	INFO("%d elements remained.", tmp_eles.size());
	std::vector<MeshLib::Node*> new_nodes;
	std::vector<MeshLib::Element*> new_eles;
	copyNodesElements(mesh->getNodes(), tmp_eles, new_nodes, new_eles);

	// create a new mesh object. Unsued nodes are removed while construction
	MeshLib::Mesh* new_mesh(new MeshLib::Mesh(mesh->getName(), new_nodes, new_eles));

	// write into a file
	FileIO::Legacy::MeshIO meshIO;
	meshIO.setMesh(new_mesh);
	meshIO.writeToFile(mesh_out.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #11
0
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd(
	        "Generates properties for mesh elements of an input mesh deploying a ASC raster file",
	        ' ',
	        "0.1");

	TCLAP::ValueArg<std::string> out_mesh_arg("o",
	                                          "out-mesh",
	                                          "the mesh is stored to a file of this name",
	                                          false,
	                                          "",
	                                          "filename for mesh output");
	cmd.add( out_mesh_arg );

	TCLAP::ValueArg<bool> refinement_raster_output_arg("",
	                                                   "output-refined-raster",
	                                                   "write refined raster to a new ASC file",
	                                                   false,
	                                                   false,
	                                                   "0");
	cmd.add( refinement_raster_output_arg );

	TCLAP::ValueArg<unsigned> refinement_arg(
	        "r",
	        "refine",
	        "refinement factor that raises the resolution of the raster data",
	        false,
	        1,
	        "factor (default = 1)");
	cmd.add( refinement_arg );

	TCLAP::ValueArg<std::string> mapping_arg("",
	                                         "mapping-name",
	                                         "file name of mapping",
	                                         true,
	                                         "",
	                                         "file name");
	cmd.add( mapping_arg );

	TCLAP::ValueArg<std::string> raster_arg("",
	                                        "raster-file",
	                                        "the name of the ASC raster file",
	                                        true,
	                                        "",
	                                        "file name");
	cmd.add( raster_arg );

	TCLAP::ValueArg<std::string> mesh_arg("m",
	                                      "mesh",
	                                      "the mesh is read from this file",
	                                      true,
	                                      "test.msh",
	                                      "file name");
	cmd.add( mesh_arg );

	cmd.parse( argc, argv );

	// read mesh
	MeshLib::Mesh* dest_mesh(FileIO::readMeshFromFile(mesh_arg.getValue()));

	// read raster and if required manipulate it
	GeoLib::Raster* raster(FileIO::AsciiRasterInterface::getRasterFromASCFile(
		raster_arg.getValue()));
	if (refinement_arg.getValue() > 1) {
		raster->refineRaster(refinement_arg.getValue());
		if (refinement_raster_output_arg.getValue()) {
			// write new asc file
			std::string new_raster_fname (BaseLib::dropFileExtension(
			                                      raster_arg.getValue()));
			new_raster_fname += "-" + std::to_string(raster->getNRows()) + "x" +
			                    std::to_string(raster->getNCols()) + ".asc";
			FileIO::AsciiRasterInterface::writeRasterAsASC(*raster, new_raster_fname);
		}
	}

	// put raster data in a std::vector
	GeoLib::Raster::const_iterator raster_it(raster->begin());
	std::size_t n_cols(raster->getNCols()), n_rows(raster->getNRows());
	std::size_t size(n_cols * n_rows);
	std::vector<double> src_properties(size);
	for (unsigned row(0); row<n_rows; row++) {
		for (unsigned col(0); col<n_cols; col++) {
			src_properties[row * n_cols + col] = *raster_it;
			++raster_it;
		}
	}

	{
		double mu, var;
		std::tie(mu, var) = computeMeanAndVariance(src_properties.begin(), src_properties.end());
		INFO("Mean value of source: %f.", mu);
		INFO("Variance of source: %f.", var);
	}

	MeshLib::Mesh* src_mesh(MeshLib::ConvertRasterToMesh(*raster, MeshLib::MeshElemType::QUAD,
					MeshLib::UseIntensityAs::MATERIAL).execute());

	std::vector<std::size_t> src_perm(size);
	std::iota(src_perm.begin(), src_perm.end(), 0);
	BaseLib::Quicksort<double>(src_properties, 0, size, src_perm);

	// compress the property data structure
	const std::size_t mat_map_size(src_properties.size());
	std::vector<std::size_t> mat_map(mat_map_size);
	mat_map[0] = 0;
	std::size_t n_mat(1);
	for (std::size_t k(1); k<mat_map_size; ++k) {
		if (std::fabs(src_properties[k] - src_properties[k-1]) > std::numeric_limits<double>::epsilon()) {
			mat_map[k] = mat_map[k - 1] + 1;
			n_mat++;
		} else
			mat_map[k] = mat_map[k - 1];
	}
	std::vector<double> compressed_src_properties(n_mat);
	compressed_src_properties[0] = src_properties[0];
	for (std::size_t k(1), id(1); k<mat_map_size; ++k) {
		if (std::fabs(src_properties[k] - src_properties[k-1]) > std::numeric_limits<double>::epsilon()) {
			compressed_src_properties[id] = src_properties[k];
			id++;
		}
	}
	compressed_src_properties[n_mat - 1] = src_properties[mat_map_size - 1];

	// reset materials in source mesh
	const std::size_t n_mesh_elements(src_mesh->getNElements());
	for (std::size_t k(0); k<n_mesh_elements; k++) {
		const_cast<MeshLib::Element*>(src_mesh->getElement(src_perm[k]))->setValue(mat_map[k]);
	}

	// do the interpolation
	MeshLib::Mesh2MeshPropertyInterpolation mesh_interpolation(src_mesh,
	                                                           &compressed_src_properties);
	std::vector<double> dest_properties(dest_mesh->getNElements());
	mesh_interpolation.setPropertiesForMesh(const_cast<MeshLib::Mesh*>(dest_mesh),
	                                        dest_properties);

	const std::size_t n_dest_mesh_elements(dest_mesh->getNElements());

	{ // write property file
		std::string property_fname(mapping_arg.getValue());
		std::ofstream property_out(property_fname.c_str());
		if (!property_out)
		{
			ERR("Could not open file %s for writing the mapping.", property_fname.c_str());
			return -1;
		}

		for (std::size_t k(0); k < n_dest_mesh_elements; k++)
			property_out << k << " " << dest_properties[k] << "\n";
		property_out.close();
	}

	{
		double mu, var;
		std::tie(mu, var) = computeMeanAndVariance(dest_properties.begin(), dest_properties.end());
		INFO("Mean value of destination: %f.", mu);
		INFO("Variance of destination: %f.", var);
	}

	if (! out_mesh_arg.getValue().empty()) {
		std::vector<std::size_t> dest_perm(n_dest_mesh_elements);
		std::iota(dest_perm.begin(), dest_perm.end(), 0);
		BaseLib::Quicksort<double>(dest_properties, 0, n_dest_mesh_elements, dest_perm);

		// reset materials in destination mesh
		for (std::size_t k(0); k<n_dest_mesh_elements; k++) {
			const_cast<MeshLib::Element*>(dest_mesh->getElement(dest_perm[k]))->setValue(k);
		}

		FileIO::Legacy::MeshIO mesh_writer;
		mesh_writer.setPrecision(12);
		mesh_writer.setMesh(dest_mesh);
		mesh_writer.writeToFile(out_mesh_arg.getValue());
	}

	delete raster;
	delete src_mesh;
	delete dest_mesh;

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #12
0
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();

	TCLAP::CmdLine cmd("Simple matrix vector multiplication test employing pthreads", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m matrix".
	TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string");

	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( matrix_arg );

	TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number");
	cmd.add( n_cores_arg );

	TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number");
	cmd.add( n_mults_arg );

	TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
	cmd.add( output_arg );

	TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string");
	cmd.add( verbosity_arg );

	cmd.parse( argc, argv );

	std::string fname_mat (matrix_arg.getValue());

	FormatterCustom *custom_format (new FormatterCustom);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	logog::LogFile *logog_file(NULL);
	if (! output_arg.getValue().empty()) {
		logog_file = new logog::LogFile(output_arg.getValue().c_str());
		logog_file->SetFormatter( *custom_format );
	}

#ifdef OGS_BUILD_INFO
	INFO("%s was build with compiler %s", argv[0], CMAKE_CXX_COMPILER);
#ifdef CMAKE_BUILD_TYPE
	if (std::string(CMAKE_BUILD_TYPE).compare("Release") == 0) {
		INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_RELEASE);
	} else {
		INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_DEBUG);
	}
#else
    INFO("CXX_FLAGS: %s", CMAKE_CXX_FLAGS);
#endif
#endif

#ifdef UNIX
	const int max_host_name_len (255);
	char *hostname(new char[max_host_name_len]);
	if (gethostname(hostname, max_host_name_len) == 0)
		INFO("hostname: %s", hostname);
	delete [] host_name_len;
#endif

	// *** reading matrix in crs format from file
	std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
	double *A(NULL);
	unsigned *iA(NULL), *jA(NULL), n;
	if (in) {
		INFO("reading matrix from %s ...", fname_mat.c_str());
		BaseLib::RunTime timer;
		timer.start();
		CS_read(in, n, iA, jA, A);
		timer.stop();
		INFO("\t- took %e s", timer.elapsed());
	} else {
		ERR("error reading matrix from %s", fname_mat.c_str());
		return -1;
	}
	unsigned nnz(iA[n]);
	INFO("\tParameters read: n=%d, nnz=%d", n, nnz);

#ifdef HAVE_PTHREADS
	unsigned n_threads(n_cores_arg.getValue());
	MathLib::CRSMatrixPThreads<double> mat (n, iA, jA, A, n_threads);

	double *x(new double[n]);
	double *y(new double[n]);

	for (unsigned k(0); k<n; ++k)
		x[k] = 1.0;

	// read the number of multiplication to execute
	unsigned n_mults (n_mults_arg.getValue());

	INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads);
	BaseLib::RunTime run_timer;
	BaseLib::CPUTime cpu_timer;
	run_timer.start();
	cpu_timer.start();
	for (size_t k(0); k<n_mults; k++) {
		mat.amux (1.0, x, y);
	}
	cpu_timer.stop();
	run_timer.stop();

	INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed());

	delete [] x;
	delete [] y;
#endif

	delete custom_format;
	delete logogCout;
	delete logog_file;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #13
0
ファイル: MatVecMultNDPerm.cpp プロジェクト: UFZ-MJ/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();

	TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM), where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m matrix".
	TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format");

	// Add the argument matrix_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( matrix_arg );

//	TCLAP::ValueArg<unsigned> n_cores_arg("n", "number-cores", "number of cores to use", true, "1", "number");
//	cmd.add( n_cores_arg );

	TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications");
	cmd.add( n_mults_arg );

	TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
	cmd.add( output_arg );

	TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string");
	cmd.add( verbosity_arg );

	cmd.parse( argc, argv );

	// read the number of multiplication to execute
	unsigned n_mults (n_mults_arg.getValue());
	std::string fname_mat (matrix_arg.getValue());
	bool verbose (verbosity_arg.getValue());

	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	INFO("%s was build with compiler %s",
		argv[0],
		BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG
	INFO("CXX_FLAGS: %s %s",
		BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
		BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else
	INFO("CXX_FLAGS: %s %s",
		BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
		BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif

#ifdef UNIX
	const std::size_t length(256);
	char *hostname(new char[length]);
	gethostname (hostname, length);
	INFO("hostname: %s", hostname);
	delete [] hostname;
#endif

	// *** reading matrix in crs format from file
	std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
	double *A(NULL);
	unsigned *iA(NULL), *jA(NULL), n;
	if (in) {
		if (verbose) {
			INFO("reading matrix from %s ...", fname_mat.c_str());
		}
		BaseLib::RunTime timer;
		timer.start();
		CS_read(in, n, iA, jA, A);
		if (verbose) {
			INFO("\t- took %e s", timer.elapsed());
		}
	} else {
		ERR("error reading matrix from %s", fname_mat.c_str());
		return -1;
	}
	unsigned nnz(iA[n]);
	if (verbose) {
		INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
	}

	MathLib::CRSMatrixReordered mat(n, iA, jA, A);

	double *x(new double[n]);
	double *y(new double[n]);

	for (unsigned k(0); k<n; ++k)
		x[k] = 1.0;

	// create time measurement objects
	BaseLib::RunTime run_timer;
	BaseLib::CPUTime cpu_timer;

	// calculate the nested dissection reordering
	if (verbose) {
		INFO("*** calculating nested dissection (ND) permutation of matrix ...");
	}
	run_timer.start();
	cpu_timer.start();
	MathLib::Cluster cluster_tree(n, iA, jA);
	unsigned *op_perm(new unsigned[n]);
	unsigned *po_perm(new unsigned[n]);
	for (unsigned k(0); k<n; k++)
		op_perm[k] = po_perm[k] = k;
	cluster_tree.createClusterTree(op_perm, po_perm, 1000);
	if (verbose) {
		INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
	}

	// applying the nested dissection reordering
	if (verbose) {
		INFO("\t[ND] applying nested dissection permutation to FEM matrix ... ");
	}
	run_timer.start();
	cpu_timer.start();
	mat.reorderMatrix(op_perm, po_perm);
	if (verbose) {
		INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
	}

#ifndef NDEBUG
//	std::string fname_mat_out(fname_mat.substr(0,fname_mat.length()-4)+"-reordered.bin");
//	std::ofstream os (fname_mat_out.c_str(), std::ios::binary);
//	if (os) {
//		std::cout << "writing matrix to " << fname_mat_out << " ... " << std::flush;
//		CS_write(os, n, mat.getRowPtrArray(), mat.getColIdxArray(), mat.getEntryArray());
//		std::cout << "done" << std::endl;
//	}
#endif

	if (verbose) {
		INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS ... ", n_mults);
	}
	run_timer.start();
	cpu_timer.start();
	for (std::size_t k(0); k<n_mults; k++) {
		mat.amux (1.0, x, y);
	}

	if (verbose) {
		INFO("\t[MVM] - took %e sec\t %e sec", cpu_timer.elapsed(), run_timer.elapsed());
	}

	delete [] x;
	delete [] y;

	delete custom_format;
	delete logogCout;
	LOGOG_SHUTDOWN();


	return 0;
}
コード例 #14
0
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Collapse mesh nodes and, if necessary, remove elements", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m meshfile".
	TCLAP::ValueArg<std::string> input_mesh_arg("m","mesh","input mesh file name",true,"","string");
	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( input_mesh_arg );

	TCLAP::ValueArg<std::string> output_mesh_arg("","out-mesh","mesh file name for output",false,"","string");
	cmd.add( output_mesh_arg );

	TCLAP::ValueArg<double> distance_arg("d","collapse-distance","maximal distance two nodes are collapsed",false,0.01,"for example you can set this parameter to 10^{-6} times maximal area length");
	cmd.add( distance_arg );

	cmd.parse( argc, argv );

	std::string fname (input_mesh_arg.getValue());

	FileIO::MeshIO mesh_io;
#ifndef WIN32
	BaseLib::MemWatch mem_watch;
	unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
	BaseLib::RunTime run_time;
	run_time.start();
#endif
	MeshLib::Mesh* mesh = mesh_io.loadMeshFromFile(fname);
#ifndef WIN32
	if (mesh) {
		unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
		INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
	}
	run_time.stop();
	if (mesh) {
		INFO ("time for reading: %f s", run_time.elapsed());
	}
#endif

#ifndef WIN32
	unsigned long mem_without_meshgrid (mem_watch.getVirtMemUsage());
	run_time.start();
#endif
	MeshLib::MeshCoarsener mesh_coarsener(mesh);
	MeshLib::Mesh *collapsed_mesh(mesh_coarsener (distance_arg.getValue()));

#ifndef WIN32
	run_time.stop();
	unsigned long mem_with_meshgrid (mem_watch.getVirtMemUsage());
	INFO ("mem for meshgrid: %i MB", (mem_with_meshgrid - mem_without_meshgrid)/(1024*1024));
	INFO ("time for collapsing: %f s", run_time.elapsed());
#endif

	mesh_io.setMesh(collapsed_mesh);
	std::string out_fname (output_mesh_arg.getValue());
	if (out_fname.empty()) {
		out_fname = "/home/fischeth/workspace/OGS-6/Build/CollapsedMesh.msh";
	}
	INFO ("writing collapsed mesh to %s", out_fname.c_str());
	mesh_io.writeToFile(out_fname);
	INFO ("done");

	delete mesh;
	delete collapsed_mesh;
	delete custom_format;
	delete logogCout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #15
0
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Append line elements into a mesh.", ' ', "0.1");
	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
	                                     "the name of the file containing the input mesh", true,
	                                     "", "file name of input mesh");
	cmd.add(mesh_in);
	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "file name of output mesh");
	cmd.add(mesh_out);
	TCLAP::ValueArg<std::string> geoFileArg("g", "geo-file",
	                                      "the name of the geometry file which contains polylines", true, "", "the name of the geometry file");
	cmd.add(geoFileArg);

	// parse arguments
	cmd.parse(argc, argv);

	// read GEO objects
	GeoLib::GEOObjects geo_objs;
	FileIO::BoostXmlGmlInterface xml(geo_objs);
	xml.readFile(geoFileArg.getValue());

	std::vector<std::string> geo_names;
	geo_objs.getGeometryNames (geo_names);
	if (geo_names.empty ())
	{
		std::cout << "no geometries found" << std::endl;
		return -1;
	}
	const GeoLib::PolylineVec* ply_vec (geo_objs.getPolylineVecObj(geo_names[0]));
	if (!ply_vec)
	{
		std::cout << "could not found polylines" << std::endl;
		return -1;
	}

	// read a mesh
	MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue()));
	if (!mesh)
	{
		ERR("Mesh file %s not found", mesh_in.getValue().c_str());
		return 1;
	}
	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());

	// add line elements
	std::unique_ptr<MeshLib::Mesh> new_mesh =
	    MeshGeoToolsLib::appendLinesAlongPolylines(*mesh, *ply_vec);
	INFO("Mesh created: %d nodes, %d elements.", new_mesh->getNNodes(), new_mesh->getNElements());

	// write into a file
	FileIO::Legacy::MeshIO meshIO;
	meshIO.setMesh(new_mesh.get());
	meshIO.writeToFile(mesh_out.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 1;
}
コード例 #16
0
ファイル: MatVecMultNDPermOpenMP.cpp プロジェクト: JobstM/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();

	TCLAP::CmdLine cmd("The purpose of this program is the speed test of sparse matrix vector multiplication (MVM) employing OpenMP technique, where the matrix is stored in CRS format. Before executing the MVM a nested dissection reordering is performed.", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m matrix".
	TCLAP::ValueArg<std::string> matrix_arg("m","matrix","input matrix file in CRS format",true,"","file name of the matrix in CRS format");

	// Add the argument matrix_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( matrix_arg );

	TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", true, 1, "number of cores");
	cmd.add( n_cores_arg );

	TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number of multiplications");
	cmd.add( n_mults_arg );

	TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
	cmd.add( output_arg );

	TCLAP::ValueArg<bool> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string");
	cmd.add( verbosity_arg );

	cmd.parse( argc, argv );

	// read the number of multiplication to execute
	unsigned n_mults (n_mults_arg.getValue());
	std::string fname_mat (matrix_arg.getValue());
	bool verbose (verbosity_arg.getValue());

	FormatterCustom *custom_format (new FormatterCustom);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	// read number of threads
	unsigned n_threads (n_cores_arg.getValue());

#ifdef OGS_BUILD_INFO
	INFO("%s was build with compiler %s", argv[0], CMAKE_CXX_COMPILER);
	if (std::string(CMAKE_BUILD_TYPE).compare("Release") == 0) {
		INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_RELEASE);
	} else {
		INFO("CXX_FLAGS: %s %s", CMAKE_CXX_FLAGS, CMAKE_CXX_FLAGS_DEBUG);
	}
#endif

#ifdef UNIX
	const size_t length(256);
	char *hostname(new char[length]);
	gethostname (hostname, length);
	INFO("hostname: %s", hostname);
	delete [] hostname;
#endif

	// *** reading matrix in crs format from file
	std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
	double *A(NULL);
	unsigned *iA(NULL), *jA(NULL), n;
	if (in) {
		if (verbose) {
			INFO("reading matrix from %s ...", fname_mat.c_str());
		}
		BaseLib::RunTime timer;
		timer.start();
		CS_read(in, n, iA, jA, A);
		timer.stop();
		if (verbose) {
			INFO("\t- took %e s", timer.elapsed());
		}
	} else {
		ERR("error reading matrix from %s", fname_mat.c_str());
		return -1;
	}
	unsigned nnz(iA[n]);
	if (verbose) {
		INFO("\tParameters read: n=%d, nnz=%d", n, nnz);
	}

#ifdef _OPENMP
	omp_set_num_threads(n_threads);
	MathLib::CRSMatrixReorderedOpenMP mat(n, iA, jA, A);
#else
	delete [] iA;
	delete [] jA;
	delete [] A;
	ERROR("program is not using OpenMP");
	return -1;
#endif
	double *x(new double[n]);
	double *y(new double[n]);

	for (unsigned k(0); k<n; ++k)
		x[k] = 1.0;

	// create time measurement objects
	BaseLib::RunTime run_timer;
	BaseLib::CPUTime cpu_timer;

	// calculate the nested dissection reordering
	if (verbose) {
		INFO("*** calculating nested dissection (ND) permutation of matrix ...");
	}
	run_timer.start();
	cpu_timer.start();
	MathLib::Cluster cluster_tree(n, iA, jA);
	unsigned *op_perm(new unsigned[n]);
	unsigned *po_perm(new unsigned[n]);
	for (unsigned k(0); k<n; k++)
		op_perm[k] = po_perm[k] = k;
	cluster_tree.createClusterTree(op_perm, po_perm, 1000);
	cpu_timer.stop();
	run_timer.stop();
	if (verbose) {
		INFO("\t[ND] - took %e sec \t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
	}

	// applying the nested dissection reordering
	if (verbose) {
		INFO("\t[ND] applying nested dissection permutation to FEM matrix ... ");
	}
	run_timer.start();
	cpu_timer.start();
	mat.reorderMatrix(op_perm, po_perm);
	cpu_timer.stop();
	run_timer.stop();
	if (verbose) {
		INFO("\t[ND]: - took %e sec\t%e sec", cpu_timer.elapsed(), run_timer.elapsed());
	}

	if (verbose) {
		INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads)... ", n_mults, n_threads);
	}

	run_timer.start();
	cpu_timer.start();
	for (size_t k(0); k<n_mults; k++) {
		mat.amux (1.0, x, y);
	}
	cpu_timer.stop();
	run_timer.stop();

	if (verbose) {
		INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed());
	}

	delete [] x;
	delete [] y;

	delete custom_format;
	delete logogCout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #17
0
ファイル: editMaterialID.cpp プロジェクト: Yonghuizz/ogs
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Edit material IDs of mesh elements.", ' ', "0.1");
	TCLAP::SwitchArg replaceArg("r", "replace", "replace material IDs", false);
	TCLAP::SwitchArg condenseArg("c", "condense", "condense material IDs", false);
	TCLAP::SwitchArg specifyArg("s", "specify", "specify material IDs by element types (-e)", false);
	std::vector<TCLAP::Arg*> vec_xors;
	vec_xors.push_back(&replaceArg);
	vec_xors.push_back(&condenseArg);
	vec_xors.push_back(&specifyArg);
	cmd.xorAdd(vec_xors);
	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
	                                     "the name of the file containing the input mesh", true,
	                                     "", "file name");
	cmd.add(mesh_in);
	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "file name");
	cmd.add(mesh_out);
	TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id",
	                                      "current material id to be replaced", false, "number");
	cmd.add(matIDArg);
	TCLAP::ValueArg<unsigned> newIDArg("n", "new-material-id",
	                                      "new material id", false, 0, "number");
	cmd.add(newIDArg);
	std::vector<std::string> eleList(MeshLib::getMeshElemTypeStringsShort());
	TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
	TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type",
	                                      "element type", false, "", &allowedVals);
	cmd.add(eleTypeArg);

	cmd.parse(argc, argv);

	if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet()) {
		INFO("Please select editing mode: -r or -c or -s");
		return 0;
	} else if (replaceArg.isSet() && condenseArg.isSet()) {
		INFO("Please select only one editing mode: -r or -c or -s");
		return 0;
	} else if (replaceArg.isSet()) {
		if (!matIDArg.isSet() || !newIDArg.isSet()) {
			INFO("current and new material IDs must be provided for replacement");
			return 0;
		}
	} else if (specifyArg.isSet()) {
		if (!eleTypeArg.isSet() || !newIDArg.isSet()) {
			INFO("element type and new material IDs must be provided to specify elements");
			return 0;
		}
	}

	MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue()));
	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());

	if (condenseArg.isSet()) {
		INFO("Condensing material ID...");
		MeshLib::ElementValueModification::condense(*mesh);
	} else if (replaceArg.isSet()) {
		INFO("Replacing material ID...");
		const auto vecOldID = matIDArg.getValue();
		const unsigned newID = newIDArg.getValue();
		for (auto oldID : vecOldID) {
			INFO("%d -> %d", oldID, newID);
			MeshLib::ElementValueModification::replace(*mesh, oldID, newID, true);
		}
	} else if (specifyArg.isSet()) {
		INFO("Specifying material ID...");
		const std::string eleTypeName(eleTypeArg.getValue());
		const MeshLib::MeshElemType eleType = MeshLib::String2MeshElemType(eleTypeName);
		const unsigned newID = newIDArg.getValue();
		unsigned cnt = MeshLib::ElementValueModification::setByElementType(*mesh, eleType, newID);
		INFO("updated %d elements", cnt);
	}

	// write into a file
	FileIO::writeMeshToFile(*mesh, mesh_out.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #18
0
ファイル: removeMeshElements.cpp プロジェクト: rinkk/ogs
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "0.1");

	// Bounding box params
	TCLAP::ValueArg<double> zLargeArg("", "z-max", "largest allowed extent in z-dimension",
	                                  false, std::numeric_limits<double>::max(), "value");
	cmd.add(zLargeArg);
	TCLAP::ValueArg<double> zSmallArg("", "z-min", "smallest allowed extent in z-dimension",
	                                  false,  -1 * std::numeric_limits<double>::max(), "value");
	cmd.add(zSmallArg);
	TCLAP::ValueArg<double> yLargeArg("", "y-max", "largest allowed extent in y-dimension",
	                                  false, std::numeric_limits<double>::max(), "value");
	cmd.add(yLargeArg);
	TCLAP::ValueArg<double> ySmallArg("", "y-min", "smallest allowed extent in y-dimension",
	                                   false,  -1 * std::numeric_limits<double>::max(), "value");
	cmd.add(ySmallArg);
	TCLAP::ValueArg<double> xLargeArg("", "x-max", "largest allowed extent in x-dimension",
	                                   false, std::numeric_limits<double>::max(), "value");
	cmd.add(xLargeArg);
	TCLAP::ValueArg<double> xSmallArg("", "x-min", "smallest allowed extent in x-dimension",
	                                  false, -1 * std::numeric_limits<double>::max(), "value");
	cmd.add(xSmallArg);

	// Non-bounding-box params
	TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false);
	cmd.add(zveArg);
	TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type",
	                                      "element type to be removed", false, "element type");
	cmd.add(eleTypeArg);
	TCLAP::MultiArg<unsigned> matIDArg("m", "material-id",
	                                      "material id", false, "material id");
	cmd.add(matIDArg);

	// I/O params
	TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
	                                      "the name of the file the mesh will be written to", true,
	                                      "", "file name of output mesh");
	cmd.add(mesh_out);
	TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file",
	                                     "the name of the file containing the input mesh", true,
	                                     "", "file name of input mesh");
	cmd.add(mesh_in);

	cmd.parse(argc, argv);

	MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue()));
	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
	MeshLib::ElementSearch ex(*mesh);

	// search elements IDs to be removed
	if (zveArg.isSet()) {
		const std::size_t n_removed_elements = ex.searchByContent();
		INFO("%d zero volume elements found.", n_removed_elements);
	}
	if (eleTypeArg.isSet()) {
		const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
		for (auto typeName : eleTypeNames) {
			const MeshLib::MeshElemType type = MeshLib::String2MeshElemType(typeName);
			if (type == MeshLib::MeshElemType::INVALID) continue;
			const std::size_t n_removed_elements = ex.searchByElementType(type);
			INFO("%d %s elements found.", n_removed_elements, typeName.c_str());
		}
	}
	if (matIDArg.isSet()) {
		const std::vector<unsigned> vec_matID = matIDArg.getValue();
		for (auto matID : vec_matID) {
			const std::size_t n_removed_elements = ex.searchByMaterialID(matID);
			INFO("%d elements with material ID %d found.", n_removed_elements, matID);
		}
	}

	if (xSmallArg.isSet() || xLargeArg.isSet() ||
	    ySmallArg.isSet() || yLargeArg.isSet() ||
	    zSmallArg.isSet() || zLargeArg.isSet())
	{
		bool aabb_error (false);
		if (xSmallArg.getValue() >= xLargeArg.getValue())
		{
		    ERR ("Minimum x-extent larger than maximum x-extent.");
		    aabb_error = true;
		}
		if (ySmallArg.getValue() >= yLargeArg.getValue())
		{
		    ERR ("Minimum y-extent larger than maximum y-extent.");
		    aabb_error = true;
		}
		if (zSmallArg.getValue() >= zLargeArg.getValue())
		{
		    ERR ("Minimum z-extent larger than maximum z-extent.");
		    aabb_error = true;
		}
		if (aabb_error)
		    return 1;

		std::array<MathLib::Point3d, 2> extent({{
			MathLib::Point3d(std::array<double,3>{{xSmallArg.getValue(),
				ySmallArg.getValue(), zSmallArg.getValue()}}),
			MathLib::Point3d(std::array<double,3>{{xLargeArg.getValue(),
				yLargeArg.getValue(), zLargeArg.getValue()}})}});
		const std::size_t n_removed_elements = ex.searchByBoundingBox(
			GeoLib::AABB(extent.begin(), extent.end()));
		INFO("%d elements found.", n_removed_elements);
	}

	// remove the elements and create a new mesh object.
	MeshLib::Mesh const*const new_mesh = MeshLib::removeElements(*mesh, ex.getSearchedElementIDs(), mesh->getName());

	// write into a file
	FileIO::Legacy::MeshIO meshIO;
	meshIO.setMesh(new_mesh);
	meshIO.writeToFile(mesh_out.getValue());

	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #19
0
int main (int argc, char* argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Add EMI data as a scalar cell array to a 2d mesh.", ' ', "0.1");

	// I/O params
	TCLAP::ValueArg<std::string> poly_out("o", "polydata-output-file",
	                                      "the name of the file the data will be written to", true,
	                                      "", "file name of polydata file");
	cmd.add(poly_out);
	TCLAP::ValueArg<std::string> csv_in("i", "csv-input-file",
	                                    "csv-file containing EMI data", true,
	                                    "", "name of the csv input file");
	cmd.add(csv_in);
	TCLAP::ValueArg<std::string> dem_in("s", "DEM-file",
	                                    "Surface DEM for mapping ERT data", false,
	                                    "", "file name of the Surface DEM");
	cmd.add(dem_in);
	cmd.parse(argc, argv);

	MeshLib::Mesh* mesh (nullptr);
	if (dem_in.isSet())
	{
		mesh = FileIO::VtuInterface::readVTUFile(dem_in.getValue());
		if (mesh == nullptr)
		{
			ERR ("Error reading mesh file.");
			return -2;
		}

		if (mesh->getDimension() != 2)
		{
			ERR ("This utility can handle only 2d meshes at this point.");
			delete mesh;
			return -3;
		}
		INFO("Surface mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
	}

	GeoLib::GEOObjects geo_objects;
	FileIO::XmlGmlInterface xml(geo_objects);
	//std::vector<GeoLib::Polyline*> *lines = new std::vector<GeoLib::Polyline*>;
	std::array<char, 2> dipol = {{ 'H', 'V' }};
	std::array<char,3> const regions = {{'A', 'B', 'C'}};
	for (std::size_t j=0; j<dipol.size(); ++j)
	{
		std::vector<GeoLib::Point*> *points   = new std::vector<GeoLib::Point*>;
		for (std::size_t i=0; i<regions.size(); ++i)
		{
			//std::size_t const start_idx (points->size());
			getPointsFromFile(*points, csv_in.getValue(), dipol[j], regions[i]);
			//std::size_t const end_idx (points->size());
			//GeoLib::Polyline* line = new GeoLib::Polyline(*points);
			//for (std::size_t j=start_idx; j<end_idx; ++j)
			//	line->addPoint(j);
			//lines->push_back(line);
		}
		std::string geo_name (std::string("EMI Data ").append(1,dipol[j]));
		geo_objects.addPointVec(points, geo_name);
		//geo_objects.addPolylineVec(lines, geo_name);

		if (mesh != nullptr)
		{
			GeoMapper mapper(geo_objects, geo_name);
			mapper.mapOnMesh(mesh);
		}
		
		xml.setNameForExport(geo_name);
		std::string const output_name = poly_out.getValue() + "_" + dipol[j] + ".gml";
		xml.writeToFile(output_name);
		
		std::vector<double> emi;
		for (std::size_t i=0; i<regions.size(); ++i)
			getMeasurements(emi, csv_in.getValue(), dipol[j], regions[i]);
		writeMeasurementsToFile(emi, poly_out.getValue(), dipol[j]);
		std::for_each(points->begin(), points->end(), std::default_delete<GeoLib::Point>());
		delete points;
	}
	
	delete mesh;
	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #20
0
ファイル: MatMult.cpp プロジェクト: Yonghuizz/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();

	TCLAP::CmdLine cmd("Simple matrix vector multiplication test", ' ', "0.1");

	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m matrix".
	TCLAP::ValueArg<std::string> matrix_arg("m", "matrix", "input matrix file", true, "", "string");

	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( matrix_arg );

	TCLAP::ValueArg<unsigned> n_cores_arg("p", "number-cores", "number of cores to use", false, 1, "number");
	cmd.add( n_cores_arg );

	TCLAP::ValueArg<unsigned> n_mults_arg("n", "number-of-multiplications", "number of multiplications to perform", true, 10, "number");
	cmd.add( n_mults_arg );

	TCLAP::ValueArg<std::string> output_arg("o", "output", "output file", false, "", "string");
	cmd.add( output_arg );

	TCLAP::ValueArg<unsigned> verbosity_arg("v", "verbose", "level of verbosity [0 very low information, 1 much information]", false, 0, "string");
	cmd.add( verbosity_arg );

	cmd.parse( argc, argv );

	// read the number of multiplication to execute
	unsigned n_mults (n_mults_arg.getValue());
	std::string fname_mat (matrix_arg.getValue());

	FormatterCustom *custom_format (new FormatterCustom);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	logog::LogFile *logog_file(NULL);
	if (! output_arg.getValue().empty()) {
		logog_file = new logog::LogFile(output_arg.getValue().c_str());
		logog_file->SetFormatter( *custom_format );
	}

	// read number of threads
	unsigned n_threads (n_cores_arg.getValue());

	INFO("%s was build with compiler %s",
		argv[0],
		BaseLib::BuildInfo::cmake_cxx_compiler.c_str());
#ifdef NDEBUG
	INFO("CXX_FLAGS: %s %s",
		BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
		BaseLib::BuildInfo::cmake_cxx_flags_release.c_str());
#else
	INFO("CXX_FLAGS: %s %s",
		BaseLib::BuildInfo::cmake_cxx_flags.c_str(),
		BaseLib::BuildInfo::cmake_cxx_flags_debug.c_str());
#endif

#ifdef UNIX
	const int max_host_name_len (255);
	char *hostname(new char[max_host_name_len]);
	if (gethostname(hostname, max_host_name_len) == 0)
		INFO("hostname: %s", hostname);
	delete [] host_name_len;
#endif

	// *** reading matrix in crs format from file
	std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary);
	double *A(NULL);
	unsigned *iA(NULL), *jA(NULL), n;
	if (in) {
		INFO("reading matrix from %s ...", fname_mat.c_str());
		BaseLib::RunTime timer;
		timer.start();
		CS_read(in, n, iA, jA, A);
		INFO("\t- took %e s", timer.elapsed());
	} else {
		INFO("error reading matrix from %s", fname_mat.c_str());
		return -1;
	}
	unsigned nnz(iA[n]);
	INFO("\tParameters read: n=%d, nnz=%d", n, nnz);

#ifdef _OPENMP
	omp_set_num_threads(n_threads);
	unsigned *mat_entries_per_core(new unsigned[n_threads]);
	for (unsigned k(0); k<n_threads; k++) {
		mat_entries_per_core[k] = 0;
	}

	OPENMP_LOOP_TYPE i;
	{
#pragma omp parallel for
		for (i = 0; i < n; i++) {
			mat_entries_per_core[omp_get_thread_num()] += iA[i + 1] - iA[i];
		}
	}

	INFO("*** work per core ***");
	for (unsigned k(0); k<n_threads; k++) {
		INFO("\t%d\t%d", k, mat_entries_per_core[k]);
	}
#endif

#ifdef _OPENMP
	omp_set_num_threads(n_threads);
	MathLib::CRSMatrixOpenMP<double, unsigned> mat (n, iA, jA, A);
#else
	MathLib::CRSMatrix<double, unsigned> mat (n, iA, jA, A);
#endif

	double *x(new double[n]);
	double *y(new double[n]);

	for (unsigned k(0); k<n; ++k)
		x[k] = 1.0;

	INFO("*** %d matrix vector multiplications (MVM) with Toms amuxCRS (%d threads) ...", n_mults, n_threads);
	BaseLib::RunTime run_timer;
	BaseLib::CPUTime cpu_timer;
	run_timer.start();
	cpu_timer.start();
	for (std::size_t k(0); k<n_mults; k++) {
		mat.amux (1.0, x, y);
	}

	INFO("\t[MVM] - took %e sec cpu time, %e sec run time", cpu_timer.elapsed(), run_timer.elapsed());

	delete [] x;
	delete [] y;

	delete custom_format;
	delete logogCout;
	delete logog_file;
	LOGOG_SHUTDOWN();

	return 0;
}
コード例 #21
0
ファイル: queryMesh.cpp プロジェクト: envinf/ogs
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();
	logog::Cout* logog_cout (new logog::Cout);
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog_cout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Query mesh information", ' ', BaseLib::BuildInfo::git_describe);
	TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string");
	cmd.add( mesh_arg );
	TCLAP::MultiArg<std::size_t> eleId_arg("e","element-id","element ID",false,"number");
	cmd.add( eleId_arg );
	TCLAP::MultiArg<std::size_t> nodeId_arg("n","node-id","node ID",false,"number");
	cmd.add( nodeId_arg );

	cmd.parse( argc, argv );

	const std::string filename(mesh_arg.getValue());

	// read the mesh file
	const MeshLib::Mesh* mesh = FileIO::readMeshFromFile(filename);
	if (!mesh)
		return 1;

	std::cout << std::scientific << std::setprecision(12);
	for (auto ele_id : eleId_arg.getValue())
	{
		std::cout << "--------------------------------------------------------" << std::endl;
		auto* ele = mesh->getElement(ele_id);
		std::cout << "# Element " << ele->getID() << std::endl;
		std::cout << "Type : " << CellType2String(ele->getCellType()) << std::endl;
		std::cout << "Mat ID : " << ele->getValue() << std::endl;
		std::cout << "Nodes: " << std::endl;
		for (unsigned i=0; i<ele->getNNodes(); i++)
			std::cout <<  ele->getNode(i)->getID() << " " << *ele->getNode(i) << std::endl;
		std::cout << "Content: " << ele->getContent() << std::endl;
		std::cout << "Neighbors: ";
		for (unsigned i=0; i<ele->getNNeighbors(); i++)
		{
			if (ele->getNeighbor(i))
				std::cout << ele->getNeighbor(i)->getID() << " ";
			else
				std::cout << "none ";
		}
		std::cout << std::endl;
	}

	for (auto node_id : nodeId_arg.getValue())
	{
		std::cout << "--------------------------------------------------------" << std::endl;
		auto* node = mesh->getNode(node_id);
		std::cout << "# Node" << node->getID() << std::endl;
		std::cout << "Coordinates: " << *node << std::endl;
		std::cout << "Connected elements: " ;
		for (unsigned i=0; i<node->getNElements(); i++)
			std::cout << node->getElement(i)->getID() << " ";
		std::cout << std::endl;
	}

	delete mesh;
	delete custom_format;
	delete logog_cout;
	LOGOG_SHUTDOWN();
}