@@ -554,44 +554,25 @@ void Core::IO::read_design(InputFile& input, const std::string& name,
554554void Core::IO::read_knots (InputFile& input, const std::string& name,
555555 std::shared_ptr<Core::FE::Nurbs::Knotvector>& disknots)
556556{
557- // io to shell
558557 const int myrank = Core::Communication::my_mpi_rank (input.get_comm ());
559-
560558 Teuchos::Time time (" " , true );
561559
562- // only the knotvector section of this discretisation
563- // type is of interest
564560 std::string field;
565- if (name == " fluid" or name == " xfluid" or name == " porofluid" )
566- {
561+ if (name == " fluid" || name == " xfluid" || name == " porofluid" )
567562 field = " FLUID" ;
568- }
569563 else if (name == " structure" )
570- {
571564 field = " STRUCTURE" ;
572- }
573565 else if (name == " ale" )
574- {
575566 field = " ALE" ;
576- }
577567 else if (name == " scatra" )
578- {
579568 field = " TRANSPORT" ;
580- }
581569 else if (name == " thermo" )
582- {
583570 field = " THERMO" ;
584- }
585571 else if (name == " scatra_micro" )
586- {
587572 field = " TRANSPORT2" ;
588- }
589573 else
590- {
591- FOUR_C_THROW (" Unknown discretization name for knotvector input\n " );
592- }
574+ FOUR_C_THROW (" Unknown discretization name for knotvector input." );
593575
594- // another valid section name was found
595576 const std::string sectionname = field + " KNOTVECTORS" ;
596577
597578 if (myrank == 0 )
@@ -600,54 +581,24 @@ void Core::IO::read_knots(InputFile& input, const std::string& name,
600581 fflush (stdout);
601582 }
602583
603- // number of patches to be determined
604584 int npatches = 0 ;
605-
606- // dimension of nurbs patches
607585 int nurbs_dim = 0 ;
608586
609- // --------------------------------------------------------------------
610- // --------------------------------------------------------------------
611- // first, determine number of patches and dimension of nurbs
612- // --------------------------------------------------------------------
613- // --------------------------------------------------------------------
587+ for (const auto & line : input.in_section (sectionname))
614588 {
615- // temporary string
589+ std::string line_str{line.get_as_dat_style_string ()};
590+ std::istringstream file{line_str};
616591 std::string tmp;
617- // loop lines in file
618- for (const auto & line : input.in_section (sectionname))
619- {
620- // count number of patches in knotvector section of
621- // this discretisation
622- {
623- std::string::size_type loc;
624- std::istringstream file{std::string{line.get_as_dat_style_string ()}};
625- file >> tmp;
626-
627- // check for the number of dimensions
628- loc = tmp.rfind (" NURBS_DIMENSION" );
629- if (loc != std::string::npos)
630- {
631- // set number of nurbs dimension
632- std::string str_nurbs_dim;
633- file >> str_nurbs_dim;
634- char * endptr = nullptr ;
635- nurbs_dim = static_cast <int >(strtol (str_nurbs_dim.c_str (), &endptr, 10 ));
592+ file >> tmp;
636593
637- continue ;
638- }
639-
640- // check for a new patch
641- loc = tmp.rfind (" ID" );
642- if (loc != std::string::npos)
643- {
644- // increase number of patches
645- npatches++;
646-
647- continue ;
648- }
649- }
650- } // end loop through file
594+ if (tmp == " NURBS_DIMENSION" )
595+ {
596+ file >> nurbs_dim;
597+ }
598+ else if (tmp == " ID" )
599+ {
600+ npatches++;
601+ }
651602 }
652603
653604 if (myrank == 0 )
@@ -656,203 +607,80 @@ void Core::IO::read_knots(InputFile& input, const std::string& name,
656607 fflush (stdout);
657608 }
658609
659-
660- // --------------------------------------------------------------------
661- // --------------------------------------------------------------------
662- // alloc knotvector object to fill
663- // --------------------------------------------------------------------
664- // --------------------------------------------------------------------
665-
666- // allocate knotvector for this dis
667610 disknots = std::make_shared<Core::FE::Nurbs::Knotvector>(nurbs_dim, npatches);
611+ if (!disknots) FOUR_C_THROW (" disknots should have been allocated before" );
668612
669- // make sure that we have some Knotvector object to fill
670- if (disknots == nullptr )
671- {
672- FOUR_C_THROW (" disknots should have been allocated before" );
673- }
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);
674616
675- // --------------------------------------------------------------------
676- // --------------------------------------------------------------------
677- // finally read knotvector section
678- // --------------------------------------------------------------------
679- // --------------------------------------------------------------------
680- {
681- // this is a pointer to the knots of one patch in one direction
682- // we will read them and put them
683- std::vector<std::shared_ptr<std::vector<double >>> patch_knots (nurbs_dim);
617+ bool read = false ;
618+ int npatch = 0 , actdim = -1 , count_read = 0 ;
684619
685- // temporary string
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};
686624 std::string tmp;
625+ file >> tmp;
687626
688- // start to read something when read is true
689- bool read = false ;
690-
691- // index for number of patch
692- int npatch = 0 ;
693- // index for u/v/w
694- int actdim = -1 ;
695- // ints for the number of knots
696- std::vector<int > n_x_m_x_l (nurbs_dim);
697- // ints for patches degrees
698- std::vector<int > degree (nurbs_dim);
699- // a vector of strings holding the knotvectortypes read
700- std::vector<std::string> knotvectortype (nurbs_dim);
701-
702- // count for sanity check
703- int count_read = 0 ;
704- std::vector<int > count_vals (nurbs_dim);
705-
706- // loop lines in file
707- for (const auto & line : input.in_section (sectionname))
627+ if (tmp == " BEGIN" )
708628 {
709- std::istringstream file{std::string{line.get_as_dat_style_string ()}};
710- file >> tmp;
711-
712- // check for a new patch
713- std::string::size_type loc = tmp.rfind (" BEGIN" );
714- if (loc != std::string::npos)
715- {
716- file >> tmp;
717-
718- // activate reading
719- read = true ;
720-
721- actdim = -1 ;
722-
723- // create vectors for knots in this patch
724- for (int rr = 0 ; rr < nurbs_dim; ++rr)
725- {
726- patch_knots[rr] = std::make_shared<std::vector<double >>();
727- (*(patch_knots[rr])).clear ();
728- }
729-
730- // reset counter for knot values
731- for (int rr = 0 ; rr < nurbs_dim; rr++)
732- {
733- count_vals[rr] = 0 ;
734- }
735-
736- continue ;
737- }
738-
739- // get ID of patch we are currently reading
740- loc = tmp.rfind (" ID" );
741- if (loc != std::string::npos)
742- {
743- std::string str_npatch;
744- file >> str_npatch;
745-
746- char * endptr = nullptr ;
747- npatch = static_cast <int >(strtol (str_npatch.c_str (), &endptr, 10 ));
748- npatch--;
749-
750- continue ;
751- }
752-
753- // get number of knots in the knotvector direction
754- // we are currently reading
755- loc = tmp.rfind (" NUMKNOTS" );
756- if (loc != std::string::npos)
757- {
758- std::string str_numknots;
759- file >> str_numknots;
760-
761- // increase dimesion for knotvector (i.e. next time
762- // we'll fill the following knot vector)
763- actdim++;
764- if (actdim > nurbs_dim)
765- {
766- FOUR_C_THROW (
767- " too many knotvectors, we only need one for each dimension (nurbs_dim = {})\n " ,
768- nurbs_dim);
769- }
770-
771- char * endptr = nullptr ;
772- n_x_m_x_l[actdim] = static_cast <int >(strtol (str_numknots.c_str (), &endptr, 10 ));
773-
774- continue ;
775- }
776-
777- // get number of bspline polinomial associated with
778- // knots in this direction
779- loc = tmp.rfind (" DEGREE" );
780- if (loc != std::string::npos)
781- {
782- std::string str_degree;
783- file >> str_degree;
784-
785- char * endptr = nullptr ;
786- degree[actdim] = static_cast <int >(strtol (str_degree.c_str (), &endptr, 10 ));
787-
788- continue ;
789- }
790-
791- // get type of knotvector (interpolated or periodic)
792- loc = tmp.rfind (" TYPE" );
793- if (loc != std::string::npos)
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)
794654 {
795- std::string type;
796-
797- file >> type;
798- knotvectortype[actdim] = type;
799-
800- continue ;
655+ disknots->set_knots (
656+ rr, npatch, degree[rr], n_x_m_x_l[rr], knotvectortype[rr], patch_knots[rr]);
801657 }
802-
803- // locate end of patch
804- loc = tmp.rfind (" END" );
805- if (loc != std::string::npos)
658+ read = false ;
659+ for (int rr = 0 ; rr < nurbs_dim; ++rr)
806660 {
807- for ( int rr = 0 ; rr < nurbs_dim; ++rr )
661+ if (n_x_m_x_l[rr] != count_vals[rr] )
808662 {
809- disknots-> set_knots (
810- rr, npatch, degree [rr], n_x_m_x_l[rr], knotvectortype[rr], patch_knots[rr] );
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 );
811665 }
812- file >> tmp;
813- // stop reading of knot values if we are here
814- read = false ;
815-
816- for (int rr = 0 ; rr < nurbs_dim; rr++)
817- {
818- if (n_x_m_x_l[rr] != count_vals[rr])
819- {
820- FOUR_C_THROW (" not enough knots read in dim {} ({}!=NUMKNOTS={}), nurbs_dim={}\n " , rr,
821- count_vals[rr], n_x_m_x_l[rr], nurbs_dim);
822- }
823- }
824-
825- // count for sanity check
826- count_read++;
827-
828- continue ;
829666 }
830-
831- // reading of knot values if read is true and no
832- // other keyword was found
833- if (read)
834- {
835- char * endptr = nullptr ;
836-
837- double dv = strtod (tmp.c_str (), &endptr);
838-
839- // count for sanity check
840- count_vals[actdim]++;
841-
842- (*(patch_knots[actdim])).push_back (dv);
843- }
844- } // end loop through file
845-
846- if (count_read != npatches)
667+ count_read++;
668+ }
669+ else if (read)
847670 {
848- FOUR_C_THROW (" wasn't able to read enough patches\n " );
671+ patch_knots[actdim]->push_back (std::stod (tmp));
672+ count_vals[actdim]++;
849673 }
850674 }
851675
676+ if (count_read != npatches)
677+ {
678+ FOUR_C_THROW (" wasn't able to read enough patches\n " );
679+ }
680+
852681 if (myrank == 0 )
853682 {
854683 Core::IO::cout << " in...." << time.totalElapsedTime (true ) << " secs\n " ;
855-
856684 time.reset ();
857685 fflush (stdout);
858686 }
0 commit comments