#include <MEDCouplingCMesh.hxx>
#include <MEDFileField1TS.hxx>
#include "MEDFileMesh.hxx"
+#include "MEDLoader.hxx"
using namespace std;
using namespace MEDCoupling;
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<concF2.getNumberOfComponents();j++)
for (int i=0;i<concF2.getNumberOfElements();i++)
- concF2(i,j)=i*j;
- concF2.writeMED("FieldConcF2", true);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
+ concF2(i,j)=i*(j+2);
+ concF2.writeMED("FieldConcF2", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
+ concF2.writeVTK("FieldConcF2", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
+ concF2.writeCSV("FieldConcF2");//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
Mesh M3(0.0,1.0,2,0.,1.,2,0.,1.,2);
Field concF3("CONCENTRATION",FACES,M3) ;
CPPUNIT_ASSERT_EQUAL( double(i+j), concF4(i,j) );
CPPUNIT_ASSERT(concF4.meshNotDeleted());
concF4.writeMED("FieldConcF4");//This saves the mesh and the values of iteration 0 at time t=0
-// concF4.deleteMEDCouplingUMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line
+ concF4.writeVTK("FieldConcF4");//This saves the mesh and the values of iteration 0 at time t=0
+ concF4.writeCSV("FieldConcF4");//This saves the mesh and the values of iteration 0 at time t=0
+ concF4.deleteMEDCouplingMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line
concF4.setTime(0.5,1);//Increase the time to 0.5 and the iteration to 1
for (int j=0;j<concF4.getNumberOfComponents();j++)
for (int i=0;i<concF4.getNumberOfElements();i++)
- concF4(i,j)=i*j;
+ concF4(i,j)=i*(j+2);
concF4.writeMED("FieldConcF4", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
-
+ concF4.writeVTK("FieldConcF4", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
+ concF4.writeCSV("FieldConcF4");//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
+
//Create a constant field on the mesh fileNameMEDn
Field concF5(fileNameMEDn,NODES,std::vector<double> (3,1),"CONSTANT_Field");
CPPUNIT_ASSERT_EQUAL( 3, concF5.getNumberOfComponents() );
cout<<"Mesh name : " << concF5.getMesh().getName()<<endl;
cout<<"Field name : " << concF5.getName()<<endl;
concF5.setTime(0.5,1);//Increase the time to 0.5 and the iteration to 1
- concF5.writeMED("FieldConcF5",false);//This saves the mesh and the values of iteration 0 at time t=0
- //concF5.deleteMEDCouplingUMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line
+ concF5.writeMED("FieldConcF5");//This saves the mesh and the values of iteration 0 at time t=0
+ concF5.writeVTK("FieldConcF5");//This saves the mesh and the values of iteration 0 at time t=0
+ concF5.writeCSV("FieldConcF5");//This saves the mesh and the values of iteration 0 at time t=0
+ concF5.deleteMEDCouplingMesh();//medcouplingmesh is no longer needed as the mesh was already saved in the previous line
for (int j=0;j<concF5.getNumberOfComponents();j++)
for (int i=0;i<concF5.getNumberOfElements();i++)
concF5(i,j)=i*j;
- //concF5.writeMED("FieldConcF5", false);//This saves only the values of iteration 1 at time t=0.5. The previous values are not deleted
-
-
- /* 2D image mesh */
- //int _spaceDim=2;
- //double *originPtr = new double[_spaceDim];
- //double *dxyzPtr = new double[_spaceDim];
- //mcIdType *nodeStrctPtr = new mcIdType[_spaceDim];
-
- //originPtr[0]=0;
- //originPtr[1]=0;
- //nodeStrctPtr[0]=3;
- //nodeStrctPtr[1]=3;
- //dxyzPtr[0]=1;
- //dxyzPtr[1]=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);
-
- //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<DataArrayDouble> 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<DataArrayDouble> 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<MEDCouplingCMesh> mesh=MEDCouplingCMesh::New("My2D_CMesh");
mesh->setCoords(arrX,arrY);
- arrX->decrRef();
- arrY->decrRef();
- MEDCouplingUMesh * m1 = mesh->buildUnstructured();
+ MCAuto<MEDCouplingUMesh> m1 = mesh->buildUnstructured();
m1->setName("mesh");
//Field
- MEDCouplingFieldDouble * f = MEDCouplingFieldDouble::New(ON_CELLS, ONE_TIME);
+ MCAuto<MEDCouplingFieldDouble> 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<DataArrayDouble> 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<MEDFileField1TS> 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<DataArrayDouble> da2 = da->deepCopy();
+ f->setTime(1.0,1,0);
+ MCAuto<DataArrayDouble> da3 = da2->negate();
+ f->setArray(da3);
+
+ MCAuto<MEDFileField1TS> 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<Fbottom_cells.getNumberOfElements(); i++)
+ Fbottom_cells[i]=300;
+ Fbottom_cells.writeMED("./meshSquare",false);
+ Fbottom_cells.writeVTK("./meshSquare",true);
+ Fbottom_cells.writeCSV("./meshSquare");
+ Field Fbottom_nodes("Bottom_BC",NODES,Mbottom);
+ for(int i=0; i<Fbottom_nodes.getNumberOfElements(); i++)
+ Fbottom_nodes[i]=300;
+ Fbottom_nodes.writeMED("./meshSquare",false);
+ Fbottom_cells.writeVTK("./meshSquare",true);
+ Fbottom_cells.writeCSV("./meshSquare");
}
CPPUNIT_ASSERT(M1.meshNotDeleted());
CPPUNIT_ASSERT(M1.isStructured());
- double x11=M1.getCells()[1].x();
- double y11=M1.getCells()[1].y();
+ double x11=M1.getCell(1).x();
+ double y11=M1.getCell(1).y();
CPPUNIT_ASSERT_EQUAL( x11, 1.5 );
CPPUNIT_ASSERT_EQUAL( y11, 0.0 );
M1.setGroupAtFaceByCoords(0.,0.,0.,1.E-14,"LeftEdge") ;
for(int i=0; i<nbCellsM2; i++)
areaM2+=M2.getCell(i).getMeasure();
CPPUNIT_ASSERT_DOUBLES_EQUAL( 16., areaM2, eps );
- double x1=M2.getCells()[4].x();
- double y1=M2.getCells()[4].y();
+ double x1=M2.getCell(4).x();
+ double y1=M2.getCell(4).y();
CPPUNIT_ASSERT_EQUAL( x1, 0.5 );
CPPUNIT_ASSERT_EQUAL( y1, 1.5 );
- double x2=M2.getNodes()[24].x();
- double y2=M2.getNodes()[24].y();
+ double x2=M2.getNode(24).x();
+ double y2=M2.getNode(24).y();
CPPUNIT_ASSERT_EQUAL( x2, 4. );
CPPUNIT_ASSERT_EQUAL( y2, 4. );
std::map<int,int> indexFaces=M2.getIndexFacePeriodic();
for (int i=0;i<nbFaces;i++)
{
- double x=M2.getFaces()[i].x();
- double y=M2.getFaces()[i].y();
+ double x=M2.getFace(i).x();
+ double y=M2.getFace(i).y();
if (y==0. && x==0.5)
{
int indexFace=M2.getIndexFacePeriodic(i);
indexFaces=M3.getIndexFacePeriodic();
for (int i=0;i<nbFaces;i++)
{
- double x=M3.getFaces()[i].x();
- double y=M3.getFaces()[i].y();
- double z=M3.getFaces()[i].z();
+ double x=M3.getFace(i).x();
+ double y=M3.getFace(i).y();
+ double z=M3.getFace(i).z();
if (z==0. && x==1./8 && y==1./8)
{
int indexFace=M3.getIndexFacePeriodic(i);
CPPUNIT_ASSERT_EQUAL( 40, M22.getNumberOfFaces() );
CPPUNIT_ASSERT_EQUAL( 40, M22.getNumberOfEdges() );
CPPUNIT_ASSERT(M22.meshNotDeleted());
- CPPUNIT_ASSERT(!M22.isStructured());
+ CPPUNIT_ASSERT(M22.isStructured());
cout<<"Test mesh M22 normals "<<endl;
testNormals(M22);
testNormals(M3Tetra);
//Testing a 2D unstructured mesh (triangles)
- Mesh M23("./meshSquare.med");
+ Mesh M23("./meshSquare.med", "Mesh_1", 0);
CPPUNIT_ASSERT(M23.getNameOfFaceGroups().size() == 5);//There is a default group named "Boundary" that is created by the mesh class;
CPPUNIT_ASSERT(M23.getNameOfFaceGroups()[0].compare("Boundary")==0);
CPPUNIT_ASSERT(M23.getNameOfFaceGroups()[1].compare("Bottom")==0);
CPPUNIT_ASSERT_EQUAL( 40, M6.getNumberOfFaces() );
CPPUNIT_ASSERT_EQUAL( 40, M6.getNumberOfEdges() );
CPPUNIT_ASSERT(M6.meshNotDeleted());
- CPPUNIT_ASSERT(!M6.isStructured());
+ CPPUNIT_ASSERT(M6.isStructured());
/*
const MEDCouplingMesh* M1MEDMesh = M2.getMEDCouplingMesh();
CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., volM7, eps );
//Testing deletion of MEDCoupling for unstructured meshes (should not deletethe structured meshes)
- M1.deleteMEDCouplingUMesh();
- M2.deleteMEDCouplingUMesh();
- M23.deleteMEDCouplingUMesh();
- M3.deleteMEDCouplingUMesh();
- M4.deleteMEDCouplingUMesh();
- M5.deleteMEDCouplingUMesh();
- M2Triangle.deleteMEDCouplingUMesh();
- M3Tetra.deleteMEDCouplingUMesh();
+ M1.deleteMEDCouplingMesh();
+ M2.deleteMEDCouplingMesh();
+ M23.deleteMEDCouplingMesh();
+ M3.deleteMEDCouplingMesh();
+ M4.deleteMEDCouplingMesh();
+ M5.deleteMEDCouplingMesh();
+ M2Triangle.deleteMEDCouplingMesh();
+ M3Tetra.deleteMEDCouplingMesh();
//Testting boundary functions
Mesh M5Boundary = M5.getBoundaryMesh ( );
A4.setValue(3,2,15.);
A4.setValue(3,3,16.);
+ A4.viewMatrix();//Display matrix coefficients on the screen
+ A4.viewMatrix(true,0.05, "A4");//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
+ //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) );
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
}