<commit_before>/** @file gsExprHelper.h

    @brief Generic expressions helper

    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>
*/

#pragma once

#include <gsAssembler/gsExpressions.h>

namespace gismo
{
/**
   Class holding an expression environment
 */
template<class T>
class gsExprHelper
{
private:
    gsExprHelper(const gsExprHelper &);

    gsExprHelper() : mesh_ptr(NULL)
    { mutVar.setData(mutData); }

private:
    typedef std::map<const gsFunctionSet<T>*,gsFuncData<T> > FunctionTable;
    typedef typename FunctionTable::iterator ftIterator;
    typedef typename FunctionTable::const_iterator const_ftIterator;
    typedef std::deque<gsDofMapper>    DofMappers;

    // variable/space list
    std::deque<expr::gsFeVariable<T> > m_vlist;
    std::deque<expr::gsFeSpace<T> >    m_slist;

    // background functions
    FunctionTable m_itable;
    FunctionTable m_ptable;
    //FunctionTable i_map;

    DofMappers m_mappers;

    // geometry map
    expr::gsGeometryMap<T> mapVar, mapVar2;
public:
    gsMapData<T> mapData, mapData2;
private:

    // mutable pair of variable and data,
    // ie. not uniquely assigned to a gsFunctionSet
    expr::gsFeVariable<T> mutVar ;
    gsFuncData<T>         mutData;
    bool mutParametric;

    gsSortedVector<const gsFunctionSet<T>*> evList;

    const gsMultiBasis<T> * mesh_ptr;

public:
    typedef const expr::gsGeometryMap<T> & geometryMap;
    typedef const expr::gsFeElement<T>   & element;
    typedef const expr::gsFeVariable<T>  & variable;
    typedef const expr::gsFeSpace<T>     & space;
    typedef const expr::gsNullExpr<T>      nullExpr;


    typedef expr::gsFeVariable<T>  & nonConstVariable;
    typedef expr::gsFeSpace<T>     & nonConstSpace;

    typedef memory::unique_ptr<gsExprHelper> uPtr;
    typedef memory::shared_ptr<gsExprHelper>  Ptr;
public:

    gsMatrix<T> & points() { return mapData.points; }

    static uPtr make() { return uPtr(new gsExprHelper()); }

    void reset()
    {
        m_ptable.clear();
        m_itable.clear();
        points().clear();
        m_vlist .clear();
        m_slist .clear();
        //mapVar.reset();
    }

    void print() const
    {
        //mapData.side
        if ( mapVar.isValid() ) // list ?
        {
            gsInfo << "mapVar: "<< &mapData <<"\n";
        }

        if ( mutVar.isValid() && 0!=mutData.flags)
        {
            gsInfo << "mutVar: "<< &mutVar <<"\n";
        }

        gsInfo << "ptable:\n";
        for (const_ftIterator it = m_ptable.begin(); it != m_ptable.end(); ++it)
        {
            gsInfo << " * "<< &it->first <<" --> "<< &it->second <<"\n";
        }

        gsInfo << "itable:\n";
        for (const_ftIterator it = m_itable.begin(); it != m_itable.end(); ++it)
        {
            gsInfo << " * "<< &it->first <<" --> "<< &it->second <<"\n";
        }
    }

    void cleanUp()
    {
        mapData.clear();
        mapData2.clear();
        mutData.clear();
        for (ftIterator it = m_ptable.begin(); it != m_ptable.end(); ++it)
            it->second.clear();
        for (ftIterator it = m_itable.begin(); it != m_itable.end(); ++it)
            it->second.clear();
    }

    void setMultiBasis(const gsMultiBasis<T> & mesh) { mesh_ptr = &mesh; }

    bool multiBasisSet() { return NULL!=mesh_ptr;}

    const gsMultiBasis<T> & multiBasis()
    {
        GISMO_ASSERT(multiBasisSet(), "Integration elements not set.");
        return *mesh_ptr;
    }


    geometryMap getMap(const gsFunction<T> & mp)
    {
        //mapData.clear();
        mapVar.registerData(mp, mapData);
        return mapVar;
    }

    geometryMap getMap(const gsMultiPatch<T> & mp)
    {
        //mapData.clear();
        if (!mapVar.isValid() )
        {
            mapVar.registerData(mp, mapData);
            return mapVar;
        }
        else
        {
            mapVar2.registerData(mp, mapData2);
            return mapVar2;
        }
    }

    geometryMap getMap() const
    {
        GISMO_ASSERT(mapVar.isValid(), "The Geometry map is not initialized)");
        return mapVar;
    }

    nonConstVariable getVar(const gsFunctionSet<T> & mp, index_t dim = 1)
    {
        // todo: static dispatch for ScalarValued
        m_vlist.push_back( expr::gsFeVariable<T>() );
        expr::gsFeVariable<T> & var = m_vlist.back();<commit_msg>add getmap2<commit_after>/** @file gsExprHelper.h

    @brief Generic expressions helper

    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>
*/

#pragma once

#include <gsAssembler/gsExpressions.h>

namespace gismo
{
/**
   Class holding an expression environment
 */
template<class T>
class gsExprHelper
{
private:
    gsExprHelper(const gsExprHelper &);

    gsExprHelper() : mesh_ptr(NULL)
    { mutVar.setData(mutData); }

private:
    typedef std::map<const gsFunctionSet<T>*,gsFuncData<T> > FunctionTable;
    typedef typename FunctionTable::iterator ftIterator;
    typedef typename FunctionTable::const_iterator const_ftIterator;
    typedef std::deque<gsDofMapper>    DofMappers;

    // variable/space list
    std::deque<expr::gsFeVariable<T> > m_vlist;
    std::deque<expr::gsFeSpace<T> >    m_slist;

    // background functions
    FunctionTable m_itable;
    FunctionTable m_ptable;
    //FunctionTable i_map;

    DofMappers m_mappers;

    // geometry map
    expr::gsGeometryMap<T> mapVar, mapVar2;
public:
    gsMapData<T> mapData, mapData2;
private:

    // mutable pair of variable and data,
    // ie. not uniquely assigned to a gsFunctionSet
    expr::gsFeVariable<T> mutVar ;
    gsFuncData<T>         mutData;
    bool mutParametric;

    gsSortedVector<const gsFunctionSet<T>*> evList;

    const gsMultiBasis<T> * mesh_ptr;

public:
    typedef const expr::gsGeometryMap<T> & geometryMap;
    typedef const expr::gsFeElement<T>   & element;
    typedef const expr::gsFeVariable<T>  & variable;
    typedef const expr::gsFeSpace<T>     & space;
    typedef const expr::gsNullExpr<T>      nullExpr;

    typedef expr::gsFeVariable<T>  & nonConstVariable;
    typedef expr::gsFeSpace<T>     & nonConstSpace;

    typedef memory::unique_ptr<gsExprHelper> uPtr;
    typedef memory::shared_ptr<gsExprHelper>  Ptr;
public:

    gsMatrix<T> & points() { return mapData.points; }

    static uPtr make() { return uPtr(new gsExprHelper()); }

    void reset()
    {
        m_ptable.clear();
        m_itable.clear();
        points().clear();
        m_vlist .clear();
        m_slist .clear();
        //mapVar.reset();
    }

    void print() const
    {
        //mapData.side
        if ( mapVar.isValid() ) // list ?
        {
            gsInfo << "mapVar: "<< &mapData <<"\n";
        }

        if ( mutVar.isValid() && 0!=mutData.flags)
        {
            gsInfo << "mutVar: "<< &mutVar <<"\n";
        }

        gsInfo << "ptable:\n";
        for (const_ftIterator it = m_ptable.begin(); it != m_ptable.end(); ++it)
        {
            gsInfo << " * "<< &it->first <<" --> "<< &it->second <<"\n";
        }

        gsInfo << "itable:\n";
        for (const_ftIterator it = m_itable.begin(); it != m_itable.end(); ++it)
        {
            gsInfo << " * "<< &it->first <<" --> "<< &it->second <<"\n";
        }
    }

    void cleanUp()
    {
        mapData.clear();
        mapData2.clear();
        mutData.clear();
        for (ftIterator it = m_ptable.begin(); it != m_ptable.end(); ++it)
            it->second.clear();
        for (ftIterator it = m_itable.begin(); it != m_itable.end(); ++it)
            it->second.clear();
    }

    void setMultiBasis(const gsMultiBasis<T> & mesh) { mesh_ptr = &mesh; }

    bool multiBasisSet() { return NULL!=mesh_ptr;}

    const gsMultiBasis<T> & multiBasis()
    {
        GISMO_ASSERT(multiBasisSet(), "Integration elements not set.");
        return *mesh_ptr;
    }


    geometryMap getMap(const gsFunction<T> & mp)
    {
        //mapData.clear();
        mapVar.registerData(mp, mapData);
        return mapVar;
    }

    geometryMap getMap(const gsMultiPatch<T> & mp)
    {
        //mapData.clear();
        if (!mapVar.isValid() )
        {
            mapVar.registerData(mp, mapData);
            return mapVar;
        }
        else
        {
            mapVar2.registerData(mp, mapData2);
            return mapVar2;
        }
    }

    geometryMap getMap() const
    {
        GISMO_ASSERT(mapVar.isValid(), "The Geometry map is not initialized)");
        return mapVar;
    }

    geometryMap getMap2() const
    {
        GISMO_ASSERT(mapVar2.isValid(), "The Geometry map2 is not initialized)");
        return mapVar2;
    }

    nonConstVariable getVar(const gsFunctionSet<T> & mp, index_t dim = 1)
    {
        // todo: static dispatch for ScalarValued
        m_vlist.push_back( expr::gsFeVariable<T>() );
        expr::gsFeVariable<T> & var = m_vlist.back();
{'fraction_non_alphanumeric': 0.1339034423035289, 'fraction_numerical': 0.0031392076206971206, 'mean_word_length': 2.3979404192717912, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3603804', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2977, 'n_words': 676}