MOAB: Mesh Oriented datABase  (version 5.4.1)
viscous_cfd.cpp File Reference
#include "TestUtil.hpp"
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include "Mesquite.hpp"
#include "MsqError.hpp"
#include "MeshImpl.hpp"
#include "ViscousCFDTetShapeWrapper.hpp"
#include "MsqVertex.hpp"
+ Include dependency graph for viscous_cfd.cpp:

Go to the source code of this file.

Functions

void help (const char *argv0)
void tet_dihedral_angle_ratios (Mesh &mesh, double &ratio_min, double &ratio_avg, double &ratio_max, MsqError &err)
int main (int argc, char *argv[])
static double da (double dot)

Variables

std::string DEFAULT_INPUT = "unittest/mesquite/3D/vtk/tets/untangled/flat-tet-sphere.vtk"

Function Documentation

static double da ( double  dot) [inline, static]

Definition at line 143 of file viscous_cfd.cpp.

Referenced by v_quad_max_aspect_frobenius(), v_quad_med_aspect_frobenius(), and v_quad_radius_ratio().

{
    return 180 - ( 180 / M_PI ) * acos( dot );
}
void help ( const char *  argv0)

Definition at line 65 of file viscous_cfd.cpp.

References DEFAULT_INPUT.

{
    std::cerr << "Usage: " << argv0 << " [<input_file>] [<output_file>]" << std::endl
              << "  default input file is: " << DEFAULT_INPUT << std::endl
              << "  defualt is no output file" << std::endl
              << "  Warning: input mesh is assumed to lie in Z=5 plane" << std::endl;
    exit( 1 );
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 78 of file viscous_cfd.cpp.

References DEFAULT_INPUT, help(), input_file, mesh, MBMesquite::MeshImpl::read_vtk(), MBMesquite::IQInterface::run_instructions(), tet_dihedral_angle_ratios(), and MBMesquite::MeshImpl::write_vtk().

{
    const char* input_file  = DEFAULT_INPUT.c_str();
    const char* output_file = NULL;
    switch( argc )
    {
        default:
            help( argv[0] );
        case 3:
            if( !strcmp( argv[2], "-h" ) ) help( argv[0] );
            output_file = argv[2];
        case 2:
            if( !strcmp( argv[1], "-h" ) ) help( argv[0] );
            input_file = argv[1];
        case 1:;
    }

    /* Read a VTK Mesh file */
    MsqPrintError err( cout );
    MBMesquite::MeshImpl mesh;
    mesh.read_vtk( input_file, err );
    if( err )
    {
        std::cerr << input_file << ": file read failed" << endl;
        return 1;
    }

    double min_ini, avg_ini, max_ini;
    tet_dihedral_angle_ratios( mesh, min_ini, avg_ini, max_ini, err );

    /* Run optimizer */
    ViscousCFDTetShapeWrapper smoother( 1e-2 );
    smoother.run_instructions( &mesh, err );
    if( err ) return 1;

    double min_fin, avg_fin, max_fin;
    tet_dihedral_angle_ratios( mesh, min_fin, avg_fin, max_fin, err );

    cout << "\tMinimum \tAverage \tMaximum " << endl
         << "Init\t" << min_ini << '\t' << avg_ini << '\t' << max_ini << endl
         << "Fini\t" << min_fin << '\t' << avg_fin << '\t' << max_fin << endl;

    if( output_file )
    {
        mesh.write_vtk( output_file, err );
        if( err )
        {
            std::cerr << output_file << ": file write failed" << endl;
            return 1;
        }
        else
        {
            std::cout << "Wrote file: " << output_file << endl;
        }
    }

    if( min_ini > min_fin || avg_ini > avg_fin || max_ini > max_fin )
    {
        std::cerr << "Dihedral handle ratio decreased" << endl;
        return 1;
    }

    return 0;
}
void tet_dihedral_angle_ratios ( Mesh mesh,
double &  ratio_min,
double &  ratio_avg,
double &  ratio_max,
MsqError err 
)

Definition at line 148 of file viscous_cfd.cpp.

References MBMesquite::arrptr(), MBMesquite::da(), MBMesquite::Mesh::elements_get_attached_vertices(), MBMesquite::Mesh::elements_get_topologies(), MBMesquite::Mesh::get_all_elements(), MBMesquite::TETRAHEDRON, and MBMesquite::Mesh::vertices_get_coordinates().

Referenced by main().

{
    std::vector< Mesh::VertexHandle > verts;
    std::vector< Mesh::ElementHandle > tets;
    std::vector< MsqVertex > coords( 4 );
    std::vector< size_t > junk;
    mesh.get_all_elements( tets, err );

    ratio_min    = HUGE_VAL;
    ratio_max    = -HUGE_VAL;
    ratio_avg    = 0;
    size_t count = 0;

    for( std::vector< Mesh::ElementHandle >::iterator i = tets.begin(); i != tets.end(); ++i )
    {

        Mesh::ElementHandle e = *i;
        EntityTopology type;
        mesh.elements_get_topologies( &e, &type, 1, err );
        assert( !err );
        if( type != TETRAHEDRON ) continue;

        verts.clear();
        mesh.elements_get_attached_vertices( &e, 1, verts, junk, err );
        assert( !err );
        assert( verts.size() == 4 );
        mesh.vertices_get_coordinates( arrptr( verts ), arrptr( coords ), 4, err );
        assert( !err );

        Vector3D v01 = coords[1] - coords[0];
        Vector3D v02 = coords[2] - coords[0];
        Vector3D v31 = coords[1] - coords[3];
        Vector3D v32 = coords[2] - coords[3];

        Vector3D n012 = ~( v02 * v01 );
        Vector3D n013 = ~( v31 * v01 );
        Vector3D n023 = ~( v02 * v32 );
        Vector3D n123 = ~( v31 * v32 );

        double ds[] = { da( n012 % n013 ), da( n012 % n123 ), da( n012 % n023 ),
                        da( n013 % n023 ), da( n013 % n123 ), da( n023 % n123 ) };

        double ratio = *std::min_element( ds, ds + 6 ) / *std::max_element( ds, ds + 6 );
        if( ratio < ratio_min ) ratio_min = ratio;
        if( ratio > ratio_max ) ratio_max = ratio;
        ratio_avg += ratio;
        count++;
    }

    if( count ) ratio_avg /= count;
}

Variable Documentation

std::string DEFAULT_INPUT = "unittest/mesquite/3D/vtk/tets/untangled/flat-tet-sphere.vtk"

Definition at line 63 of file viscous_cfd.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines