- Thank you received: 0
translate python grad(u).trans code to C++
3 years 1 month ago #4017
by Kai
translate python grad(u).trans code to C++ was created by Kai
Hi all ,
i try to translate the following piece of python code
into corresponding C++ code so far i have
but the TransposeCF leads to
So my question is how can i transpose v->Deriv() and u->Deriv() ?
Thank you for any help
i try to translate the following piece of python code
Code:
self.u = self.fes.TrialFunction()
self.v = self.fes.TestFunction()
# StiffnessMatrix depending on material type:
if (self.material.type == "linear"):
self.A = BilinearForm(self.fes)
self.A += 2 * self.material.mu * InnerProduct(1 / 2 * (grad(self.u) + grad(self.u).trans),
1 / 2 * (grad(self.v) + grad(self.v).trans)) * dx
into corresponding C++ code so far i have
Code:
ngcomp::ProxyNode u = fes->GetTrialFunction();
ngcomp::ProxyNode v = fes->GetTestFunction();
Flags flags_bfa;
std::shared_ptr<T_BilinearFormSymmetric<double>> bfa = make_shared<T_BilinearFormSymmetric<double>> (fes, "a", flags_bfa);
bfa->AddIntegrator(make_shared<SymbolicBilinearFormIntegrator>(
material.mu * InnerProduct(
0.5f*(u->Deriv() + TransposeCF(u->Deriv())),
0.5f*(v->Deriv() + TransposeCF(v->Deriv()))),
VOL, VOL));
but the TransposeCF leads to
Code:
terminate called after throwing an instance of 'ngcore::Exception'
what(): Transpose of non-matrix called
00:46:50: Das Programm ist abgestürzt.
So my question is how can i transpose v->Deriv() and u->Deriv() ?
Thank you for any help
3 years 1 month ago #4019
by joachim
Replied by joachim on topic translate python grad(u).trans code to C++
Hi Kai,
can you show us how you created the finite element space fes ? Is it really vector-valued ?
For debugging, you can insert a
before the exception is thrown.
Joachim
can you show us how you created the finite element space fes ? Is it really vector-valued ?
For debugging, you can insert a
Code:
cout << *(u->Deriv()) << endl;
before the exception is thrown.
Joachim
3 years 1 month ago #4020
by Kai
Replied by Kai on topic translate python grad(u).trans code to C++
Hi Joachim,
thanks for quick response, i used the wrong FESpace. Now iam using VectorH1FESpace but the next problem follows : the SymbolicBilinearFormIntegrator does not work with Vector valued Coefficient functions ...
hope this is ok to attach my new qustion here in this thread ?
thanks for quick response, i used the wrong FESpace. Now iam using VectorH1FESpace but the next problem follows : the SymbolicBilinearFormIntegrator does not work with Vector valued Coefficient functions ...
hope this is ok to attach my new qustion here in this thread ?
3 years 1 month ago #4021
by joachim
Replied by joachim on topic translate python grad(u).trans code to C++
yes, at the end you need a scalar-valued function for the SymbolicBilinearFormIntegrator.
You get it, for example, by taking InnerProduct(grad(u), grad(v)).
grad(u) and grad(v) are matrix-valued.
You get it, for example, by taking InnerProduct(grad(u), grad(v)).
grad(u) and grad(v) are matrix-valued.
3 years 1 month ago #4022
by Kai
Replied by Kai on topic translate python grad(u).trans code to C++
But i do already the InnerProduct like InnerProdukt(grad(u) + Transpose(grad(u)), grad(v) + Transpose(grad(v)))
but this returns a coef innerproduct, fix size = 9, real ... i do not see whats wrong here ... mathematically this should work ?
Code:
bfa->AddIntegrator(make_shared<SymbolicBilinearFormIntegrator>(
material.mu * InnerProduct(
0.5f*(u->Deriv() + TransposeCF(u->Deriv())),
0.5f*(v->Deriv() + TransposeCF(v->Deriv()))),
VOL, VOL));
but this returns a coef innerproduct, fix size = 9, real ... i do not see whats wrong here ... mathematically this should work ?
3 years 1 month ago #4023
by joachim
Replied by joachim on topic translate python grad(u).trans code to C++
can you do a
and send the output ?
If this does not help, you may send the complete example.
Code:
auto func = material.mu * InnerProduct(
0.5f*(u->Deriv() + TransposeCF(u->Deriv())),
0.5f*(v->Deriv() + TransposeCF(v->Deriv())));
cout << *func << endl;
and send the output ?
If this does not help, you may send the complete example.
Time to create page: 0.117 seconds