From 9dd24e98e19849303ac607930c4603083eef1f7f Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 13 Jan 2022 17:57:10 +0100 Subject: [PATCH] Updated tests with newly added functions --- CDMATH/tests/cdmath/FieldTests.cxx | 161 ++++++++---------- CDMATH/tests/cdmath/MeshTests.cxx | 44 ++--- .../tests/cdmath/SparseMatrixPetscTests.cxx | 14 ++ 3 files changed, 111 insertions(+), 108 deletions(-) diff --git a/CDMATH/tests/cdmath/FieldTests.cxx b/CDMATH/tests/cdmath/FieldTests.cxx index fef87d3..b0fef89 100755 --- a/CDMATH/tests/cdmath/FieldTests.cxx +++ b/CDMATH/tests/cdmath/FieldTests.cxx @@ -13,6 +13,7 @@ #include #include #include "MEDFileMesh.hxx" +#include "MEDLoader.hxx" using namespace std; using namespace MEDCoupling; @@ -254,12 +255,16 @@ FieldTests::testClassField( void ) CPPUNIT_ASSERT_EQUAL( 8, concF2.getNumberOfElements() ); CPPUNIT_ASSERT(concF2.meshNotDeleted()); concF2.writeMED("FieldConcF2");//This saves the mesh and the values of iteration 0 at time t=0 -// concF2.deleteMEDCouplingUMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line + concF2.writeVTK("FieldConcF2");//This saves the mesh and the values of iteration 0 at time t=0 + concF2.writeCSV("FieldConcF2");//This saves the mesh and the values of iteration 0 at time t=0 + concF2.deleteMEDCouplingMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line concF2.setTime(0.5,1);//Increase the time to 0.5 and the iteration to 1 for (int j=0;j (3,1),"CONSTANT_Field"); CPPUNIT_ASSERT_EQUAL( 3, concF5.getNumberOfComponents() ); @@ -305,103 +314,83 @@ FieldTests::testClassField( void ) cout<<"Mesh name : " << concF5.getMesh().getName()<buildUnstructured(); - //m1->setName("mesh"); - - //MEDCouplingFieldDouble * f = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME); - //f->setMesh(m1); - //f->setName("F"); - //*f=0; - //f->setTime(0.0,0,0); - - //MEDFileField1TS * ff; - //ff->setFieldNoProfileSBT(f); - - /* 1D image mesh */ - //int _spaceDim=1; - //double *originPtr = new double[_spaceDim]; - //double *dxyzPtr = new double[_spaceDim]; - //mcIdType *nodeStrctPtr = new mcIdType[_spaceDim]; - - //originPtr[0]=0; - //nodeStrctPtr[0]=3; - //dxyzPtr[0]=1; - - //MEDCouplingIMesh * _mesh=MEDCouplingIMesh::New("test", - //_spaceDim, - //nodeStrctPtr, - //nodeStrctPtr+_spaceDim, - //originPtr, - //originPtr+_spaceDim, - //dxyzPtr, - //dxyzPtr+_spaceDim); - //MEDCouplingUMesh * m1 = _mesh->buildUnstructured(); - //m1->setName("mesh"); - - //MEDCouplingFieldDouble * f = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME); - //f->setMesh(m1); - //f->setName("F"); - //*f=0; - //f->setTime(0.0,0,0); + concF5.writeMED("FieldConcF5", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted + concF5.writeVTK("FieldConcF5", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted + concF5.writeCSV("FieldConcF5");//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted - //MEDFileField1TS * ff; - //ff->setFieldNoProfileSBT(f); - - /* 2D cartesian mesh */ - //Dataarray + /* Delete the mesh then save the field */ + // Build a 2D cartesian mesh double XCoords[3]={0.,1.,2.}; double YCoords[3]={0.,1.,2.}; - MEDCoupling::DataArrayDouble *arrX=MEDCoupling::DataArrayDouble::New(); + MCAuto arrX=DataArrayDouble::New(); arrX->alloc(3,1); std::copy(XCoords,XCoords+3,arrX->getPointer()); arrX->setInfoOnComponent(0,"X [m]"); - MEDCoupling::DataArrayDouble *arrY=MEDCoupling::DataArrayDouble::New(); + MCAuto arrY=DataArrayDouble::New(); arrY->alloc(3,1); std::copy(YCoords,YCoords+3,arrY->getPointer()); arrY->setInfoOnComponent(0,"Y [m]"); //Mesh - MEDCoupling::MEDCouplingCMesh *mesh=MEDCoupling::MEDCouplingCMesh::New("My2D_CMesh"); + MCAuto mesh=MEDCouplingCMesh::New("My2D_CMesh"); mesh->setCoords(arrX,arrY); - arrX->decrRef(); - arrY->decrRef(); - MEDCouplingUMesh * m1 = mesh->buildUnstructured(); + MCAuto m1 = mesh->buildUnstructured(); m1->setName("mesh"); //Field - MEDCouplingFieldDouble * f = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME); + MCAuto f = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME); f->setMesh(m1); f->setName("F"); - *f=0; f->setTime(0.0,0,0); - //MEDFileField1TS - MEDFileField1TS * ff; - //ff->setFieldNoProfileSBT(f); + + MCAuto da = DataArrayDouble::New(); da->alloc(4,1); + double vals[4]={1.,2., 3., 4.}; + std::copy(vals,vals+4,da->rwBegin()); + f->setArray(da); + + // Sauvegarde Maillage d'abord: + auto fName = "./test.med"; + MEDCoupling::WriteUMesh(fName, m1, true); + + // Maintenant juste les champs: + MCAuto ff = MEDFileField1TS::New(); + ff->setFieldNoProfileSBT(f); + ff->write(fName, 0); // 0 overwrite + + // Tue le maillage + m1 = 0; // directly garbage collected, this is C++ man !! + + // Ecrit encore du champ: + MCAuto da2 = da->deepCopy(); + f->setTime(1.0,1,0); + MCAuto da3 = da2->negate(); + f->setArray(da3); + + MCAuto ff2 = MEDFileField1TS::New(); + + ff2->setFieldNoProfileSBT(f); // le maillage n'existe plus, tant pis :-) + ff2->write(fName, 0); // 0 oui oui on veut bien 0 ici. + + /* Create a field on a boundary */ + Mesh Msquare("./meshSquare.med", "Mesh_1", 0); + Mesh Mbottom = Msquare.getBoundaryGroupMesh ( "Bottom" ); + Mbottom.writeMED("./meshSquare", false); + Mbottom.writeVTK("./meshSquare"); + Field Fbottom_cells("Bottom_BC",CELLS,Mbottom); + for(int i=0; i indexFaces=M2.getIndexFacePeriodic(); for (int i=0;izoom in, middle mouse->zoom out, right mouse->continue with the simulation + //A4.viewMatrix(true,-1);//This pauses the x window until the user presses right mouse + A4.getEigenvalues( 4, EPS_SMALLEST_MAGNITUDE, 1e-6, EPSKRYLOVSCHUR, true, 0.05, "A4");//Plot eigenvalues in a X-Windows and write the image in a file + A4.getSingularValues( 4, SVD_SMALLEST , 1e-6, SVDCYCLIC , true, 0.05, "A4");//Plot eigenvalues in a X-Windows and write the image in a file + SparseMatrixPetsc A5(A4.transpose()); CPPUNIT_ASSERT_EQUAL( 1., A5(0,0) ); CPPUNIT_ASSERT_EQUAL( 5., A5(0,1) ); @@ -263,4 +270,11 @@ SparseMatrixPetscTests::testClassSparseMatrixPetsc( void ) CPPUNIT_ASSERT_EQUAL( 4.0, A8(0,1) ); CPPUNIT_ASSERT_EQUAL( 6.0, A8(1,0) ); CPPUNIT_ASSERT_EQUAL( 8.0, A8(1,1) ); + + A8.viewMatrix();//Display matrix coefficients on the screen + A8.viewMatrix(true,0.05, "A8");//Open an x windows displaying the matrix nonzero strcture + //The following line would pause the x window until the user presses right mouse : left mouse->zoom in, middle mouse->zoom out, right mouse->continue with the simulation + //A8.viewMatrix(true,-1);//This pauses the x window until the user presses right mouse + A8.getEigenvalues( 4, EPS_SMALLEST_MAGNITUDE, 1e-6, EPSKRYLOVSCHUR, true, 0.05, "A8");//Plot eigenvalues in a X-Windows and write the image in a file + A8.getSingularValues( 4, SVD_SMALLEST , 1e-6, SVDCYCLIC , true, 0.05, "A8");//Plot eigenvalues in a X-Windows and write the image in a file } -- 2.39.2