<commit_before>/** @file gsBoundaryConditions.hpp

    @brief Implementation file for the gsBoundaryConditions class.

    This file is part of the G+Smo library.

    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

    Author(s): <NAME>
*/

#include <gsIO/gsXml.h>
#include <gsCore/gsFunctionExpr.h>
#include <gsUtils/gsSortedVector.h>

namespace gismo
{

namespace internal
{

/// @brief I/O for boundary conditions from file
template<class T>
class gsXml< gsBoundaryConditions<T> >
{
private:
    gsXml() { }
    typedef gsBoundaryConditions<T> Object;
public:
    GSXML_COMMON_FUNCTIONS(Object);
    static std::string tag  () { return "boundaryConditions"; }
    static std::string type () { return ""; }

    GSXML_GET_POINTER(Object);

    static void get_into(gsXmlNode * node, Object & result)
    {
        GISMO_ASSERT(!strcmp(node->name(), tag().c_str()),
                "Something went wrong. Expected tag "<< tag());

        //gsXmlNode * tmp = node->first_node("patches");
        //GISMO_ASSERT(tmp, "No pathes tag");
//
//        std::istringstream str;
//        str.str( tmp->value() );
//        // Resolve ID numbers
//        std::map<int,int> ids;
//        if ( ! strcmp( tmp->first_attribute("type")->value(), "id_range") )
//        {
//            int first, last;
//            gsGetInt(str, first);
//            gsGetInt(str, last);
//            for ( int i = first; i<=last; ++i )
//                ids[i] = i - first;
//        }
//        else if ( ! strcmp( tmp->first_attribute("type")->value(),"id_index") )
//        {
//            int c = 0;
//            for (int pindex; gsGetInt(str, pindex);)
//                ids[pindex] = c++;
//        }
//        else
//        {
//            gsWarn<<"Incomplete tag \"patch\" in boundaryConditions.\n";
//        }
        std::istringstream str;
        std::map<int, int> ids;

        // Read function inventory
        int count = countByTag("Function", node);
        std::vector<typename gsFunctionExpr<T>::Ptr> func(count); // todo: gsFunction::Ptr
        for (gsXmlNode * child = node->first_node("Function"); child; child =
                child->next_sibling("Function"))
        {
            const int i = atoi(child->first_attribute("index")->value());
            func[i] = memory::make_shared(new gsFunctionExpr<T>);
            getFunctionFromXml(child, *func[i]);
        }

        // Read boundary conditions
        std::vector<patchSide> boundaries;
        for (gsXmlNode * child = node->first_node("bc"); child;
                child = child->next_sibling("bc"))
        {
            const int uIndex = atoi(child->first_attribute("unknown")->value());
            const int fIndex = atoi(
                    child->first_attribute("function")->value());

            const gsXmlAttribute * comp = child->first_attribute("component");
            int cIndex = -1;
            if (NULL != comp)
                cIndex = atoi( child->first_attribute("component")->value() );

            getBoundaries(child, ids, boundaries);

            const gsXmlAttribute * bcat = child->first_attribute("type");
            GISMO_ASSERT(NULL != bcat, "No type provided");
            const char * bctype = bcat->value();
            for (std::vector<patchSide>::const_iterator it = boundaries.begin();
                    it != boundaries.end(); ++it)
                result.add(it->patch, it->side(), bctype, func[fIndex], uIndex,cIndex,
                        false);        //parametric
        }

        T val(0);
        for (gsXmlNode * child = node->first_node("cv"); child;
                child = child->next_sibling("cv"))
        {
            str.clear();
            str.str(child->value());
            GISMO_ENSURE(gsGetReal(str, val), "No value");
            const int uIndex = atoi(child->first_attribute("unknown")->value());
            const int cIndex = atoi(child->first_attribute("corner")->value());
            int pIndex = atoi(child->first_attribute("patch")->value());
            pIndex = ids[pIndex];
<commit_msg>improve reading of BC from xml file<commit_after>/** @file gsBoundaryConditions.hpp

    @brief Implementation file for the gsBoundaryConditions class.

    This file is part of the G+Smo library.

    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

    Author(s): <NAME>
*/

#include <gsIO/gsXml.h>
#include <gsCore/gsFunctionExpr.h>
#include <gsUtils/gsSortedVector.h>

namespace gismo
{

namespace internal
{

/// @brief I/O for boundary conditions from file
template<class T>
class gsXml< gsBoundaryConditions<T> >
{
private:
    gsXml() { }
    typedef gsBoundaryConditions<T> Object;
public:
    GSXML_COMMON_FUNCTIONS(Object);
    static std::string tag  () { return "boundaryConditions"; }
    static std::string type () { return ""; }

    GSXML_GET_POINTER(Object);

    static void get_into(gsXmlNode * node, Object & result)
    {
        GISMO_ASSERT(!strcmp(node->name(), tag().c_str()),
                "Something went wrong. Expected tag "<< tag());

        //gsXmlNode * tmp = node->first_node("patches");
        //GISMO_ASSERT(tmp, "No pathes tag");
//
//        std::istringstream str;
//        str.str( tmp->value() );
//        // Resolve ID numbers
//        std::map<int,int> ids;
//        if ( ! strcmp( tmp->first_attribute("type")->value(), "id_range") )
//        {
//            int first, last;
//            gsGetInt(str, first);
//            gsGetInt(str, last);
//            for ( int i = first; i<=last; ++i )
//                ids[i] = i - first;
//        }
//        else if ( ! strcmp( tmp->first_attribute("type")->value(),"id_index") )
//        {
//            int c = 0;
//            for (int pindex; gsGetInt(str, pindex);)
//                ids[pindex] = c++;
//        }
//        else
//        {
//            gsWarn<<"Incomplete tag \"patch\" in boundaryConditions.\n";
//        }
        std::istringstream str;
        std::map<int, int> ids;

        // Read function inventory
        int count = countByTag("Function", node);
        std::vector<typename gsFunctionExpr<T>::Ptr> func(count); // todo: gsFunction::Ptr
        for (gsXmlNode * child = node->first_node("Function"); child; child =
                child->next_sibling("Function"))
        {
            const int i = atoi(child->first_attribute("index")->value());
            func[i] = memory::make_shared(new gsFunctionExpr<T>);
            getFunctionFromXml(child, *func[i]);
        }

        // Read boundary conditions
        std::vector<patchSide> boundaries;
        for (gsXmlNode * child = node->first_node("bc"); child;
                child = child->next_sibling("bc"))
        {
            const int uIndex = atoi(child->first_attribute("unknown")->value());
            const int fIndex = atoi(
                    child->first_attribute("function")->value());

            const gsXmlAttribute * comp = child->first_attribute("component");
            int cIndex = -1;
            if (NULL != comp)
                cIndex = atoi( comp->value() );

            const gsXmlAttribute * att_ispar = child->first_attribute("parametric");
            bool ispar = false;
            if (NULL != att_ispar)
                ispar = atoi( att_ispar->value() );

            getBoundaries(child, ids, boundaries);

            const gsXmlAttribute * bcat = child->first_attribute("type");
            GISMO_ASSERT(NULL != bcat, "No type provided");
            const char * bctype = bcat->value();
            for (std::vector<patchSide>::const_iterator it = boundaries.begin();
                    it != boundaries.end(); ++it)
                result.add(it->patch, it->side(), bctype,
                           func[fIndex], uIndex,cIndex, ispar);
        }

        T val(0);
        for (gsXmlNode * child = node->first_node("cv"); child;
                child = child->next_sibling("cv"))
        {
            str.clear();
            str.str(child->value());
            GISMO_ENSURE(gsGetReal(str, val), "No value");
            const int uIndex = atoi(child->first_attribute("unknown")->value());
            const int cIndex = atoi(child->first_attribute("corner")->value());
            int pIndex = atoi(child->first_attribute("patch")->value());
            pIndex = ids[pIndex];

{'fraction_non_alphanumeric': 0.14928330031464865, 'fraction_numerical': 0.001631511478848619, 'mean_word_length': 2.081508078994614, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '651017', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2502, 'n_words': 594}