After having knee replacement, sex can be resumed when you have healed and feel more comfortable, usually around 4 weeks after surgery. It will take a few weeks for your knee to heal and get moving again. You will have swelling and experience fatigue. You will most likely require pain medications during this time period.
Waiting to resume sexual activity until you feel more like yourself will result in more pleasant relations. It will also give your knee the opportunity to heal successfully.
Avoid kneeling positions at first. Eventually, when you are completely healed, most surgeons allow you to kneel but you might not be comfortable doing so for several months. Check with your surgeon to make sure this is the case. At first, stay relaxed and use positions that are comfortable for your knee. Pillows can be used to support your knee. You might find pain medications, either narcotic or over-the-counter, helpful to keep you comfortable. Plan sex for a time when you are well rested.