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
This commit is contained in:
parent
2febd03de2
commit
f58393f317
@ -14,56 +14,47 @@
|
||||
#include "HDF5Writer.h"
|
||||
#include "XMLWriter.h"
|
||||
#include "StringUtils.h"
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#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 <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef std::map< std::string,std::vector<XMLWriter::Entry> > ProcessList;
|
||||
typedef std::map< std::string,std::vector<int> > VTFList;
|
||||
|
||||
|
||||
std::vector<ASMbase*> readBasis (const std::string& name,
|
||||
int patches, HDF5Writer& hdf, int dim, int level)
|
||||
int patches, HDF5Writer& hdf,
|
||||
int dim, int level)
|
||||
{
|
||||
unsigned char nf = 1;
|
||||
ASM::Discretization ptype;
|
||||
std::vector<ASMbase*> result;
|
||||
for (int i=0;i<patches;++i) {
|
||||
std::stringstream geom;
|
||||
std::stringstream geom, basis;
|
||||
geom << '/' << level << "/basis/";
|
||||
geom << name;
|
||||
geom << "/";
|
||||
geom << i+1;
|
||||
std::string out;
|
||||
hdf.readString(geom.str(),out);
|
||||
std::stringstream basis;
|
||||
ptype = out.substr(0,10) == "# LRSPLINE" ? ASM::LRSpline : ASM::Spline;
|
||||
basis << out;
|
||||
if (out.substr(0,10) == "# LRSPLINE") {
|
||||
switch (dim) {
|
||||
#if HAS_LRSPLINE == 1
|
||||
case 2:
|
||||
result.push_back(new ASMu2D(basis,2,1));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
} else {
|
||||
if (dim == 1)
|
||||
result.push_back(new ASMs1D(basis,1,1));
|
||||
if (dim == 2)
|
||||
result.push_back(new ASMs2D(basis,2,1));
|
||||
if (dim == 3)
|
||||
result.push_back(new ASMs3D(basis,false,1));
|
||||
else if (dim == 2) {
|
||||
result.push_back(ASM2D::create(ptype,&nf));
|
||||
assert(result.back());
|
||||
result.back()->read(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<x*>(y); \
|
||||
if (t) \
|
||||
t->getGridParameters(gpar[k],k,n[k]-1); \
|
||||
}
|
||||
std::vector<RealArray*> generateFEModel(std::vector<ASMbase*> patches,
|
||||
int dims, int* n)
|
||||
{
|
||||
std::vector<RealArray*> result;
|
||||
result.reserve(patches.size());
|
||||
for (size_t i=0;i<patches.size();++i) {
|
||||
RealArray* gpar = new RealArray[dims];
|
||||
for (int k=0;k<dims;++k) {
|
||||
if (dims == 2) {
|
||||
#if HAS_LRSPLINE == 1
|
||||
TRY(ASMu2D,patches[i])
|
||||
#endif
|
||||
TRY(ASMs2D,patches[i])
|
||||
ASM2D* patch = dynamic_cast<ASM2D*>(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<ASMs3D*>(patches[i]);
|
||||
if (patch) patch->getGridParameters(gpar[k],k,n[k]-1);
|
||||
}
|
||||
}
|
||||
result.push_back(gpar);
|
||||
|
@ -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,11 +380,12 @@ 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:
|
||||
|
105
src/SIM/SIM2D.C
105
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 <fstream>
|
||||
@ -115,7 +110,6 @@ bool SIM2D::parse (char* keyWord, std::istream& is)
|
||||
}
|
||||
|
||||
if (isn.good() && pid > 0)
|
||||
{
|
||||
if (!static_cast<ASMs2D*>(myModel[pid-1])->assignNodeNumbers(n))
|
||||
{
|
||||
std::cerr <<" *** SIM2D::parse: Failed to assign node numbers"
|
||||
@ -124,7 +118,6 @@ bool SIM2D::parse (char* keyWord, std::istream& is)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (!strncasecmp(keyWord,"PROPERTYFILE",12))
|
||||
{
|
||||
@ -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;
|
||||
|
||||
if (pid > 0 && (pch = dynamic_cast<ASM2D*>(myModel[pid-1])))
|
||||
{
|
||||
std::cout <<"\tConstraining P"<< patch
|
||||
<<" point at "<< rx <<" "<< ry
|
||||
<<" with code "<< bcode << std::endl;
|
||||
static_cast<ASMs2D*>(myModel[pid-1])->constrainNode(rx,ry,bcode);
|
||||
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]);
|
||||
std::ifstream is(patchFile);
|
||||
if (!is.good())
|
||||
{
|
||||
std::cerr <<" *** SIM2D: Failure opening patch file"
|
||||
<< patchFile << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (pch->empty() || this->getLocalPatchIndex(pchInd+1) < 1)
|
||||
|
||||
ASMbase* pch = ASM2D::create(discretization,nf);
|
||||
if (pch)
|
||||
{
|
||||
std::cout <<"\nReading patch file "<< patchFile << std::endl;
|
||||
if (!pch->read(is))
|
||||
{
|
||||
delete pch;
|
||||
return false;
|
||||
}
|
||||
else if (pch->empty() || this->getLocalPatchIndex(pchInd+1) < 1)
|
||||
delete pch;
|
||||
else
|
||||
myModel.push_back(pch);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SIM2D::readPatches (std::istream& isp)
|
||||
|
||||
bool SIM2D::readPatches (std::istream& isp)
|
||||
{
|
||||
ASMbase* pch = 0;
|
||||
for (int patchNo = 1; isp.good(); patchNo++)
|
||||
for (int pchInd = 1; isp.good(); pchInd++)
|
||||
if ((pch = ASM2D::create(discretization,nf)))
|
||||
{
|
||||
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::cout <<"Reading patch "<< pchInd << std::endl;
|
||||
if (!pch->read(isp))
|
||||
{
|
||||
delete pch;
|
||||
return false;
|
||||
}
|
||||
if (pch->empty() || this->getLocalPatchIndex(patchNo) < 1)
|
||||
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<int>& elements,
|
||||
const std::vector<int>& 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<ASMu2D*>(myModel[i])->refine(elements,options,fName))
|
||||
#endif
|
||||
if (!myModel[i]->empty() && (pch = dynamic_cast<ASM2D*>(myModel[i])))
|
||||
if (!pch->refine(elements,options,fName))
|
||||
return false;
|
||||
|
||||
isRefined = true;
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
SIMbase::Discretization SIMbase::discretization = SIMbase::Spline;
|
||||
ASM::Discretization SIMbase::discretization = ASM::Spline;
|
||||
bool SIMbase::preserveNOrder = false;
|
||||
bool SIMbase::ignoreDirichlet = false;
|
||||
int SIMbase::num_threads_SLU = 1;
|
||||
@ -283,7 +283,7 @@ bool SIMbase::preprocess (const std::vector<int>& 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 =";
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user