Skip to content
Snippets Groups Projects
Commit 45e02f76 authored by Elias Pipping's avatar Elias Pipping
Browse files

[Extend] Add tool to generate a uniform grid

This can be used in conjunction with paraview to interpolate data from
an unstructured, fine grid (on which plotting a vector field would
lead to a mess) onto a structured, coarser grid using the 'Resample
with DataSet' filter.
parent 2bf06e90
No related branches found
No related tags found
No related merge requests found
set(SOURCE_FILES
set(SW_SOURCE_FILES
assemblers.cc
enumparser.cc
hdf5/frictionalboundary-writer.cc
......@@ -19,6 +19,12 @@ set(SOURCE_FILES
time-stepping/state.cc
vtk.cc
)
set(UGW_SOURCE_FILES
assemblers.cc # FIXME
sand-wedge-data/mygrid.cc
uniform-grid-writer.cc
vtk.cc
)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/sand-wedge-data")
dune_symlink_to_source_files(FILES
......@@ -28,18 +34,23 @@ dune_symlink_to_source_files(FILES
"sand-wedge-data/parset-3D.cfg")
foreach(_dim 2 3)
set(_target sand-wedge-${_dim}D)
add_executable(${_target} ${SOURCE_FILES})
add_dune_ug_flags(${_target})
set(_sw_target sand-wedge-${_dim}D)
set(_ugw_target uniform-grid-writer-${_dim}D)
add_executable(${_sw_target} ${SW_SOURCE_FILES})
add_executable(${_ugw_target} ${UGW_SOURCE_FILES})
add_dune_ug_flags(${_sw_target})
add_dune_ug_flags(${_ugw_target})
set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(TARGET ${_sw_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
target_link_libraries(${_sw_target} ${Boost_FILESYSTEM_LIBRARY})
target_link_libraries(${_sw_target} ${Boost_SYSTEM_LIBRARY})
target_link_libraries(${_target} ${Boost_FILESYSTEM_LIBRARY})
target_link_libraries(${_target} ${Boost_SYSTEM_LIBRARY})
set_property(TARGET ${_sw_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIR})
target_link_libraries(${_sw_target} ${HDF5_LIBRARIES})
set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIR})
target_link_libraries(${_target} ${HDF5_LIBRARIES})
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS "MY_DIM=${_dim}")
set_property(TARGET ${_sw_target} APPEND PROPERTY COMPILE_DEFINITIONS "MY_DIM=${_dim}")
set_property(TARGET ${_ugw_target} APPEND PROPERTY COMPILE_DEFINITIONS "MY_DIM=${_dim}")
endforeach()
# Mark UG as required
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cmath>
#include <exception>
#include <iostream>
#include <dune/common/exceptions.hh>
// #include <dune/common/parametertree.hh>
// #include <dune/common/parametertreeparser.hh>
#include "assemblers.hh"
#include "diameter.hh"
#include "gridselector.hh"
#include "sand-wedge-data/mygrid.hh"
#include "vtk.hh"
size_t const dims = MY_DIM;
size_t const refinements = 5; // FIXME?
int main(int argc, char *argv[]) {
try {
// Dune::ParameterTree parset;
// Dune::ParameterTreeParser::readOptions(argc, argv, parset);
using GridView = Grid::LeafGridView;
using MyAssembler = MyAssembler<GridView, dims>;
GridConstructor<Grid> gridConstructor;
auto grid = gridConstructor.getGrid();
// refine uniformly!
for (size_t refinement = 0; refinement < refinements; ++refinement)
grid->globalRefine(1);
double minDiameter = std::numeric_limits<double>::infinity();
double maxDiameter = 0.0;
for (auto &&e : elements(grid->leafGridView())) {
auto const geometry = e.geometry();
auto const diam = diameter(geometry);
minDiameter = std::min(minDiameter, diam);
maxDiameter = std::max(maxDiameter, diam);
}
std::cout << "min diameter: " << minDiameter << std::endl;
std::cout << "max diameter: " << maxDiameter << std::endl;
auto const leafView = grid->leafGridView();
auto const leafVertexCount = leafView.size(dims);
std::cout << "Number of DOFs: " << leafVertexCount << std::endl;
MyAssembler const myAssembler(leafView);
MyVTKWriter<typename MyAssembler::VertexBasis,
typename MyAssembler::CellBasis> const
vtkWriter(myAssembler.cellBasis, myAssembler.vertexBasis, "obs");
vtkWriter.writeGrid();
} catch (Dune::Exception &e) {
Dune::derr << "Dune reported error: " << e << std::endl;
} catch (std::exception &e) {
std::cerr << "Standard exception: " << e.what() << std::endl;
}
}
......@@ -46,4 +46,13 @@ void MyVTKWriter<VertexBasis, CellBasis>::write(
writer.write(filename.c_str(), Dune::VTK::appendedraw);
}
template <class VertexBasis, class CellBasis>
void MyVTKWriter<VertexBasis, CellBasis>::writeGrid() const {
Dune::VTKWriter<typename VertexBasis::GridView> writer(
vertexBasis.getGridView());
std::string const filename = prefix + "_grid";
writer.write(filename.c_str(), Dune::VTK::appendedraw);
}
#include "vtk_tmpl.cc"
......@@ -15,5 +15,7 @@ template <class VertexBasis, class CellBasis> class MyVTKWriter {
template <class Vector, class ScalarVector>
void write(size_t record, Vector const &u, Vector const &v,
ScalarVector const &alpha, ScalarVector const &stress) const;
void writeGrid() const;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment