From 84d30e81f7370ee3a235b043c88d00f2c6cbebd4 Mon Sep 17 00:00:00 2001 From: Van Dung NGUYEN <vdg.nguyen@gmail.com> Date: Fri, 3 Feb 2023 23:36:36 +0100 Subject: [PATCH] get bounds of fitting parameters --- NonLinearSolver/modelReduction/Optimizer.h | 5 ++ .../TrainingArbitraryDeepMaterialNetworks.cpp | 10 ++- .../TrainingArbitraryDeepMaterialNetworks.h | 2 + .../TrainingDeepMaterialNetworks.cpp | 79 ++++++++++++++++++- .../TrainingDeepMaterialNetworks.h | 2 + .../TrainingDeepMaterialNetworksNonLinear.cpp | 7 ++ .../TrainingDeepMaterialNetworksNonLinear.h | 2 + 7 files changed, 105 insertions(+), 2 deletions(-) diff --git a/NonLinearSolver/modelReduction/Optimizer.h b/NonLinearSolver/modelReduction/Optimizer.h index e36297d57..d3db3e9fd 100644 --- a/NonLinearSolver/modelReduction/Optimizer.h +++ b/NonLinearSolver/modelReduction/Optimizer.h @@ -53,6 +53,11 @@ class LossFunction */ virtual void initializeFittingParameters(fullVector<double>& W) = 0; + /*! @param[out] WLower lower bound of the fitting parameters + * @param[out] WUpper upper bound of the fitting parameters + */ + virtual void getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const = 0; + /*! \brief update the model with the new fitting parameter @param[in] W the fitting parameters */ diff --git a/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.cpp b/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.cpp index 89bff9c5e..0cf2d4d7a 100644 --- a/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.cpp +++ b/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.cpp @@ -870,7 +870,15 @@ void TrainingDeepMaterialNetworkLinearElastic::saveModel(const std::string fname void TrainingDeepMaterialNetworkLinearElastic::initializeFittingParameters(fullVector<double>& W) { numberDofs(W); -} +}; + +// get bounds of fitting parmaters +void TrainingDeepMaterialNetworkLinearElastic::getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const +{ + Msg::Error("TrainingDeepMaterialNetworkLinearElastic::getUnknownBounds has not been implemeneted"); + Msg::Exit(1); +}; + // update the model with the new fitting parameter void TrainingDeepMaterialNetworkLinearElastic::updateModelFromFittingParameters(const fullVector<double>& W) { diff --git a/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.h b/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.h index d5373ff21..6b031e0bd 100644 --- a/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.h +++ b/NonLinearSolver/modelReduction/TrainingArbitraryDeepMaterialNetworks.h @@ -106,6 +106,8 @@ class TrainingDeepMaterialNetworkLinearElastic : public TrainingArbitraryDeepMat virtual void saveModel(const std::string fname) const; // start numbering fitting parameters virtual void initializeFittingParameters(fullVector<double>& W); + // get bounds of fitting parmaters + virtual void getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const; // update the model with the new fitting parameter virtual void updateModelFromFittingParameters(const fullVector<double>& W); // in case of fails diff --git a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.cpp b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.cpp index 3c963eec9..9f010a115 100644 --- a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.cpp +++ b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.cpp @@ -4028,7 +4028,84 @@ void TrainingDeepMaterialNetwork::saveModel(const std::string fname) const void TrainingDeepMaterialNetwork::initializeFittingParameters(fullVector<double>& W) { numberDofs(W); -} +}; + +void TrainingDeepMaterialNetwork::getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const +{ + // Dof of all nodes + Tree::nodeContainer allNodes; + _T->getAllNodes(allNodes); + + // initialize data from tree + // + int sizeOfR = _unknown.size(); + WLower.resize(sizeOfR,true); + WUpper.resize(sizeOfR,true); + // + for (int i=0; i< allNodes.size(); i++) + { + const TreeNode& node = *(allNodes[i]); + std::vector<Dof> R; + getKeys(&node,R); + int Rsize = R.size(); + if (node.childs.size() ==0) + { + int numCoh = 0; + int numCohDirVars = 0; + if (node.withCohesive()) + { + numCoh = node.cohesiveCoeffVars.size(); + numCohDirVars = node.cohesiveDirectionVars.size2(); + } + for (int j=0; j< Rsize; j++) + { + std::map<Dof,int>::const_iterator itR = _unknown.find(R[j]); + if (itR != _unknown.end()) + { + if (j == 0) + { + // leaf + WLower(itR->second) = node.af->getReciprocalVal(0.001); + WUpper(itR->second) = node.af->getReciprocalVal(1); + } + else if ((j > 0) && (j< numCoh+1)) + { + WLower(itR->second) = 0.1; + WUpper(itR->second) = 0.9; + } + else if ((j >= numCoh+1) && (j < numCoh*numCohDirVars+numCoh+1)) + { + int index = j -(numCoh+1); + int k = index/numCohDirVars; + int l = index%numCohDirVars; + //Msg::Info("index = %d k=%d, l=%d",index,k,l); + WLower(itR->second) = 0; + WUpper(itR->second) = 1.; + } + else + { + Msg::Error("wrong position"); + Msg::Exit(0); + } + }; + } + } + else + { + for (int j=0; j< Rsize; j++) + { + std::map<Dof,int>::const_iterator itR = _unknown.find(R[j]); + if (itR != _unknown.end()) + { + WLower(itR->second) = 0; + WUpper(itR->second) = 1.; + }; + } + } + }; +}; + + // update the model with the new fitting parameter void TrainingDeepMaterialNetwork::updateModelFromFittingParameters(const fullVector<double>& W) { diff --git a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.h b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.h index 34a1849a0..8e5de7ed1 100644 --- a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.h +++ b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworks.h @@ -403,6 +403,8 @@ class TrainingDeepMaterialNetwork : public LossFunction virtual void saveModel(const std::string fname) const; // start numbering fitting parameters virtual void initializeFittingParameters(fullVector<double>& W); + // get bounds of fitting paraeters + virtual void getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const; // update the model with the new fitting parameter virtual void updateModelFromFittingParameters(const fullVector<double>& W); // in case of fails diff --git a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.cpp b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.cpp index 7d2752e00..6f2d9b106 100644 --- a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.cpp +++ b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.cpp @@ -1811,6 +1811,13 @@ void TrainingDeepMaterialNetworkNonLinear::initializeFittingParameters(fullVecto { numberDofs(W); } + +// get bounds of fitting parmaters +void TrainingDeepMaterialNetworkNonLinear::getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const +{ + Msg::Error("TrainingDeepMaterialNetworkNonLinear::getUnknownBounds has not been implemeneted"); + Msg::Exit(1); +}; // update the model with the new fitting parameter void TrainingDeepMaterialNetworkNonLinear::updateModelFromFittingParameters(const fullVector<double>& W) { diff --git a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.h b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.h index 5dbafa399..3bf011cd2 100644 --- a/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.h +++ b/NonLinearSolver/modelReduction/TrainingDeepMaterialNetworksNonLinear.h @@ -208,6 +208,8 @@ class TrainingDeepMaterialNetworkNonLinear : public TrainingArbitraryDeepMateria virtual void saveModel(const std::string fname) const; // start numbering fitting parameters virtual void initializeFittingParameters(fullVector<double>& W); + // get bounds of fitting paraeters + virtual void getUnknownBounds(fullVector<double>& WLower, fullVector<double>& WUpper) const; // update the model with the new fitting parameter virtual void updateModelFromFittingParameters(const fullVector<double>& W); // in case of fails -- GitLab