Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

translate python grad(u).trans code to C++

More
2 years 6 months ago #4017 by Kai
Hi all :),
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 :)
More
2 years 6 months ago #4019 by joachim
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
Code:
cout << *(u->Deriv()) << endl;

before the exception is thrown.

Joachim
More
2 years 6 months ago #4020 by Kai
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 ?
More
2 years 6 months ago #4021 by joachim
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.
More
2 years 6 months ago #4022 by Kai
But i do already the InnerProduct like InnerProdukt(grad(u) + Transpose(grad(u)), grad(v) + Transpose(grad(v)))
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 ?
More
2 years 6 months ago #4023 by joachim
can you do a
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.135 seconds