int main(int argc, char **argv)
{
#ifdef HAVE_MPI
    int required_thread_support=MPI_THREAD_SINGLE;
    int provided_thread_support;
    MPI_Init_thread(&argc, &argv, required_thread_support, &provided_thread_support);
    assert(required_thread_support==provided_thread_support);
#endif

#ifdef HAVE_VTK
    Mesh<double> *mesh=VTKTools<double>::import_vtu("../data/box200x200.vtu");
    mesh->create_boundary();

    size_t NNodes = mesh->get_number_nodes();

    // Set up field - use first touch policy
    std::vector<double> psi(NNodes);
    #pragma omp parallel
    {
        #pragma omp for schedule(static)
        for(size_t i=0; i<NNodes; i++)
            psi[i] = pow(mesh->get_coords(i)[0]+0.1, 2) + pow(mesh->get_coords(i)[1]+0.1, 2);
    }

    MetricField<double,2> metric_field(*mesh);

    double tic = get_wtime();
    metric_field.add_field(&(psi[0]), 1.0);
    double toc = get_wtime();

    metric_field.update_mesh();

    std::vector<double> metric(NNodes*3);
    metric_field.get_metric(&(metric[0]));

    double rms[] = {0., 0., 0.};
    for(size_t i=0; i<NNodes; i++) {
        rms[0] += pow(2.0-metric[i*3  ], 2);
        rms[1] += pow(    metric[i*3+1], 2);
        rms[2] += pow(2.0-metric[i*3+2], 2);
    }

    double max_rms = 0;
    for(size_t i=0; i<3; i++) {
        rms[i] = sqrt(rms[i]/NNodes);
        max_rms = std::max(max_rms, rms[i]);
    }

    std::string vtu_filename("../data/test_hessian_2d");
    VTKTools<double>::export_vtu(vtu_filename.c_str(), mesh, &(psi[0]));

    std::cout<<"Hessian :: loop time = "<<toc-tic<<std::endl
             <<"RMS = "<<rms[0]<<", "<<rms[1]<<", "<<rms[2]<<std::endl;
    if(max_rms>0.01)
        std::cout<<"fail\n";
    else
        std::cout<<"pass\n";

    delete mesh;
#else
    std::cerr<<"Pragmatic was configured without VTK"<<std::endl;
#endif

#ifdef HAVE_MPI
    MPI_Finalize();
#endif

    return 0;
}
int main(int argc, char **argv)
{
    int rank=0;
    int required_thread_support=MPI_THREAD_SINGLE;
    int provided_thread_support;
    MPI_Init_thread(&argc, &argv, required_thread_support, &provided_thread_support);
    assert(required_thread_support==provided_thread_support);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    bool verbose = false;
    if(argc>1) {
        verbose = std::string(argv[1])=="-v";
    }

#ifdef HAVE_VTK
    Mesh<double> *mesh=VTKTools<double>::import_vtu("../data/box200x200.vtu");
    mesh->create_boundary();

    MetricField<double,2> metric_field(*mesh);

    size_t NNodes = mesh->get_number_nodes();
    for(size_t i=0; i<NNodes; i++) {
        double m[] = {0.5, 0.0, 0.5};
        metric_field.set_metric(m, i);
    }
    metric_field.update_mesh();

    Coarsen<double,2> adapt(*mesh);

    double L_up = sqrt(2.0);
    double L_low = L_up*0.5;

    double tic = get_wtime();
    adapt.coarsen(L_low, L_up);
    double toc = get_wtime();

    mesh->defragment();

    int nelements = mesh->get_number_elements();

    long double perimeter = mesh->calculate_perimeter();
    long double area = mesh->calculate_area();

    if(verbose) {

        if(rank==0)
            std::cout<<"Coarsen loop time:    "<<toc-tic<<std::endl
                     <<"Number elements:      "<<nelements<<std::endl
                     <<"Perimeter:            "<<perimeter<<std::endl;
    }

    VTKTools<double>::export_vtu("../data/test_coarsen_2d", mesh);

    delete mesh;

    if(rank==0) {
        std::cout<<"Expecting 2 elements: ";
        if(nelements==2)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;

        long double perimeter_exact(4);
        std::cout<<"Expecting perimeter = "<<perimeter_exact<<": "<<perimeter<<" ("<<std::abs(perimeter-perimeter_exact)/std::max(perimeter, perimeter_exact)<<") ";
        if(std::abs(perimeter-perimeter_exact)/std::max(perimeter, perimeter_exact)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;

        long double area_exact = 1;
        std::cout<<"Expecting area = "<<area_exact<<": ";
        if(std::abs(area-area_exact)/std::max(area, area_exact)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;
    }
#else
    std::cerr<<"Pragmatic was configured without VTK"<<std::endl;
#endif

    MPI_Finalize();

    return 0;
}
int main(int argc, char **argv)
{
    int rank=0;
    int required_thread_support=MPI_THREAD_SINGLE;
    int provided_thread_support;
    MPI_Init_thread(&argc, &argv, required_thread_support, &provided_thread_support);
    assert(required_thread_support==provided_thread_support);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    bool verbose = false;
    if(argc>1) {
        verbose = std::string(argv[1])=="-v";
    }

#ifdef HAVE_LIBMESHB
    Mesh<double> *mesh=GMFTools<double>::import_gmf_mesh("../data/cube20x20x20");
    pragmatic_init_light((void*)mesh);

    int * boundary = mesh->get_boundaryTags();

    int nbrElm = mesh->get_number_elements();
    std::vector<int> regions;
    regions.resize(nbrElm);
    for (int iElm = 0; iElm < nbrElm; ++iElm) {
        const int * m = mesh->get_element(iElm);
        double barycenter[3] ={0.};
        for (int i=0; i<4;++i) {
            const double * coords = mesh->get_coords(m[i]);
            for (int j=0; j<3; ++j)
                barycenter[j] += coords[j];
        }
        if (barycenter[0] >= 2) {
            if (barycenter[2] > 2) 
                regions[iElm] = 2;
            else
                regions[iElm] = 3;
        }
        else {
            regions[iElm] = 1;
        }
    }
    mesh->set_regions(&regions[0]);
    mesh->set_internal_boundaries();

    MetricField<double,3> metric_field(*mesh);

    size_t NNodes = mesh->get_number_nodes();
    
    double m[6] = {0.};
    for(size_t i=0; i<NNodes; i++) {
        double lmax = 1/(0.05*0.05);
        m[0] = 5*lmax;
        m[3] = lmax;
        m[5] = 0.1*lmax;
        metric_field.set_metric(m, i);
    }
    metric_field.update_mesh();

    GMFTools<double>::export_gmf_mesh("../data/test_int_regions_3d-initial", mesh);

    pragmatic_adapt(0, 0);

    if(verbose)
        mesh->verify();

    mesh->defragment();

    GMFTools<double>::export_gmf_mesh("../data/test_int_regions_3d", mesh);
#ifdef HAVE_VTK
    VTKTools<double>::export_vtu("../data/test_int_regions_3d", mesh);
#else
    std::cerr<<"Warning: Pragmatic was configured without VTK support"<<std::endl;
#endif

    long double area = mesh->calculate_area();
    long double volume = mesh->calculate_volume();
    long double volume1 = mesh->calculate_volume(1);
    long double volume2 = mesh->calculate_volume(2);
    long double volume3 = mesh->calculate_volume(3);
    if(rank==0) {
        long double ideal_area(9), ideal_volume(1), ideal_volume1(0.5), ideal_volume2(0.25), ideal_volume3(0.25); // the internal boundary is counted twice
        std::cout<<"Expecting total volume == 1:           ";
        if(std::abs(volume-ideal_volume)/std::max(volume, ideal_volume)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;
        std::cout<<"Expecting volume for region 1 == 0.5:  ";
        if(std::abs(volume1-ideal_volume1)/std::max(volume1, ideal_volume1)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;
        std::cout<<"Expecting volume for region 2 == 0.25: ";
        if(std::abs(volume2-ideal_volume2)/std::max(volume2, ideal_volume2)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;
        std::cout<<"Expecting volume for region 3 == 0.25: ";
        if(std::abs(volume3-ideal_volume3)/std::max(volume3, ideal_volume3)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;

        std::cout<<"Expecting area == 9:                   ";
        if(std::abs(area-ideal_area)/std::max(area, ideal_area)<DBL_EPSILON)
            std::cout<<"pass"<<std::endl;
        else
            std::cout<<"fail"<<std::endl;
    }

    delete mesh;
#else
    std::cerr<<"Pragmatic was configured without libmeshb"<<std::endl;
#endif

    MPI_Finalize();

    return 0;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
#ifdef HAVE_MPI
    int required_thread_support=MPI_THREAD_SINGLE;
    int provided_thread_support;
    MPI_Init_thread(&argc, &argv, required_thread_support, &provided_thread_support);
    assert(required_thread_support==provided_thread_support);
#endif

    bool verbose = false;
    if(argc>1) {
        verbose = std::string(argv[1])=="-v";
    }

#ifdef HAVE_VTK
    Mesh<double> *mesh=VTKTools<double>::import_vtu("../data/box10x10x10.vtu");
    mesh->create_boundary();

    MetricField<double,3> metric_field(*mesh);

    size_t NNodes = mesh->get_number_nodes();

    std::vector<double> psi(NNodes);
    for(size_t i=0; i<NNodes; i++)
        psi[i] =
            pow(mesh->get_coords(i)[0], 4) +
            pow(mesh->get_coords(i)[1], 4) +
            pow(mesh->get_coords(i)[2], 4);

    metric_field.add_field(&(psi[0]), 0.001);
    metric_field.update_mesh();

    Refine<double,3> adapt(*mesh);

    double tic = get_wtime();
    for(int i=0; i<2; i++)
        adapt.refine(sqrt(2.0));
    double toc = get_wtime();

    if(verbose)
        mesh->verify();

    mesh->defragment();

    VTKTools<double>::export_vtu("../data/test_refine_3d", mesh);

    double qmean = mesh->get_qmean();
    double qmin = mesh->get_qmin();
    int nelements = mesh->get_number_elements();

    if(verbose)
        std::cout<<"Refine loop time:    "<<toc-tic<<std::endl
                 <<"Number elements:     "<<nelements<<std::endl
                 <<"Quality mean:        "<<qmean<<std::endl
                 <<"Quality min:         "<<qmin<<std::endl;

    long double area = mesh->calculate_area();
    long double volume = mesh->calculate_volume();

    long double ideal_area(6), ideal_volume(1);
    std::cout<<"Checking area == 6: ";
    if(std::abs(area-ideal_area)/std::max(area, ideal_area)<DBL_EPSILON)
        std::cout<<"pass"<<std::endl;
    else
        std::cout<<"fail (area="<<area<<")"<<std::endl;

    std::cout<<"Checking volume == 1: ";
    if(std::abs(volume-ideal_volume)/std::max(volume, ideal_volume)<DBL_EPSILON)
        std::cout<<"pass"<<std::endl;
    else
        std::cout<<"fail (volume="<<volume<<")"<<std::endl;

    delete mesh;
#else
    std::cerr<<"Pragmatic was configured without VTK"<<std::endl;
#endif

#ifdef HAVE_MPI
    MPI_Finalize();
#endif

    return 0;
}