Skip to content

Commit 4187b5b

Browse files
committed
Read NURBS knot vectors on rank 0 only
1 parent 33e1c6b commit 4187b5b

File tree

1 file changed

+84
-78
lines changed

1 file changed

+84
-78
lines changed

src/core/io/src/4C_io_input_file_utils.cpp

Lines changed: 84 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -579,111 +579,117 @@ void Core::IO::read_knots(InputFile& input, const std::string& name,
579579
{
580580
Core::IO::cout << "Reading knot vectors for " << name << " discretization :\n";
581581
fflush(stdout);
582-
}
583-
584-
int npatches = 0;
585-
int nurbs_dim = 0;
586582

587-
for (const auto& line : input.in_section(sectionname))
588-
{
589-
std::string line_str{line.get_as_dat_style_string()};
590-
std::istringstream file{line_str};
591-
std::string tmp;
592-
file >> tmp;
583+
int npatches = 0;
584+
int nurbs_dim = 0;
593585

594-
if (tmp == "NURBS_DIMENSION")
586+
for (const auto& line : input.in_section_rank_0_only(sectionname))
595587
{
596-
file >> nurbs_dim;
597-
}
598-
else if (tmp == "ID")
599-
{
600-
npatches++;
588+
std::string line_str{line.get_as_dat_style_string()};
589+
std::istringstream file{line_str};
590+
std::string tmp;
591+
file >> tmp;
592+
593+
std::cout << "Token: " << tmp << std::endl;
594+
595+
if (tmp == "NURBS_DIMENSION")
596+
{
597+
file >> nurbs_dim;
598+
}
599+
else if (tmp == "ID")
600+
{
601+
npatches++;
602+
}
601603
}
602-
}
603604

604-
if (myrank == 0)
605-
{
606605
printf(" %8d patches", npatches);
607606
fflush(stdout);
608-
}
609607

610-
disknots = std::make_shared<Core::FE::Nurbs::Knotvector>(nurbs_dim, npatches);
611-
if (!disknots) FOUR_C_THROW("disknots should have been allocated before");
608+
disknots = std::make_shared<Core::FE::Nurbs::Knotvector>(nurbs_dim, npatches);
612609

613-
std::vector<std::shared_ptr<std::vector<double>>> patch_knots(nurbs_dim);
614-
std::vector<int> n_x_m_x_l(nurbs_dim), degree(nurbs_dim), count_vals(nurbs_dim);
615-
std::vector<std::string> knotvectortype(nurbs_dim);
610+
std::vector<std::shared_ptr<std::vector<double>>> patch_knots(nurbs_dim);
611+
std::vector<int> n_x_m_x_l(nurbs_dim), degree(nurbs_dim), count_vals(nurbs_dim);
612+
std::vector<std::string> knotvectortype(nurbs_dim);
616613

617-
bool read = false;
618-
int npatch = 0, actdim = -1, count_read = 0;
619-
620-
for (const auto& line : input.in_section(sectionname))
621-
{
622-
std::string line_str{line.get_as_dat_style_string()};
623-
std::istringstream file{line_str};
624-
std::string tmp;
625-
file >> tmp;
614+
bool read = false;
615+
int npatch = 0, actdim = -1, count_read = 0;
626616

627-
if (tmp == "BEGIN")
617+
for (const auto& line : input.in_section_rank_0_only(sectionname))
628618
{
629-
read = true;
630-
actdim = -1;
631-
for (auto& knots : patch_knots) knots = std::make_shared<std::vector<double>>();
632-
std::fill(count_vals.begin(), count_vals.end(), 0);
633-
}
634-
else if (tmp == "ID")
635-
{
636-
file >> npatch;
637-
npatch--;
638-
}
639-
else if (tmp == "NUMKNOTS")
640-
{
641-
file >> n_x_m_x_l[++actdim];
642-
}
643-
else if (tmp == "DEGREE")
644-
{
645-
file >> degree[actdim];
646-
}
647-
else if (tmp == "TYPE")
648-
{
649-
file >> knotvectortype[actdim];
650-
}
651-
else if (tmp == "END")
652-
{
653-
for (int rr = 0; rr < nurbs_dim; ++rr)
619+
std::string line_str{line.get_as_dat_style_string()};
620+
std::istringstream file{line_str};
621+
std::string tmp;
622+
file >> tmp;
623+
624+
if (tmp == "BEGIN")
625+
{
626+
read = true;
627+
actdim = -1;
628+
for (auto& knots : patch_knots) knots = std::make_shared<std::vector<double>>();
629+
std::fill(count_vals.begin(), count_vals.end(), 0);
630+
}
631+
else if (tmp == "ID")
654632
{
655-
disknots->set_knots(
656-
rr, npatch, degree[rr], n_x_m_x_l[rr], knotvectortype[rr], patch_knots[rr]);
633+
file >> npatch;
634+
npatch--;
657635
}
658-
read = false;
659-
for (int rr = 0; rr < nurbs_dim; ++rr)
636+
else if (tmp == "NUMKNOTS")
660637
{
661-
if (n_x_m_x_l[rr] != count_vals[rr])
638+
file >> n_x_m_x_l[++actdim];
639+
}
640+
else if (tmp == "DEGREE")
641+
{
642+
file >> degree[actdim];
643+
}
644+
else if (tmp == "TYPE")
645+
{
646+
file >> knotvectortype[actdim];
647+
}
648+
else if (tmp == "END")
649+
{
650+
for (int rr = 0; rr < nurbs_dim; ++rr)
662651
{
663-
FOUR_C_THROW("not enough knots read in dim {} ({}!=NUMKNOTS={}), nurbs_dim={}\n", rr,
664-
count_vals[rr], n_x_m_x_l[rr], nurbs_dim);
652+
disknots->set_knots(
653+
rr, npatch, degree[rr], n_x_m_x_l[rr], knotvectortype[rr], patch_knots[rr]);
665654
}
655+
read = false;
656+
for (int rr = 0; rr < nurbs_dim; ++rr)
657+
{
658+
if (n_x_m_x_l[rr] != count_vals[rr])
659+
{
660+
FOUR_C_THROW("not enough knots read in dim {} ({}!=NUMKNOTS={}), nurbs_dim={}\n", rr,
661+
count_vals[rr], n_x_m_x_l[rr], nurbs_dim);
662+
}
663+
}
664+
count_read++;
665+
}
666+
else if (read)
667+
{
668+
patch_knots[actdim]->push_back(std::stod(tmp));
669+
count_vals[actdim]++;
666670
}
667-
count_read++;
668671
}
669-
else if (read)
672+
673+
if (count_read != npatches)
670674
{
671-
patch_knots[actdim]->push_back(std::stod(tmp));
672-
count_vals[actdim]++;
675+
FOUR_C_THROW("wasn't able to read enough patches\n");
673676
}
674-
}
675677

676-
if (count_read != npatches)
677-
{
678-
FOUR_C_THROW("wasn't able to read enough patches\n");
679-
}
678+
std::cout << "Rank 0 sending out knot vectors to all other processors" << std::endl;
679+
// Now we have to broadcast the knot vectors to all other processors
680+
Core::Communication::broadcast(*disknots, 0, input.get_comm());
680681

681-
if (myrank == 0)
682-
{
683682
Core::IO::cout << " in...." << time.totalElapsedTime(true) << " secs\n";
684683
time.reset();
685684
fflush(stdout);
686685
}
686+
else
687+
{
688+
std::cout << "Rank " << myrank << " waiting for knot vectors from rank 0" << std::endl;
689+
// All other ranks receive the knot vectors from rank 0.
690+
disknots = std::make_shared<Core::FE::Nurbs::Knotvector>();
691+
Core::Communication::broadcast(*disknots, 0, input.get_comm());
692+
}
687693
}
688694

689695
FOUR_C_NAMESPACE_CLOSE

0 commit comments

Comments
 (0)