From f58393f317fd45ce2b63bd972ac3649bcc70a88a Mon Sep 17 00:00:00 2001 From: kmo Date: Thu, 27 Oct 2011 16:53:24 +0000 Subject: [PATCH] Some refactoring: Moved instanciation of 2D patches to static create method in ASM2D-scope and Discretization enum to ASM-scope git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@1280 e10b68d5-8a6e-419e-a041-bce267b0401d --- Apps/HDF5toVTx/HDF5toVTx.C | 66 ++++++++----------- src/SIM/SIM1D.C | 13 ++-- src/SIM/SIM2D.C | 129 ++++++++++++++++--------------------- src/SIM/SIM2D.h | 4 +- src/SIM/SIM3D.C | 13 ++-- src/SIM/SIMbase.C | 20 +++--- src/SIM/SIMbase.h | 6 +- 7 files changed, 108 insertions(+), 143 deletions(-) diff --git a/Apps/HDF5toVTx/HDF5toVTx.C b/Apps/HDF5toVTx/HDF5toVTx.C index 3b518186..4d70750f 100644 --- a/Apps/HDF5toVTx/HDF5toVTx.C +++ b/Apps/HDF5toVTx/HDF5toVTx.C @@ -14,56 +14,47 @@ #include "HDF5Writer.h" #include "XMLWriter.h" #include "StringUtils.h" -#include -#include -#include #include "ASMs1D.h" #include "ASMs2D.h" #include "ASMs3D.h" -#if HAS_LRSPLINE == 1 -#include "LR/ASMu2D.h" -#endif #include "ElementBlock.h" #include "VTF.h" #include "VTU.h" - +#include +#include +#include #include typedef std::map< std::string,std::vector > ProcessList; -typedef std::map< std::string, std::vector > VTFList; +typedef std::map< std::string,std::vector > VTFList; -std::vector readBasis(const std::string& name, - int patches, HDF5Writer& hdf, int dim, int level) + +std::vector readBasis (const std::string& name, + int patches, HDF5Writer& hdf, + int dim, int level) { + unsigned char nf = 1; + ASM::Discretization ptype; std::vector result; for (int i=0;iread(basis); } + else if (dim == 3) + result.push_back(new ASMs3D(basis,false,1)); result.back()->generateFEMTopology(); } @@ -157,26 +148,21 @@ void writePatchGeometry(ASMbase* patch, int id, VTF& myVtf, int* nViz, int block } -#define TRY(x,y) { x* t = dynamic_cast(y); \ - if (t) \ - t->getGridParameters(gpar[k],k,n[k]-1); \ - } std::vector generateFEModel(std::vector patches, int dims, int* n) { std::vector result; + result.reserve(patches.size()); for (size_t i=0;i(patches[i]); + if (patch) patch->getGridParameters(gpar[k],k,n[k]-1); } - if (dims == 3) { - ASMs3D* patch = (ASMs3D*)patches[i]; - patch->getGridParameters(gpar[k],k,n[k]-1); + else if (dims == 3) { + ASMs3D* patch = dynamic_cast(patches[i]); + if (patch) patch->getGridParameters(gpar[k],k,n[k]-1); } } result.push_back(gpar); diff --git a/src/SIM/SIM1D.C b/src/SIM/SIM1D.C index a4342e3a..ba06f33f 100644 --- a/src/SIM/SIM1D.C +++ b/src/SIM/SIM1D.C @@ -40,10 +40,10 @@ bool SIM1D::parse (char* keyWord, std::istream& is) for (int i = 0; i < npatch && (cline = utl::readLine(is)); i++) { switch (discretization) { - case Lagrange: + case ASM::Lagrange: pch = new ASMs1DLag(strtok(cline," "),1,nf); break; - case Spectral: + case ASM::Spectral: pch = new ASMs1DSpec(strtok(cline," "),1,nf); break; default: @@ -380,16 +380,17 @@ void SIM1D::readPatches (std::istream& isp) for (int patchNo = 1; isp.good(); patchNo++) { std::cout <<"Reading patch "<< patchNo << std::endl; - switch (discretization) { - case Lagrange: + switch (discretization) + { + case ASM::Lagrange: pch = new ASMs1DLag(isp,1,nf); break; - case Spectral: + case ASM::Spectral: pch = new ASMs1DSpec(isp,1,nf); break; default: pch = new ASMs1D(isp,1,nf); - } + } if (pch->empty()) delete pch; else diff --git a/src/SIM/SIM2D.C b/src/SIM/SIM2D.C index d258b47c..9b2d6f46 100644 --- a/src/SIM/SIM2D.C +++ b/src/SIM/SIM2D.C @@ -12,12 +12,7 @@ //============================================================================== #include "SIM2D.h" -#include "ASMs2Dmx.h" -#include "ASMs2DmxLag.h" -#include "ASMs2DSpec.h" -#ifdef HAS_LRSPLINE -#include "LR/ASMu2D.h" -#endif +#include "ASMs2D.h" #include "Functions.h" #include "Utilities.h" #include @@ -115,14 +110,12 @@ bool SIM2D::parse (char* keyWord, std::istream& is) } if (isn.good() && pid > 0) - { if (!static_cast(myModel[pid-1])->assignNodeNumbers(n)) { std::cerr <<" *** SIM2D::parse: Failed to assign node numbers" <<" for patch "<< patch << std::endl; return false; } - } } } @@ -386,6 +379,7 @@ bool SIM2D::parse (char* keyWord, std::istream& is) if (ignoreDirichlet) return true; // Ignore all boundary conditions if (!this->createFEMmodel()) return false; + ASM2D* pch = 0; int nfix = atoi(keyWord+9); std::cout <<"\nNumber of fixed points: "<< nfix << std::endl; for (int i = 0; i < nfix && (cline = utl::readLine(is)); i++) @@ -393,15 +387,16 @@ bool SIM2D::parse (char* keyWord, std::istream& is) int patch = atoi(strtok(cline," ")); double rx = atof(strtok(NULL," ")); double ry = atof(strtok(NULL," ")); - int bcode = (cline = strtok(NULL," ")) ? atoi(cline) : 123; + int bcode = (cline = strtok(NULL," ")) ? atoi(cline) : 12; int pid = this->getLocalPatchIndex(patch); - if (pid < 1) continue; - - std::cout <<"\tConstraining P"<< patch - <<" point at "<< rx <<" "<< ry - <<" with code "<< bcode << std::endl; - static_cast(myModel[pid-1])->constrainNode(rx,ry,bcode); + if (pid > 0 && (pch = dynamic_cast(myModel[pid-1]))) + { + std::cout <<"\tConstraining P"<< patch + <<" point at "<< rx <<" "<< ry + <<" with code "<< bcode << std::endl; + pch->constrainNode(rx,ry,bcode); + } } } @@ -479,69 +474,54 @@ void SIM2D::setQuadratureRule (size_t ng) } -void SIM2D::readPatch (const char* patchFile, int pchInd) +bool SIM2D::readPatch (const char* patchFile, int pchInd) { - ASMbase* pch = 0; - switch (discretization) { - case Lagrange: - if (nf[1] > 0) - pch = new ASMs2DmxLag(patchFile,2,nf[0],nf[1]); - else - pch = new ASMs2DLag(patchFile,2,nf[0]); - break; - case Spectral: - pch = new ASMs2DSpec(patchFile,2,nf[0]); - break; -#ifdef HAS_LRSPLINE - case LRSpline: - pch = new ASMu2D(patchFile,2,nf[0]); - break; -#endif - default: - if (nf[1] > 0) - pch = new ASMs2Dmx(patchFile,2,nf[0],nf[1]); - else - pch = new ASMs2D(patchFile,2,nf[0]); - } - if (pch->empty() || this->getLocalPatchIndex(pchInd+1) < 1) - delete pch; - else - myModel.push_back(pch); -} - - -void SIM2D::readPatches (std::istream& isp) -{ - ASMbase* pch = 0; - for (int patchNo = 1; isp.good(); patchNo++) + std::ifstream is(patchFile); + if (!is.good()) { - std::cout <<"Reading patch "<< patchNo << std::endl; - switch (discretization) { - case Lagrange: - if (nf[1] > 0) - pch = new ASMs2DmxLag(isp,2,nf[0],nf[1]); - else - pch = new ASMs2DLag(isp,2,nf[0]); - break; - case Spectral: - pch = new ASMs2DSpec(isp,2,nf[0]); - break; - case LRSpline: -#ifdef HAS_LRSPLINE - pch = new ASMu2D(isp,2,nf[0]); - break; -#endif - default: - if (nf[1] > 0) - pch = new ASMs2Dmx(isp,2,nf[0],nf[1]); - else - pch = new ASMs2D(isp,2,nf[0]); + std::cerr <<" *** SIM2D: Failure opening patch file" + << patchFile << std::endl; + return false; + } + + ASMbase* pch = ASM2D::create(discretization,nf); + if (pch) + { + std::cout <<"\nReading patch file "<< patchFile << std::endl; + if (!pch->read(is)) + { + delete pch; + return false; } - if (pch->empty() || this->getLocalPatchIndex(patchNo) < 1) + else if (pch->empty() || this->getLocalPatchIndex(pchInd+1) < 1) delete pch; else myModel.push_back(pch); } + + return true; +} + + +bool SIM2D::readPatches (std::istream& isp) +{ + ASMbase* pch = 0; + for (int pchInd = 1; isp.good(); pchInd++) + if ((pch = ASM2D::create(discretization,nf))) + { + std::cout <<"Reading patch "<< pchInd << std::endl; + if (!pch->read(isp)) + { + delete pch; + return false; + } + else if (pch->empty() || this->getLocalPatchIndex(pchInd) < 1) + delete pch; + else + myModel.push_back(pch); + } + + return true; } @@ -560,11 +540,10 @@ void SIM2D::clonePatches (const FEModelVec& patches, bool SIM2D::refine (const std::vector& elements, const std::vector& options, const char* fName) { + ASM2D* pch = 0; for (size_t i = 0; i < myModel.size(); i++) - if (!myModel.empty()) -#ifdef HAS_LRSPLINE - if (!static_cast(myModel[i])->refine(elements,options,fName)) -#endif + if (!myModel[i]->empty() && (pch = dynamic_cast(myModel[i]))) + if (!pch->refine(elements,options,fName)) return false; isRefined = true; diff --git a/src/SIM/SIM2D.h b/src/SIM/SIM2D.h index 3207a76f..a2fac8ed 100644 --- a/src/SIM/SIM2D.h +++ b/src/SIM/SIM2D.h @@ -51,10 +51,10 @@ protected: //! \brief Reads a patch from given input file. //! \param[in] patchFile Name of file to read from //! \param[in] pchInd 0-based index of the patch to read - void readPatch(const char* patchFile, int pchInd); + bool readPatch(const char* patchFile, int pchInd); //! \brief Reads patches from given input stream. //! \param[in] isp The file stream to read from - void readPatches(std::istream& isp); + bool readPatches(std::istream& isp); //! \brief Refines a list of elements. //! \param[in] elements 1-based indices of the elements to refine diff --git a/src/SIM/SIM3D.C b/src/SIM/SIM3D.C index 267abe93..c0219a5c 100644 --- a/src/SIM/SIM3D.C +++ b/src/SIM/SIM3D.C @@ -43,13 +43,13 @@ bool SIM3D::parse (char* keyWord, std::istream& is) { cline = strtok(cline," "); switch (discretization) { - case Lagrange: + case ASM::Lagrange: if (nf[1] > 0) pch = new ASMs3DmxLag(cline,checkRHSys,nf[0],nf[1]); else pch = new ASMs3DLag(cline,checkRHSys,nf[0]); break; - case Spectral: + case ASM::Spectral: pch = new ASMs3DSpec(cline,checkRHSys,nf[0]); break; default: @@ -598,14 +598,15 @@ void SIM3D::readPatches (std::istream& isp) for (int patchNo = 1; isp.good(); patchNo++) { std::cout <<"Reading patch "<< patchNo << std::endl; - switch (discretization) { - case Lagrange: + switch (discretization) + { + case ASM::Lagrange: if (nf[1] > 0) pch = new ASMs3DmxLag(isp,checkRHSys,nf[0],nf[1]); else pch = new ASMs3DLag(isp,checkRHSys,nf[0]); break; - case Spectral: + case ASM::Spectral: pch = new ASMs3DSpec(isp,checkRHSys,nf[0]); break; default: @@ -613,7 +614,7 @@ void SIM3D::readPatches (std::istream& isp) pch = new ASMs3Dmx(isp,checkRHSys,nf[0],nf[1]); else pch = new ASMs3D(isp,checkRHSys,nf[0]); - } + } if (pch->empty() || this->getLocalPatchIndex(patchNo) < 1) delete pch; else diff --git a/src/SIM/SIMbase.C b/src/SIM/SIMbase.C index 4e178db0..70dc4e2b 100644 --- a/src/SIM/SIMbase.C +++ b/src/SIM/SIMbase.C @@ -37,10 +37,10 @@ #include -SIMbase::Discretization SIMbase::discretization = SIMbase::Spline; -bool SIMbase::preserveNOrder = false; -bool SIMbase::ignoreDirichlet = false; -int SIMbase::num_threads_SLU = 1; +ASM::Discretization SIMbase::discretization = ASM::Spline; +bool SIMbase::preserveNOrder = false; +bool SIMbase::ignoreDirichlet = false; +int SIMbase::num_threads_SLU = 1; SIMbase::SIMbase () : g2l(&myGlb2Loc) @@ -283,7 +283,7 @@ bool SIMbase::preprocess (const std::vector& ignored, bool fixDup) // will map the global node numbers to local node numbers on the current // processor. In serial simulations, the global-to-local mapping will be unity // unless the original global node number sequence had "holes" due to - // duplicated nodes and/or erast patches. + // duplicated nodes and/or erased patches. int ngnod = 0; int renum = 0; if (preserveNOrder) @@ -1225,7 +1225,7 @@ bool SIMbase::writeGlvS (const Vector& psol, const int* nViz, else sID[k++].push_back(nBlock); - if (discretization == Spline) + if (discretization == ASM::Spline || discretization == ASM::SplineC1) { // 3. Projection of secondary solution variables (tensorial splines only) @@ -1305,7 +1305,7 @@ bool SIMbase::writeGlvS (const Vector& psol, const int* nViz, if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,haveAsol?"FE":0), ++idBlock,iStep)) return false; - if (discretization == Spline) + if (discretization == ASM::Spline || discretization == ASM::SplineC1) for (i = 0; i < nf && !sID[j].empty(); i++, j++) if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,"Projected"), ++idBlock,iStep)) return false; @@ -1610,7 +1610,7 @@ bool SIMbase::dumpResults (const Vector& psol, double time, std::ostream& os, // Find all evaluation points within this patch, if any for (j = 0, p = myPoints.begin(); p != myPoints.end(); j++, p++) if (this->getLocalPatchIndex(p->patch) == (int)(i+1)) - if (discretization == Spline || discretization == LRSpline) + if (discretization >= ASM::Spline) { points.push_back(p->inod > 0 ? p->inod : -(j+1)); for (k = 0; k < myModel[i]->getNoParamDim(); k++) @@ -1622,7 +1622,7 @@ bool SIMbase::dumpResults (const Vector& psol, double time, std::ostream& os, if (points.empty()) continue; // no points in this patch myModel[i]->extractNodeVec(psol,myProblem->getSolution()); - if (discretization == Spline || discretization == LRSpline) + if (discretization >= ASM::Spline) { // Evaluate the primary solution variables if (!myModel[i]->evalSolution(sol1,myProblem->getSolution(),params,false)) @@ -1658,7 +1658,7 @@ bool SIMbase::dumpResults (const Vector& psol, double time, std::ostream& os, for (k = 1; k <= sol1.rows(); k++) os << std::setw(flWidth) << utl::trunc(sol1(k,j+1)); - if (discretization == Spline || discretization == LRSpline) + if (discretization >= ASM::Spline) { if (formatted && sol2.rows() > 0) os <<"\n\t\tsol2 ="; diff --git a/src/SIM/SIMbase.h b/src/SIM/SIMbase.h index 4269f008..ddbfd88f 100644 --- a/src/SIM/SIMbase.h +++ b/src/SIM/SIMbase.h @@ -17,6 +17,7 @@ #include "SIMinput.h" #include "SystemMatrix.h" #include "TimeDomain.h" +#include "ASMenums.h" #include "Property.h" #include "Function.h" #include "Vec3.h" @@ -543,10 +544,7 @@ protected: virtual double externalEnergy(const Vectors& psol) const; public: - //! \brief Enum defining the available discretization methods. - enum Discretization { Spline, Lagrange, Spectral, LRSpline }; - - static Discretization discretization; //!< Spatial discretization option + static ASM::Discretization discretization; //!< Spatial discretization option static bool ignoreDirichlet; //!< Set to \e true for free vibration analysis static bool preserveNOrder; //!< Set to \e true to preserve node ordering