Commit b17cac6a authored by Kirill Terekhov's avatar Kirill Terekhov

Add GridTools

Convert file format of the mesh

Compute difference of the data on same and different grids
parent 0349a30e
......@@ -13,6 +13,9 @@ add_executable(Sector sector.cpp)
add_executable(Sew sew.cpp)
add_executable(Scale scale.cpp)
add_executable(Move move.cpp)
add_executable(Convert convert.cpp)
add_executable(SameMeshDifference difference_same.cpp)
add_executable(MeshDifference difference_map.cpp)
target_link_libraries(FixFaults inmost)
if(USE_MPI)
......@@ -151,3 +154,33 @@ if(USE_MPI)
endif(USE_MPI)
install(TARGETS Move EXPORT inmost-targets RUNTIME DESTINATION bin)
target_link_libraries(Convert inmost)
if(USE_MPI)
message("linking Convert with MPI")
target_link_libraries(Convert ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(Convert PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
install(TARGETS Convert EXPORT inmost-targets RUNTIME DESTINATION bin)
target_link_libraries(SameMeshDifference inmost)
if(USE_MPI)
message("linking SameMeshDifference with MPI")
target_link_libraries(SameMeshDifference ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(SameMeshDifference PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
install(TARGETS SameMeshDifference EXPORT inmost-targets RUNTIME DESTINATION bin)
target_link_libraries(MeshDifference inmost)
if(USE_MPI)
message("linking MeshDifference with MPI")
target_link_libraries(MeshDifference ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(MeshDifference PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
install(TARGETS MeshDifference EXPORT inmost-targets RUNTIME DESTINATION bin)
#include <stdio.h>
#include "inmost.h"
using namespace INMOST;
typedef Storage::real real;
typedef Storage::real_array real_array;
int main(int argc, char ** argv)
{
if( argc < 3 )
{
printf("Usage: %s input_mesh1 [input_mesh2] ... output_format\n",argv[0]);
return -1;
}
std::string output_fmt = argv[argc-1];
std::cout << "Output format: " << output_fmt << std::endl;
for(int k = 1 ; k < argc-1; ++k)
{
Mesh m;
std::string load_file = std::string(argv[k]);
std::string save_file = load_file.substr(0,load_file.find_last_of(".")) + "." + output_fmt;
std::cout << load_file << " -> " << save_file << std::endl;
m.Load(load_file);
m.Save(save_file);
}
return 0;
}
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "inmost.h"
using namespace INMOST;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cout << "Usage: " << argv[0] ;
std::cout << " mesh1 mesh2" << std::endl;
return -1;
}
Mesh m1,m2;
//m1.SetFileOption("VTK_GRID_DIMS","2");
//m2.SetFileOption("VTK_GRID_DIMS","2");
m1.SetFileOption("VERBOSITY","2");
m2.SetFileOption("VERBOSITY","2");
m1.Load(argv[1]);
m2.Load(argv[2]);
Tag volumes_tag = m1.CreateTag("VOLUMES_FOR_NORMS_CALCULATION",DATA_REAL,CELL|FACE|EDGE|NODE,NONE,1);
for(ElementType etype = NODE; etype <= CELL; etype = etype << 1)
{
for(int id = 0; id < m1.LastLocalID(etype); id++)
{
Element c1 = m1.ElementByLocalID(etype,id);
if( c1.isValid() )
{
Storage::real vol = 0;
ElementArray<Cell> cells = c1.getCells();
for(ElementArray<Cell>::iterator it = cells.begin(); it != cells.end(); ++it)
{
vol += it->Volume() / static_cast<Storage::real>(it->nbAdjElements(etype));
}
c1->RealDF(volumes_tag) = vol;
}
}
}
for(Mesh::iteratorTag t = m1.BeginTag(); t != m1.EndTag(); t++)
{
if( *t == m1.CoordsTag() ) continue;
if( t->GetSize() == ENUMUNDEF ) continue;
if( t->GetDataType() != DATA_REAL ) continue;
if( m2.HaveTag(t->GetTagName()) )
{
Tag t2 = m2.GetTag(t->GetTagName());
if( t->GetSize() != t2.GetSize() ) continue;
for(ElementType etype = NODE; etype <= CELL; etype = etype << 1)
{
if( m1.ElementDefined(*t,etype) && m2.ElementDefined(t2,etype) )
{
Storage::real Cnorm = 0, L1norm = 0, L2norm = 0, absval, Lvol = 0, vol;
for(int id = 0; id < m1.LastLocalID(etype); id++)
{
Element c1 = m1.ElementByLocalID(etype,id);
Element c2 = m2.ElementByLocalID(etype,id);
if( c1.isValid() && c2.isValid() )
{
vol = c1->RealDF(volumes_tag);
Storage::real_array arr1 = c1->RealArray(*t);
Storage::real_array arr2 = c2->RealArray(t2);
for(int k = 0; k < (int)arr1.size(); k++)
{
absval = fabs(arr1[k]-arr2[k]);
arr1[k] = absval;
if( Cnorm < absval ) Cnorm = absval;
L1norm += absval*vol;
L2norm += absval*absval*vol;
Lvol += vol;
}
}
}
std::cout << "Data " << t->GetTagName() << " on " << ElementTypeName(etype) << " Cnorm " << Cnorm << " L1norm " << L1norm/Lvol << " L2norm " << sqrt(L2norm/Lvol) << std::endl;
}
}
}
}
m1.DeleteTag(volumes_tag);
m1.Save("diff.gmv");
m1.Save("diff.vtk");
m1.Save("diff.pmf");
return 0;
}
......@@ -18,3 +18,34 @@ unite_faces - Unite faces of the cell that share the same adjacent cell, some ed
mesh_input - general polyhedral grid
mesh_output - output general polyhedral grid with united faces, default grid.vtk
difference_same - Computes difference between the real data on all elements of two similar grids
and writes the grid with the difference. It writes absolute value of difference.
Outputs L_inf, L_1, L_2 norms of the difference.
Similar grids means their grid blocks order should match between each other
Usage:
difference_same mesh_file1 mesh_file2
mesh_file1 - first mesh file
mesh_file2 - second mesh file
difference_map - Computes difference between the real data on cells of two different grids
and writes both grids with the difference. It writes absolute value of difference.
Outputs L_inf, L_1, L_2 norms of the difference.
It will map cells between two grids by checking which cell centers on one grid
fit into which cells on the other and vice verse, resulting in bijective mapping.
Then for each cell on one grid difference between it's value and mean value
of it's mapping is calculated.
Usage:
difference_map mesh_input1 mesh_input2 [mesh_output1] [mesh_output2]
mesh_input1 - first mesh file
mesh_input2 - second mesh file
mesh_output1 - where to write first mesh with the difference, if not specified, writes to mesh1diff.vtk
mesh_output2 - where to write second mesh with the difference, if not specified, writes to mesh2diff.vtk
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment