コード例 #1
0
int main(int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logo_setup;

    TCLAP::CmdLine cmd(
        "Converts a geometry defined on a given mesh to distinct meshes.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2018, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);

    TCLAP::ValueArg<double> search_length_arg(
        "s",
        "searchlength",
        "search length determining radius for the node search algorithm. "
        "Non-negative floating point number (default 1e-16) ",
        false,
        1e-16,
        "float");
    cmd.add(search_length_arg);

    TCLAP::ValueArg<std::string> geometry_arg("g",
                                              "geometry",
                                              "the file name the geometry",
                                              true,
                                              "",
                                              "geometry file name");
    cmd.add(geometry_arg);

    TCLAP::ValueArg<std::string> mesh_arg(
        "m",
        "mesh",
        "the file name of the mesh where the geometry is defined",
        true,
        "",
        "mesh file name");
    cmd.add(mesh_arg);
    cmd.parse(argc, argv);

    std::unique_ptr<MeshLib::Mesh> mesh{
        MeshLib::IO::readMeshFromFile(mesh_arg.getValue())};

    auto const geo_objects = readGeometry(geometry_arg.getValue());

    double const search_length = search_length_arg.getValue();

    auto const extracted_meshes = constructAdditionalMeshesFromGeoObjects(
        *geo_objects,
        *mesh,
        std::make_unique<MeshGeoToolsLib::SearchLength>(search_length));

    for (auto const& m_ptr : extracted_meshes)
    {
        MeshLib::IO::writeMeshToFile(*m_ptr, m_ptr->getName() + ".vtu");
    }

    return EXIT_SUCCESS;
}
コード例 #2
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(
	        "Creates a new file for material properties and sets the material ids in the msh-file to 0",
	        ' ',
	        "0.1");

	TCLAP::ValueArg<std::string> mesh_arg("m",
	                                          "mesh",
	                                          "the mesh to open from a file",
	                                          false,
	                                          "",
	                                          "filename for mesh input");
	cmd.add( mesh_arg );

	cmd.parse( argc, argv );

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

	std::vector<MeshLib::Element*> &elems = *(const_cast<std::vector<MeshLib::Element*>*>(&(mesh->getElements())));
	std::size_t nElems(elems.size());

	std::string name = BaseLib::extractBaseNameWithoutExtension(mesh_arg.getValue());
	// create file
	std::string new_matname(name + "_prop");
	std::ofstream out_prop( new_matname.c_str(), std::ios::out );
	if (out_prop.is_open())
	{
		for (std::size_t i=0; i<nElems; i++)
			out_prop << i << "\t" << elems[i]->getValue() << "\n";
		out_prop.close();
	}
	else
	{
		ERR("Could not create property \"%s\" file.", new_matname.c_str());
		return -1;
	}

	// set mat ids to 0 and write new msh file
	for (std::size_t i=0; i<nElems; i++)
		elems[i]->setValue(0);

	std::string new_mshname(name + "_new.vtu");
	INFO("Writing mesh to file \"%s\".", new_mshname.c_str());
	FileIO::VtuInterface mesh_io(mesh);
	mesh_io.writeToFile (new_mshname);

	INFO("New files \"%s\" and \"%s\" written.", new_mshname.c_str(), new_matname.c_str());
	std::cout << "Conversion finished." << std::endl;

	return 1;
}
コード例 #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
int main (int argc, char* argv[])
{
	TCLAP::CmdLine cmd("Simple mesh creator for unstructured meshes", ' ', "0.1");
	TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "the mesh is stored to this file", true, "test.msh", "filename");
	cmd.add( mesh_arg );
	TCLAP::ValueArg<unsigned> width_arg("c","columns","the number of columns of the structured mesh", true, 1000, "number of cols");
	cmd.add( width_arg );
	TCLAP::ValueArg<unsigned> height_arg("r","rows","the number of rows of the structured mesh", true, 1000, "number of rows");
	cmd.add( height_arg );
	TCLAP::ValueArg<double> edge_length_arg("e","edge-length","the size of the edge length", false, 1, "edge length");
	cmd.add( edge_length_arg );
	TCLAP::ValueArg<double> origin_x_arg("x","origin-x","x coordinate of the origin of the mesh", false, 0.0, "x coords");
	cmd.add( origin_x_arg );
	TCLAP::ValueArg<double> origin_y_arg("y","origin-y","y coordinate of the origin of the mesh", false, 0.0, "y coords");
	cmd.add( origin_y_arg );
	TCLAP::ValueArg<double> origin_z_arg("z","origin-z","z coordinate of the origin of the mesh", false, 0.0, "z coords");
	cmd.add( origin_z_arg );

	cmd.parse( argc, argv );

	// thanks to KR for this algorithm
	unsigned height(height_arg.getValue()), width(width_arg.getValue());
	double edge_length(edge_length_arg.getValue());
	const unsigned size (height*width);
	double* values (new double[size]);
	const double origin[3] = {origin_x_arg.getValue() + edge_length/2, origin_y_arg.getValue() + edge_length/2, origin_z_arg.getValue()};
	for (unsigned i=0; i<size; ++i) values[i]=0;
	MeshLib::Mesh* mesh(MeshLib::VtkMeshConverter::convertImgToMesh(values, origin, height, width,
		edge_length, MeshLib::MeshElemType::QUAD, MeshLib::UseIntensityAs::DATAVECTOR));

	delete [] values;

	FileIO::Legacy::MeshIO mesh_writer;
	mesh_writer.setMesh(mesh);
	mesh_writer.setPrecision(12);
	mesh_writer.writeToFile(mesh_arg.getValue());

	delete mesh;
}
コード例 #5
0
ファイル: queryMesh.cpp プロジェクト: xingyuanmiao/ogs
int main(int argc, char *argv[])
{
	ApplicationsLib::LogogSetup logog_setup;

	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
	auto const mesh = std::unique_ptr<MeshLib::Mesh>(
		MeshLib::IO::readMeshFromFile(filename));
	if (!mesh)
		return EXIT_FAILURE;

	auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");

	for (auto ele_id : eleId_arg.getValue())
	{
		std::stringstream out;
		out << std::scientific
		    << std::setprecision(std::numeric_limits<double>::digits10);
		out << "--------------------------------------------------------" << std::endl;
		auto* ele = mesh->getElement(ele_id);
		out << "# Element " << ele->getID() << std::endl;
		out << "Type : " << CellType2String(ele->getCellType()) << std::endl;
		if (materialIds)
			out << "Mat ID : " << (*materialIds)[ele_id] << std::endl;
		out << "Nodes: " << std::endl;
		for (unsigned i=0; i<ele->getNNodes(); i++)
			out <<  ele->getNode(i)->getID() << " " << *ele->getNode(i) << std::endl;
		out << "Content: " << ele->getContent() << std::endl;
		out << "Neighbors: ";
		for (unsigned i=0; i<ele->getNNeighbors(); i++)
		{
			if (ele->getNeighbor(i))
				out << ele->getNeighbor(i)->getID() << " ";
			else
				out << "none ";
		}
		out << std::endl;
		INFO("%s", out.str().c_str());
	}

	for (auto node_id : nodeId_arg.getValue())
	{
		std::stringstream out;
		out << std::scientific
		    << std::setprecision(std::numeric_limits<double>::digits10);
		out << "--------------------------------------------------------" << std::endl;
		auto* node = mesh->getNode(node_id);
		out << "# Node" << node->getID() << std::endl;
		out << "Coordinates: " << *node << std::endl;
		out << "Connected elements: " ;
		for (unsigned i=0; i<node->getNElements(); i++)
			out << node->getElement(i)->getID() << " ";
		out << std::endl;
		INFO("%s", out.str().c_str());
	}
}
コード例 #6
0
ファイル: scaleProperty.cpp プロジェクト: endJunction/ogs
int main(int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logo_setup;

    TCLAP::CmdLine cmd(
        "Scales a property of a mesh.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);

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

    TCLAP::ValueArg<std::string> property_arg(
        "p",
        "property-name",
        "the name of the property the values are stored for",
        true,
        "",
        "property name as string");
    cmd.add(property_arg);

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

    std::vector<std::string> allowed_units{ "mm/a", "mm/month", "m/s" };
    TCLAP::ValuesConstraint<std::string> allowed_units_constraints{
        allowed_units};
    TCLAP::ValueArg<std::string> unit_arg("u",
                                          "input-unit",
                                          "input unit of the data",
                                          true,
                                          "m/s",
                                          &allowed_units_constraints);
    cmd.add(unit_arg);

    cmd.parse(argc, argv);

    std::unique_ptr<MeshLib::Mesh> mesh(
        MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));

    double scale(1.0);
    if (unit_arg.getValue() == "m/s")
    {
        scale = 1.0;
    }
    else if (unit_arg.getValue() == "mm/a")
    {
        scale = 1e-3 / (365.25 * 86400);
    }
    else if (unit_arg.getValue() == "mm/month")
    {
        scale = 1e-3 * (12.0 / (365.25 * 86400));
    }

    MeshLib::scaleMeshPropertyVector(*mesh, property_arg.getValue(), scale);

    MeshLib::IO::writeMeshToFile(*mesh, out_mesh_arg.getValue());

    return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: checkMesh.cpp プロジェクト: TomFischer/ogs
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Checks mesh properties.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::ogs_version +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::ogs_version);
    TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string");
    cmd.add( mesh_arg );
    TCLAP::SwitchArg valid_arg("v","validation","validate the mesh");
    cmd.add( valid_arg );
    TCLAP::SwitchArg print_properties_arg("p","print_properties","print properties stored in the mesh");
    cmd.add( print_properties_arg );

    cmd.parse( argc, argv );

    // read the mesh file
    BaseLib::MemWatch mem_watch;
    const unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
    BaseLib::RunTime run_time;
    run_time.start();
    std::unique_ptr<MeshLib::Mesh> mesh(
        MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
    if (!mesh)
    {
        return EXIT_FAILURE;
    }

    const unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
    if (mem_with_mesh>0)
    {
        INFO ("Memory size: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
        (void)mem_with_mesh;
    }
    INFO ("Time for reading: %g s", run_time.elapsed());

    // Geometric information
    const GeoLib::AABB aabb(MeshLib::MeshInformation::getBoundingBox(*mesh));
    auto minPt(aabb.getMinPoint());
    auto maxPt(aabb.getMaxPoint());
    INFO("Node coordinates:");
    INFO("\tx [%g, %g] (extent %g)", minPt[0], maxPt[0], maxPt[0]-minPt[0]);
    INFO("\ty [%g, %g] (extent %g)", minPt[1], maxPt[1], maxPt[1]-minPt[1]);
    INFO("\tz [%g, %g] (extent %g)", minPt[2], maxPt[2], maxPt[2]-minPt[2]);

    INFO("Edge length: [%g, %g]", mesh->getMinEdgeLength(), mesh->getMaxEdgeLength());

    // Element information
    const std::array<unsigned, 7> nr_ele_types(MeshLib::MeshInformation::getNumberOfElementTypes(*mesh));
    INFO("Element types:");
    unsigned etype = 0;
    if (nr_ele_types[etype] > 0)
    {
        INFO("\t%d lines", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d triangles", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d quads", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d tetrahedra", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d hexahedra", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d pyramids", nr_ele_types[etype]);
    }
    if (nr_ele_types[++etype] > 0)
    {
        INFO("\t%d prisms", nr_ele_types[etype]);
    }

    std::vector<std::string> const& vec_names (mesh->getProperties().getPropertyVectorNames());
    INFO("There are %d properties in the mesh:", vec_names.size());
    for (const auto & vec_name : vec_names)
    {
        auto vec_bounds (MeshLib::MeshInformation::getValueBounds<int>(*mesh, vec_name));
        if (vec_bounds.second != std::numeric_limits<int>::max())
        {
            INFO("\t%s: [%d, %d]", vec_name.c_str(), vec_bounds.first,
                 vec_bounds.second);
        }
        else
        {
            auto vec_bounds (MeshLib::MeshInformation::getValueBounds<double>(*mesh, vec_name));
            if (vec_bounds.second != std::numeric_limits<double>::max())
            {
                INFO("\t%s: [%g, %g]", vec_name.c_str(), vec_bounds.first,
                     vec_bounds.second);
            }
            else
            {
                INFO("\t%s: Unknown properties", vec_name.c_str());
            }
        }
    }

    if (valid_arg.isSet()) {
        // MeshValidation outputs error messages
        // Remark: MeshValidation can modify the original mesh
        MeshLib::MeshValidation validation(*mesh);

        unsigned const n_holes (MeshLib::MeshValidation::detectHoles(*mesh));
        if (n_holes > 0)
        {
            INFO("%d hole(s) detected within the mesh", n_holes);
        }
        else
        {
            INFO ("No holes found within the mesh.");
        }
    }
}
コード例 #8
0
int main (int argc, char* argv[])
{
	ApplicationsLib::LogogSetup logog_setup;

	TCLAP::CmdLine cmd(
		"Creates a layered 3D OGS mesh from an existing 2D OGS mesh and raster "
		"files representing subsurface layers. Supported raster formats are "
		"ArcGIS ascii rasters (*.asc) and Surfer Grids (*.grd)."
		"",
		' ',
		"1.0");

	TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
		"The name of the file containing the 2D input mesh.", true, "", "input file name");
	cmd.add(mesh_arg);

	TCLAP::ValueArg<std::string> mesh_out_arg("o", "output-mesh-file",
		"The name of the file to which the resulting 3D mesh will be written.",
		true, "", "output file name");
	cmd.add(mesh_out_arg);

	TCLAP::ValueArg<std::string> raster_path_arg("r", "raster-list", 
		"An ascii-file containing a list of raster files, starting from top (DEM) to bottom.",
		true, "", "list of raster files");
	cmd.add(raster_path_arg);

	double min_thickness (std::numeric_limits<double>::epsilon());
	TCLAP::ValueArg<double> min_thickness_arg("t", "thickness",
		"The minimum thickness of a layer to be integrated at any given location.",
		false, min_thickness, "minimum layer thickness");
	cmd.add(min_thickness_arg);

	cmd.parse(argc, argv);

	if (min_thickness_arg.isSet())
	{
		min_thickness = min_thickness_arg.getValue();
		if (min_thickness < 0)
		{
			ERR("Minimum layer thickness must be non-negative value.");
			return EXIT_FAILURE;
		}
	}

	INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str());
	std::unique_ptr<MeshLib::Mesh> const sfc_mesh (FileIO::readMeshFromFile(mesh_arg.getValue()));
	if (!sfc_mesh) {
		ERR("Error reading mesh \"%s\".", mesh_arg.getValue().c_str());
		return EXIT_FAILURE;
	}
	if (sfc_mesh->getDimension() != 2) {
		ERR("Input mesh needs to be a 2D mesh.");
		return EXIT_FAILURE;
	}
	INFO("done.");

	std::vector<std::string> raster_paths;
	if (readRasterPaths(raster_path_arg.getValue(), raster_paths) != 0)
		return EXIT_FAILURE;

	MeshLib::MeshLayerMapper mapper;
	if (auto rasters = FileIO::readRasters(raster_paths))
	{
		if (!mapper.createLayers(*sfc_mesh, *rasters, min_thickness))
			return EXIT_FAILURE;
	}
	else
		return EXIT_FAILURE;

	std::string output_name (mesh_out_arg.getValue());
	if (!BaseLib::hasFileExtension("vtu", output_name))
		output_name.append(".vtu");
	INFO("Writing mesh \"%s\" ... ", output_name.c_str());
	FileIO::writeMeshToFile(*(mapper.getMesh("SubsurfaceMesh").release()), output_name);
	INFO("done.");

	return EXIT_SUCCESS;
}
コード例 #9
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();
}
コード例 #10
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();
}
コード例 #11
0
ファイル: MoveMesh.cpp プロジェクト: TomFischer/ogs
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    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.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::ogs_version +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::ogs_version);
    // 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());

    std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));

    if (!mesh) {
        ERR("Could not read mesh from file '%s'.", fname.c_str());
        return EXIT_FAILURE;
    }

    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 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";
    }

    MeshLib::IO::writeMeshToFile(*mesh, out_fname);

    return EXIT_SUCCESS;
}
コード例 #12
0
int main(int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logo_setup;

    TCLAP::CmdLine cmd(
        "Generates properties for mesh elements of an input mesh deploying a "
        "ASC raster file.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::ogs_version +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::ogs_version);

    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> raster_arg("",
                                            "raster-file",
                                            "the name of the ASC raster file",
                                            true,
                                            "",
                                            "file name");
    cmd.add(raster_arg);

    TCLAP::ValueArg<std::string> property_arg(
        "p",
        "property-name",
        "the name of the property the values are stored for",
        true,
        "",
        "property name as string");
    cmd.add(property_arg);

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

    cmd.parse(argc, argv);

    // read mesh
    std::unique_ptr<MeshLib::Mesh> dest_mesh(
        MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));

    // read raster and if required manipulate it
    auto raster = std::unique_ptr<GeoLib::Raster>(
        FileIO::AsciiRasterInterface::getRasterFromASCFile(
            raster_arg.getValue()));
    GeoLib::RasterHeader header(raster->getHeader());
    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(header.n_rows) + "x" +
                                std::to_string(header.n_cols) + ".asc";
            FileIO::AsciiRasterInterface::writeRasterAsASC(*raster,
                                                           new_raster_fname);
        }
    }

    std::unique_ptr<MeshLib::Mesh> src_mesh(
        MeshLib::RasterToMesh::convert(*raster,
                                       MeshLib::MeshElemType::QUAD,
                                       MeshLib::UseIntensityAs::DATAVECTOR,
                                       property_arg.getValue()));

    // do the interpolation
    MeshLib::Mesh2MeshPropertyInterpolation mesh_interpolation(
        *src_mesh, property_arg.getValue());
    mesh_interpolation.setPropertiesForMesh(*dest_mesh);

    if (!out_mesh_arg.getValue().empty())
    {
        MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
    }

    return EXIT_SUCCESS;
}
コード例 #13
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;
}
コード例 #14
0
ファイル: queryMesh.cpp プロジェクト: endJunction/ogs
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Query mesh information.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', 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 );
    TCLAP::SwitchArg showNodeWithMaxEle_arg("", "show-node-with-max-elements", "show a node having the max number of connected elements", false);
    cmd.add( showNodeWithMaxEle_arg );

    cmd.parse( argc, argv );

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

    // read the mesh file
    auto const mesh = std::unique_ptr<MeshLib::Mesh>(
        MeshLib::IO::readMeshFromFile(filename));
    if (!mesh)
    {
        return EXIT_FAILURE;
    }

    std::vector<std::size_t> selected_node_ids;
    if  (showNodeWithMaxEle_arg.getValue())
    {
        auto itr = std::max_element(mesh->getNodes().begin(), mesh->getNodes().end(),
                     [](MeshLib::Node* i, MeshLib::Node* j) { return i->getNumberOfElements() < j->getNumberOfElements(); });
        if (itr != mesh->getNodes().end())
        {
            MeshLib::Node* node = *itr;
            selected_node_ids.push_back(node->getID());
        }
    }
    selected_node_ids.insert(selected_node_ids.end(), nodeId_arg.getValue().begin(), nodeId_arg.getValue().end());

    auto const materialIds = materialIDs(*mesh);
    for (auto ele_id : eleId_arg.getValue())
    {
        std::stringstream out;
        out << std::scientific
            << std::setprecision(std::numeric_limits<double>::digits10);
        out << "--------------------------------------------------------" << std::endl;
        auto* ele = mesh->getElement(ele_id);
        out << "# Element " << ele->getID() << std::endl;
        out << "Type : " << CellType2String(ele->getCellType()) << std::endl;
        if (materialIds)
        {
            out << "Mat ID : " << (*materialIds)[ele_id] << std::endl;
        }
        out << "Nodes: " << std::endl;
        for (unsigned i = 0; i < ele->getNumberOfNodes(); i++)
        {
            out << ele->getNode(i)->getID() << " " << *ele->getNode(i)
                << std::endl;
        }
        out << "Content: " << ele->getContent() << std::endl;
        out << "Neighbors: ";
        for (unsigned i=0; i<ele->getNumberOfNeighbors(); i++)
        {
            if (ele->getNeighbor(i))
            {
                out << ele->getNeighbor(i)->getID() << " ";
            }
            else
            {
                out << "none ";
            }
        }
        out << std::endl;
        INFO("%s", out.str().c_str());
    }

    for (auto node_id : selected_node_ids)
    {
        std::stringstream out;
        out << std::scientific
            << std::setprecision(std::numeric_limits<double>::digits10);
        out << "--------------------------------------------------------" << std::endl;
        MeshLib::Node const* node = mesh->getNode(node_id);
        out << "# Node " << node->getID() << std::endl;
        out << "Coordinates: " << *node << std::endl;
        out << "Connected elements (" << node->getNumberOfElements() << "): ";
        for (auto ele : node->getElements())
        {
            out << ele->getID() << " ";
        }
        out << std::endl;
        out << "Connected nodes (" << node->getConnectedNodes().size() << "): ";
        for (auto nd : node->getConnectedNodes())
        {
            out << nd->getID() << " ";
        }
        out << std::endl;
        INFO("%s", out.str().c_str());
    }
}
コード例 #15
0
ファイル: UnityPreprocessing.cpp プロジェクト: wenqing/ogs
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Prepares OGS-meshes for use in Unity.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);

    TCLAP::ValueArg<std::string> mesh_arg("i", "input",
        "the file containing the original OGS mesh", true,
        "", "input file name");
    cmd.add(mesh_arg);

    TCLAP::ValueArg<std::string> mesh_out_arg("o", "output",
        "the file name the result will be written to", true,
        "", "output file name");
    cmd.add(mesh_out_arg);

    cmd.parse(argc, argv);

    INFO("Reading mesh '%s' ... ", mesh_arg.getValue().c_str());
    std::unique_ptr<MeshLib::Mesh> mesh {MeshLib::IO::readMeshFromFile(mesh_arg.getValue())};
    if (!mesh)
        return EXIT_FAILURE;
    INFO("done.\n");

    INFO("Checking for line elements...");
    std::array<unsigned, 7> const& n_element_types =
        MeshLib::MeshInformation::getNumberOfElementTypes(*mesh);
    std::unique_ptr<MeshLib::Mesh> result;
    if (n_element_types[0] == 0)
    {
        INFO ("No line elements found.\n");
        result = std::move(mesh);
    }
    else if (n_element_types[0] == mesh->getNumberOfElements())
    {
        INFO ("Keeping line mesh.\n");
        result = std::move(mesh);
    }
    else
    {
        MeshLib::ElementSearch searcher(*mesh);
        std::size_t const n_rem_elems = searcher.searchByElementType(MeshLib::MeshElemType::LINE);
        result.reset(MeshLib::removeElements(*mesh, searcher.getSearchedElementIDs(), "temp mesh"));
        INFO ("%d line elements found and removed.\n", n_rem_elems);
    }

    INFO("Checking for cell-arrays...");
    if (containsCellVecs(*result))
        result.reset(constructMesh(*result));
    else
        INFO("No cell arrays found, keeping mesh structure.\n");

    INFO("Writing mesh '%s' ... ", mesh_out_arg.getValue().c_str());
    MeshLib::IO::VtuInterface writer(result.get(), vtkXMLWriter::Ascii, false);
    writer.writeToFile(mesh_out_arg.getValue());
    INFO("done.");

    return EXIT_SUCCESS;
}
コード例 #16
0
int main (int argc, char* argv[])
{
	ApplicationsLib::LogogSetup logog_setup;

	TCLAP::CmdLine cmd(
		"Creates boundary conditions for mesh nodes along polylines."
		"The documentation is available at https://docs.opengeosys.org/docs/tools/model-preparation/create-boundary-conditions-along-a-polyline",
		' ',
		"0.1");
	TCLAP::ValueArg<bool> gml_arg("", "gml",
		"if switched on write found nodes to file in gml format", false, 0, "bool");
	cmd.add(gml_arg);

	TCLAP::ValueArg<std::string> output_base_fname("o", "output-base-file-name",
		"the base name of the file the output (geometry (gli) and boundary"\
		"condition (bc)) will be written to", true,
		"", "file name");
	cmd.add(output_base_fname);

	TCLAP::ValueArg<std::string> bc_type("t", "type",
		"the process type the boundary condition will be written for "\
		"currently LIQUID_FLOW (primary variable PRESSURE1) and "\
		"GROUNDWATER_FLOW (primary variable HEAD, default) are supported", true,
		"",
		"process type as string (LIQUID_FLOW or GROUNDWATER_FLOW (default))");
	cmd.add(bc_type);

	TCLAP::ValueArg<double> search_length_arg("s", "search-length",
		"The size of the search length. The default value is "
		"std::numeric_limits<double>::epsilon()", false,
		std::numeric_limits<double>::epsilon(), "floating point number");
	cmd.add(search_length_arg);

	TCLAP::ValueArg<std::string> geometry_fname("i", "input-geometry",
		"the name of the file containing the input geometry", true,
		"", "file name");
	cmd.add(geometry_fname);

	TCLAP::ValueArg<std::string> mesh_arg("m", "mesh-file",
		"the name of the file containing the mesh", true,
		"", "file name");
	cmd.add(mesh_arg);

	cmd.parse(argc, argv);

	// *** read mesh
	INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str());
	MeshLib::Mesh * subsurface_mesh(FileIO::readMeshFromFile(mesh_arg.getValue()));
	INFO("done.");
	INFO("Extracting top surface of mesh \"%s\" ... ",
		mesh_arg.getValue().c_str());
	const MathLib::Vector3 dir(0,0,-1);
	double const angle(90);
	std::unique_ptr<MeshLib::Mesh> surface_mesh(
	    MeshLib::MeshSurfaceExtraction::getMeshSurface(*subsurface_mesh, dir,
	                                                   angle));
	INFO("done.");
	delete subsurface_mesh;
	subsurface_mesh = nullptr;

	// *** read geometry
	GeoLib::GEOObjects geometries;
	FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries);

	std::string geo_name;
	{
		std::vector<std::string> geo_names;
		geometries.getGeometryNames(geo_names);
		geo_name = geo_names[0];
	}

	// *** check if the data is usable
	// *** get vector of polylines
	std::vector<GeoLib::Polyline*> const* plys(geometries.getPolylineVec(geo_name));
	if (!plys) {
		ERR("Could not get vector of polylines out of geometry \"%s\".",
			geo_name.c_str());
		return -1;
	}

	MeshGeoToolsLib::SearchLength search_length_strategy;
	if (search_length_arg.isSet()) {
		search_length_strategy =
			MeshGeoToolsLib::SearchLength(search_length_arg.getValue());
	}

	GeoLib::GEOObjects geometry_sets;
	MeshGeoToolsLib::MeshNodeSearcher mesh_searcher(*surface_mesh,
		search_length_strategy);
	for(std::size_t k(0); k<plys->size(); k++) {
		std::vector<std::size_t> ids
			(mesh_searcher.getMeshNodeIDsAlongPolyline(*((*plys)[k])));
		if (ids.empty())
			continue;
		std::string geo_name("Polyline-"+std::to_string(k));
		convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, geo_name,
			geometry_sets);
	}

	// merge all together
	std::vector<std::string> geo_names;
	geometry_sets.getGeometryNames(geo_names);
	if (geo_names.empty()) {
		ERR("Did not find mesh nodes along polylines.");
		return -1;
	}

	std::string merge_name("AllMeshNodesAlongPolylines");
	if (geometry_sets.mergeGeometries(geo_names, merge_name) == 2)
		merge_name = geo_names[0];

	GeoLib::PointVec const* pnt_vec(geometry_sets.getPointVecObj(merge_name));
	std::vector<GeoLib::Point*> const* merged_pnts(pnt_vec->getVector());

	std::vector<GeoLib::Point> pnts_with_id;
	const std::size_t n_merged_pnts(merged_pnts->size());
	for(std::size_t k(0); k<n_merged_pnts; ++k) {
		pnts_with_id.emplace_back(*((*merged_pnts)[k]), k);
	}

	std::sort(pnts_with_id.begin(), pnts_with_id.end(),
		[](GeoLib::Point const& p0, GeoLib::Point const& p1)
			{ return p0 < p1; }
	);

	double const eps (std::numeric_limits<double>::epsilon());
	auto surface_pnts = std::unique_ptr<std::vector<GeoLib::Point*>>(
	    new std::vector<GeoLib::Point*>);
	std::map<std::string, std::size_t> *name_id_map(
		new std::map<std::string, std::size_t>
	);

	// insert first point
	surface_pnts->push_back(
		new GeoLib::Point(pnts_with_id[0], surface_pnts->size()));
	std::string element_name;
	pnt_vec->getNameOfElementByID(0, element_name);
	name_id_map->insert(
		std::pair<std::string, std::size_t>(element_name,0)
	);
	for (std::size_t k(1); k < n_merged_pnts; ++k) {
		const GeoLib::Point& p0 (pnts_with_id[k-1]);
		const GeoLib::Point& p1 (pnts_with_id[k]);
		if (std::abs (p0[0] - p1[0]) > eps || std::abs (p0[1] - p1[1]) > eps) {
			surface_pnts->push_back(new GeoLib::Point(pnts_with_id[k],
				surface_pnts->size()));
			std::string element_name;
			pnt_vec->getNameOfElementByID(k, element_name);
			name_id_map->insert(
				std::pair<std::string, std::size_t>(element_name,
				surface_pnts->size()-1)
			);
		}
	}

	std::string surface_name(BaseLib::dropFileExtension(mesh_arg.getValue())+"-MeshNodesAlongPolylines");
	geometry_sets.addPointVec(std::move(surface_pnts), surface_name, name_id_map, 1e-6);

	// write the BCs and the merged geometry set to file
	std::string const base_fname(
	    BaseLib::dropFileExtension(output_base_fname.getValue()));
	writeBCsAndGeometry(geometry_sets, surface_name, base_fname,
	                    bc_type.getValue(), gml_arg.getValue());
	return 0;
}
コード例 #17
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();
}
コード例 #18
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Creates a new file for material properties and sets the material ids "
        "in the msh-file to 0\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);

    TCLAP::ValueArg<std::string> mesh_arg("m",
                                              "mesh",
                                              "the mesh to open from a file",
                                              false,
                                              "",
                                              "filename for mesh input");
    cmd.add( mesh_arg );

    cmd.parse( argc, argv );

    // read mesh
    std::unique_ptr<MeshLib::Mesh> mesh(
        MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));

    if (!mesh)
    {
        INFO("Could not read mesh from file '%s'.",
             mesh_arg.getValue().c_str());
        return EXIT_FAILURE;
    }

    auto const materialIds = materialIDs(*mesh);
    if (!materialIds)
    {
        OGS_FATAL("Mesh contains no int-property vector named 'MaterialIDs'.");
    }

    std::size_t const n_properties(materialIds->size());
    assert(n_properties != mesh->getNumberOfElements());

    std::string const name =
        BaseLib::extractBaseNameWithoutExtension(mesh_arg.getValue());
    // create file
    std::string const new_matname(name + "_prop");
    std::ofstream out_prop(new_matname.c_str(), std::ios::out);
    if (out_prop.is_open())
    {
        for (std::size_t i = 0; i < n_properties; ++i)
        {
            out_prop << i << "\t" << (*materialIds)[i] << "\n";
        }
        out_prop.close();
    }
    else
    {
        ERR("Could not create property '%s' file.", new_matname.c_str());
        return EXIT_FAILURE;
    }

    mesh->getProperties().removePropertyVector("MaterialIDs");

    std::string const new_mshname(name + "_new.vtu");
    INFO("Writing mesh to file '%s'.", new_mshname.c_str());
    MeshLib::IO::writeMeshToFile(*mesh, new_mshname);

    INFO("New files '%s' and '%s' written.", new_mshname.c_str(),
         new_matname.c_str());

    return EXIT_SUCCESS;
}
コード例 #19
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
            "Creates a new file for material properties and sets the material ids in the msh-file to 0",
            ' ',
            "0.1");

    TCLAP::ValueArg<std::string> mesh_arg("m",
                                              "mesh",
                                              "the mesh to open from a file",
                                              false,
                                              "",
                                              "filename for mesh input");
    cmd.add( mesh_arg );

    cmd.parse( argc, argv );

    // read mesh
    std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
    if (!mesh) {
        INFO("Could not read mesh from file \"%s\".", mesh_arg.getValue().c_str());
        return EXIT_FAILURE;
    }
    if (!mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
    {
        ERR("Mesh contains no int-property vector named \"MaterialIds\".");
        return EXIT_FAILURE;
    }
    auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");

    std::size_t const n_properties(materialIds->size());
    if (n_properties != mesh->getNumberOfElements()) {
        ERR("Size mismatch: number of elements (%u) != number of material "
            "properties (%u).", mesh->getNumberOfElements(), n_properties);
        return EXIT_FAILURE;
    }
    std::string const name = BaseLib::extractBaseNameWithoutExtension(mesh_arg.getValue());
    // create file
    std::string const new_matname(name + "_prop");
    std::ofstream out_prop( new_matname.c_str(), std::ios::out );
    if (out_prop.is_open())
    {
        for (std::size_t i=0; i<n_properties; ++i)
            out_prop << i << "\t" << (*materialIds)[i] << "\n";
        out_prop.close();
    }
    else
    {
        ERR("Could not create property \"%s\" file.", new_matname.c_str());
        return EXIT_FAILURE;
    }

    mesh->getProperties().removePropertyVector("MaterialIDs");

    std::string const new_mshname(name + "_new.vtu");
    INFO("Writing mesh to file \"%s\".", new_mshname.c_str());
    MeshLib::IO::writeMeshToFile(*mesh, new_mshname);

    INFO("New files \"%s\" and \"%s\" written.", new_mshname.c_str(), new_matname.c_str());

    return EXIT_SUCCESS;
}