<commit_before>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "ceed.hpp"

#include "../../general/device.hpp"
#include "../../fem/gridfunc.hpp"

#include <sys/types.h>
#include <sys/stat.h>
#ifndef _WIN32
typedef struct stat struct_stat;
#else
#define stat(dir, buf) _stat(dir, buf)
#define S_ISDIR(mode) _S_IFDIR(mode)
typedef struct _stat struct_stat;
#endif

namespace mfem
{

namespace internal
{

#ifdef MFEM_USE_CEED
extern Ceed ceed;

std::string ceed_path;

extern CeedBasisMap ceed_basis_map;
extern CeedRestrMap ceed_restr_map;
#endif

}

void InitCeedCoeff(Coefficient* Q, CeedData* ptr)
{
#ifdef MFEM_USE_CEED
   if (ConstantCoefficient* coeff = dynamic_cast<ConstantCoefficient*>(Q))
   {
      CeedConstCoeff* ceedCoeff = new CeedConstCoeff{coeff->constant};
      ptr->coeff_type = CeedCoeff::Const;
      ptr->coeff = (void*)ceedCoeff;
   }
   else if (GridFunctionCoefficient* coeff =
               dynamic_cast<GridFunctionCoefficient*>(Q))
   {
      CeedGridCoeff* ceedCoeff = new CeedGridCoeff;
      ceedCoeff->coeff = coeff->GetGridFunction();
      ptr->coeff_type = CeedCoeff::Grid;
      ptr->coeff = (void*)ceedCoeff;
   }
   else
   {
      MFEM_ABORT("This type of Coefficient is not supported.");
   }
#else
   mfem_error("MFEM must be built with MFEM_USE_CEED=YES to use libCEED.");
#endif
}

void CeedPAAssemble(const CeedPAOperator& op,
                    CeedData& ceedData)
{
#ifdef MFEM_USE_CEED
   const FiniteElementSpace &fes = op.fes;
   const mfem::IntegrationRule &irm = op.ir;
   Ceed ceed(internal::ceed);
   mfem::Mesh *mesh = fes.GetMesh();
   CeedInt nqpts, nelem = mesh->GetNE();
   CeedInt dim = mesh->SpaceDimension(), vdim = fes.GetVDim();
   CeedMemType mem;
   CeedGetPreferredMemType(ceed, &mem);

   mesh->EnsureNodes();
   InitCeedBasisAndRestriction(fes, irm, ceed, &ceedData.basis, &ceedData.restr);

   const mfem::FiniteElementSpace *mesh_fes = mesh->GetNodalFESpace();
   MFEM_VERIFY(mesh_fes, "the Mesh has no nodal FE space");
   InitCeedBasisAndRestriction(*mesh_fes, irm, ceed, &ceedData.mesh_basis,
                               &ceedData.mesh_restr);

   CeedBasisGetNumQuadraturePoints(ceedData.basis, &nqpts);

   const int qdatasize = op.qdatasize;
   CeedElemRestrictionCreateStrided(ceed, nelem, nqpts, qdatasize,
                                    nelem*nqpts*qdatasize, CEED_STRIDES_BACKEND,
                                    &ceedData.restr_i);

   CeedVectorCreate(ceed, mesh->GetNodes()->Size(), &ceedData.node_coords);
   CeedScalar *nodes_ptr;
   CeedGetPreferredMemType(ceed, &mem);
   if ( Device::Allows(Backend::DEVICE_MASK) && mem==CEED_MEM_DEVICE )
   {
      nodes_ptr = const_cast<CeedScalar*>(mesh->GetNodes()->Read());
   }
   else
   {
      nodes_ptr = const_cast<CeedScalar*>(mesh->GetNodes()->HostRead());
      mem = CEED_MEM_HOST;
   }
   CeedVectorSetArray(ceedData.node_coords, mem, CEED_USE_POINTER, nodes_ptr);

   CeedVectorCreate(ceed, nelem * nqpts * qdatasize, &ceedData.rho);

   // Context data to be passed to the 'f_build_diff' Q-function.<commit_msg>move things around<commit_after>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#include "ceed.hpp"

#include "../../general/device.hpp"
#include "../../fem/gridfunc.hpp"

#include <sys/types.h>
#include <sys/stat.h>
#ifndef _WIN32
typedef struct stat struct_stat;
#else
#define stat(dir, buf) _stat(dir, buf)
#define S_ISDIR(mode) _S_IFDIR(mode)
typedef struct _stat struct_stat;
#endif

namespace mfem
{

namespace internal
{

#ifdef MFEM_USE_CEED
extern Ceed ceed;

std::string ceed_path;

extern CeedBasisMap ceed_basis_map;
extern CeedRestrMap ceed_restr_map;
#endif

}

void InitCeedCoeff(Coefficient* Q, CeedData* ptr)
{
#ifdef MFEM_USE_CEED
   if (ConstantCoefficient* coeff = dynamic_cast<ConstantCoefficient*>(Q))
   {
      CeedConstCoeff* ceedCoeff = new CeedConstCoeff{coeff->constant};
      ptr->coeff_type = CeedCoeff::Const;
      ptr->coeff = (void*)ceedCoeff;
   }
   else if (GridFunctionCoefficient* coeff =
               dynamic_cast<GridFunctionCoefficient*>(Q))
   {
      CeedGridCoeff* ceedCoeff = new CeedGridCoeff;
      ceedCoeff->coeff = coeff->GetGridFunction();
      ptr->coeff_type = CeedCoeff::Grid;
      ptr->coeff = (void*)ceedCoeff;
   }
   else
   {
      MFEM_ABORT("This type of Coefficient is not supported.");
   }
#else
   mfem_error("MFEM must be built with MFEM_USE_CEED=YES to use libCEED.");
#endif
}

void CeedPAAssemble(const CeedPAOperator& op,
                    CeedData& ceedData)
{
#ifdef MFEM_USE_CEED
   const FiniteElementSpace &fes = op.fes;
   const mfem::IntegrationRule &irm = op.ir;
   Ceed ceed(internal::ceed);
   mfem::Mesh *mesh = fes.GetMesh();
   CeedInt nqpts, nelem = mesh->GetNE();
   CeedInt dim = mesh->SpaceDimension(), vdim = fes.GetVDim();

   mesh->EnsureNodes();
   InitCeedBasisAndRestriction(fes, irm, ceed, &ceedData.basis, &ceedData.restr);

   const mfem::FiniteElementSpace *mesh_fes = mesh->GetNodalFESpace();
   MFEM_VERIFY(mesh_fes, "the Mesh has no nodal FE space");
   InitCeedBasisAndRestriction(*mesh_fes, irm, ceed, &ceedData.mesh_basis,
                               &ceedData.mesh_restr);

   CeedBasisGetNumQuadraturePoints(ceedData.basis, &nqpts);

   const int qdatasize = op.qdatasize;
   CeedElemRestrictionCreateStrided(ceed, nelem, nqpts, qdatasize,
                                    nelem*nqpts*qdatasize, CEED_STRIDES_BACKEND,
                                    &ceedData.restr_i);

   CeedVectorCreate(ceed, mesh->GetNodes()->Size(), &ceedData.node_coords);
   CeedScalar *nodes_ptr;
   CeedMemType mem;
   CeedGetPreferredMemType(ceed, &mem);
   if ( Device::Allows(Backend::DEVICE_MASK) && mem==CEED_MEM_DEVICE )
   {
      nodes_ptr = const_cast<CeedScalar*>(mesh->GetNodes()->Read());
   }
   else
   {
      nodes_ptr = const_cast<CeedScalar*>(mesh->GetNodes()->HostRead());
      mem = CEED_MEM_HOST;
   }
   CeedVectorSetArray(ceedData.node_coords, mem, CEED_USE_POINTER, nodes_ptr);

   CeedVectorCreate(ceed, nelem * nqpts * qdatasize, &ceedData.rho);

   // Context data to be passed to the 'f_build_diff' Q-function.
{'fraction_non_alphanumeric': 0.11635798105471512, 'fraction_numerical': 0.0048070125830623495, 'mean_word_length': 3.6600790513833994, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3785947', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2462, 'n_words': 555}