MV_Vector operator-(const MV_Vector &x, const MV_Vector &y) { unsigned int N = x.size(); if (N != y.size()) { cout << "Incompatible vector lengths in -." << endl; exit(1); } MV_Vector result(N); for (unsigned int i=0;i<N; i++) result(i) = x(i) - y(i); return result; }
real dot(const MV_Vector &x, const MV_Vector &y) { // Check for compatible dimensions: if (x.size() != y.size()) { cout << "Incompatible dimensions in dot(). " << endl; exit(1); } real temp = 0; for (unsigned int i=0; i<x.size();i++) temp += x(i)*y(i); return temp; }
MV_Vector operator*(const real &a, const MV_Vector &x) { int N = x.size(); MV_Vector result(N); for (int i=0;i<N;i++) result(i) = x(i)*a; return result; }
double Maxim(MV_Vector<double> Gradient) { double maxim = Gradient(0); for (int i = 0; i < Gradient.size(); i++) if (Gradient(i) > maxim) maxim = Gradient(i); return maxim; }
MV_Vector operator*(const MV_Vector &x, const real &a) { // This is the other commutative case of vector*scalar. // It should be just defined to be // "return operator*(a,x);" // but some compilers (e.g. Turbo C++ v.3.0) have trouble // determining the proper template match. For the moment, // we'll just duplicate the code in the scalar * vector // case above. int N = x.size(); MV_Vector result(N); for (int i=0;i<N;i++) result(i) = x(i)*a; return result; }
bool WavesSparseDS::fillJcol(MV_Vector<int>& jcol_vector, const int no_nonzero) { // redimIrow must be called prior to fillJcol! // general use: redimIrow - compute jcol_vector - fillJcol bool b = (jcol_arr.size() != no_nonzero) ? true : false; if (irow(nrows) != no_nonzero || jcol_vector.size() < no_nonzero) { cout << "WavesSparseDS::fillJcol irow and jcol are not consistent.\n" << flush; } jcol_arr.newsize(no_nonzero); //redim and copy for (int i = 0; i < no_nonzero; i++) jcol_arr(i) = jcol_vector(i); nonzeroes = jcol_length = jcol_arr.size(); // exact length diagonal_computed = false; //the diagonal is not yet computed return b; }
int main(int argc, char **argv) { if (argc > 1) { // get the input parameters from the .dat file: double dxFEM, dyFEM, dzFEM, x_minFEM, y_minFEM, z_minFEM; int nsd, NxFEM, NyFEM, NzFEM; int NoObjects, i; char* fname = argv[1]; WavesOutputs out1; //load the geometrical parameters: out1.load_FEM_parameters(fname, nsd, NxFEM, NyFEM, NzFEM, dxFEM, dyFEM, dzFEM, x_minFEM, y_minFEM, z_minFEM, NoObjects); // create the mesh for the homogeneous medium: ElementType etype = ELMTET1; // Create the FDM grid in the FEM domain: WavesSDGeometry outer1(NxFEM, NyFEM, NzFEM, nsd, dxFEM, dyFEM, dzFEM, x_minFEM, y_minFEM, z_minFEM); // initialize FEM mesh using structure of FDM mesh (outer1) WavesGridB tet1; makeGrid(outer1,tet1,etype,1); WavesOptional opt(tet1); // add the objects into the mesh: MV_Vector<double> Markers; Markers.newsize(tet1.getNoNodes()); string objecttype; MV_Vector<double> Coord(6); Coord = 0.0; double velocity; int TypeOfMat; MV_Vector<double> MatVec(tet1.getNoNodes()); //vector of coefficient values at nodes MatVec = 1.0; cout << "Number of objects: " << NoObjects << endl; for (i = 0; i < NoObjects; i++) { objecttype = out1.load_object_type(fname, i); cout << "Object no. " << i+1 << ": object type: " << objecttype << endl; out1.load_object_parameters(fname, i, TypeOfMat, velocity, Coord); cout << "Type of Material and velocity: " << TypeOfMat << " " << velocity << endl; SetMatType(tet1, objecttype, TypeOfMat, Coord); SetMat(tet1, objecttype, velocity, Coord, MatVec); //SetMat2(tet1, objecttype, velocity, Coord, dxFEM, dyFEM, dzFEM, MatVec); for (int j=0;j < 6; j++) cout << Coord(j) << " "; cout << endl; } cout << "Max of Material " << Maxim(MatVec) << endl; WavesOutputs out(tet1, Markers); string FEMGridFileName = out1.FEM_grid_file_name(fname); const char* FEMGridFile = FEMGridFileName.c_str(); tet1.print(FEMGridFile); if (argc >2) { char* fname1 = argv[2]; opt.writeInp3D(fname1, &tet1, MatVec,1); } if (argc > 3) // save the coefficient: { char* fname2 = argv[3]; ofstream output; output.open(fname2); if (output.is_open()) { for (int i = 0; i < MatVec.size(); i++) output << MatVec(i) << " "; output.close(); } } // extract the boundary nodes: double x, y, z, x_maxFEM, y_maxFEM, z_maxFEM; int ii, bd_idx; bd_idx = 0; x_maxFEM = x_minFEM + (NxFEM-1)*dxFEM; y_maxFEM = y_minFEM + (NyFEM-1)*dyFEM; z_maxFEM = z_minFEM + (NzFEM-1)*dzFEM; for (ii = 0; ii < tet1.getNoNodes(); ii++) { x = tet1.getCoor(ii,0); y = tet1.getCoor(ii,1); z = tet1.getCoor(ii,2); if ((x - x_minFEM)*(x - x_maxFEM)*(y - y_minFEM)*(y - y_maxFEM)*(z-z_minFEM)*(z - z_maxFEM) == 0) { bd_idx +=1; } } cout << "Number of boundary nodes: " << bd_idx << endl; // save the boundary grid file: string bdgridFile = out.boundary_grid_file_name(argv[1]); const char* BoundaryGridFile = bdgridFile.c_str(); FILE* fp = fopen(BoundaryGridFile,"w"); fprintf(fp, "%i \n", bd_idx); for (ii = 0; ii < tet1.getNoNodes(); ii++) { x = tet1.getCoor(ii,0); y = tet1.getCoor(ii,1); z = tet1.getCoor(ii,2); if ( (x - x_minFEM)*(x - x_maxFEM)*(y - y_minFEM)*(y - y_maxFEM)*(z - z_minFEM)*(z - z_maxFEM) == 0 ) fprintf(fp, "%i %f %f %f\n", ii+1, x, y, z); } fclose(fp); cout << "Boundary grid written to the file: " << BoundaryGridFile << endl; } else cout << "Not enough input " << endl; return 0; }