9 #include "Utils/FParameters.hpp"
11 #include "Components/FParticleType.hpp"
12 #include "Components/FTypedLeaf.hpp"
14 #include "Containers/FOctree.hpp"
15 #include "Containers/FVector.hpp"
17 #include "Core/FFmmAlgorithmThreadTsm.hpp"
19 #include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
20 #include "Kernels/Rotation/FRotationCell.hpp"
21 #include "Kernels/Rotation/FRotationKernel.hpp"
36 typedef FTypedRotationCell<FReal, P>
39 typedef FP2PParticleContainerIndexed<FReal>
42 typedef FTypedLeaf<FReal, ContainerClass>
45 typedef FOctree<FReal, CellClass, ContainerClass, LeafClass>
48 typedef FRotationKernel<FReal, CellClass, ContainerClass, P>
51 typedef FFmmAlgorithmThreadTsm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>
70 std::vector<Tetra::prm> & prmTet ,
71 std::vector<Facette::prm> & prmFac ,
72 const int ScalfmmNbThreads )
76 omp_set_num_threads(ScalfmmNbThreads);
77 norm = 1. / (2. * msh.
l.maxCoeff());
80 for (idxPart = 0; idxPart <
NOD; ++idxPart)
83 tree.insert(FPoint<FReal>(pTarget.x(), pTarget.y(), pTarget.z()),
84 FParticleType::FParticleTypeTarget, idxPart);
87 insertCharges<Tetra::Tet, Tetra::NPI>(msh.
tet, idxPart, msh.
c);
88 insertCharges<Facette::Fac, Facette::NPI>(msh.
fac, idxPart, msh.
c);
128 template<
class T, const
int NPI>
129 void insertCharges(std::vector<T>
const &container, FSize &idx, Eigen::Ref<Eigen::Vector3d>
const c)
131 std::for_each(container.begin(), container.end(),
132 [
this, c, &idx](T
const &elem)
134 Eigen::Matrix<double,Nodes::DIM,NPI> gauss;
135 elem.getPtGauss(gauss);
137 for (int j = 0; j < NPI; j++, idx++)
139 double x = norm*(gauss(0,j) - c.x());
140 double y = norm*(gauss(1,j) - c.y());
141 double z = norm*(gauss(2,j) - c.z());
142 tree.insert(FPoint<FReal>(x,y,z), FParticleType::FParticleTypeSource, idx, 0.0);
152 std::fill(srcDen.begin(),srcDen.end(),0);
154 std::for_each(msh.
tet.begin(), msh.
tet.end(),
156 { tet.charges(prmTetra[tet.idxPrm], getter, srcDen, nsrc); });
157 std::fill(corr.begin(),corr.end(),0);
158 std::for_each(msh.
fac.begin(), msh.
fac.end(),
160 { fac.charges(prmFacette[fac.idxPrm], getter, srcDen, nsrc, corr); });
170 calc_charges(getter, msh);
176 const int nbParticlesInLeaf = leaf->getSrc()->getNbParticles();
177 const FVector<long long> &indexes = leaf->getSrc()->getIndexes();
178 FReal *
const physicalValues = leaf->getSrc()->getPhysicalValues();
179 for (
int idxPart = 0; idxPart < nbParticlesInLeaf; ++idxPart)
181 physicalValues[idxPart] = srcDen[indexes[idxPart] - NOD];
184 std::fill_n(leaf->getTargets()->getPotentials(),
185 leaf->getTargets()->getNbParticles(), 0);
188 tree.forEachCell([](
CellClass *cell) { cell->resetToInitialState(); });
195 const FReal *
const potentials = leaf->getTargets()->getPotentials();
196 const int nbParticlesInLeaf = leaf->getTargets()->getNbParticles();
197 const FVector<long long> &indexes = leaf->getTargets()->getIndexes();
199 for (
int idxPart = 0; idxPart < nbParticlesInLeaf; ++idxPart)
201 const int indexPartOrig = indexes[idxPart];
202 msh.
set(indexPartOrig, setter,
203 (potentials[idxPart] * norm + corr[indexPartOrig]) / (4 * M_PI));
const Eigen::Vector3d getNode_p(const int i) const
Definition: mesh.h:83
Eigen::Vector3d l
Definition: mesh.h:128
int getNbFacs(void) const
Definition: mesh.h:77
Eigen::Vector3d c
Definition: mesh.h:125
std::vector< Tetra::Tet > tet
Definition: mesh.h:137
int getNbTets(void) const
Definition: mesh.h:80
std::vector< Facette::Fac > fac
Definition: mesh.h:134
void set(const int i, std::function< void(Nodes::Node &, const double)> what_to_set, const double val)
Definition: mesh.h:178
Definition: fmm_demag.h:65
const int NOD
Definition: fmm_demag.h:116
double norm
Definition: fmm_demag.h:121
fmm(Mesh::mesh &msh, std::vector< Tetra::prm > &prmTet, std::vector< Facette::prm > &prmFac, const int ScalfmmNbThreads)
Definition: fmm_demag.h:69
void insertCharges(std::vector< T > const &container, FSize &idx, Eigen::Ref< Eigen::Vector3d > const c)
Definition: fmm_demag.h:129
std::vector< double > corr
Definition: fmm_demag.h:107
void calc_demag(Mesh::mesh &msh)
Definition: fmm_demag.h:97
std::vector< double > srcDen
Definition: fmm_demag.h:104
void calc_charges(std::function< const Eigen::Vector3d(Nodes::Node)> getter, Mesh::mesh &msh)
Definition: fmm_demag.h:149
std::vector< Facette::prm > prmFacette
Definition: fmm_demag.h:113
OctreeClass tree
Definition: fmm_demag.h:118
void demag(std::function< const Eigen::Vector3d(Nodes::Node)> getter, std::function< void(Nodes::Node &, const double)> setter, Mesh::mesh &msh)
Definition: fmm_demag.h:166
std::vector< Tetra::prm > prmTetra
Definition: fmm_demag.h:110
KernelClass kernels
Definition: fmm_demag.h:119
class mesh, readMesh is expecting a mesh file in gmsh format either text or binary,...
const int NPI
Definition: facette.h:18
void set_phiv(Node &n, double val)
Definition: node.h:174
void set_phi(Node &n, double val)
Definition: node.h:171
const int NPI
Definition: tetra.h:23
const FPoint< FReal > boxCenter(0., 0., 0.)
FRotationKernel< FReal, CellClass, ContainerClass, P > KernelClass
Definition: fmm_demag.h:49
FP2PParticleContainerIndexed< FReal > ContainerClass
Definition: fmm_demag.h:40
FTypedRotationCell< FReal, P > CellClass
Definition: fmm_demag.h:37
FTypedLeaf< FReal, ContainerClass > LeafClass
Definition: fmm_demag.h:43
FOctree< FReal, CellClass, ContainerClass, LeafClass > OctreeClass
Definition: fmm_demag.h:46
const int P
Definition: fmm_demag.h:32
const double boxWidth
Definition: fmm_demag.h:57
const int SizeSubLevels
Definition: fmm_demag.h:56
const int NbLevels
Definition: fmm_demag.h:55
double FReal
Definition: fmm_demag.h:34
FFmmAlgorithmThreadTsm< OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass
Definition: fmm_demag.h:52