7 #include "GmshConfig.h"
23 #if defined(HAVE_POST)
74 if(dim == 3 ||
_dim == 3)
76 else if(dim == 2 ||
_dim == 2)
88 std::string sysname =
"A";
93 FILE *
f =
Fopen(
"K.txt",
"w");
98 fprintf(
f,
"%+e ", valeur);
108 fprintf(
f,
"%+e\n", valeur);
116 std::string sysname =
"A";
120 #if defined(HAVE_PETSC)
122 #elif defined(HAVE_GMM)
131 printf(
"-- done solving!\n");
143 printf(
"elastic energy=%f\n", energ);
159 printf(
"elastic energy=%f\n", energ);
164 FILE *
f =
Fopen(fn.c_str(),
"r");
166 Msg::Error(
"Could not open file '%s'", fn.c_str());
171 if(fscanf(
f,
"%s", what) != 1) {
177 if(fgets(buffer,
sizeof(buffer),
f) ==
nullptr)
180 else if(!strcmp(what,
"ElasticDomain")) {
183 if(fscanf(
f,
"%d %lf %lf", &physical, &field.
_e, &field.
_nu) != 3) {
191 else if(!strcmp(what,
"LagrangeMultipliers")) {
194 double d1, d2, d3, val;
195 if(fscanf(
f,
"%d %lf %lf %lf %lf %lf %d", &physical, &field.
_tau, &d1,
196 &d2, &d3, &val, &field.
_tag) != 7) {
208 else if(!strcmp(what,
"Void")) {
211 if(fscanf(
f,
"%d", &physical) != 1) {
215 field.
_e = field.
_nu = 0;
220 else if(!strcmp(what,
"NodeDisplacement")) {
223 if(fscanf(
f,
"%d %d %lf", &node, &comp, &val) != 3) {
235 else if(!strcmp(what,
"EdgeDisplacement")) {
238 if(fscanf(
f,
"%d %d %lf", &edge, &comp, &val) != 3) {
250 else if(!strcmp(what,
"FaceDisplacement")) {
253 if(fscanf(
f,
"%d %d %lf", &face, &comp, &val) != 3) {
265 else if(!strcmp(what,
"NodeForce")) {
266 double val1, val2, val3;
268 if(fscanf(
f,
"%d %lf %lf %lf", &node, &val1, &val2, &val3) != 4) {
279 else if(!strcmp(what,
"EdgeForce")) {
280 double val1, val2, val3;
282 if(fscanf(
f,
"%d %lf %lf %lf", &edge, &val1, &val2, &val3) != 4) {
293 else if(!strcmp(what,
"FaceForce")) {
294 double val1, val2, val3;
296 if(fscanf(
f,
"%d %lf %lf %lf", &face, &val1, &val2, &val3) != 4) {
307 else if(!strcmp(what,
"VolumeForce")) {
308 double val1, val2, val3;
310 if(fscanf(
f,
"%d %lf %lf %lf", &volume, &val1, &val2, &val3) != 4) {
321 else if(!strcmp(what,
"MeshFile")) {
323 if(fscanf(
f,
"%s", name) != 1) {
329 else if(!strcmp(what,
"CutMeshPlane")) {
331 if(fscanf(
f,
"%lf %lf %lf %lf", &a, &b, &
c, &d) != 4) {
340 else if(!strcmp(what,
"CutMeshSphere")) {
342 if(fscanf(
f,
"%lf %lf %lf %lf", &x, &y, &
z, &r) != 4) {
351 else if(!strcmp(what,
"CutMeshMathExpr")) {
353 if(fscanf(
f,
"%s", expr) != 1) {
357 std::string exprS(expr);
429 diri.
_comp = component;
430 diri.
_tag = entityId;
452 const std::vector<double> value)
454 if(value.size() != 3)
return;
473 const std::vector<double> value)
537 for(std::size_t i = 0; i <
allNeumann.size(); i++) {
551 printf(
"Lagrange Mult Lag\n");
560 printf(
"Lagrange Mult Lap\n");
567 printf(
"Lagrange Mult Load\n");
590 double st[6] = {0., 0., 0., 0., 0., 0.};
602 std::vector<SVector3> val(nbVertex);
607 for(
int k = 0; k < nbVertex; k++) {
610 Field.f(&p, 0, 0, 0, val[k]);
620 double u = center.
x(), v = center.
y(), w = center.
z();
625 double eps[6] = {gradux[0],
628 0.5 * (gradux[1] + graduy[0]),
629 0.5 * (gradux[2] + graduz[0]),
630 0.5 * (graduy[2] + graduz[1])};
632 double A = E / (1. + nu);
633 double B = A * (nu / (1. - 2 * nu));
634 double trace = eps[0] + eps[1] + eps[2];
635 st[0] += (A * eps[0] + B * trace) * vol;
636 st[1] += (A * eps[1] + B * trace) * vol;
637 st[2] += (A * eps[2] + B * trace) * vol;
638 st[3] += (A * eps[3]) * vol;
639 st[4] += (A * eps[4]) * vol;
640 st[5] += (A * eps[5]) * vol;
644 for(
int i = 0; i < 6; i++) stiff[i] = st[i] / volTot;
649 double st[6] = {0., 0., 0., 0., 0., 0.};
659 std::vector<SVector3> val(nbVertex);
664 for(
int k = 0; k < nbVertex; k++) {
667 Field.f(&p, 0, 0, 0, val[k]);
677 double u = center.
x(), v = center.
y(), w = center.
z();
682 st[0] += gradux[0] * vol;
683 st[1] += graduy[1] * vol;
684 st[2] += graduz[2] * vol;
685 st[3] += 0.5 * (gradux[1] + graduy[0]) * vol;
686 st[4] += 0.5 * (gradux[2] + graduz[0]) * vol;
687 st[5] += 0.5 * (graduy[2] + graduz[1]) * vol;
691 for(
int i = 0; i < 6; i++) strain[i] = st[i] / volTot;
698 std::cout <<
"compute displacement error" << std::endl;
700 std::set<MVertex *> v;
701 std::map<MVertex *, MElement *> vCut;
710 if(vCut.find(e->
getVertex(j)) == vCut.end())
721 for(
auto it = v.begin(); it != v.end(); ++it) {
724 Field.f(&p, 0, 0, 0, val);
725 SVector3 sol((*f0)((*it)->x(), (*it)->y(), (*it)->z()),
726 (*f1)((*it)->x(), (*it)->y(), (*it)->z()),
727 (*f2)((*it)->x(), (*it)->y(), (*it)->z()));
728 double diff =
normSq(sol - val);
731 for(
auto it = vCut.begin();
732 it != vCut.end(); ++it) {
735 double xyz[3] = {it->first->
x(), it->first->y(), it->first->z()};
736 it->second->xyz2uvw(xyz, uvw);
737 Field.f(it->second, uvw[0], uvw[1], uvw[2], val);
738 SVector3 sol((*f0)(xyz[0], xyz[1], xyz[2]), (*f1)(xyz[0], xyz[1], xyz[2]),
739 (*f2)(xyz[0], xyz[1], xyz[2]));
740 double diff =
normSq(sol - val);
743 printf(
"Displacement Error = %g\n", sqrt(err));
763 for(
int j = 0; j < npts; j++) {
764 double u = GP[j].
pt[0];
765 double v = GP[j].
pt[1];
766 double w = GP[j].
pt[2];
767 double weight = GP[j].
weight;
772 solField.
f(e, u, v, w, FEMVALUE);
773 SVector3 sol((*f0)(p.
x(), p.
y(), p.
z()), (*f1)(p.
x(), p.
y(), p.
z()),
774 (*f2)(p.
x(), p.
y(), p.
z()));
775 double diff =
normSq(sol - FEMVALUE);
776 val += diff * detJ * weight;
780 printf(
"L2Norm = %g\n", sqrt(val));
789 #if defined(HAVE_POST)
791 PView *elasticitySolver::buildErrorView(
const std::string postFileName,
796 std::cout <<
"build Error View" << std::endl;
797 std::map<int, std::vector<double> > data;
811 for(
int j = 0; j < npts; j++) {
812 double u = GP[j].
pt[0];
813 double v = GP[j].
pt[1];
814 double w = GP[j].
pt[2];
815 double weight = GP[j].
weight;
820 solField.f(e, u, v, w, FEMVALUE);
821 SVector3 sol((*f0)(p.
x(), p.
y(), p.
z()), (*f1)(p.
x(), p.
y(), p.
z()),
822 (*f2)(p.
x(), p.
y(), p.
z()));
823 double diff =
normSq(sol - FEMVALUE);
824 val += diff * detJ * weight;
826 std::vector<double> vec;
827 vec.push_back(sqrt(val));
836 PView *elasticitySolver::buildDisplacementView(
const std::string postFileName)
838 std::cout <<
"build Displacement View" << std::endl;
839 std::set<MVertex *> v;
840 std::map<MVertex *, MElement *> vCut;
849 if(vCut.find(e->
getVertex(j)) == vCut.end())
859 std::map<int, std::vector<double> > data;
861 for(
auto it = v.begin(); it != v.end(); ++it) {
864 Field.f(&p, 0, 0, 0, val);
865 std::vector<double> vec(3);
869 data[(*it)->getNum()] = vec;
871 for(
auto it = vCut.begin();
872 it != vCut.end(); ++it) {
875 double xyz[3] = {it->first->
x(), it->first->y(), it->first->z()};
876 it->second->xyz2uvw(xyz, uvw);
877 Field.f(it->second, uvw[0], uvw[1], uvw[2], val);
878 std::vector<double> vec(3);
882 data[it->first->getNum()] = vec;
888 PView *elasticitySolver::buildStressesView(
const std::string postFileName)
890 double sti[6] = {0., 0., 0., 0., 0., 0.};
891 double str[6] = {0., 0., 0., 0., 0., 0.};
893 std::cout <<
"build stresses view" << std::endl;
894 std::map<int, std::vector<double> > data;
905 std::vector<SVector3> val(nbVertex);
910 for(
int k = 0; k < nbVertex; k++) {
913 Field.f(&p, 0, 0, 0, val[k]);
923 double u = center.
x(), v = center.
y(), w = center.
z();
928 double eps[6] = {gradux[0],
931 0.5 * (gradux[1] + graduy[0]),
932 0.5 * (gradux[2] + graduz[0]),
933 0.5 * (graduy[2] + graduz[1])};
935 double A = E / (1. + nu);
936 double B = A * (nu / (1. - 2 * nu));
937 double trace = eps[0] + eps[1] + eps[2];
938 double sxx = A * eps[0] + B * trace;
939 double syy = A * eps[1] + B * trace;
940 double szz = A * eps[2] + B * trace;
941 double sxy = A * eps[3];
942 double sxz = A * eps[4];
943 double syz = A * eps[5];
945 std::vector<double> vec(9);
958 for(
int k = 0; k < 6; k++) str[k] += eps[k] * vol;
968 for(
int i = 0; i < 6; i++) {
969 str[i] = str[i] / volTot;
970 sti[i] = sti[i] / volTot;
972 printf(
"effective stiffn = ");
973 for(
int i = 0; i < 6; i++) printf(
"%g ", sti[i]);
975 printf(
"effective strain = ");
976 for(
int i = 0; i < 6; i++) printf(
"%g ", str[i]);
983 PView *elasticitySolver::buildStrainView(
const std::string postFileName)
985 std::cout <<
"build strain view" << std::endl;
986 std::map<int, std::vector<double> > data;
994 std::vector<SVector3> val(nbVertex);
999 for(
int k = 0; k < nbVertex; k++) {
1002 Field.f(&p, 0, 0, 0, val[k]);
1003 valx[k] = val[k](0);
1004 valy[k] = val[k](1);
1005 valz[k] = val[k](2);
1011 double u = 0.33, v = 0.33, w = 0.0;
1016 std::vector<double> vec(9);
1020 vec[1] = vec[3] = 0.5 * (gradux[0] + graduy[1]);
1021 vec[2] = vec[6] = 0.5 * (gradux[0] + graduz[2]);
1022 vec[5] = vec[7] = 0.5 * (gradux[1] + graduz[2]);
1032 elasticitySolver::buildLagrangeMultiplierView(
const std::string &postFileName,
1035 std::cout <<
"build Lagrange Multiplier View" << std::endl;
1041 std::set<MVertex *> v;
1051 std::map<int, std::vector<double> > data;
1053 for(
auto it = v.begin(); it != v.end(); ++it) {
1056 Field.f(&p, 0, 0, 0, val);
1057 std::vector<double> vec;
1059 data[(*it)->getNum()] = vec;
1065 PView *elasticitySolver::buildElasticEnergyView(
const std::string postFileName)
1067 std::cout <<
"build Elastic Energy View" << std::endl;
1068 std::map<int, std::vector<double> > data;
1084 int npts = Integ_Bulk.getIntPoints(e, &GP);
1085 Elastic_Energy_Term.get(e, npts, GP, energ);
1086 One.get(e, npts, GP, vol);
1087 std::vector<double> vec;
1088 vec.push_back(energ / vol);
1096 PView *elasticitySolver::buildVolumeView(
const std::string postFileName)
1098 std::cout <<
"build Volume View";
1099 std::map<int, std::vector<double> > data;
1111 int npts = Integ_Vol.getIntPoints(e, &GP);
1112 One.get(e, npts, GP, vol);
1114 std::vector<double> vec;
1127 int npts = Integ_Vol.getIntPoints(e, &GP);
1128 One.get(e, npts, GP, l);
1136 std::cout <<
" / total vol = " << voltot << std::endl;
1140 PView *elasticitySolver::buildVonMisesView(
const std::string postFileName)
1142 std::cout <<
"build elastic view" << std::endl;
1143 std::map<int, std::vector<double> > data;
1156 int npts = Integ_Bulk.getIntPoints(e, &GP);
1157 Elastic_Energy_Term.get(e, npts, GP, energ);
1158 std::vector<double> vec;
1159 vec.push_back(energ);
1160 data[(*it)->getNum()] = vec;