Skip to content

Commit

Permalink
Merge pull request #364 from asartori86/parsed_grid_1-3
Browse files Browse the repository at this point in the history
Instantiate ParsedGridGenerator<1,3>
  • Loading branch information
luca-heltai authored Oct 23, 2017
2 parents 01d0db3 + 4f00c67 commit 648a3db
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 13 deletions.
91 changes: 78 additions & 13 deletions source/parsed_grid_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,63 @@ struct PGGHelper
}
}

static void
create_grid(ParsedGridGenerator<1, 3> *p,
Triangulation<1,3> &tria)
{
if (p->grid_name == "rectangle")
{
Tensor<1,1> initializer1;
Tensor<1,1> initializer2;
for (unsigned int i=0; i<1; ++i)
{
initializer1[i]=p->point_option_one(i);
initializer2[i]=p->point_option_two(i);
}
Point<1> p1(initializer1);
Point<1> p2(initializer2);

GridGenerator::subdivided_hyper_rectangle (tria,
p->un_int_vec_option_one,
p2,
p1,
p->colorize);
}
else if (p->grid_name == "file")
{
GridIn<1, 3> gi;
gi.attach_triangulation(tria);

std::ifstream in(p->input_grid_file_name.c_str());
AssertThrow(in, ExcIO());

std::string ext = extension(p->input_grid_file_name);
if (ext == "vtk")
gi.read_vtk(in);
else if (ext == "msh")
gi.read_msh(in);
else if (ext == "ucd" || ext == "inp")
gi.read_ucd(in);
else if (ext == "unv")
gi.read_unv(in);
else if (ext == "ar")
{
boost::archive::text_iarchive ia(in);
tria.load(ia, 0);
}
else if (ext == "bin")
{
boost::archive::binary_iarchive ia(in);
tria.load(ia, 0);
}
else
Assert(false, ExcNotImplemented());
}
else
AssertThrow(false, ExcMessage("Not implemented: " + p->grid_name));

}

/**
* This function is used to generate grids when spacedim = dim = 3.
*/
Expand Down Expand Up @@ -886,25 +943,34 @@ void ParsedGridGenerator<dim, spacedim>::create(Triangulation<dim,spacedim> &tri
Assert(grid_name != "", ExcNotInitialized());
PGGHelper::create_grid( this, tria);

parse_manifold_descriptors(optional_manifold_descriptors);
if (!(dim==1 && spacedim==3))
{
parse_manifold_descriptors(optional_manifold_descriptors);

if (copy_boundary_to_manifold_ids || create_default_manifolds)
GridTools::copy_boundary_to_manifold_id(tria);
if (copy_boundary_to_manifold_ids || create_default_manifolds)
GridTools::copy_boundary_to_manifold_id(tria);

if (copy_material_to_manifold_ids)
GridTools::copy_material_to_manifold_id(tria);
if (copy_material_to_manifold_ids)
GridTools::copy_material_to_manifold_id(tria);

if (create_default_manifolds)
parse_manifold_descriptors(default_manifold_descriptors);
if (create_default_manifolds)
parse_manifold_descriptors(default_manifold_descriptors);

// Now attach the manifold descriptors
for (auto m: manifold_descriptors)
{
tria.set_manifold(m.first, *m.second);
// Now attach the manifold descriptors
for (auto m: manifold_descriptors)
{
tria.set_manifold(m.first, *m.second);
}
}

}

template<>
void
ParsedGridGenerator<1, 3>::parse_manifold_descriptors(const std::string &)
{
Assert(false,ExcNotImplemented());
}

template <int dim, int spacedim>
void
Expand All @@ -923,7 +989,6 @@ ParsedGridGenerator<dim, spacedim>::parse_manifold_descriptors(const std::string
}



template <int dim, int spacedim>
void ParsedGridGenerator<dim, spacedim>::write(const Triangulation<dim,spacedim> &tria,
const std::string &filename) const
Expand Down Expand Up @@ -1019,7 +1084,7 @@ D2K_NAMESPACE_CLOSE

template class deal2lkit::ParsedGridGenerator<1,1>;
template class deal2lkit::ParsedGridGenerator<1,2>;
//template class deal2lkit::ParsedGridGenerator<1,3>;
template class deal2lkit::ParsedGridGenerator<1,3>;
template class deal2lkit::ParsedGridGenerator<2,2>;
template class deal2lkit::ParsedGridGenerator<2,3>;
template class deal2lkit::ParsedGridGenerator<3,3>;
Expand Down
46 changes: 46 additions & 0 deletions tests/parsed_grid_generator/parsed_grid_generator_13.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//-----------------------------------------------------------
//
// Copyright (C) 2017 by the deal2lkit authors
//
// This file is part of the deal2lkit library.
//
// The deal2lkit library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal2lkit distribution.
//
//-----------------------------------------------------------


#include "../tests.h"
#include <deal2lkit/utilities.h>
#include <deal2lkit/parsed_grid_generator.h>

#include <deal.II/grid/grid_out.h>
#include <deal.II/base/utilities.h>


using namespace deal2lkit;

template<int dim, int spacedim>
void test(ParsedGridGenerator<dim, spacedim> &pgg)
{
Triangulation<dim, spacedim> *tria = pgg.serial();
GridOut go;
go.write_msh(*tria, deallog.get_file_stream());
delete tria;
}


int main ()
{
initlog();
ParsedGridGenerator<1,3> a("Flagellum", "rectangle");
ParameterAcceptor::initialize();
ParameterAcceptor::prm.log_parameters(deallog);

deallog <<"flagellum"<<std::endl;
test(a);
}
28 changes: 28 additions & 0 deletions tests/parsed_grid_generator/parsed_grid_generator_13.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

DEAL:parameters:Flagellum::Colorize: false
DEAL:parameters:Flagellum::Copy boundary to manifold ids: false
DEAL:parameters:Flagellum::Copy material to manifold ids: false
DEAL:parameters:Flagellum::Create default manifolds: true
DEAL:parameters:Flagellum::Grid to generate: rectangle
DEAL:parameters:Flagellum::Input grid file name:
DEAL:parameters:Flagellum::Manifold descriptors:
DEAL:parameters:Flagellum::Mesh smoothing alogrithm: none
DEAL:parameters:Flagellum::Optional Point<spacedim> 1: 0,0,0
DEAL:parameters:Flagellum::Optional Point<spacedim> 2: 1,0,0
DEAL:parameters:Flagellum::Optional double 1: 1.0
DEAL:parameters:Flagellum::Optional double 2: 0.5
DEAL:parameters:Flagellum::Optional double 3: 1.5
DEAL:parameters:Flagellum::Optional int 1: 1
DEAL:parameters:Flagellum::Optional int 2: 2
DEAL:parameters:Flagellum::Optional vector of dim int: 1
DEAL:parameters:Flagellum::Output grid file name:
DEAL::flagellum
$NOD
2
1 0.00000 0.00000 0.00000
2 1.00000 0.00000 0.00000
$ENDNOD
$ELM
1
1 1 0 0 2 1 2
$ENDELM

0 comments on commit 648a3db

Please # to comment.