Maj terminée. Pour consulter la release notes associée voici le lien :
https://about.gitlab.com/releases/2021/07/07/critical-security-release-gitlab-14-0-4-released/

Une nouvelle version du portail de gestion des comptes externes sera mise en production lundi 09 août. Elle permettra d'allonger la validité d'un compte externe jusqu'à 3 ans. Pour plus de détails sur cette version consulter : https://doc-si.inria.fr/x/FCeS

utestSphericalWithPrevious.cpp 7.38 KB
Newer Older
1
// ===================================================================================
COULAUD Olivier's avatar
COULAUD Olivier committed
2
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas, Matthias Messner
3 4 5 6 7 8 9 10 11 12 13 14
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.  
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info". 
// "http://www.gnu.org/licenses".
15
// ===================================================================================
COULAUD Olivier's avatar
COULAUD Olivier committed
16 17


BRAMAS Berenger's avatar
BRAMAS Berenger committed
18
#include "Utils/FGlobal.hpp"
COULAUD Olivier's avatar
COULAUD Olivier committed
19

BRAMAS Berenger's avatar
BRAMAS Berenger committed
20 21
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
22

BRAMAS Berenger's avatar
BRAMAS Berenger committed
23 24 25
#include "Kernels/Spherical/FSphericalCell.hpp"
#include "Kernels/Spherical/FSphericalKernel.hpp"
#include "Components/FSimpleLeaf.hpp"
26

BRAMAS Berenger's avatar
BRAMAS Berenger committed
27
#include "Files/FFmaGenericLoader.hpp"
COULAUD Olivier's avatar
COULAUD Olivier committed
28

BRAMAS Berenger's avatar
BRAMAS Berenger committed
29
#include "Files/FTreeIO.hpp"
30

BRAMAS Berenger's avatar
BRAMAS Berenger committed
31
#include "Core/FFmmAlgorithm.hpp"
32 33

#include "FUTester.hpp"
BRAMAS Berenger's avatar
BRAMAS Berenger committed
34
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
35

berenger-bramas's avatar
berenger-bramas committed
36
/**
COULAUD Olivier's avatar
COULAUD Olivier committed
37 38
 * This test compare a previous FMM result with a previous simulation result.
 */
39

40
typedef double FReal;
41
typedef FSphericalCell<FReal>           CellClass;
42
typedef FP2PParticleContainerIndexed<FReal>  ContainerClass;
43

44
typedef FSphericalKernel< FReal, CellClass, ContainerClass >          KernelClass;
45

46 47
typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
48

49
typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
50

51 52
/** To check if a value is correct */
bool IsSimilar(const FReal good, const FReal other){
COULAUD Olivier's avatar
COULAUD Olivier committed
53 54
	const FReal Epsilon = FReal(0.0001);
	return (FMath::Abs(good-other)/FMath::Abs(good)) < Epsilon;
55 56
}

berenger-bramas's avatar
berenger-bramas committed
57
/** The test class */
berenger-bramas's avatar
berenger-bramas committed
58
class TestSphericalWithPrevious : public FUTester<TestSphericalWithPrevious> {
COULAUD Olivier's avatar
COULAUD Olivier committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	/** the test */
	void TestTree(){
		if(sizeof(FReal) == sizeof(float) ) {
			std::cerr << "No input data available for Float "<< std::endl;
			uassert(false);
		}
		//
		//  Load a Tree
		const std::string DataFile = (sizeof(FReal) == sizeof(float))?
				SCALFMMDataPath+"UTest/SphericalPrevious.data.single":
				SCALFMMDataPath+"UTest/SphericalPrevious.data.double";
		//
		// Load particles
		//

		const std::string parFile( (sizeof(FReal) == sizeof(float))?
				"UTest/DirectFloat.bfma":
				"UTest/DirectDouble.bfma");
		//
		std::string filename(SCALFMMDataPath+parFile);
		//
80
		FFmaGenericLoader<FReal> loader(filename);
COULAUD Olivier's avatar
COULAUD Olivier committed
81 82 83 84 85 86 87 88 89 90 91 92 93
		if(!loader.isOpen()){
			Print("Cannot open particles file.");
			uassert(false);
			return;
		}
		FSize nbParticles = loader.getNumberOfParticles() ;
		//
		const int NbLevels      = 5;
		const int SizeSubLevels = 3;
		const int DevP = 9;
		//
		// Create octree
		//
94
		FSphericalCell<FReal>::Init(DevP);
COULAUD Olivier's avatar
COULAUD Olivier committed
95 96 97
		//
		OctreeClass testTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
		//
98
		for(FSize idxPart = 0 ; idxPart < nbParticles ; ++idxPart){
99
            FPoint<FReal> position;
COULAUD Olivier's avatar
COULAUD Olivier committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113
			FReal physicalValue = 0.0;
			loader.fillParticle(&position,&physicalValue);
			// put in tree
			testTree.insert(position, idxPart, physicalValue);
		}
		//
		//  Run simulation 1
		KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
		FmmClass algo(&testTree,&kernels);
		Print("Run simulation 1 ...");

		algo.execute();

		// If needed save the result
BRAMAS Berenger's avatar
BRAMAS Berenger committed
114
        //FTreeIO<FReal>::Save<OctreeClass, CellClass, LeafClass, ContainerClass >(DataFile.c_str(), testTree);
COULAUD Olivier's avatar
COULAUD Olivier committed
115 116 117

		// Load previous result
		OctreeClass goodTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
118
        FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(DataFile.c_str(), goodTree);
COULAUD Olivier's avatar
COULAUD Olivier committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

		// Compare the two simulations
		Print("Check the particles...");
		{ // Check that each particle has been summed with all other
			OctreeClass::Iterator testOctreeIterator(&testTree);
			OctreeClass::Iterator goodOctreeIterator(&goodTree);

			testOctreeIterator.gotoBottomLeft();
			goodOctreeIterator.gotoBottomLeft();

			do{
				if(testOctreeIterator.getCurrentGlobalIndex() != goodOctreeIterator.getCurrentGlobalIndex()){
					uassert(false);
					break;
				}

				if(testOctreeIterator.getCurrentListSrc()->getNbParticles() != goodOctreeIterator.getCurrentListSrc()->getNbParticles()){
					uassert(false);
					break;
				}

				const ContainerClass* testLeaf = testOctreeIterator.getCurrentListSrc();
				const ContainerClass* goodLeaf = goodOctreeIterator.getCurrentListSrc();

143
				for(FSize idxPart = 0 ; idxPart < testLeaf->getNbParticles() ; ++idxPart ){
COULAUD Olivier's avatar
COULAUD Olivier committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
					uassert( IsSimilar(goodLeaf->getPotentials()[idxPart], testLeaf->getPotentials()[idxPart]) );
					uassert( IsSimilar(goodLeaf->getForcesX()[idxPart], testLeaf->getForcesX()[idxPart]) );
					uassert( IsSimilar(goodLeaf->getForcesY()[idxPart], testLeaf->getForcesY()[idxPart]) );
					uassert( IsSimilar(goodLeaf->getForcesZ()[idxPart], testLeaf->getForcesZ()[idxPart]) );
				}

				if(!testOctreeIterator.moveRight()){
					if(goodOctreeIterator.moveRight()){
						uassert(false);
					}
					break;
				}
				if(!goodOctreeIterator.moveRight()){
					uassert(false);
					break;
				}

			} while(true);
		}
		Print("Check the leaves...");
		{ // Ceck if there is number of NbPart summed at level 1
			OctreeClass::Iterator testOctreeIterator(&testTree);
			OctreeClass::Iterator goodOctreeIterator(&goodTree);

			testOctreeIterator.gotoBottomLeft();
			goodOctreeIterator.gotoBottomLeft();

			for(int idxLevel = NbLevels - 1 ; idxLevel > 1 ; --idxLevel ){
				do{
					if(testOctreeIterator.getCurrentGlobalIndex() != goodOctreeIterator.getCurrentGlobalIndex()){
						uassert(false);
						break;
					}

178 179 180 181 182
					for(int idxLocal = 0 ; idxLocal < CellClass::local_expansion_t::getSize() ; ++idxLocal){
						IsSimilar(testOctreeIterator.getCurrentCell()->getLocalExpansionData().get()[idxLocal].getReal(),
								goodOctreeIterator.getCurrentCell()->getLocalExpansionData().get()[idxLocal].getReal());
						IsSimilar(testOctreeIterator.getCurrentCell()->getLocalExpansionData().get()[idxLocal].getImag(),
								goodOctreeIterator.getCurrentCell()->getLocalExpansionData().get()[idxLocal].getImag());
COULAUD Olivier's avatar
COULAUD Olivier committed
183 184
					}

185 186 187 188 189
					for(int idxPole = 0 ; idxPole < CellClass::multipole_t::getSize() ; ++idxPole){
						IsSimilar(testOctreeIterator.getCurrentCell()->getMultipoleData().get()[idxPole].getReal(),
								goodOctreeIterator.getCurrentCell()->getMultipoleData().get()[idxPole].getReal());
						IsSimilar(testOctreeIterator.getCurrentCell()->getMultipoleData().get()[idxPole].getImag(),
								goodOctreeIterator.getCurrentCell()->getMultipoleData().get()[idxPole].getImag());
COULAUD Olivier's avatar
COULAUD Olivier committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
					}

					if(!testOctreeIterator.moveRight()){
						if(goodOctreeIterator.moveRight()){
							uassert(false);
						}
						break;
					}
					if(!goodOctreeIterator.moveRight()){
						uassert(false);
						break;
					}

				} while(true);

				testOctreeIterator.moveUp();
				testOctreeIterator.gotoLeft();

				goodOctreeIterator.moveUp();
				goodOctreeIterator.gotoLeft();
			}
		}
		Print("Over...");
	}


	// set test
	void SetTests(){
		AddTest(&TestSphericalWithPrevious::TestTree,"Test Simu and compare tree");
	}
220 221 222 223 224
};



// You must do this
berenger-bramas's avatar
berenger-bramas committed
225
TestClass(TestSphericalWithPrevious)
226 227


228