mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 21:40:33 +05:00
python - element has material name
This commit is contained in:
parent
1ac9c02f5b
commit
b3591f829a
@ -93,10 +93,10 @@ extern "C" {
|
||||
DLL_HEADER void Ng_SetElementIndex(const int ei, const int index);
|
||||
|
||||
// Get Material of element ei
|
||||
DLL_HEADER char * Ng_GetElementMaterial (int ei);
|
||||
DLL_HEADER const char * Ng_GetElementMaterial (int ei);
|
||||
|
||||
// Get Material of domain dom
|
||||
DLL_HEADER char * Ng_GetDomainMaterial (int dom);
|
||||
DLL_HEADER const char * Ng_GetDomainMaterial (int dom);
|
||||
|
||||
// Get User Data
|
||||
DLL_HEADER int Ng_GetUserDataSize (char * id);
|
||||
|
@ -74,7 +74,7 @@ namespace netgen
|
||||
public:
|
||||
NG_ELEMENT_TYPE type;
|
||||
int index; // material / boundary condition
|
||||
|
||||
const string * mat; // material / boundary label
|
||||
NG_ELEMENT_TYPE GetType() const { return type; }
|
||||
int GetIndex() const { return index-1; }
|
||||
Ng_Points points; // all points
|
||||
|
@ -89,7 +89,12 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (int nr) const
|
||||
|
||||
Ng_Element ret;
|
||||
ret.type = NG_ELEMENT_TYPE(el.GetType());
|
||||
ret.index = mesh->GetFaceDescriptor(el.GetIndex()).BCProperty();
|
||||
const FaceDescriptor & fd = mesh->GetFaceDescriptor(el.GetIndex());
|
||||
ret.index = fd.BCProperty();
|
||||
if (mesh->GetDimension() == 3)
|
||||
ret.mat = &fd.GetBCName();
|
||||
else
|
||||
ret.mat = mesh -> GetMaterialPtr(ret.index);
|
||||
ret.points.num = el.GetNP();
|
||||
ret.points.ptr = (int*)&el[0];
|
||||
|
||||
@ -114,7 +119,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (int nr) const
|
||||
Ng_Element ret;
|
||||
ret.type = NG_ELEMENT_TYPE(el.GetType());
|
||||
ret.index = el.GetIndex();
|
||||
|
||||
ret.mat = mesh -> GetMaterialPtr(ret.index);
|
||||
ret.points.num = el.GetNP();
|
||||
ret.points.ptr = (int*)&el[0];
|
||||
|
||||
|
@ -399,16 +399,17 @@ void Ng_SetElementIndex(const int ei, const int index)
|
||||
mesh->VolumeElement(ei).SetIndex(index);
|
||||
}
|
||||
|
||||
char * Ng_GetElementMaterial (int ei)
|
||||
const char * Ng_GetElementMaterial (int ei)
|
||||
{
|
||||
static char empty[] = "";
|
||||
if (mesh->GetDimension() == 3)
|
||||
{
|
||||
int ind = mesh->VolumeElement(ei).GetIndex();
|
||||
// cout << "ind = " << ind << endl;
|
||||
const char * mat = mesh->GetMaterial (ind);
|
||||
const string * mat = mesh->GetMaterialPtr (ind);
|
||||
if (mat)
|
||||
return const_cast<char*> (mat);
|
||||
// return const_cast<char*> (mat);
|
||||
return mat->c_str();
|
||||
else
|
||||
return empty;
|
||||
}
|
||||
@ -417,24 +418,24 @@ char * Ng_GetElementMaterial (int ei)
|
||||
{
|
||||
int ind = mesh->SurfaceElement(ei).GetIndex();
|
||||
ind = mesh->GetFaceDescriptor(ind).BCProperty();
|
||||
const char * mat = mesh->GetMaterial ( ind );
|
||||
const string * mat = mesh->GetMaterialPtr ( ind );
|
||||
if (mat)
|
||||
return const_cast<char*> (mat);
|
||||
return mat->c_str();
|
||||
else
|
||||
return empty;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char * Ng_GetDomainMaterial (int dom)
|
||||
const char * Ng_GetDomainMaterial (int dom)
|
||||
{
|
||||
static char empty[] = "";
|
||||
// astrid
|
||||
if ( 1 ) // mesh->GetDimension() == 3)
|
||||
{
|
||||
const char * mat = mesh->GetMaterial(dom);
|
||||
const string * mat = mesh->GetMaterialPtr(dom);
|
||||
if (mat)
|
||||
return const_cast<char*> (mat);
|
||||
return mat->c_str();
|
||||
else
|
||||
return empty;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ void WriteJCMFormat (const Mesh & mesh,
|
||||
int nDomains=mesh.GetNDomains();
|
||||
for (i=1; i<=nDomains; i++)
|
||||
{
|
||||
if (mesh.GetMaterial(i))
|
||||
if (mesh.GetMaterialPtr(i))
|
||||
outfile << "#" << mesh.GetMaterial(i)
|
||||
<< ": Material ID = "
|
||||
<< i << "\n";
|
||||
|
@ -63,15 +63,14 @@ namespace netgen
|
||||
delete hpelements;
|
||||
|
||||
for (int i = 0; i < materials.Size(); i++)
|
||||
delete [] materials[i];
|
||||
|
||||
delete materials[i];
|
||||
for(int i = 0; i < userdata_int.Size(); i++)
|
||||
delete userdata_int[i];
|
||||
for(int i = 0; i < userdata_double.Size(); i++)
|
||||
delete userdata_double[i];
|
||||
|
||||
for (int i = 0; i < bcnames.Size(); i++ )
|
||||
if ( bcnames[i] ) delete bcnames[i];
|
||||
delete bcnames[i];
|
||||
|
||||
#ifdef PARALLEL
|
||||
delete paralleltop;
|
||||
@ -587,7 +586,7 @@ namespace netgen
|
||||
|
||||
int cntmat = 0;
|
||||
for (i = 1; i <= materials.Size(); i++)
|
||||
if (materials.Get(i) && strlen (materials.Get(i)))
|
||||
if (materials.Get(i) && materials.Get(i)->length())
|
||||
cntmat++;
|
||||
|
||||
if (cntmat)
|
||||
@ -595,7 +594,7 @@ namespace netgen
|
||||
outfile << "materials" << endl;
|
||||
outfile << cntmat << endl;
|
||||
for (i = 1; i <= materials.Size(); i++)
|
||||
if (materials.Get(i) && strlen (materials.Get(i)))
|
||||
if (materials.Get(i) && materials.Get(i)->length())
|
||||
outfile << i << " " << materials.Get(i) << endl;
|
||||
}
|
||||
|
||||
@ -5541,7 +5540,7 @@ namespace netgen
|
||||
SetNextMajorTimeStamp();
|
||||
}
|
||||
|
||||
void Mesh :: SetMaterial (int domnr, const char * mat)
|
||||
void Mesh :: SetMaterial (int domnr, const string & mat)
|
||||
{
|
||||
if (domnr > materials.Size())
|
||||
{
|
||||
@ -5550,15 +5549,19 @@ namespace netgen
|
||||
for (int i = olds; i < domnr; i++)
|
||||
materials[i] = 0;
|
||||
}
|
||||
/*
|
||||
materials.Elem(domnr) = new char[strlen(mat)+1];
|
||||
strcpy (materials.Elem(domnr), mat);
|
||||
*/
|
||||
materials.Elem(domnr) = new string(mat);
|
||||
}
|
||||
|
||||
const char * Mesh :: GetMaterial (int domnr) const
|
||||
const string & Mesh :: GetMaterial (int domnr) const
|
||||
{
|
||||
if (domnr <= materials.Size())
|
||||
return materials.Get(domnr);
|
||||
return 0;
|
||||
return *materials.Get(domnr);
|
||||
static string emptystring;
|
||||
return emptystring;
|
||||
}
|
||||
|
||||
void Mesh ::SetNBCNames ( int nbcn )
|
||||
|
@ -82,7 +82,7 @@ namespace netgen
|
||||
Array<EdgeDescriptor> edgedecoding;
|
||||
|
||||
/// sub-domain materials
|
||||
Array<char*> materials;
|
||||
Array<string*> materials;
|
||||
|
||||
/// labels for boundary conditions
|
||||
Array<string*> bcnames;
|
||||
@ -573,9 +573,11 @@ namespace netgen
|
||||
{ return edgedecoding.Append(fd) - 1; }
|
||||
|
||||
///
|
||||
DLL_HEADER void SetMaterial (int domnr, const char * mat);
|
||||
DLL_HEADER void SetMaterial (int domnr, const string & mat);
|
||||
///
|
||||
const char * GetMaterial (int domnr) const;
|
||||
const string & GetMaterial (int domnr) const;
|
||||
const string * GetMaterialPtr (int domnr) const // 1-based
|
||||
{ return domnr <= materials.Size() ? materials.Get(domnr) : nullptr; }
|
||||
|
||||
DLL_HEADER void SetNBCNames ( int nbcn );
|
||||
|
||||
@ -583,7 +585,7 @@ namespace netgen
|
||||
|
||||
const string & GetBCName ( int bcnr ) const;
|
||||
|
||||
string * GetBCNamePtr ( int bcnr )
|
||||
string * GetBCNamePtr (int bcnr) const
|
||||
{ return bcnr < bcnames.Size() ? bcnames[bcnr] : nullptr; }
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user