Skip to content
Snippets Groups Projects
Commit 02742ad3 authored by Van Dung NGUYEN's avatar Van Dung NGUYEN
Browse files

add func

parent 356156f4
No related branches found
No related tags found
1 merge request!309Master
...@@ -26,7 +26,7 @@ activationFunction* activationFunction::createActivationFunction(const char what ...@@ -26,7 +26,7 @@ activationFunction* activationFunction::createActivationFunction(const char what
else if (strcmp(what, "rectifier")==0) else if (strcmp(what, "rectifier")==0)
{ {
Msg::Info("create RectifierActivationFunction"); Msg::Info("create RectifierActivationFunction");
return new RectifierActivationFunction(); return new RectifierActivationFunction(10.);
} }
else if (strcmp(what, "linear")==0) else if (strcmp(what, "linear")==0)
{ {
......
...@@ -60,14 +60,16 @@ class SquareActivationFunction: public activationFunction ...@@ -60,14 +60,16 @@ class SquareActivationFunction: public activationFunction
class RectifierActivationFunction: public activationFunction class RectifierActivationFunction: public activationFunction
{ {
protected:
double _fact;
public: public:
RectifierActivationFunction(){} RectifierActivationFunction(double f=10.): activationFunction(),_fact(f){}
RectifierActivationFunction(const RectifierActivationFunction& src): activationFunction(src){} RectifierActivationFunction(const RectifierActivationFunction& src): activationFunction(src){}
virtual ~RectifierActivationFunction(){} virtual ~RectifierActivationFunction(){}
virtual activationFunction::functionType getType() const {return activationFunction::rectifier;}; virtual activationFunction::functionType getType() const {return activationFunction::rectifier;};
virtual std::string getName() const {return "rectifier";}; virtual std::string getName() const {return "rectifier";};
virtual double getVal(double x) const {return (log(1.+exp(10.*x)))/10.;}; virtual double getVal(double x) const {return (log(1.+exp(_fact*x)))/_fact;};
virtual double getDiff(double x) const {return exp(10.*x)/(1.+exp(10.*x));}; virtual double getDiff(double x) const {return exp(_fact*x)/(1.+exp(_fact*x));};
virtual activationFunction* clone() const {return new RectifierActivationFunction(*this);}; virtual activationFunction* clone() const {return new RectifierActivationFunction(*this);};
}; };
......
...@@ -149,7 +149,11 @@ void makePhysicalByBox::write_MSH2(const std::map<int, elementGroup>& gMap, con ...@@ -149,7 +149,11 @@ void makePhysicalByBox::write_MSH2(const std::map<int, elementGroup>& gMap, con
bool makePhysicalByBox::box::inBox(MElement* ele) const bool makePhysicalByBox::box::inBox(MElement* ele) const
{ {
SPoint3 P = ele->barycenter(); SPoint3 P = ele->barycenter();
if ( (P.x() >=xmin)&& (P.x()<=xmax) && (P.y() >=ymin)&& (P.y()<=ymax)) SPoint3 Pc;
Pc[0] = 0.5*(xmax+xmin);
Pc[1] = 0.5*(ymax+ymin);
Pc[2] = 0.;
if ((P.distance(Pc) < r) && ( (P.x() >=xmin)&& (P.x()<=xmax) && (P.y() >=ymin)&& (P.y()<=ymax)))
{ {
return true; return true;
} }
...@@ -173,6 +177,7 @@ void makePhysicalByBox::run(const std::string inputMeshFile, const std::string o ...@@ -173,6 +177,7 @@ void makePhysicalByBox::run(const std::string inputMeshFile, const std::string o
{ {
allBox.emplace_back(); allBox.emplace_back();
box& b = allBox.back(); box& b = allBox.back();
b.r = 0.3*std::min(dx,dy);
b.xmin = xmin+i*dx; b.xmin = xmin+i*dx;
b.xmax = xmin+(i+1)*dx; b.xmax = xmin+(i+1)*dx;
b.ymin = ymin+j*dy; b.ymin = ymin+j*dy;
...@@ -193,21 +198,29 @@ void makePhysicalByBox::run(const std::string inputMeshFile, const std::string o ...@@ -193,21 +198,29 @@ void makePhysicalByBox::run(const std::string inputMeshFile, const std::string o
std::map<int, std::vector<GEntity*> > &entmap = groups[dim]; std::map<int, std::vector<GEntity*> > &entmap = groups[dim];
std::map<int, elementGroup> allG; std::map<int, elementGroup> allG;
int boxSize = allBox.size();
for (std::map<int, std::vector<GEntity*> >::iterator it = entmap.begin(); it!= entmap.end(); it++){ for (std::map<int, std::vector<GEntity*> >::iterator it = entmap.begin(); it!= entmap.end(); it++){
std::vector<GEntity*> &ent = it->second; std::vector<GEntity*> &ent = it->second;
for (unsigned int i = 0; i < ent.size(); i++){ for (unsigned int i = 0; i < ent.size(); i++){
for (unsigned int j = 0; j < ent[i]->getNumMeshElements(); j++){ for (unsigned int j = 0; j < ent[i]->getNumMeshElements(); j++){
MElement *e = ent[i]->getMeshElement(j); MElement *e = ent[i]->getMeshElement(j);
bool found = false;
for (int num=0; num < allBox.size(); num++) for (int num=0; num < allBox.size(); num++)
{ {
box& b = allBox[num]; box& b = allBox[num];
if (b.inBox(e)) if (b.inBox(e))
{ {
elementGroup& gr = allG[num]; elementGroup& gr = allG[1];
gr.insert(e); gr.insert(e);
found = true;
break; break;
} }
} }
if (!found)
{
elementGroup& gr = allG[boxSize];
gr.insert(e);
}
} }
} }
} }
......
...@@ -93,7 +93,8 @@ class makePhysicalByBox ...@@ -93,7 +93,8 @@ class makePhysicalByBox
{ {
public: public:
double xmin, xmax, ymin, ymax; double xmin, xmax, ymin, ymax;
box():xmin(0.),xmax(0.),ymin(0.),ymax(0.){} double r; //
box():xmin(0.),xmax(0.),ymin(0.),ymax(0.), r(0.){}
~box(){} ~box(){}
bool inBox(MElement* ele) const; bool inBox(MElement* ele) const;
void printData() const void printData() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment