Skip to content

Commit 648a3db

Browse files
authored
Merge pull request #364 from asartori86/parsed_grid_1-3
Instantiate ParsedGridGenerator<1,3>
2 parents 01d0db3 + 4f00c67 commit 648a3db

3 files changed

Lines changed: 152 additions & 13 deletions

File tree

source/parsed_grid_generator.cc

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,63 @@ struct PGGHelper
595595
}
596596
}
597597

598+
static void
599+
create_grid(ParsedGridGenerator<1, 3> *p,
600+
Triangulation<1,3> &tria)
601+
{
602+
if (p->grid_name == "rectangle")
603+
{
604+
Tensor<1,1> initializer1;
605+
Tensor<1,1> initializer2;
606+
for (unsigned int i=0; i<1; ++i)
607+
{
608+
initializer1[i]=p->point_option_one(i);
609+
initializer2[i]=p->point_option_two(i);
610+
}
611+
Point<1> p1(initializer1);
612+
Point<1> p2(initializer2);
613+
614+
GridGenerator::subdivided_hyper_rectangle (tria,
615+
p->un_int_vec_option_one,
616+
p2,
617+
p1,
618+
p->colorize);
619+
}
620+
else if (p->grid_name == "file")
621+
{
622+
GridIn<1, 3> gi;
623+
gi.attach_triangulation(tria);
624+
625+
std::ifstream in(p->input_grid_file_name.c_str());
626+
AssertThrow(in, ExcIO());
627+
628+
std::string ext = extension(p->input_grid_file_name);
629+
if (ext == "vtk")
630+
gi.read_vtk(in);
631+
else if (ext == "msh")
632+
gi.read_msh(in);
633+
else if (ext == "ucd" || ext == "inp")
634+
gi.read_ucd(in);
635+
else if (ext == "unv")
636+
gi.read_unv(in);
637+
else if (ext == "ar")
638+
{
639+
boost::archive::text_iarchive ia(in);
640+
tria.load(ia, 0);
641+
}
642+
else if (ext == "bin")
643+
{
644+
boost::archive::binary_iarchive ia(in);
645+
tria.load(ia, 0);
646+
}
647+
else
648+
Assert(false, ExcNotImplemented());
649+
}
650+
else
651+
AssertThrow(false, ExcMessage("Not implemented: " + p->grid_name));
652+
653+
}
654+
598655
/**
599656
* This function is used to generate grids when spacedim = dim = 3.
600657
*/
@@ -886,25 +943,34 @@ void ParsedGridGenerator<dim, spacedim>::create(Triangulation<dim,spacedim> &tri
886943
Assert(grid_name != "", ExcNotInitialized());
887944
PGGHelper::create_grid( this, tria);
888945

889-
parse_manifold_descriptors(optional_manifold_descriptors);
946+
if (!(dim==1 && spacedim==3))
947+
{
948+
parse_manifold_descriptors(optional_manifold_descriptors);
890949

891-
if (copy_boundary_to_manifold_ids || create_default_manifolds)
892-
GridTools::copy_boundary_to_manifold_id(tria);
950+
if (copy_boundary_to_manifold_ids || create_default_manifolds)
951+
GridTools::copy_boundary_to_manifold_id(tria);
893952

894-
if (copy_material_to_manifold_ids)
895-
GridTools::copy_material_to_manifold_id(tria);
953+
if (copy_material_to_manifold_ids)
954+
GridTools::copy_material_to_manifold_id(tria);
896955

897-
if (create_default_manifolds)
898-
parse_manifold_descriptors(default_manifold_descriptors);
956+
if (create_default_manifolds)
957+
parse_manifold_descriptors(default_manifold_descriptors);
899958

900-
// Now attach the manifold descriptors
901-
for (auto m: manifold_descriptors)
902-
{
903-
tria.set_manifold(m.first, *m.second);
959+
// Now attach the manifold descriptors
960+
for (auto m: manifold_descriptors)
961+
{
962+
tria.set_manifold(m.first, *m.second);
963+
}
904964
}
905965

906966
}
907967

968+
template<>
969+
void
970+
ParsedGridGenerator<1, 3>::parse_manifold_descriptors(const std::string &)
971+
{
972+
Assert(false,ExcNotImplemented());
973+
}
908974

909975
template <int dim, int spacedim>
910976
void
@@ -923,7 +989,6 @@ ParsedGridGenerator<dim, spacedim>::parse_manifold_descriptors(const std::string
923989
}
924990

925991

926-
927992
template <int dim, int spacedim>
928993
void ParsedGridGenerator<dim, spacedim>::write(const Triangulation<dim,spacedim> &tria,
929994
const std::string &filename) const
@@ -1019,7 +1084,7 @@ D2K_NAMESPACE_CLOSE
10191084

10201085
template class deal2lkit::ParsedGridGenerator<1,1>;
10211086
template class deal2lkit::ParsedGridGenerator<1,2>;
1022-
//template class deal2lkit::ParsedGridGenerator<1,3>;
1087+
template class deal2lkit::ParsedGridGenerator<1,3>;
10231088
template class deal2lkit::ParsedGridGenerator<2,2>;
10241089
template class deal2lkit::ParsedGridGenerator<2,3>;
10251090
template class deal2lkit::ParsedGridGenerator<3,3>;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//-----------------------------------------------------------
2+
//
3+
// Copyright (C) 2017 by the deal2lkit authors
4+
//
5+
// This file is part of the deal2lkit library.
6+
//
7+
// The deal2lkit library is free software; you can use it, redistribute
8+
// it, and/or modify it under the terms of the GNU Lesser General
9+
// Public License as published by the Free Software Foundation; either
10+
// version 2.1 of the License, or (at your option) any later version.
11+
// The full text of the license can be found in the file LICENSE at
12+
// the top level of the deal2lkit distribution.
13+
//
14+
//-----------------------------------------------------------
15+
16+
17+
#include "../tests.h"
18+
#include <deal2lkit/utilities.h>
19+
#include <deal2lkit/parsed_grid_generator.h>
20+
21+
#include <deal.II/grid/grid_out.h>
22+
#include <deal.II/base/utilities.h>
23+
24+
25+
using namespace deal2lkit;
26+
27+
template<int dim, int spacedim>
28+
void test(ParsedGridGenerator<dim, spacedim> &pgg)
29+
{
30+
Triangulation<dim, spacedim> *tria = pgg.serial();
31+
GridOut go;
32+
go.write_msh(*tria, deallog.get_file_stream());
33+
delete tria;
34+
}
35+
36+
37+
int main ()
38+
{
39+
initlog();
40+
ParsedGridGenerator<1,3> a("Flagellum", "rectangle");
41+
ParameterAcceptor::initialize();
42+
ParameterAcceptor::prm.log_parameters(deallog);
43+
44+
deallog <<"flagellum"<<std::endl;
45+
test(a);
46+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
DEAL:parameters:Flagellum::Colorize: false
3+
DEAL:parameters:Flagellum::Copy boundary to manifold ids: false
4+
DEAL:parameters:Flagellum::Copy material to manifold ids: false
5+
DEAL:parameters:Flagellum::Create default manifolds: true
6+
DEAL:parameters:Flagellum::Grid to generate: rectangle
7+
DEAL:parameters:Flagellum::Input grid file name:
8+
DEAL:parameters:Flagellum::Manifold descriptors:
9+
DEAL:parameters:Flagellum::Mesh smoothing alogrithm: none
10+
DEAL:parameters:Flagellum::Optional Point<spacedim> 1: 0,0,0
11+
DEAL:parameters:Flagellum::Optional Point<spacedim> 2: 1,0,0
12+
DEAL:parameters:Flagellum::Optional double 1: 1.0
13+
DEAL:parameters:Flagellum::Optional double 2: 0.5
14+
DEAL:parameters:Flagellum::Optional double 3: 1.5
15+
DEAL:parameters:Flagellum::Optional int 1: 1
16+
DEAL:parameters:Flagellum::Optional int 2: 2
17+
DEAL:parameters:Flagellum::Optional vector of dim int: 1
18+
DEAL:parameters:Flagellum::Output grid file name:
19+
DEAL::flagellum
20+
$NOD
21+
2
22+
1 0.00000 0.00000 0.00000
23+
2 1.00000 0.00000 0.00000
24+
$ENDNOD
25+
$ELM
26+
1
27+
1 1 0 0 2 1 2
28+
$ENDELM

0 commit comments

Comments
 (0)